Skip to content

Commit

Permalink
Backwards compatibility added
Browse files Browse the repository at this point in the history
  • Loading branch information
cgranleese-r7 committed Jan 9, 2025
1 parent 412a1ba commit 95dd2cd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
46 changes: 29 additions & 17 deletions lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,30 @@ def initialize(client)
self.client = client
end

def resolve_host(hostname, family=AF_INET)
def resolve_host(hostname, family = AF_INET)
request = Packet.create_request(COMMAND_ID_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)

raw = response.get_tlv_value(TLV_TYPE_IP)
ips = []
if response.has_tlv?(TLV_TYPE_RESOLVE_HOST_ENTRY)
response.each(TLV_TYPE_RESOLVE_HOST_ENTRY) do |tlv|
tlv.each(TLV_TYPE_IP) do |ip|
ips << raw_to_host_ip_pair(hostname, ip.value)[:ip]
end
end
elsif response.has_tlv?(TLV_TYPE_IP)
ip = response.get_tlv_value(TLV_TYPE_IP)
ips << raw_to_host_ip_pair(hostname, ip)[:ip]
end

return raw_to_host_ip_pair(hostname, raw)
{ hostname: hostname, ip: ips.first, ips: ips }
end

def resolve_hosts(hostnames, family=AF_INET)
def resolve_hosts(hostnames, family = AF_INET)
result = []
request = Packet.create_request(COMMAND_ID_STDAPI_NET_RESOLVE_HOSTS)
request.add_tlv(TLV_TYPE_ADDR_TYPE, family)

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

response = client.send_request(request)

hosts = []
raws = []

response.each(TLV_TYPE_IP) do |raw|
raws << raw
end

0.upto(hostnames.length - 1) do |i|
raw = raws[i]
host = hostnames[i]

hosts << raw_to_host_ip_pair(host, raw&.value)
if response.has_tlv?(TLV_TYPE_RESOLVE_HOST_ENTRY)
response.each_with_index(TLV_TYPE_RESOLVE_HOST_ENTRY) do |tlv, index|
ips = []
tlv.each(TLV_TYPE_IP) do |ip|
ips << raw_to_host_ip_pair(hostnames[index], ip.value)[:ip]
end
result << { hostname: hostnames[index], ip: ips.first, ips: ips }
end
elsif response.has_tlv?(TLV_TYPE_IP)
response.each_with_index(TLV_TYPE_IP) do |tlv, index|
ips = [raw_to_host_ip_pair(hostnames[index], tlv.value)[:ip]]
result << { hostname: hostnames[index], ip: ips.first, ips: ips }
end
end

return hosts
result
end

def raw_to_host_ip_pair(host, raw)
Expand Down
4 changes: 3 additions & 1 deletion lib/rex/post/meterpreter/extensions/stdapi/tlv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ module Stdapi

TLV_TYPE_SHUTDOWN_HOW = TLV_META_TYPE_UINT | 1530

# Resolve hosts/host
TLV_TYPE_RESOLVE_HOST_ENTRY = TLV_META_TYPE_GROUP | 1550

##
#
# Sys
Expand Down Expand Up @@ -293,4 +296,3 @@ module Stdapi
TLV_TYPE_AUDIO_INTERFACE_NAME = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 13)

end; end; end; end; end

0 comments on commit 95dd2cd

Please sign in to comment.