CTFroom: RootMe — Web File Upload Bypass (.phtml) & SUID Privilege Escalation
Bypassing client-side and server-side file extension filters to upload a PHP webshell using .phtml extension, capturing a reverse shell, and hunting for misconfigured SUID binaries to elevate directly to root.
Challenge Overview
RootMe is a staple penetration testing challenge that demonstrates how incomplete server-side file extension blacklists and misconfigured file permissions (SUID bits) can lead to complete machine takeover.
Phase 1: Port Scanning & Directory Discovery
Discovered services:
Running directory brute-forcing with gobuster:
Discovered interesting endpoints:
/panel/ — File upload portal/uploads/ — Public directory where uploaded files are storedPhase 2: File Upload Filter Bypassing
Visiting http://10.10.65.120/panel/, we find a file upload form.
Attempting to upload a standard PHP reverse shell (shell.php) triggers an error:
The server checks for the .php file extension. However, Apache configurations often map alternative PHP execution extensions. We test common bypasses:
.php3.php4.php5.phtmlWe rename our payload to shell.phtml:
Uploading shell.phtml succeeds with a green confirmation message!
Phase 3: Triggering Reverse Shell
We start our Netcat listener:
In the browser, we browse to http://10.10.65.120/uploads/shell.phtml. The script executes, sending a shell back to our listener:
We locate the user flag:
Phase 4: SUID Binary Enumeration & Root Escalation
We search the entire filesystem for binaries with the SetUID (SUID) permission bit enabled:
Among standard system binaries (/bin/ping, /bin/su), we identify an anomalous binary:
Having the SUID bit on a scripting interpreter like Python allows any user to execute arbitrary commands with the privileges of the file owner (root).
Checking GTFOBins for python with SUID:
Executing the payload:
We have root access (euid=0). We read the root flag:
Key Takeaways & Defense
php_flag engine off or RemoveHandler .php .phtml in the upload directory.