Skip to content

Commit

Permalink
Add JSON Output #312
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardottt committed May 29, 2024
1 parent 159d210 commit 4aa8b68
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 14 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 💡
Expand Down Expand Up @@ -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 📌
-------

Expand Down
11 changes: 4 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions pkg/favirecon/favirecon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 2 additions & 0 deletions pkg/input/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Options struct {
Cidr bool
RateLimit int
Proxy string
JSON bool
}

// configureOutput configures the output on the screen.
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/output/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import "github.com/projectdiscovery/gologger"
var printed = false

const (
Version = "v0.1.1"
Version = "v0.1.2"
banner = ` ____ _
/ __/___ __ __(_)_______ _________ ____
/ /_/ __ ` + `\/ | / / / ___/ _ \/ ___/ __ \/ __ \
Expand Down
20 changes: 15 additions & 5 deletions pkg/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4aa8b68

Please sign in to comment.