Return nil on error, and move the module to post/multi.
This commit is contained in:
@@ -48,7 +48,7 @@ class Resolve
|
||||
def resolve_hosts(hostnames, family=AF_INET)
|
||||
request = Packet.create_request('stdapi_net_resolve_hosts')
|
||||
request.add_tlv(TLV_TYPE_ADDR_TYPE, family)
|
||||
|
||||
|
||||
hostnames.each do |hostname|
|
||||
request.add_tlv(TLV_TYPE_HOST_NAME, hostname)
|
||||
end
|
||||
@@ -84,7 +84,7 @@ class Resolve
|
||||
end
|
||||
|
||||
if raw.empty?
|
||||
ip = ""
|
||||
ip = nil
|
||||
else
|
||||
if type == AF_INET
|
||||
ip = Rex::Socket.addr_ntoa(raw[0..3])
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
#
|
||||
# This file is part of the Metasploit Framework and may be subject to
|
||||
# redistribution and commercial restrictions. Please see the Metasploit
|
||||
# web site for more information on licensing and terms of use.
|
||||
# http://metasploit.com/
|
||||
##
|
||||
|
||||
require 'msf/core'
|
||||
require 'rex'
|
||||
|
||||
class Metasploit3 < Msf::Post
|
||||
|
||||
def initialize(info={})
|
||||
super( update_info( info,
|
||||
'Name' => 'Windows Resolve Hosts',
|
||||
'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([
|
||||
OptString.new('HOSTNAMES', [true, 'Comma seperated list of hostnames to resolve.']),
|
||||
OptEnum.new('AI_FAMILY', [true, 'Address Family', 'IPv4', ['IPv4', 'IPv6'] ])
|
||||
], self.class)
|
||||
end
|
||||
|
||||
def run
|
||||
hosts = datastore['HOSTNAMES'].split(',')
|
||||
|
||||
if datastore['AI_FAMILY'] == 'IPv4'
|
||||
family = AF_INET
|
||||
else
|
||||
family = AF_INET6
|
||||
end
|
||||
|
||||
# Clear whitespace
|
||||
hosts.collect{|x| x.strip!}
|
||||
|
||||
print_status("Attempting to resolve '#{hosts.join(', ')}' on #{sysinfo['Computer']}") if not sysinfo.nil?
|
||||
|
||||
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
|
||||
@@ -10,6 +10,10 @@ require 'rex'
|
||||
|
||||
class Metasploit3 < Msf::Post
|
||||
|
||||
require 'msf/core/module/deprecated'
|
||||
include Msf::Module::Deprecated
|
||||
deprecated Date.new(2013, 12, 9), 'post/multi/gather/resolve_hosts'
|
||||
|
||||
def initialize(info={})
|
||||
super( update_info( info,
|
||||
'Name' => 'Windows Resolve Hosts',
|
||||
@@ -55,7 +59,11 @@ class Metasploit3 < Msf::Post
|
||||
)
|
||||
|
||||
response.each do |result|
|
||||
table << [result[:hostname], result[:ip]]
|
||||
if result[:ip].nil?
|
||||
table << [result[:hostname], '[Failed To Resolve]']
|
||||
else
|
||||
table << [result[:hostname], result[:ip]]
|
||||
end
|
||||
end
|
||||
|
||||
table.print
|
||||
|
||||
Reference in New Issue
Block a user