Fixed golint issues

This commit is contained in:
Víctor Zamanillo 2020-09-25 18:30:38 +02:00
parent bdc394abea
commit d184548c29
7 changed files with 47 additions and 41 deletions

View File

@ -38,7 +38,7 @@ func main() {
httpxOptions.RetryMax = options.Retries
httpxOptions.FollowRedirects = options.FollowRedirects
httpxOptions.FollowHostRedirects = options.FollowHostRedirects
httpxOptions.HttpProxy = options.HttpProxy
httpxOptions.HTTPProxy = options.HTTPProxy
httpxOptions.Unsafe = options.Unsafe
httpxOptions.RequestOverride = httpx.RequestOverride{URIPath: options.RequestURI}
@ -110,8 +110,8 @@ func main() {
scanopts.OutputWithNoColor = options.NoColor
scanopts.ResponseInStdout = options.responseInStdout
scanopts.OutputWebSocket = options.OutputWebSocket
scanopts.TlsProbe = options.TLSProbe
scanopts.CspProbe = options.CSPProbe
scanopts.TLSProbe = options.TLSProbe
scanopts.CSPProbe = options.CSPProbe
if options.RequestURI != "" {
scanopts.RequestURI = options.RequestURI
}
@ -235,18 +235,18 @@ func process(t string, wg *sizedwaitgroup.SizedWaitGroup, hp *httpx.HTTPX, proto
defer wg.Done()
r := analyze(hp, protocol, target, 0, method, &scanopts)
output <- r
if scanopts.TlsProbe && r.TlsData != nil {
scanopts.TlsProbe = false
for _, tt := range r.TlsData.DNSNames {
if scanopts.TLSProbe && r.TLSData != nil {
scanopts.TLSProbe = false
for _, tt := range r.TLSData.DNSNames {
process(tt, wg, hp, protocol, scanopts, output)
}
for _, tt := range r.TlsData.CommonName {
for _, tt := range r.TLSData.CommonName {
process(tt, wg, hp, protocol, scanopts, output)
}
}
if scanopts.CspProbe && r.CspData != nil {
scanopts.CspProbe = false
for _, tt := range r.CspData.Domains {
if scanopts.CSPProbe && r.CSPData != nil {
scanopts.CSPProbe = false
for _, tt := range r.CSPData.Domains {
process(tt, wg, hp, protocol, scanopts, output)
}
}
@ -267,12 +267,12 @@ func process(t string, wg *sizedwaitgroup.SizedWaitGroup, hp *httpx.HTTPX, proto
defer wg.Done()
r := analyze(hp, protocol, target, port, method, &scanopts)
output <- r
if scanopts.TlsProbe && r.TlsData != nil {
scanopts.TlsProbe = false
for _, tt := range r.TlsData.DNSNames {
if scanopts.TLSProbe && r.TLSData != nil {
scanopts.TLSProbe = false
for _, tt := range r.TLSData.DNSNames {
process(tt, wg, hp, protocol, scanopts, output)
}
for _, tt := range r.TlsData.CommonName {
for _, tt := range r.TLSData.CommonName {
process(tt, wg, hp, protocol, scanopts, output)
}
}
@ -326,8 +326,8 @@ type scanOptions struct {
OutputWithNoColor bool
OutputMethod bool
ResponseInStdout bool
TlsProbe bool
CspProbe bool
TLSProbe bool
CSPProbe bool
RequestURI string
OutputContentType bool
RequestBody string
@ -562,8 +562,8 @@ retry:
WebServer: serverHeader,
Response: serverResponseRaw,
WebSocket: isWebSocket,
TlsData: resp.TlsData,
CspData: resp.CspData,
TLSData: resp.TLSData,
CSPData: resp.CSPData,
Pipeline: pipeline,
HTTP2: http2,
Method: method,
@ -589,8 +589,8 @@ type Result struct {
Response string `json:"serverResponse,omitempty"`
WebSocket bool `json:"websocket,omitempty"`
ContentType string `json:"content-type,omitempty"`
TlsData *httpx.TlsData `json:"tls,omitempty"`
CspData *httpx.CspData `json:"csp,omitempty"`
TLSData *httpx.TLSData `json:"tls,omitempty"`
CSPData *httpx.CSPData `json:"csp,omitempty"`
Pipeline bool `json:"pipeline,omitempty"`
HTTP2 bool `json:"http2"`
Method string `json:"method"`
@ -626,7 +626,7 @@ type Options struct {
FollowRedirects bool
StoreResponse bool
StoreResponseDir string
HttpProxy string
HTTPProxy string
SocksProxy string
JSONOutput bool
InputFile string
@ -689,7 +689,7 @@ func ParseOptions() *Options {
flag.StringVar(&options.StoreResponseDir, "srd", "output", "Save response directory")
flag.BoolVar(&options.FollowRedirects, "follow-redirects", false, "Follow Redirects")
flag.BoolVar(&options.FollowHostRedirects, "follow-host-redirects", false, "Only follow redirects on the same host")
flag.StringVar(&options.HttpProxy, "http-proxy", "", "HTTP Proxy, eg http://127.0.0.1:8080")
flag.StringVar(&options.HTTPProxy, "http-proxy", "", "HTTP Proxy, eg http://127.0.0.1:8080")
flag.BoolVar(&options.JSONOutput, "json", false, "JSON Output")
flag.StringVar(&options.InputFile, "l", "", "File containing domains")
flag.StringVar(&options.Methods, "x", "", "Request Methods, use ALL to check all verbs ()")
@ -794,9 +794,9 @@ func (options *Options) configureOutput() {
const banner = `
__ __ __ _ __
/ /_ / /_/ /_____ | |/ /
/ __ \/ __/ __/ __ \| /
/ / / / /_/ /_/ /_/ / |
/_/ /_/\__/\__/ .___/_/|_|
/ __ \/ __/ __/ __ \| /
/ / / / /_/ /_/ /_/ / |
/_/ /_/\__/\__/ .___/_/|_|
/_/ v1.0.2
`

View File

@ -13,6 +13,7 @@ const (
MethodTrace = "TRACE" // RFC 7231, 4.3.8
)
// AllHTTPMethods contains all available HTTP methods
func AllHTTPMethods() []string {
return []string{
MethodGet,

View File

@ -15,11 +15,13 @@ var CSPHeaders []string = []string{
"X-Webkit-Csp-Report-Only", // non - standard
}
type CspData struct {
// CSPData contains the Content-Security-Policy domain list
type CSPData struct {
Domains []string `json:"domains,omitempty"`
}
func (h *HTTPX) CspGrab(r *http.Response) *CspData {
// CSPGrab fills the CSPData
func (h *HTTPX) CSPGrab(r *http.Response) *CSPData {
domains := make(map[string]struct{})
for _, cspHeader := range CSPHeaders {
cspRaw := r.Header.Get(cspHeader)
@ -39,7 +41,7 @@ func (h *HTTPX) CspGrab(r *http.Response) *CspData {
}
if len(domains) > 0 {
return &CspData{Domains: slice.ToSlice(domains)}
return &CSPData{Domains: slice.ToSlice(domains)}
}
return nil
}

View File

@ -35,7 +35,7 @@ func New(options *Options) (*HTTPX, error) {
httpx := &HTTPX{}
dialer, err := cache.NewDialer(cache.DefaultOptions)
if err != nil {
return nil, fmt.Errorf("Could not create resolver cache: %s", err)
return nil, fmt.Errorf("could not create resolver cache: %s", err)
}
httpx.Options = options
@ -76,8 +76,8 @@ func New(options *Options) (*HTTPX, error) {
DisableKeepAlives: true,
}
if httpx.Options.HttpProxy != "" {
proxyURL, parseErr := url.Parse(httpx.Options.HttpProxy)
if httpx.Options.HTTPProxy != "" {
proxyURL, parseErr := url.Parse(httpx.Options.HTTPProxy)
if parseErr != nil {
return nil, parseErr
}
@ -105,7 +105,7 @@ func New(options *Options) (*HTTPX, error) {
httpx.RequestOverride = &options.RequestOverride
httpx.cdn, err = cdncheck.New()
if err != nil {
return nil, fmt.Errorf("Could not create cdn check: %s", err)
return nil, fmt.Errorf("could not create cdn check: %s", err)
}
return httpx, nil
@ -165,14 +165,15 @@ func (h *HTTPX) Do(req *retryablehttp.Request) (*Response, error) {
if !h.Options.Unsafe {
// extracts TLS data if any
resp.TlsData = h.TlsGrab(httpresp)
resp.TLSData = h.TLSGrab(httpresp)
}
resp.CspData = h.CspGrab(httpresp)
resp.CSPData = h.CSPGrab(httpresp)
return &resp, nil
}
// RequestOverride contains the URI path to override the request
type RequestOverride struct {
URIPath string
}

View File

@ -19,7 +19,7 @@ type Options struct {
Unsafe bool
RequestOverride RequestOverride
HttpProxy string
HTTPProxy string
SocksProxy string
// VHOSTs options

View File

@ -13,9 +13,9 @@ type Response struct {
Raw string
Words int
Lines int
TlsData *TlsData
CspData *CspData
Http2 bool
TLSData *TLSData
CSPData *CSPData
HTTP2 bool
Pipeline bool
}

View File

@ -4,7 +4,8 @@ import (
"net/http"
)
type TlsData struct {
// TLSData contains the relevant Transport Layer Security information
type TLSData struct {
DNSNames []string `json:"dns_names,omitempty"`
Emails []string `json:"emails,omitempty"`
CommonName []string `json:"common_name,omitempty"`
@ -13,9 +14,10 @@ type TlsData struct {
IssuerOrg []string `json:"issuer_organization,omitempty"`
}
func (h *HTTPX) TlsGrab(r *http.Response) *TlsData {
// TLSGrab fills the TLSData
func (h *HTTPX) TLSGrab(r *http.Response) *TLSData {
if r.TLS != nil {
var tlsdata TlsData
var tlsdata TLSData
for _, certificate := range r.TLS.PeerCertificates {
tlsdata.DNSNames = append(tlsdata.DNSNames, certificate.DNSNames...)
tlsdata.Emails = append(tlsdata.Emails, certificate.EmailAddresses...)