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/post/multi/gather/dns_reverse_lookup.rb
Views: 11784
##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)20)21register_options(22[2324OptAddressRange.new('RHOSTS', [true, 'IP Range to perform reverse lookup against.'])2526]27)28end2930# Run Method for when run command is issued31def run32iprange = datastore['RHOSTS']33print_status("Performing DNS Reverse Lookup for IP range #{iprange}")34iplst = []3536a = []37ipadd = Rex::Socket::RangeWalker.new(iprange)38numip = ipadd.num_ips39while (iplst.length < numip)40ipa = ipadd.next_ip41if !ipa42break43end4445iplst << ipa46end4748case session.platform49when 'windows'50cmd = 'nslookup'51when 'solaris'52cmd = '/usr/sbin/host'53else54cmd = '/usr/bin/host'55end5657while !iplst.nil? && !iplst.empty?581.upto session.max_threads do59a << framework.threads.spawn("Module(#{refname})", false, iplst.shift) do |ip_add|60next if ip_add.nil?6162r = cmd_exec(cmd, " #{ip_add}")63case session.platform64when 'windows'65if r =~ /(Name)/66r.scan(/Name:\s*\S*\s/) do |n|67hostname = n.split(': ')68print_good "\t #{ip_add} is #{hostname[1].chomp("\n")}"69report_host({70host: ip_add,71name: hostname[1].strip72})73end74else75vprint_status("#{ip_add} does not have a Reverse Lookup Record")76end77else78if r !~ /not found/i79hostname = r.scan(/domain name pointer (\S*)\./).join80print_good "\t #{ip_add} is #{hostname}"81report_host({82host: ip_add,83name: hostname.strip84})85else86vprint_status("#{ip_add} does not have a Reverse Lookup Record")87end88end89end90a.map(&:join)91end92end93end94end959697