diff --git a/client.go b/client.go index ec96309..ff17267 100644 --- a/client.go +++ b/client.go @@ -226,6 +226,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{} @@ -529,6 +532,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 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" +}