From ee0705e2242040ecd015e630d8b9630e31d26322 Mon Sep 17 00:00:00 2001 From: Joona Hoikkala Date: Thu, 13 May 2021 19:07:00 +0300 Subject: [PATCH] Fix an issue where output file was created regardless of -or (#444) * Fix an issue where output file was created regardless of -or * Add CHANGELOG entry --- CHANGELOG.md | 1 + main.go | 2 +- pkg/ffuf/config.go | 2 +- pkg/ffuf/optionsparser.go | 14 +++++++------- pkg/output/file_csv.go | 5 ----- pkg/output/file_html.go | 5 ----- pkg/output/file_json.go | 5 ----- pkg/output/file_md.go | 5 ----- pkg/output/stdout.go | 8 ++++---- 9 files changed, 14 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf97877..5611dae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - master - New - Changed + - Fixed an issue where output file was created regardless of `-or` - v1.3.1 - New diff --git a/main.go b/main.go index 7da9b8c..0f2a715 100644 --- a/main.go +++ b/main.go @@ -58,7 +58,7 @@ func ParseFlags(opts *ffuf.ConfigOptions) *ffuf.ConfigOptions { flag.BoolVar(&ignored, "compressed", true, "Dummy flag for copy as curl functionality (ignored)") flag.BoolVar(&ignored, "i", true, "Dummy flag for copy as curl functionality (ignored)") flag.BoolVar(&ignored, "k", false, "Dummy flag for backwards compatibility") - flag.BoolVar(&opts.Output.OutputCreateEmptyFile, "or", opts.Output.OutputCreateEmptyFile, "Don't create the output file if we don't have results") + flag.BoolVar(&opts.Output.OutputSkipEmptyFile, "or", opts.Output.OutputSkipEmptyFile, "Don't create the output file if we don't have results") flag.BoolVar(&opts.General.AutoCalibration, "ac", opts.General.AutoCalibration, "Automatically calibrate filtering options") flag.BoolVar(&opts.General.Colors, "c", opts.General.Colors, "Colorize output.") flag.BoolVar(&opts.General.Noninteractive, "noninteractive", opts.General.Noninteractive, "Disable the interactive console functionality") diff --git a/pkg/ffuf/config.go b/pkg/ffuf/config.go index 1b7fe58..a5e56ea 100644 --- a/pkg/ffuf/config.go +++ b/pkg/ffuf/config.go @@ -34,7 +34,7 @@ type Config struct { OutputDirectory string `json:"outputdirectory"` OutputFile string `json:"outputfile"` OutputFormat string `json:"outputformat"` - OutputCreateEmptyFile bool `json:"OutputCreateEmptyFile"` + OutputSkipEmptyFile bool `json:"OutputSkipEmptyFile"` ProgressFrequency int `json:"-"` ProxyURL string `json:"proxyurl"` Quiet bool `json:"quiet"` diff --git a/pkg/ffuf/optionsparser.go b/pkg/ffuf/optionsparser.go index e04aa48..c8d0235 100644 --- a/pkg/ffuf/optionsparser.go +++ b/pkg/ffuf/optionsparser.go @@ -74,11 +74,11 @@ type InputOptions struct { } type OutputOptions struct { - DebugLog string - OutputDirectory string - OutputFile string - OutputFormat string - OutputCreateEmptyFile bool + DebugLog string + OutputDirectory string + OutputFile string + OutputFormat string + OutputSkipEmptyFile bool } type FilterOptions struct { @@ -146,7 +146,7 @@ func NewConfigOptions() *ConfigOptions { c.Output.OutputDirectory = "" c.Output.OutputFile = "" c.Output.OutputFormat = "json" - c.Output.OutputCreateEmptyFile = false + c.Output.OutputSkipEmptyFile = false return c } @@ -382,7 +382,7 @@ func ConfigFromOptions(parseOpts *ConfigOptions, ctx context.Context, cancel con conf.InputShell = parseOpts.Input.InputShell conf.OutputFile = parseOpts.Output.OutputFile conf.OutputDirectory = parseOpts.Output.OutputDirectory - conf.OutputCreateEmptyFile = parseOpts.Output.OutputCreateEmptyFile + conf.OutputSkipEmptyFile = parseOpts.Output.OutputSkipEmptyFile conf.IgnoreBody = parseOpts.HTTP.IgnoreBody conf.Quiet = parseOpts.General.Quiet conf.StopOn403 = parseOpts.General.StopOn403 diff --git a/pkg/output/file_csv.go b/pkg/output/file_csv.go index 70f0dee..1a6bcc3 100644 --- a/pkg/output/file_csv.go +++ b/pkg/output/file_csv.go @@ -12,11 +12,6 @@ import ( var staticheaders = []string{"url", "redirectlocation", "position", "status_code", "content_length", "content_words", "content_lines", "content_type", "resultfile"} func writeCSV(filename string, config *ffuf.Config, res []ffuf.Result, encode bool) error { - - if config.OutputCreateEmptyFile && (len(res) == 0) { - return nil - } - header := make([]string, 0) f, err := os.Create(filename) if err != nil { diff --git a/pkg/output/file_html.go b/pkg/output/file_html.go index 2f6bcf2..f4f35a8 100644 --- a/pkg/output/file_html.go +++ b/pkg/output/file_html.go @@ -177,11 +177,6 @@ func colorizeResults(results []ffuf.Result) []ffuf.Result { } func writeHTML(filename string, config *ffuf.Config, results []ffuf.Result) error { - - if config.OutputCreateEmptyFile && (len(results) == 0) { - return nil - } - results = colorizeResults(results) ti := time.Now() diff --git a/pkg/output/file_json.go b/pkg/output/file_json.go index cf495b2..709fa3f 100644 --- a/pkg/output/file_json.go +++ b/pkg/output/file_json.go @@ -37,11 +37,6 @@ type jsonFileOutput struct { } func writeEJSON(filename string, config *ffuf.Config, res []ffuf.Result) error { - - if config.OutputCreateEmptyFile && (len(res) == 0) { - return nil - } - t := time.Now() outJSON := ejsonFileOutput{ CommandLine: config.CommandLine, diff --git a/pkg/output/file_md.go b/pkg/output/file_md.go index 86db0b8..7ae722b 100644 --- a/pkg/output/file_md.go +++ b/pkg/output/file_md.go @@ -21,11 +21,6 @@ const ( ) func writeMarkdown(filename string, config *ffuf.Config, res []ffuf.Result) error { - - if config.OutputCreateEmptyFile && (len(res) == 0) { - return nil - } - ti := time.Now() keywords := make([]string, 0) diff --git a/pkg/output/stdout.go b/pkg/output/stdout.go index 043427c..3758f22 100644 --- a/pkg/output/stdout.go +++ b/pkg/output/stdout.go @@ -225,10 +225,6 @@ func (s *Stdoutput) writeToAll(filename string, config *ffuf.Config, res []ffuf. // Go through each type of write, adding // the suffix to each output file. - if config.OutputCreateEmptyFile && (len(res) == 0) { - return nil - } - s.config.OutputFile = BaseFilename + ".json" err = writeJSON(filename, s.config, res) if err != nil { @@ -272,6 +268,10 @@ func (s *Stdoutput) writeToAll(filename string, config *ffuf.Config, res []ffuf. // SaveFile saves the current results to a file of a given type func (s *Stdoutput) SaveFile(filename, format string) error { var err error + if s.config.OutputSkipEmptyFile && len(s.Results) == 0 { + s.Info("No results and -or defined, output file not written.") + return err + } switch format { case "all": err = s.writeToAll(filename, s.config, append(s.Results, s.CurrentResults...))