Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/templates/templates_utils.go
2843 views
1
package templates
2
3
import "github.com/projectdiscovery/nuclei/v3/pkg/protocols"
4
5
// HasRequest returns true if the given requests slice is non-empty.
6
//
7
// If n is provided, it checks for more than n requests.
8
func HasRequest[T protocols.Request](requests []T, n ...int) bool {
9
if len(n) > 0 {
10
return len(requests) > n[0]
11
}
12
13
return len(requests) > 0
14
}
15
16
// HasDNSRequest returns true if the template has a DNS request.
17
//
18
// If n is provided, it checks for more than n requests.
19
func (t *Template) HasDNSRequest(n ...int) bool {
20
return HasRequest(t.RequestsDNS, n...)
21
}
22
23
// HasFileRequest returns true if the template has a File request.
24
//
25
// If n is provided, it checks for more than n requests.
26
func (t *Template) HasFileRequest(n ...int) bool {
27
return HasRequest(t.RequestsFile, n...)
28
}
29
30
// HasHTTPRequest returns true if the template has an HTTP request.
31
//
32
// If n is provided, it checks for more than n requests.
33
func (t *Template) HasHTTPRequest(n ...int) bool {
34
return HasRequest(t.RequestsHTTP, n...)
35
}
36
37
// HasHeadlessRequest returns true if the template has a Headless protocol
38
// request.
39
//
40
// If n is provided, it checks for more than n requests.
41
func (t *Template) HasHeadlessRequest(n ...int) bool {
42
return HasRequest(t.RequestsHeadless, n...)
43
}
44
45
// HasNetworkRequest returns true if the template has a Network protocol
46
// request.
47
//
48
// If n is provided, it checks for more than n requests.
49
func (t *Template) HasNetworkRequest(n ...int) bool {
50
return HasRequest(t.RequestsNetwork, n...)
51
}
52
53
// HasSSLRequest returns true if the template has an SSL request.
54
//
55
// If n is provided, it checks for more than n requests.
56
func (t *Template) HasSSLRequest(n ...int) bool {
57
return HasRequest(t.RequestsSSL, n...)
58
}
59
60
// HasWebsocketRequest returns true if the template has a Websocket protocol
61
// request.
62
//
63
// If n is provided, it checks for more than n requests.
64
func (t *Template) HasWebsocketRequest(n ...int) bool {
65
return HasRequest(t.RequestsWebsocket, n...)
66
}
67
68
// HasWHOISRequest returns true if the template has a WHOIS request.
69
//
70
// If n is provided, it checks for more than n requests.
71
func (t *Template) HasWHOISRequest(n ...int) bool {
72
return HasRequest(t.RequestsWHOIS, n...)
73
}
74
75
// HasCodeRequest returns true if the template has a Code request.
76
//
77
// If n is provided, it checks for more than n requests.
78
func (t *Template) HasCodeRequest(n ...int) bool {
79
return HasRequest(t.RequestsCode, n...)
80
}
81
82
// HasJavascriptRequest returns true if the template has a Javascript protocol
83
// request.
84
//
85
// If n is provided, it checks for more than n requests.
86
func (t *Template) HasJavascriptRequest(n ...int) bool {
87
return HasRequest(t.RequestsJavascript, n...)
88
}
89
90
// HasQueueRequests returns true if the template has queued requests.
91
//
92
// Queued requests contain all template requests in order (both protocol &
93
// request order).
94
//
95
// If n is provided, it checks for more than n requests.
96
func (t *Template) HasQueueRequests(n ...int) bool {
97
return HasRequest(t.RequestsQueue, n...)
98
}
99
100
// HasWorkflows returns true if the template has workflows defined.
101
func (t *Template) HasWorkflows() bool {
102
return len(t.Workflows) > 0
103
}
104
105
// IsFuzzableRequest returns true if the template has at least one request with
106
// fuzzing configured.
107
//
108
// Currently, it checks across HTTP and Headless requests.
109
func (t *Template) IsFuzzableRequest() bool {
110
if t.HasHTTPRequest() {
111
for _, request := range t.RequestsHTTP {
112
if request.HasFuzzing() {
113
return true
114
}
115
}
116
}
117
118
if t.HasHeadlessRequest() {
119
for _, request := range t.RequestsHeadless {
120
if request.HasFuzzing() {
121
return true
122
}
123
}
124
}
125
126
return false
127
}
128
129
// IsFlowTemplate returns true if the template has a flow defined.
130
func (template *Template) IsFlowTemplate() bool {
131
return template.Flow != "" && len(template.Flow) > 0
132
}
133
134
// IsGlobalMatchersTemplate returns true if the template has global matchers
135
// defined.
136
func (template *Template) IsGlobalMatchersTemplate() bool {
137
return template.Options != nil &&
138
template.Options.GlobalMatchers != nil &&
139
template.Options.GlobalMatchers.HasMatchers()
140
}
141
142