Skip to content

Commit

Permalink
Added -no-meta flag to ignore meta
Browse files Browse the repository at this point in the history
  • Loading branch information
Ice3man543 committed Oct 19, 2020
1 parent b194472 commit 4ec229e
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 77 deletions.
3 changes: 2 additions & 1 deletion v2/internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Options struct {
Stdin bool // Stdin specifies whether stdin input was given to the process
StopAtFirstMatch bool // Stop processing template at first full match (this may break chained requests)
BulkSize int // Number of targets analyzed in parallel for each template
NoMeta bool // Don't display metadata for the matches
}

type multiStringFlag []string
Expand Down Expand Up @@ -82,7 +83,7 @@ func ParseOptions() *Options {
flag.IntVar(&options.RateLimit, "rate-limit", -1, "Per Target Rate-Limit")
flag.BoolVar(&options.StopAtFirstMatch, "stop-at-first-match", false, "Stop processing http requests at first match (this may break template/workflow logic)")
flag.IntVar(&options.BulkSize, "bulk-size", 150, "Number of hosts analyzed in parallel per template")

flag.BoolVar(&options.NoMeta, "no-meta", false, "Don't display metadata for the matches")
flag.Parse()

// Check if stdin pipe was given
Expand Down
2 changes: 2 additions & 0 deletions v2/internal/runner/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (r *Runner) processTemplateWithList(p progress.IProgress, template *templat
Writer: r.output,
JSON: r.options.JSON,
JSONRequests: r.options.JSONRequests,
NoMeta: r.options.NoMeta,
ColoredOutput: !r.options.NoColor,
Colorizer: r.colorizer,
Decolorizer: r.decolorizer,
Expand All @@ -62,6 +63,7 @@ func (r *Runner) processTemplateWithList(p progress.IProgress, template *templat
CustomHeaders: r.options.CustomHeaders,
JSON: r.options.JSON,
JSONRequests: r.options.JSONRequests,
NoMeta: r.options.NoMeta,
CookieReuse: value.CookieReuse,
ColoredOutput: !r.options.NoColor,
Colorizer: &r.colorizer,
Expand Down
3 changes: 3 additions & 0 deletions v2/pkg/executer/executer_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type DNSExecuter struct {
debug bool
jsonOutput bool
jsonRequest bool
noMeta bool
Results bool
dnsClient *retryabledns.Client
template *templates.Template
Expand All @@ -47,6 +48,7 @@ type DNSOptions struct {
Debug bool
JSON bool
JSONRequests bool
NoMeta bool
Template *templates.Template
DNSRequest *requests.DNSRequest
Writer *bufwriter.Writer
Expand All @@ -62,6 +64,7 @@ func NewDNSExecuter(options *DNSOptions) *DNSExecuter {

executer := &DNSExecuter{
debug: options.Debug,
noMeta: options.NoMeta,
jsonOutput: options.JSON,
jsonRequest: options.JSONRequests,
dnsClient: dnsClient,
Expand Down
3 changes: 3 additions & 0 deletions v2/pkg/executer/executer_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type HTTPExecuter struct {
Results bool
jsonOutput bool
jsonRequest bool
noMeta bool
stopAtFirstMatch bool
}

Expand All @@ -74,6 +75,7 @@ type HTTPOptions struct {
Debug bool
JSON bool
JSONRequests bool
NoMeta bool
CookieReuse bool
ColoredOutput bool
StopAtFirstMatch bool
Expand Down Expand Up @@ -119,6 +121,7 @@ func NewHTTPExecuter(options *HTTPOptions) (*HTTPExecuter, error) {
debug: options.Debug,
jsonOutput: options.JSON,
jsonRequest: options.JSONRequests,
noMeta: options.NoMeta,
httpClient: client,
rawHTTPClient: rawClient,
template: options.Template,
Expand Down
64 changes: 33 additions & 31 deletions v2/pkg/executer/output_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ import (
func (e *DNSExecuter) writeOutputDNS(domain string, req, resp *dns.Msg, matcher *matchers.Matcher, extractorResults []string) {
if e.jsonOutput {
output := make(jsonOutput)
output["template"] = e.template.ID
output["type"] = "dns"
output["matched"] = domain
for k, v := range e.template.Info {
output[k] = v
}
if matcher != nil && len(matcher.Name) > 0 {
output["matcher_name"] = matcher.Name
}
if len(extractorResults) > 0 {
output["extracted_results"] = extractorResults
}
if e.jsonRequest {
output["request"] = req.String()
output["response"] = resp.String()

if !e.noMeta {
output["template"] = e.template.ID
output["type"] = "dns"
for k, v := range e.template.Info {
output[k] = v
}
if matcher != nil && len(matcher.Name) > 0 {
output["matcher_name"] = matcher.Name
}
if len(extractorResults) > 0 {
output["extracted_results"] = extractorResults
}
if e.jsonRequest {
output["request"] = req.String()
output["response"] = resp.String()
}
}

data, err := jsoniter.Marshal(output)
Expand All @@ -49,28 +52,29 @@ func (e *DNSExecuter) writeOutputDNS(domain string, req, resp *dns.Msg, matcher
builder := &strings.Builder{}
colorizer := e.colorizer

builder.WriteRune('[')
builder.WriteString(colorizer.Colorizer.BrightGreen(e.template.ID).String())
if !e.noMeta {
builder.WriteRune('[')
builder.WriteString(colorizer.Colorizer.BrightGreen(e.template.ID).String())

if matcher != nil && len(matcher.Name) > 0 {
builder.WriteString(":")
builder.WriteString(colorizer.Colorizer.BrightGreen(matcher.Name).Bold().String())
}

builder.WriteString("] [")
builder.WriteString(colorizer.Colorizer.BrightBlue("dns").String())
builder.WriteString("] ")
if matcher != nil && len(matcher.Name) > 0 {
builder.WriteString(":")
builder.WriteString(colorizer.Colorizer.BrightGreen(matcher.Name).Bold().String())
}

if e.template.Info["severity"] != "" {
builder.WriteString("[")
builder.WriteString(colorizer.GetColorizedSeverity(e.template.Info["severity"]))
builder.WriteString("] [")
builder.WriteString(colorizer.Colorizer.BrightBlue("dns").String())
builder.WriteString("] ")
}

if e.template.Info["severity"] != "" {
builder.WriteString("[")
builder.WriteString(colorizer.GetColorizedSeverity(e.template.Info["severity"]))
builder.WriteString("] ")
}
}
builder.WriteString(domain)

// If any extractors, write the results
if len(extractorResults) > 0 {
if len(extractorResults) > 0 && !e.noMeta {
builder.WriteString(" [")

for i, result := range extractorResults {
Expand All @@ -80,10 +84,8 @@ func (e *DNSExecuter) writeOutputDNS(domain string, req, resp *dns.Msg, matcher
builder.WriteRune(',')
}
}

builder.WriteString("]")
}

builder.WriteRune('\n')

// Write output to screen as well as any output file
Expand Down
92 changes: 47 additions & 45 deletions v2/pkg/executer/output_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,48 @@ import (
// writeOutputHTTP writes http output to streams
func (e *HTTPExecuter) writeOutputHTTP(req *requests.HTTPRequest, resp *http.Response, body string, matcher *matchers.Matcher, extractorResults []string, meta map[string]interface{}) {
var URL string
// rawhttp
if req.RawRequest != nil {
URL = req.RawRequest.FullURL
}
// retryablehttp
if req.Request != nil {
URL = req.Request.URL.String()
}

if e.jsonOutput {
output := make(jsonOutput)
output["template"] = e.template.ID
output["type"] = "http"
output["matched"] = URL
if len(meta) > 0 {
output["meta"] = meta
}
for k, v := range e.template.Info {
output[k] = v
}
if matcher != nil && len(matcher.Name) > 0 {
output["matcher_name"] = matcher.Name
}
if len(extractorResults) > 0 {
output["extracted_results"] = extractorResults
}

// TODO: URL should be an argument
if e.jsonRequest {
dumpedRequest, err := requests.Dump(req, URL)
if err != nil {
gologger.Warningf("could not dump request: %s\n", err)
} else {
output["request"] = string(dumpedRequest)
output["matched"] = URL
if !e.noMeta {
output["template"] = e.template.ID
output["type"] = "http"
if len(meta) > 0 {
output["meta"] = meta
}
for k, v := range e.template.Info {
output[k] = v
}
if matcher != nil && len(matcher.Name) > 0 {
output["matcher_name"] = matcher.Name
}
if len(extractorResults) > 0 {
output["extracted_results"] = extractorResults
}

dumpedResponse, err := httputil.DumpResponse(resp, false)
if err != nil {
gologger.Warningf("could not dump response: %s\n", err)
} else {
output["response"] = string(dumpedResponse) + body
// TODO: URL should be an argument
if e.jsonRequest {
dumpedRequest, err := requests.Dump(req, URL)
if err != nil {
gologger.Warningf("could not dump request: %s\n", err)
} else {
output["request"] = string(dumpedRequest)
}

dumpedResponse, err := httputil.DumpResponse(resp, false)
if err != nil {
gologger.Warningf("could not dump response: %s\n", err)
} else {
output["response"] = string(dumpedResponse) + body
}
}
}

Expand All @@ -76,28 +77,29 @@ func (e *HTTPExecuter) writeOutputHTTP(req *requests.HTTPRequest, resp *http.Res
builder := &strings.Builder{}
colorizer := e.colorizer

builder.WriteRune('[')
builder.WriteString(colorizer.Colorizer.BrightGreen(e.template.ID).String())

if matcher != nil && len(matcher.Name) > 0 {
builder.WriteString(":")
builder.WriteString(colorizer.Colorizer.BrightGreen(matcher.Name).Bold().String())
}
if !e.noMeta {
builder.WriteRune('[')
builder.WriteString(colorizer.Colorizer.BrightGreen(e.template.ID).String())

builder.WriteString("] [")
builder.WriteString(colorizer.Colorizer.BrightBlue("http").String())
builder.WriteString("] ")
if matcher != nil && len(matcher.Name) > 0 {
builder.WriteString(":")
builder.WriteString(colorizer.Colorizer.BrightGreen(matcher.Name).Bold().String())
}

if e.template.Info["severity"] != "" {
builder.WriteString("[")
builder.WriteString(colorizer.GetColorizedSeverity(e.template.Info["severity"]))
builder.WriteString("] [")
builder.WriteString(colorizer.Colorizer.BrightBlue("http").String())
builder.WriteString("] ")
}

if e.template.Info["severity"] != "" {
builder.WriteString("[")
builder.WriteString(colorizer.GetColorizedSeverity(e.template.Info["severity"]))
builder.WriteString("] ")
}
}
builder.WriteString(URL)

// If any extractors, write the results
if len(extractorResults) > 0 {
if len(extractorResults) > 0 && !e.noMeta {
builder.WriteString(" [")

for i, result := range extractorResults {
Expand All @@ -112,7 +114,7 @@ func (e *HTTPExecuter) writeOutputHTTP(req *requests.HTTPRequest, resp *http.Res
}

// write meta if any
if len(req.Meta) > 0 {
if len(req.Meta) > 0 && !e.noMeta {
builder.WriteString(" [")

var metas []string
Expand Down

0 comments on commit 4ec229e

Please sign in to comment.