Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/input/provider/simple.go
2070 views
1
package provider
2
3
import (
4
"github.com/projectdiscovery/nuclei/v3/pkg/input/types"
5
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/contextargs"
6
)
7
8
// SimpleInputProvider is a simple input provider for nuclei
9
// that acts like a No-Op and returns given list of urls as input
10
type SimpleInputProvider struct {
11
Inputs []*contextargs.MetaInput
12
}
13
14
// NewSimpleInputProvider creates a new simple input provider
15
func NewSimpleInputProvider() *SimpleInputProvider {
16
return &SimpleInputProvider{
17
Inputs: make([]*contextargs.MetaInput, 0),
18
}
19
}
20
21
// NewSimpleInputProviderWithUrls creates a new simple input provider with the given urls
22
func NewSimpleInputProviderWithUrls(executionId string, urls ...string) *SimpleInputProvider {
23
provider := NewSimpleInputProvider()
24
for _, url := range urls {
25
provider.Set(executionId, url)
26
}
27
return provider
28
}
29
30
// Count returns the total number of targets for the input provider
31
func (s *SimpleInputProvider) Count() int64 {
32
return int64(len(s.Inputs))
33
}
34
35
// Iterate over all inputs in order
36
func (s *SimpleInputProvider) Iterate(callback func(value *contextargs.MetaInput) bool) {
37
for _, input := range s.Inputs {
38
if !callback(input) {
39
break
40
}
41
}
42
}
43
44
// Set adds an item to the input provider
45
func (s *SimpleInputProvider) Set(_ string, value string) {
46
metaInput := contextargs.NewMetaInput()
47
metaInput.Input = value
48
s.Inputs = append(s.Inputs, metaInput)
49
}
50
51
// SetWithProbe adds an item to the input provider with HTTP probing
52
func (s *SimpleInputProvider) SetWithProbe(_ string, value string, probe types.InputLivenessProbe) error {
53
probedValue, err := probe.ProbeURL(value)
54
if err != nil {
55
return err
56
}
57
metaInput := contextargs.NewMetaInput()
58
metaInput.Input = probedValue
59
s.Inputs = append(s.Inputs, metaInput)
60
return nil
61
}
62
63
// SetWithExclusions adds an item to the input provider if it doesn't match any of the exclusions
64
func (s *SimpleInputProvider) SetWithExclusions(_ string, value string) error {
65
metaInput := contextargs.NewMetaInput()
66
metaInput.Input = value
67
s.Inputs = append(s.Inputs, metaInput)
68
return nil
69
}
70
71
// InputType returns the type of input provider
72
func (s *SimpleInputProvider) InputType() string {
73
return "SimpleInputProvider"
74
}
75
76
// Close the input provider and cleanup any resources
77
func (s *SimpleInputProvider) Close() {
78
// no-op
79
}
80
81