Contents

🌐 Trickster

A detailed write-up of the Web challenge 'Trickster' from PicoCTF - 2024

/images/PicoGym/PicoCTF-2024/Trickster/challenge_presentation.png
Challenge Presentation

📊 Challenge Overview

Category Details Additional Info
🏆 Event PicoGym Event Link
🔰 Category Web 🌐
💎 Points Out of 500 total
⭐ Difficulty 🟡 Medium Personal Rating: 3/10
👤 Author Junias Bonou Profile
🎮 Solves 8.398 solve rate
📅 Date 31-01-2025 PicoGym
🦾 Solved By mH4ck3r0n3 Team:

📝 Challenge Information

I found a web app that can help process images: PNG images only!

🎯 Challenge Files & Infrastructure

Provided Files

1
Files: None

🔍 Initial Analysis

First Steps

Initially, the website appears as follows:

/images/PicoGym/PicoCTF-2024/Trickster/site_presentation.png
Site Presentation

with a form where it’s possible to upload a .png image. Uploading a random png file showed a successful upload. I decided to use the wappalyzer extension to understand which language and server type it was using:

/images/PicoGym/PicoCTF-2024/Trickster/wappalyzer.png
Wappalyzer

As we can see, it runs on an Apache server and uses PHP. The second thing I did was run gobuster to perform discovery of files or directories on the web server:

/images/PicoGym/PicoCTF-2024/Trickster/gobuster.png
Gobuster

From gobuster, something interesting came up, namely robots.txt and the /uploads/ folder. Visiting the robots file, I found two paths:

/images/PicoGym/PicoCTF-2024/Trickster/robots.png
Robots

Namely, /instructions.txt and the /uploads folder, which I had already previously found through gobuster. Visiting the /instructions.txt page, I found this:

/images/PicoGym/PicoCTF-2024/Trickster/instructions.png
Instructions

These were actual instructions for the web application. As we can see, the web application only checks that .png is present in the file extension and that the file contains the associated magic number for .png. A magic number is like a header in the binary file that indicates the type of extension the file has. Once I understood this, I made sure I could upload files other than .png by creating a file containing the word PNG (the magic number) and renaming it as exploit.png.php. When I tried to upload it, I got a valid upload, so I immediately understood how to exploit the vulnerability.

🔬 Vulnerability Analysis

Potential Vulnerabilities

  • Polyglot File
  • RCE

🎯 Solution Path

Exploitation Steps

Initial setup

To exploit the vulnerability, I created a file exploit.png.php to upload it validly to the server, adding the PNG magic number at the beginning of the file, which the server checks before allowing the upload. Then, I searched for a reverse shell (cmd) on https://www.revshells.com/ and pasted it below the PNG signature I had previously written.

Exploitation

Once this was done, the exploit consisted of uploading the file I created and then visiting the page /uploads/exploit.png.php to execute the code inside it. Through a shell created within the page using PHP’s system function, I was able to achieve RCE (Remote Code Execution) and execute commands on the web server. After that, all that was left was to find the flag:

1
2
ls ..
cat ../MFRDAZLDMUYDG.txt

Since when running ls .., the only unusual file I found was named MFRDAZLDMUYDG.txt, I immediately thought it was the flag. Indeed, by using cat on that file, I found the flag inside.

Flag capture

/images/PicoGym/PicoCTF-2024/Trickster/manual_flag.png
Manual Flag

🛠️ Exploitation Process

Approach

The exploit exactly follows the steps previously described. It sends a POST request to upload the exploit.png.php file, and then performs a GET request to /uploads/exploit.png.php, passing the parameter cmd=cat MFRDAZLDMUYDG.txt. In the response to the request, I extracted the flag using a regex and printed it.

🚩 Flag Capture

Flag

picoCTF{c3rt!fi3d_Xp3rt_tr1ckst3r_ab0ece03}

Proof of Execution

/images/PicoGym/PicoCTF-2024/Trickster/automated_flag.png
Automated Flag
Screenshot of successful exploitation

🔧 Tools Used

Tool Purpose
Python Exploit

💡 Key Learnings

New Knowledge

I have learned what a polyglot file is and how to exploit the vulnerability related to file uploads with RCE.

Skills Improved

  • Binary Exploitation
  • Reverse Engineering
  • Web Exploitation
  • Cryptography
  • Forensics
  • OSINT
  • Miscellaneous

📚 References & Resources

Learning Resources


📊 Final Statistics

Metric Value Notes
Time to Solve 00:08 From start to flag
Global Ranking Challenge ranking
Points Earned Team contribution

Created: 31-01-2025 • Last Modified: 31-01-2025 *Author: mH4ck3r0n3 • Team: *