mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-24 13:05:27 +00:00
lint
This commit is contained in:
parent
752bd3bc67
commit
6692c1db8a
@ -19,7 +19,9 @@ func writeToFile(filename string, data []byte) {
|
||||
if err != nil {
|
||||
log.Fatalf("Could not create file %s: %s\n", filename, err)
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
_, err = file.Write(data)
|
||||
if err != nil {
|
||||
|
||||
@ -41,7 +41,9 @@ func runFunctionalTests(debug bool) (error, bool) {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not open test cases"), true
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
errored, failedTestCases := runTestCases(file, debug)
|
||||
|
||||
|
||||
@ -23,7 +23,9 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalf("Could not create file: %s\n", err)
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
err = filepath.WalkDir(templatesDirectory, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil || d.IsDir() {
|
||||
|
||||
@ -18,7 +18,9 @@ func (h *customConfigDirTest) Execute(filePath string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(customTempDirectory)
|
||||
defer func() {
|
||||
_ = os.RemoveAll(customTempDirectory)
|
||||
}()
|
||||
results, err := testutils.RunNucleiBareArgsAndGetResults(debug, []string{"NUCLEI_CONFIG_DIR=" + customTempDirectory}, "-t", filePath, "-u", "8x8exch02.8x8.com")
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -21,7 +21,7 @@ type dslVersionWarning struct{}
|
||||
func (d *dslVersionWarning) Execute(templatePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "DSL version parsing warning test")
|
||||
_, _ = fmt.Fprintf(w, "DSL version parsing warning test")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -37,7 +37,7 @@ type dslShowVersionWarning struct{}
|
||||
func (d *dslShowVersionWarning) Execute(templatePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "DSL version parsing warning test")
|
||||
_, _ = fmt.Fprintf(w, "DSL version parsing warning test")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
|
||||
@ -49,7 +49,7 @@ func (t *iterateValuesFlow) Execute(filePath string) error {
|
||||
}
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte(fmt.Sprint(testemails)))
|
||||
_, _ = fmt.Fprint(w, fmt.Sprint(testemails))
|
||||
})
|
||||
router.GET("/user/"+getBase64(testemails[0]), func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
@ -55,7 +55,7 @@ func (h *httpFuzzQuery) Execute(filePath string) error {
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
value := r.URL.Query().Get("id")
|
||||
fmt.Fprintf(w, "This is test matcher text: %v", value)
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text: %v", value)
|
||||
})
|
||||
ts := httptest.NewTLSServer(router)
|
||||
defer ts.Close()
|
||||
@ -75,7 +75,7 @@ func (h *fuzzModeOverride) Execute(filePath string) error {
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
value := r.URL.Query().Get("id")
|
||||
fmt.Fprintf(w, "This is test matcher text: %v", value)
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text: %v", value)
|
||||
})
|
||||
ts := httptest.NewTLSServer(router)
|
||||
defer ts.Close()
|
||||
@ -120,7 +120,7 @@ func (h *fuzzTypeOverride) Execute(filePath string) error {
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
value := r.URL.Query().Get("id")
|
||||
fmt.Fprintf(w, "This is test matcher text: %v", value)
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text: %v", value)
|
||||
})
|
||||
ts := httptest.NewTLSServer(router)
|
||||
defer ts.Close()
|
||||
@ -164,7 +164,7 @@ func (h *HeadlessFuzzingQuery) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
resp := fmt.Sprintf("<html><body>%s</body></html>", r.URL.Query().Get("url"))
|
||||
fmt.Fprint(w, resp)
|
||||
_, _ = fmt.Fprint(w, resp)
|
||||
})
|
||||
ts := httptest.NewTLSServer(router)
|
||||
defer ts.Close()
|
||||
@ -190,7 +190,7 @@ func (h *fuzzMultipleMode) Execute(filePath string) error {
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
resp := fmt.Sprintf("<html><body><h1>This is multi-mode fuzzing test: %v <h1></body></html>", xClientId)
|
||||
fmt.Fprint(w, resp)
|
||||
_, _ = fmt.Fprint(w, resp)
|
||||
})
|
||||
ts := httptest.NewTLSServer(router)
|
||||
defer ts.Close()
|
||||
|
||||
@ -82,13 +82,15 @@ func (h *clientCertificate) Execute(filePath string) error {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "Hello, %s!\n", r.TLS.PeerCertificates[0].Subject)
|
||||
_, _ = fmt.Fprintf(w, "Hello, %s!\n", r.TLS.PeerCertificates[0].Subject)
|
||||
})
|
||||
|
||||
_ = os.WriteFile("server.crt", []byte(serverCRT), permissionutil.ConfigFilePermission)
|
||||
_ = os.WriteFile("server.key", []byte(serverKey), permissionutil.ConfigFilePermission)
|
||||
defer os.Remove("server.crt")
|
||||
defer os.Remove("server.key")
|
||||
defer func() {
|
||||
_ = os.Remove("server.crt")
|
||||
_ = os.Remove("server.key")
|
||||
}()
|
||||
|
||||
serverCert, _ := tls.LoadX509KeyPair("server.crt", "server.key")
|
||||
|
||||
|
||||
@ -178,7 +178,9 @@ func (h *headlessFileUpload) Execute(filePath string) error {
|
||||
return
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
content, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
@ -235,7 +237,9 @@ func (h *headlessFileUploadNegative) Execute(filePath string) error {
|
||||
return
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
content, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
|
||||
@ -108,7 +108,7 @@ func (h *httpMatcherExtractorDynamicExtractor) Execute(filePath string) error {
|
||||
<a href="/domains">Domains</a>
|
||||
</body>
|
||||
</html>`
|
||||
fmt.Fprint(w, html)
|
||||
_, _ = fmt.Fprint(w, html)
|
||||
})
|
||||
router.GET("/domains", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
html := `<!DOCTYPE html>
|
||||
@ -121,7 +121,7 @@ func (h *httpMatcherExtractorDynamicExtractor) Execute(filePath string) error {
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
fmt.Fprint(w, html)
|
||||
_, _ = fmt.Fprint(w, html)
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -143,7 +143,7 @@ func (h *httpInteractshRequest) Execute(filePath string) error {
|
||||
value := r.Header.Get("url")
|
||||
if value != "" {
|
||||
if resp, _ := retryablehttp.DefaultClient().Get(value); resp != nil {
|
||||
resp.Body.Close()
|
||||
_ = resp.Body.Close()
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -213,7 +213,7 @@ func (h *httpInteractshStopAtFirstMatchRequest) Execute(filePath string) error {
|
||||
value := r.Header.Get("url")
|
||||
if value != "" {
|
||||
if resp, _ := retryablehttp.DefaultClient().Get(value); resp != nil {
|
||||
resp.Body.Close()
|
||||
_ = resp.Body.Close()
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -235,7 +235,7 @@ func (h *httpGetHeaders) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
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)
|
||||
@ -256,7 +256,7 @@ func (h *httpGetQueryString) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
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)
|
||||
@ -279,7 +279,7 @@ func (h *httpGetRedirects) Execute(filePath string) error {
|
||||
http.Redirect(w, r, "/redirected", http.StatusFound)
|
||||
})
|
||||
router.GET("/redirected", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "This is test redirects matcher text")
|
||||
_, _ = fmt.Fprintf(w, "This is test redirects matcher text")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -329,7 +329,7 @@ func (h *httpDisableRedirects) Execute(filePath string) error {
|
||||
http.Redirect(w, r, "/redirected", http.StatusMovedPermanently)
|
||||
})
|
||||
router.GET("/redirected", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "This is test redirects matcher text")
|
||||
_, _ = fmt.Fprintf(w, "This is test redirects matcher text")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -348,7 +348,7 @@ type httpGet struct{}
|
||||
func (h *httpGet) 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")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -367,7 +367,7 @@ type httpDSLVariable struct{}
|
||||
func (h *httpDSLVariable) 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")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -450,7 +450,7 @@ func (h *httpPostBody) Execute(filePath string) error {
|
||||
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")
|
||||
_, _ = fmt.Fprintf(w, "This is test post-body matcher text")
|
||||
}
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
@ -485,7 +485,7 @@ func (h *httpPostJSONBody) Execute(filePath string) error {
|
||||
return
|
||||
}
|
||||
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)
|
||||
@ -525,7 +525,7 @@ func (h *httpPostMultipartBody) Execute(filePath string) error {
|
||||
return
|
||||
}
|
||||
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)
|
||||
@ -555,12 +555,12 @@ func (h *httpRawDynamicExtractor) Execute(filePath string) error {
|
||||
return
|
||||
}
|
||||
if strings.EqualFold(r.Form.Get("testing"), "parameter") {
|
||||
fmt.Fprintf(w, "Token: 'nuclei'")
|
||||
_, _ = fmt.Fprintf(w, "Token: 'nuclei'")
|
||||
}
|
||||
})
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
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)
|
||||
@ -584,7 +584,7 @@ func (h *httpRawGetQuery) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
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)
|
||||
@ -604,7 +604,7 @@ type httpRawGet struct{}
|
||||
func (h *httpRawGet) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "Test is test raw-get-matcher text")
|
||||
_, _ = fmt.Fprintf(w, "Test is test raw-get-matcher text")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -633,7 +633,7 @@ func (h *httpRawWithParams) Execute(filePath string) error {
|
||||
if !reflect.DeepEqual(params["key2"], []string{"value2"}) {
|
||||
errx = errorutil.WrapfWithNil(errx, "expected %v, got %v", []string{"value2"}, params["key2"])
|
||||
}
|
||||
fmt.Fprintf(w, "Test is test raw-params-matcher text")
|
||||
_, _ = fmt.Fprintf(w, "Test is test raw-params-matcher text")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -685,11 +685,12 @@ func (h *httpRawPayload) Execute(filePath string) error {
|
||||
routerErr = err
|
||||
return
|
||||
}
|
||||
// nolint
|
||||
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")
|
||||
_, _ = fmt.Fprintf(w, "Test is raw-payload matcher text")
|
||||
}
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
@ -719,7 +720,7 @@ func (h *httpRawPostBody) Execute(filePath string) error {
|
||||
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")
|
||||
_, _ = fmt.Fprintf(w, "Test is test raw-post-body-matcher text")
|
||||
}
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
@ -872,7 +873,7 @@ func (h *httpRawCookieReuse) Execute(filePath string) error {
|
||||
}
|
||||
|
||||
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)
|
||||
@ -950,7 +951,9 @@ func (h *httpRequestSelfContained) Execute(filePath string) error {
|
||||
go func() {
|
||||
_ = server.ListenAndServe()
|
||||
}()
|
||||
defer server.Close()
|
||||
defer func() {
|
||||
_ = server.Close()
|
||||
}()
|
||||
|
||||
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "", debug, "-esc")
|
||||
if err != nil {
|
||||
@ -986,7 +989,9 @@ func (h *httpRequestSelfContainedWithParams) Execute(filePath string) error {
|
||||
go func() {
|
||||
_ = server.ListenAndServe()
|
||||
}()
|
||||
defer server.Close()
|
||||
defer func() {
|
||||
_ = server.Close()
|
||||
}()
|
||||
|
||||
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "", debug, "-esc")
|
||||
if err != nil {
|
||||
@ -1019,7 +1024,9 @@ func (h *httpRequestSelfContainedFileInput) Execute(filePath string) error {
|
||||
go func() {
|
||||
_ = server.ListenAndServe()
|
||||
}()
|
||||
defer server.Close()
|
||||
defer func() {
|
||||
_ = server.Close()
|
||||
}()
|
||||
|
||||
// create temp file
|
||||
FileLoc, err := os.CreateTemp("", "self-contained-payload-*.txt")
|
||||
@ -1029,7 +1036,9 @@ func (h *httpRequestSelfContainedFileInput) Execute(filePath string) error {
|
||||
if _, err := FileLoc.Write([]byte("one\ntwo\n")); err != nil {
|
||||
return errorutil.NewWithErr(err).Msgf("failed to write payload to temp file")
|
||||
}
|
||||
defer FileLoc.Close()
|
||||
defer func() {
|
||||
_ = FileLoc.Close()
|
||||
}()
|
||||
|
||||
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "", debug, "-V", "test="+FileLoc.Name(), "-esc")
|
||||
if err != nil {
|
||||
@ -1052,7 +1061,7 @@ type httpGetCaseInsensitive struct{}
|
||||
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")
|
||||
_, _ = fmt.Fprintf(w, "THIS IS TEST MATCHER TEXT")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -1071,7 +1080,7 @@ type httpGetCaseInsensitiveCluster struct{}
|
||||
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")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -1154,7 +1163,7 @@ type httpStopAtFirstMatch struct{}
|
||||
func (h *httpStopAtFirstMatch) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "This is test")
|
||||
_, _ = fmt.Fprintf(w, "This is test")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -1173,7 +1182,7 @@ type httpStopAtFirstMatchWithExtractors struct{}
|
||||
func (h *httpStopAtFirstMatchWithExtractors) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "This is test")
|
||||
_, _ = fmt.Fprintf(w, "This is test")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -1192,7 +1201,7 @@ type httpVariables struct{}
|
||||
func (h *httpVariables) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "%s\n%s\n%s", r.Header.Get("Test"), r.Header.Get("Another"), r.Header.Get("Email"))
|
||||
_, _ = fmt.Fprintf(w, "%s\n%s\n%s", r.Header.Get("Test"), r.Header.Get("Another"), r.Header.Get("Email"))
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -1294,7 +1303,7 @@ func (h *httpRedirectMatchURL) Execute(filePath string) error {
|
||||
_, _ = w.Write([]byte("This is test redirects matcher text"))
|
||||
})
|
||||
router.GET("/redirected", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "This is test redirects matcher text")
|
||||
_, _ = fmt.Fprintf(w, "This is test redirects matcher text")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -1342,7 +1351,7 @@ func (h *annotationTimeout) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
time.Sleep(4 * time.Second)
|
||||
fmt.Fprintf(w, "This is test matcher text")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
})
|
||||
ts := httptest.NewTLSServer(router)
|
||||
defer ts.Close()
|
||||
@ -1362,7 +1371,7 @@ func (h *customAttackType) Execute(filePath string) error {
|
||||
got := []string{}
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
got = append(got, r.URL.RawQuery)
|
||||
fmt.Fprintf(w, "This is test custom payload")
|
||||
_, _ = fmt.Fprintf(w, "This is test custom payload")
|
||||
})
|
||||
ts := httptest.NewTLSServer(router)
|
||||
defer ts.Close()
|
||||
@ -1410,7 +1419,7 @@ func (h *httpCLBodyWithoutHeader) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
w.Header()["Content-Length"] = []string{"-1"}
|
||||
fmt.Fprintf(w, "this is a test")
|
||||
_, _ = fmt.Fprintf(w, "this is a test")
|
||||
})
|
||||
ts := httptest.NewTLSServer(router)
|
||||
defer ts.Close()
|
||||
@ -1430,7 +1439,7 @@ func (h *httpCLBodyWithHeader) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
w.Header()["Content-Length"] = []string{"50000"}
|
||||
fmt.Fprintf(w, "this is a test")
|
||||
_, _ = fmt.Fprintf(w, "this is a test")
|
||||
})
|
||||
ts := httptest.NewTLSServer(router)
|
||||
defer ts.Close()
|
||||
@ -1449,7 +1458,7 @@ type ConstantWithCliVar struct{}
|
||||
func (h *ConstantWithCliVar) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprint(w, r.URL.Query().Get("p"))
|
||||
_, _ = fmt.Fprint(w, r.URL.Query().Get("p"))
|
||||
})
|
||||
ts := httptest.NewTLSServer(router)
|
||||
defer ts.Close()
|
||||
@ -1486,10 +1495,10 @@ type httpDisablePathAutomerge struct{}
|
||||
func (h *httpDisablePathAutomerge) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/api/v1/test", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprint(w, r.URL.Query().Get("id"))
|
||||
_, _ = fmt.Fprint(w, r.URL.Query().Get("id"))
|
||||
})
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprint(w, "empty path in raw request")
|
||||
_, _ = fmt.Fprint(w, "empty path in raw request")
|
||||
})
|
||||
|
||||
ts := httptest.NewServer(router)
|
||||
@ -1523,10 +1532,10 @@ func (h *httpPreprocessor) Execute(filePath string) error {
|
||||
value := r.URL.RequestURI()
|
||||
if re.MatchString(value) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprint(w, "ok")
|
||||
_, _ = fmt.Fprint(w, "ok")
|
||||
} else {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
fmt.Fprint(w, "not ok")
|
||||
_, _ = fmt.Fprint(w, "not ok")
|
||||
}
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
@ -1547,11 +1556,11 @@ func (h *httpMultiRequest) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/ping", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprint(w, "ping")
|
||||
_, _ = fmt.Fprint(w, "ping")
|
||||
})
|
||||
router.GET("/pong", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprint(w, "pong")
|
||||
_, _ = fmt.Fprint(w, "pong")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
|
||||
@ -89,7 +89,9 @@ func main() {
|
||||
// start fuzz playground server
|
||||
defer fuzzplayground.Cleanup()
|
||||
server := fuzzplayground.GetPlaygroundServer()
|
||||
defer server.Close()
|
||||
defer func() {
|
||||
_ = server.Close()
|
||||
}()
|
||||
go func() {
|
||||
if err := server.Start("localhost:8082"); err != nil {
|
||||
if !strings.Contains(err.Error(), "Server closed") {
|
||||
|
||||
@ -48,9 +48,9 @@ func (h *goIntegrationTest) Execute(templatePath string) error {
|
||||
router := httprouter.New()
|
||||
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "This is test matcher text")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
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)
|
||||
|
||||
@ -31,9 +31,9 @@ func (h *remoteTemplateList) Execute(templateList string) error {
|
||||
router := httprouter.New()
|
||||
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "This is test matcher text")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
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")
|
||||
}
|
||||
})
|
||||
|
||||
@ -55,7 +55,9 @@ func (h *remoteTemplateList) Execute(templateList string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove("test-config.yaml")
|
||||
defer func() {
|
||||
_ = os.Remove("test-config.yaml")
|
||||
}()
|
||||
|
||||
results, err := testutils.RunNucleiBareArgsAndGetResults(debug, nil, "-target", ts.URL, "-template-url", ts.URL+"/template_list", "-config", "test-config.yaml")
|
||||
if err != nil {
|
||||
@ -72,9 +74,9 @@ func (h *excludedTemplate) Execute(templateList string) error {
|
||||
router := httprouter.New()
|
||||
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "This is test matcher text")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
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)
|
||||
@ -95,9 +97,9 @@ func (h *remoteTemplateListNotAllowed) Execute(templateList string) error {
|
||||
router := httprouter.New()
|
||||
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "This is test matcher text")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
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")
|
||||
}
|
||||
})
|
||||
|
||||
@ -130,9 +132,9 @@ func (h *remoteWorkflowList) Execute(workflowList string) error {
|
||||
router := httprouter.New()
|
||||
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "This is test matcher text")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
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")
|
||||
}
|
||||
})
|
||||
|
||||
@ -154,7 +156,9 @@ func (h *remoteWorkflowList) Execute(workflowList string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove("test-config.yaml")
|
||||
defer func() {
|
||||
_ = os.Remove("test-config.yaml")
|
||||
}()
|
||||
|
||||
results, err := testutils.RunNucleiBareArgsAndGetResults(debug, nil, "-target", ts.URL, "-workflow-url", ts.URL+"/workflow_list", "-config", "test-config.yaml")
|
||||
if err != nil {
|
||||
@ -177,7 +181,9 @@ func (h *nonExistentTemplateList) Execute(nonExistingTemplateList string) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove("test-config.yaml")
|
||||
defer func() {
|
||||
_ = os.Remove("test-config.yaml")
|
||||
}()
|
||||
|
||||
_, err = testutils.RunNucleiBareArgsAndGetResults(debug, nil, "-target", ts.URL, "-template-url", ts.URL+"/404", "-config", "test-config.yaml")
|
||||
if err == nil {
|
||||
@ -200,7 +206,9 @@ func (h *nonExistentWorkflowList) Execute(nonExistingWorkflowList string) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove("test-config.yaml")
|
||||
defer func() {
|
||||
_ = os.Remove("test-config.yaml")
|
||||
}()
|
||||
|
||||
_, err = testutils.RunNucleiBareArgsAndGetResults(debug, nil, "-target", ts.URL, "-workflow-url", ts.URL+"/404", "-config", "test-config.yaml")
|
||||
if err == nil {
|
||||
|
||||
@ -33,7 +33,9 @@ func (h *networkBasic) Execute(filePath string) error {
|
||||
var routerErr error
|
||||
|
||||
ts := testutils.NewTCPServer(nil, defaultStaticPort, func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
data, err := reader.ConnReadNWithTimeout(conn, 4, time.Duration(5)*time.Second)
|
||||
if err != nil {
|
||||
@ -68,7 +70,9 @@ func (h *networkMultiStep) Execute(filePath string) error {
|
||||
var routerErr error
|
||||
|
||||
ts := testutils.NewTCPServer(nil, defaultStaticPort, func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
data, err := reader.ConnReadNWithTimeout(conn, 5, time.Duration(5)*time.Second)
|
||||
if err != nil {
|
||||
@ -114,7 +118,9 @@ type networkRequestSelContained struct{}
|
||||
// Execute executes a test case and returns an error if occurred
|
||||
func (h *networkRequestSelContained) Execute(filePath string) error {
|
||||
ts := testutils.NewTCPServer(nil, defaultStaticPort, func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
_, _ = conn.Write([]byte("Authentication successful"))
|
||||
})
|
||||
@ -134,7 +140,9 @@ func (h *networkVariables) Execute(filePath string) error {
|
||||
var routerErr error
|
||||
|
||||
ts := testutils.NewTCPServer(nil, defaultStaticPort, func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
data, err := reader.ConnReadNWithTimeout(conn, 4, time.Duration(5)*time.Second)
|
||||
if err != nil {
|
||||
@ -162,7 +170,9 @@ type networkPort struct{}
|
||||
|
||||
func (n *networkPort) Execute(filePath string) error {
|
||||
ts := testutils.NewTCPServer(nil, 23846, func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
data, err := reader.ConnReadNWithTimeout(conn, 4, time.Duration(5)*time.Second)
|
||||
if err != nil {
|
||||
@ -195,7 +205,9 @@ func (n *networkPort) Execute(filePath string) error {
|
||||
|
||||
// this is positive test case where we expect port to be overridden and 34567 to be used
|
||||
ts2 := testutils.NewTCPServer(nil, 34567, func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
data, err := reader.ConnReadNWithTimeout(conn, 4, time.Duration(5)*time.Second)
|
||||
if err != nil {
|
||||
|
||||
@ -21,7 +21,9 @@ type sslBasic struct{}
|
||||
// Execute executes a test case and returns an error if occurred
|
||||
func (h *sslBasic) Execute(filePath string) error {
|
||||
ts := testutils.NewTCPServer(&tls.Config{}, defaultStaticPort, func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
data := make([]byte, 4)
|
||||
if _, err := conn.Read(data); err != nil {
|
||||
return
|
||||
@ -42,7 +44,9 @@ type sslBasicZtls struct{}
|
||||
// Execute executes a test case and returns an error if occurred
|
||||
func (h *sslBasicZtls) Execute(filePath string) error {
|
||||
ts := testutils.NewTCPServer(&tls.Config{}, defaultStaticPort, func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
data := make([]byte, 4)
|
||||
if _, err := conn.Read(data); err != nil {
|
||||
return
|
||||
@ -63,7 +67,9 @@ type sslCustomCipher struct{}
|
||||
// Execute executes a test case and returns an error if occurred
|
||||
func (h *sslCustomCipher) Execute(filePath string) error {
|
||||
ts := testutils.NewTCPServer(&tls.Config{CipherSuites: []uint16{tls.TLS_AES_128_GCM_SHA256}}, defaultStaticPort, func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
data := make([]byte, 4)
|
||||
if _, err := conn.Read(data); err != nil {
|
||||
return
|
||||
@ -84,7 +90,9 @@ type sslCustomVersion struct{}
|
||||
// Execute executes a test case and returns an error if occurred
|
||||
func (h *sslCustomVersion) Execute(filePath string) error {
|
||||
ts := testutils.NewTCPServer(&tls.Config{MinVersion: tls.VersionTLS12, MaxVersion: tls.VersionTLS12}, defaultStaticPort, func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
data := make([]byte, 4)
|
||||
if _, err := conn.Read(data); err != nil {
|
||||
return
|
||||
@ -104,7 +112,9 @@ type sslWithVars struct{}
|
||||
|
||||
func (h *sslWithVars) Execute(filePath string) error {
|
||||
ts := testutils.NewTCPServer(&tls.Config{}, defaultStaticPort, func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
data := make([]byte, 4)
|
||||
if _, err := conn.Read(data); err != nil {
|
||||
return
|
||||
@ -128,7 +138,9 @@ func (h *sslMultiReq) Execute(filePath string) error {
|
||||
MinVersion: tls.VersionSSL30,
|
||||
MaxVersion: tls.VersionTLS11,
|
||||
}, defaultStaticPort, func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
data := make([]byte, 4)
|
||||
if _, err := conn.Read(data); err != nil {
|
||||
return
|
||||
|
||||
@ -19,7 +19,9 @@ func (h *templateDirWithTargetTest) Execute(filePath string) error {
|
||||
if err != nil {
|
||||
return errorutil.NewWithErr(err).Msgf("failed to create temp dir")
|
||||
}
|
||||
defer os.RemoveAll(tempdir)
|
||||
defer func() {
|
||||
_ = os.RemoveAll(tempdir)
|
||||
}()
|
||||
|
||||
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug, "-ud", tempdir)
|
||||
if err != nil {
|
||||
|
||||
@ -62,7 +62,7 @@ type workflowBasic struct{}
|
||||
func (h *workflowBasic) 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")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -81,7 +81,7 @@ type workflowConditionMatched struct{}
|
||||
func (h *workflowConditionMatched) 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")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -100,7 +100,7 @@ type workflowConditionUnmatch struct{}
|
||||
func (h *workflowConditionUnmatch) 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")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -119,7 +119,7 @@ type workflowMatcherName struct{}
|
||||
func (h *workflowMatcherName) 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")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -138,7 +138,7 @@ type workflowComplexConditions struct{}
|
||||
func (h *workflowComplexConditions) 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")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -162,11 +162,11 @@ type workflowHttpKeyValueShare struct{}
|
||||
func (h *workflowHttpKeyValueShare) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/path1", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "href=\"test-value\"")
|
||||
_, _ = fmt.Fprintf(w, "href=\"test-value\"")
|
||||
})
|
||||
router.GET("/path2", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
fmt.Fprintf(w, "%s", body)
|
||||
_, _ = fmt.Fprintf(w, "%s", body)
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -214,11 +214,11 @@ func (h *workflowMultiProtocolKeyValueShare) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
// the response of path1 contains a domain that will be extracted and shared with the second template
|
||||
router.GET("/path1", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "href=\"blog.projectdiscovery.io\"")
|
||||
_, _ = fmt.Fprintf(w, "href=\"blog.projectdiscovery.io\"")
|
||||
})
|
||||
// path2 responds with the value of the "extracted" query parameter, e.g.: /path2?extracted=blog.projectdiscovery.io => blog.projectdiscovery.io
|
||||
router.GET("/path2", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "%s", r.URL.Query().Get("extracted"))
|
||||
_, _ = fmt.Fprintf(w, "%s", r.URL.Query().Get("extracted"))
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
@ -238,15 +238,15 @@ func (h *workflowMultiMatchKeyValueShare) Execute(filePath string) error {
|
||||
var receivedData []string
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "This is test matcher text")
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
})
|
||||
router.GET("/path1", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
fmt.Fprintf(w, "href=\"test-value-%s\"", r.URL.Query().Get("v"))
|
||||
_, _ = fmt.Fprintf(w, "href=\"test-value-%s\"", r.URL.Query().Get("v"))
|
||||
})
|
||||
router.GET("/path2", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
receivedData = append(receivedData, string(body))
|
||||
fmt.Fprintf(w, "test-value")
|
||||
_, _ = fmt.Fprintf(w, "test-value")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
|
||||
@ -141,8 +141,8 @@ func main() {
|
||||
}
|
||||
|
||||
pprof.StopCPUProfile()
|
||||
memProfileFile.Close()
|
||||
traceFile.Close()
|
||||
_ = memProfileFile.Close()
|
||||
_ = traceFile.Close()
|
||||
trace.Stop()
|
||||
|
||||
runtime.MemProfileRate = oldMemProfileRate
|
||||
@ -228,7 +228,7 @@ func main() {
|
||||
nucleiRunner.Close()
|
||||
// on successful execution remove the resume file in case it exists
|
||||
if fileutil.FileExists(resumeFileName) {
|
||||
os.Remove(resumeFileName)
|
||||
_ = os.Remove(resumeFileName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -135,7 +135,9 @@ func process(opts options) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(tempDir)
|
||||
defer func() {
|
||||
_ = os.RemoveAll(tempDir)
|
||||
}()
|
||||
|
||||
var errFile *os.File
|
||||
if opts.errorLogFile != "" {
|
||||
@ -143,7 +145,9 @@ func process(opts options) error {
|
||||
if err != nil {
|
||||
gologger.Fatal().Msgf("could not open error log file: %s\n", err)
|
||||
}
|
||||
defer errFile.Close()
|
||||
defer func() {
|
||||
_ = errFile.Close()
|
||||
}()
|
||||
}
|
||||
|
||||
templateCatalog := disk.NewCatalog(filepath.Dir(opts.input))
|
||||
@ -226,7 +230,7 @@ func logErrMsg(path string, err error, debug bool, errFile *os.File) string {
|
||||
msg = fmt.Sprintf("❌ template: %s err: %s\n", path, err)
|
||||
}
|
||||
if errFile != nil {
|
||||
_, _ = errFile.WriteString(fmt.Sprintf("❌ template: %s err: %s\n", path, err))
|
||||
_, _ = fmt.Fprintf(errFile, "❌ template: %s err: %s\n", path, err)
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
@ -18,7 +18,9 @@ func main() {
|
||||
|
||||
defer fuzzplayground.Cleanup()
|
||||
server := fuzzplayground.GetPlaygroundServer()
|
||||
defer server.Close()
|
||||
defer func() {
|
||||
_ = server.Close()
|
||||
}()
|
||||
|
||||
// Start the server
|
||||
if err := server.Start(addr); err != nil {
|
||||
|
||||
@ -34,6 +34,7 @@ func main() {
|
||||
}
|
||||
|
||||
func initializeNucleiEngine() (*nuclei.NucleiEngine, error) {
|
||||
//nolint
|
||||
return nuclei.NewNucleiEngine(
|
||||
nuclei.WithTemplateFilters(nuclei.TemplateFilters{Tags: []string{"oast"}}),
|
||||
nuclei.EnableStatsWithOpts(nuclei.StatsOptions{MetricServerPort: 6064}),
|
||||
|
||||
@ -127,8 +127,10 @@ func (u *UploadWriter) autoCommit(ctx context.Context, r *io.PipeReader) {
|
||||
|
||||
// continuously read from the reader and send to channel
|
||||
go func() {
|
||||
defer r.Close()
|
||||
defer close(ch)
|
||||
defer func() {
|
||||
_ = r.Close()
|
||||
close(ch)
|
||||
}()
|
||||
for {
|
||||
data, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
@ -213,7 +215,9 @@ func (u *UploadWriter) upload(data []byte) error {
|
||||
if err != nil {
|
||||
return errorutil.NewWithErr(err).Msgf("could not upload results")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() {
|
||||
_ = resp.Body.Close()
|
||||
}()
|
||||
bin, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return errorutil.NewWithErr(err).Msgf("could not get id from response")
|
||||
@ -251,12 +255,12 @@ func (u *UploadWriter) getRequest(bin []byte) (*retryablehttp.Request, error) {
|
||||
return nil, errorutil.NewWithErr(err).Msgf("could not create cloud upload request")
|
||||
}
|
||||
// add pdtm meta params
|
||||
req.URL.Params.Merge(updateutils.GetpdtmParams(config.Version))
|
||||
req.Params.Merge(updateutils.GetpdtmParams(config.Version))
|
||||
// if it is upload endpoint also include name if it exists
|
||||
if u.scanName != "" && req.URL.Path == uploadEndpoint {
|
||||
req.URL.Params.Add("name", u.scanName)
|
||||
if u.scanName != "" && req.Path == uploadEndpoint {
|
||||
req.Params.Add("name", u.scanName)
|
||||
}
|
||||
req.URL.Update()
|
||||
req.Update()
|
||||
|
||||
req.Header.Set(pdcpauth.ApiKeyHeaderName, u.creds.APIKey)
|
||||
if u.TeamID != NoneTeamID && u.TeamID != "" {
|
||||
|
||||
@ -47,7 +47,7 @@ func DoHealthCheck(options *types.Options) string {
|
||||
}
|
||||
c4, err := net.Dial("tcp4", "scanme.sh:80")
|
||||
if err == nil && c4 != nil {
|
||||
c4.Close()
|
||||
_ = c4.Close()
|
||||
}
|
||||
testResult = "Ok"
|
||||
if err != nil {
|
||||
@ -56,7 +56,7 @@ func DoHealthCheck(options *types.Options) string {
|
||||
test.WriteString(fmt.Sprintf("IPv4 connectivity to scanme.sh:80 => %s\n", testResult))
|
||||
c6, err := net.Dial("tcp6", "scanme.sh:80")
|
||||
if err == nil && c6 != nil {
|
||||
c6.Close()
|
||||
_ = c6.Close()
|
||||
}
|
||||
testResult = "Ok"
|
||||
if err != nil {
|
||||
@ -65,7 +65,7 @@ func DoHealthCheck(options *types.Options) string {
|
||||
test.WriteString(fmt.Sprintf("IPv6 connectivity to scanme.sh:80 => %s\n", testResult))
|
||||
u4, err := net.Dial("udp4", "scanme.sh:53")
|
||||
if err == nil && u4 != nil {
|
||||
u4.Close()
|
||||
_ = u4.Close()
|
||||
}
|
||||
testResult = "Ok"
|
||||
if err != nil {
|
||||
|
||||
@ -121,7 +121,7 @@ func ParseOptions(options *types.Options) {
|
||||
|
||||
// Set GitHub token in env variable. runner.getGHClientWithToken() reads token from env
|
||||
if options.GitHubToken != "" && os.Getenv("GITHUB_TOKEN") != options.GitHubToken {
|
||||
os.Setenv("GITHUB_TOKEN", options.GitHubToken)
|
||||
_ = os.Setenv("GITHUB_TOKEN", options.GitHubToken)
|
||||
}
|
||||
|
||||
if options.UncoverQuery != nil {
|
||||
@ -303,7 +303,9 @@ func createReportingOptions(options *types.Options) (*reporting.Options, error)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not open reporting config file")
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
if err := yaml.DecodeAndValidate(file, reportingOptions); err != nil {
|
||||
return nil, errors.Wrap(err, "could not parse reporting config file")
|
||||
@ -380,7 +382,9 @@ func loadResolvers(options *types.Options) {
|
||||
if err != nil {
|
||||
gologger.Fatal().Msgf("Could not open resolvers file: %s\n", err)
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
|
||||
@ -30,7 +30,9 @@ func loadProxyServers(options *types.Options) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open proxy file: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
proxy := scanner.Text()
|
||||
@ -52,12 +54,13 @@ func loadProxyServers(options *types.Options) error {
|
||||
return errorutil.WrapfWithNil(err, "failed to parse proxy got %v", err)
|
||||
}
|
||||
if options.ProxyInternal {
|
||||
os.Setenv(HTTP_PROXY_ENV, proxyURL.String())
|
||||
_ = os.Setenv(HTTP_PROXY_ENV, proxyURL.String())
|
||||
}
|
||||
if proxyURL.Scheme == proxyutils.HTTP || proxyURL.Scheme == proxyutils.HTTPS {
|
||||
switch proxyURL.Scheme {
|
||||
case proxyutils.HTTP, proxyutils.HTTPS:
|
||||
gologger.Verbose().Msgf("Using %s as proxy server", proxyURL.String())
|
||||
options.AliveHttpProxy = proxyURL.String()
|
||||
} else if proxyURL.Scheme == proxyutils.SOCKS5 {
|
||||
case proxyutils.SOCKS5:
|
||||
options.AliveSocksProxy = proxyURL.String()
|
||||
gologger.Verbose().Msgf("Using %s as socket proxy server", proxyURL.String())
|
||||
}
|
||||
|
||||
@ -439,6 +439,7 @@ func (r *Runner) setupPDCPUpload(writer output.Writer) output.Writer {
|
||||
if r.options.ScanID != "" {
|
||||
r.options.EnableCloudUpload = true
|
||||
}
|
||||
//nolint
|
||||
if !(r.options.EnableCloudUpload || EnableCloudUpload) {
|
||||
r.pdcpUploadErrMsg = fmt.Sprintf("[%v] Scan results upload to cloud is disabled.", r.colorizer.BrightYellow("WRN"))
|
||||
return writer
|
||||
@ -940,7 +941,9 @@ func UploadResultsToCloud(options *types.Options) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not open scan upload file")
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
gologger.Info().Msgf("Uploading scan results to cloud dashboard from %s", options.ScanUploadFile)
|
||||
dec := json.NewDecoder(file)
|
||||
|
||||
@ -64,8 +64,8 @@ func TestWalkReflectStructAssignsEnvVars(t *testing.T) {
|
||||
B: "$VAR_TWO",
|
||||
},
|
||||
}
|
||||
os.Setenv("VAR_EXAMPLE", "value")
|
||||
os.Setenv("VAR_TWO", "value2")
|
||||
_ = os.Setenv("VAR_EXAMPLE", "value")
|
||||
_ = os.Setenv("VAR_TWO", "value2")
|
||||
|
||||
Walk(testStruct, expandEndVars)
|
||||
|
||||
@ -79,9 +79,9 @@ func TestWalkReflectStructHandlesDifferentTypes(t *testing.T) {
|
||||
B: "$VAR_TWO",
|
||||
C: "$VAR_THREE",
|
||||
}
|
||||
os.Setenv("VAR_EXAMPLE", "value")
|
||||
os.Setenv("VAR_TWO", "2")
|
||||
os.Setenv("VAR_THREE", "true")
|
||||
_ = os.Setenv("VAR_EXAMPLE", "value")
|
||||
_ = os.Setenv("VAR_TWO", "2")
|
||||
_ = os.Setenv("VAR_THREE", "true")
|
||||
|
||||
Walk(testStruct, expandEndVars)
|
||||
|
||||
@ -96,9 +96,9 @@ func TestWalkReflectStructEmpty(t *testing.T) {
|
||||
B: "",
|
||||
C: "$VAR_THREE",
|
||||
}
|
||||
os.Setenv("VAR_EXAMPLE", "value")
|
||||
os.Setenv("VAR_TWO", "2")
|
||||
os.Setenv("VAR_THREE", "true")
|
||||
_ = os.Setenv("VAR_EXAMPLE", "value")
|
||||
_ = os.Setenv("VAR_TWO", "2")
|
||||
_ = os.Setenv("VAR_THREE", "true")
|
||||
|
||||
Walk(testStruct, expandEndVars)
|
||||
|
||||
@ -116,7 +116,7 @@ func TestWalkReflectStructWithNoYamlTag(t *testing.T) {
|
||||
C: "$GITHUB_USER",
|
||||
}
|
||||
|
||||
os.Setenv("GITHUB_USER", "testuser")
|
||||
_ = os.Setenv("GITHUB_USER", "testuser")
|
||||
|
||||
Walk(test, expandEndVars)
|
||||
require.Equal(t, "testuser", test.A)
|
||||
@ -132,9 +132,9 @@ func TestWalkReflectStructHandlesNestedStructs(t *testing.T) {
|
||||
C: "$VAR_THREE",
|
||||
},
|
||||
}
|
||||
os.Setenv("VAR_EXAMPLE", "value")
|
||||
os.Setenv("VAR_TWO", "2")
|
||||
os.Setenv("VAR_THREE", "true")
|
||||
_ = os.Setenv("VAR_EXAMPLE", "value")
|
||||
_ = os.Setenv("VAR_TWO", "2")
|
||||
_ = os.Setenv("VAR_THREE", "true")
|
||||
|
||||
Walk(testStruct, expandEndVars)
|
||||
|
||||
|
||||
@ -125,7 +125,7 @@ func NewStatsServer(fuzzStatsDB *stats.Tracker) (*DASTServer, error) {
|
||||
|
||||
func (s *DASTServer) Close() {
|
||||
s.nucleiExecutor.Close()
|
||||
s.echo.Close()
|
||||
_ = s.echo.Close()
|
||||
s.tasksPool.StopAndWaitFor(1 * time.Minute)
|
||||
}
|
||||
|
||||
|
||||
@ -43,8 +43,8 @@ func (d *Dynamic) GetDomainAndDomainRegex() ([]string, []string) {
|
||||
domainRegex = append(domainRegex, secret.DomainsRegex...)
|
||||
}
|
||||
if d.Secret != nil {
|
||||
domains = append(domains, d.Secret.Domains...)
|
||||
domainRegex = append(domainRegex, d.Secret.DomainsRegex...)
|
||||
domains = append(domains, d.Domains...)
|
||||
domainRegex = append(domainRegex, d.DomainsRegex...)
|
||||
}
|
||||
uniqueDomains := sliceutil.Dedupe(domains)
|
||||
uniqueDomainRegex := sliceutil.Dedupe(domainRegex)
|
||||
@ -74,7 +74,7 @@ func (d *Dynamic) Validate() error {
|
||||
}
|
||||
|
||||
if d.Secret != nil {
|
||||
d.Secret.skipCookieParse = true // skip cookie parsing in dynamic secrets during validation
|
||||
d.skipCookieParse = true // skip cookie parsing in dynamic secrets during validation
|
||||
if err := d.Secret.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -187,7 +187,7 @@ func (d *Dynamic) GetStrategies() []AuthStrategy {
|
||||
}
|
||||
var strategies []AuthStrategy
|
||||
if d.Secret != nil {
|
||||
strategies = append(strategies, d.Secret.GetStrategy())
|
||||
strategies = append(strategies, d.GetStrategy())
|
||||
}
|
||||
for _, secret := range d.Secrets {
|
||||
strategies = append(strategies, secret.GetStrategy())
|
||||
|
||||
@ -20,7 +20,9 @@ func ReadIgnoreFile() IgnoreFile {
|
||||
gologger.Error().Msgf("Could not read nuclei-ignore file: %s\n", err)
|
||||
return IgnoreFile{}
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
ignore := IgnoreFile{}
|
||||
if err := yaml.NewDecoder(file).Decode(&ignore); err != nil {
|
||||
|
||||
@ -74,7 +74,9 @@ func getTemplateID(filePath string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
return GetTemplateIDFromReader(file, filePath)
|
||||
}
|
||||
|
||||
|
||||
@ -117,7 +117,9 @@ func generateAITemplate(prompt string) (string, string, error) {
|
||||
if err != nil {
|
||||
return "", "", errorutil.New("Failed to send HTTP request: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() {
|
||||
_ = resp.Body.Close()
|
||||
}()
|
||||
|
||||
if resp.StatusCode == http.StatusUnauthorized {
|
||||
return "", "", errorutil.New("Invalid API Key or API Key not configured, Create one for free at https://cloud.projectdiscovery.io/")
|
||||
|
||||
@ -239,7 +239,9 @@ func (store *Store) ReadTemplateFromURI(uri string, remote bool) ([]byte, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() {
|
||||
_ = resp.Body.Close()
|
||||
}()
|
||||
return io.ReadAll(resp.Body)
|
||||
} else {
|
||||
return os.ReadFile(uri)
|
||||
|
||||
@ -49,9 +49,10 @@ func getRemoteTemplatesAndWorkflows(templateURLs, workflowURLs, remoteTemplateDo
|
||||
err = remoteContent.Error
|
||||
}
|
||||
} else {
|
||||
if remoteContent.Type == Template {
|
||||
switch remoteContent.Type {
|
||||
case Template:
|
||||
remoteTemplateList = append(remoteTemplateList, remoteContent.Content...)
|
||||
} else if remoteContent.Type == Workflow {
|
||||
case Workflow:
|
||||
remoteWorkFlowList = append(remoteWorkFlowList, remoteContent.Content...)
|
||||
}
|
||||
}
|
||||
@ -80,7 +81,9 @@ func getRemoteContent(URL string, remoteTemplateDomainList []string, remoteConte
|
||||
}
|
||||
return
|
||||
}
|
||||
defer response.Body.Close()
|
||||
defer func() {
|
||||
_ = response.Body.Close()
|
||||
}()
|
||||
if response.StatusCode < 200 || response.StatusCode > 299 {
|
||||
remoteContentChannel <- RemoteContent{
|
||||
Error: fmt.Errorf("get \"%s\": unexpect status %d", URL, response.StatusCode),
|
||||
|
||||
4
pkg/external/customtemplates/s3.go
vendored
4
pkg/external/customtemplates/s3.go
vendored
@ -96,7 +96,9 @@ func downloadToFile(downloader *manager.Downloader, targetDirectory, bucket, key
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fd.Close()
|
||||
defer func() {
|
||||
_ = fd.Close()
|
||||
}()
|
||||
|
||||
// Download the file using the AWS SDK for Go
|
||||
_, err = downloader.Download(context.TODO(), fd, &s3.GetObjectInput{Bucket: &bucket, Key: &key})
|
||||
|
||||
@ -123,7 +123,7 @@ func (a *Analyzer) Analyze(options *analyzers.Options) (bool, string, error) {
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "could not rebuild request")
|
||||
}
|
||||
gologger.Verbose().Msgf("[%s] Sending request with %d delay for: %s", a.Name(), delay, rebuilt.URL.String())
|
||||
gologger.Verbose().Msgf("[%s] Sending request with %d delay for: %s", a.Name(), delay, rebuilt.String())
|
||||
|
||||
timeTaken, err := doHTTPRequestWithTimeTracing(rebuilt, options.HttpClient)
|
||||
if err != nil {
|
||||
|
||||
@ -60,11 +60,7 @@ func checkTimingDependency(
|
||||
requestsLeft := requestsLimit
|
||||
|
||||
var requestsSent []requestsSentMetadata
|
||||
for {
|
||||
if requestsLeft <= 0 {
|
||||
break
|
||||
}
|
||||
|
||||
for requestsLeft > 0 {
|
||||
isCorrelationPossible, delayRecieved, err := sendRequestAndTestConfidence(regression, highSleepTimeSeconds, requestSender, baselineDelay)
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
|
||||
@ -36,7 +36,7 @@ func (q *Path) Parse(req *retryablehttp.Request) (bool, error) {
|
||||
q.req = req
|
||||
q.value = NewValue("")
|
||||
|
||||
splitted := strings.Split(req.URL.Path, "/")
|
||||
splitted := strings.Split(req.Path, "/")
|
||||
values := make(map[string]interface{})
|
||||
for i := range splitted {
|
||||
pathTillNow := strings.Join(splitted[:i+1], "/")
|
||||
@ -83,7 +83,7 @@ func (q *Path) Delete(key string) error {
|
||||
// component rebuilt
|
||||
func (q *Path) Rebuild() (*retryablehttp.Request, error) {
|
||||
originalValues := mapsutil.Map[string, any]{}
|
||||
splitted := strings.Split(q.req.URL.Path, "/")
|
||||
splitted := strings.Split(q.req.Path, "/")
|
||||
for i := range splitted {
|
||||
pathTillNow := strings.Join(splitted[:i+1], "/")
|
||||
if pathTillNow == "" {
|
||||
@ -92,7 +92,7 @@ func (q *Path) Rebuild() (*retryablehttp.Request, error) {
|
||||
originalValues[strconv.Itoa(i)] = pathTillNow
|
||||
}
|
||||
|
||||
originalPath := q.req.URL.Path
|
||||
originalPath := q.req.Path
|
||||
lengthSplitted := len(q.value.parsed.Map)
|
||||
for i := lengthSplitted; i > 0; i-- {
|
||||
key := strconv.Itoa(i)
|
||||
@ -120,7 +120,7 @@ func (q *Path) Rebuild() (*retryablehttp.Request, error) {
|
||||
// Clone the request and update the path
|
||||
cloned := q.req.Clone(context.Background())
|
||||
if err := cloned.UpdateRelPath(rebuiltPath, true); err != nil {
|
||||
cloned.URL.RawPath = rebuiltPath
|
||||
cloned.RawPath = rebuiltPath
|
||||
}
|
||||
return cloned, nil
|
||||
}
|
||||
|
||||
@ -40,8 +40,8 @@ func TestURLComponent(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Equal(t, "/newpath", rebuilt.URL.Path, "unexpected URL path")
|
||||
require.Equal(t, "https://example.com/newpath", rebuilt.URL.String(), "unexpected full URL")
|
||||
require.Equal(t, "/newpath", rebuilt.Path, "unexpected URL path")
|
||||
require.Equal(t, "https://example.com/newpath", rebuilt.String(), "unexpected full URL")
|
||||
}
|
||||
|
||||
func TestURLComponent_NestedPaths(t *testing.T) {
|
||||
@ -74,7 +74,7 @@ func TestURLComponent_NestedPaths(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if newReq.URL.Path != "/user/753'/profile" {
|
||||
if newReq.Path != "/user/753'/profile" {
|
||||
t.Fatal("expected path to be modified")
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ func (q *Query) Rebuild() (*retryablehttp.Request, error) {
|
||||
return nil, errors.Wrap(err, "could not encode query")
|
||||
}
|
||||
cloned := q.req.Clone(context.Background())
|
||||
cloned.URL.RawQuery = encoded
|
||||
cloned.RawQuery = encoded
|
||||
|
||||
// Clear the query parameters and re-add them
|
||||
cloned.Params = nil
|
||||
|
||||
@ -41,6 +41,6 @@ func TestQueryComponent(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
require.Equal(t, "foo=baz", rebuilt.URL.RawQuery, "unexpected query string")
|
||||
require.Equal(t, "https://example.com?foo=baz", rebuilt.URL.String(), "unexpected url")
|
||||
require.Equal(t, "foo=baz", rebuilt.RawQuery, "unexpected query string")
|
||||
require.Equal(t, "https://example.com?foo=baz", rebuilt.String(), "unexpected url")
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ func (m *MultiPartForm) Encode(data KV) (string, error) {
|
||||
return "", Itererr
|
||||
}
|
||||
|
||||
w.Close()
|
||||
_ = w.Close()
|
||||
return b.String(), nil
|
||||
}
|
||||
|
||||
@ -142,7 +142,9 @@ func (m *MultiPartForm) Decode(data string) (KV, error) {
|
||||
if err != nil {
|
||||
return KV{}, err
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
buffer := new(bytes.Buffer)
|
||||
if _, err := buffer.ReadFrom(file); err != nil {
|
||||
|
||||
@ -98,6 +98,7 @@ func (rule *Rule) Execute(input *ExecuteRuleInput) (err error) {
|
||||
// match rule part with component name
|
||||
displayDebugFuzzPoints := make(map[string]map[string]string)
|
||||
for _, componentName := range component.Components {
|
||||
//nolint
|
||||
if !(rule.Part == componentName || sliceutil.Contains(rule.Parts, componentName) || rule.partType == requestPartType) {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ func (rule *Rule) execWithInput(input *ExecuteRuleInput, httpReq *retryablehttp.
|
||||
if rule.options.FuzzParamsFrequency != nil {
|
||||
if rule.options.FuzzParamsFrequency.IsParameterFrequent(
|
||||
parameter,
|
||||
httpReq.URL.String(),
|
||||
httpReq.String(),
|
||||
rule.options.TemplateID,
|
||||
) {
|
||||
return nil
|
||||
|
||||
@ -96,9 +96,10 @@ func getCorrectSiteName(originalURL string) string {
|
||||
// Site is the host:port combo
|
||||
siteName := parsed.Host
|
||||
if parsed.Port() == "" {
|
||||
if parsed.Scheme == "https" {
|
||||
switch parsed.Scheme {
|
||||
case "https":
|
||||
siteName = fmt.Sprintf("%s:443", siteName)
|
||||
} else if parsed.Scheme == "http" {
|
||||
case "http":
|
||||
siteName = fmt.Sprintf("%s:80", siteName)
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,9 @@ func TestBurpParse(t *testing.T) {
|
||||
|
||||
file, err := os.Open(proxifyInputFile)
|
||||
require.Nilf(t, err, "error opening proxify input file: %v", err)
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
err = format.Parse(file, func(request *types.RequestResponse) bool {
|
||||
gotMethodsToURLs = append(gotMethodsToURLs, request.URL.String())
|
||||
|
||||
@ -88,7 +88,9 @@ func WriteOpenAPIVarDumpFile(vars *OpenAPIParamsCfgFile) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
_ = f.Close()
|
||||
}()
|
||||
bin, err := yaml.Marshal(vars)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -44,7 +44,9 @@ func TestJSONFormatterParse(t *testing.T) {
|
||||
|
||||
file, err := os.Open(proxifyInputFile)
|
||||
require.Nilf(t, err, "error opening proxify input file: %v", err)
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
var urls []string
|
||||
err = format.Parse(file, func(request *types.RequestResponse) bool {
|
||||
|
||||
@ -217,7 +217,7 @@ func generateRequestsFromOp(opts *generateReqOptions) error {
|
||||
return nil
|
||||
} else {
|
||||
// if it is in path then remove it from path
|
||||
opts.requestPath = strings.Replace(opts.requestPath, fmt.Sprintf("{%s}", value.Name), "", -1)
|
||||
opts.requestPath = strings.ReplaceAll(opts.requestPath, fmt.Sprintf("{%s}", value.Name), "")
|
||||
if !opts.opts.RequiredOnly {
|
||||
gologger.Verbose().Msgf("openapi: skipping optional param (%s) in (%v) in request [%s] %s due to missing value (%v)\n", value.Name, value.In, opts.method, opts.requestPath, value.Name)
|
||||
}
|
||||
@ -233,7 +233,7 @@ func generateRequestsFromOp(opts *generateReqOptions) error {
|
||||
return nil
|
||||
} else {
|
||||
// if it is in path then remove it from path
|
||||
opts.requestPath = strings.Replace(opts.requestPath, fmt.Sprintf("{%s}", value.Name), "", -1)
|
||||
opts.requestPath = strings.ReplaceAll(opts.requestPath, fmt.Sprintf("{%s}", value.Name), "")
|
||||
if !opts.opts.RequiredOnly {
|
||||
gologger.Verbose().Msgf("openapi: skipping optional param (%s) in (%v) in request [%s] %s due to missing value (%v)\n", value.Name, value.In, opts.method, opts.requestPath, value.Name)
|
||||
}
|
||||
@ -244,7 +244,7 @@ func generateRequestsFromOp(opts *generateReqOptions) error {
|
||||
}
|
||||
if opts.requiredOnly && !value.Required {
|
||||
// remove them from path if any
|
||||
opts.requestPath = strings.Replace(opts.requestPath, fmt.Sprintf("{%s}", value.Name), "", -1)
|
||||
opts.requestPath = strings.ReplaceAll(opts.requestPath, fmt.Sprintf("{%s}", value.Name), "")
|
||||
continue // Skip this parameter if it is not required and we want only required ones
|
||||
}
|
||||
|
||||
@ -319,7 +319,7 @@ func generateRequestsFromOp(opts *generateReqOptions) error {
|
||||
_ = multipartWriter.WriteField(k, types.ToString(v))
|
||||
}
|
||||
}
|
||||
multipartWriter.Close()
|
||||
_ = multipartWriter.Close()
|
||||
// body = buffer.String()
|
||||
cloned.Body = io.NopCloser(buffer)
|
||||
cloned.ContentLength = int64(len(buffer.Bytes()))
|
||||
|
||||
@ -44,7 +44,9 @@ func TestOpenAPIParser(t *testing.T) {
|
||||
|
||||
file, err := os.Open(proxifyInputFile)
|
||||
require.Nilf(t, err, "error opening proxify input file: %v", err)
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
err = format.Parse(file, func(rr *types.RequestResponse) bool {
|
||||
gotMethodsToURLs[rr.Request.Method] = append(gotMethodsToURLs[rr.Request.Method],
|
||||
|
||||
@ -17,7 +17,9 @@ func TestSwaggerAPIParser(t *testing.T) {
|
||||
|
||||
file, err := os.Open(proxifyInputFile)
|
||||
require.Nilf(t, err, "error opening proxify input file: %v", err)
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
err = format.Parse(file, func(request *types.RequestResponse) bool {
|
||||
gotMethodsToURLs = append(gotMethodsToURLs, request.URL.String())
|
||||
|
||||
@ -20,7 +20,9 @@ func TestYamlFormatterParse(t *testing.T) {
|
||||
|
||||
file, err := os.Open(proxifyInputFile)
|
||||
require.Nilf(t, err, "error opening proxify input file: %v", err)
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
var urls []string
|
||||
err = format.Parse(file, func(request *types.RequestResponse) bool {
|
||||
|
||||
@ -73,7 +73,7 @@ func NewHttpInputProvider(opts *HttpMultiFormatOptions) (*HttpInputProvider, err
|
||||
}
|
||||
defer func() {
|
||||
if inputFile != nil {
|
||||
inputFile.Close()
|
||||
_ = inputFile.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
@ -261,7 +261,7 @@ func (i *ListInputProvider) InputType() string {
|
||||
|
||||
// Close closes the input provider
|
||||
func (i *ListInputProvider) Close() {
|
||||
i.hostMap.Close()
|
||||
_ = i.hostMap.Close()
|
||||
if i.hostMapStream != nil {
|
||||
i.hostMapStream.Close()
|
||||
}
|
||||
@ -303,7 +303,7 @@ func (i *ListInputProvider) initializeInputSources(opts *Options) error {
|
||||
}
|
||||
if input != nil {
|
||||
i.scanInputFromReader(options.ExecutionId, input)
|
||||
input.Close()
|
||||
_ = input.Close()
|
||||
}
|
||||
}
|
||||
if options.Uncover && options.UncoverQuery != nil {
|
||||
|
||||
@ -13,7 +13,9 @@ func TestConvertInputToType(t *testing.T) {
|
||||
hm, err := hybrid.New(hybrid.DefaultDiskOptions)
|
||||
require.NoError(t, err, "could not create hybrid map")
|
||||
helper.InputsHTTP = hm
|
||||
defer hm.Close()
|
||||
defer func() {
|
||||
_ = hm.Close()
|
||||
}()
|
||||
|
||||
_ = hm.Set("google.com", []byte("https://google.com"))
|
||||
|
||||
|
||||
@ -18,10 +18,14 @@ func TestTemplateInstallation(t *testing.T) {
|
||||
tm := &TemplateManager{}
|
||||
dir, err := os.MkdirTemp("", "nuclei-templates-*")
|
||||
require.Nil(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
defer func() {
|
||||
_ = os.RemoveAll(dir)
|
||||
}()
|
||||
cfgdir, err := os.MkdirTemp("", "nuclei-config-*")
|
||||
require.Nil(t, err)
|
||||
defer os.RemoveAll(cfgdir)
|
||||
defer func() {
|
||||
_ = os.RemoveAll(cfgdir)
|
||||
}()
|
||||
|
||||
// set the config directory to a temporary directory
|
||||
config.DefaultConfig.SetConfigDir(cfgdir)
|
||||
|
||||
@ -92,7 +92,9 @@ func doVersionCheck(isSDK bool) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() {
|
||||
_ = resp.Body.Close()
|
||||
}()
|
||||
bin, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -47,7 +47,9 @@ func TestZipSlip(t *testing.T) {
|
||||
}
|
||||
|
||||
configuredTemplateDirectory := filepath.Join(os.TempDir(), "templates")
|
||||
defer os.RemoveAll(configuredTemplateDirectory)
|
||||
defer func() {
|
||||
_ = os.RemoveAll(configuredTemplateDirectory)
|
||||
}()
|
||||
|
||||
t.Run("negative scenarios", func(t *testing.T) {
|
||||
filePathsFromZip := []string{
|
||||
|
||||
@ -126,7 +126,6 @@ func (c *Compiler) ExecuteWithOptions(program *goja.Program, args *ExecuteArgs,
|
||||
results, err := contextutil.ExecFuncWithTwoReturns(ctx, func() (val goja.Value, err error) {
|
||||
// TODO(dwisiswant0): remove this once we get the RCA.
|
||||
defer func() {
|
||||
return
|
||||
if ci.IsCI() {
|
||||
return
|
||||
}
|
||||
|
||||
@ -89,7 +89,6 @@ func executeWithRuntime(runtime *goja.Runtime, p *goja.Program, args *ExecuteArg
|
||||
|
||||
// TODO(dwisiswant0): remove this once we get the RCA.
|
||||
defer func() {
|
||||
return
|
||||
if ci.IsCI() {
|
||||
return
|
||||
}
|
||||
|
||||
@ -36,10 +36,10 @@ func (d *TemplateData) WriteGoTemplate(outputDirectory string, pkgName string) e
|
||||
}
|
||||
|
||||
if err := tmpl.Execute(output, d); err != nil {
|
||||
output.Close()
|
||||
_ = output.Close()
|
||||
return errors.Wrap(err, "could not execute go class template")
|
||||
}
|
||||
output.Close()
|
||||
_ = output.Close()
|
||||
|
||||
cmd := exec.Command("gofmt", "-w", filename)
|
||||
cmd.Stderr = os.Stderr
|
||||
@ -68,10 +68,10 @@ func (d *TemplateData) WriteJSTemplate(outputDirectory string, pkgName string) e
|
||||
}
|
||||
|
||||
if err := tmpl.Execute(output, d); err != nil {
|
||||
output.Close()
|
||||
_ = output.Close()
|
||||
return errors.Wrap(err, "could not execute js class template")
|
||||
}
|
||||
output.Close()
|
||||
_ = output.Close()
|
||||
|
||||
cmd := exec.Command("js-beautify", "-r", filename)
|
||||
cmd.Stderr = os.Stderr
|
||||
@ -91,18 +91,20 @@ func (d *TemplateData) WriteMarkdownIndexTemplate(outputDirectory string) error
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not create markdown index template")
|
||||
}
|
||||
defer output.Close()
|
||||
defer func() {
|
||||
_ = output.Close()
|
||||
}()
|
||||
|
||||
buffer := &bytes.Buffer{}
|
||||
_, _ = buffer.WriteString("# Index\n\n")
|
||||
for _, v := range markdownIndexes {
|
||||
_, _ = buffer.WriteString(fmt.Sprintf("* %s\n", v))
|
||||
_, _ = fmt.Fprintf(buffer, "* %s\n", v)
|
||||
}
|
||||
_, _ = buffer.WriteString("\n\n")
|
||||
|
||||
_, _ = buffer.WriteString("# Scripts\n\n")
|
||||
for _, v := range d.NativeScripts {
|
||||
_, _ = buffer.WriteString(fmt.Sprintf("* `%s`\n", v))
|
||||
_, _ = fmt.Fprintf(buffer, "* `%s`\n", v)
|
||||
}
|
||||
if _, err := output.Write(buffer.Bytes()); err != nil {
|
||||
return errors.Wrap(err, "could not write markdown index template")
|
||||
@ -131,10 +133,10 @@ func (d *TemplateData) WriteMarkdownLibraryDocumentation(outputDirectory string,
|
||||
|
||||
markdownIndexes[pkgName] = fmt.Sprintf("[%s](%s.md)", pkgName, pkgName)
|
||||
if err := tmpl.Execute(output, d); err != nil {
|
||||
output.Close()
|
||||
_ = output.Close()
|
||||
return err
|
||||
}
|
||||
output.Close()
|
||||
_ = output.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -50,6 +50,7 @@ func (p *GojaModule) Name() string {
|
||||
}
|
||||
|
||||
// wrapModuleFunc wraps a Go function with context injection for modules
|
||||
// nolint
|
||||
func wrapModuleFunc(runtime *goja.Runtime, fn interface{}) interface{} {
|
||||
fnType := reflect.TypeOf(fn)
|
||||
if fnType.Kind() != reflect.Func {
|
||||
@ -87,6 +88,7 @@ func wrapModuleFunc(runtime *goja.Runtime, fn interface{}) interface{} {
|
||||
|
||||
// Add execution ID to context if available
|
||||
if execID := runtime.Get("executionId"); execID != nil {
|
||||
//nolint
|
||||
ctx = context.WithValue(ctx, "executionId", execID.String())
|
||||
}
|
||||
|
||||
|
||||
@ -26,6 +26,7 @@ func (f *FuncOpts) valid() bool {
|
||||
}
|
||||
|
||||
// wrapWithContext wraps a Go function with context injection
|
||||
// nolint
|
||||
func wrapWithContext(runtime *goja.Runtime, fn interface{}) interface{} {
|
||||
fnType := reflect.TypeOf(fn)
|
||||
if fnType.Kind() != reflect.Func {
|
||||
|
||||
@ -83,7 +83,9 @@ func sendToKDCTcp(kclient *Client, msg string) ([]byte, error) {
|
||||
errs = append(errs, fmt.Sprintf("error establishing connection to %s: %v", kdcs[i], err))
|
||||
continue
|
||||
}
|
||||
defer tcpConn.Close()
|
||||
defer func() {
|
||||
_ = tcpConn.Close()
|
||||
}()
|
||||
_ = tcpConn.SetDeadline(time.Now().Add(time.Duration(kclient.config.timeout) * time.Second)) //read and write deadline
|
||||
rb, err := sendTCP(tcpConn.(*net.TCPConn), []byte(msg))
|
||||
if err != nil {
|
||||
@ -119,7 +121,9 @@ func sendToKDCUdp(kclient *Client, msg string) ([]byte, error) {
|
||||
errs = append(errs, fmt.Sprintf("error establishing connection to %s: %v", kdcs[i], err))
|
||||
continue
|
||||
}
|
||||
defer udpConn.Close()
|
||||
defer func() {
|
||||
_ = udpConn.Close()
|
||||
}()
|
||||
_ = udpConn.SetDeadline(time.Now().Add(time.Duration(kclient.config.timeout) * time.Second)) //read and write deadline
|
||||
rb, err := sendUDP(udpConn.(*net.UDPConn), []byte(msg))
|
||||
if err != nil {
|
||||
@ -138,7 +142,9 @@ func sendToKDCUdp(kclient *Client, msg string) ([]byte, error) {
|
||||
// sendUDP sends bytes to connection over UDP.
|
||||
func sendUDP(conn *net.UDPConn, b []byte) ([]byte, error) {
|
||||
var r []byte
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
_, err := conn.Write(b)
|
||||
if err != nil {
|
||||
return r, fmt.Errorf("error sending to (%s): %v", conn.RemoteAddr().String(), err)
|
||||
@ -157,7 +163,9 @@ func sendUDP(conn *net.UDPConn, b []byte) ([]byte, error) {
|
||||
|
||||
// sendTCP sends bytes to connection over TCP.
|
||||
func sendTCP(conn *net.TCPConn, b []byte) ([]byte, error) {
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
var r []byte
|
||||
// RFC 4120 7.2.2 specifies the first 4 bytes indicate the length of the message in big endian order.
|
||||
hb := make([]byte, 4)
|
||||
|
||||
@ -363,5 +363,5 @@ func (c *Client) GetVersion() []string {
|
||||
// client.Close();
|
||||
// ```
|
||||
func (c *Client) Close() {
|
||||
c.conn.Close()
|
||||
_ = c.conn.Close()
|
||||
}
|
||||
|
||||
@ -78,7 +78,9 @@ func connect(executionId string, host string, port int, username string, passwor
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer db.Close()
|
||||
defer func() {
|
||||
_ = db.Close()
|
||||
}()
|
||||
|
||||
_, err = db.Exec("select 1")
|
||||
if err != nil {
|
||||
@ -124,7 +126,9 @@ func isMssql(executionId string, host string, port int) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
data, check, err := mssql.DetectMSSQL(conn, 5*time.Second)
|
||||
if check && err != nil {
|
||||
@ -177,7 +181,9 @@ func (c *MSSQLClient) ExecuteQuery(ctx context.Context, host string, port int, u
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer db.Close()
|
||||
defer func() {
|
||||
_ = db.Close()
|
||||
}()
|
||||
|
||||
db.SetMaxOpenConns(1)
|
||||
db.SetMaxIdleConns(0)
|
||||
|
||||
@ -52,7 +52,9 @@ func isMySQL(executionId string, host string, port int) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
plugin := &mysqlplugin.MYSQLPlugin{}
|
||||
service, err := plugin.Run(conn, 5*time.Second, plugins.Target{Host: host})
|
||||
@ -145,7 +147,9 @@ func fingerprintMySQL(executionId string, host string, port int) (MySQLInfo, err
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
plugin := &mysqlplugin.MYSQLPlugin{}
|
||||
service, err := plugin.Run(conn, 5*time.Second, plugins.Target{Host: host})
|
||||
@ -218,7 +222,9 @@ func (c *MySQLClient) ExecuteQueryWithOpts(ctx context.Context, opts MySQLOption
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer db.Close()
|
||||
defer func() {
|
||||
_ = db.Close()
|
||||
}()
|
||||
db.SetMaxOpenConns(1)
|
||||
db.SetMaxIdleConns(0)
|
||||
|
||||
|
||||
@ -77,7 +77,9 @@ func connectWithDSN(dsn string) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer db.Close()
|
||||
defer func() {
|
||||
_ = db.Close()
|
||||
}()
|
||||
db.SetMaxOpenConns(1)
|
||||
db.SetMaxIdleConns(0)
|
||||
|
||||
|
||||
@ -48,7 +48,9 @@ func isOracle(executionId string, host string, port int) (IsOracleResponse, erro
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
oracledbPlugin := oracledb.ORACLEPlugin{}
|
||||
service, err := oracledbPlugin.Run(conn, timeout, plugins.Target{Host: host})
|
||||
|
||||
@ -49,7 +49,9 @@ func isPoP3(executionId string, host string, port int) (IsPOP3Response, error) {
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
pop3Plugin := pop3.POP3Plugin{}
|
||||
service, err := pop3Plugin.Run(conn, timeout, plugins.Target{Host: host})
|
||||
|
||||
@ -13,7 +13,6 @@ import (
|
||||
postgres "github.com/praetorian-inc/fingerprintx/pkg/plugins/services/postgresql"
|
||||
utils "github.com/projectdiscovery/nuclei/v3/pkg/js/utils"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/js/utils/pgwrap"
|
||||
_ "github.com/projectdiscovery/nuclei/v3/pkg/js/utils/pgwrap"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
||||
)
|
||||
|
||||
@ -52,7 +51,9 @@ func isPostgres(executionId string, host string, port int) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
_ = conn.SetDeadline(time.Now().Add(timeout))
|
||||
|
||||
@ -127,7 +128,9 @@ func executeQuery(executionId string, host string, port int, username string, pa
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer db.Close()
|
||||
defer func() {
|
||||
_ = db.Close()
|
||||
}()
|
||||
|
||||
rows, err := db.Query(query)
|
||||
if err != nil {
|
||||
@ -192,7 +195,9 @@ func connect(executionId string, host string, port int, username string, passwor
|
||||
},
|
||||
IdleCheckFrequency: -1,
|
||||
}).WithContext(ctx).WithTimeout(10 * time.Second)
|
||||
defer db.Close()
|
||||
defer func() {
|
||||
_ = db.Close()
|
||||
}()
|
||||
|
||||
_, err := db.Exec("select 1")
|
||||
if err != nil {
|
||||
|
||||
@ -51,7 +51,9 @@ func isRDP(executionId string, host string, port int) (IsRDPResponse, error) {
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
server, isRDP, err := rdp.DetectRDP(conn, timeout)
|
||||
if err != nil {
|
||||
@ -105,7 +107,9 @@ func checkRDPAuth(executionId string, host string, port int) (CheckRDPAuthRespon
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
pluginInfo, auth, err := rdp.DetectRDPAuth(conn, timeout)
|
||||
if err != nil {
|
||||
|
||||
@ -35,7 +35,9 @@ func getServerInfo(executionId string, host string, port int) (string, error) {
|
||||
Password: "", // no password set
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
defer client.Close()
|
||||
defer func() {
|
||||
_ = client.Close()
|
||||
}()
|
||||
|
||||
// Ping the Redis server
|
||||
_, err := client.Ping(context.TODO()).Result()
|
||||
@ -75,7 +77,9 @@ func connect(executionId string, host string, port int, password string) (bool,
|
||||
Password: password, // no password set
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
defer client.Close()
|
||||
defer func() {
|
||||
_ = client.Close()
|
||||
}()
|
||||
|
||||
_, err := client.Ping(context.TODO()).Result()
|
||||
if err != nil {
|
||||
@ -113,7 +117,9 @@ func getServerInfoAuth(executionId string, host string, port int, password strin
|
||||
Password: password, // no password set
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
defer client.Close()
|
||||
defer func() {
|
||||
_ = client.Close()
|
||||
}()
|
||||
|
||||
// Ping the Redis server
|
||||
_, err := client.Ping(context.TODO()).Result()
|
||||
@ -150,7 +156,9 @@ func isAuthenticated(executionId string, host string, port int) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
_, err = plugin.Run(conn, timeout, plugins.Target{Host: host})
|
||||
if err != nil {
|
||||
@ -177,7 +185,9 @@ func RunLuaScript(ctx context.Context, host string, port int, password string, s
|
||||
Password: password,
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
defer client.Close()
|
||||
defer func() {
|
||||
_ = client.Close()
|
||||
}()
|
||||
|
||||
// Ping the Redis server
|
||||
_, err := client.Ping(context.TODO()).Result()
|
||||
|
||||
@ -48,7 +48,9 @@ func isRsync(executionId string, host string, port int) (IsRsyncResponse, error)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
rsyncPlugin := rsync.RSYNCPlugin{}
|
||||
service, err := rsyncPlugin.Run(conn, timeout, plugins.Target{Host: host})
|
||||
|
||||
@ -62,7 +62,9 @@ func connectSMBInfoMode(executionId string, host string, port int) (*smb.SMBLog,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
result, err = getSMBInfo(conn, true, true)
|
||||
if err != nil {
|
||||
return result, nil
|
||||
@ -121,7 +123,9 @@ func listShares(executionId string, host string, port int, user string, password
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
d := &smb2.Dialer{
|
||||
Initiator: &smb2.NTLMInitiator{
|
||||
|
||||
@ -25,7 +25,9 @@ func collectSMBv2Metadata(executionId string, host string, port int, timeout tim
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
metadata, err := smb.DetectSMBv2(conn, timeout)
|
||||
if err != nil {
|
||||
|
||||
@ -43,7 +43,9 @@ func detectSMBGhost(executionId string, host string, port int) (bool, error) {
|
||||
return false, err
|
||||
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
_, err = conn.Write([]byte(pkt))
|
||||
if err != nil {
|
||||
|
||||
@ -96,7 +96,9 @@ func (c *Client) IsSMTP() (SMTPResponse, error) {
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
smtpPlugin := pluginsmtp.SMTPPlugin{}
|
||||
service, err := smtpPlugin.Run(conn, timeout, plugins.Target{Host: c.host})
|
||||
@ -135,7 +137,9 @@ func (c *Client) IsOpenRelay(msg *SMTPMessage) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
client, err := smtp.NewClient(conn, c.host)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
||||
@ -135,7 +135,9 @@ func (c *SSHClient) Run(cmd string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer session.Close()
|
||||
defer func() {
|
||||
_ = session.Close()
|
||||
}()
|
||||
|
||||
data, err := session.Output(cmd)
|
||||
if err != nil {
|
||||
@ -211,7 +213,9 @@ func connectSSHInfoMode(opts *connectOptions) (*ssh.HandshakeLog, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer client.Close()
|
||||
defer func() {
|
||||
_ = client.Close()
|
||||
}()
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
@ -48,7 +48,9 @@ func isTelnet(executionId string, host string, port int) (IsTelnetResponse, erro
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
telnetPlugin := telnet.TELNETPlugin{}
|
||||
service, err := telnetPlugin.Run(conn, timeout, plugins.Target{Host: host})
|
||||
|
||||
@ -49,7 +49,9 @@ func isVNC(executionId string, host string, port int) (IsVNCResponse, error) {
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
vncPlugin := vnc.VNCPlugin{}
|
||||
service, err := vncPlugin.Run(conn, timeout, plugins.Target{Host: host})
|
||||
|
||||
@ -14,20 +14,24 @@ const (
|
||||
PGWrapDriver = "pgwrap"
|
||||
)
|
||||
|
||||
// nolint
|
||||
type pgDial struct {
|
||||
fd *fastdialer.Dialer
|
||||
}
|
||||
|
||||
// nolint
|
||||
func (p *pgDial) Dial(network, address string) (net.Conn, error) {
|
||||
return p.fd.Dial(context.TODO(), network, address)
|
||||
}
|
||||
|
||||
// nolint
|
||||
func (p *pgDial) DialTimeout(network, address string, timeout time.Duration) (net.Conn, error) {
|
||||
ctx, cancel := context.WithTimeoutCause(context.Background(), timeout, fastdialer.ErrDialTimeout)
|
||||
defer cancel()
|
||||
return p.fd.Dial(ctx, network, address)
|
||||
}
|
||||
|
||||
// nolint
|
||||
func (p *pgDial) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
return p.fd.Dial(ctx, network, address)
|
||||
}
|
||||
@ -44,6 +48,7 @@ type PgDriver struct{}
|
||||
// library.
|
||||
func (d PgDriver) Open(name string) (driver.Conn, error) {
|
||||
panic("todo")
|
||||
// nolint
|
||||
return nil, nil
|
||||
//return pq.DialOpen(&pgDial{fd: dialer.Fastdialer}, name)
|
||||
}
|
||||
|
||||
@ -21,7 +21,9 @@ type SQLResult struct {
|
||||
//
|
||||
// The function closes the sql.Rows when finished.
|
||||
func UnmarshalSQLRows(rows *sql.Rows) (*SQLResult, error) {
|
||||
defer rows.Close()
|
||||
defer func() {
|
||||
_ = rows.Close()
|
||||
}()
|
||||
columnTypes, err := rows.ColumnTypes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -243,7 +243,7 @@ func (operators *Operators) Execute(data map[string]interface{}, match MatchFunc
|
||||
}
|
||||
|
||||
// state variable to check if all extractors are internal
|
||||
var allInternalExtractors bool = true
|
||||
allInternalExtractors := true
|
||||
|
||||
// Start with the extractors first and evaluate them.
|
||||
for _, extractor := range operators.Extractors {
|
||||
|
||||
@ -229,7 +229,7 @@ type IssueTrackerMetadata struct {
|
||||
|
||||
// NewStandardWriter creates a new output writer based on user configurations
|
||||
func NewStandardWriter(options *types.Options) (*StandardWriter, error) {
|
||||
resumeBool := false
|
||||
var resumeBool bool
|
||||
if options.Resume != "" {
|
||||
resumeBool = true
|
||||
}
|
||||
@ -452,13 +452,13 @@ func (w *StandardWriter) Colorizer() aurora.Aurora {
|
||||
// Close closes the output writing interface
|
||||
func (w *StandardWriter) Close() {
|
||||
if w.outputFile != nil {
|
||||
w.outputFile.Close()
|
||||
_ = w.outputFile.Close()
|
||||
}
|
||||
if w.traceFile != nil {
|
||||
w.traceFile.Close()
|
||||
_ = w.traceFile.Close()
|
||||
}
|
||||
if w.errorFile != nil {
|
||||
w.errorFile.Close()
|
||||
_ = w.errorFile.Close()
|
||||
}
|
||||
}
|
||||
|
||||
@ -563,8 +563,8 @@ func (w *StandardWriter) WriteStoreDebugData(host, templateID, eventType string,
|
||||
fmt.Print(err)
|
||||
return
|
||||
}
|
||||
_, _ = f.WriteString(fmt.Sprintln(data))
|
||||
f.Close()
|
||||
_, _ = fmt.Fprintln(f, data)
|
||||
_ = f.Close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -148,7 +148,7 @@ func (p *StatsTicker) makePrintCallback() func(stats clistats.StatisticsClient)
|
||||
if startedAt, ok := stats.GetStatic("startedAt"); ok {
|
||||
if startedAtTime, ok := startedAt.(time.Time); ok {
|
||||
duration = time.Since(startedAtTime)
|
||||
builder.WriteString(fmt.Sprintf("[%s]", fmtDuration(duration)))
|
||||
_, _ = fmt.Fprintf(builder, "[%s]", fmtDuration(duration))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -84,5 +84,5 @@ func (pf *ProjectFile) Set(req []byte, resp *http.Response, data []byte) error {
|
||||
}
|
||||
|
||||
func (pf *ProjectFile) Close() {
|
||||
pf.hm.Close()
|
||||
_ = pf.hm.Close()
|
||||
}
|
||||
|
||||
@ -249,14 +249,14 @@ func (request *Request) ExecuteWithResults(input *contextargs.Context, dynamicVa
|
||||
gologger.Debug().MsgFunc(func() string {
|
||||
dashes := strings.Repeat("-", 15)
|
||||
sb := &strings.Builder{}
|
||||
sb.WriteString(fmt.Sprintf("[%s] Dumped Executed Source Code for input/stdin: '%v'", request.options.TemplateID, input.MetaInput.Input))
|
||||
sb.WriteString(fmt.Sprintf("\n%v\n%v\n%v\n", dashes, "Source Code:", dashes))
|
||||
_, _ = fmt.Fprintf(sb, "[%s] Dumped Executed Source Code for input/stdin: '%v'", request.options.TemplateID, input.MetaInput.Input)
|
||||
_, _ = fmt.Fprintf(sb, "\n%v\n%v\n%v\n", dashes, "Source Code:", dashes)
|
||||
sb.WriteString(interpretEnvVars(request.Source, allvars))
|
||||
sb.WriteString("\n")
|
||||
sb.WriteString(fmt.Sprintf("\n%v\n%v\n%v\n", dashes, "Command Executed:", dashes))
|
||||
_, _ = fmt.Fprintf(sb, "\n%v\n%v\n%v\n", dashes, "Command Executed:", dashes)
|
||||
sb.WriteString(interpretEnvVars(gOutput.Command, allvars))
|
||||
sb.WriteString("\n")
|
||||
sb.WriteString(fmt.Sprintf("\n%v\n%v\n%v\n", dashes, "Command Output:", dashes))
|
||||
_, _ = fmt.Fprintf(sb, "\n%v\n%v\n%v\n", dashes, "Command Output:", dashes)
|
||||
sb.WriteString(gOutput.DebugData.String())
|
||||
sb.WriteString("\n")
|
||||
sb.WriteString("[WRN] Command Output here is stdout+sterr, in response variables they are seperate (use -v -svd flags for more details)")
|
||||
|
||||
@ -77,7 +77,7 @@ func New(opts Options) (*Service, error) {
|
||||
mappingFile := filepath.Join(config.DefaultConfig.GetTemplateDir(), mappingFilename)
|
||||
if file, err := os.Open(mappingFile); err == nil {
|
||||
_ = yaml.NewDecoder(file).Decode(&mappingData)
|
||||
file.Close()
|
||||
_ = file.Close()
|
||||
}
|
||||
if opts.ExecuterOpts.Options.Verbose {
|
||||
gologger.Verbose().Msgf("Normalized mapping (%d): %v\n", len(mappingData), mappingData)
|
||||
@ -206,7 +206,9 @@ func (s *Service) getTagsUsingWappalyzer(input *contextargs.MetaInput) []string
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() {
|
||||
_ = resp.Body.Close()
|
||||
}()
|
||||
data, err := io.ReadAll(io.LimitReader(resp.Body, maxDefaultBody))
|
||||
if err != nil {
|
||||
return nil
|
||||
|
||||
@ -76,11 +76,8 @@ func FindExpressions(data, OpenMarker, CloseMarker string, base map[string]inter
|
||||
iterations int
|
||||
exps []string
|
||||
)
|
||||
for {
|
||||
// check if we reached the maximum number of iterations
|
||||
if iterations > maxIterations {
|
||||
break
|
||||
}
|
||||
for iterations < maxIterations {
|
||||
// attempt to find open markers
|
||||
iterations++
|
||||
// attempt to find open markers
|
||||
indexOpenMarker := strings.Index(data, OpenMarker)
|
||||
|
||||
@ -42,7 +42,9 @@ func (generator *PayloadGenerator) loadPayloads(payloads map[string]interface{},
|
||||
// loadPayloadsFromFile loads a file to a string slice
|
||||
func (generator *PayloadGenerator) loadPayloadsFromFile(file io.ReadCloser) ([]string, error) {
|
||||
var lines []string
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
|
||||
@ -85,7 +85,7 @@ func (c *Cache) Close() {
|
||||
// NormalizeCacheValue processes the input value and returns a normalized cache
|
||||
// value.
|
||||
func (c *Cache) NormalizeCacheValue(value string) string {
|
||||
var normalizedValue string = value
|
||||
normalizedValue := value
|
||||
|
||||
u, err := url.ParseRequestURI(value)
|
||||
if err != nil || u.Host == "" {
|
||||
|
||||
@ -183,9 +183,9 @@ func (c *Client) processInteractionForRequest(interaction *server.Interaction, d
|
||||
|
||||
if c.options.FuzzParamsFrequency != nil {
|
||||
if !matched {
|
||||
c.options.FuzzParamsFrequency.MarkParameter(data.Parameter, data.Request.URL.String(), data.Operators.TemplateID)
|
||||
c.options.FuzzParamsFrequency.MarkParameter(data.Parameter, data.Request.String(), data.Operators.TemplateID)
|
||||
} else {
|
||||
c.options.FuzzParamsFrequency.UnmarkParameter(data.Parameter, data.Request.URL.String(), data.Operators.TemplateID)
|
||||
c.options.FuzzParamsFrequency.UnmarkParameter(data.Parameter, data.Request.String(), data.Operators.TemplateID)
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,7 +257,7 @@ func (c *Client) Close() bool {
|
||||
}
|
||||
if c.interactsh != nil {
|
||||
_ = c.interactsh.StopPolling()
|
||||
c.interactsh.Close()
|
||||
_ = c.interactsh.Close()
|
||||
}
|
||||
|
||||
c.requests.Purge()
|
||||
|
||||
@ -182,7 +182,7 @@ func initDialers(options *types.Options) error {
|
||||
HTTPClientPool: mapsutil.NewSyncLockMap[string, *retryablehttp.Client](),
|
||||
}
|
||||
|
||||
dialers.Set(options.ExecutionId, dialersInstance)
|
||||
_ = dialers.Set(options.ExecutionId, dialersInstance)
|
||||
|
||||
// Set a custom dialer for the "nucleitcp" protocol. This is just plain TCP, but it's registered
|
||||
// with a different name so that we do not clobber the "tcp" dialer in the event that nuclei is
|
||||
|
||||
@ -35,6 +35,7 @@ func GetRandomIPWithCidr(cidrs ...string) (net.IP, error) {
|
||||
}
|
||||
|
||||
switch {
|
||||
//nolint
|
||||
case 255 == ipnet.Mask[len(ipnet.Mask)-1]:
|
||||
return baseIp, nil
|
||||
case iputil.IsIPv4(baseIp.String()):
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"github.com/cespare/xxhash"
|
||||
)
|
||||
|
||||
|
||||
// TmplClusterKey generates a unique key for the request
|
||||
// to be used in the clustering process.
|
||||
func (request *Request) TmplClusterKey() uint64 {
|
||||
@ -20,5 +19,6 @@ func (request *Request) TmplClusterKey() uint64 {
|
||||
|
||||
// IsClusterable returns true if the request is eligible to be clustered.
|
||||
func (request *Request) IsClusterable() bool {
|
||||
// nolint
|
||||
return !(len(request.Resolvers) > 0 || request.Trace || request.ID != "")
|
||||
}
|
||||
|
||||
@ -66,6 +66,7 @@ func (c *Configuration) Hash() string {
|
||||
|
||||
// Get creates or gets a client for the protocol based on custom configuration
|
||||
func Get(options *types.Options, configuration *Configuration) (*retryabledns.Client, error) {
|
||||
//nolint
|
||||
if !(configuration.Retries > 1) && len(configuration.Resolvers) == 0 {
|
||||
return normalClient, nil
|
||||
}
|
||||
|
||||
@ -150,9 +150,9 @@ func traceToString(traceData *retryabledns.TraceData, withSteps bool) string {
|
||||
if traceData != nil {
|
||||
for i, dnsRecord := range traceData.DNSData {
|
||||
if withSteps {
|
||||
buffer.WriteString(fmt.Sprintf("request %d to resolver %s:\n", i, strings.Join(dnsRecord.Resolver, ",")))
|
||||
_, _ = fmt.Fprintf(buffer, "request %d to resolver %s:\n", i, strings.Join(dnsRecord.Resolver, ","))
|
||||
}
|
||||
buffer.WriteString(dnsRecord.Raw)
|
||||
_, _ = fmt.Fprintf(buffer, "%s\n", dnsRecord.Raw)
|
||||
}
|
||||
}
|
||||
return buffer.String()
|
||||
|
||||
@ -100,7 +100,7 @@ func (request *Request) GetID() string {
|
||||
// Compile compiles the protocol request for further execution.
|
||||
func (request *Request) Compile(options *protocols.ExecutorOptions) error {
|
||||
// if there are no matchers/extractors, we trigger an error as no operation would be performed on the template
|
||||
if request.Operators.IsEmpty() {
|
||||
if request.IsEmpty() {
|
||||
return errors.New("empty operators")
|
||||
}
|
||||
compiled := &request.Operators
|
||||
|
||||
@ -208,7 +208,9 @@ func readChunk(fileName string) ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer r.Close()
|
||||
defer func() {
|
||||
_ = r.Close()
|
||||
}()
|
||||
|
||||
var buff [1024]byte
|
||||
if _, err = io.ReadFull(r, buff[:]); err != nil {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user