From 4aa8b681a8023643282017932a1719c1117156ef Mon Sep 17 00:00:00 2001 From: edoardottt Date: Wed, 29 May 2024 20:59:44 +0200 Subject: [PATCH] Add JSON Output #312 --- README.md | 7 +++++++ go.mod | 11 ++++------- pkg/favirecon/favirecon.go | 9 +++++++++ pkg/input/flags.go | 2 ++ pkg/output/banner.go | 2 +- pkg/output/output.go | 20 +++++++++++++++----- snapcraft.yaml | 2 +- 7 files changed, 39 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d73ba80..dee380a 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ OUTPUT: -o, -output string File to write output results -v, -verbose Verbose output -s, -silent Silent output. Print only results + -j, -json JSON output ``` Examples 💡 @@ -127,6 +128,12 @@ Use a Proxy favirecon -u https://www.github.com -px http://127.0.0.1:8080 ``` +JSON Output + +```console +favirecon -u https://www.github.com -j +``` + Changelog 📌 ------- diff --git a/go.mod b/go.mod index a762afc..86eaa8a 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,10 @@ require ( github.com/projectdiscovery/goflags v0.1.54 github.com/projectdiscovery/gologger v1.1.12 github.com/projectdiscovery/utils v0.1.0 + go.uber.org/ratelimit v0.3.1 + github.com/stretchr/testify v1.9.0 + github.com/twmb/murmur3 v1.1.8 + github.com/projectdiscovery/mapcidr v1.1.34 ) require ( @@ -29,9 +33,6 @@ require ( golang.org/x/mod v0.13.0 // indirect golang.org/x/sys v0.18.0 // indirect golang.org/x/tools v0.14.0 // indirect -) - -require ( github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/aymerick/douceur v0.2.0 // indirect github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 // indirect @@ -45,13 +46,9 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/nwaples/rardecode v1.1.3 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/projectdiscovery/mapcidr v1.1.34 github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect - github.com/stretchr/testify v1.9.0 - github.com/twmb/murmur3 v1.1.8 github.com/ulikunitz/xz v0.5.11 // indirect github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect - go.uber.org/ratelimit v0.3.1 golang.org/x/net v0.23.0 // indirect gopkg.in/djherbis/times.v1 v1.3.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/pkg/favirecon/favirecon.go b/pkg/favirecon/favirecon.go index 55363db..db10dda 100644 --- a/pkg/favirecon/favirecon.go +++ b/pkg/favirecon/favirecon.go @@ -202,6 +202,15 @@ func writeOutput(wg *sync.WaitGroup, m *sync.Mutex, options *input.Options, o ou out := o.Format() + if options.JSON { + outJSON, err := o.FormatJSON() + if err != nil { + gologger.Fatal().Msg(err.Error()) + } + + out = string(outJSON) + } + if options.Output != nil { if _, err := options.Output.Write([]byte(out + "\n")); err != nil && options.Verbose { gologger.Fatal().Msg(err.Error()) diff --git a/pkg/input/flags.go b/pkg/input/flags.go index 8e9555f..afd64f0 100644 --- a/pkg/input/flags.go +++ b/pkg/input/flags.go @@ -38,6 +38,7 @@ type Options struct { Cidr bool RateLimit int Proxy string + JSON bool } // configureOutput configures the output on the screen. @@ -76,6 +77,7 @@ func ParseOptions() *Options { flagSet.StringVarP(&options.FileOutput, "output", "o", "", `File to write output results`), flagSet.BoolVarP(&options.Verbose, "verbose", "v", false, `Verbose output`), flagSet.BoolVarP(&options.Silent, "silent", "s", false, `Silent output. Print only results`), + flagSet.BoolVarP(&options.JSON, "json", "j", false, `JSON output`), ) if help() || noArgs() { diff --git a/pkg/output/banner.go b/pkg/output/banner.go index 8461d71..289805a 100644 --- a/pkg/output/banner.go +++ b/pkg/output/banner.go @@ -12,7 +12,7 @@ import "github.com/projectdiscovery/gologger" var printed = false const ( - Version = "v0.1.1" + Version = "v0.1.2" banner = ` ____ _ / __/___ __ __(_)_______ _________ ____ / /_/ __ ` + `\/ | / / / ___/ _ \/ ___/ __ \/ __ \ diff --git a/pkg/output/output.go b/pkg/output/output.go index 1b0abfe..a49e501 100644 --- a/pkg/output/output.go +++ b/pkg/output/output.go @@ -7,14 +7,15 @@ This repository is under MIT License https://github.com/edoardottt/favirecon/blo package output import ( + "encoding/json" "fmt" "sync" ) type Found struct { - URL string - Hash string - Name string + URL string `json:"URL,omitempty"` + Hash string `json:"Hash,omitempty"` + Name string `json:"Name,omitempty"` } type Result struct { @@ -30,8 +31,7 @@ func New() Result { } } -// Printed checks if a string has been previously -// printed. +// Printed checks if a string has been previously printed. func (o *Result) Printed(found string) bool { o.Mutex.RLock() if _, ok := o.Map[found]; !ok { @@ -52,3 +52,13 @@ func (o *Result) Printed(found string) bool { func (f *Found) Format() string { return fmt.Sprintf("[%s] [%s] %s", f.Hash, f.Name, f.URL) } + +// FormatJSON returns the input as JSON string. +func (f *Found) FormatJSON() ([]byte, error) { + jsonOutput, err := json.Marshal(f) + if err != nil { + return nil, err + } + + return jsonOutput, nil +} diff --git a/snapcraft.yaml b/snapcraft.yaml index c9b39af..e59559e 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -3,7 +3,7 @@ summary: Use favicon.ico to improve your target recon phase description: | Use favicon.ico to improve your target recon phase. Quickly detect technologies, WAF, exposed panels, known services. -version: 0.1.1 +version: 0.1.2 grade: stable base: core20