mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 23:05:26 +00:00
Compiling templates + misc stuff
This commit is contained in:
parent
62603b7d5f
commit
088c8770cc
@ -239,22 +239,19 @@ func (r *Runner) RunEnumeration() {
|
|||||||
|
|
||||||
for _, t := range availableTemplates {
|
for _, t := range availableTemplates {
|
||||||
wgtemplates.Add()
|
wgtemplates.Add()
|
||||||
go func(template interface{}) {
|
go func(template *templates.Template) {
|
||||||
defer wgtemplates.Done()
|
if template.Workflow != nil {
|
||||||
switch tt := template.(type) {
|
|
||||||
case *templates.Template:
|
|
||||||
for _, request := range tt.RequestsDNS {
|
|
||||||
results.Or(r.processTemplateWithList(p, tt, request))
|
|
||||||
}
|
|
||||||
for _, request := range tt.BulkRequestsHTTP {
|
|
||||||
results.Or(r.processTemplateWithList(p, tt, request))
|
|
||||||
}
|
|
||||||
case *workflows.Workflow:
|
|
||||||
results.Or(r.processWorkflowWithList(p, template.(*workflows.Workflow)))
|
results.Or(r.processWorkflowWithList(p, template.(*workflows.Workflow)))
|
||||||
|
|
||||||
|
}
|
||||||
|
for _, request := range template.RequestsDNS {
|
||||||
|
results.Or(r.processTemplateWithList(p, tt, request))
|
||||||
|
}
|
||||||
|
for _, request := range template.RequestsHTTP {
|
||||||
|
results.Or(r.processTemplateWithList(p, tt, request))
|
||||||
}
|
}
|
||||||
}(t)
|
}(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
wgtemplates.Wait()
|
wgtemplates.Wait()
|
||||||
p.Stop()
|
p.Stop()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,8 @@ import (
|
|||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
||||||
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns"
|
||||||
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/http"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,23 +32,32 @@ func Parse(file string, options *protocols.ExecuterOptions) (*Template, error) {
|
|||||||
options.TemplateInfo = template.Info
|
options.TemplateInfo = template.Info
|
||||||
options.TemplatePath = file
|
options.TemplatePath = file
|
||||||
|
|
||||||
|
// We don't support both http and dns in a single template
|
||||||
|
if len(template.RequestsDNS) > 0 && len(template.RequestsHTTP) > 0 {
|
||||||
|
return nil, fmt.Errorf("both http and dns requests for %s", template.ID)
|
||||||
|
}
|
||||||
// If no requests, and it is also not a workflow, return error.
|
// If no requests, and it is also not a workflow, return error.
|
||||||
if len(template.RequestsDNS)+len(template.RequestsDNS)+len(template.Workflows) <= 0 {
|
if len(template.RequestsDNS)+len(template.RequestsDNS)+len(template.Workflows) == 0 {
|
||||||
return nil, fmt.Errorf("no requests defined for %s", template.ID)
|
return nil, fmt.Errorf("no requests defined for %s", template.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile the requests found
|
// Compile the requests found
|
||||||
for _, request := range template.RequestsDNS {
|
for _, request := range template.RequestsDNS {
|
||||||
if err := request.Compile(options); err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not compile dns request")
|
|
||||||
}
|
|
||||||
template.totalRequests += request.Requests()
|
template.totalRequests += request.Requests()
|
||||||
}
|
}
|
||||||
for _, request := range template.RequestsHTTP {
|
for _, request := range template.RequestsHTTP {
|
||||||
if err := request.Compile(options); err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not compile dns request")
|
|
||||||
}
|
|
||||||
template.totalRequests += request.Requests()
|
template.totalRequests += request.Requests()
|
||||||
}
|
}
|
||||||
|
if len(template.RequestsDNS) > 0 {
|
||||||
|
template.executer = dns.NewExecuter(template.RequestsDNS, options)
|
||||||
|
err = template.executer.Compile()
|
||||||
|
}
|
||||||
|
if len(template.RequestsHTTP) > 0 {
|
||||||
|
template.executer = http.NewExecuter(template.RequestsHTTP, options)
|
||||||
|
err = template.executer.Compile()
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "could not compile request")
|
||||||
|
}
|
||||||
return template, nil
|
return template, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/http"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/http"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/workflows"
|
"github.com/projectdiscovery/nuclei/v2/pkg/workflows"
|
||||||
@ -22,6 +23,7 @@ type Template struct {
|
|||||||
|
|
||||||
path string
|
path string
|
||||||
totalRequests int
|
totalRequests int
|
||||||
|
executer protocols.Executer
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPath returns the path of the template.
|
// GetPath returns the path of the template.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user