Upgrade reverse shell to interactive

First things first

When getting a reverse shell, it will most probably be a basic shell that doesn't have TAB auto-completion or gets broken when using CTRL + C To upgrade to a interactive shell we can do the following:

Steps
script /dev/null -c bash
"CTRL + Z"
stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=/bin/bash    #Optional
stty size                 #In attacking shell to check sizing you want
stty rows n columns m     #"n" and "m" corresponding to the size we just checked
  1. script /dev/null -c bash script starts a script session that records every command you do, but we pass the output to /dev/null, thus discarding it, then -c allows us to pass a command, in this case bash so it runs the bash shell within that session

  2. CTRL + Z Sends current process to the foreground, returning us to our attacking shell

  3. stty raw -echo; fg stty to change terminal settings, raw to turn on raw mode so input as for example CTRL + C is not interpreted in the attacker terminal and -echo so its not printed too fg "foreground" brings back the process of the victim's terminal

  4. reset xterm Write it even if the prompt is hidden, will reset the terminal to its default state and we are almost finished

  5. export TERM=xterm Establishes xterm as the terminal emulator if it isn't already

  6. export SHELL=/bin/bash Optional step but recommended as bash is in almost systems so its compatible and we want everything to be functional

  7. stty size In our attacking shell, will print current size of the window in rows and columns so that's what we want to imitate

  8. stty rows n columns m Sets the victim shell to the same size as our terminal, so binaries like nano look proportionate

Last updated