Skip to content

Commit 95dd2cd

Browse files
committed
Backwards compatibility added
1 parent 412a1ba commit 95dd2cd

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,30 @@ def initialize(client)
3131
self.client = client
3232
end
3333

34-
def resolve_host(hostname, family=AF_INET)
34+
def resolve_host(hostname, family = AF_INET)
3535
request = Packet.create_request(COMMAND_ID_STDAPI_NET_RESOLVE_HOST)
3636
request.add_tlv(TLV_TYPE_HOST_NAME, hostname)
3737
request.add_tlv(TLV_TYPE_ADDR_TYPE, family)
3838

3939
response = client.send_request(request)
4040

41-
raw = response.get_tlv_value(TLV_TYPE_IP)
41+
ips = []
42+
if response.has_tlv?(TLV_TYPE_RESOLVE_HOST_ENTRY)
43+
response.each(TLV_TYPE_RESOLVE_HOST_ENTRY) do |tlv|
44+
tlv.each(TLV_TYPE_IP) do |ip|
45+
ips << raw_to_host_ip_pair(hostname, ip.value)[:ip]
46+
end
47+
end
48+
elsif response.has_tlv?(TLV_TYPE_IP)
49+
ip = response.get_tlv_value(TLV_TYPE_IP)
50+
ips << raw_to_host_ip_pair(hostname, ip)[:ip]
51+
end
4252

43-
return raw_to_host_ip_pair(hostname, raw)
53+
{ hostname: hostname, ip: ips.first, ips: ips }
4454
end
4555

46-
def resolve_hosts(hostnames, family=AF_INET)
56+
def resolve_hosts(hostnames, family = AF_INET)
57+
result = []
4758
request = Packet.create_request(COMMAND_ID_STDAPI_NET_RESOLVE_HOSTS)
4859
request.add_tlv(TLV_TYPE_ADDR_TYPE, family)
4960

@@ -53,21 +64,22 @@ def resolve_hosts(hostnames, family=AF_INET)
5364

5465
response = client.send_request(request)
5566

56-
hosts = []
57-
raws = []
58-
59-
response.each(TLV_TYPE_IP) do |raw|
60-
raws << raw
61-
end
62-
63-
0.upto(hostnames.length - 1) do |i|
64-
raw = raws[i]
65-
host = hostnames[i]
66-
67-
hosts << raw_to_host_ip_pair(host, raw&.value)
67+
if response.has_tlv?(TLV_TYPE_RESOLVE_HOST_ENTRY)
68+
response.each_with_index(TLV_TYPE_RESOLVE_HOST_ENTRY) do |tlv, index|
69+
ips = []
70+
tlv.each(TLV_TYPE_IP) do |ip|
71+
ips << raw_to_host_ip_pair(hostnames[index], ip.value)[:ip]
72+
end
73+
result << { hostname: hostnames[index], ip: ips.first, ips: ips }
74+
end
75+
elsif response.has_tlv?(TLV_TYPE_IP)
76+
response.each_with_index(TLV_TYPE_IP) do |tlv, index|
77+
ips = [raw_to_host_ip_pair(hostnames[index], tlv.value)[:ip]]
78+
result << { hostname: hostnames[index], ip: ips.first, ips: ips }
79+
end
6880
end
6981

70-
return hosts
82+
result
7183
end
7284

7385
def raw_to_host_ip_pair(host, raw)

lib/rex/post/meterpreter/extensions/stdapi/tlv.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ module Stdapi
105105

106106
TLV_TYPE_SHUTDOWN_HOW = TLV_META_TYPE_UINT | 1530
107107

108+
# Resolve hosts/host
109+
TLV_TYPE_RESOLVE_HOST_ENTRY = TLV_META_TYPE_GROUP | 1550
110+
108111
##
109112
#
110113
# Sys
@@ -293,4 +296,3 @@ module Stdapi
293296
TLV_TYPE_AUDIO_INTERFACE_NAME = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 13)
294297

295298
end; end; end; end; end
296-

0 commit comments

Comments
 (0)