Project

General

Profile

Actions

Security #9117

closed
LS PA

doh2: evasion if DNS query is sent in DATA frame without END_STREAM

Security #9117: doh2: evasion if DNS query is sent in DATA frame without END_STREAM

Added by Lukas Sismis about 2 months ago. Updated 3 days ago.

Status:
Closed
Priority:
Normal
Target version:
Affected Versions:
Label:
CVE:
Git IDs:

4978393899c54936e4cadae08be5c016b8e395cc

Severity:
LOW
Disclosure Date:

Description

# D7 — DOH2 detect_progress DNS evasion

> **Re-validated on 8.0.7 RELEASE (`d681600f3`, branch `release-8.0.7-260913122826`): still
> REPRODUCED — this repo's history briefly marked it "FIXED-UPSTREAM" after testing the wrong
> Suricata version (9.0.0-dev main, where the full DOH2 inspection rework `5735b87c3` lives). That
> commit is NOT an ancestor of this branch's HEAD. This branch does carry a related but incomplete
> partial fix, `b80d5f751` "detect/doh2: prefilter does not use dns engine progress" (Ticket 8454,
> cherry-picked from `898446aee8`) — it added the `tx->tx_ptr == tx_ptr` guard only to the *update*
> site (`src/detect-engine-prefilter.c` line ~156-163, described below), but the *skip* check at
> line ~135 still has no such guard, so the exact evasion this file describes still works. Re-running
> `reproducer.sh` against the fresh normal build confirms: `control: dns sid=1000001 alerts: 1 ...`
> vs `bug: dns sid=1000001 alerts: 0 ...` — `PASS: DNS rule evaded on bug pcap`. This should be
> flagged for backport of the full rework, or a targeted fix to the skip-check site.**

## Finding

- **Files / lines**:
  - `src/detect-engine-prefilter.c:156-163, Suricata 8.0.7` -- guarded by
    `tx->tx_ptr == tx_ptr && engine->is_last_for_progress`, and the comment
    explicitly says *"tx->tx_ptr == tx_ptr ensures we do not use a dns engine
    progress to update a HTTP2 tx detect_progress in case of DOH2"* — i.e. the
    guard protects the *update* direction but the *skip* at line 135 applies to
    all engines including the DNS engines of a DOH2 flow.
- **Bug class**: detection evasion (missing inspection), state-tracking logic bug.

## Mechanism

For a DOH2 flow, the "tx" Suricata iterates is the **HTTP2 transaction**; the
DNS message is an inner transaction (`SCDoH2GetDnsTx`, `rust/src/http2/http2.rs:1419`)
that only materialises when the HTTP/2 DATA frames are complete
(`handle_dns_data` is called on EOS, `http2.rs:475`).

`DetectRunPrefilterTx` keeps one shared `tx->detect_progress` per direction on
the outer HTTP2 tx. The engines are sorted by `tx_min_progress`, and the last
engine for a progress level sets `tx->detect_progress = min_progress + 1` — but
only if `tx->tx_ptr == tx_ptr` (outer pointer), so only *HTTP2* engines update
the HTTP2 tx's `detect_progress`.

Timeline for `DATA(DNS query)` **without** END_STREAM followed by an empty
`DATA` **with** END_STREAM:

1. The first DATA frame advances the HTTP2 tx state to `HTTP2StateDataClient`
   (`=3`, `http2.rs:463`). The inner DNS tx does not exist yet, so the DNS
   engine's `DetectGetInnerTx` returns NULL and the DNS engine is skipped with
   `tx->detect_progress` untouched. Meanwhile, the HTTP2 engines (registered
   with `tx_min_progress` 1..3, e.g. `http.method` at `HTTP2StateOpen=1`,
   `src/detect-http-method.c:112`) run, and on the pass where the state has
   moved past 1, the *last HTTP2 engine for progress 1* (which is
   `is_last_for_progress` for the HTTP2 alproto run) sets
   `tx->detect_progress = 2`.
2. At EOS, the DNS message is parsed into `doh.dns_request_tx`, and the flow is
   force-switched to `ALPROTO_DOH2` (`http2.rs:483-493`).
3. On the next detection pass over the same tx, the DNS engines
   (`dns.query` etc., `tx_min_progress = 1`, registered for DOH2 via
   `RegisterInternal()`'s re-registration at `src/detect-engine-mpm.c:110-113`)
   hit the skip at line 135: `tx->detect_progress (2) > 1` → `goto next`. The
   DNS prefilter never runs, the rule never becomes a candidate, and it is
   never inspected.

Result: a DNS rule (`dns.query; content:"evil.com"`) that fires when the DOH2
DATA frame carries END_STREAM (single-frame control) is silently evaded when
the DNS query is sent in a DATA frame *without* END_STREAM and the stream is
closed by a later frame.

Provided SV tests cover both control (passing) variant and the evaded variant.


Related issues 1 (0 open — 1 closed)

Related to Suricata - Security #9182: doh2: DNS inspection progress type confusion remains on 8.0.xClosedPhilippe AntoineActions
Actions

Also available in: PDF Atom