Skip to content

Commit

Permalink
Merge pull request #66 from projectdiscovery/feat-hosts-file
Browse files Browse the repository at this point in the history
Adding support for hosts file result
  • Loading branch information
ehsandeep committed Jul 26, 2022
2 parents cd4b87f + 2d0b0e8 commit 45451ae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions client.go
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion hostsfile/hostsfile.go
Expand Up @@ -3,6 +3,7 @@ package hostsfile
import (
"errors"
"fmt"
"net"
"os"
"runtime"
"strings"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
}

0 comments on commit 45451ae

Please sign in to comment.