Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added dnsx
Binary file not shown.
20 changes: 19 additions & 1 deletion internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,25 @@ func (r *Runner) worker() {
}
// add flags for cdn
if r.options.OutputCDN {
dnsData.IsCDNIP, dnsData.CDNName, _ = r.dnsx.CdnCheck(domain)
if len(dnsData.A) > 0 || len(dnsData.AAAA) > 0 || len(dnsData.CNAME) > 0 {
// reuse existing DNS response to avoid redundant lookups and ensure
// consistency between reported records and CDN detection
var cdnErr error
dnsData.IsCDNIP, dnsData.CDNName, dnsData.CDNType, cdnErr = r.dnsx.CdnCheckRespData(dnsData.DNSData)
if cdnErr != nil {
gologger.Debug().Msgf("cdn check failed for %s: %v", domain, cdnErr)
}
} else {
// fall back to a fresh lookup when the response lacks A/AAAA/CNAME records
var cdnErr error
dnsData.IsCDNIP, dnsData.CDNName, cdnErr = r.dnsx.CdnCheck(domain)
if cdnErr != nil {
gologger.Debug().Msgf("cdn check failed for %s: %v", domain, cdnErr)
}
if dnsData.IsCDNIP {
dnsData.CDNType = "cdn"
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
if r.options.ASN {
results := []*asnmap.Response{}
Expand Down
13 changes: 11 additions & 2 deletions libs/dnsx/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net"

retryabledns "github.com/projectdiscovery/retryabledns"
iputil "github.com/projectdiscovery/utils/ip"
)

Expand All @@ -18,7 +19,6 @@ func (d *DNSX) CdnCheck(domain string) (bool, string, error) {
return false, "", err
}
ipv4Ips := []net.IP{}
// filter ipv4s for ips
for _, ip := range ips {
if iputil.IsIPv4(ip) {
ipv4Ips = append(ipv4Ips, ip)
Expand All @@ -31,5 +31,14 @@ func (d *DNSX) CdnCheck(domain string) (bool, string, error) {
if !iputil.IsIP(ipAddr) {
return false, "", fmt.Errorf("%s is not a valid ip", ipAddr)
}
return d.cdn.CheckCDN(net.ParseIP((ipAddr)))
return d.cdn.CheckCDN(net.ParseIP(ipAddr))
}

// CdnCheckRespData verifies if the given DNS response data is part of known CDN/WAF/Cloud ranges,
// avoiding additional DNS lookups by reusing already-resolved data.
func (d *DNSX) CdnCheckRespData(dnsdata *retryabledns.DNSData) (matched bool, value string, itemType string, err error) {
if d.cdn == nil {
return false, "", "", errors.New("cdn client not initialized")
}
return d.cdn.CheckDNSResponse(dnsdata)
}
1 change: 1 addition & 0 deletions libs/dnsx/dnsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type ResponseData struct {
*retryabledns.DNSData
IsCDNIP bool `json:"cdn,omitempty" csv:"cdn"`
CDNName string `json:"cdn-name,omitempty" csv:"cdn-name"`
CDNType string `json:"cdn-type,omitempty" csv:"cdn-type"`
ASN *AsnResponse `json:"asn,omitempty" csv:"asn"`
}
type AsnResponse struct {
Expand Down
Loading