From 492253b67b09da8a7eff110aa4a090288a4c9c85 Mon Sep 17 00:00:00 2001 From: Cory Date: Sun, 20 Oct 2019 10:38:11 -0500 Subject: [PATCH] Add option for -debug-log. (#74) * Add options for -disable-logging and -logfile. Both of these options have to do with the logging surrounding issues such as #39. Where in that issue the server was returning data after the connection was closed. Therefore, I added two options one for completely disabling all of the internal logging functionality aka sending it to /dev/null. Another for writing the logging information to a file so it can be retrieved later if need be. * Changed to automatically disable internal logging. Per the changes requested by @joohoi, changed to a single flag `-debug-log` which will place all of the internal logging into the specified file. If the file fails to be opened or is not specified it will disable the logging. * Update readme with the changes for -debug-log. --- README.md | 5 +++++ main.go | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/README.md b/README.md index 23c28bf..04baf82 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,8 @@ To define the test case for ffuf, use the keyword `FUZZ` anywhere in the URL (`- Wordlist file path or - to read from standard input -x string HTTP Proxy URL + -debug-log string + Write the debug logging information to the specified file. ``` eg. `ffuf -u https://example.org/FUZZ -w /path/to/wordlist` @@ -186,10 +188,13 @@ The only dependency of ffuf is Go 1.11. No dependencies outside of Go standard l - New - New CLI flag: -l, shows target location of redirect responses - New CLI flac: -acc, custom auto-calibration strings + - New CLI flag: -debug-log, writes the debug logging to the specified file. + - Changed - New CLI flag: -i, dummy flag that does nothing. for compatibility with copy as curl. - New CLI flag: -b/--cookie, cookie data for compatibility with copy as curl. - Filtering and matching by status code, response size or word count now allow using ranges in addition to single values + - The internal logging information to be discarded, and can be written to a file with the new `-debug-log` flag. - v0.10 diff --git a/main.go b/main.go index 68c2962..9971fa4 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,8 @@ import ( "context" "flag" "fmt" + "io/ioutil" + "log" "net/http" "net/url" "os" @@ -34,6 +36,7 @@ type cliOptions struct { cookies multiStringFlag AutoCalibrationStrings multiStringFlag showVersion bool + debugLog string } type multiStringFlag []string @@ -94,11 +97,24 @@ func main() { flag.IntVar(&conf.Threads, "t", 40, "Number of concurrent threads.") flag.IntVar(&conf.Timeout, "timeout", 10, "HTTP request timeout in seconds.") flag.BoolVar(&opts.showVersion, "V", false, "Show version information.") + flag.StringVar(&opts.debugLog, "debug-log", "", "Write all of the internal logging to the specified file.") flag.Parse() if opts.showVersion { fmt.Printf("ffuf version: %s\n", ffuf.VERSION) os.Exit(0) } + if len(opts.debugLog) != 0 { + f, err := os.OpenFile(opts.debugLog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + fmt.Fprintf(os.Stderr, "Disabling logging, encountered error(s): %s\n", err) + log.SetOutput(ioutil.Discard) + } else { + log.SetOutput(f) + defer f.Close() + } + } else { + log.SetOutput(ioutil.Discard) + } if err := prepareConfig(&opts, &conf); err != nil { fmt.Fprintf(os.Stderr, "Encountered error(s): %s\n", err) flag.Usage()