From fb1be906f07c015046e7e857432d5bd85cbe7c4c Mon Sep 17 00:00:00 2001 From: Joona Hoikkala Date: Thu, 4 Mar 2021 22:04:04 +0200 Subject: [PATCH] Move version output to a function (#407) * Version info as function (#3) * Opportunistic coloring --- help.go | 2 +- main.go | 2 +- pkg/ffuf/const.go | 3 ++- pkg/ffuf/util.go | 6 ++++++ pkg/output/stdout.go | 8 +++++--- pkg/runner/simple.go | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/help.go b/help.go index e9db37e..7d87be8 100644 --- a/help.go +++ b/help.go @@ -123,7 +123,7 @@ func Usage() { } }) - fmt.Printf("Fuzz Faster U Fool - v%s\n\n", ffuf.VERSION) + fmt.Printf("Fuzz Faster U Fool - v%s\n\n", ffuf.Version()) // Print out the sections for _, section := range sections { diff --git a/main.go b/main.go index 3301500..00d97e3 100644 --- a/main.go +++ b/main.go @@ -136,7 +136,7 @@ func main() { opts = ParseFlags(opts) if opts.General.ShowVersion { - fmt.Printf("ffuf version: %s\n", ffuf.VERSION) + fmt.Printf("ffuf version: %s\n", ffuf.Version()) os.Exit(0) } if len(opts.Output.DebugLog) != 0 { diff --git a/pkg/ffuf/const.go b/pkg/ffuf/const.go index 93896b4..fa761be 100644 --- a/pkg/ffuf/const.go +++ b/pkg/ffuf/const.go @@ -2,5 +2,6 @@ package ffuf const ( //VERSION holds the current version number - VERSION = "1.3.0-git" + VERSION = "1.3.0-git" + VERSION_APPENDIX = "" ) diff --git a/pkg/ffuf/util.go b/pkg/ffuf/util.go index 327fa6a..e9a8aa9 100644 --- a/pkg/ffuf/util.go +++ b/pkg/ffuf/util.go @@ -1,6 +1,7 @@ package ffuf import ( + "fmt" "math/rand" "os" ) @@ -41,3 +42,8 @@ func FileExists(path string) bool { return !md.IsDir() } + +//Version returns the ffuf version string +func Version() string { + return fmt.Sprintf("%s%s", VERSION, VERSION_APPENDIX) +} diff --git a/pkg/output/stdout.go b/pkg/output/stdout.go index ef2d583..9981d6a 100644 --- a/pkg/output/stdout.go +++ b/pkg/output/stdout.go @@ -7,6 +7,7 @@ import ( "os" "path" "strconv" + "strings" "time" "github.com/ffuf/ffuf/pkg/ffuf" @@ -52,7 +53,8 @@ func NewStdoutput(conf *ffuf.Config) *Stdoutput { } func (s *Stdoutput) Banner() { - fmt.Fprintf(os.Stderr, "%s\n v%s\n%s\n\n", BANNER_HEADER, ffuf.VERSION, BANNER_SEP) + version := strings.ReplaceAll(ffuf.Version(), "<3", fmt.Sprintf("%s<3%s", ANSI_RED, ANSI_CLEAR)) + fmt.Fprintf(os.Stderr, "%s\n v%s\n%s\n\n", BANNER_HEADER, version, BANNER_SEP) printOption([]byte("Method"), []byte(s.config.Method)) printOption([]byte("URL"), []byte(s.config.Url)) @@ -211,9 +213,9 @@ func (s *Stdoutput) writeToAll(config *ffuf.Config, res []Result) error { // Go through each type of write, adding // the suffix to each output file. - if(config.OutputCreateEmptyFile && (len(res) == 0)){ + if config.OutputCreateEmptyFile && (len(res) == 0) { return nil - } + } s.config.OutputFile = BaseFilename + ".json" err = writeJSON(s.config, s.Results) diff --git a/pkg/runner/simple.go b/pkg/runner/simple.go index 2dca7e0..e13415e 100644 --- a/pkg/runner/simple.go +++ b/pkg/runner/simple.go @@ -104,7 +104,7 @@ func (r *SimpleRunner) Execute(req *ffuf.Request) (ffuf.Response, error) { // set default User-Agent header if not present if _, ok := req.Headers["User-Agent"]; !ok { - req.Headers["User-Agent"] = fmt.Sprintf("%s v%s", "Fuzz Faster U Fool", ffuf.VERSION) + req.Headers["User-Agent"] = fmt.Sprintf("%s v%s", "Fuzz Faster U Fool", ffuf.Version()) } // Handle Go http.Request special cases