Merge pull request #1071 from projectdiscovery/it_debug

Show the command line arguments of integration tests if debug is enabled
dev
Sandeep Singh 2021-10-04 03:56:08 +05:30 committed by GitHub
commit f346fb6f7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 91 additions and 87 deletions

View File

@ -15,6 +15,7 @@ import (
) )
var ( var (
debug = os.Getenv("DEBUG") == "true"
success = aurora.Green("[✓]").String() success = aurora.Green("[✓]").String()
failed = aurora.Red("[✘]").String() failed = aurora.Red("[✘]").String()
errored = false errored = false
@ -65,11 +66,11 @@ func runIndividualTestCase(testcase string) error {
if len(parts) > 1 { if len(parts) > 1 {
finalArgs = parts[1:] finalArgs = parts[1:]
} }
mainOutput, err := testutils.RunNucleiBinaryAndGetLoadedTemplates(*mainNucleiBinary, finalArgs) mainOutput, err := testutils.RunNucleiBinaryAndGetLoadedTemplates(*mainNucleiBinary, debug, finalArgs)
if err != nil { if err != nil {
return errors.Wrap(err, "could not run nuclei main test") return errors.Wrap(err, "could not run nuclei main test")
} }
devOutput, err := testutils.RunNucleiBinaryAndGetLoadedTemplates(*devNucleiBinary, finalArgs) devOutput, err := testutils.RunNucleiBinaryAndGetLoadedTemplates(*devNucleiBinary, debug, finalArgs)
if err != nil { if err != nil {
return errors.Wrap(err, "could not run nuclei dev test") return errors.Wrap(err, "could not run nuclei dev test")
} }

View File

@ -14,7 +14,7 @@ type dnsBasic struct{}
func (h *dnsBasic) Execute(filePath string) error { func (h *dnsBasic) Execute(filePath string) error {
var routerErr error var routerErr error
results, err := testutils.RunNucleiAndGetResults(filePath, "one.one.one.one", debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "one.one.one.one", debug)
if err != nil { if err != nil {
return err return err
} }

View File

@ -47,16 +47,16 @@ type httpGetHeaders struct{}
// Execute executes a test case and returns an error if occurred // Execute executes a test case and returns an error if occurred
func (h *httpGetHeaders) Execute(filePath string) error { func (h *httpGetHeaders) Execute(filePath string) error {
router := httprouter.New() router := httprouter.New()
router.GET("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
if strings.EqualFold(r.Header.Get("test"), "nuclei") { if strings.EqualFold(r.Header.Get("test"), "nuclei") {
fmt.Fprintf(w, "This is test headers matcher text") fmt.Fprintf(w, "This is test headers matcher text")
} }
})) })
ts := httptest.NewServer(router) ts := httptest.NewServer(router)
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -71,16 +71,16 @@ type httpGetQueryString struct{}
// Execute executes a test case and returns an error if occurred // Execute executes a test case and returns an error if occurred
func (h *httpGetQueryString) Execute(filePath string) error { func (h *httpGetQueryString) Execute(filePath string) error {
router := httprouter.New() router := httprouter.New()
router.GET("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
if strings.EqualFold(r.URL.Query().Get("test"), "nuclei") { if strings.EqualFold(r.URL.Query().Get("test"), "nuclei") {
fmt.Fprintf(w, "This is test querystring matcher text") fmt.Fprintf(w, "This is test querystring matcher text")
} }
})) })
ts := httptest.NewServer(router) ts := httptest.NewServer(router)
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -95,18 +95,18 @@ type httpGetRedirects struct{}
// Execute executes a test case and returns an error if occurred // Execute executes a test case and returns an error if occurred
func (h *httpGetRedirects) Execute(filePath string) error { func (h *httpGetRedirects) Execute(filePath string) error {
router := httprouter.New() router := httprouter.New()
router.GET("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
http.Redirect(w, r, "/redirected", http.StatusFound) http.Redirect(w, r, "/redirected", http.StatusFound)
})) })
router.GET("/redirected", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.GET("/redirected", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
fmt.Fprintf(w, "This is test redirects matcher text") fmt.Fprintf(w, "This is test redirects matcher text")
})) })
ts := httptest.NewServer(router) ts := httptest.NewServer(router)
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -121,14 +121,14 @@ type httpGet struct{}
// Execute executes a test case and returns an error if occurred // Execute executes a test case and returns an error if occurred
func (h *httpGet) Execute(filePath string) error { func (h *httpGet) Execute(filePath string) error {
router := httprouter.New() router := httprouter.New()
router.GET("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
fmt.Fprintf(w, "This is test matcher text") fmt.Fprintf(w, "This is test matcher text")
})) })
ts := httptest.NewServer(router) ts := httptest.NewServer(router)
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -145,7 +145,7 @@ func (h *httpPostBody) Execute(filePath string) error {
router := httprouter.New() router := httprouter.New()
var routerErr error var routerErr error
router.POST("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
routerErr = err routerErr = err
@ -154,11 +154,11 @@ func (h *httpPostBody) Execute(filePath string) error {
if strings.EqualFold(r.Form.Get("username"), "test") && strings.EqualFold(r.Form.Get("password"), "nuclei") { 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") fmt.Fprintf(w, "This is test post-body matcher text")
} }
})) })
ts := httptest.NewServer(router) ts := httptest.NewServer(router)
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -178,7 +178,7 @@ func (h *httpPostJSONBody) Execute(filePath string) error {
router := httprouter.New() router := httprouter.New()
var routerErr error var routerErr error
router.POST("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
type doc struct { type doc struct {
@ -193,11 +193,11 @@ func (h *httpPostJSONBody) Execute(filePath string) error {
if strings.EqualFold(obj.Username, "test") && strings.EqualFold(obj.Password, "nuclei") { if strings.EqualFold(obj.Username, "test") && strings.EqualFold(obj.Password, "nuclei") {
fmt.Fprintf(w, "This is test post-json-body matcher text") fmt.Fprintf(w, "This is test post-json-body matcher text")
} }
})) })
ts := httptest.NewServer(router) ts := httptest.NewServer(router)
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -217,7 +217,7 @@ func (h *httpPostMultipartBody) Execute(filePath string) error {
router := httprouter.New() router := httprouter.New()
var routerErr error var routerErr error
router.POST("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
if err := r.ParseMultipartForm(1 * 1024); err != nil { if err := r.ParseMultipartForm(1 * 1024); err != nil {
routerErr = err routerErr = err
@ -236,11 +236,11 @@ func (h *httpPostMultipartBody) Execute(filePath string) error {
if strings.EqualFold(password[0], "nuclei") && strings.EqualFold(file[0].Filename, "username") { if strings.EqualFold(password[0], "nuclei") && strings.EqualFold(file[0].Filename, "username") {
fmt.Fprintf(w, "This is test post-multipart matcher text") fmt.Fprintf(w, "This is test post-multipart matcher text")
} }
})) })
ts := httptest.NewServer(router) ts := httptest.NewServer(router)
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -260,7 +260,7 @@ func (h *httpRawDynamicExtractor) Execute(filePath string) error {
router := httprouter.New() router := httprouter.New()
var routerErr error var routerErr error
router.POST("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
routerErr = err routerErr = err
@ -269,17 +269,17 @@ func (h *httpRawDynamicExtractor) Execute(filePath string) error {
if strings.EqualFold(r.Form.Get("testing"), "parameter") { if strings.EqualFold(r.Form.Get("testing"), "parameter") {
fmt.Fprintf(w, "Token: 'nuclei'") fmt.Fprintf(w, "Token: 'nuclei'")
} }
})) })
router.GET("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
if strings.EqualFold(r.URL.Query().Get("username"), "nuclei") { if strings.EqualFold(r.URL.Query().Get("username"), "nuclei") {
fmt.Fprintf(w, "Test is test-dynamic-extractor-raw matcher text") fmt.Fprintf(w, "Test is test-dynamic-extractor-raw matcher text")
} }
})) })
ts := httptest.NewServer(router) ts := httptest.NewServer(router)
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -299,16 +299,16 @@ func (h *httpRawGetQuery) Execute(filePath string) error {
router := httprouter.New() router := httprouter.New()
var routerErr error var routerErr error
router.GET("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
if strings.EqualFold(r.URL.Query().Get("test"), "nuclei") { if strings.EqualFold(r.URL.Query().Get("test"), "nuclei") {
fmt.Fprintf(w, "Test is test raw-get-query-matcher text") fmt.Fprintf(w, "Test is test raw-get-query-matcher text")
} }
})) })
ts := httptest.NewServer(router) ts := httptest.NewServer(router)
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -328,15 +328,15 @@ func (h *httpRawGet) Execute(filePath string) error {
router := httprouter.New() router := httprouter.New()
var routerErr error var routerErr error
router.GET("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
fmt.Fprintf(w, "Test is test raw-get-matcher text") fmt.Fprintf(w, "Test is test raw-get-matcher text")
})) })
ts := httptest.NewServer(router) ts := httptest.NewServer(router)
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -356,7 +356,7 @@ func (h *httpRawPayload) Execute(filePath string) error {
router := httprouter.New() router := httprouter.New()
var routerErr error var routerErr error
router.POST("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
routerErr = err routerErr = err
@ -368,11 +368,11 @@ func (h *httpRawPayload) Execute(filePath string) error {
if strings.EqualFold(r.Form.Get("username"), "test") && (strings.EqualFold(r.Form.Get("password"), "nuclei") || strings.EqualFold(r.Form.Get("password"), "guest")) { 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") fmt.Fprintf(w, "Test is raw-payload matcher text")
} }
})) })
ts := httptest.NewServer(router) ts := httptest.NewServer(router)
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -392,7 +392,7 @@ func (h *httpRawPostBody) Execute(filePath string) error {
router := httprouter.New() router := httprouter.New()
var routerErr error var routerErr error
router.POST("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
routerErr = err routerErr = err
@ -401,11 +401,11 @@ func (h *httpRawPostBody) Execute(filePath string) error {
if strings.EqualFold(r.Form.Get("username"), "test") && strings.EqualFold(r.Form.Get("password"), "nuclei") { 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") fmt.Fprintf(w, "Test is test raw-post-body-matcher text")
} }
})) })
ts := httptest.NewServer(router) ts := httptest.NewServer(router)
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -425,7 +425,7 @@ func (h *httpRawCookieReuse) Execute(filePath string) error {
router := httprouter.New() router := httprouter.New()
var routerErr error var routerErr error
router.POST("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
routerErr = err routerErr = err
@ -434,8 +434,8 @@ func (h *httpRawCookieReuse) Execute(filePath string) error {
if strings.EqualFold(r.Form.Get("testing"), "parameter") { if strings.EqualFold(r.Form.Get("testing"), "parameter") {
http.SetCookie(w, &http.Cookie{Name: "nuclei", Value: "test"}) http.SetCookie(w, &http.Cookie{Name: "nuclei", Value: "test"})
} }
})) })
router.GET("/", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
routerErr = err routerErr = err
@ -450,11 +450,11 @@ func (h *httpRawCookieReuse) Execute(filePath string) error {
if strings.EqualFold(cookie.Value, "test") { if strings.EqualFold(cookie.Value, "test") {
fmt.Fprintf(w, "Test is test-cookie-reuse matcher text") fmt.Fprintf(w, "Test is test-cookie-reuse matcher text")
} }
})) })
ts := httptest.NewServer(router) ts := httptest.NewServer(router)
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -479,7 +479,7 @@ func (h *httpRawUnsafeRequest) Execute(filePath string) error {
}) })
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, "http://"+ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "http://"+ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -499,18 +499,18 @@ func (h *httpRequestCondition) Execute(filePath string) error {
router := httprouter.New() router := httprouter.New()
var routerErr error var routerErr error
router.GET("/200", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.GET("/200", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
w.WriteHeader(200) w.WriteHeader(200)
})) })
router.GET("/400", httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { router.GET("/400", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
httpDebugRequestDump(r) httpDebugRequestDump(r)
w.WriteHeader(400) w.WriteHeader(400)
})) })
ts := httptest.NewServer(router) ts := httptest.NewServer(router)
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }

