Skip to content

Commit

Permalink
Merge pull request #213 from Marmelatze/json-requests-dns
Browse files Browse the repository at this point in the history
add json-requests for DNS
  • Loading branch information
ehsandeep committed Aug 13, 2020
2 parents e22213f + 7a1aa77 commit 2dfd245
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ This will display help for the tool. Here are all the switches it supports.
| -t | Templates input file/files to check across hosts | nuclei -t nuclei-templates/cves/ |
| -nC | Don't Use colors in output | nuclei -nC |
| -json | Prints and write output in json format | nuclei -json |
| -json-requests | Write requests/responses for matches in JSON output | nuclei -json -json-requests |
| -o | File to save output result (optional) | nuclei -o output.txt |
| -pbar | Enable the progress bar (optional) | nuclei -pbar |
| -silent | Show only found results in output | nuclei -silent |
Expand Down
35 changes: 18 additions & 17 deletions v2/internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,14 +466,15 @@ func (r *Runner) processTemplateWithList(p progress.IProgress, template *templat
switch value := request.(type) {
case *requests.DNSRequest:
dnsExecuter = executer.NewDNSExecuter(&executer.DNSOptions{
Debug: r.options.Debug,
Template: template,
DNSRequest: value,
Writer: writer,
JSON: r.options.JSON,
ColoredOutput: !r.options.NoColor,
Colorizer: r.colorizer,
Decolorizer: r.decolorizer,
Debug: r.options.Debug,
Template: template,
DNSRequest: value,
Writer: writer,
JSON: r.options.JSON,
JSONRequests: r.options.JSONRequests,
ColoredOutput: !r.options.NoColor,
Colorizer: r.colorizer,
Decolorizer: r.decolorizer,
})
case *requests.BulkHTTPRequest:
httpExecuter, err = executer.NewHTTPExecuter(&executer.HTTPOptions{
Expand Down Expand Up @@ -609,18 +610,18 @@ func (r *Runner) ProcessWorkflow(p progress.IProgress, workflow *workflows.Workf
ProxySocksURL: r.options.ProxySocksURL,
CustomHeaders: r.options.CustomHeaders,
CookieJar: jar,
ColoredOutput: !r.options.NoColor,
Colorizer: r.colorizer,
Decolorizer: r.decolorizer,
ColoredOutput: !r.options.NoColor,
Colorizer: r.colorizer,
Decolorizer: r.decolorizer,
}
} else if len(t.RequestsDNS) > 0 {
template.DNSOptions = &executer.DNSOptions{
Debug: r.options.Debug,
Template: t,
Writer: writer,
ColoredOutput: !r.options.NoColor,
Colorizer: r.colorizer,
Decolorizer: r.decolorizer,
Debug: r.options.Debug,
Template: t,
Writer: writer,
ColoredOutput: !r.options.NoColor,
Colorizer: r.colorizer,
Decolorizer: r.decolorizer,
}
}
if template.DNSOptions != nil || template.HTTPOptions != nil {
Expand Down
17 changes: 10 additions & 7 deletions v2/pkg/executer/executer_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
type DNSExecuter struct {
debug bool
jsonOutput bool
jsonRequest bool
Results bool
dnsClient *retryabledns.Client
template *templates.Template
Expand All @@ -44,11 +45,12 @@ var DefaultResolvers = []string{

// DNSOptions contains configuration options for the DNS executer.
type DNSOptions struct {
Debug bool
JSON bool
Template *templates.Template
DNSRequest *requests.DNSRequest
Writer *bufio.Writer
Debug bool
JSON bool
JSONRequests bool
Template *templates.Template
DNSRequest *requests.DNSRequest
Writer *bufio.Writer

ColoredOutput bool
Colorizer aurora.Aurora
Expand All @@ -63,6 +65,7 @@ func NewDNSExecuter(options *DNSOptions) *DNSExecuter {
executer := &DNSExecuter{
debug: options.Debug,
jsonOutput: options.JSON,
jsonRequest: options.JSONRequests,
dnsClient: dnsClient,
template: options.Template,
dnsRequest: options.DNSRequest,
Expand Down Expand Up @@ -127,7 +130,7 @@ func (e *DNSExecuter) ExecuteDNS(p progress.IProgress, URL string) (result Resul
// If the matcher has matched, and its an OR
// write the first output then move to next matcher.
if matcherCondition == matchers.ORCondition && len(e.dnsRequest.Extractors) == 0 {
e.writeOutputDNS(domain, matcher, nil)
e.writeOutputDNS(domain, compiledRequest, resp, matcher, nil)
result.GotResults = true
}
}
Expand All @@ -147,7 +150,7 @@ func (e *DNSExecuter) ExecuteDNS(p progress.IProgress, URL string) (result Resul
// Write a final string of output if matcher type is
// AND or if we have extractors for the mechanism too.
if len(e.dnsRequest.Extractors) > 0 || matcherCondition == matchers.ANDCondition {
e.writeOutputDNS(domain, nil, extractorResults)
e.writeOutputDNS(domain, compiledRequest, resp, nil, extractorResults)
result.GotResults = true
}

Expand Down
7 changes: 6 additions & 1 deletion v2/pkg/executer/output_dns.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package executer

import (
"github.com/miekg/dns"
"strings"

jsoniter "github.com/json-iterator/go"
Expand All @@ -9,7 +10,7 @@ import (
)

// writeOutputDNS writes dns output to streams
func (e *DNSExecuter) writeOutputDNS(domain string, matcher *matchers.Matcher, extractorResults []string) {
func (e *DNSExecuter) writeOutputDNS(domain string, req *dns.Msg, resp *dns.Msg, matcher *matchers.Matcher, extractorResults []string) {
if e.jsonOutput {
output := jsonOutput{
Template: e.template.ID,
Expand All @@ -25,6 +26,10 @@ func (e *DNSExecuter) writeOutputDNS(domain string, matcher *matchers.Matcher, e
if len(extractorResults) > 0 {
output.ExtractedResults = extractorResults
}
if e.jsonRequest {
output.Request = req.String()
output.Response = resp.String()
}
data, err := jsoniter.Marshal(output)
if err != nil {
gologger.Warningf("Could not marshal json output: %s\n", err)
Expand Down

0 comments on commit 2dfd245

Please sign in to comment.