2021-02-25 23:32:43 +05:30
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"net"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/http/httptest"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/julienschmidt/httprouter"
|
2021-09-03 16:48:39 +03:00
|
|
|
|
2021-11-05 03:01:41 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/testutils"
|
2021-02-25 23:32:43 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var httpTestcases = map[string]testutils.TestCase{
|
2021-10-29 19:11:57 +03:00
|
|
|
"http/get-headers.yaml": &httpGetHeaders{},
|
|
|
|
|
"http/get-query-string.yaml": &httpGetQueryString{},
|
|
|
|
|
"http/get-redirects.yaml": &httpGetRedirects{},
|
|
|
|
|
"http/get.yaml": &httpGet{},
|
|
|
|
|
"http/post-body.yaml": &httpPostBody{},
|
|
|
|
|
"http/post-json-body.yaml": &httpPostJSONBody{},
|
|
|
|
|
"http/post-multipart-body.yaml": &httpPostMultipartBody{},
|
|
|
|
|
"http/raw-cookie-reuse.yaml": &httpRawCookieReuse{},
|
|
|
|
|
"http/raw-dynamic-extractor.yaml": &httpRawDynamicExtractor{},
|
|
|
|
|
"http/raw-get-query.yaml": &httpRawGetQuery{},
|
|
|
|
|
"http/raw-get.yaml": &httpRawGet{},
|
|
|
|
|
"http/raw-payload.yaml": &httpRawPayload{},
|
|
|
|
|
"http/raw-post-body.yaml": &httpRawPostBody{},
|
|
|
|
|
"http/raw-unsafe-request.yaml": &httpRawUnsafeRequest{},
|
|
|
|
|
"http/request-condition.yaml": &httpRequestCondition{},
|
|
|
|
|
"http/request-condition-new.yaml": &httpRequestCondition{},
|
|
|
|
|
"http/interactsh.yaml": &httpInteractshRequest{},
|
|
|
|
|
"http/self-contained.yaml": &httpRequestSelContained{},
|
|
|
|
|
"http/get-case-insensitive.yaml": &httpGetCaseInsensitive{},
|
|
|
|
|
"http/get.yaml,http/get-case-insensitive.yaml": &httpGetCaseInsensitiveCluster{},
|
2021-11-09 06:10:07 +05:30
|
|
|
"http/get-redirects-chain-headers.yaml": &httpGetRedirectsChainHeaders{},
|
2021-02-25 23:32:43 +05:30
|
|
|
}
|
|
|
|
|
|
2021-09-16 21:29:58 +05:30
|
|
|
type httpInteractshRequest struct{}
|
|
|
|
|
|
|
|
|
|
// Executes executes a test case and returns an error if occurred
|
|
|
|
|
func (h *httpInteractshRequest) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
router.GET("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
|
|
|
value := r.Header.Get("url")
|
|
|
|
|
if value != "" {
|
|
|
|
|
if resp, _ := http.DefaultClient.Get(value); resp != nil {
|
|
|
|
|
resp.Body.Close()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-26 16:29:00 +05:30
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-09-16 21:29:58 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 23:32:43 +05:30
|
|
|
type httpGetHeaders struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-02-25 23:32:43 +05:30
|
|
|
func (h *httpGetHeaders) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
2021-10-01 18:23:06 +03:00
|
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
if strings.EqualFold(r.Header.Get("test"), "nuclei") {
|
|
|
|
|
fmt.Fprintf(w, "This is test headers matcher text")
|
|
|
|
|
}
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
2021-02-25 23:32:43 +05:30
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-02-25 23:32:43 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type httpGetQueryString struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-02-25 23:32:43 +05:30
|
|
|
func (h *httpGetQueryString) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
2021-10-01 18:23:06 +03:00
|
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
if strings.EqualFold(r.URL.Query().Get("test"), "nuclei") {
|
|
|
|
|
fmt.Fprintf(w, "This is test querystring matcher text")
|
|
|
|
|
}
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
2021-02-25 23:32:43 +05:30
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-02-25 23:32:43 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type httpGetRedirects struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-02-25 23:32:43 +05:30
|
|
|
func (h *httpGetRedirects) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
2021-10-01 18:23:06 +03:00
|
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-26 13:13:11 +05:30
|
|
|
http.Redirect(w, r, "/redirected", http.StatusFound)
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
|
|
|
|
router.GET("/redirected", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
fmt.Fprintf(w, "This is test redirects matcher text")
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
2021-02-25 23:32:43 +05:30
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-02-25 23:32:43 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type httpGet struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-02-25 23:32:43 +05:30
|
|
|
func (h *httpGet) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
2021-10-01 18:23:06 +03:00
|
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
fmt.Fprintf(w, "This is test matcher text")
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
2021-02-25 23:32:43 +05:30
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-02-25 23:32:43 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type httpPostBody struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-02-25 23:32:43 +05:30
|
|
|
func (h *httpPostBody) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
var routerErr error
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
if err := r.ParseForm(); err != nil {
|
|
|
|
|
routerErr = err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if strings.EqualFold(r.Form.Get("username"), "test") && strings.EqualFold(r.Form.Get("password"), "nuclei") {
|
|
|
|
|
fmt.Fprintf(w, "This is test post-body matcher text")
|
|
|
|
|
}
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
2021-02-25 23:32:43 +05:30
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-02-25 23:32:43 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if routerErr != nil {
|
|
|
|
|
return routerErr
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type httpPostJSONBody struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-02-25 23:32:43 +05:30
|
|
|
func (h *httpPostJSONBody) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
var routerErr error
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
type doc struct {
|
|
|
|
|
Username string `json:"username"`
|
|
|
|
|
Password string `json:"password"`
|
|
|
|
|
}
|
|
|
|
|
obj := &doc{}
|
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(obj); err != nil {
|
|
|
|
|
routerErr = err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if strings.EqualFold(obj.Username, "test") && strings.EqualFold(obj.Password, "nuclei") {
|
|
|
|
|
fmt.Fprintf(w, "This is test post-json-body matcher text")
|
|
|
|
|
}
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
2021-02-25 23:32:43 +05:30
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-02-25 23:32:43 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if routerErr != nil {
|
|
|
|
|
return routerErr
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type httpPostMultipartBody struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-02-25 23:32:43 +05:30
|
|
|
func (h *httpPostMultipartBody) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
var routerErr error
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
if err := r.ParseMultipartForm(1 * 1024); err != nil {
|
|
|
|
|
routerErr = err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
password, ok := r.MultipartForm.Value["password"]
|
|
|
|
|
if !ok || len(password) != 1 {
|
|
|
|
|
routerErr = errors.New("no password in request")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
file := r.MultipartForm.File["username"]
|
|
|
|
|
if len(file) != 1 {
|
|
|
|
|
routerErr = errors.New("no file in request")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if strings.EqualFold(password[0], "nuclei") && strings.EqualFold(file[0].Filename, "username") {
|
|
|
|
|
fmt.Fprintf(w, "This is test post-multipart matcher text")
|
|
|
|
|
}
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
2021-02-25 23:32:43 +05:30
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-02-25 23:32:43 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if routerErr != nil {
|
|
|
|
|
return routerErr
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type httpRawDynamicExtractor struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-02-25 23:32:43 +05:30
|
|
|
func (h *httpRawDynamicExtractor) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
var routerErr error
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
if err := r.ParseForm(); err != nil {
|
|
|
|
|
routerErr = err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if strings.EqualFold(r.Form.Get("testing"), "parameter") {
|
|
|
|
|
fmt.Fprintf(w, "Token: 'nuclei'")
|
|
|
|
|
}
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
|
|
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
if strings.EqualFold(r.URL.Query().Get("username"), "nuclei") {
|
|
|
|
|
fmt.Fprintf(w, "Test is test-dynamic-extractor-raw matcher text")
|
|
|
|
|
}
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
2021-02-25 23:32:43 +05:30
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-02-25 23:32:43 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if routerErr != nil {
|
|
|
|
|
return routerErr
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type httpRawGetQuery struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-02-25 23:32:43 +05:30
|
|
|
func (h *httpRawGetQuery) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
var routerErr error
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
if strings.EqualFold(r.URL.Query().Get("test"), "nuclei") {
|
|
|
|
|
fmt.Fprintf(w, "Test is test raw-get-query-matcher text")
|
|
|
|
|
}
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
2021-02-25 23:32:43 +05:30
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-02-25 23:32:43 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if routerErr != nil {
|
|
|
|
|
return routerErr
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type httpRawGet struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-02-25 23:32:43 +05:30
|
|
|
func (h *httpRawGet) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
var routerErr error
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
fmt.Fprintf(w, "Test is test raw-get-matcher text")
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
2021-02-25 23:32:43 +05:30
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-02-25 23:32:43 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if routerErr != nil {
|
|
|
|
|
return routerErr
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type httpRawPayload struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-02-25 23:32:43 +05:30
|
|
|
func (h *httpRawPayload) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
var routerErr error
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
if err := r.ParseForm(); err != nil {
|
|
|
|
|
routerErr = err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if !(strings.EqualFold(r.Header.Get("another_header"), "bnVjbGVp") || strings.EqualFold(r.Header.Get("another_header"), "Z3Vlc3Q=")) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if strings.EqualFold(r.Form.Get("username"), "test") && (strings.EqualFold(r.Form.Get("password"), "nuclei") || strings.EqualFold(r.Form.Get("password"), "guest")) {
|
|
|
|
|
fmt.Fprintf(w, "Test is raw-payload matcher text")
|
|
|
|
|
}
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
2021-02-25 23:32:43 +05:30
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-02-25 23:32:43 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if routerErr != nil {
|
|
|
|
|
return routerErr
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 2 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type httpRawPostBody struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-02-25 23:32:43 +05:30
|
|
|
func (h *httpRawPostBody) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
var routerErr error
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
if err := r.ParseForm(); err != nil {
|
|
|
|
|
routerErr = err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if strings.EqualFold(r.Form.Get("username"), "test") && strings.EqualFold(r.Form.Get("password"), "nuclei") {
|
|
|
|
|
fmt.Fprintf(w, "Test is test raw-post-body-matcher text")
|
|
|
|
|
}
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
2021-02-25 23:32:43 +05:30
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-02-25 23:32:43 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if routerErr != nil {
|
|
|
|
|
return routerErr
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type httpRawCookieReuse struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-02-25 23:32:43 +05:30
|
|
|
func (h *httpRawCookieReuse) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
var routerErr error
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
if err := r.ParseForm(); err != nil {
|
|
|
|
|
routerErr = err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if strings.EqualFold(r.Form.Get("testing"), "parameter") {
|
|
|
|
|
http.SetCookie(w, &http.Cookie{Name: "nuclei", Value: "test"})
|
|
|
|
|
}
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
|
|
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-02-25 23:32:43 +05:30
|
|
|
if err := r.ParseForm(); err != nil {
|
|
|
|
|
routerErr = err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
cookie, err := r.Cookie("nuclei")
|
|
|
|
|
if err != nil {
|
|
|
|
|
routerErr = err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if strings.EqualFold(cookie.Value, "test") {
|
|
|
|
|
fmt.Fprintf(w, "Test is test-cookie-reuse matcher text")
|
|
|
|
|
}
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
2021-02-25 23:32:43 +05:30
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-02-25 23:32:43 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if routerErr != nil {
|
|
|
|
|
return routerErr
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type httpRawUnsafeRequest struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-02-25 23:32:43 +05:30
|
|
|
func (h *httpRawUnsafeRequest) Execute(filePath string) error {
|
|
|
|
|
var routerErr error
|
|
|
|
|
|
|
|
|
|
ts := testutils.NewTCPServer(func(conn net.Conn) {
|
|
|
|
|
defer conn.Close()
|
2021-06-15 11:46:02 +05:30
|
|
|
_, _ = conn.Write([]byte("HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 36\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nThis is test raw-unsafe-matcher test"))
|
2021-02-25 23:32:43 +05:30
|
|
|
})
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "http://"+ts.URL, debug)
|
2021-02-25 23:32:43 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if routerErr != nil {
|
|
|
|
|
return routerErr
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2021-03-09 14:45:04 +05:30
|
|
|
|
|
|
|
|
type httpRequestCondition struct{}
|
|
|
|
|
|
2021-09-03 17:25:50 +03:00
|
|
|
// Execute executes a test case and returns an error if occurred
|
2021-03-09 14:45:04 +05:30
|
|
|
func (h *httpRequestCondition) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
var routerErr error
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
router.GET("/200", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-03-09 14:45:04 +05:30
|
|
|
w.WriteHeader(200)
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
|
|
|
|
router.GET("/400", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-03-09 14:45:04 +05:30
|
|
|
w.WriteHeader(400)
|
2021-10-01 18:23:06 +03:00
|
|
|
})
|
2021-03-09 14:45:04 +05:30
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
2021-10-01 18:23:06 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
2021-03-09 14:45:04 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if routerErr != nil {
|
|
|
|
|
return routerErr
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2021-10-19 22:17:44 +05:30
|
|
|
|
|
|
|
|
type httpRequestSelContained struct{}
|
|
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
|
func (h *httpRequestSelContained) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
var routerErr error
|
|
|
|
|
|
|
|
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-10-19 22:20:29 +05:30
|
|
|
_, _ = w.Write([]byte("This is self-contained response"))
|
2021-10-19 22:17:44 +05:30
|
|
|
})
|
|
|
|
|
server := &http.Server{
|
2021-10-20 20:13:40 +05:30
|
|
|
Addr: fmt.Sprintf("localhost:%d", defaultStaticPort),
|
2021-10-19 22:17:44 +05:30
|
|
|
Handler: router,
|
|
|
|
|
}
|
|
|
|
|
go func() {
|
|
|
|
|
_ = server.ListenAndServe()
|
|
|
|
|
}()
|
|
|
|
|
defer server.Close()
|
|
|
|
|
|
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "", debug)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if routerErr != nil {
|
|
|
|
|
return routerErr
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2021-10-29 19:11:57 +03:00
|
|
|
|
|
|
|
|
type httpGetCaseInsensitive struct{}
|
|
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
|
func (h *httpGetCaseInsensitive) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
|
|
|
fmt.Fprintf(w, "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
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type httpGetCaseInsensitiveCluster struct{}
|
|
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
|
func (h *httpGetCaseInsensitiveCluster) Execute(filesPath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
|
|
|
fmt.Fprintf(w, "This is test matcher text")
|
|
|
|
|
})
|
|
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
|
|
files := strings.Split(filesPath, ",")
|
|
|
|
|
|
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(files[0], ts.URL, debug, "-t", files[1])
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 2 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2021-11-09 06:10:07 +05:30
|
|
|
|
|
|
|
|
type httpGetRedirectsChainHeaders struct{}
|
|
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
|
func (h *httpGetRedirectsChainHeaders) Execute(filePath string) error {
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
|
|
|
http.Redirect(w, r, "/redirected", http.StatusFound)
|
|
|
|
|
})
|
|
|
|
|
router.GET("/redirected", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
|
|
|
w.Header().Set("Secret", "TestRedirectHeaderMatch")
|
|
|
|
|
http.Redirect(w, r, "/final", http.StatusFound)
|
|
|
|
|
})
|
|
|
|
|
router.GET("/final", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2021-11-09 06:12:36 +05:30
|
|
|
_, _ = w.Write([]byte("ok"))
|
2021-11-09 06:10:07 +05:30
|
|
|
})
|
|
|
|
|
ts := httptest.NewServer(router)
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if len(results) != 1 {
|
|
|
|
|
return errIncorrectResultsCount(results)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|