๐ Editor
A detailed write-up of the Web challenge 'Editor' from SwampCTF - 2025
๐ Challenge Overview
Category Details Additional Info ๐ Event SwampCTF-2025 Event Link ๐ฐ Category Web ๐ ๐ Points 150 Out of 500 total โญ Difficulty ๐ข Easy Personal Rating: 0/10 ๐ค Author Unknown Profile ๐ฎ Solves (At the time of flag submission) 152 solve rate ๐ Date 31-03-2025 SwampCTF-2025 ๐ฆพ Solved By mH4ck3r0n3 Team: havce
๐ Challenge Information
I took a few hours to create a simple HTML/CSS previewer system. Since there’s no way to add JavaScript then my server should be safe, right? Grab the flag from the http://chals.swampctf.com:47821/flag.txt file on the server to show that this isn’t the case. The flag is in the standard format. Good luck! http://chals.swampctf.com:47821
๐ฏ Challenge Files & Infrastructure
Provided Files
Files:
๐ Initial Analysis
First Steps
Initially, the website appears as follows:
Since I didn’t find anything interesting here, I moved on to analyzing the attached files. This is a
Flaskchallenge where we need to access the/flag.txtroute. Direct access results in aForbiddenresponse:
1 2 3 4 5 6 7 8 9 10 11 12@app.route("/", defaults={"path": "index.html"}) @app.route("/<path:path>") def serve_files(path): ย ย try: ย ย ย ย return send_from_directory(app.static_folder, path) ย ย except: ย ย ย ย referer = request.headers.get("Referer", "") ย ย ย ย if not referer or not (referer.startswith("http://127.0.0.1:5000/") or referer.startswith("http://localhost:5000/")): ย ย ย ย ย ย print(referer) ย ย ย ย ย ย abort(403, description="Forbidden: Accessing files directly is not allowed... You didn't think it'd be that easy did you.") ย ย ย ย return send_from_directory("/app/", path)As we can see, if the
Refererheader is not set tohttp://127.0.0.1:5000/orhttp://localhost:5000/, we receive a403status code. Initially, I thought it would be enough to make a request like this:
1curl http://chals.swampctf.com:47821/flag.txt -H "Referer: http://localhost:5000/"to access the
/flag.txtroute, but this returnedForbidden:Let’s move on to the exploitation phase.
๐ฌ Vulnerability Analysis
Potential Vulnerabilities
- 403 Bypass (?)
๐ฏ Solution Path
Exploitation Steps
Initial setup
To better understand the challenge and how it works, the first thing I did was test it locally. When I tried sending the same request as before:
1curl http://localhost:5000/flag.txt -H "Referer: http://localhost:5000/"I was able to retrieve the flag:
How is this possible? At first, I thought the challenge was brokenโฆ let’s move on to the next phase to analyze everything more thoroughly.
Exploitation
The first thing I did was import
systo usesys.stdout.flush()and addprint()debug statements to understand how the challenge works. However, focusing on the fact that it worked withHost: localhost:5000andReferer: http://localhost:5000/, I tried the same approach for the remote challenge by sending a request with identicalHostandRefererheaders:
1curl http://chals.swampctf.com:47821/flag.txt -H "Referer: http://chals.swampctf.com:47821/"Using this method, just like with localhost, I obtained the flag. I then thought that the implementation on the server might be different (?).
Flag capture
๐ ๏ธ Exploitation Process
Approach
The automatic exploit performs a simple GET request by setting the
Referer: http://chals.swampctf.com:47821/header and prints the response.
๐ฉ Flag Capture
FlagswampCTF{c55_qu3r135_n07_j5}
Proof of Execution
๐ง Tools Used
Tool Purpose Python Exploit
๐ก Key Learnings
Skills Improved
- Binary Exploitation
- Reverse Engineering
- Web Exploitation
- Cryptography
- Forensics
- OSINT
- Miscellaneous
๐ Final Statistics
| Metric | Value | Notes |
|---|---|---|
| Time to Solve | 00:10 | From start to flag |
| Global Ranking (At the time of flag submission) | 17/751 | Challenge ranking |
| Points Earned | 150 | Team contribution |
Created: 31-03-2025 โข Last Modified: 31-03-2025 Author: mH4ck3r0n3 โข Team: havce