Upgrading a Reverse Shell to a Fully Interactive TTY

When a reverse shell is obtained, it is often limited and non-interactive.
Common issues include missing tab completion, broken terminal behavior, and the inability to use interactive programs such as sudo, su, or text editors.

This guide describes a standard and reliable method to upgrade a basic reverse shell to a fully interactive TTY.


Step 1 — Spawn a Pseudo-Terminal (PTY)

The first step is to spawn a pseudo-terminal on the target system using Python.
This provides a more functional shell environment.

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

At this stage, the shell is improved but still not fully interactive.


Step 2 — Background the Shell

Press the following key combination to background the current shell and return to your local terminal:

1
CTRL + Z

This suspends the remote shell process and allows you to adjust your local terminal settings.


Step 3 — Fix Terminal Line Settings

On your local machine, configure the terminal to properly handle raw input and disable echoing:

1
stty raw -echo

Then, bring the remote shell back to the foreground:

1
fg

At this point, input handling and command execution should behave much more like a normal terminal.


Step 4 — Set the Terminal Environment

Finally, define the terminal type on the target system to enable features such as clear screen support and proper formatting.

1
export TERM=xterm

Optionally, you can also set the terminal dimensions to fully restore usability:

1
stty rows 40 columns 120

Result

After completing these steps, the reverse shell will behave like a standard interactive terminal, with:

  • Proper command-line editing
  • Tab completion
  • Support for interactive programs (sudo, su, nano, etc.)
  • Correct screen rendering

Summary

Step Purpose
pty.spawn() Create a pseudo-terminal
CTRL + Z Suspend shell to fix local TTY
stty raw -echo; fg Restore proper input handling
export TERM=xterm Enable full terminal capabilities
← Torna alla home