Path: blob/master/modules/post/multi/gather/dns_reverse_lookup.rb
19664 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post67def initialize(info = {})8super(9update_info(10info,11'Name' => 'Multi Gather DNS Reverse Lookup Scan',12'Description' => %q{13Performs DNS reverse lookup using the OS included DNS query command.14},15'License' => MSF_LICENSE,16'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],17'Platform' => %w[bsd linux osx solaris win],18'SessionTypes' => [ 'meterpreter', 'shell' ],19'Notes' => {20'Stability' => [CRASH_SAFE],21'SideEffects' => [],22'Reliability' => []23}24)25)26register_options(27[28OptAddressRange.new('RHOSTS', [true, 'IP Range to perform reverse lookup against.'])29]30)31end3233def run34iprange = datastore['RHOSTS']35print_status("Performing DNS Reverse Lookup for IP range #{iprange}")36iplst = []3738a = []39ipadd = Rex::Socket::RangeWalker.new(iprange)40numip = ipadd.num_ips41while (iplst.length < numip)42ipa = ipadd.next_ip43if !ipa44break45end4647iplst << ipa48end4950case session.platform51when 'windows'52cmd = 'nslookup'53when 'solaris'54cmd = '/usr/sbin/host'55else56cmd = '/usr/bin/host'57end5859while !iplst.nil? && !iplst.empty?601.upto session.max_threads do61a << framework.threads.spawn("Module(#{refname})", false, iplst.shift) do |ip_add|62next if ip_add.nil?6364r = cmd_exec(cmd, " #{ip_add}")65case session.platform66when 'windows'67if r =~ /(Name)/68r.scan(/Name:\s*\S*\s/) do |n|69hostname = n.split(': ')70print_good "\t #{ip_add} is #{hostname[1].chomp("\n")}"71report_host({72host: ip_add,73name: hostname[1].strip74})75end76else77vprint_status("#{ip_add} does not have a Reverse Lookup Record")78end79else80if r !~ /not found/i81hostname = r.scan(/domain name pointer (\S*)\./).join82print_good "\t #{ip_add} is #{hostname}"83report_host({84host: ip_add,85name: hostname.strip86})87else88vprint_status("#{ip_add} does not have a Reverse Lookup Record")89end90end91end92a.map(&:join)93end94end95end96end979899