🌐 Trickster
A detailed write-up of the Web challenge 'Trickster' from PicoCTF - 2024
📊 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
1Files: None
🔍 Initial Analysis
First Steps
Initially, the website appears as follows:
with a form where it’s possible to upload a
.pngimage. Uploading a random png file showed a successful upload. I decided to use thewappalyzerextension to understand which language and server type it was using:As we can see, it runs on an
Apacheserver and usesPHP. The second thing I did was rungobusterto perform discovery of files or directories on the web server:From
gobuster, something interesting came up, namelyrobots.txtand the/uploads/folder. Visiting the robots file, I found two paths:Namely,
/instructions.txtand the/uploadsfolder, which I had already previously found through gobuster. Visiting the/instructions.txtpage, I found this:These were actual instructions for the web application. As we can see, the web application only checks that
.pngis present in the file extension and that the file contains the associatedmagic numberfor.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.pngby creating a file containing the wordPNG(the magic number) and renaming it asexploit.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.phpto upload it validly to the server, adding thePNGmagic 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 thePNGsignature 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.phpto execute the code inside it. Through a shell created within the page using PHP’ssystemfunction, 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 2ls .. cat ../MFRDAZLDMUYDG.txtSince when running
ls .., the only unusual file I found was namedMFRDAZLDMUYDG.txt, I immediately thought it was the flag. Indeed, by usingcaton that file, I found the flag inside.
Flag capture
🛠️ Exploitation Process
Approach
The exploit exactly follows the steps previously described. It sends a POST request to upload the
exploit.png.phpfile, and then performs a GET request to/uploads/exploit.png.php, passing the parametercmd=cat MFRDAZLDMUYDG.txt. In the response to the request, I extracted the flag using a regex and printed it.
🚩 Flag Capture
FlagpicoCTF{c3rt!fi3d_Xp3rt_tr1ckst3r_ab0ece03}
Proof of Execution
🔧 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: *