# Matchers

Matchers decide whether a response shows what the signature looks for.
Each matcher tests one part of the response in one way; the block's
`matchers-condition` combines them. A response that passes is a match:
it is recorded as evidence and its extractors run.

## Matcher fields

```yaml
matchers:
  - type: word
    part: body
    condition: and
    case-insensitive: true
    words:
      - "stack trace"
      - "exception"
```

| Field | Default | Meaning |
|---|---|---|
| `type` | `word` | `word`, `regex`, `status`, `size`, `binary` or `dsl` |
| `part` | `body` | The part of the response to test, see below |
| `condition` | `or` | For several values in one matcher: `or` passes when any matches, `and` when all do |
| `negative` | `false` | Invert the result |
| `internal` | `false` | Evaluate the matcher but leave it out of the result |
| `name` | | Optional label |

## Parts

| Part | Content |
|---|---|
| `body` | Response body as text, decoded with the response's character set |
| `header` | Response headers, one `name: value` line each |
| `all` | Headers, an empty line, then the body |
| `raw` | The body decoded as UTF-8, ignoring invalid bytes |
| `response` | Same as `body` |
| `request` | Not populated by the scan client today; always empty |

Header names in the `header` and `all` parts are lowercase, and repeated
headers are joined into one line with `, `. Use lowercase names or
`case-insensitive: true` when matching on headers. Bodies are read up to
5 MiB; longer bodies are cut.

`interactsh_protocol` passes validation but is not supported by the
engine; a matcher on it never matches (or always matches when negative).

## Word

Plain substring search.

```yaml
- type: word
  words:
    - "root:x:0:0"
    - "daemon:x:1:1"
  condition: and
```

`case-insensitive: true` lowers both sides before comparing.

## Regex

Python regular expressions, searched with multiline and dot-all flags, so
`^` and `$` match at line breaks and `.` also matches newlines. Prefer
lazy quantifiers such as `.*?` for that reason. A pattern that does not
compile counts as no match rather than an error.

```yaml
- type: regex
  regex:
    - "SQL syntax.*?MySQL"
    - "\\bORA-\\d{5}"
```

In double-quoted YAML strings, backslashes must be doubled. Single-quoted
or block strings keep them as written.

## Status

Passes when the status code is in the list. `part` does not apply.

```yaml
- type: status
  status:
    - 200
    - 302
```

A request that failed (connection refused, timeout, TLS failure) has the
status `0`.

## Size

Passes when the length of the chosen part, in characters, is exactly one
of the listed values. It is an equality test, not a range; use a DSL
matcher on `content_length` for comparisons.

```yaml
- type: size
  size:
    - 0
```

## Binary

Passes when any of the hexadecimal byte sequences occurs in the chosen
part. Spaces in the pattern are ignored. `condition` does not apply: one
sequence is enough.

```yaml
- type: binary
  binary:
    - "504B0304"
```

The part is text decoded from the response and converted back to bytes
as Latin-1. Byte sequences are reliable only for responses whose text
round-trips through that encoding; a response with characters outside
Latin-1 makes the signature fail with an error in the scan log.

## DSL

Expressions evaluated against the response. See
[Variables and DSL](./variables.md#conditions) for what an expression may
contain.

```yaml
- type: dsl
  dsl:
    - "status_code == 200"
    - "content_length > 1000"
  condition: and
```

An expression that cannot be evaluated counts as false.

## Combining matchers

`matchers-condition` on the block (or at the top level) combines the
matchers: `or` (the default) passes when any matcher passes, `and` when
all do.

```yaml
matchers-condition: and
matchers:
  - type: status
    status:
      - 200

  - type: word
    words:
      - "phpinfo()"
```

## Negative matchers

`negative: true` inverts a matcher. Combined with `and`, it rules out
responses that would otherwise match, such as a block page or a login form
that repeats the payload.

```yaml
matchers-condition: and
matchers:
  - type: regex
    regex:
      - "Warning.*?\\Wmysqli?_"

  - type: word
    negative: true
    words:
      - "Request Blocked"
```

## Internal matchers

An `internal: true` matcher is evaluated but does not count toward the
result. A block whose matchers are all internal never matches.

## Writing reliable matchers

- Match something only the vulnerable behaviour produces, not words that
  appear on ordinary pages.
- Pair a broad matcher (status, a word) with a specific one under `and`.
- Use negative matchers for known false positives.
- Reflected payloads match their own request; look for the effect of the
  payload, not the payload text alone.
