Skip to content

Commit

Permalink
Fill the DNSData.ANY (#137)
Browse files Browse the repository at this point in the history
* Fill the DNSDATA.ANY

* Add GetSOARecords fuction for DNSData.

- This getSOA records are used the in nuclei, dnsx
  • Loading branch information
ShubhamRasal authored Jun 7, 2023
1 parent 56277a1 commit ea74349
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ func (c *Client) queryMultiple(host string, requestTypes []uint16, resolver Reso
}
msg.Question[0] = question
}
// If the request type is dns.TypeANY, set the 'AnyQuery' flag in dnsdata to true.
// This indicates that the dnsdata supports storing DNSDATA.ANY queries and the associated responses.
if requestType == dns.TypeANY {
dnsdata.AnyQuery = true
}

var (
resp *dns.Msg
Expand Down Expand Up @@ -564,10 +569,12 @@ type DNSData struct {
RawResp *dns.Msg `json:"raw_resp,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
HostsFile bool `json:"hosts_file,omitempty"`
AnyQuery bool `json:"-"`
}

type SOA struct {
Name string `json:"name,omitempty"`
NS string `json:"ns,omitempty"`
Mbox string `json:"mailbox,omitempty"`
Serial uint32 `json:"serial,omitempty"`
Refresh uint32 `json:"refresh,omitempty"`
Retry uint32 `json:"retry,omitempty"`
Expand Down Expand Up @@ -597,13 +604,15 @@ func (d *DNSData) ParseFromRR(rrs []dns.RR) error {
d.CNAME = append(d.CNAME, trimChars(recordType.Target))
case *dns.SOA:
d.SOA = append(d.SOA, SOA{
Name: recordType.Hdr.Name,
NS: recordType.Ns,
Mbox: recordType.Mbox,
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:
Expand All @@ -625,6 +634,9 @@ func (d *DNSData) ParseFromRR(rrs []dns.RR) error {
}
d.AllRecords = append(d.AllRecords, record.String())
}
if d.AnyQuery {
d.ANY = sliceutil.Merge(d.A, d.NS, d.AAAA, d.SRV, d.TXT, d.CAA, d.MX, d.PTR, d.CNAME, d.GetSOARecords())
}
return nil
}

Expand Down Expand Up @@ -702,3 +714,12 @@ type AXFRData struct {
Host string `json:"host,omitempty"`
DNSData []*DNSData `json:"chain,omitempty"`
}

// GetSOARecords returns the NS and Mbox of all SOA records as a string slice
func (d *DNSData) GetSOARecords() []string {
var soaRecords []string
for _, soa := range d.SOA {
soaRecords = append(soaRecords, soa.NS, soa.Mbox)
}
return soaRecords
}

0 comments on commit ea74349

Please sign in to comment.