-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Added support for writing results as JSON. #119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"bufio" | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net" | ||
"os" | ||
|
@@ -33,6 +34,7 @@ type Gobuster struct { | |
context context.Context | ||
requestsExpected int | ||
requestsIssued int | ||
cachedResults []Result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bad idea. This will blow out memory big time for huge result sets. Data should be streamed out as it's captured rather that cached and then serialised in one hit. |
||
mu *sync.RWMutex | ||
plugin GobusterPlugin | ||
IsWildcard bool | ||
|
@@ -79,6 +81,12 @@ func (g *Gobuster) Results() <-chan Result { | |
return g.resultChan | ||
} | ||
|
||
// Returns our results as JSON | ||
func (g *Gobuster) ResultsAsJson() (string, error) { | ||
jsonResults, err := json.Marshal(g.cachedResults) | ||
return string(jsonResults), err | ||
} | ||
|
||
// Errors returns a channel of errors | ||
func (g *Gobuster) Errors() <-chan error { | ||
return g.errorChan | ||
|
@@ -145,13 +153,20 @@ func (g *Gobuster) worker(wordChan <-chan string, wg *sync.WaitGroup) { | |
continue | ||
} else { | ||
for _, r := range res { | ||
g.cacheResult(r) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The result should not be cached here. |
||
g.resultChan <- r | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
func (g *Gobuster) cacheResult(r Result) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function not necessary. It should be handled in the result handler. |
||
g.mu.Lock() | ||
g.cachedResults = append(g.cachedResults, r) | ||
g.mu.Unlock() | ||
} | ||
|
||
func (g *Gobuster) getWordlist() (*bufio.Scanner, error) { | ||
if g.Opts.Wordlist == "-" { | ||
// Read directly from stdin | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single-letters only for parameters (thanks to the command line parsing).