Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to add query string to each request #279

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion cli/cmd/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"log"
"strings"

"github.com/OJ/gobuster/v3/cli"
"github.com/OJ/gobuster/v3/gobusterdir"
Expand Down Expand Up @@ -77,6 +78,18 @@ func parseDirOptions() (*libgobuster.Options, *gobusterdir.OptionsDir, error) {
return nil, nil, fmt.Errorf("invalid value for status-codes-blacklist: %w", err)
}

plugin.QueryString, err = cmdDir.Flags().GetString("query")
if err != nil {
return nil, nil, fmt.Errorf("invalid query string")
}
if plugin.QueryString != "" {
if strings.HasSuffix(plugin.URL, "/") {
plugin.URL = plugin.URL + "?" + plugin.QueryString
} else {
plugin.URL = plugin.URL + "?" + plugin.QueryString
}
}

// blacklist will override the normal status codes
if plugin.StatusCodesBlacklist != "" {
ret, err := helper.ParseCommaSeparatedInt(plugin.StatusCodesBlacklist)
Expand Down Expand Up @@ -155,7 +168,7 @@ func init() {
cmdDir.Flags().Bool("wildcard", false, "Force continued operation when wildcard found")
cmdDir.Flags().BoolP("discover-backup", "d", false, "Upon finding a file search for backup files")
cmdDir.Flags().IntSlice("exclude-length", []int{}, "exclude the following content length (completely ignores the status). Supply multiple times to exclude multiple sizes.")

cmdDir.Flags().StringP("query", "Q", "", "Specify a query string to be added to the end of each request")
cmdDir.PersistentPreRun = func(cmd *cobra.Command, args []string) {
configureGlobalOptions()
}
Expand Down
9 changes: 9 additions & 0 deletions gobusterdir/gobusterdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"context"
"fmt"
"net/http"
"strings"
"text/tabwriter"

Expand Down Expand Up @@ -108,6 +109,14 @@ func (d *GobusterDir) RequestsPerRun() int {
// PreRun is the pre run implementation of gobusterdir
func (d *GobusterDir) PreRun() error {
// add trailing slash
if strings.Contains(d.options.URL, "?") {
resp, err := http.Get(d.options.URL)
if err != nil {
fmt.Printf(err.Error())
}
finalURL := resp.Request.URL.String()
d.options.URL = finalURL
}
if !strings.HasSuffix(d.options.URL, "/") {
d.options.URL = fmt.Sprintf("%s/", d.options.URL)
}
Expand Down
1 change: 1 addition & 0 deletions gobusterdir/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type OptionsDir struct {
StatusCodes string
StatusCodesParsed libgobuster.IntSet
StatusCodesBlacklist string
QueryString string
StatusCodesBlacklistParsed libgobuster.IntSet
UseSlash bool
WildcardForced bool
Expand Down