diff --git a/cmd/all/all.go b/cmd/all/all.go index 5bba0e0..af23219 100644 --- a/cmd/all/all.go +++ b/cmd/all/all.go @@ -27,6 +27,11 @@ var AllCmd = &cobra.Command{ log.Warn("cidr is required") return } + records, err := scanner.DumpAXFR(dns.Fqdn(command.Opts.Zone), "ns.dns."+command.Opts.Zone+":53") + if err == nil { + printResult(records) + } + log.Errorf("Transfer failed: %v", err) ipNets, err := pkg.ParseStringToIPNet(command.Opts.Cidr) if err != nil { log.Warnf("ParseStringToIPNet failed: %v", err) @@ -37,8 +42,6 @@ var AllCmd = &cobra.Command{ } else { Run(ipNets) } - records := scanner.DumpAXFR(dns.Fqdn(command.Opts.Zone), "ns.dns."+command.Opts.Zone+":53") - printResult(records) }, } diff --git a/cmd/axfr/axfr.go b/cmd/axfr/axfr.go index 21ce554..7539a36 100644 --- a/cmd/axfr/axfr.go +++ b/cmd/axfr/axfr.go @@ -35,7 +35,12 @@ var AxfrCmd = &cobra.Command{ } log.Debugf("same command: dig axfr %v @%v", zone, dnsServer) - var records define.Records = scanner.DumpAXFR(zone, dnsServer) + var records define.Records + records, err := scanner.DumpAXFR(zone, dnsServer) + if err != nil { + log.Errorf("Transfer failed: %v", err) + return + } if command.Opts.OutputFile != "" { f, err := os.OpenFile(command.Opts.OutputFile, os.O_CREATE|os.O_WRONLY, 0644) if err != nil { diff --git a/pkg/scanner/scanner.go b/pkg/scanner/scanner.go index 1ccf0c5..8e4231d 100644 --- a/pkg/scanner/scanner.go +++ b/pkg/scanner/scanner.go @@ -42,13 +42,13 @@ func ScanSvcForPorts(records []define.Record) []define.Record { } // default target should be zone -func DumpAXFR(target string, dnsServer string) []define.Record { +func DumpAXFR(target string, dnsServer string) ([]define.Record, error) { t := new(dns.Transfer) m := new(dns.Msg) m.SetAxfr(target) ch, err := t.In(m, dnsServer) if err != nil { - log.Fatalf("Transfer failed: %v", err) + return nil, err } var records []define.Record for rr := range ch { @@ -64,5 +64,5 @@ func DumpAXFR(target string, dnsServer string) []define.Record { } log.Debugf("Record: %v", rr.RR) } - return records + return records, nil }