From 36afb466c3e6ad544e994653cd9ccb80db4a8d43 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Thu, 4 Jun 2020 01:21:08 +0200 Subject: [PATCH] corrected json output --- go.mod | 2 +- go.sum | 4 ++-- pkg/runner/enumerate.go | 17 +++++++++++++++-- pkg/runner/options.go | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index ba92c1d7..e8cb2a2a 100644 --- a/go.mod +++ b/go.mod @@ -7,5 +7,5 @@ require ( github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 github.com/projectdiscovery/gologger v1.0.0 github.com/remeh/sizedwaitgroup v1.0.0 - golang.org/x/net v0.0.0-20200528225125-3c3fba18258b + golang.org/x/net v0.0.0-20200602114024-627f9648deb9 ) diff --git a/go.sum b/go.sum index 6da9e75a..d05fd0f4 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20200528225125-3c3fba18258b h1:IYiJPiJfzktmDAO1HQiwjMjwjlYKHAL7KzeD544RJPs= -golang.org/x/net v0.0.0-20200528225125-3c3fba18258b/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM= +golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= diff --git a/pkg/runner/enumerate.go b/pkg/runner/enumerate.go index 172e5747..d428fd58 100644 --- a/pkg/runner/enumerate.go +++ b/pkg/runner/enumerate.go @@ -1,6 +1,7 @@ package runner import ( + "encoding/json" "net" "os" "time" @@ -100,8 +101,20 @@ func (r *Runner) EnumerateSingleHost(host string, ports map[int]struct{}, output } gologger.Infof("Found %d ports on host %s (%s)\n", len(results), host, hostIP) - for port := range results { - gologger.Silentf("%s:%d\n", host, port) + if r.options.JSON { + data := JSONResult{Host: host} + for port := range results { + data.Port = port + b, err := json.Marshal(data) + if err != nil { + continue + } + gologger.Silentf("%s\n", string(b)) + } + } else { + for port := range results { + gologger.Silentf("%s:%d\n", host, port) + } } // In case the user has given an output file, write all the found diff --git a/pkg/runner/options.go b/pkg/runner/options.go index e351c3bb..a87e9140 100644 --- a/pkg/runner/options.go +++ b/pkg/runner/options.go @@ -43,7 +43,7 @@ func ParseOptions() *Options { flag.StringVar(&options.PortsFile, "ports-file", "", "File containing ports to enumerate for on hosts") flag.StringVar(&options.Output, "o", "", "File to write output to (optional)") flag.StringVar(&options.OutputDirectory, "oD", "", "Directory to write enumeration results to (optional)") - flag.BoolVar(&options.JSON, "oJ", false, "Write output in JSON lines Format") + flag.BoolVar(&options.JSON, "json", false, "Write output in JSON lines Format") flag.BoolVar(&options.Silent, "silent", false, "Show only host:ports in output") flag.IntVar(&options.Retries, "retries", 1, "Number of retries for the port scan probe") flag.IntVar(&options.Rate, "rate", 1000, "Rate of port scan probe requests")