-
Notifications
You must be signed in to change notification settings - Fork 3.2k
How to Write Unique Matchers in Nuclei Templates
Effective matchers are crucial for accurate template execution and preventing false positives. This guide categorizes matchers into three types with real-world examples and best practices.
Before diving into matcher implementation, always start by thinking through these three key questions based on the type of template you're creating:
- For Detection Templates: What unique identifiers can confirm this is the right product/service?
- For CVE Templates: What product-specific strings ensure I'm testing the vulnerable application?
- For Misconfiguration Templates: What service-specific patterns confirm the target technology?
- For CVE Templates: What specific indicators prove this vulnerability exists and was exploited?
- For XSS/SQLi Templates: What payload responses confirm successful injection?
- For Misconfiguration Templates: What configuration patterns indicate the security issue?
- For All Templates: What HTTP status codes, headers, or timing patterns support my primary detection?
- For Web Templates: What content-types, response sizes, or cache headers add confidence?
- For Network Templates: What protocol responses or connection patterns validate the finding?
| Template Type | Primary Focus | Secondary Focus | Supporting Focus |
|---|---|---|---|
| Detection/Tech | Product/Service ID | Version/Features | Status Codes |
| CVE/Vulnerability | Product ID + Vuln Evidence | Exploit Results | Response Validation |
| Misconfiguration | Service ID + Config Issue | Error Messages | Protocol Responses |
| Credential/Auth | Product ID + Auth Bypass | Login Success | Session Evidence |
Remember: The order matters! Start with identification, add vulnerability-specific detection, then strengthen with supporting matchers.
Purpose: Ensure the template matches against the expected target product/technology/service, preventing false positives from unrelated applications or services.
Key Principle: Use unique strings, headers, or patterns that are specific to the target product, technology, or service.
# TeamSpeak 3 Server Detection
matchers:
- type: word
words:
- "TS3"
- "TeamSpeak 3 ServerQuery interface"
condition: and# Flexmls IDX Plugin Detection
matchers:
- type: regex
part: body
regex:
- '(?i)Stable.tag:\s?([\w.]+)'# CUPS Server Detection
matchers:
- type: word
part: header
words:
- "Server: CUPS"# SearXNG Search Engine Detection
matchers:
- type: word
part: body
words:
- "<title>SearXNG</title>"- Use unique product/service names, version strings, or branded elements
- Look for distinctive HTML comments, meta tags, or JavaScript variables
- Utilize specific HTTP headers (Server, X-Powered-By, etc.)
- Include version detection when possible for better accuracy
- Identify service-specific protocols, commands, or response patterns
- Avoid generic terms that could match multiple products/services
Purpose: Detect specific vulnerabilities or misconfigurations with high precision, ensuring the vulnerability actually exists.
Key Principle: Match on vulnerability-specific indicators, error messages, or exploit results.
# CVE-2022-0543 - Redis RCE
matchers:
- type: regex
regex:
- "root:.*:0:0:" # /etc/passwd content indicating successful command execution# SLiMS XSS Detection
matchers:
- type: word
words:
- '<script>alert(document.domain)</script>' # Injected payload
- 'SLiMS' # Product confirmation
- 'name="author' # Additional product marker
condition: and# ZenML Authentication Bypass (CVE-2024-25723)
matchers:
- type: dsl
dsl:
- "compare_versions(version, '< 0.46.7')"
- "!contains_any(version, '0.44.4', '0.43.1', '0.42.2')"
- "contains_all(body, 'deployment_type', 'database_type')"
condition: and# Brother Printer Status Redirect Detection
matchers:
- type: word
part: header
words:
- "/general/status.html" # Specific redirect pattern- Match on actual exploit results (command output, injected content)
- Use vulnerability-specific error messages or responses
- Implement version checks with precise version ranges
- Look for unique vulnerability indicators (specific paths, parameters)
- Combine multiple indicators to reduce false positives
Purpose: Provide additional validation to strengthen detection accuracy when primary matchers lack uniqueness.
Key Principle: Use common HTTP elements that support but don't define the detection.
# Successful Response Validation
matchers:
- type: status
status:
- 200# Redirect Detection Support
matchers:
- type: status
status:
- 301# HTML Content Validation
matchers:
- type: word
part: content_type
words:
- "text/html"# Cache Behavior Validation
matchers:
- type: word
part: header
words:
- "no-store"
- "no-cache"
condition: or# Time-based Detection Support
matchers:
- type: dsl
dsl:
- "duration >= 5"- Never use supporting matchers as the primary detection method
- Combine with product or vulnerability identification matchers
- Use
matchers-condition: andto ensure all conditions are met - Common supporting matchers include:
- HTTP status codes (200, 301, 302, 403, 404, 500)
- Content-Type headers
- Response size ranges
- Response timing patterns
- Generic cache control headers
matchers-condition: and
matchers:
- type: word
words:
- "Product-Specific-String" # Product identification
- type: word
words:
- "vulnerability-indicator" # Vulnerability identification
- type: status
status:
- 200 # Supporting matchermatchers-condition: or
matchers:
- type: word
words:
- "path1-specific-indicator"
- type: word
words:
- "path2-specific-indicator"# BAD: Too generic, matches many applications
matchers:
- type: word
words:
- "admin"
- "login"# BAD: Status codes alone are not unique
matchers:
- type: status
status:
- 200# BAD: "error" appears in many applications
matchers:
- type: word
words:
- "error"matchers-condition: and
matchers:
- type: word
words:
- "MySpecificProduct v" # Unique product identifier
- "vulnerability-specific" # Vulnerability indicator
condition: and
- type: status
status:
- 200 # Supporting validation- Start with Product/Service Identification: Always confirm you're testing the right product/service
- Add Vulnerability Specifics: Include unique vulnerability indicators
- Use Supporting Matchers: Add status codes, content-types for additional validation
- Test Thoroughly: Verify against both vulnerable and non-vulnerable instances
- Document Reasoning: Explain why each matcher was chosen
- Primary: Product/Technology/Service identification (most important)
- Secondary: Vulnerability-specific indicators
- Tertiary: Supporting matchers (status, content-type, etc.)
This hierarchy ensures templates are both accurate and maintainable.