2011-10-12 23:26:10 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# ## This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2011-10-12 23:26:10 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
require 'msf/core/post/common'
|
|
|
|
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
|
|
|
include Msf::Post::Common
|
|
|
|
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
|
|
|
'Name' => 'Multi Gather DNS Reverse Lookup Scan',
|
2011-10-17 03:49:49 +00:00
|
|
|
'Description' => %q{
|
2011-10-12 23:26:10 +00:00
|
|
|
Performs DNS reverse lookup using the OS included DNS query command.
|
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Platform' => [ 'windows','linux', 'osx', 'bsd', 'solaris' ],
|
|
|
|
'SessionTypes' => [ 'meterpreter','shell' ]
|
|
|
|
))
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
|
|
|
|
OptAddressRange.new('RHOSTS', [true, 'IP Range to perform reverse lookup against.'])
|
|
|
|
|
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Run Method for when run command is issued
|
|
|
|
def run
|
|
|
|
iprange = datastore['RHOSTS']
|
|
|
|
found_hosts = []
|
|
|
|
print_status("Performing DNS Reverse Lookup for IP range #{iprange}")
|
|
|
|
iplst = []
|
|
|
|
|
|
|
|
i, a = 0, []
|
|
|
|
ipadd = Rex::Socket::RangeWalker.new(iprange)
|
|
|
|
numip = ipadd.num_ips
|
|
|
|
while (iplst.length < numip)
|
|
|
|
ipa = ipadd.next_ip
|
|
|
|
if (not ipa)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
iplst << ipa
|
|
|
|
end
|
|
|
|
|
|
|
|
if session.type =~ /shell/
|
|
|
|
# Only one thread possible when shell
|
|
|
|
thread_num = 1
|
|
|
|
else
|
|
|
|
# When Meterpreter the safest thread number is 10
|
|
|
|
thread_num = 10
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
iplst.each do |ip|
|
|
|
|
# Set count option for ping command
|
|
|
|
plat = session.platform
|
|
|
|
case plat
|
|
|
|
when /win/i
|
|
|
|
ns_opt = " #{ip}"
|
|
|
|
cmd = "nslookup"
|
|
|
|
when /solaris/i
|
|
|
|
ns_opt = " #{ip}"
|
|
|
|
cmd = "/usr/sbin/host"
|
|
|
|
else
|
|
|
|
ns_opt = " #{ip}"
|
|
|
|
cmd = "/usr/bin/host"
|
|
|
|
end
|
|
|
|
|
2011-10-15 01:37:50 +00:00
|
|
|
if i <= thread_num
|
2011-10-12 23:26:10 +00:00
|
|
|
a.push(::Thread.new {
|
|
|
|
r = cmd_exec(cmd, ns_opt)
|
|
|
|
|
|
|
|
case plat
|
|
|
|
when /win/
|
|
|
|
if r =~ /(Name)/
|
|
|
|
r.scan(/Name:\s*\S*\s/) do |n|
|
|
|
|
hostname = n.split(": ")
|
|
|
|
print_good "\t #{ip} is #{hostname[1].chomp("\n")}"
|
|
|
|
report_host({
|
|
|
|
:host => ip,
|
|
|
|
:name => hostname[1].strip,
|
2011-10-13 01:50:15 +00:00
|
|
|
:comm => "Discovered thru post reverse DNS lookup"
|
2011-10-12 23:26:10 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
else
|
|
|
|
vprint_status("#{ip} does not have a Reverse Lookup Record")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if r !~ /not found/i
|
|
|
|
hostname = r.scan(/domain name pointer (\S*)\./).join
|
|
|
|
print_good "\t #{ip} is #{hostname}"
|
|
|
|
report_host({
|
|
|
|
:host => ip,
|
|
|
|
:name => hostname.strip,
|
2011-10-13 01:50:15 +00:00
|
|
|
:comm => "Discovered thru post reverse DNS lookup"
|
2011-10-12 23:26:10 +00:00
|
|
|
})
|
|
|
|
else
|
|
|
|
vprint_status("#{ip} does not have a Reverse Lookup Record")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
})
|
|
|
|
i += 1
|
|
|
|
else
|
|
|
|
sleep(0.05) and a.delete_if {|x| not x.alive?} while not a.empty?
|
|
|
|
i = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
a.delete_if {|x| not x.alive?} while not a.empty?
|
|
|
|
|
|
|
|
end
|
2011-10-17 03:49:49 +00:00
|
|
|
end
|