这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- master
- New
- Changed
- Fixed an issue where output file was created regardless of `-or`

- v1.3.1
- New
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pkg/ffuf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
14 changes: 7 additions & 7 deletions pkg/ffuf/optionsparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions pkg/output/file_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions pkg/output/file_html.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 0 additions & 5 deletions pkg/output/file_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions pkg/output/file_md.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/output/stdout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The length of s.Results is not guaranteed to have the results stored in it at the time of this check. This is because they may still be sitting in s.CurrentResults having not been appended. This means when we use the -or argument it will always fail to create a file!

We need to check the length of the result from append(s.Results, s.CurrentResults...) as you were doing previously inside each writeJSON, writeEJSON...

nit: it would be simpler to have one line like:

res = append(s.Results, s.CurrentResults...)

and use the res as an arg to pass to all the output functions.

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...))
Expand Down