2021-02-21 16:31:34 +05:30
|
|
|
package headless
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/headless/engine"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Request contains a Headless protocol request to be made from a template
|
|
|
|
|
type Request struct {
|
2021-08-03 22:33:50 +05:30
|
|
|
// ID is the ID of the request
|
2021-08-04 14:20:48 +05:30
|
|
|
ID string `yaml:"id,omitempty"`
|
2021-02-21 16:31:34 +05:30
|
|
|
|
2021-07-27 16:03:56 +05:30
|
|
|
// description: |
|
|
|
|
|
// Steps is the list of actions to run for headless request
|
2021-08-04 14:20:48 +05:30
|
|
|
Steps []*engine.Action `yaml:"steps,omitempty"`
|
2021-02-21 16:31:34 +05:30
|
|
|
|
|
|
|
|
// Operators for the current request go here.
|
|
|
|
|
operators.Operators `yaml:",inline,omitempty"`
|
|
|
|
|
CompiledOperators *operators.Operators `yaml:"-"`
|
|
|
|
|
|
|
|
|
|
// cache any variables that may be needed for operation.
|
|
|
|
|
options *protocols.ExecuterOptions
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step is a headless protocol request step.
|
|
|
|
|
type Step struct {
|
|
|
|
|
// Action is the headless action to execute for the script
|
|
|
|
|
Action string `yaml:"action"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetID returns the unique ID of the request if any.
|
|
|
|
|
func (r *Request) GetID() string {
|
|
|
|
|
return r.ID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compile compiles the protocol request for further execution.
|
|
|
|
|
func (r *Request) Compile(options *protocols.ExecuterOptions) error {
|
|
|
|
|
if len(r.Matchers) > 0 || len(r.Extractors) > 0 {
|
|
|
|
|
compiled := &r.Operators
|
|
|
|
|
if err := compiled.Compile(); err != nil {
|
|
|
|
|
return errors.Wrap(err, "could not compile operators")
|
|
|
|
|
}
|
|
|
|
|
r.CompiledOperators = compiled
|
|
|
|
|
}
|
|
|
|
|
r.options = options
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Requests returns the total number of requests the YAML rule will perform
|
|
|
|
|
func (r *Request) Requests() int {
|
|
|
|
|
return 1
|
|
|
|
|
}
|