Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/fuzz/component/component.go
2070 views
1
package component
2
3
import (
4
"errors"
5
"strings"
6
7
"github.com/leslie-qiwa/flat"
8
"github.com/projectdiscovery/retryablehttp-go"
9
)
10
11
// ErrSetValue is a error raised when a value cannot be set
12
var ErrSetValue = errors.New("could not set value")
13
14
func IsErrSetValue(err error) bool {
15
if err == nil {
16
return false
17
}
18
return strings.Contains(err.Error(), "could not set value")
19
}
20
21
// ErrKeyNotFound is a error raised when a key is not found
22
var ErrKeyNotFound = errors.New("key not found")
23
24
// Component is a component for a request
25
type Component interface {
26
// Name returns the name of the component
27
Name() string
28
// Parse parses the component and returns the
29
// parsed component
30
Parse(req *retryablehttp.Request) (bool, error)
31
// Iterate iterates over all values of a component
32
// ex in case of query component, it will iterate over each query parameter
33
// depending on the rule if mode is single
34
// request is rebuilt for each value in this callback
35
// and in case of multiple, request will be rebuilt after iteration of all values
36
Iterate(func(key string, value interface{}) error) error
37
// SetValue sets a value in the component
38
// for a key
39
//
40
// After calling setValue for mutation, the value must be
41
// called again so as to reset the body to its original state.
42
SetValue(key string, value string) error
43
// Delete deletes a key from the component
44
// If it is applicable
45
Delete(key string) error
46
// Rebuild returns a new request with the
47
// component rebuilt
48
Rebuild() (*retryablehttp.Request, error)
49
// Clones current state of this component
50
Clone() Component
51
}
52
53
const (
54
// RequestBodyComponent is the name of the request body component
55
RequestBodyComponent = "body"
56
// RequestQueryComponent is the name of the request query component
57
RequestQueryComponent = "query"
58
// RequestPathComponent is the name of the request url component
59
RequestPathComponent = "path"
60
// RequestHeaderComponent is the name of the request header component
61
RequestHeaderComponent = "header"
62
// RequestCookieComponent is the name of the request cookie component
63
RequestCookieComponent = "cookie"
64
)
65
66
// Components is a list of all available components
67
var Components = []string{
68
RequestBodyComponent,
69
RequestQueryComponent,
70
RequestHeaderComponent,
71
RequestPathComponent,
72
RequestCookieComponent,
73
}
74
75
// New creates a new component for a componentType
76
func New(componentType string) Component {
77
switch componentType {
78
case "body":
79
return NewBody()
80
case "query":
81
return NewQuery()
82
case "path":
83
return NewPath()
84
case "header":
85
return NewHeader()
86
case "cookie":
87
return NewCookie()
88
}
89
return nil
90
}
91
92
var (
93
flatOpts = &flat.Options{
94
Safe: true,
95
Delimiter: "~",
96
}
97
)
98
99