If debug is enabled, show matchers that are not named also #1084

This commit is contained in:
forgedhallpass 2021-10-05 22:02:09 +03:00
parent 404f8ebb27
commit ed3b80b5d7

View File

@ -1,6 +1,8 @@
package operators package operators
import ( import (
"strconv"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors" "github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
@ -136,14 +138,10 @@ func (operators *Operators) Execute(data map[string]interface{}, match MatchFunc
} }
} }
for _, matcher := range operators.Matchers { for matcherIndex, matcher := range operators.Matchers {
// Check if the matcher matched
if isMatch, matched := match(data, matcher); isMatch { if isMatch, matched := match(data, matcher); isMatch {
// If the matcher has matched, and it's an OR matcherName := getMatcherName(matcher, matcherIndex)
// write the first output then move to next matcher. result.Matches[matcherName] = matched
if matcherCondition == matchers.ORCondition && matcher.Name != "" {
result.Matches[matcher.Name] = matched
}
matches = true matches = true
} else if matcherCondition == matchers.ANDCondition { } else if matcherCondition == matchers.ANDCondition {
@ -172,6 +170,14 @@ func (operators *Operators) Execute(data map[string]interface{}, match MatchFunc
return nil, false return nil, false
} }
func getMatcherName(matcher *matchers.Matcher, matcherIndex int) string {
if matcher.Name != "" {
return matcher.Name
} else {
return matcher.Type + "-" + strconv.Itoa(matcherIndex)
}
}
// ExecuteInternalExtractors executes internal dynamic extractors // ExecuteInternalExtractors executes internal dynamic extractors
func (operators *Operators) ExecuteInternalExtractors(data map[string]interface{}, extract ExtractFunc) map[string]interface{} { func (operators *Operators) ExecuteInternalExtractors(data map[string]interface{}, extract ExtractFunc) map[string]interface{} {
dynamicValues := make(map[string]interface{}) dynamicValues := make(map[string]interface{})