Project

General

Profile

Actions

Bug #9200

closed
JI PA

http: evasion when compression bomb cap returns success without a decompressor

Bug #9200: http: evasion when compression bomb cap returns success without a decompressor

Added by Jason Ish about 2 months ago. Updated 8 days ago.

Status:
Closed
Priority:
Normal
Target version:
Affected Versions:
Effort:
Difficulty:
Label:

Description

Summary

On a keep-alive HTTP/1 connection, response_prepend_decompressor returns Ok once the flow has already seen compression-bomb-count bombs. The fast path has already stored the single Content-Encoding in response_content_encoding_processing, and that field is not cleared. The next body then does response_decompressor.take() on an empty slot and returns HtpStatus::ERROR. HTPHandleResponseData turns HTP_STREAM_STATE_ERROR into a parser failure, and AppLayerParserParse calls StreamTcpDisableAppLayer for that TCP flow. One connection therefore shows both effects. The gzip body that arrives after the cap is never decompressed, so a file_data rule misses its plaintext, and a later uncompressed response on the same flow creates no HTTP transaction. request_prepend_decompressor has the same early return. Unpack suricata-http-bomb-limit-applayer-off.tar.gz and run ./verify.sh.

Affected Versions

Tested image jasonish/suricata:latest. suricata -V reports This is Suricata version 8.0.7 RELEASE. IDS mode, image default suricata.yaml. compression-bomb-count stays commented. The libhtp default and that comment are both 3. compression-bomb-limit stays at 1 MiB and the ratio stays at 2048. Response decompression is left enabled. A single gzip or deflate body cannot reach ratio 2048, so the counter is advanced with Content-Encoding: br bodies that do.

Preconditions

The sensor must be inspecting the TCP connection with default HTTP decompression. The attacker needs no account. They need one keep-alive connection whose first responses actually increment bombs (decompressed length above 1 MiB and ratio above 2048), then one more single-value compressed response, then another response on that same flow. A comma-separated Content-Encoding does not set response_content_encoding_processing before the early return, so that path does not produce this error. Three small gzip bodies do not increment bombs.

Security Impact

Proven on this build, one flow. Control uses 2 bombs, under the default cap. The following gzip plaintext matches file_data sid 1000001, and GET /c/after-plain still produces an HTTP event plus http.uri sid 1000002. Attack uses 3 bombs. EVE shows 3 COMPRESSION_BOMB anomalies and one COMPRESSION_BOMB_LIMIT_REACHED. The same gzip URL is logged as an HTTP transaction, but sid 1000001 does not fire. GET /a/after-plain produces neither an HTTP event nor sid 1000003. The server still answers both requests. The Suricata process stays up. Other flows are not shown to be affected. Bomb-limit log lines alone are not the result. The missing file_data hit and the missing follow-up transaction are.

Vulnerable Code

Fast path stores the encoding, then asks for a decompressor (rust/htp/src/response.rs):

resp.response_content_encoding_processing = resp.response_content_encoding;
// ...
self.response_prepend_decompressor(response_content_encoding_processing)?;

At the cap the helper returns success and leaves that field set:

if self.bombs >= compression_options.get_max_bombs() {
// skip decompression for this flow if too many bombs were seen
return Ok(());
}

The body path then treats a missing decompressor as fatal:

let mut decompressor = resp.response_decompressor.take().ok_or(HtpStatus::ERROR)?;

request_prepend_decompressor in rust/htp/src/request.rs returns Ok(()) on the same bombs >= max check and also leaves the processing encoding unchanged. The run below is the response side, which is what turns the next single-value body into HTP_STREAM_STATE_ERROR.

Call Chain

Response bytes -> HTPHandleResponseData (src/app-layer-htp.c:877, HTP_STREAM_STATE_ERROR sets ret = -1, returned at :945) -> response_initialize_decompressors (rust/htp/src/response.rs:1166 sets processing, :1176 calls prepend) -> response_prepend_decompressor (rust/htp/src/response.rs:1329 returns Ok) -> response_body_data (rust/htp/src/response.rs:1079 take() fails) -> response_data (rust/htp/src/response.rs:1609 sets HtpStreamState::ERROR) -> AppLayerParserParse (src/app-layer-parser.c:1652 goes to error) -> StreamTcpDisableAppLayer (src/app-layer-parser.c:1754).

Payload

Three responses, each Content-Encoding: br, body 38 bytes, decompressing to 1056768 zero bytes (ratio about 27810). Brotli bytes:

a3ffff837f02201e0b0472ef0ff4ff7ff04f00c4611180eefd41fc7fe09f0088c30200dd0b00

Then one Content-Encoding: gzip response whose plaintext is E2EGZIPMARKER followed by zeros to 64 KiB (115 bytes on the wire). Then one uncompressed GET /a/after-plain body E2EPLAINMARKER. Rules:

alert http any any -> any any (msg:"gzip plaintext reached file_data"; flow:to_client,established; file_data; content:"E2EGZIPMARKER"; sid:1000001; rev:1;)
alert http any any -> any any (msg:"control follow-up transaction"; flow:to_server,established; http.uri; content:"/c/after-plain"; sid:1000002; rev:1;)
alert http any any -> any any (msg:"attack follow-up transaction"; flow:to_server,established; http.uri; content:"/a/after-plain"; sid:1000003; rev:1;)

The control connection is the same sequence with two brotli bodies and the /c/ prefix.

Reproduction

Image jasonish/suricata:latest, IDS, af-packet on the docker bridge that carries the HTTP server. Host connects to the server container on TCP port 80. The same port is published at 127.0.0.1:18083. This run used http://172.33.97.20:80. Defaults only. No change to compression-bomb-count, and decompression stays on.

This one case covers both effects of the same failure. The compressed body after the cap does not reach detection, and the application layer is removed for the rest of that flow.

Attachment suricata-http-bomb-limit-applayer-off.tar.gz:

./verify.sh

show_results.sh on the passing run:

control_file_data_alerts=1
control_followup_alerts=1
control_followup_http=1
control_compression_bomb=2
control_bomb_limit_reached=0
attack_bomb_http=3
attack_gzip_http=1
attack_compression_bomb=3
attack_bomb_limit_reached=1
attack_file_data_alerts=0
attack_followup_alerts=0
attack_followup_http=0
VERDICT: PASS

Attachment verify-suricata-http-bomb-limit-applayer-off.tar.gz is a suricata-verify test directory (test.yaml, test.rules, README.md, writepcap.py, input.pcap). Unpack it under the suricata-verify tests/ tree and run run.py suricata-http-bomb-limit-applayer-off. Expected on this build: one file_data alert for /c/gzip-marker, one http.uri alert for /c/after-plain, no alert for /a/gzip-marker or /a/after-plain, an HTTP event for /c/after-plain, no HTTP event for /a/after-plain, five COMPRESSION_BOMB anomalies and one COMPRESSION_BOMB_LIMIT_REACHED.

Fix Recommendation

In response_prepend_decompressor, when bombs >= max_bombs, set response_content_encoding_processing to HtpContentEncoding::None before returning Ok. Do the same for request_content_encoding_processing in request_prepend_decompressor. The fast path assigns the compressed type before the call, so an early return that only skips creating the decompressor leaves response_body_data to take() an empty slot and fail the stream. Clearing the processing encoding makes that body take the identity branch. Skipping decompression then stays a per-body decision and does not call StreamTcpDisableAppLayer. response_body_data should also treat a missing decompressor as that skip, not as HtpStatus::ERROR, so a stale processing flag cannot kill the flow.


Files


Subtasks 1 (0 open — 1 closed)

Bug #9212: http: evasion when compression bomb cap returns success without a decompressor (8.0.x backport)ClosedPhilippe AntoineActions
Actions

Also available in: PDF Atom