Fixed gocritic issues

This commit is contained in:
Víctor Zamanillo 2020-09-25 18:39:35 +02:00
parent d184548c29
commit c1df31cb49
8 changed files with 26 additions and 25 deletions

View File

@ -90,7 +90,7 @@ func main() {
rawhttp.AutomaticHostHeader(false)
}
}
if strings.ToLower(options.Methods) == "all" {
if strings.EqualFold(options.Methods, "all") {
scanopts.Methods = httputilz.AllHTTPMethods()
} else if options.Methods != "" {
scanopts.Methods = append(scanopts.Methods, stringz.SplitByCharAndTrimSpace(options.Methods, ",")...)
@ -214,7 +214,7 @@ func main() {
}
for sc.Scan() {
process(sc.Text(), &wg, hp, protocol, scanopts, output)
process(sc.Text(), &wg, hp, protocol, &scanopts, output)
}
wg.Wait()
@ -225,7 +225,7 @@ func main() {
}
func process(t string, wg *sizedwaitgroup.SizedWaitGroup, hp *httpx.HTTPX, protocol string, scanopts scanOptions, output chan Result) {
func process(t string, wg *sizedwaitgroup.SizedWaitGroup, hp *httpx.HTTPX, protocol string, scanopts *scanOptions, output chan Result) {
for target := range targets(stringz.TrimProtocol(t)) {
// if no custom ports specified then test the default ones
if len(customport.Ports) == 0 {
@ -233,7 +233,7 @@ func process(t string, wg *sizedwaitgroup.SizedWaitGroup, hp *httpx.HTTPX, proto
wg.Add()
go func(target, method string) {
defer wg.Done()
r := analyze(hp, protocol, target, 0, method, &scanopts)
r := analyze(hp, protocol, target, 0, method, scanopts)
output <- r
if scanopts.TLSProbe && r.TLSData != nil {
scanopts.TLSProbe = false
@ -265,7 +265,7 @@ func process(t string, wg *sizedwaitgroup.SizedWaitGroup, hp *httpx.HTTPX, proto
wg.Add()
go func(port int, method string) {
defer wg.Done()
r := analyze(hp, protocol, target, port, method, &scanopts)
r := analyze(hp, protocol, target, port, method, scanopts)
output <- r
if scanopts.TLSProbe && r.TLSData != nil {
scanopts.TLSProbe = false
@ -339,7 +339,7 @@ type scanOptions struct {
OutputCDN bool
}
func analyze(hp *httpx.HTTPX, protocol string, domain string, port int, method string, scanopts *scanOptions) Result {
func analyze(hp *httpx.HTTPX, protocol, domain string, port int, method string, scanopts *scanOptions) Result {
retried := false
retry:
URL := fmt.Sprintf("%s://%s", protocol, domain)
@ -541,7 +541,8 @@ retry:
// leaving last 4 bytes free to append ".txt"
domainFile = domainFile[:251]
}
domainFile = strings.Replace(domainFile, "/", "_", -1) + ".txt"
domainFile = strings.ReplaceAll(domainFile, "/", "_") + ".txt"
responsePath := path.Join(scanopts.StoreResponseDirectory, domainFile)
err := ioutil.WriteFile(responsePath, []byte(resp.Raw), 0644)
if err != nil {

View File

@ -35,7 +35,7 @@ func DumpResponse(resp *http.Response) (string, error) {
}
// ParseRequest from raw string
func ParseRequest(req string) (method string, path string, headers map[string]string, body string, err error) {
func ParseRequest(req string) (method, path string, headers map[string]string, body string, err error) {
headers = make(map[string]string)
reader := bufio.NewReader(strings.NewReader(req))
s, err := reader.ReadString('\n')

View File

@ -9,8 +9,8 @@ import (
// CSPHeaders is an incomplete list of most common CSP headers
var CSPHeaders []string = []string{
"Content-Security-Policy", //standard
"Content-Security-Policy-Report-Only", //standard
"Content-Security-Policy", // standard
"Content-Security-Policy-Report-Only", // standard
"X-Content-Security-Policy-Report-Only", // non - standard
"X-Webkit-Csp-Report-Only", // non - standard
}

View File

@ -11,7 +11,7 @@ import (
// Credits: https://gist.github.com/zhangbaohe/c691e1da5bbdc7f41ca5
//convert GBK to UTF-8
// Decodegbk converts GBK to UTF-8
func Decodegbk(s []byte) ([]byte, error) {
I := bytes.NewReader(s)
O := transform.NewReader(I, simplifiedchinese.GBK.NewDecoder())
@ -22,7 +22,7 @@ func Decodegbk(s []byte) ([]byte, error) {
return d, nil
}
//convert BIG5 to UTF-8
// Decodebig5 converts BIG5 to UTF-8
func Decodebig5(s []byte) ([]byte, error) {
I := bytes.NewReader(s)
O := transform.NewReader(I, traditionalchinese.Big5.NewDecoder())
@ -33,7 +33,7 @@ func Decodebig5(s []byte) ([]byte, error) {
return d, nil
}
//convert UTF-8 to BIG5
// Encodebig5 converts UTF-8 to BIG5
func Encodebig5(s []byte) ([]byte, error) {
I := bytes.NewReader(s)
O := transform.NewReader(I, traditionalchinese.Big5.NewEncoder())

View File

@ -9,10 +9,10 @@ import (
)
// SupportHTTP2 checks if the target host supports HTTP2
func (h *HTTPX) SupportHTTP2(protocol, method, URL string) bool {
func (h *HTTPX) SupportHTTP2(protocol, method, targetURL string) bool {
// http => supports HTTP1.1 => HTTP/2 (H2C)
if protocol == "http" {
req, err := retryablehttp.NewRequest(method, URL, nil)
req, err := retryablehttp.NewRequest(method, targetURL, nil)
if err != nil {
return false
}
@ -30,7 +30,7 @@ func (h *HTTPX) SupportHTTP2(protocol, method, URL string) bool {
}
// attempts a direct http2 connection
req, err := http.NewRequest(method, URL, nil)
req, err := http.NewRequest(method, targetURL, nil)
if err != nil {
return false
}

View File

@ -182,9 +182,9 @@ type RequestOverride struct {
func (h *HTTPX) doUnsafe(req *retryablehttp.Request) (*http.Response, error) {
method := req.Method
headers := req.Header
url := req.URL.String()
targetURL := req.URL.String()
body := req.Body
return rawhttp.DoRaw(method, url, h.RequestOverride.URIPath, headers, body)
return rawhttp.DoRaw(method, targetURL, h.RequestOverride.URIPath, headers, body)
}
// Verify the http calls and apply-cascade all the filters, as soon as one matches it returns true
@ -214,8 +214,8 @@ func (h *HTTPX) AddFilter(f Filter) {
}
// NewRequest from url
func (h *HTTPX) NewRequest(method, URL string) (req *retryablehttp.Request, err error) {
req, err = retryablehttp.NewRequest(method, URL, nil)
func (h *HTTPX) NewRequest(method, targetURL string) (req *retryablehttp.Request, err error) {
req, err = retryablehttp.NewRequest(method, targetURL, nil)
if err != nil {
return
}
@ -232,7 +232,7 @@ func (h *HTTPX) SetCustomHeaders(r *retryablehttp.Request, headers map[string]st
for name, value := range headers {
r.Header.Set(name, value)
// host header is particular
if strings.ToLower(name) == "host" {
if strings.EqualFold(name, "host") {
r.Host = value
}
}

View File

@ -30,7 +30,7 @@ func (r *Response) GetHeader(name string) string {
}
// GetHeaderPart with offset
func (r *Response) GetHeaderPart(name string, sep string) string {
func (r *Response) GetHeaderPart(name, sep string) string {
v, ok := r.Headers[name]
if ok && len(v) > 0 {
tokens := strings.Split(strings.Join(v, " "), sep)

View File

@ -5,8 +5,8 @@ import (
"strings"
)
func TrimProtocol(URL string) string {
URL = strings.TrimSpace(URL)
func TrimProtocol(targetURL string) string {
URL := strings.TrimSpace(targetURL)
if strings.HasPrefix(strings.ToLower(URL), "http://") || strings.HasPrefix(strings.ToLower(URL), "https://") {
URL = URL[strings.Index(URL, "//")+2:]
}
@ -32,7 +32,7 @@ func StringToSliceInt(s string) ([]int, error) {
return r, nil
}
func SplitByCharAndTrimSpace(s string, splitchar string) (result []string) {
func SplitByCharAndTrimSpace(s, splitchar string) (result []string) {
for _, token := range strings.Split(s, splitchar) {
result = append(result, strings.TrimSpace(token))
}