Upgrading TTY

March 09, 2025

When we establish a reverse shell, it is often very limited in functionality and prone to breaking.

Basic features like command history navigation (using up/down arrows) or autocomplete may not work. To resolve these limitations, we can upgrade our TTY using the python or stty method.

Below is a step-by-step guide on how to do this.

1. Spawn a TTY Shell
Run this in the reverse shell:

python3 -c 'import pty; pty.spawn("/bin/bash")'

2. Adjust Terminal Settings

  • Suspend the shell: Ctrl+Z
  • In your local terminal, run:

      stty raw -echo  
      fg  
      [Press Enter Twice]  
    

3. Fix Terminal Size (Optional)

  • In a local terminal:
      echo $TERM          # e.g., xterm-256color  
      stty size           # e.g., 38 116  
    
  • Back in the reverse shell, set:
      export TERM=xterm-256color  
      stty rows 38 columns 116  
    

You now have a fully interactive TTY shell with command history, autocomplete, and full terminal features.

Reference: Ropnop Blog