Shocker: Breaking Legacy Web Gateways via Environment Injection
The web server ran a CGI script vulnerable to Shellshock, allowing an attacker to inject commands via the User-Agent header and execute them as the web user. The attacker then escalated to root because the user could run Perl with sudo without a password.
Published on emmanuelwiseman.medium.com
Hack The Box’s Shocker is a legacy Linux infrastructure asset hosting an unauthenticated web gateway configured with an outdated Common Gateway Interface (CGI) processing script. The operational objective of this assessment was to establish an initial access boundary foothold, evaluate perimeter input string…
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 CGI script passed unsanitised HTTP headers to a vulnerable Bash version, and the sudoers file allowed the web user to run Perl as root without a password.
Impact
An attacker could execute commands as the web user and then escalate to root, leading to full host compromise and data exfiltration.
What the attacker needed
Network access to the web server; vulnerable CGI script; sudo permission to run Perl
The fix
The report does not state a specific fix, but it should be fixed by decommissioning legacy CGI and restricting sudo to specific scripts rather than interpreters.
How it was found
- Scan the target and find the /cgi-bin/ directory by monitoring 403 responses.
- Fuzz for script extensions and discover /cgi-bin/user.sh.
- Send a crafted User-Agent header containing a Shellshock payload to execute a command.
- Upgrade to a reverse shell by sending a payload that connects back to the attacker.
- Check sudo permissions and find that the user can run /usr/bin/perl as root without a password.
- Use Perl to spawn a root shell and read the flag files.
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 web server had an old program that passed user-supplied headers to a command shell without proper checks. An attacker could sneak in extra commands that the server would run. Separately, the web user was allowed to run a programming language tool as an administrator without a password, which let the attacker take full control.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.