Skip to content

Commit

Permalink
limit cname recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Sep 2, 2024
1 parent f95dad8 commit 509afcb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
sliceutil "github.com/projectdiscovery/utils/slice"
)

var (
DefaultMaxPerCNAMEFollows = 32
)

var internalRangeCheckerInstance *internalRangeChecker

func init() {
Expand Down Expand Up @@ -62,6 +66,10 @@ func NewWithOptions(options Options) (*Client, error) {
knownHosts, _ = hostsfile.ParseDefault()
}

if options.MaxPerCNAMEFollows == 0 {
options.MaxPerCNAMEFollows = DefaultMaxPerCNAMEFollows
}

httpClient := doh.NewHttpClientWithTimeout(options.Timeout)

client := Client{
Expand Down Expand Up @@ -472,6 +480,7 @@ func (c *Client) Trace(host string, requestType uint16, maxrecursion int) (*Trac
msg.SetQuestion(host, requestType)
servers := RootDNSServersIPv4
seenNS := make(map[string]struct{})
seenCName := make(map[string]int)
for i := 1; i < maxrecursion; i++ {
msg.SetQuestion(host, requestType)
dnsdatas, err := c.QueryParallel(host, requestType, servers)
Expand Down Expand Up @@ -534,6 +543,10 @@ func (c *Client) Trace(host string, requestType uint16, maxrecursion int) (*Trac

// follow cname if any
if nextCname != "" {
seenCName[nextCname]++
if seenCName[nextCname] > c.options.MaxPerCNAMEFollows {
break
}
host = nextCname
}
}
Expand Down
1 change: 1 addition & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Options struct {
LocalAddrIP net.IP
LocalAddrPort uint16
ConnectionPoolThreads int
MaxPerCNAMEFollows int
}

// Returns a net.Addr of a UDP or TCP type depending on whats required
Expand Down

0 comments on commit 509afcb

Please sign in to comment.