View File

@ -32,7 +32,7 @@ func (h *networkBasic) Execute(filePath string) error {
}) })
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }
@ -75,7 +75,7 @@ func (h *networkMultiStep) Execute(filePath string) error {
}) })
defer ts.Close() defer ts.Close()
results, err := testutils.RunNucleiAndGetResults(filePath, ts.URL, debug) results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
if err != nil { if err != nil {
return err return err
} }

View File

@ -188,3 +188,10 @@ func createGroup(flagSet *goflags.FlagSet, groupName, description string, flags
currentFlag.Group(groupName) currentFlag.Group(groupName)
} }
} }
/*
HacktoberFest update: Below, you can find our ticket recommendations. Tasks with the "good first issue" label are suitable for first time contributors. If you have other ideas, or need help with getting started, join our Discord channel or reach out to @forgedhallpass.
https://github.com/issues?q=is%3Aopen+is%3Aissue+user%3Aprojectdiscovery+label%3AHacktoberfest
*/

View File

@ -2,6 +2,7 @@ package testutils
import ( import (
"errors" "errors"
"fmt"
"net" "net"
"os" "os"
"os/exec" "os/exec"
@ -9,20 +10,36 @@ import (
"strings" "strings"
) )
// RunNucleiAndGetResults returns a list of results for a template // RunNucleiTemplateAndGetResults returns a list of results for a template
func RunNucleiAndGetResults(template, url string, debug bool, extra ...string) ([]string, error) { func RunNucleiTemplateAndGetResults(template, url string, debug bool, extra ...string) ([]string, error) {
cmd := exec.Command("./nuclei", "-t", template, "-target", url, "-silent") return runNucleiAndGetResults(true, template, url, debug, extra...)
}
// RunNucleiWorkflowAndGetResults returns a list of results for a workflow
func RunNucleiWorkflowAndGetResults(template, url string, debug bool, extra ...string) ([]string, error) {
return runNucleiAndGetResults(false, template, url, debug, extra...)
}
func runNucleiAndGetResults(isTemplate bool, template, url string, debug bool, extra ...string) ([]string, error) {
var templateOrWorkflowFlag string
if isTemplate {
templateOrWorkflowFlag = "-t"
} else {
templateOrWorkflowFlag = "-w"
}
cmd := exec.Command("./nuclei", templateOrWorkflowFlag, template, "-target", url, "-silent")
if debug { if debug {
cmd = exec.Command("./nuclei", "-t", template, "-target", url, "-debug") cmd = exec.Command("./nuclei", templateOrWorkflowFlag, template, "-target", url, "-debug")
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
fmt.Println(cmd.String())
} }
cmd.Args = append(cmd.Args, extra...) cmd.Args = append(cmd.Args, extra...)
data, err := cmd.Output() data, err := cmd.Output()
if err != nil { if err != nil {
return nil, err return nil, err
} }
parts := []string{} var parts []string
items := strings.Split(string(data), "\n") items := strings.Split(string(data), "\n")
for _, i := range items { for _, i := range items {
if i != "" { if i != "" {
@ -35,9 +52,11 @@ func RunNucleiAndGetResults(template, url string, debug bool, extra ...string) (
var templateLoaded = regexp.MustCompile(`(?:Templates|Workflows) loaded[^:]*: (\d+)`) var templateLoaded = regexp.MustCompile(`(?:Templates|Workflows) loaded[^:]*: (\d+)`)
// RunNucleiBinaryAndGetLoadedTemplates returns a list of results for a template // RunNucleiBinaryAndGetLoadedTemplates returns a list of results for a template
func RunNucleiBinaryAndGetLoadedTemplates(nucleiBinary string, args []string) (string, error) { func RunNucleiBinaryAndGetLoadedTemplates(nucleiBinary string, debug bool, args []string) (string, error) {
cmd := exec.Command(nucleiBinary, args...) cmd := exec.Command(nucleiBinary, args...)
if debug {
fmt.Println(cmd.String())
}
data, err := cmd.CombinedOutput() data, err := cmd.CombinedOutput()
if err != nil { if err != nil {
return "", err return "", err
@ -49,29 +68,6 @@ func RunNucleiBinaryAndGetLoadedTemplates(nucleiBinary string, args []string) (s
return matches[0][1], nil return matches[0][1], nil
} }
// RunNucleiWorkflowAndGetResults returns a list of results for a workflow
func RunNucleiWorkflowAndGetResults(template, url string, debug bool, extra ...string) ([]string, error) {
cmd := exec.Command("./nuclei", "-w", template, "-target", url, "-silent")
if debug {
cmd = exec.Command("./nuclei", "-w", template, "-target", url, "-debug")
cmd.Stderr = os.Stderr
}
cmd.Args = append(cmd.Args, extra...)
data, err := cmd.Output()
if err != nil {
return nil, err
}
parts := []string{}
items := strings.Split(string(data), "\n")
for _, i := range items {
if i != "" {
parts = append(parts, i)
}
}
return parts, nil
}
// TestCase is a single integration test case // TestCase is a single integration test case
type TestCase interface { type TestCase interface {
// Execute executes a test case and returns any errors if occurred // Execute executes a test case and returns any errors if occurred