Skip to content

Commit

Permalink
Addresses PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cgranleese-r7 committed Nov 7, 2023
1 parent d6e59c1 commit cd9020e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/msf/core/post/dns/resolve_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ module ResolveHost
#
# @param [String] host Hostname
# @return [Array, nil] result[:ips], ips The resolved IPs
def resolve_host(host)
def resolve_host(host, family)
if client.respond_to?(:net) && client.commands.include?(Rex::Post::Meterpreter::Extensions::Stdapi::COMMAND_ID_STDAPI_NET_RESOLVE_HOST)
result = client.net.resolve.resolve_host(host)
result = client.net.resolve.resolve_host(host, family)
result[:ips]
else
ips = []
Expand Down
26 changes: 22 additions & 4 deletions modules/post/windows/gather/enum_computers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def run
#
# @param [String] host Hostname
# @return [String] ip The resolved IP
def gethost(hostname)
def gethost(hostname, family)
## get IP for host
vprint_status("Looking up IP for #{hostname}")
resolve_host(hostname).join(', ')
resolve_host(hostname, family)
end

def get_domain_computers
Expand All @@ -87,6 +87,7 @@ def get_domain_computers
end

def list_computers(domain, hosts)
meterpreter_dns_resolving_errors = []
tbl = Rex::Text::Table.new(
'Header' => 'List of identified Hosts.',
'Indent' => 1,
Expand All @@ -98,12 +99,29 @@ def list_computers(domain, hosts)
]
)
hosts.each do |hostname|
hostip = gethost(hostname)
tbl << [domain, hostname, hostip]
begin
hostipv4 = gethost(hostname, AF_INET)
rescue Rex::Post::Meterpreter::RequestError => e
meterpreter_dns_resolving_errors << "IPV4: #{hostname} could not be resolved - #{e}"
end

begin
hostname = "google.com"
hostipv6 = gethost(hostname, AF_INET6)
rescue Rex::Post::Meterpreter::RequestError => e
meterpreter_dns_resolving_errors << "IPV6: #{hostname} could not be resolved - #{e}"
end

hostipv4.each { |ip| tbl << [domain, hostname, ip] } unless hostipv4.nil?
hostipv6.each { |ip| tbl << [domain, hostname, ip] } unless hostipv6.nil?
end

print_line("\n#{tbl}\n")

meterpreter_dns_resolving_errors.each do | error |
print_warning(error)
end

report_note(
host: session,
type: 'domain.hosts',
Expand Down

0 comments on commit cd9020e

Please sign in to comment.