mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-29 22:23:02 +00:00
* multi proto request genesis * adds template context dynamic vars * feat: proto level resp variables * remove proto prefix hacky logic * implement template ctx args * remove old var name logic * improve AddTemplateVars func * add multi proto comments+docs * vardump with sorted keys * fix race condition in ctx args * default initialize ctx args * use generic map * index variables with multiple values * fix nil cookies * use synclock map * fix build failure * fix lint error * resolve merge conflicts * multi proto: add unit+ integration tests * fix unit tests * Issue 3339 headless fuzz (#3790) * Basic headless fuzzing * Remove debug statements * Add integration tests * Update template * Fix recognize payload value in matcher * Update tempalte * use req.SetURL() --------- Co-authored-by: Tarun Koyalwar <tarun@projectdiscovery.io> * Auto Generate Syntax Docs + JSONSchema [Fri Jun 9 00:23:32 UTC 2023] 🤖 * Add headless header and status matchers (#3794) * add headless header and status matchers * rename headers as header * add integration test for header+status * fix typo --------- Co-authored-by: Shubham Rasal <shubham@projectdiscovery.io> Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Dogan Can Bakir <65292895+dogancanbakir@users.noreply.github.com>
92 lines
2.5 KiB
Go
92 lines
2.5 KiB
Go
package matchers
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/Knetic/govaluate"
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/operators/common/dsl"
|
|
)
|
|
|
|
// CompileMatchers performs the initial setup operation on a matcher
|
|
func (matcher *Matcher) CompileMatchers() error {
|
|
var ok bool
|
|
|
|
// Support hexadecimal encoding for matchers too.
|
|
if matcher.Encoding == "hex" {
|
|
for i, word := range matcher.Words {
|
|
if decoded, err := hex.DecodeString(word); err == nil && len(decoded) > 0 {
|
|
matcher.Words[i] = string(decoded)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Set up the matcher type
|
|
computedType, err := toMatcherTypes(matcher.GetType().String())
|
|
if err != nil {
|
|
return fmt.Errorf("unknown matcher type specified: %s", matcher.Type)
|
|
}
|
|
|
|
matcher.matcherType = computedType
|
|
|
|
// Validate the matcher structure
|
|
if err := matcher.Validate(); err != nil {
|
|
return err
|
|
}
|
|
|
|
// By default, match on body if user hasn't provided any specific items
|
|
if matcher.Part == "" && matcher.GetType() != DSLMatcher {
|
|
matcher.Part = "body"
|
|
}
|
|
|
|
// Compile the regexes
|
|
for _, regex := range matcher.Regex {
|
|
compiled, err := regexp.Compile(regex)
|
|
if err != nil {
|
|
return fmt.Errorf("could not compile regex: %s", regex)
|
|
}
|
|
matcher.regexCompiled = append(matcher.regexCompiled, compiled)
|
|
}
|
|
|
|
// Compile and validate binary Values in matcher
|
|
for _, value := range matcher.Binary {
|
|
if decoded, err := hex.DecodeString(value); err != nil {
|
|
return fmt.Errorf("could not hex decode binary: %s", value)
|
|
} else {
|
|
matcher.binaryDecoded = append(matcher.binaryDecoded, string(decoded))
|
|
}
|
|
}
|
|
|
|
// Compile the dsl expressions
|
|
for _, dslExpression := range matcher.DSL {
|
|
compiledExpression, err := govaluate.NewEvaluableExpressionWithFunctions(dslExpression, dsl.HelperFunctions)
|
|
if err != nil {
|
|
return &dsl.CompilationError{DslSignature: dslExpression, WrappedError: err}
|
|
}
|
|
matcher.dslCompiled = append(matcher.dslCompiled, compiledExpression)
|
|
}
|
|
|
|
// Set up the condition type, if any.
|
|
if matcher.Condition != "" {
|
|
matcher.condition, ok = ConditionTypes[matcher.Condition]
|
|
if !ok {
|
|
return fmt.Errorf("unknown condition specified: %s", matcher.Condition)
|
|
}
|
|
} else {
|
|
matcher.condition = ORCondition
|
|
}
|
|
|
|
if matcher.CaseInsensitive {
|
|
if matcher.GetType() != WordsMatcher {
|
|
return fmt.Errorf("case-insensitive flag is supported only for 'word' matchers (not '%s')", matcher.Type)
|
|
}
|
|
for i := range matcher.Words {
|
|
matcher.Words[i] = strings.ToLower(matcher.Words[i])
|
|
}
|
|
}
|
|
return nil
|
|
}
|