Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cdn check with domain and with dns response #377

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
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.
4 changes: 3 additions & 1 deletion internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,9 @@ func (r *Runner) worker() {
}
// add flags for cdn
if r.options.OutputCDN {
dnsData.IsCDNIP, dnsData.CDNName, _ = r.dnsx.CdnCheck(domain)
// dnsData.IsCDNIP, dnsData.CDNName, _, _ = r.dnsx.CdnCheck(domain)
// prevent new dns requests
dnsData.IsCDNIP, dnsData.CDNName, _, _ = r.dnsx.CdnCheckRespData(dnsData.DNSData)
}
if r.options.ASN {
results := []*asnmap.Response{}
Expand Down
37 changes: 17 additions & 20 deletions libs/dnsx/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,29 @@ package dnsx
import (
"net"

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

// CdnCheck verifies if the given ip is part of Cdn ranges
func (d *DNSX) CdnCheck(domain string) (bool, string, error) {
// CdnCheck verifies if the given domain/ip is part of Cdn/Waf/Cloud ranges
func (d *DNSX) CdnCheck(input string) (matched bool, value string, itemType string, err error) {
if d.cdn == nil {
return false, "", errorutil.New("cdn client not initialized")
return false, "", "", errorutil.New("cdn client not initialized")
}
ips, err := net.LookupIP(domain)
if err != nil {
return false, "", err
if iputil.IsIP(input) {
ipAddr := net.ParseIP(input)
matched, value, itemType, err = d.cdn.Check(ipAddr)
return
}
ipv4Ips := []net.IP{}
// filter ipv4s for ips
for _, ip := range ips {
if iputil.IsIPv4(ip) {
ipv4Ips = append(ipv4Ips, ip)
}
}
if len(ipv4Ips) < 1 {
return false, "", errorutil.New("No IPV4s found in lookup for %v", domain)
}
ipAddr := ipv4Ips[0].String()
if !iputil.IsIP(ipAddr) {
return false, "", errorutil.New("%s is not a valid ip", ipAddr)

return d.cdn.CheckDomainWithFallback(input)
}

// CdnCheck verifies if the given dnsResponse is part of Cdn/Waf/Cloud ranges
func (d *DNSX) CdnCheckRespData(dnsdata *retryabledns.DNSData) (matched bool, value string, itemType string, err error) {
if d.cdn == nil {
return false, "", "", errorutil.New("cdn client not initialized")
}
return d.cdn.CheckCDN(net.ParseIP((ipAddr)))
return d.cdn.CheckDNSResponse(dnsdata)
}
Loading