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$',
|
2012-10-23 18:33:01 +00:00
|
|
|
'Platform' => [ 'win','linux', 'osx', 'bsd', 'solaris' ],
|
2012-07-22 03:54:29 +00:00
|
|
|
'SessionTypes' => [ 'meterpreter', 'shell' ]
|
2011-10-12 23:26:10 +00:00
|
|
|
))
|
|
|
|
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']
|
|
|
|
print_status("Performing DNS Reverse Lookup for IP range #{iprange}")
|
|
|
|
iplst = []
|
|
|
|
|
2012-07-22 03:54:29 +00:00
|
|
|
a = []
|
2011-10-12 23:26:10 +00:00
|
|
|
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
|
2012-07-22 03:54:29 +00:00
|
|
|
# Use the shell platform for selecting the command
|
|
|
|
platform = session.platform
|
2011-10-12 23:26:10 +00:00
|
|
|
else
|
2012-07-22 03:54:29 +00:00
|
|
|
# When in Meterpreter the safest thread number is 10
|
2011-10-12 23:26:10 +00:00
|
|
|
thread_num = 10
|
2012-07-22 03:54:29 +00:00
|
|
|
# For Meterpreter use the sysinfo OS since java Meterpreter returns java as platform
|
|
|
|
platform = session.sys.config.sysinfo['OS']
|
2011-10-12 23:26:10 +00:00
|
|
|
end
|
|
|
|
|
2012-07-22 03:54:29 +00:00
|
|
|
platform = session.platform
|
2011-10-12 23:26:10 +00:00
|
|
|
|
2012-07-22 03:54:29 +00:00
|
|
|
case platform
|
|
|
|
when /win/i
|
|
|
|
cmd = "nslookup"
|
|
|
|
when /solaris/i
|
|
|
|
cmd = "/usr/sbin/host"
|
|
|
|
else
|
|
|
|
cmd = "/usr/bin/host"
|
|
|
|
end
|
|
|
|
while(not iplst.nil? and not iplst.empty?)
|
2012-08-07 20:59:01 +00:00
|
|
|
1.upto(thread_num) do
|
|
|
|
a << framework.threads.spawn("Module(#{self.refname})", false, iplst.shift) do |ip_add|
|
|
|
|
next if ip_add.nil?
|
2012-07-22 03:54:29 +00:00
|
|
|
r = cmd_exec(cmd, " #{ip_add}")
|
|
|
|
case platform
|
|
|
|
when /win/
|
|
|
|
if r =~ /(Name)/
|
|
|
|
r.scan(/Name:\s*\S*\s/) do |n|
|
|
|
|
hostname = n.split(": ")
|
|
|
|
print_good "\t #{ip_add} is #{hostname[1].chomp("\n")}"
|
2011-10-12 23:26:10 +00:00
|
|
|
report_host({
|
2012-07-22 03:54:29 +00:00
|
|
|
:host => ip_add,
|
|
|
|
:name => hostname[1].strip
|
2011-10-12 23:26:10 +00:00
|
|
|
})
|
|
|
|
end
|
2012-07-22 03:54:29 +00:00
|
|
|
else
|
|
|
|
vprint_status("#{ip_add} does not have a Reverse Lookup Record")
|
2011-10-12 23:26:10 +00:00
|
|
|
end
|
2012-07-22 03:54:29 +00:00
|
|
|
else
|
|
|
|
if r !~ /not found/i
|
|
|
|
hostname = r.scan(/domain name pointer (\S*)\./).join
|
|
|
|
print_good "\t #{ip_add} is #{hostname}"
|
|
|
|
report_host({
|
|
|
|
:host => ip_add,
|
|
|
|
:name => hostname.strip
|
|
|
|
})
|
|
|
|
else
|
|
|
|
vprint_status("#{ip_add} does not have a Reverse Lookup Record")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-08-07 20:59:01 +00:00
|
|
|
a.map {|x| x.join }
|
|
|
|
end
|
2011-10-12 23:26:10 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-17 03:49:49 +00:00
|
|
|
end
|