Skip to content

Commit 4aa8b68

Browse files
committed
Add JSON Output #312
1 parent 159d210 commit 4aa8b68

File tree

7 files changed

+39
-14
lines changed

7 files changed

+39
-14
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ OUTPUT:
8484
-o, -output string File to write output results
8585
-v, -verbose Verbose output
8686
-s, -silent Silent output. Print only results
87+
-j, -json JSON output
8788
```
8889

8990
Examples 💡
@@ -127,6 +128,12 @@ Use a Proxy
127128
favirecon -u https://www.github.com -px http://127.0.0.1:8080
128129
```
129130

131+
JSON Output
132+
133+
```console
134+
favirecon -u https://www.github.com -j
135+
```
136+
130137
Changelog 📌
131138
-------
132139

go.mod

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ require (
77
github.com/projectdiscovery/goflags v0.1.54
88
github.com/projectdiscovery/gologger v1.1.12
99
github.com/projectdiscovery/utils v0.1.0
10+
go.uber.org/ratelimit v0.3.1
11+
github.com/stretchr/testify v1.9.0
12+
github.com/twmb/murmur3 v1.1.8
13+
github.com/projectdiscovery/mapcidr v1.1.34
1014
)
1115

1216
require (
@@ -29,9 +33,6 @@ require (
2933
golang.org/x/mod v0.13.0 // indirect
3034
golang.org/x/sys v0.18.0 // indirect
3135
golang.org/x/tools v0.14.0 // indirect
32-
)
33-
34-
require (
3536
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
3637
github.com/aymerick/douceur v0.2.0 // indirect
3738
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 // indirect
@@ -45,13 +46,9 @@ require (
4546
github.com/modern-go/reflect2 v1.0.2 // indirect
4647
github.com/nwaples/rardecode v1.1.3 // indirect
4748
github.com/pkg/errors v0.9.1 // indirect
48-
github.com/projectdiscovery/mapcidr v1.1.34
4949
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
50-
github.com/stretchr/testify v1.9.0
51-
github.com/twmb/murmur3 v1.1.8
5250
github.com/ulikunitz/xz v0.5.11 // indirect
5351
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
54-
go.uber.org/ratelimit v0.3.1
5552
golang.org/x/net v0.23.0 // indirect
5653
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
5754
gopkg.in/yaml.v3 v3.0.1 // indirect

pkg/favirecon/favirecon.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ func writeOutput(wg *sync.WaitGroup, m *sync.Mutex, options *input.Options, o ou
202202

203203
out := o.Format()
204204

205+
if options.JSON {
206+
outJSON, err := o.FormatJSON()
207+
if err != nil {
208+
gologger.Fatal().Msg(err.Error())
209+
}
210+
211+
out = string(outJSON)
212+
}
213+
205214
if options.Output != nil {
206215
if _, err := options.Output.Write([]byte(out + "\n")); err != nil && options.Verbose {
207216
gologger.Fatal().Msg(err.Error())

pkg/input/flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Options struct {
3838
Cidr bool
3939
RateLimit int
4040
Proxy string
41+
JSON bool
4142
}
4243

4344
// configureOutput configures the output on the screen.
@@ -76,6 +77,7 @@ func ParseOptions() *Options {
7677
flagSet.StringVarP(&options.FileOutput, "output", "o", "", `File to write output results`),
7778
flagSet.BoolVarP(&options.Verbose, "verbose", "v", false, `Verbose output`),
7879
flagSet.BoolVarP(&options.Silent, "silent", "s", false, `Silent output. Print only results`),
80+
flagSet.BoolVarP(&options.JSON, "json", "j", false, `JSON output`),
7981
)
8082

8183
if help() || noArgs() {

pkg/output/banner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import "github.com/projectdiscovery/gologger"
1212
var printed = false
1313

1414
const (
15-
Version = "v0.1.1"
15+
Version = "v0.1.2"
1616
banner = ` ____ _
1717
/ __/___ __ __(_)_______ _________ ____
1818
/ /_/ __ ` + `\/ | / / / ___/ _ \/ ___/ __ \/ __ \

pkg/output/output.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ This repository is under MIT License https://github.com/edoardottt/favirecon/blo
77
package output
88

99
import (
10+
"encoding/json"
1011
"fmt"
1112
"sync"
1213
)
1314

1415
type Found struct {
15-
URL string
16-
Hash string
17-
Name string
16+
URL string `json:"URL,omitempty"`
17+
Hash string `json:"Hash,omitempty"`
18+
Name string `json:"Name,omitempty"`
1819
}
1920

2021
type Result struct {
@@ -30,8 +31,7 @@ func New() Result {
3031
}
3132
}
3233

33-
// Printed checks if a string has been previously
34-
// printed.
34+
// Printed checks if a string has been previously printed.
3535
func (o *Result) Printed(found string) bool {
3636
o.Mutex.RLock()
3737
if _, ok := o.Map[found]; !ok {
@@ -52,3 +52,13 @@ func (o *Result) Printed(found string) bool {
5252
func (f *Found) Format() string {
5353
return fmt.Sprintf("[%s] [%s] %s", f.Hash, f.Name, f.URL)
5454
}
55+
56+
// FormatJSON returns the input as JSON string.
57+
func (f *Found) FormatJSON() ([]byte, error) {
58+
jsonOutput, err := json.Marshal(f)
59+
if err != nil {
60+
return nil, err
61+
}
62+
63+
return jsonOutput, nil
64+
}

snapcraft.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ summary: Use favicon.ico to improve your target recon phase
33
description: |
44
Use favicon.ico to improve your target recon phase.
55
Quickly detect technologies, WAF, exposed panels, known services.
6-
version: 0.1.1
6+
version: 0.1.2
77
grade: stable
88
base: core20
99

0 commit comments

Comments
 (0)