From 6c62463f83be1cb8272aceb8a3aaa0009d346254 Mon Sep 17 00:00:00 2001 From: Meatballs Date: Thu, 20 Jun 2013 22:17:31 +0100 Subject: [PATCH] Add ipv6 resolution and remove nix --- .../meterpreter/extensions/stdapi/constants.rb | 8 ++++++++ .../meterpreter/extensions/stdapi/net/resolve.rb | 11 ++++++----- .../general => windows/gather}/resolve_hosts.rb | 15 +++++++++++---- 3 files changed, 25 insertions(+), 9 deletions(-) rename modules/post/{multi/general => windows/gather}/resolve_hosts.rb (76%) diff --git a/lib/rex/post/meterpreter/extensions/stdapi/constants.rb b/lib/rex/post/meterpreter/extensions/stdapi/constants.rb index b18b25af21..4d661a64b4 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/constants.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/constants.rb @@ -11,6 +11,14 @@ # ### +## +# +# Net +# +## +AF_INET = 2 +AF_INET6 = 23 + ## # # Permissions diff --git a/lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb b/lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb index 52f9ef35e7..a503569606 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb @@ -33,9 +33,10 @@ class Resolve self.client = client end - def resolve_host(hostname) + 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) @@ -45,9 +46,10 @@ class Resolve return raw_to_host_ip_pair(hostname, raw, type) end - def resolve_hosts(hostnames) + 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 @@ -58,7 +60,6 @@ class Resolve raws = [] types = [] - # This is probably neater creating a TLV_GROUP? response.each(TLV_TYPE_IP) do |raw| raws << raw end @@ -86,7 +87,7 @@ class Resolve if raw.empty? ip = "" else - if type == 2 + if type == AF_INET ip = Rex::Socket.addr_ntoa(raw[0..3]) else ip = Rex::Socket.addr_ntoa(raw[0..16]) diff --git a/modules/post/multi/general/resolve_hosts.rb b/modules/post/windows/gather/resolve_hosts.rb similarity index 76% rename from modules/post/multi/general/resolve_hosts.rb rename to modules/post/windows/gather/resolve_hosts.rb index 271a6d9a71..f29971d32e 100644 --- a/modules/post/multi/general/resolve_hosts.rb +++ b/modules/post/windows/gather/resolve_hosts.rb @@ -12,9 +12,9 @@ class Metasploit3 < Msf::Post def initialize(info={}) super( update_info( info, - 'Name' => 'Multi General Resolve Hosts', + 'Name' => 'Windows Resolve Hosts', 'Description' => %q{ - Resolves hostnames. + Resolves hostnames to either IPv4 or IPv6 addresses. }, 'License' => MSF_LICENSE, 'Author' => [ 'Ben Campbell ' ], @@ -23,19 +23,26 @@ class Metasploit3 < Msf::Post )) register_options([ - OptString.new('HOSTNAMES', [true, 'Comma seperated list of hostnames to resolve.']) + 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['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) + response = client.net.resolve.resolve_hosts(hosts, family) table = Rex::Ui::Text::Table.new( 'Indent' => 0,