Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/protocols/headless/engine/action.go
2072 views
1
package engine
2
3
import (
4
"strings"
5
6
"github.com/invopop/jsonschema"
7
)
8
9
// Action is an action taken by the browser to reach a navigation
10
//
11
// Each step that the browser executes is an action. Most navigations
12
// usually start from the ActionLoadURL event, and further navigations
13
// are discovered on the found page. We also keep track and only
14
// scrape new navigation from pages we haven't crawled yet.
15
type Action struct {
16
// description:
17
// Args contain arguments for the headless action.
18
//
19
// Per action arguments are described in detail [here](https://nuclei.projectdiscovery.io/templating-guide/protocols/headless/).
20
Data map[string]string `yaml:"args,omitempty" json:"args,omitempty" jsonschema:"title=arguments for headless action,description=Args contain arguments for the headless action"`
21
// description: |
22
// Name is the name assigned to the headless action.
23
//
24
// This can be used to execute code, for instance in browser
25
// DOM using script action, and get the result in a variable
26
// which can be matched upon by nuclei. An Example template [here](https://github.com/projectdiscovery/nuclei-templates/blob/main/headless/prototype-pollution-check.yaml).
27
Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"title=name for headless action,description=Name is the name assigned to the headless action"`
28
// description: |
29
// Description is the optional description of the headless action
30
Description string `yaml:"description,omitempty" json:"description,omitempty" jsonschema:"title=description for headless action,description=Description of the headless action"`
31
// description: |
32
// Action is the type of the action to perform.
33
ActionType ActionTypeHolder `yaml:"action" json:"action" jsonschema:"title=action to perform,description=Type of actions to perform,enum=navigate,enum=script,enum=click,enum=rightclick,enum=text,enum=screenshot,enum=time,enum=select,enum=files,enum=waitload,enum=getresource,enum=extract,enum=setmethod,enum=addheader,enum=setheader,enum=deleteheader,enum=setbody,enum=waitevent,enum=keyboard,enum=debug,enum=sleep"`
34
}
35
36
func (a Action) JSONSchemaExtend(schema *jsonschema.Schema) {
37
argsSchema, ok := schema.Properties.Get("args")
38
if !ok {
39
return
40
}
41
argsSchema.PatternProperties = map[string]*jsonschema.Schema{
42
".*": {
43
OneOf: []*jsonschema.Schema{
44
{
45
Type: "string",
46
},
47
{
48
Type: "integer",
49
},
50
{
51
Type: "boolean",
52
},
53
},
54
},
55
}
56
argsSchema.Ref = ""
57
}
58
59
// String returns the string representation of an action
60
func (a *Action) String() string {
61
builder := &strings.Builder{}
62
builder.WriteString(a.ActionType.String())
63
if a.Name != "" {
64
builder.WriteString(" Name:")
65
builder.WriteString(a.Name)
66
}
67
builder.WriteString(" ")
68
for k, v := range a.Data {
69
builder.WriteString(k)
70
builder.WriteString(":")
71
builder.WriteString(v)
72
builder.WriteString(",")
73
}
74
return strings.TrimSuffix(builder.String(), ",")
75
}
76
77
// GetArg returns an arg for a name
78
func (a *Action) GetArg(name string) string {
79
v, ok := a.Data[name]
80
if !ok {
81
return ""
82
}
83
return v
84
}
85
86