For the complete documentation index, see llms.txt. This page is also available as Markdown.

Stabilizing Shells

Interactive Upgrade

Python

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

Python3

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

Full Upgrade

python3 -c 'import pty; pty.spawn("/bin/bash")'
ctrl + z
stty raw -echo; fg
export TERM=xterm
# local terminal
stty -a
# remote terminal 
stty cols=xx rows=xx

Bash

SOCAT

attacker host

target Host

Second Method

  • in a local terminal

  • Set TTY to raw

  • Foreground the shell

  • Reinitialize terminal

  • Set shell terminal type


Spawning Interactive Shells

When landing on a system with a limited (non-tty) shell, Python may not be installed. These alternative methods can spawn an interactive shell using whatever is available on the target. Wherever /bin/sh appears, it can be replaced with /bin/bash if available.

/bin/sh -i

Executes the shell interpreter in interactive mode (-i).

Perl

From within a Perl script:

Ruby

From within a Ruby script:

Lua

AWK

Find

Searches for any file, then uses -exec to invoke awk which spawns a shell:

Simpler variant that directly launches a shell:

VIM

Or from within vim:


Execution Permissions Check

After spawning a shell, verify what you can do:

Check sudo permissions:

Last updated