From 93888e039277b0f99a8c517570380f5a63f5ffbe Mon Sep 17 00:00:00 2001 From: hach Date: Fri, 12 May 2023 16:45:41 +0200 Subject: [PATCH 1/2] add SOA support --- client.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index 9b974e4..318a0ab 100644 --- a/client.go +++ b/client.go @@ -530,7 +530,7 @@ type DNSData struct { MX []string `json:"mx,omitempty"` PTR []string `json:"ptr,omitempty"` ANY []string `json:"any,omitempty"` - SOA []string `json:"soa,omitempty"` + SOA SOA `json:"soa,omitempty"` NS []string `json:"ns,omitempty"` TXT []string `json:"txt,omitempty"` SRV []string `json:"srv,omitempty"` @@ -548,6 +548,15 @@ type DNSData struct { HostsFile bool `json:"hosts_file,omitempty"` } +type SOA struct { + Name string `json:"name,omitempty"` + Serial uint32 `json:"serial,omitempty"` + Refresh uint32 `json:"refresh,omitempty"` + Retry uint32 `json:"retry,omitempty"` + Expire uint32 `json:"expire,omitempty"` + Minttl uint32 `json:"minttl,omitempty"` +} + // CheckInternalIPs when set to true returns if DNS response IPs // belong to internal IP ranges. var CheckInternalIPs = false @@ -569,8 +578,14 @@ func (d *DNSData) ParseFromRR(rrs []dns.RR) error { case *dns.CNAME: d.CNAME = append(d.CNAME, trimChars(recordType.Target)) case *dns.SOA: - d.SOA = append(d.SOA, trimChars(recordType.Ns)) - d.SOA = append(d.SOA, trimChars(recordType.Mbox)) + d.SOA = SOA{ + Name: recordType.Hdr.Name, + Serial: recordType.Serial, + Refresh: recordType.Refresh, + Retry: recordType.Retry, + Expire: recordType.Expire, + Minttl: recordType.Minttl, + } case *dns.PTR: d.PTR = append(d.PTR, trimChars(recordType.Ptr)) case *dns.MX: @@ -614,7 +629,7 @@ func (d *DNSData) ParseFromEnvelopeChan(envChan chan *dns.Envelope) error { } func (d *DNSData) contains() bool { - return len(d.A) > 0 || len(d.AAAA) > 0 || len(d.CNAME) > 0 || len(d.MX) > 0 || len(d.NS) > 0 || len(d.PTR) > 0 || len(d.ANY) > 0 || len(d.TXT) > 0 || len(d.SRV) > 0 || len(d.SOA) > 0 || len(d.CAA) > 0 + return len(d.A) > 0 || len(d.AAAA) > 0 || len(d.CNAME) > 0 || len(d.MX) > 0 || len(d.NS) > 0 || len(d.PTR) > 0 || len(d.ANY) > 0 || len(d.TXT) > 0 || len(d.SRV) > 0 || d.SOA.Name != "" || len(d.CAA) > 0 } // JSON returns the object as json string @@ -635,7 +650,6 @@ func (d *DNSData) dedupe() { d.MX = sliceutil.Dedupe(d.MX) d.PTR = sliceutil.Dedupe(d.PTR) d.ANY = sliceutil.Dedupe(d.ANY) - d.SOA = sliceutil.Dedupe(d.SOA) d.NS = sliceutil.Dedupe(d.NS) d.TXT = sliceutil.Dedupe(d.TXT) d.SRV = sliceutil.Dedupe(d.SRV) From abcbbd727d3cd663abf7c3f17b18c79fc542a941 Mon Sep 17 00:00:00 2001 From: hach Date: Thu, 18 May 2023 10:43:27 +0200 Subject: [PATCH 2/2] support multiple SOA response + add SOA test --- client.go | 8 ++++---- client_test.go | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index 318a0ab..beaeaab 100644 --- a/client.go +++ b/client.go @@ -530,7 +530,7 @@ type DNSData struct { MX []string `json:"mx,omitempty"` PTR []string `json:"ptr,omitempty"` ANY []string `json:"any,omitempty"` - SOA SOA `json:"soa,omitempty"` + SOA []SOA `json:"soa,omitempty"` NS []string `json:"ns,omitempty"` TXT []string `json:"txt,omitempty"` SRV []string `json:"srv,omitempty"` @@ -578,14 +578,14 @@ func (d *DNSData) ParseFromRR(rrs []dns.RR) error { case *dns.CNAME: d.CNAME = append(d.CNAME, trimChars(recordType.Target)) case *dns.SOA: - d.SOA = SOA{ + d.SOA = append(d.SOA, SOA{ Name: recordType.Hdr.Name, Serial: recordType.Serial, Refresh: recordType.Refresh, Retry: recordType.Retry, Expire: recordType.Expire, Minttl: recordType.Minttl, - } + }) case *dns.PTR: d.PTR = append(d.PTR, trimChars(recordType.Ptr)) case *dns.MX: @@ -629,7 +629,7 @@ func (d *DNSData) ParseFromEnvelopeChan(envChan chan *dns.Envelope) error { } func (d *DNSData) contains() bool { - return len(d.A) > 0 || len(d.AAAA) > 0 || len(d.CNAME) > 0 || len(d.MX) > 0 || len(d.NS) > 0 || len(d.PTR) > 0 || len(d.ANY) > 0 || len(d.TXT) > 0 || len(d.SRV) > 0 || d.SOA.Name != "" || len(d.CAA) > 0 + return len(d.A) > 0 || len(d.AAAA) > 0 || len(d.CNAME) > 0 || len(d.MX) > 0 || len(d.NS) > 0 || len(d.PTR) > 0 || len(d.ANY) > 0 || len(d.TXT) > 0 || len(d.SRV) > 0 || len(d.SOA) > 0 || len(d.CAA) > 0 } // JSON returns the object as json string diff --git a/client_test.go b/client_test.go index 976a7cb..6c8fd20 100644 --- a/client_test.go +++ b/client_test.go @@ -66,12 +66,18 @@ func TestDOT(t *testing.T) { func TestQueryMultiple(t *testing.T) { client, _ := New([]string{"8.8.8.8:53", "1.1.1.1:53"}, 5) - d, err := client.QueryMultiple("example.com", []uint16{dns.TypeA, dns.TypeAAAA}) + // Test various query types + d, err := client.QueryMultiple("scanme.sh", []uint16{ + dns.TypeA, + dns.TypeAAAA, + dns.TypeSOA, + }) require.Nil(t, err) // From current dig result require.True(t, len(d.A) > 0) require.True(t, len(d.AAAA) > 0) + require.True(t, len(d.SOA) > 0) require.NotZero(t, d.TTL) }