Skip to content

Commit

Permalink
making cdn check optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Oct 2, 2020
1 parent f4d155f commit d4e72d8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
7 changes: 4 additions & 3 deletions cmd/httpx/httpx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]")
}

Expand Down Expand Up @@ -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"`
}

Expand Down
13 changes: 9 additions & 4 deletions common/httpx/cdn.go
Original file line number Diff line number Diff line change
@@ -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)))
}
8 changes: 5 additions & 3 deletions common/httpx/httpx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion common/httpx/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,6 +36,7 @@ var DefaultOptions = Options{
Timeout: 30 * time.Second,
RetryMax: 5,
Unsafe: false,
CdnCheck: true,
// VHOSTs options
VHostIgnoreStatusCode: false,
VHostIgnoreContentLength: true,
Expand All @@ -43,5 +45,4 @@ var DefaultOptions = Options{
VHostStripHTML: false,
VHostSimilarityRatio: 85,
DefaultUserAgent: "httpx - Open-source project (github.com/projectdiscovery/httpx)",
// Smuggling Options
}

0 comments on commit d4e72d8

Please sign in to comment.