Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions cmd/integration-test/matcher-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package main

import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
"sync/atomic"

"github.com/projectdiscovery/nuclei/v3/pkg/output"
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
Expand All @@ -16,6 +19,7 @@ var matcherStatusTestcases = []TestCaseInfo{
{Path: "protocols/javascript/net-https.yaml", TestCase: &javascriptNoAccess{}},
{Path: "protocols/websocket/basic.yaml", TestCase: &websocketNoAccess{}},
{Path: "protocols/dns/a.yaml", TestCase: &dnsNoAccess{}},
{Path: "protocols/http/matcher-status-multiple-failures.yaml", TestCase: &httpMultipleFailures{}},
}

type httpNoAccess struct{}
Expand Down Expand Up @@ -118,3 +122,28 @@ func (h *dnsNoAccess) Execute(filePath string) error {
}
return nil
}

type httpMultipleFailures struct{}

// Execute tests that multiple failed requests all generate events with -ms flag
func (h *httpMultipleFailures) Execute(filePath string) error {
var requestCount int64

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
atomic.AddInt64(&requestCount, 1)
fmt.Fprintln(w, "test response")
}))
defer ts.Close()

results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug, "-ms", "-j")
if err != nil {
return err
}

actualRequestCount := atomic.LoadInt64(&requestCount)
if len(results) != int(actualRequestCount) {
return fmt.Errorf("matcher-status regression: server received %d requests but only %d events were output", actualRequestCount, len(results))
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
id: matcher-status-multiple-failures

info:
name: Test Matcher Status Multiple Failures
author: pdteam
severity: info

http:
- method: GET
path:
- "{{BaseURL}}/"
- "{{BaseURL}}/test"
- "{{BaseURL}}/admin"

matchers:
- type: word
words:
- "THIS_STRING_WILL_NEVER_MATCH"
part: body
6 changes: 4 additions & 2 deletions pkg/tmplexec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ func (e *TemplateExecuter) Execute(ctx *scan.ScanContext) (bool, error) {
// non-`global-matchers` templates can enter the `writeFailureCallback`
// func to log failure output.
wr := writer.WriteResult(event, e.options.Output, e.options.Progress, e.options.IssuesClient)
if wr && !isGlobalMatchers {
matched.Store(true)
if wr {
if !isGlobalMatchers {
matched.Store(true)
}
Comment on lines -185 to +188
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren’t both of them (this & cc5c550) logically equivalent and producing the same result?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I misidentified the root cause.
I'll open a new PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries.

} else {
lastMatcherEvent = event
}
Expand Down
Loading