Skip to content

Commit

Permalink
using IPv4 for nameservers
Browse files Browse the repository at this point in the history
  • Loading branch information
5amu committed Jul 5, 2022
1 parent 7448ff9 commit 942b700
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 12 deletions.
10 changes: 5 additions & 5 deletions cmd/dnshunter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func main() {
banner()

if err := mainFlagSet.Parse(os.Args[1:]); err != nil {
common.Error(fmt.Sprintf("%v", err))
fmt.Println(common.Error(fmt.Sprintf("%v", err)))
os.Exit(1)
}

if len(os.Args) < 2 {
usage()
common.Error("not enough arguments")
fmt.Println(common.Error("not enough arguments"))
os.Exit(1)
}

Expand All @@ -66,19 +66,19 @@ func main() {
}

if vers1 || vers2 {
common.Error(fmt.Sprintf("version %v\n", common.DNSHunterVersion))
fmt.Println(common.Error(fmt.Sprintf("version %v\n", common.DNSHunterVersion)))
os.Exit(0)
}

if len(mainFlagSet.Args()) != 1 {
usage()
common.Error("please, specify a target domain")
fmt.Println(common.Error("please, specify a target domain"))
os.Exit(1)
}

domain := mainFlagSet.Arg(0)
if err := run(outfile, nsfile, domain); err != nil {
common.Error(fmt.Sprintf("%v", err))
fmt.Println(common.Error(fmt.Sprintf("%v", err)))
os.Exit(1)
}
}
55 changes: 48 additions & 7 deletions cmd/dnshunter/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ func run(outfile string, nsfile string, domain string) error {

initialInfo := common.Info(fmt.Sprintf("scanning domain : %v\n", domain))
initialInfo += common.Info(fmt.Sprintf("using nameservers : %v\n", nameservers))

nameservers, err = nameserversToIPv4(nameservers)
if err != nil {
return err
}

initialInfo += common.Info(fmt.Sprintf("with IPv4 version : %v\n", nameservers))
if outfile != "" {
initialInfo += common.Info(fmt.Sprintf("saving output to : %v\n", outfile))
} else {
Expand All @@ -33,11 +40,14 @@ func run(outfile string, nsfile string, domain string) error {
var results []*output.CheckOutput
for _, check := range internal.CheckList {
check.Init(c)
check.Start(domain, nameservers)

if err := check.Start(domain, nameservers); err != nil {
return err
}

r := check.Results()
fmt.Println(r.String())
results = append(results, r)
fmt.Println(r)
}

if outfile != "" {
Expand Down Expand Up @@ -78,12 +88,43 @@ func nameserversFromDNS(domain string) (result []string, err error) {
}

for _, r := range r.Answer {
// google.com. 14332 IN NS ns3.google.com.
splitted := strings.Split(r.String(), "\t")
last := splitted[len(splitted)-1]

result = append(result, last)
switch t := r.(type) {
case *dns.NS:
// google.com. 14332 IN NS ns3.google.com.
splitted := strings.Split(t.String(), "\t")
last := splitted[len(splitted)-1]
result = append(result, last)
}
}

return result, nil
}

func nameserversToIPv4(fqdns []string) (result []string, err error) {
for _, fqdn := range fqdns {

c := new(dns.Client)
m := new(dns.Msg)
m.SetQuestion(fqdn, dns.TypeA)

r, _, err := c.Exchange(m, net.JoinHostPort(common.DefaultNameserver, "53"))
if err != nil {
return nil, err
}

if r.Rcode != dns.RcodeSuccess {
return nil, fmt.Errorf("invalid answer from %v after A query for %v", common.DefaultNameserver, fqdn)
}

for _, r := range r.Answer {
switch t := r.(type) {
case *dns.A:
// google.com. 14332 IN NS ns3.google.com.
splitted := strings.Split(t.String(), "\t")
last := splitted[len(splitted)-1]
result = append(result, last)
}
}
}
return
}

0 comments on commit 942b700

Please sign in to comment.