diff --git a/cmd/httpx/httpx.go b/cmd/httpx/httpx.go index b59e7c0d..26b99592 100644 --- a/cmd/httpx/httpx.go +++ b/cmd/httpx/httpx.go @@ -47,6 +47,7 @@ func main() { httpxOptions.HTTPProxy = options.HTTPProxy httpxOptions.Unsafe = options.Unsafe httpxOptions.RequestOverride = httpx.RequestOverride{URIPath: options.RequestURI} + httpxOptions.CdnCheck = options.OutputCDN var key, value string httpxOptions.CustomHeaders = make(map[string]string) @@ -542,8 +543,8 @@ retry: builder.WriteString(fmt.Sprintf(" [%s]", cnames[0])) } - isCDN := hp.CdnCheck(ip) - if scanopts.OutputCDN && isCDN { + isCDN, err := hp.CdnCheck(ip) + if scanopts.OutputCDN && isCDN && err == nil { builder.WriteString(" [cdn]") } @@ -621,7 +622,7 @@ type Result struct { WebSocket bool `json:"websocket,omitempty"` Pipeline bool `json:"pipeline,omitempty"` HTTP2 bool `json:"http2"` - CDN bool `json:"cdn"` + CDN bool `json:"cdn,omitempty"` Duration time.Duration `json:"duration"` } diff --git a/common/httpx/cdn.go b/common/httpx/cdn.go index 942fee03..7bbf276c 100644 --- a/common/httpx/cdn.go +++ b/common/httpx/cdn.go @@ -1,10 +1,15 @@ package httpx -import "net" +import ( + "fmt" + "net" +) // CdnCheck verifies if the given ip is part of Cdn ranges -func (h *HTTPX) CdnCheck(ip string) bool { - ok, err := h.cdn.Check(net.ParseIP((ip))) +func (h *HTTPX) CdnCheck(ip string) (bool, error) { + if h.cdn == nil { + return false, fmt.Errorf("cdn client not configured") + } - return ok && err == nil + return h.cdn.Check(net.ParseIP((ip))) } diff --git a/common/httpx/httpx.go b/common/httpx/httpx.go index bf4729d8..eb884f92 100644 --- a/common/httpx/httpx.go +++ b/common/httpx/httpx.go @@ -103,9 +103,11 @@ func New(options *Options) (*HTTPX, error) { httpx.htmlPolicy = bluemonday.NewPolicy() httpx.CustomHeaders = httpx.Options.CustomHeaders httpx.RequestOverride = &options.RequestOverride - httpx.cdn, err = cdncheck.New() - if err != nil { - return nil, fmt.Errorf("could not create cdn check: %s", err) + if options.CdnCheck { + httpx.cdn, err = cdncheck.New() + if err != nil { + return nil, fmt.Errorf("could not create cdn check: %s", err) + } } return httpx, nil diff --git a/common/httpx/option.go b/common/httpx/option.go index c7bb2d8b..256b1214 100644 --- a/common/httpx/option.go +++ b/common/httpx/option.go @@ -11,6 +11,7 @@ type Options struct { HTTPProxy string SocksProxy string Threads int + CdnCheck bool // Timeout is the maximum time to wait for the request Timeout time.Duration // RetryMax is the maximum number of retries @@ -35,6 +36,7 @@ var DefaultOptions = Options{ Timeout: 30 * time.Second, RetryMax: 5, Unsafe: false, + CdnCheck: true, // VHOSTs options VHostIgnoreStatusCode: false, VHostIgnoreContentLength: true, @@ -43,5 +45,4 @@ var DefaultOptions = Options{ VHostStripHTML: false, VHostSimilarityRatio: 85, DefaultUserAgent: "httpx - Open-source project (github.com/projectdiscovery/httpx)", - // Smuggling Options }