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
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.
LS Updated by Lukas Sismis about 2 months ago
The report says it has been fixed in main but wanted to share this here in case somebody relevant, e.g., @Philippe Antoine could confirm/invalidate this.
PA Updated by Philippe Antoine about 2 months ago
- Status changed from New to Feedback
Where can I find the provided SV tests ?
LS Updated by Lukas Sismis about 2 months ago
Just clarifying, Philippe received the tests (mr 241)
PA Updated by Philippe Antoine about 2 months ago
- Assignee set to Philippe Antoine
PA Updated by Philippe Antoine about 2 months ago
- Status changed from Feedback to Triaged
- Assignee changed from Philippe Antoine to OISF Dev
- Target version changed from TBD to 8.0.8
Confirmed this is a real bug only affecting main-8 after #8386 has been merged in main
PA Updated by Philippe Antoine about 2 months ago
Not sure we want to treat this as a security issue because of detection evasion of dns keywords with this evil pattern of DOH2 traffic
Or just a bug
PA Updated by Philippe Antoine about 2 months ago
- Severity set to LOW
Setting LOW severity until we decide if it is just a bug
PA Updated by Philippe Antoine about 2 months ago
- Status changed from Triaged to In Review
- Assignee changed from OISF Dev to Philippe Antoine
gitlab MR
JI Updated by Jason Ish about 1 month ago
Fix our previous pattern as a low-security visibility bypass issue.
JI Updated by Jason Ish about 1 month ago
- Related to Security #9182: doh2: DNS inspection progress type confusion remains on 8.0.x added
JI Updated by Jason Ish about 1 month ago
- GHSA set to GHSA-qcfp-c5xm-562j
SB Updated by Shivani Bhardwaj 29 days ago
- Subject changed from detect: DOH2 detect_progress DNS evasion to doh2: evasion if DNS query is sent in DATA frame without END_STREAM
VJ Updated by Victor Julien 21 days ago
- Status changed from In Review to Resolved
PA Updated by Philippe Antoine 20 days ago
- Status changed from Resolved to Closed
Actions