From bbb0c49d7fa76704795d506a2fb8f969f3594c25 Mon Sep 17 00:00:00 2001 From: mzack Date: Sun, 17 Jul 2022 12:00:10 +0200 Subject: [PATCH 1/2] Adding support for hosts file result --- client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client.go b/client.go index 7d53240..9efcd5e 100644 --- a/client.go +++ b/client.go @@ -223,6 +223,9 @@ func (c *Client) queryMultiple(host string, requestTypes []uint16, resolver Reso } } } + if len(dnsdata.AAAA)+len(dnsdata.A) > 0 { + dnsdata.HostsFile = true + } } msg := &dns.Msg{} @@ -526,6 +529,7 @@ type DNSData struct { AXFRData *AXFRData `json:"axfr,omitempty"` RawResp *dns.Msg `json:"raw_resp,omitempty"` Timestamp time.Time `json:"timestamp,omitempty"` + HostsFile bool `json:"hosts_file,omitempty"` } // CheckInternalIPs when set to true returns if DNS response IPs From 2d0b0e81dd89abbbf7a3f3a15613e689fc8e8656 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Sun, 17 Jul 2022 12:58:27 +0200 Subject: [PATCH 2/2] handling windows localhost --- hostsfile/hostsfile.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/hostsfile/hostsfile.go b/hostsfile/hostsfile.go index 2a3946f..8d70611 100644 --- a/hostsfile/hostsfile.go +++ b/hostsfile/hostsfile.go @@ -3,6 +3,7 @@ package hostsfile import ( "errors" "fmt" + "net" "os" "runtime" "strings" @@ -11,8 +12,12 @@ import ( "github.com/projectdiscovery/stringsutil" ) +const ( + localhostName = "localhost" +) + func Path() string { - if runtime.GOOS == "windows" { + if isWindows() { return fmt.Sprintf(`%s\System32\Drivers\etc\hosts`, os.Getenv("SystemRoot")) } return "/etc/hosts" @@ -52,5 +57,19 @@ func Parse(p string) (map[string][]string, error) { } } } + + // windows 11 resolves localhost with system dns resolver + if _, ok := items[localhostName]; !ok && isWindows() { + localhostIPs, err := net.LookupHost(localhostName) + if err != nil { + return nil, err + } + items[localhostName] = localhostIPs + } + return items, nil } + +func isWindows() bool { + return runtime.GOOS == "windows" +}