mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 09:55:25 +00:00
Add support for DNS requests
This commit is contained in:
parent
ea6229300d
commit
4d8131c8d8
@ -290,7 +290,8 @@ func (r *Runner) RunEnumeration() {
|
|||||||
case *templates.Template:
|
case *templates.Template:
|
||||||
barIndex++
|
barIndex++
|
||||||
template := t.(*templates.Template)
|
template := t.(*templates.Template)
|
||||||
totalRequests += template.GetHTTPRequestsCount()
|
totalRequests += template.GetHTTPRequestCount()
|
||||||
|
totalRequests += template.GetDNSRequestCount()
|
||||||
parsedTemplates = append(parsedTemplates, match)
|
parsedTemplates = append(parsedTemplates, match)
|
||||||
default:
|
default:
|
||||||
gologger.Errorf("Could not parse file '%s': %s\n", match, err)
|
gologger.Errorf("Could not parse file '%s': %s\n", match, err)
|
||||||
@ -426,7 +427,7 @@ func (r *Runner) processTemplateWithList(p *progress.Progress, template *templat
|
|||||||
globalresult.Or(result.GotResults)
|
globalresult.Or(result.GotResults)
|
||||||
}
|
}
|
||||||
if dnsExecuter != nil {
|
if dnsExecuter != nil {
|
||||||
result = dnsExecuter.ExecuteDNS(URL)
|
result = dnsExecuter.ExecuteDNS(p, URL)
|
||||||
globalresult.Or(result.GotResults)
|
globalresult.Or(result.GotResults)
|
||||||
}
|
}
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package executer
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/projectdiscovery/nuclei/v2/internal/progress"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ func NewDNSExecuter(options *DNSOptions) *DNSExecuter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ExecuteDNS executes the DNS request on a URL
|
// ExecuteDNS executes the DNS request on a URL
|
||||||
func (e *DNSExecuter) ExecuteDNS(URL string) (result Result) {
|
func (e *DNSExecuter) ExecuteDNS(p *progress.Progress, URL string) (result Result) {
|
||||||
// Parse the URL and return domain if URL.
|
// Parse the URL and return domain if URL.
|
||||||
var domain string
|
var domain string
|
||||||
if isURL(URL) {
|
if isURL(URL) {
|
||||||
@ -75,26 +76,34 @@ func (e *DNSExecuter) ExecuteDNS(URL string) (result Result) {
|
|||||||
compiledRequest, err := e.dnsRequest.MakeDNSRequest(domain)
|
compiledRequest, err := e.dnsRequest.MakeDNSRequest(domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Error = errors.Wrap(err, "could not make dns request")
|
result.Error = errors.Wrap(err, "could not make dns request")
|
||||||
|
p.Drop(1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.debug {
|
if e.debug {
|
||||||
|
p.StartStdCapture()
|
||||||
gologger.Infof("Dumped DNS request for %s (%s)\n\n", URL, e.template.ID)
|
gologger.Infof("Dumped DNS request for %s (%s)\n\n", URL, e.template.ID)
|
||||||
fmt.Fprintf(os.Stderr, "%s\n", compiledRequest.String())
|
fmt.Fprintf(os.Stderr, "%s\n", compiledRequest.String())
|
||||||
|
p.StopStdCapture()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the request to the target servers
|
// Send the request to the target servers
|
||||||
resp, err := e.dnsClient.Do(compiledRequest)
|
resp, err := e.dnsClient.Do(compiledRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Error = errors.Wrap(err, "could not send dns request")
|
result.Error = errors.Wrap(err, "could not send dns request")
|
||||||
|
p.Drop(1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.Update()
|
||||||
|
|
||||||
gologger.Verbosef("Sent DNS request to %s\n", "dns-request", URL)
|
gologger.Verbosef("Sent DNS request to %s\n", "dns-request", URL)
|
||||||
|
|
||||||
if e.debug {
|
if e.debug {
|
||||||
|
p.StartStdCapture()
|
||||||
gologger.Infof("Dumped DNS response for %s (%s)\n\n", URL, e.template.ID)
|
gologger.Infof("Dumped DNS response for %s (%s)\n\n", URL, e.template.ID)
|
||||||
fmt.Fprintf(os.Stderr, "%s\n", resp.String())
|
fmt.Fprintf(os.Stderr, "%s\n", resp.String())
|
||||||
|
p.StopStdCapture()
|
||||||
}
|
}
|
||||||
|
|
||||||
matcherCondition := e.dnsRequest.GetMatchersCondition()
|
matcherCondition := e.dnsRequest.GetMatchersCondition()
|
||||||
@ -109,7 +118,9 @@ func (e *DNSExecuter) ExecuteDNS(URL string) (result Result) {
|
|||||||
// If the matcher has matched, and its an OR
|
// If the matcher has matched, and its an OR
|
||||||
// write the first output then move to next matcher.
|
// write the first output then move to next matcher.
|
||||||
if matcherCondition == matchers.ORCondition && len(e.dnsRequest.Extractors) == 0 {
|
if matcherCondition == matchers.ORCondition && len(e.dnsRequest.Extractors) == 0 {
|
||||||
|
p.StartStdCapture()
|
||||||
e.writeOutputDNS(domain, matcher, nil)
|
e.writeOutputDNS(domain, matcher, nil)
|
||||||
|
p.StopStdCapture()
|
||||||
result.GotResults = true
|
result.GotResults = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,7 +140,9 @@ func (e *DNSExecuter) ExecuteDNS(URL string) (result Result) {
|
|||||||
// Write a final string of output if matcher type is
|
// Write a final string of output if matcher type is
|
||||||
// AND or if we have extractors for the mechanism too.
|
// AND or if we have extractors for the mechanism too.
|
||||||
if len(e.dnsRequest.Extractors) > 0 || matcherCondition == matchers.ANDCondition {
|
if len(e.dnsRequest.Extractors) > 0 || matcherCondition == matchers.ANDCondition {
|
||||||
|
p.StartStdCapture()
|
||||||
e.writeOutputDNS(domain, nil, extractorResults)
|
e.writeOutputDNS(domain, nil, extractorResults)
|
||||||
|
p.StopStdCapture()
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@ -111,7 +111,7 @@ func (e *HTTPExecuter) ExecuteHTTP(p *progress.Progress, URL string) (result Res
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
remaining := e.template.GetHTTPRequestsCount()
|
remaining := e.template.GetHTTPRequestCount()
|
||||||
|
|
||||||
e.bulkHttpRequest.CreateGenerator(URL)
|
e.bulkHttpRequest.CreateGenerator(URL)
|
||||||
for e.bulkHttpRequest.Next(URL) && !result.Done {
|
for e.bulkHttpRequest.Next(URL) && !result.Done {
|
||||||
|
|||||||
@ -42,6 +42,11 @@ func (r *DNSRequest) SetMatchersCondition(condition matchers.ConditionType) {
|
|||||||
r.matchersCondition = condition
|
r.matchersCondition = condition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the total number of requests the YAML rule will perform
|
||||||
|
func (r *DNSRequest) GetRequestCount() int64 {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
// MakeDNSRequest creates a *dns.Request from a request template
|
// MakeDNSRequest creates a *dns.Request from a request template
|
||||||
func (r *DNSRequest) MakeDNSRequest(domain string) (*dns.Msg, error) {
|
func (r *DNSRequest) MakeDNSRequest(domain string) (*dns.Msg, error) {
|
||||||
domain = dns.Fqdn(domain)
|
domain = dns.Fqdn(domain)
|
||||||
|
|||||||
@ -28,10 +28,18 @@ type Info struct {
|
|||||||
Description string `yaml:"description,omitempty"`
|
Description string `yaml:"description,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t* Template) GetHTTPRequestsCount() int64 {
|
func (t* Template) GetHTTPRequestCount() int64 {
|
||||||
var count int64 = 0
|
var count int64 = 0
|
||||||
for _, request := range t.BulkRequestsHTTP {
|
for _, request := range t.BulkRequestsHTTP {
|
||||||
count += request.GetRequestCount()
|
count += request.GetRequestCount()
|
||||||
}
|
}
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Template) GetDNSRequestCount() int64 {
|
||||||
|
var count int64 = 0
|
||||||
|
for _, request := range t.RequestsDNS {
|
||||||
|
count += request.GetRequestCount()
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
@ -86,7 +86,7 @@ func (n *NucleiVar) Call(args ...tengo.Object) (ret tengo.Object, err error) {
|
|||||||
for _, request := range template.DNSOptions.Template.RequestsDNS {
|
for _, request := range template.DNSOptions.Template.RequestsDNS {
|
||||||
template.DNSOptions.DNSRequest = request
|
template.DNSOptions.DNSRequest = request
|
||||||
dnsExecuter := executer.NewDNSExecuter(template.DNSOptions)
|
dnsExecuter := executer.NewDNSExecuter(template.DNSOptions)
|
||||||
result := dnsExecuter.ExecuteDNS(n.URL)
|
result := dnsExecuter.ExecuteDNS(p,n.URL)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
gologger.Warningf("Could not compile request for template '%s': %s\n", template.HTTPOptions.Template.ID, result.Error)
|
gologger.Warningf("Could not compile request for template '%s': %s\n", template.HTTPOptions.Template.ID, result.Error)
|
||||||
continue
|
continue
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user