Skip to content

Commit

Permalink
update: axfr feature optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
Esonhugh committed Mar 21, 2024
1 parent c16c7d8 commit caf3a2b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 5 additions & 2 deletions cmd/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
},
}

Expand Down
7 changes: 6 additions & 1 deletion cmd/axfr/axfr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -64,5 +64,5 @@ func DumpAXFR(target string, dnsServer string) []define.Record {
}
log.Debugf("Record: %v", rr.RR)
}
return records
return records, nil
}

0 comments on commit caf3a2b

Please sign in to comment.