Path: blob/master/modules/auxiliary/scanner/dcerpc/hidden.rb
19813 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary67# Exploit mixins should be called first8include Msf::Exploit::Remote::DCERPC910include Msf::Auxiliary::Report1112# Scanner mixin should be near last13include Msf::Auxiliary::Scanner1415def initialize16super(17'Name' => 'Hidden DCERPC Service Discovery',18'Description' => %q{19This module will query the endpoint mapper and make a list20of all ncacn_tcp RPC services. It will then connect to each of21these services and use the management API to list all other22RPC services accessible on this port. Any RPC service found attached23to a TCP port, but not listed in the endpoint mapper, will be displayed24and analyzed to see whether anonymous access is permitted.25},26'Author' => 'hdm',27'License' => MSF_LICENSE,28'Notes' => {29'Stability' => [CRASH_SAFE],30'SideEffects' => [],31'Reliability' => []32}33)3435deregister_options('RPORT')36end3738# Obtain information about a single host39def run_host(ip)40epm = dcerpc_endpoint_list41if !epm42print_status("Could not contact the endpoint mapper on #{ip}")43return44end4546eports = {}4748epm.each do |ep|49next if !(ep[:port] && ep[:prot] && (ep[:prot] == 'tcp'))5051eports[ep[:port]] ||= {}52eports[ep[:port]][ep[:uuid] + '_' + ep[:vers]] = true53end5455eports.each_pair do |eport, servs|56rport = eport57print_status("Looking for services on #{ip}:#{rport}...")5859ids = dcerpc_mgmt_inq_if_ids(rport)60next if !ids6162ids.each do |id|63next if servs.key?(id[0] + '_' + id[1])6465print_status("\tHIDDEN: UUID #{id[0]} v#{id[1]}")6667conn = nil68bind = nil69call = nil70data = nil71error = nil72begin73connect(true, { 'RPORT' => eport })74conn = true7576handle = dcerpc_handle(id[0], id[1], 'ncacn_ip_tcp', [eport])77dcerpc_bind(handle)78bind = true7980dcerpc.call(0, NDR.long(0) * 128)81call = true8283if !dcerpc.last_response.nil? && !dcerpc.last_response.stub_data.nil?84data = dcerpc.last_response.stub_data85end86rescue ::Interrupt87raise $ERROR_INFO88rescue StandardError => e89error = e.to_s90end9192if error93if error =~ /DCERPC FAULT/ && error !~ /nca_s_fault_access_denied/94call = true95else96elog(e)97end98end99100status = "\t\t"101status << 'CONN ' if conn102status << 'BIND ' if bind103status << 'CALL ' if call104status << "DATA=#{data.unpack('H*')[0]} " if data105status << "ERROR=#{error} " if error106107print_status(status)108print_status('')109110report_note(111host: ip,112proto: 'tcp',113port: datastore['RPORT'],114type: "DCERPC HIDDEN: UUID #{id[0]} v#{id[1]}",115data: { status: status }116)117end118end119rescue ::Interrupt120raise $ERROR_INFO121rescue StandardError => e122print_status("Error: #{e}")123end124end125126127