1
1
Fork 0
mirror of https://github.com/OJ/gobuster.git synced 2024-05-11 12:26:01 +02:00
This commit is contained in:
Christian Mehlmauer 2019-05-17 17:23:20 +02:00
parent 6aff466090
commit 0dcdf6fc64
No known key found for this signature in database
GPG Key ID: DCF54A05D6E62591
10 changed files with 68 additions and 20 deletions

29
.golangci.yml Normal file
View File

@ -0,0 +1,29 @@
linters:
enable-all: true
disable:
- lll
- gocyclo
issues:
exclude-rules:
- text: "TLS InsecureSkipVerify may be true"
linters:
- gosec
- text: ifElseChain
linters:
- gocritic
- path: cli\\cmd\\.+\.go
linters:
- gochecknoinits
- gochecknoglobals
- path: cli/cmd/.+\.go
linters:
- gochecknoinits
- gochecknoglobals
- path: _test\.go
linters:
- scopelint

View File

@ -8,4 +8,4 @@ go:
- "1.12.x"
- master
script: make test
script: make lint test

View File

@ -41,12 +41,19 @@ darwin:
done; \
echo "Done."
all: clean fmt update test darwin linux windows
all: clean fmt update lint test darwin linux windows
test:
@go test -v -race ./... ; \
echo "Done."
lint:
@go get -u github.com/golangci/golangci-lint@master ; \
golangci-lint run ./... ; \
go mod tidy ; \
echo Done
clean:
@rm -rf ${TARGET}/* ; \
go clean ./... ; \
echo "Done."

View File

@ -53,7 +53,7 @@ func BenchmarkDirMode(b *testing.B) {
}
defer os.Remove(wordlist.Name())
for w := 0; w < 1000; w++ {
wordlist.WriteString(fmt.Sprintf("%d\n", w))
_, _ = wordlist.WriteString(fmt.Sprintf("%d\n", w))
}
wordlist.Close()

View File

@ -22,7 +22,7 @@ func runDNS(cmd *cobra.Command, args []string) error {
plugin, err := gobusterdns.NewGobusterDNS(globalopts, pluginopts)
if err != nil {
return fmt.Errorf("Error on creating gobusterdns: %v", err)
return fmt.Errorf("error on creating gobusterdns: %v", err)
}
if err := cli.Gobuster(mainContext, globalopts, plugin); err != nil {

View File

@ -28,7 +28,7 @@ func BenchmarkVhostMode(b *testing.B) {
}
defer os.Remove(wordlist.Name())
for w := 0; w < 1000; w++ {
wordlist.WriteString(fmt.Sprintf("%d\n", w))
_, _ = wordlist.WriteString(fmt.Sprintf("%d\n", w))
}
wordlist.Close()

View File

@ -153,15 +153,16 @@ func (d *GobusterDir) ResultToString(r *libgobuster.Result) (*string, error) {
// Prefix if we're in verbose mode
if d.globalopts.Verbose {
if r.Status == libgobuster.StatusFound {
switch r.Status {
case libgobuster.StatusFound:
if _, err := fmt.Fprintf(buf, "Found: "); err != nil {
return nil, err
}
} else if r.Status == libgobuster.StatusMissed {
case libgobuster.StatusMissed:
if _, err := fmt.Fprintf(buf, "Missed: "); err != nil {
return nil, err
}
} else {
default:
return nil, fmt.Errorf("unknown status %d", r.Status)
}
}

View File

@ -8,7 +8,7 @@ import (
"github.com/OJ/gobuster/v3/libgobuster"
)
// ParseExtensions parses the extensions provided as a comma seperated list
// ParseExtensions parses the extensions provided as a comma separated list
func ParseExtensions(extensions string) (libgobuster.StringSet, error) {
if extensions == "" {
return libgobuster.StringSet{}, fmt.Errorf("invalid extension string provided")
@ -24,7 +24,7 @@ func ParseExtensions(extensions string) (libgobuster.StringSet, error) {
return ret, nil
}
// ParseStatusCodes parses the status codes provided as a comma seperated list
// ParseStatusCodes parses the status codes provided as a comma separated list
func ParseStatusCodes(statuscodes string) (libgobuster.IntSet, error) {
if statuscodes == "" {
return libgobuster.IntSet{}, fmt.Errorf("invalid status code string provided")

View File

@ -13,16 +13,15 @@ import (
"unicode/utf8"
)
var defaultUserAgent = DefaultUserAgent()
// HTTPClient represents a http object
type HTTPClient struct {
client *http.Client
context context.Context
userAgent string
username string
password string
includeLength bool
client *http.Client
context context.Context
userAgent string
defaultUserAgent string
username string
password string
includeLength bool
}
// HTTPOptions provides options to the http client
@ -80,6 +79,7 @@ func NewHTTPClient(c context.Context, opt *HTTPOptions) (*HTTPClient, error) {
client.password = opt.Password
client.includeLength = opt.IncludeLength
client.userAgent = opt.UserAgent
client.defaultUserAgent = DefaultUserAgent()
return &client, nil
}
@ -192,7 +192,7 @@ func (client *HTTPClient) makeRequest(method, fullURL, host, cookie string, data
if client.userAgent != "" {
req.Header.Set("User-Agent", client.userAgent)
} else {
req.Header.Set("User-Agent", defaultUserAgent)
req.Header.Set("User-Agent", client.defaultUserAgent)
}
if client.username != "" {
@ -203,7 +203,7 @@ func (client *HTTPClient) makeRequest(method, fullURL, host, cookie string, data
if err != nil {
if ue, ok := err.(*url.Error); ok {
if strings.HasPrefix(ue.Err.Error(), "x509") {
return nil, fmt.Errorf("Invalid certificate: %v", ue.Err)
return nil, fmt.Errorf("invalid certificate: %v", ue.Err)
}
}
return nil, err

View File

@ -11,6 +11,7 @@ IF "%ARG%"=="test" (
IF "%ARG%"=="clean" (
del /F /Q %TARGET%\*.*
go clean ./...
echo Done.
GOTO Done
)
@ -43,6 +44,7 @@ IF "%ARG%"=="fmt" (
IF "%ARG%"=="all" (
CALL :Fmt
CALL :Update
CALL :Lint
CALL :Test
CALL :Darwin
CALL :Linux
@ -64,6 +66,15 @@ go test -v ./...
echo Done
EXIT /B 0
:Lint
set GO111MODULE=on
echo Linting ...
go get -u github.com/golangci/golangci-lint@master
golangci-lint run ./...
rem remove test deps
go mod tidy
echo Done
:Fmt
set GO111MODULE=on
echo Formatting ...