这是indexloc提供的服务,不要输入任何密码
Skip to content

Add output to CSV file #12

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

Merged
merged 1 commit into from
Apr 3, 2019
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ To define the test case for ffuf, use the keyword `FUZZ` anywhere in the URL (`-
-o string
Write output to file
-of string
Output file format. Available formats: json (default "json")
Output file format. Available formats: json, csv, ecsv (default "json")
-p delay
Seconds of delay between requests, or a range of random delay. For example "0.1" or "0.1-2.0"
-s Do not print additional information (silent mode)
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func main() {
flag.StringVar(&opts.proxyURL, "x", "", "HTTP Proxy URL")
flag.StringVar(&conf.Method, "X", "GET", "HTTP method to use")
flag.StringVar(&conf.OutputFile, "o", "", "Write output to file")
flag.StringVar(&opts.outputFormat, "of", "json", "Output file format. Available formats: json")
flag.StringVar(&opts.outputFormat, "of", "json", "Output file format. Available formats: json, csv, ecsv")
flag.BoolVar(&conf.Quiet, "s", false, "Do not print additional information (silent mode)")
flag.BoolVar(&conf.StopOn403, "sf", false, "Stop when > 90% of responses return 403 Forbidden")
flag.IntVar(&conf.Threads, "t", 40, "Number of concurrent threads.")
Expand Down Expand Up @@ -186,7 +186,7 @@ func prepareConfig(parseOpts *cliOptions, conf *ffuf.Config) error {
//Check the output file format option
if conf.OutputFile != "" {
//No need to check / error out if output file isn't defined
outputFormats := []string{"json"}
outputFormats := []string{"json", "csv", "ecsv"}
found := false
for _, f := range outputFormats {
if f == parseOpts.outputFormat {
Expand Down
51 changes: 51 additions & 0 deletions pkg/output/file_csv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package output

import (
"encoding/base64"
"encoding/csv"
"os"
"strconv"

"github.com/ffuf/ffuf/pkg/ffuf"
)

var header = []string{"input", "status_code", "content_length", "content_words"}

func writeCSV(config *ffuf.Config, res []Result, encode bool) error {
f, err := os.Create(config.OutputFile)
if err != nil {
return err
}
defer f.Close()

w := csv.NewWriter(f)
defer w.Flush()

if err := w.Write(header); err != nil {
return err
}
for _, r := range res {
if encode {
r.Input = base64encode(r.Input)
}

err := w.Write(toCSV(r))
if err != nil {
return err
}
}
return nil
}

func base64encode(in string) string {
return base64.StdEncoding.EncodeToString([]byte(in))
}

func toCSV(r Result) []string {
return []string{
r.Input,
strconv.FormatInt(r.StatusCode, 10),
strconv.FormatInt(r.ContentLength, 10),
strconv.FormatInt(r.ContentWords, 10),
}
}
4 changes: 4 additions & 0 deletions pkg/output/stdout.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (s *Stdoutput) Finalize() error {
if s.config.OutputFile != "" {
if s.config.OutputFormat == "json" {
err = writeJSON(s.config, s.Results)
} else if s.config.OutputFormat == "csv" {
err = writeCSV(s.config, s.Results, false)
} else if s.config.OutputFormat == "ecsv" {
err = writeCSV(s.config, s.Results, true)
}
if err != nil {
s.Error(fmt.Sprintf("%s", err))
Expand Down