Skip to content

About

Exploit for Node.js Inspector enabling code execution via the Chrome DevTools Protocol

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Node-Inspector-Exploit

Exploit for Node.js Inspector enabling code execution via the Chrome DevTools Protocol

Technical Explanation

Background

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.

Attack Vector & Mechanics

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:

  1. HTTP Upgrade Handshake: The script creates a raw TCP socket connection to 127.0.0.1:9229 and sends an HTTP request containing standard Upgrade: websocket headers to establish a WebSocket session with the V8 Inspector endpoint UUID ().

  2. Chrome DevTools Protocol (CDP) Frame Construction: After receiving an HTTP/1.1 101 Switching Protocols response, the client formats a raw RFC 6455-compliant WebSocket frame using standard XOR client-masking.

  3. Remote Code Execution via Runtime.evaluate: The payload passes a JSON-RPC message targeting the CDP Runtime.evaluate method. By evaluating the expression:

    process.mainModule.require("child_process").execSync("cp /bin/bash /tmp/rootbash && chmod +s /tmp/rootbash").toString() 

Consequences

Immediate, full Remote Code Execution (RCE) under the permissions of the user running the Node.js process.

Mitigation

  • 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 reach 127.0.0.1:9229 can 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/nftables rules 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 to 9229, 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-brk at 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-brk and an open 9229 (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.

About

Exploit for Node.js Inspector enabling code execution via the Chrome DevTools Protocol

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages