2023-08-31 18:03:01 +05:30
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/base64"
|
|
|
|
|
"fmt"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/http/httptest"
|
|
|
|
|
|
|
|
|
|
"github.com/julienschmidt/httprouter"
|
2023-10-17 17:44:13 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
|
2023-08-31 18:03:01 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var flowTestcases = []TestCaseInfo{
|
|
|
|
|
{Path: "flow/conditional-flow.yaml", TestCase: &conditionalFlow{}},
|
|
|
|
|
{Path: "flow/conditional-flow-negative.yaml", TestCase: &conditionalFlowNegative{}},
|
|
|
|
|
{Path: "flow/iterate-values-flow.yaml", TestCase: &iterateValuesFlow{}},
|
2024-01-29 05:20:01 +05:30
|
|
|
{Path: "flow/iterate-one-value-flow.yaml", TestCase: &iterateOneValueFlow{}},
|
2023-08-31 18:03:01 +05:30
|
|
|
{Path: "flow/dns-ns-probe.yaml", TestCase: &dnsNsProbe{}},
|
2023-11-02 13:33:40 +05:30
|
|
|
{Path: "flow/flow-hide-matcher.yaml", TestCase: &flowHideMatcher{}},
|
2023-08-31 18:03:01 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type conditionalFlow struct{}
|
|
|
|
|
|
|
|
|
|
func (t *conditionalFlow) Execute(filePath string) error {
|
2024-11-19 12:38:25 +07:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "cloud.projectdiscovery.io", debug)
|
2023-08-31 18:03:01 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2023-11-02 13:33:40 +05:30
|
|
|
return expectResultsCount(results, 1)
|
2023-08-31 18:03:01 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type conditionalFlowNegative struct{}
|
|
|
|
|
|
|
|
|
|
func (t *conditionalFlowNegative) Execute(filePath string) error {
|
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "scanme.sh", debug)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return expectResultsCount(results, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type iterateValuesFlow struct{}
|
|
|
|
|
|
|
|
|
|
func (t *iterateValuesFlow) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
testemails := []string{
|
|
|
|
|
"secrets@scanme.sh",
|
|
|
|
|
"superadmin@scanme.sh",
|
|
|
|
|
}
|
|
|
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
2025-07-01 00:40:44 +07:00
|
|
|
_, _ = fmt.Fprint(w, testemails)
|
2023-08-31 18:03:01 +05:30
|
|
|
})
|
|
|
|
|
router.GET("/user/"+getBase64(testemails[0]), func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
|
_, _ = w.Write([]byte("Welcome ! This is test matcher text"))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.GET("/user/"+getBase64(testemails[1]), func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
|
_, _ = w.Write([]byte("Welcome ! This is test matcher text"))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2024-01-08 05:12:11 +05:30
|
|
|
return expectResultsCount(results, 2)
|
2023-08-31 18:03:01 +05:30
|
|
|
}
|
|
|
|
|
|
2024-01-29 05:20:01 +05:30
|
|
|
type iterateOneValueFlow struct{}
|
|
|
|
|
|
|
|
|
|
func (t *iterateOneValueFlow) Execute(filePath string) error {
|
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "https://scanme.sh", debug)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return expectResultsCount(results, 1)
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 18:03:01 +05:30
|
|
|
type dnsNsProbe struct{}
|
|
|
|
|
|
|
|
|
|
func (t *dnsNsProbe) Execute(filePath string) error {
|
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "oast.fun", debug)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2024-01-08 05:12:11 +05:30
|
|
|
return expectResultsCount(results, 2)
|
2023-08-31 18:03:01 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getBase64(input string) string {
|
|
|
|
|
return base64.StdEncoding.EncodeToString([]byte(input))
|
|
|
|
|
}
|
2023-11-02 13:33:40 +05:30
|
|
|
|
|
|
|
|
type flowHideMatcher struct{}
|
|
|
|
|
|
|
|
|
|
func (t *flowHideMatcher) Execute(filePath string) error {
|
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "scanme.sh", debug)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
// this matcher should not return any results
|
|
|
|
|
return expectResultsCount(results, 0)
|
|
|
|
|
}
|