Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/cmd/integration-test/flow.go
2070 views
1
package main
2
3
import (
4
"encoding/base64"
5
"fmt"
6
"net/http"
7
"net/http/httptest"
8
9
"github.com/julienschmidt/httprouter"
10
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
11
)
12
13
var flowTestcases = []TestCaseInfo{
14
{Path: "flow/conditional-flow.yaml", TestCase: &conditionalFlow{}},
15
{Path: "flow/conditional-flow-negative.yaml", TestCase: &conditionalFlowNegative{}},
16
{Path: "flow/iterate-values-flow.yaml", TestCase: &iterateValuesFlow{}},
17
{Path: "flow/iterate-one-value-flow.yaml", TestCase: &iterateOneValueFlow{}},
18
{Path: "flow/dns-ns-probe.yaml", TestCase: &dnsNsProbe{}},
19
{Path: "flow/flow-hide-matcher.yaml", TestCase: &flowHideMatcher{}},
20
}
21
22
type conditionalFlow struct{}
23
24
func (t *conditionalFlow) Execute(filePath string) error {
25
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "cloud.projectdiscovery.io", debug)
26
if err != nil {
27
return err
28
}
29
return expectResultsCount(results, 1)
30
}
31
32
type conditionalFlowNegative struct{}
33
34
func (t *conditionalFlowNegative) Execute(filePath string) error {
35
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "scanme.sh", debug)
36
if err != nil {
37
return err
38
}
39
return expectResultsCount(results, 0)
40
}
41
42
type iterateValuesFlow struct{}
43
44
func (t *iterateValuesFlow) Execute(filePath string) error {
45
router := httprouter.New()
46
testemails := []string{
47
"[email protected]",
48
"[email protected]",
49
}
50
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
51
w.WriteHeader(http.StatusOK)
52
_, _ = fmt.Fprint(w, testemails)
53
})
54
router.GET("/user/"+getBase64(testemails[0]), func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
55
w.WriteHeader(http.StatusOK)
56
_, _ = w.Write([]byte("Welcome ! This is test matcher text"))
57
})
58
59
router.GET("/user/"+getBase64(testemails[1]), func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
60
w.WriteHeader(http.StatusOK)
61
_, _ = w.Write([]byte("Welcome ! This is test matcher text"))
62
})
63
64
ts := httptest.NewServer(router)
65
defer ts.Close()
66
67
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
68
if err != nil {
69
return err
70
}
71
return expectResultsCount(results, 2)
72
}
73
74
type iterateOneValueFlow struct{}
75
76
func (t *iterateOneValueFlow) Execute(filePath string) error {
77
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "https://scanme.sh", debug)
78
if err != nil {
79
return err
80
}
81
return expectResultsCount(results, 1)
82
}
83
84
type dnsNsProbe struct{}
85
86
func (t *dnsNsProbe) Execute(filePath string) error {
87
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "oast.fun", debug)
88
if err != nil {
89
return err
90
}
91
return expectResultsCount(results, 2)
92
}
93
94
func getBase64(input string) string {
95
return base64.StdEncoding.EncodeToString([]byte(input))
96
}
97
98
type flowHideMatcher struct{}
99
100
func (t *flowHideMatcher) Execute(filePath string) error {
101
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "scanme.sh", debug)
102
if err != nil {
103
return err
104
}
105
// this matcher should not return any results
106
return expectResultsCount(results, 0)
107
}
108
109