🌐 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
1
Files: None
🔍 Initial Analysis
First Steps
Initially, the website appears as follows:
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 thewappalyzer
extension to understand which language and server type it was using:As we can see, it runs on an
Apache
server and usesPHP
. The second thing I did was rungobuster
to perform discovery of files or directories on the web server:From
gobuster
, something interesting came up, namelyrobots.txt
and the/uploads/
folder. Visiting the robots file, I found two paths:Namely,
/instructions.txt
and the/uploads
folder, which I had already previously found through gobuster. Visiting the/instructions.txt
page, I found this: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 associatedmagic 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 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.php
to upload it validly to the server, adding thePNG
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 thePNG
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’ssystem
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 namedMFRDAZLDMUYDG.txt
, I immediately thought it was the flag. Indeed, by usingcat
on 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.php
file, 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: *