Exploit for Node.js Inspector enabling code execution via the Chrome DevTools Protocol
When Node.js is launched with debugging flags like --inspect or --inspect-brk, it opens a TCP service on port 9229. This service uses the Chrome DevTools Protocol (CDP) to allow developers to attach debuggers, inspect variable states, and dynamically execute JavaScript inside the running process.
Because the V8 Inspector does not implement authentication by default, any client that can establish a WebSocket connection to the inspector endpoint achieves full arbitrary code execution within the security context of the Node.js process.
This Proof of Concept works in three main stages:
-
HTTP Upgrade Handshake: The script creates a raw TCP socket connection to
127.0.0.1:9229and sends an HTTP request containing standardUpgrade: websocketheaders to establish a WebSocket session with the V8 Inspector endpoint UUID (). -
Chrome DevTools Protocol (CDP) Frame Construction: After receiving an
HTTP/1.1 101 Switching Protocolsresponse, the client formats a raw RFC 6455-compliant WebSocket frame using standard XOR client-masking. -
Remote Code Execution via
Runtime.evaluate: The payload passes a JSON-RPC message targeting the CDPRuntime.evaluatemethod. By evaluating the expression:process.mainModule.require("child_process").execSync("cp /bin/bash /tmp/rootbash && chmod +s /tmp/rootbash").toString()
Immediate, full Remote Code Execution (RCE) under the permissions of the user running the Node.js process.
- Treat the inspector as sensitive even on loopback. Binding to
127.0.0.1(Node's default since 8.4.0) protects against remote network access, but it does not protect against other local users or processes on the same host. Any unprivileged local account that can reach127.0.0.1:9229can attach to the inspector and execute code as the user running the Node process. - Don't rely on process isolation between users. If a Node process with an open inspector runs as a more privileged user (or one with access to sensitive resources) while other, less-trusted users have shell access to the same box, the inspector becomes a direct local privilege-escalation / lateral-movement path — independent of firewall rules or public exposure.
- Restrict who can reach the port. Use OS-level controls (e.g. network namespaces, containers,
iptables/nftablesrules scoped per-user or per-cgroup, or running the process under a dedicated low-privilege account) so that other local users on a shared host genuinely cannot connect to9229, rather than assuming loopback binding is sufficient isolation. - Avoid enabling the inspector on shared/multi-user hosts entirely. On systems where multiple people or services have shell access, don't run
--inspect/--inspect-brkat all debug on an isolated single-user machine or container instead. - Keep Node.js up to date. Host-header validation (added in Node 10.x/12.x+) closes the DNS-rebinding path from a browser, but it doesn't address the local-multi-user scenario above patching alone isn't sufficient mitigation here.
- Disable when done. Only run the inspector for the duration of active debugging, then shut it down. Don't leave it listening indefinitely on a host other users can log into.
- Audit for this exposure. Check for Node processes running with
--inspect/--inspect-brkand an open9229(or custom) port as part of routine hardening on any multi-user or shared server.
Note: The Inspector UUID is dynamically generated when Node.js starts. In a real testing environment, the active UUID can be retrieved from the local metadata endpoint [http://127.0.0.1:9229/json]
Note: This exploit was written with the help of AI.