making cdn check optional

This commit is contained in:
Mzack9999 2020-10-02 22:39:37 +02:00
parent f4d155f927
commit d4e72d805b
4 changed files with 20 additions and 11 deletions

View File

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

View File

@ -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)))
}

View File

@ -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

View File

@ -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
}