Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working IPv4 & IPv6 DNS resolution for single and multiple hosts #684

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sjanusz-r7
Copy link
Contributor

@sjanusz-r7 sjanusz-r7 commented Nov 15, 2023

This PR adds returning of multiple IPv4 and IPv6 addresses for a single host and multiple hosts. This is thanks to the new TLV group type, TLV_TYPE_RESOLVE_HOST_ENTRY, that comes from the pre-requisite PR here: rapid7/metasploit-framework#18499

I've changed the DWORD resolve_host function to now return the whole addrinfo structure, rather than only a single IP. This means that we now need to call freeaddrinfo() on the result to ensure proper cleanup.

Before

IPv4: Calling irb -e "puts framework.sessions.values.last.net.resolve.resolve_hosts ['google.com', 'bing.com', 'duckduckgo.com', 'cloudflare.com', 'slack.com', 'rapid7.com'], 2"

{:hostname=>"google.com", :ip=>"142.250.102.100", :ips=>["142.250.102.100"]}
{:hostname=>"bing.com", :ip=>"204.79.197.200", :ips=>["204.79.197.200"]}
{:hostname=>"duckduckgo.com", :ip=>"52.142.124.215", :ips=>["52.142.124.215"]}
{:hostname=>"cloudflare.com", :ip=>"104.16.133.229", :ips=>["104.16.133.229"]}
{:hostname=>"slack.com", :ip=>"18.169.120.191", :ips=>["18.169.120.191"]}
{:hostname=>"rapid7.com", :ip=>"108.138.85.72", :ips=>["108.138.85.72"]}

IPv6: Calling irb -e "puts framework.sessions.values.last.net.resolve.resolve_hosts ['localhost', 'mytestdns'], 23"

{:hostname=>"google.com", :ip=>"2a00:1450:4025:402::71", :ips=>["2a00:1450:4025:402::71"]}
{:hostname=>"example.com", :ip=>"2606:2800:220:1:248:1893:25c8:1946", :ips=>["2606:2800:220:1:248:1893:25c8:1946"]}

After

IPv4: Calling irb -e "puts framework.sessions.values.last.net.resolve.resolve_hosts ['google.com', 'bing.com', 'duckduckgo.com', 'cloudflare.com', 'slack.com', 'rapid7.com'], 2"

{:hostname=>"google.com", :ip=>"142.250.102.139", :ips=>["142.250.102.139", "142.250.102.100", "142.250.102.101", "142.250.102.102", "142.250.102.113", "142.250.102.138"]}
{:hostname=>"bing.com", :ip=>"204.79.197.200", :ips=>["204.79.197.200", "13.107.21.200"]}
{:hostname=>"duckduckgo.com", :ip=>"52.142.124.215", :ips=>["52.142.124.215"]}
{:hostname=>"cloudflare.com", :ip=>"104.16.133.229", :ips=>["104.16.133.229", "104.16.132.229"]}
{:hostname=>"slack.com", :ip=>"18.168.172.238", :ips=>["18.168.172.238", "18.169.61.189", "18.169.120.191", "18.134.215.41"]}
{:hostname=>"rapid7.com", :ip=>"18.66.112.46", :ips=>["18.66.112.46", "18.66.112.84", "18.66.112.28", "18.66.112.21"]}

IPv6: Calling irb -e "puts framework.sessions.values.last.net.resolve.resolve_hosts ['google.com', 'example.com'], 23"

{:hostname=>"google.com", :ip=>"2a00:1450:4025:402::65", :ips=>["2a00:1450:4025:402::65", "2a00:1450:4025:402::71", "2a00:1450:4025:402::8a", "2a00:1450:4025:402::64"]}
{:hostname=>"example.com", :ip=>"2606:2800:220:1:248:1893:25c8:1946", :ips=>["2606:2800:220:1:248:1893:25c8:1946"]}

@sjanusz-r7 sjanusz-r7 force-pushed the windows-met-dns-resolve-multiple-hosts branch from e74a88d to 7f588d3 Compare December 11, 2023 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant