
PoC and verification material for CVE-2026-42945 (CWE-122 heap overflow in ngx_http_rewrite_module -> attacker-shaped cleanup hijack -> system() RCE in the ASLR-off worker; patched-twin negative + 5/5 reliability captured in the shipped lab)
Proof-of-concept and verification material for CVE-2026-42945 ("NGINX
Rift" -- the community name from the DepthFirst disclosure): an
unauthenticated heap buffer overflow (CWE-122) in nginx's
ngx_http_rewrite_module, demonstrated in the lab through to system()
command execution inside a worker.
The advisory facts, quoted:
CVSS 8.1 --
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:Hand the vendor's secondary CVSS 4.0 vectorCVSS:4.0/AV:N/AC:H/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/ SC:N/SI:N/SA:N(base 9.2 CRITICAL, source: F5 SIRT via NVD metrics). CWE-122. "NGINX Plus and NGINX Open Source have a vulnerability in the ngx_http_rewrite_module module. This vulnerability exists when the rewrite directive is followed by a rewrite, if, or set directive and an unnamed Perl-Compatible Regular Expression (PCRE) capture (for example, $1, $2) with a replacement string that includes a question mark (?). An unauthenticated attacker ... may cause a heap buffer overflow in the NGINX worker process leading to a restart. Additionally, attackers can execute code on systems with ASLR disabled or when the attacker can bypass ASLR." (F5 security advisory K000161019; GHSA-gcgv-v5gf-c543)
ngx_http_script_start_args_code() sets the script engine's is_args flag
when a rewrite replacement contains ?, and nothing ever clears it. A later
set $var $unnamed-capture then sizes the destination with a freshly
zeroed sub-engine (raw capture length) but copies on the polluted main
engine, where every escapable byte expands 3x under ngx_escape_uri's
ARGS table (+ -> %2B). The write runs past the allocation by exactly
2 bytes per escapable byte, and the padding is attacker-chosen: a
contiguous, attacker-shaped pool overflow.
Pinned-source verification: the args[] escape bitmap used internally was
checked byte-identical against the pinned nginx src/core/ngx_string.c, and
the one-line upstream fix (ngx_http_script_regex_end_code() gains
e->is_args = 0; -- commit 2046b45a mainline / 524977e7c in 1.30.1)
matches the behavior A/B below.
POST /spray, client_body_in_single_buffer on): wave 1 =
filler bodies preconditioning the pool map; wave 2 = 20 x 4000-byte
bodies starting with a fake ngx_pool_cleanup_s
(handler = &system@libc, data = cmd slot, next = 0) followed by the
command string. POST bodies are the only arbitrary-binary (NULs allowed)
vector; header-borne bytes get escaped.GET /api/ + Ax349 + +x969 + a 6-byte target; the ? in the rewrite
arms is_args; the set $var $1 copy runs the %2B-paint past A's block
into V_pool.cleanup (+0x40), landing the 6-byte fake-struct address.ngx_destroy_pool() walks the (now
attacker-controlled) cleanup chain FIRST -> c->handler(c->data) ->
system("command") in the worker.Success is always asserted by artifact readback (a nonce-keyed marker
file containing RIFT-<nonce>-B3G1N plus a uid= line, read back inside
the container) -- never by the attacker-side "connection crashed"
inference. That difference is load-bearing here: the published reference
PoC's "crashed => executed" heuristic fired with NO execution on this
lab rebuild (no marker, no child process), and this repo's drivers and
harnesses therefore never use it.
Every transcript marked captured was re-captured from a fresh checkout of
THIS tree (its own poc/ drivers and poc/ harnesses against lab/), so
the files and word forms below are the shipped ones.
| Claim | Tier | Evidence transcript |
|---|---|---|
Positive RCE, opt driver (marker + uid=0(root) readback) | captured | evidence/01-positive-opt-rce.txt |
| Positive RCE, readable driver | captured | evidence/02-positive-readable-rce.txt |
| Patched release-1.30.1 twin: sweep exhausts, exit 1, no marker, no artifact | captured | evidence/03-negative-patched-twin.txt |
| Master+worker (nobody) twin build: not captured | documented, not reproduced here -- this rebuild's deterministic fake-struct family contains no URI-safe landing window (measured, see below); its non-fire receipt is evidence/04-open-twin-master-on.txt | evidence/04-open-twin-master-on.txt |
| Reliability, opt driver: 5/5 fresh-instance legs, marker + uid=0 each | captured | evidence/05-reliability-opt-5of5.txt |
| Reliability, readable driver: 5/5 fresh-instance legs | captured | evidence/06-reliability-readable-5of5.txt |
| 4-leg verification matrix: vuln CAPTURED / patched CLEAN / unaffected SKIPPED with reason / master-ON twin documented open leg | captured | evidence/07-matrix-4legs.txt |
The captured transcripts carry raw output only -- the recording wrapper is
an internal harness, so these are the verbatim driver/harness stdout plus a
one-line [b63] marker readback receipt from docker exec where the tier
asserts the artifact. The clone used for re-capture is a neutral scratch
checkout; output bodies are byte-untouched.
setarch -R (ADDR_NO_RANDOMIZE inherited), giving a
per-BUILD deterministic layout. The positive legs live entirely in that
scope. ASLR-on is NOT claimed: with ASLR on, the same corruption yields
worker crash-loop behavior (the advisory's "leading to a restart"), not
demonstrated RCE here.SYSTEM_ADDR and the landing-table are
deterministic for THIS build+config and must be re-derived for any other
build (the derivation kit ships: see below). A rebuild shifts the
family; a marker-scan routine is provided rather than pretending the
constants travel.--tries 5 vs 15/15 at --tries 1
(internal session measurement; the shipped transcripts below are all
--tries 1 per fresh instance -- the shipped capture backs the
configured shape, not that internal count pair).poc/exploit_opt.c tunable candidate sweep (one aligned shot)
poc/exploit_readable.c heavily commented walkthrough build
poc/reliability.sh 5 fresh-instance legs per run, per-run verdict
poc/matrix.sh 4-leg verification matrix
lab/ Dockerfile + compose + nginx config + backend,
plus the per-build constant derivation kit
evidence/ the tier-table transcripts
Build (C99, no external dependencies):