The tale of Restricted Shell bypass leading to Arbitrary Code Execution
The application allowed users to execute shell commands from the web interface but used a restricted shell to limit them. An attacker could break out of the restricted shell and gain full shell access, then perform all tasks the web application could.
pranavgadekar.medium.com
Published on pranavgadekar.medium.com
Hello people, Pranav Gadekar here again and today I want to talk about a weird bug that I came across during the security assessment of a company. The bug was related to the Restricted Shell bypass.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the application relied on a restricted shell to limit command execution instead of properly validating or sanitising user input, allowing shell escape techniques.
Impact
An attacker could gain full shell access and perform all tasks that the web application was able to perform, potentially leading to further compromise.
What the attacker needed
Access to command input field
How it was found
- Access the command input field in the web interface.
- Execute a command to check the shell type, which revealed /bin/rbash.
- Try various restricted shell bypass methods, such as using vi, /bin/bash, bash -i, cp, export, ftp, gdb, man/less/more, or programming languages.
- Use Python to spawn a shell with os.system, which successfully broke out of the restricted shell.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A restricted shell is a limited command-line interface that only allows certain commands. The application let users run some commands but tried to restrict them using this shell. The attacker found a way to escape the restrictions and get a full shell, giving them more control over the system.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.