Spawing Interactive Shells


๐Ÿง  Spawning Interactive Shells

When you land a limited shell (non-tty), your capabilities may be restricted:

  • No prompt

  • No job control

  • Limited or blocked commands (e.g., sudo, su, ctrl + c)

Use one of the following methods to upgrade to an interactive TTY shell, depending on which tools/languages are available on the system.


๐Ÿ“œ Methods for Spawning TTY Shells

๐Ÿ Python (most common)

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

Alternative (if python3 is available):

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

๐Ÿงฎ /bin/sh (Bourne Shell)

/bin/sh -i
  • Launches an interactive shell directly


๐Ÿง™ Perl

Or, from a script:


๐Ÿ’Ž Ruby

From script:


๐Ÿข Lua

From script:


๐Ÿงพ AWK

  • Uses system() to spawn shell via awk, available on most Unix systems


๐Ÿ” Find

Searches for a file, and spawns a shell using awk:

Or directly invoke shell:


๐Ÿ“ VIM

Escape to shell from within Vim:

Or manually from Vim:


๐Ÿ” Checking Execution Permissions

Check if you can run a file or binary:

Example:


๐Ÿ”‘ Check sudo Permissions

If you have a stable interactive shell, run:

Example output:

  • Indicates full sudo access without password โ€” potential for privilege escalation.

โš ๏ธ Note: sudo -l may not work in unstable or limited shells.

Last updated