diff --git a/cli/cmd/dns.go b/cli/cmd/dns.go index ceec9ec5..912d0157 100644 --- a/cli/cmd/dns.go +++ b/cli/cmd/dns.go @@ -1,6 +1,7 @@ package cmd import ( + "errors" "fmt" "log" "runtime" @@ -26,8 +27,9 @@ func runDNS(cmd *cobra.Command, args []string) error { } if err := cli.Gobuster(mainContext, globalopts, plugin); err != nil { - if goberr, ok := err.(*gobusterdns.ErrWildcard); ok { - return fmt.Errorf("%s. To force processing of Wildcard DNS, specify the '--wildcard' switch", goberr.Error()) + var wErr *gobusterdns.ErrWildcard + if errors.As(err, &wErr) { + return fmt.Errorf("%w. To force processing of Wildcard DNS, specify the '--wildcard' switch", wErr) } return fmt.Errorf("error on running gobuster: %w", err) } diff --git a/cli/cmd/fuzz.go b/cli/cmd/fuzz.go index 67223352..64c43b96 100644 --- a/cli/cmd/fuzz.go +++ b/cli/cmd/fuzz.go @@ -1,6 +1,7 @@ package cmd import ( + "errors" "fmt" "log" @@ -25,8 +26,9 @@ func runFuzz(cmd *cobra.Command, args []string) error { } if err := cli.Gobuster(mainContext, globalopts, plugin); err != nil { - if goberr, ok := err.(*gobusterfuzz.ErrWildcard); ok { - return fmt.Errorf("%s. To force processing of Wildcard responses, specify the '--wildcard' switch", goberr.Error()) + var wErr *gobusterfuzz.ErrWildcard + if errors.As(err, &wErr) { + return fmt.Errorf("%w. To force processing of Wildcard responses, specify the '--wildcard' switch", wErr) } return fmt.Errorf("error on running gobuster: %w", err) } diff --git a/cli/cmd/http.go b/cli/cmd/http.go index ba7eaeaf..6d99911a 100644 --- a/cli/cmd/http.go +++ b/cli/cmd/http.go @@ -11,7 +11,7 @@ import ( "github.com/OJ/gobuster/v3/helper" "github.com/OJ/gobuster/v3/libgobuster" "github.com/spf13/cobra" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" ) func addBasicHTTPOptions(cmd *cobra.Command) { @@ -161,7 +161,7 @@ func parseCommonHTTPOptions(cmd *cobra.Command) (libgobuster.HTTPOptions, error) if options.Username != "" && options.Password == "" { fmt.Printf("[?] Auth Password: ") // please don't remove the int cast here as it is sadly needed on windows :/ - passBytes, err := terminal.ReadPassword(int(syscall.Stdin)) //nolint:unconvert + passBytes, err := term.ReadPassword(int(syscall.Stdin)) //nolint:unconvert // print a newline to simulate the newline that was entered // this means that formatting/printing after doesn't look bad. fmt.Println("") diff --git a/go.mod b/go.mod index b8c68a49..b81b1b2e 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,8 @@ module github.com/OJ/gobuster/v3 require ( github.com/google/uuid v1.1.4 github.com/spf13/cobra v1.1.1 - golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad golang.org/x/sys v0.0.0-20210104204734-6f8348627aad // indirect - golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect + golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf ) go 1.15 diff --git a/go.sum b/go.sum index abfda8cd..8580bb9c 100644 --- a/go.sum +++ b/go.sum @@ -178,8 +178,6 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= -golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -234,12 +232,9 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad h1:MCsdmFSdEd4UEa5TKS5JztCRHK/WtvNei1edOj5RSRo= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= -golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= diff --git a/helper/helper_test.go b/helper/helper_test.go index d9fd5ff6..e96e5a87 100644 --- a/helper/helper_test.go +++ b/helper/helper_test.go @@ -24,7 +24,9 @@ func TestParseExtensions(t *testing.T) { } for _, x := range tt { + x := x // NOTE: https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables t.Run(x.testName, func(t *testing.T) { + t.Parallel() ret, err := ParseExtensions(x.extensions) if x.expectedError != "" { if err != nil && err.Error() != x.expectedError { @@ -55,7 +57,9 @@ func TestParseCommaSeparatedInt(t *testing.T) { } for _, x := range tt { + x := x // NOTE: https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables t.Run(x.testName, func(t *testing.T) { + t.Parallel() ret, err := ParseCommaSeparatedInt(x.stringCodes) if x.expectedError != "" { if err != nil && err.Error() != x.expectedError { @@ -83,6 +87,7 @@ func BenchmarkParseExtensions(b *testing.B) { } for _, x := range tt { + x := x // NOTE: https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables b.Run(x.testName, func(b2 *testing.B) { for y := 0; y < b2.N; y++ { _, _ = ParseExtensions(x.extensions) @@ -107,6 +112,7 @@ func BenchmarkParseCommaSeparatedInt(b *testing.B) { } for _, x := range tt { + x := x // NOTE: https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables b.Run(x.testName, func(b2 *testing.B) { for y := 0; y < b2.N; y++ { _, _ = ParseCommaSeparatedInt(x.stringCodes) diff --git a/libgobuster/helpers_test.go b/libgobuster/helpers_test.go index fe247121..196869bd 100644 --- a/libgobuster/helpers_test.go +++ b/libgobuster/helpers_test.go @@ -8,18 +8,21 @@ import ( ) func TestNewStringSet(t *testing.T) { + t.Parallel() if NewStringSet().Set == nil { t.Fatal("newStringSet returned nil Set") } } func TestNewIntSet(t *testing.T) { + t.Parallel() if NewIntSet().Set == nil { t.Fatal("newIntSet returned nil Set") } } func TestStringSetAdd(t *testing.T) { + t.Parallel() x := NewStringSet() x.Add("test") if len(x.Set) != 1 { @@ -28,6 +31,7 @@ func TestStringSetAdd(t *testing.T) { } func TestStringSetAddDouble(t *testing.T) { + t.Parallel() x := NewStringSet() x.Add("test") x.Add("test") @@ -37,6 +41,7 @@ func TestStringSetAddDouble(t *testing.T) { } func TestStringSetAddRange(t *testing.T) { + t.Parallel() x := NewStringSet() x.AddRange([]string{"string1", "string2"}) if len(x.Set) != 2 { @@ -45,6 +50,7 @@ func TestStringSetAddRange(t *testing.T) { } func TestStringSetAddRangeDouble(t *testing.T) { + t.Parallel() x := NewStringSet() x.AddRange([]string{"string1", "string2", "string1", "string2"}) if len(x.Set) != 2 { @@ -53,6 +59,7 @@ func TestStringSetAddRangeDouble(t *testing.T) { } func TestStringSetContains(t *testing.T) { + t.Parallel() x := NewStringSet() v := []string{"string1", "string2", "1234", "5678"} x.AddRange(v) @@ -64,6 +71,7 @@ func TestStringSetContains(t *testing.T) { } func TestStringSetContainsAny(t *testing.T) { + t.Parallel() x := NewStringSet() v := []string{"string1", "string2", "1234", "5678"} x.AddRange(v) @@ -78,6 +86,7 @@ func TestStringSetContainsAny(t *testing.T) { } func TestStringSetStringify(t *testing.T) { + t.Parallel() x := NewStringSet() v := []string{"string1", "string2", "1234", "5678"} x.AddRange(v) @@ -91,6 +100,7 @@ func TestStringSetStringify(t *testing.T) { } func TestIntSetAdd(t *testing.T) { + t.Parallel() x := NewIntSet() x.Add(1) if len(x.Set) != 1 { @@ -99,6 +109,7 @@ func TestIntSetAdd(t *testing.T) { } func TestIntSetAddDouble(t *testing.T) { + t.Parallel() x := NewIntSet() x.Add(1) x.Add(1) @@ -108,6 +119,7 @@ func TestIntSetAddDouble(t *testing.T) { } func TestIntSetContains(t *testing.T) { + t.Parallel() x := NewIntSet() v := []int{1, 2, 3, 4} for _, y := range v { @@ -121,6 +133,7 @@ func TestIntSetContains(t *testing.T) { } func TestIntSetStringify(t *testing.T) { + t.Parallel() x := NewIntSet() v := []int{1, 3, 2, 4} expected := "1,2,3,4" @@ -135,6 +148,7 @@ func TestIntSetStringify(t *testing.T) { } func TestLineCounter(t *testing.T) { + t.Parallel() var tt = []struct { testName string s string @@ -161,6 +175,7 @@ func TestLineCounter(t *testing.T) { } func TestLineCounterError(t *testing.T) { + t.Parallel() r := iotest.TimeoutReader(strings.NewReader("test")) _, err := lineCounter(r) if !errors.Is(err, iotest.ErrTimeout) { diff --git a/libgobuster/http.go b/libgobuster/http.go index d574d5c8..9f0ad5df 100644 --- a/libgobuster/http.go +++ b/libgobuster/http.go @@ -168,7 +168,8 @@ func (client *HTTPClient) makeRequest(fullURL, host string, data io.Reader) (*ht resp, err := client.client.Do(req) if err != nil { - if ue, ok := err.(*url.Error); ok { + var ue *url.Error + if errors.As(err, &ue) { if strings.HasPrefix(ue.Err.Error(), "x509") { return nil, fmt.Errorf("invalid certificate: %w", ue.Err) } diff --git a/libgobuster/http_test.go b/libgobuster/http_test.go index 4a17945c..a1e48ab8 100644 --- a/libgobuster/http_test.go +++ b/libgobuster/http_test.go @@ -43,6 +43,7 @@ func randomString(length int) (string, error) { } func TestRequest(t *testing.T) { + t.Parallel() ret, err := randomString(100) if err != nil { t.Fatal(err)