Retab changes for PR #1734
parent
322ed35bb4
commit
2e9096d427
|
@ -19,89 +19,89 @@ module Net
|
|||
###
|
||||
class Resolve
|
||||
|
||||
##
|
||||
#
|
||||
# Constructor
|
||||
#
|
||||
##
|
||||
##
|
||||
#
|
||||
# Constructor
|
||||
#
|
||||
##
|
||||
|
||||
#
|
||||
# Initializes a Resolve instance that is used to resolve network addresses
|
||||
# on the remote machine.
|
||||
#
|
||||
def initialize(client)
|
||||
self.client = client
|
||||
end
|
||||
#
|
||||
# Initializes a Resolve instance that is used to resolve network addresses
|
||||
# on the remote machine.
|
||||
#
|
||||
def initialize(client)
|
||||
self.client = client
|
||||
end
|
||||
|
||||
def resolve_host(hostname, family=AF_INET)
|
||||
request = Packet.create_request('stdapi_net_resolve_host')
|
||||
request.add_tlv(TLV_TYPE_HOST_NAME, hostname)
|
||||
request.add_tlv(TLV_TYPE_ADDR_TYPE, family)
|
||||
def resolve_host(hostname, family=AF_INET)
|
||||
request = Packet.create_request('stdapi_net_resolve_host')
|
||||
request.add_tlv(TLV_TYPE_HOST_NAME, hostname)
|
||||
request.add_tlv(TLV_TYPE_ADDR_TYPE, family)
|
||||
|
||||
response = client.send_request(request)
|
||||
response = client.send_request(request)
|
||||
|
||||
type = response.get_tlv_value(TLV_TYPE_ADDR_TYPE)
|
||||
raw = response.get_tlv_value(TLV_TYPE_IP)
|
||||
type = response.get_tlv_value(TLV_TYPE_ADDR_TYPE)
|
||||
raw = response.get_tlv_value(TLV_TYPE_IP)
|
||||
|
||||
return raw_to_host_ip_pair(hostname, raw, type)
|
||||
end
|
||||
return raw_to_host_ip_pair(hostname, raw, type)
|
||||
end
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
response = client.send_request(request)
|
||||
response = client.send_request(request)
|
||||
|
||||
hosts = []
|
||||
raws = []
|
||||
types = []
|
||||
hosts = []
|
||||
raws = []
|
||||
types = []
|
||||
|
||||
response.each(TLV_TYPE_IP) do |raw|
|
||||
raws << raw
|
||||
end
|
||||
response.each(TLV_TYPE_IP) do |raw|
|
||||
raws << raw
|
||||
end
|
||||
|
||||
response.each(TLV_TYPE_ADDR_TYPE) do |type|
|
||||
types << type
|
||||
end
|
||||
response.each(TLV_TYPE_ADDR_TYPE) do |type|
|
||||
types << type
|
||||
end
|
||||
|
||||
0.upto(hostnames.length - 1) do |i|
|
||||
raw = raws[i]
|
||||
type = types[i]
|
||||
host = hostnames[i]
|
||||
0.upto(hostnames.length - 1) do |i|
|
||||
raw = raws[i]
|
||||
type = types[i]
|
||||
host = hostnames[i]
|
||||
|
||||
hosts << raw_to_host_ip_pair(host, raw.value, type.value)
|
||||
end
|
||||
hosts << raw_to_host_ip_pair(host, raw.value, type.value)
|
||||
end
|
||||
|
||||
return hosts
|
||||
end
|
||||
return hosts
|
||||
end
|
||||
|
||||
def raw_to_host_ip_pair(host, raw, type)
|
||||
if raw.nil? or host.nil?
|
||||
return nil
|
||||
end
|
||||
def raw_to_host_ip_pair(host, raw, type)
|
||||
if raw.nil? or host.nil?
|
||||
return nil
|
||||
end
|
||||
|
||||
if raw.empty?
|
||||
ip = ""
|
||||
else
|
||||
if type == AF_INET
|
||||
ip = Rex::Socket.addr_ntoa(raw[0..3])
|
||||
else
|
||||
ip = Rex::Socket.addr_ntoa(raw[0..16])
|
||||
end
|
||||
end
|
||||
if raw.empty?
|
||||
ip = ""
|
||||
else
|
||||
if type == AF_INET
|
||||
ip = Rex::Socket.addr_ntoa(raw[0..3])
|
||||
else
|
||||
ip = Rex::Socket.addr_ntoa(raw[0..16])
|
||||
end
|
||||
end
|
||||
|
||||
result = { :hostname => host, :ip => ip }
|
||||
result = { :hostname => host, :ip => ip }
|
||||
|
||||
return result
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
attr_accessor :client # :nodoc:
|
||||
attr_accessor :client # :nodoc:
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -41,51 +41,51 @@ class Stdapi < Extension
|
|||
def initialize(client)
|
||||
super(client, 'stdapi')
|
||||
|
||||
# Alias the following things on the client object so that they
|
||||
# can be directly referenced
|
||||
client.register_extension_aliases(
|
||||
[
|
||||
{
|
||||
'name' => 'fs',
|
||||
'ext' => ObjectAliases.new(
|
||||
{
|
||||
'dir' => self.dir,
|
||||
'file' => self.file,
|
||||
'filestat' => self.filestat
|
||||
})
|
||||
},
|
||||
{
|
||||
'name' => 'sys',
|
||||
'ext' => ObjectAliases.new(
|
||||
{
|
||||
'config' => Sys::Config.new(client),
|
||||
'process' => self.process,
|
||||
'registry' => self.registry,
|
||||
'eventlog' => self.eventlog,
|
||||
'power' => self.power
|
||||
})
|
||||
},
|
||||
{
|
||||
'name' => 'net',
|
||||
'ext' => ObjectAliases.new(
|
||||
{
|
||||
'config' => Rex::Post::Meterpreter::Extensions::Stdapi::Net::Config.new(client),
|
||||
'socket' => Rex::Post::Meterpreter::Extensions::Stdapi::Net::Socket.new(client),
|
||||
'resolve' => Rex::Post::Meterpreter::Extensions::Stdapi::Net::Resolve.new(client)
|
||||
})
|
||||
},
|
||||
{
|
||||
'name' => 'railgun',
|
||||
'ext' => Rex::Post::Meterpreter::Extensions::Stdapi::Railgun::Railgun.new(client)
|
||||
},
|
||||
{
|
||||
'name' => 'webcam',
|
||||
'ext' => Rex::Post::Meterpreter::Extensions::Stdapi::Webcam::Webcam.new(client)
|
||||
},
|
||||
{
|
||||
'name' => 'ui',
|
||||
'ext' => UI.new(client)
|
||||
}
|
||||
# Alias the following things on the client object so that they
|
||||
# can be directly referenced
|
||||
client.register_extension_aliases(
|
||||
[
|
||||
{
|
||||
'name' => 'fs',
|
||||
'ext' => ObjectAliases.new(
|
||||
{
|
||||
'dir' => self.dir,
|
||||
'file' => self.file,
|
||||
'filestat' => self.filestat
|
||||
})
|
||||
},
|
||||
{
|
||||
'name' => 'sys',
|
||||
'ext' => ObjectAliases.new(
|
||||
{
|
||||
'config' => Sys::Config.new(client),
|
||||
'process' => self.process,
|
||||
'registry' => self.registry,
|
||||
'eventlog' => self.eventlog,
|
||||
'power' => self.power
|
||||
})
|
||||
},
|
||||
{
|
||||
'name' => 'net',
|
||||
'ext' => ObjectAliases.new(
|
||||
{
|
||||
'config' => Rex::Post::Meterpreter::Extensions::Stdapi::Net::Config.new(client),
|
||||
'socket' => Rex::Post::Meterpreter::Extensions::Stdapi::Net::Socket.new(client),
|
||||
'resolve' => Rex::Post::Meterpreter::Extensions::Stdapi::Net::Resolve.new(client)
|
||||
})
|
||||
},
|
||||
{
|
||||
'name' => 'railgun',
|
||||
'ext' => Rex::Post::Meterpreter::Extensions::Stdapi::Railgun::Railgun.new(client)
|
||||
},
|
||||
{
|
||||
'name' => 'webcam',
|
||||
'ext' => Rex::Post::Meterpreter::Extensions::Stdapi::Webcam::Webcam.new(client)
|
||||
},
|
||||
{
|
||||
'name' => 'ui',
|
||||
'ext' => UI.new(client)
|
||||
}
|
||||
|
||||
])
|
||||
end
|
||||
|
|
|
@ -10,54 +10,54 @@ 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.
|
||||
},
|
||||
'License' => MSF_LICENSE,
|
||||
'Author' => [ 'Ben Campbell <eat_meatballs[at]hotmail.co.uk>' ],
|
||||
'Platform' => [ 'win', 'linux' ],
|
||||
'SessionTypes' => [ 'meterpreter' ]
|
||||
))
|
||||
def initialize(info={})
|
||||
super( update_info( info,
|
||||
'Name' => 'Windows Resolve Hosts',
|
||||
'Description' => %q{
|
||||
Resolves hostnames to either IPv4 or IPv6 addresses.
|
||||
},
|
||||
'License' => MSF_LICENSE,
|
||||
'Author' => [ 'Ben Campbell <eat_meatballs[at]hotmail.co.uk>' ],
|
||||
'Platform' => [ 'win', 'linux' ],
|
||||
'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
|
||||
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(',')
|
||||
def run
|
||||
hosts = datastore['HOSTNAMES'].split(',')
|
||||
|
||||
if datastore['AI_FAMILY'] == 'IPv4'
|
||||
family = AF_INET
|
||||
else
|
||||
family = AF_INET6
|
||||
end
|
||||
if datastore['AI_FAMILY'] == 'IPv4'
|
||||
family = AF_INET
|
||||
else
|
||||
family = AF_INET6
|
||||
end
|
||||
|
||||
# Clear whitespace
|
||||
hosts.collect{|x| x.strip!}
|
||||
# Clear whitespace
|
||||
hosts.collect{|x| x.strip!}
|
||||
|
||||
print_status("Attempting to resolve '#{hosts.join(', ')}' on #{sysinfo['Computer']}") if not sysinfo.nil?
|
||||
print_status("Attempting to resolve '#{hosts.join(', ')}' on #{sysinfo['Computer']}") if not sysinfo.nil?
|
||||
|
||||
response = client.net.resolve.resolve_hosts(hosts, family)
|
||||
response = client.net.resolve.resolve_hosts(hosts, family)
|
||||
|
||||
table = Rex::Ui::Text::Table.new(
|
||||
'Indent' => 0,
|
||||
'SortIndex' => -1,
|
||||
'Columns' =>
|
||||
[
|
||||
'Hostname',
|
||||
'IP',
|
||||
]
|
||||
)
|
||||
table = Rex::Ui::Text::Table.new(
|
||||
'Indent' => 0,
|
||||
'SortIndex' => -1,
|
||||
'Columns' =>
|
||||
[
|
||||
'Hostname',
|
||||
'IP',
|
||||
]
|
||||
)
|
||||
|
||||
response.each do |result|
|
||||
table << [result[:hostname], result[:ip]]
|
||||
end
|
||||
response.each do |result|
|
||||
table << [result[:hostname], result[:ip]]
|
||||
end
|
||||
|
||||
table.print
|
||||
end
|
||||
table.print
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue