2021-02-21 16:31:34 +05:30
package headless
import (
"github.com/pkg/errors"
2021-09-07 17:31:46 +03:00
2021-02-21 16:31:34 +05:30
"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-09-07 17:31:46 +03:00
// ID is the optional id of the request
2021-08-23 23:50:45 +05:30
ID string ` yaml:"id,omitempty" jsonschema:"title=id of the request,description=Optional ID of the headless request" `
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-23 23:50:45 +05:30
Steps [ ] * engine . Action ` yaml:"steps,omitempty" jsonschema:"title=list of actions for headless request,description=List of actions to run for headless request" `
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.
2021-10-01 14:30:04 +03:00
func ( request * Request ) GetID ( ) string {
return request . ID
2021-02-21 16:31:34 +05:30
}
// Compile compiles the protocol request for further execution.
2021-10-01 14:30:04 +03:00
func ( request * Request ) Compile ( options * protocols . ExecuterOptions ) error {
if len ( request . Matchers ) > 0 || len ( request . Extractors ) > 0 {
compiled := & request . Operators
2021-02-21 16:31:34 +05:30
if err := compiled . Compile ( ) ; err != nil {
return errors . Wrap ( err , "could not compile operators" )
}
2021-10-01 14:30:04 +03:00
request . CompiledOperators = compiled
2021-02-21 16:31:34 +05:30
}
2021-10-01 14:30:04 +03:00
request . options = options
2021-02-21 16:31:34 +05:30
return nil
}
// Requests returns the total number of requests the YAML rule will perform
2021-10-01 14:30:04 +03:00
func ( request * Request ) Requests ( ) int {
2021-02-21 16:31:34 +05:30
return 1
}