This is a quick and easy post, mainly for my own reference moving forward. It will showcase how to upgrade and improve your reverse shells so that they are more user friendly.
Once you have a reverse shell, start by running the command
python -c 'import pty;pty.spawn("/bin/bash")'
Now we’ll background the window with
Z. We’ll be taken back to our Kali terminal window.
In the Kali terminal, type in
stty raw -echo. It will appear like nothing happened, but then type in
fg. Note: The text you type here will not display.
Enter. This will repopulate the command you ran to capture the shell, and then
Enter a 2nd time. This will take you back to your reverse shell.
Now, you can run
export TERM=xterm, which will allow you to do things like
clear the screen.
If you need to run
vi, you may find that your shell doesn’t display the editor correctly. For example, it may not fill out the entire terminal window (see image below).
To fix this, we’ll need to adjust the row and columns. From a new terminal window (on your local machine), run the following command.
Make note of the returned rows and columns. Back in your shell, run the following command to configure the terminal with the correct number of rows/columns.
stty rows <insert> columns <insert>
vi will work correctly.