From 95dd2cd6aa4d2fa06f79817b686772de63e753b9 Mon Sep 17 00:00:00 2001 From: cgranleese-r7 Date: Wed, 18 Oct 2023 10:46:37 +0100 Subject: [PATCH] Backwards compatibility added --- .../extensions/stdapi/net/resolve.rb | 46 ++++++++++++------- .../post/meterpreter/extensions/stdapi/tlv.rb | 4 +- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb b/lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb index 023d8251098e..7fc2d21d2fed 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb @@ -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) @@ -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) diff --git a/lib/rex/post/meterpreter/extensions/stdapi/tlv.rb b/lib/rex/post/meterpreter/extensions/stdapi/tlv.rb index b6495bb675c7..7d7a1461911f 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/tlv.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/tlv.rb @@ -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 @@ -293,4 +296,3 @@ module Stdapi TLV_TYPE_AUDIO_INTERFACE_NAME = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 13) end; end; end; end; end -