mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 00:15:28 +00:00
Moved variables to template level + misc
This commit is contained in:
parent
d09e71accf
commit
a0ece302d1
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
|
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/expressions"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/expressions"
|
||||||
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/generators"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/replacer"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/replacer"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns/dnsclientpool"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns/dnsclientpool"
|
||||||
"github.com/projectdiscovery/retryabledns"
|
"github.com/projectdiscovery/retryabledns"
|
||||||
@ -193,7 +194,11 @@ func (request *Request) Make(host string) (*dns.Msg, error) {
|
|||||||
|
|
||||||
var q dns.Question
|
var q dns.Question
|
||||||
|
|
||||||
final := replacer.Replace(request.Name, GenerateDNSVariables(host))
|
vars := GenerateDNSVariables(host)
|
||||||
|
variablesMap := request.options.Variables.Evaluate(vars)
|
||||||
|
vars = generators.MergeMaps(variablesMap, variablesMap)
|
||||||
|
|
||||||
|
final := replacer.Replace(request.Name, vars)
|
||||||
|
|
||||||
q.Name = dns.Fqdn(final)
|
q.Name = dns.Fqdn(final)
|
||||||
q.Qclass = request.class
|
q.Qclass = request.class
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/expressions"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/expressions"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/generators"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/generators"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/variables"
|
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/http/httpclientpool"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/http/httpclientpool"
|
||||||
"github.com/projectdiscovery/rawhttp"
|
"github.com/projectdiscovery/rawhttp"
|
||||||
"github.com/projectdiscovery/retryablehttp-go"
|
"github.com/projectdiscovery/retryablehttp-go"
|
||||||
@ -70,9 +69,6 @@ type Request struct {
|
|||||||
// of payloads is provided, or optionally a single file can also
|
// of payloads is provided, or optionally a single file can also
|
||||||
// be provided as payload which will be read on run-time.
|
// be provided as payload which will be read on run-time.
|
||||||
Payloads map[string]interface{} `yaml:"payloads,omitempty" jsonschema:"title=payloads for the http request,description=Payloads contains any payloads for the current request"`
|
Payloads map[string]interface{} `yaml:"payloads,omitempty" jsonschema:"title=payloads for the http request,description=Payloads contains any payloads for the current request"`
|
||||||
// description: |
|
|
||||||
// Variables contains any variables for the current request.
|
|
||||||
Variables variables.Variable `yaml:"variables,omitempty" jsonschema:"title=variables for the http request,description=Variables contains any variables for the current request"`
|
|
||||||
|
|
||||||
// description: |
|
// description: |
|
||||||
// Headers contains HTTP Headers to send with the request.
|
// Headers contains HTTP Headers to send with the request.
|
||||||
|
|||||||
@ -240,8 +240,8 @@ func (request *Request) ExecuteWithResults(reqURL string, dynamicValues, previou
|
|||||||
// returns two values, error and skip, which skips the execution for the request instance.
|
// returns two values, error and skip, which skips the execution for the request instance.
|
||||||
executeFunc := func(data string, payloads, dynamicValue map[string]interface{}) (bool, error) {
|
executeFunc := func(data string, payloads, dynamicValue map[string]interface{}) (bool, error) {
|
||||||
hasInteractMatchers := interactsh.HasMatchers(request.CompiledOperators)
|
hasInteractMatchers := interactsh.HasMatchers(request.CompiledOperators)
|
||||||
variablesMap := request.Variables.Evaluate(generators.MergeMaps(dynamicValues, payloads))
|
variablesMap := request.options.Variables.Evaluate(generators.MergeMaps(dynamicValues, payloads))
|
||||||
dynamicValues = generators.MergeMaps(variablesMap, dynamicValues)
|
payloads = generators.MergeMaps(variablesMap, payloads)
|
||||||
|
|
||||||
generatedHttpRequest, err := generator.Make(reqURL, data, payloads, dynamicValue)
|
generatedHttpRequest, err := generator.Make(reqURL, data, payloads, dynamicValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/expressions"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/expressions"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/generators"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/generators"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/variables"
|
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/network/networkclientpool"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/network/networkclientpool"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -44,9 +43,6 @@ type Request struct {
|
|||||||
// of payloads is provided, or optionally a single file can also
|
// of payloads is provided, or optionally a single file can also
|
||||||
// be provided as payload which will be read on run-time.
|
// be provided as payload which will be read on run-time.
|
||||||
Payloads map[string]interface{} `yaml:"payloads,omitempty" jsonschema:"title=payloads for the network request,description=Payloads contains any payloads for the current request"`
|
Payloads map[string]interface{} `yaml:"payloads,omitempty" jsonschema:"title=payloads for the network request,description=Payloads contains any payloads for the current request"`
|
||||||
// description: |
|
|
||||||
// Variables contains any variables for the current request.
|
|
||||||
Variables variables.Variable `yaml:"variables,omitempty" jsonschema:"title=variables for the http request,description=Variables contains any variables for the current request"`
|
|
||||||
|
|
||||||
// description: |
|
// description: |
|
||||||
// Inputs contains inputs for the network socket
|
// Inputs contains inputs for the network socket
|
||||||
|
|||||||
@ -101,8 +101,8 @@ func (request *Request) executeRequestWithPayloads(variables map[string]interfac
|
|||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
variablesMap := request.Variables.Evaluate(generators.MergeMaps(variables, payloads))
|
variablesMap := request.options.Variables.Evaluate(generators.MergeMaps(variables, payloads))
|
||||||
variables = generators.MergeMaps(variablesMap, variables)
|
payloads = generators.MergeMaps(variablesMap, payloads)
|
||||||
|
|
||||||
if host, _, splitErr := net.SplitHostPort(actualAddress); splitErr == nil {
|
if host, _, splitErr := net.SplitHostPort(actualAddress); splitErr == nil {
|
||||||
hostname = host
|
hostname = host
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/projectdiscovery/nuclei/v2/pkg/projectfile"
|
"github.com/projectdiscovery/nuclei/v2/pkg/projectfile"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/hosterrorscache"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/hosterrorscache"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/interactsh"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/interactsh"
|
||||||
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/variables"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/headless/engine"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/headless/engine"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/reporting"
|
"github.com/projectdiscovery/nuclei/v2/pkg/reporting"
|
||||||
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
|
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
|
||||||
@ -63,6 +64,8 @@ type ExecuterOptions struct {
|
|||||||
HostErrorsCache *hosterrorscache.Cache
|
HostErrorsCache *hosterrorscache.Cache
|
||||||
// Stop execution once first match is found
|
// Stop execution once first match is found
|
||||||
StopAtFirstMatch bool
|
StopAtFirstMatch bool
|
||||||
|
// Variables is a list of variables from template
|
||||||
|
Variables variables.Variable
|
||||||
|
|
||||||
Operators []*operators.Operators // only used by offlinehttp module
|
Operators []*operators.Operators // only used by offlinehttp module
|
||||||
|
|
||||||
|
|||||||
@ -63,6 +63,10 @@ func Parse(filePath string, preprocessor Preprocessor, options protocols.Execute
|
|||||||
options.TemplatePath = filePath
|
options.TemplatePath = filePath
|
||||||
options.StopAtFirstMatch = template.StopAtFirstMatch
|
options.StopAtFirstMatch = template.StopAtFirstMatch
|
||||||
|
|
||||||
|
if template.Variables.Len() > 0 {
|
||||||
|
options.Variables = template.Variables
|
||||||
|
}
|
||||||
|
|
||||||
// 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 template.Requests() == 0 {
|
if template.Requests() == 0 {
|
||||||
return nil, fmt.Errorf("no requests defined for %s", template.ID)
|
return nil, fmt.Errorf("no requests defined for %s", template.ID)
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import (
|
|||||||
validate "github.com/go-playground/validator/v10"
|
validate "github.com/go-playground/validator/v10"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/model"
|
"github.com/projectdiscovery/nuclei/v2/pkg/model"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
||||||
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/variables"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/file"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/file"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/headless"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/headless"
|
||||||
@ -98,6 +99,10 @@ type Template struct {
|
|||||||
// - "AWS"
|
// - "AWS"
|
||||||
Signature http.SignatureTypeHolder `yaml:"signature,omitempty" jsonschema:"title=signature is the http request signature method,description=Signature is the HTTP Request signature Method,enum=AWS"`
|
Signature http.SignatureTypeHolder `yaml:"signature,omitempty" jsonschema:"title=signature is the http request signature method,description=Signature is the HTTP Request signature Method,enum=AWS"`
|
||||||
|
|
||||||
|
// description: |
|
||||||
|
// Variables contains any variables for the current request.
|
||||||
|
Variables variables.Variable `yaml:"variables,omitempty" jsonschema:"title=variables for the http request,description=Variables contains any variables for the current request"`
|
||||||
|
|
||||||
// TotalRequests is the total number of requests for the template.
|
// TotalRequests is the total number of requests for the template.
|
||||||
TotalRequests int `yaml:"-" json:"-"`
|
TotalRequests int `yaml:"-" json:"-"`
|
||||||
// Executer is the actual template executor for running template requests
|
// Executer is the actual template executor for running template requests
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user