2013-10-16 21:29:55 +00:00
|
|
|
##
|
2013-10-15 18:50:46 +00:00
|
|
|
# This module requires Metasploit: http//metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2013-10-09 20:52:53 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
2013-10-14 20:17:39 +00:00
|
|
|
'Name' => 'Multi Gather Resolve Hosts',
|
2013-10-09 20:52:53 +00:00
|
|
|
'Description' => %q{
|
|
|
|
Resolves hostnames to either IPv4 or IPv6 addresses from the perspective of the remote host.
|
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'Ben Campbell <eat_meatballs[at]hotmail.co.uk>' ],
|
|
|
|
'Platform' => %w{ win python },
|
|
|
|
'SessionTypes' => [ 'meterpreter' ]
|
|
|
|
))
|
|
|
|
|
|
|
|
register_options([
|
2013-11-24 15:20:04 +00:00
|
|
|
OptString.new('HOSTNAMES', [false, 'Comma seperated list of hostnames to resolve.']),
|
|
|
|
OptPath.new('HOSTFILE', [false, 'Line separated file with hostnames to resolve.']),
|
2013-10-09 20:52:53 +00:00
|
|
|
OptEnum.new('AI_FAMILY', [true, 'Address Family', 'IPv4', ['IPv4', 'IPv6'] ])
|
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2013-11-24 15:20:04 +00:00
|
|
|
|
|
|
|
hosts = []
|
|
|
|
if datastore['HOSTNAMES']
|
2013-11-24 15:28:44 +00:00
|
|
|
hostnames = datastore['HOSTNAMES'].split(',')
|
|
|
|
hostnames.each do |hostname|
|
|
|
|
hostname.strip!
|
|
|
|
hosts << hostname unless hostname.empty?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if datastore['HOSTFILE']
|
2013-11-24 15:20:04 +00:00
|
|
|
::File.open(datastore['HOSTFILE'], "rb").each_line do |hostname|
|
|
|
|
hostname.strip!
|
|
|
|
hosts << hostname unless hostname.empty?
|
|
|
|
end
|
|
|
|
end
|
2013-10-09 20:52:53 +00:00
|
|
|
|
2013-11-24 15:28:44 +00:00
|
|
|
if hosts.empty?
|
|
|
|
fail_with(Failure::BadConfig, "No hostnames to resolve.")
|
|
|
|
end
|
|
|
|
|
|
|
|
hosts.uniq!
|
|
|
|
|
2013-10-09 20:52:53 +00:00
|
|
|
if datastore['AI_FAMILY'] == 'IPv4'
|
|
|
|
family = AF_INET
|
|
|
|
else
|
|
|
|
family = AF_INET6
|
|
|
|
end
|
|
|
|
|
2013-11-24 15:28:44 +00:00
|
|
|
print_status("Attempting to resolve '#{hosts.join(', ')}' on #{sysinfo['Computer']}") if sysinfo
|
2013-10-09 20:52:53 +00:00
|
|
|
|
|
|
|
response = client.net.resolve.resolve_hosts(hosts, family)
|
|
|
|
|
|
|
|
table = Rex::Ui::Text::Table.new(
|
|
|
|
'Indent' => 0,
|
|
|
|
'SortIndex' => -1,
|
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
'Hostname',
|
|
|
|
'IP',
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
response.each do |result|
|
|
|
|
if result[:ip].nil?
|
|
|
|
table << [result[:hostname], '[Failed To Resolve]']
|
|
|
|
else
|
|
|
|
table << [result[:hostname], result[:ip]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
table.print
|
|
|
|
end
|
|
|
|
end
|