Skip to content

Commit

Permalink
more user friendly error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
firefart committed Aug 17, 2023
1 parent 441c009 commit abd72de
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ All funds that are donated to this project will be donated to charity. A full lo

## 3.7

- TODO
- More user friendly error messages

## 3.6

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func runDir(cmd *cobra.Command, args []string) error {
return fmt.Errorf("%w. To continue please exclude the status code or the length", wErr)
}
log.Debugf("%#v", err)
return fmt.Errorf("error on running gobuster: %w", err)
return fmt.Errorf("error on running gobuster on %s: %w", pluginopts.URL, err)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func runDNS(cmd *cobra.Command, args []string) error {
return fmt.Errorf("%w. To force processing of Wildcard DNS, specify the '--wildcard' switch", wErr)
}
log.Debugf("%#v", err)
return fmt.Errorf("error on running gobuster: %w", err)
return fmt.Errorf("error on running gobuster on %s: %w", pluginopts.Domain, err)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func runFuzz(cmd *cobra.Command, args []string) error {
return fmt.Errorf("%w. To continue please exclude the status code or the length", wErr)
}
log.Debugf("%#v", err)
return fmt.Errorf("error on running gobuster: %w", err)
return fmt.Errorf("error on running gobuster on %s: %w", pluginopts.URL, err)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/tftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func runTFTP(cmd *cobra.Command, args []string) error {
log := libgobuster.NewLogger(globalopts.Debug)
if err := cli.Gobuster(mainContext, globalopts, plugin, log); err != nil {
log.Debugf("%#v", err)
return fmt.Errorf("error on running gobuster: %w", err)
return fmt.Errorf("error on running gobuster on %s: %w", pluginopts.Server, err)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/vhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func runVhost(cmd *cobra.Command, args []string) error {
log := libgobuster.NewLogger(globalopts.Debug)
if err := cli.Gobuster(mainContext, globalopts, plugin, log); err != nil {
log.Debugf("%#v", err)
return fmt.Errorf("error on running gobuster: %w", err)
return fmt.Errorf("error on running gobuster on %s: %w", pluginopts.URL, err)
}
return nil
}
Expand Down
25 changes: 22 additions & 3 deletions gobusterdir/gobusterdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"errors"
"fmt"
"io"
"net"
"net/http"
"os"
"strings"
"syscall"
"text/tabwriter"
"unicode/utf8"

Expand Down Expand Up @@ -102,7 +103,11 @@ func (d *GobusterDir) PreRun(ctx context.Context, progress *libgobuster.Progress
_, _, _, _, err := d.http.Request(ctx, d.options.URL, libgobuster.RequestOptions{})
if err != nil {
if errors.Is(err, io.EOF) {
return fmt.Errorf("server closed connection without sending any data back when connecting to %s. Maybe you are connecting via https to on http port or vice versa?", d.options.URL)
return libgobuster.ErrorEOF
} else if os.IsTimeout(err) {
return libgobuster.ErrorTimeout
} else if errors.Is(err, syscall.ECONNREFUSED) {
return libgobuster.ErrorConnectionRefused
}
return fmt.Errorf("unable to connect to %s: %w", d.options.URL, err)
}
Expand All @@ -115,6 +120,13 @@ func (d *GobusterDir) PreRun(ctx context.Context, progress *libgobuster.Progress

wildcardResp, wildcardLength, _, _, err := d.http.Request(ctx, url, libgobuster.RequestOptions{})
if err != nil {
if errors.Is(err, io.EOF) {
return libgobuster.ErrorEOF
} else if os.IsTimeout(err) {
return libgobuster.ErrorTimeout
} else if errors.Is(err, syscall.ECONNREFUSED) {
return libgobuster.ErrorConnectionRefused
}
return err
}

Expand Down Expand Up @@ -207,14 +219,21 @@ func (d *GobusterDir) ProcessWord(ctx context.Context, word string, progress *li
if err != nil {
// check if it's a timeout and if we should try again and try again
// otherwise the timeout error is raised
if netErr, ok := err.(net.Error); ok && netErr.Timeout() && i != tries {
if os.IsTimeout(err) && i != tries {
continue
} else if strings.Contains(err.Error(), "invalid control character in URL") {
// put error in error chan so it's printed out and ignore it
// so gobuster will not quit
progress.ErrorChan <- err
continue
} else {
if errors.Is(err, io.EOF) {
return libgobuster.ErrorEOF
} else if os.IsTimeout(err) {
return libgobuster.ErrorTimeout
} else if errors.Is(err, syscall.ECONNREFUSED) {
return libgobuster.ErrorConnectionRefused
}
return err
}
}
Expand Down
14 changes: 12 additions & 2 deletions gobusterfuzz/gobusterfuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"net"
"io"
"os"
"strings"
"syscall"
"text/tabwriter"

"github.com/OJ/gobuster/v3/libgobuster"
Expand Down Expand Up @@ -128,14 +131,21 @@ func (d *GobusterFuzz) ProcessWord(ctx context.Context, word string, progress *l
if err != nil {
// check if it's a timeout and if we should try again and try again
// otherwise the timeout error is raised
if netErr, ok := err.(net.Error); ok && netErr.Timeout() && i != tries {
if os.IsTimeout(err) && i != tries {
continue
} else if strings.Contains(err.Error(), "invalid control character in URL") {
// put error in error chan so it's printed out and ignore it
// so gobuster will not quit
progress.ErrorChan <- err
continue
} else {
if errors.Is(err, io.EOF) {
return libgobuster.ErrorEOF
} else if os.IsTimeout(err) {
return libgobuster.ErrorTimeout
} else if errors.Is(err, syscall.ECONNREFUSED) {
return libgobuster.ErrorConnectionRefused
}
return err
}
}
Expand Down
14 changes: 12 additions & 2 deletions gobustergcs/gobustersgcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net"
"io"
"net/http"
"os"
"regexp"
"strings"
"syscall"
"text/tabwriter"

"github.com/OJ/gobuster/v3/libgobuster"
Expand Down Expand Up @@ -98,14 +101,21 @@ func (s *GobusterGCS) ProcessWord(ctx context.Context, word string, progress *li
if err != nil {
// check if it's a timeout and if we should try again and try again
// otherwise the timeout error is raised
if netErr, ok := err.(net.Error); ok && netErr.Timeout() && i != tries {
if os.IsTimeout(err) && i != tries {
continue
} else if strings.Contains(err.Error(), "invalid control character in URL") {
// put error in error chan so it's printed out and ignore it
// so gobuster will not quit
progress.ErrorChan <- err
continue
} else {
if errors.Is(err, io.EOF) {
return libgobuster.ErrorEOF
} else if os.IsTimeout(err) {
return libgobuster.ErrorTimeout
} else if errors.Is(err, syscall.ECONNREFUSED) {
return libgobuster.ErrorConnectionRefused
}
return err
}
}
Expand Down
14 changes: 12 additions & 2 deletions gobusters3/gobusters3.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import (
"bytes"
"context"
"encoding/xml"
"errors"
"fmt"
"net"
"io"
"net/http"
"os"
"regexp"
"strings"
"syscall"
"text/tabwriter"

"github.com/OJ/gobuster/v3/libgobuster"
Expand Down Expand Up @@ -97,14 +100,21 @@ func (s *GobusterS3) ProcessWord(ctx context.Context, word string, progress *lib
if err != nil {
// check if it's a timeout and if we should try again and try again
// otherwise the timeout error is raised
if netErr, ok := err.(net.Error); ok && netErr.Timeout() && i != tries {
if os.IsTimeout(err) && i != tries {
continue
} else if strings.Contains(err.Error(), "invalid control character in URL") {
// put error in error chan so it's printed out and ignore it
// so gobuster will not quit
progress.ErrorChan <- err
continue
} else {
if errors.Is(err, io.EOF) {
return libgobuster.ErrorEOF
} else if os.IsTimeout(err) {
return libgobuster.ErrorTimeout
} else if errors.Is(err, syscall.ECONNREFUSED) {
return libgobuster.ErrorConnectionRefused
}
return err
}
}
Expand Down
24 changes: 20 additions & 4 deletions gobustervhost/gobustervhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"errors"
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
"strings"
"syscall"
"text/tabwriter"

"github.com/OJ/gobuster/v3/libgobuster"
Expand Down Expand Up @@ -97,7 +98,11 @@ func (v *GobusterVhost) PreRun(ctx context.Context, progress *libgobuster.Progre
_, _, _, body, err := v.http.Request(ctx, v.options.URL, libgobuster.RequestOptions{ReturnBody: true})
if err != nil {
if errors.Is(err, io.EOF) {
return fmt.Errorf("server closed connection without sending any data back when connecting to %s. Maybe you are connecting via https to on http port or vice versa?", v.options.URL)
return libgobuster.ErrorEOF
} else if os.IsTimeout(err) {
return libgobuster.ErrorTimeout
} else if errors.Is(err, syscall.ECONNREFUSED) {
return libgobuster.ErrorConnectionRefused
}
return fmt.Errorf("unable to connect to %s: %w", v.options.URL, err)
}
Expand All @@ -108,7 +113,11 @@ func (v *GobusterVhost) PreRun(ctx context.Context, progress *libgobuster.Progre
_, _, _, body, err = v.http.Request(ctx, v.options.URL, libgobuster.RequestOptions{Host: subdomain, ReturnBody: true})
if err != nil {
if errors.Is(err, io.EOF) {
return fmt.Errorf("server closed connection without sending any data back when connecting to %s. Maybe you are connecting via https to on http port or vice versa?", v.options.URL)
return libgobuster.ErrorEOF
} else if os.IsTimeout(err) {
return libgobuster.ErrorTimeout
} else if errors.Is(err, syscall.ECONNREFUSED) {
return libgobuster.ErrorConnectionRefused
}
return fmt.Errorf("unable to connect to %s: %w", v.options.URL, err)
}
Expand Down Expand Up @@ -142,14 +151,21 @@ func (v *GobusterVhost) ProcessWord(ctx context.Context, word string, progress *
if err != nil {
// check if it's a timeout and if we should try again and try again
// otherwise the timeout error is raised
if netErr, ok := err.(net.Error); ok && netErr.Timeout() && i != tries {
if os.IsTimeout(err) && i != tries {
continue
} else if strings.Contains(err.Error(), "invalid control character in URL") {
// put error in error chan so it's printed out and ignore it
// so gobuster will not quit
progress.ErrorChan <- err
continue
} else {
if errors.Is(err, io.EOF) {
return libgobuster.ErrorEOF
} else if os.IsTimeout(err) {
return libgobuster.ErrorTimeout
} else if errors.Is(err, syscall.ECONNREFUSED) {
return libgobuster.ErrorConnectionRefused
}
return err
}
}
Expand Down
9 changes: 9 additions & 0 deletions libgobuster/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package libgobuster

import "errors"

var (
ErrorTimeout = errors.New("timeout occured during the request")
ErrorEOF = errors.New("server closed connection without sending any data back. Maybe you are connecting via https to on http port or vice versa?")
ErrorConnectionRefused = errors.New("connection refused")
)

0 comments on commit abd72de

Please sign in to comment.