← All scrolls
D rank
INFERNO CTF v2 · Web

Quarantined: double extensions vs an async scanner

A 'ThreatShield Pro' file store that scans uploads asynchronously, beaten by a double extension and a TOCTOU window.

05 Sept 20263 min readEasy
#file-upload#toctou#race-condition

Category: Web
Difficulty: Easy
Vulnerability: Unintended Double Extension & TOCTOU Race Condition on Async Scanner
Flag: INFERNOCTF{d0ubl3_3xtens1on_4ttack??_r34lly!!}


Challenge Card & Overview

Quarantined Challenge Box

Quarantined Overview


Reconnaissance

Visiting the target greets us with an enterprise file-storage application boasting “ThreatShield Pro v3.2”—an “advanced threat detection engine” that validates uploads, filters dangerous extensions, and inspects files for malicious payloads.

Allowed Extensions (UI Policy)

.txt  .md  .csv  .json  .log  .xml  .yml  .yaml  .ini  .cfg

Uploading a standard .py file displays a short lag before showing “Threat detected - file quarantined”. The lag indicates that security verification occurs asynchronously in the background.


Discovery: Hidden Maintenance Endpoint

2.1 robots.txt

Checking robots.txt reveals non-standard administrative routes:

GET /robots.txt

User-agent: *
Allow: /
Disallow: /api/
Disallow: /api/run/
Disallow: /uploads/

2.2 Probing /api/run/<filename>

Fuzzing /api/run/ with different extensions reveals:

  • GET /api/run/test.txt -> {"error": "Unsupported script type"}
  • GET /api/run/test.sh -> {"error": "Unsupported script type"}
  • GET /api/run/test.py -> {"error": "Script not found"}

The endpoint specifically executes .py files located inside the uploads directory via python3 <filepath>.


The Unintended Vulnerability: Double Extension & Leaked Disk Filename

During the competition, players identified an unintended vector combining double extension parsing, filename disclosure, and asynchronous race conditions:

3.1 Upload Handling & Extension Extraction

In app.py:

original_name = uploaded.filename
ext = os.path.splitext(original_name)[1] if '.' in original_name else ''
file_id = uuid.uuid4().hex[:16]
secure_name = f'{file_id}{ext}'
filepath = os.path.join(app.config['UPLOAD_FOLDER'], secure_name)

uploaded.save(filepath)

return jsonify({
    'success': True,
    'file_id': file_id,
    'filename': secure_name,   # <-- Discloses stored disk name!
    'message': 'File received. Security scan in progress.',
    'status': 'scanning',
})

When uploading a double-extension file such as exploit.txt.py:

  1. os.path.splitext("exploit.txt.py") evaluates ext as .py.
  2. The file is saved directly as <file_id>.py.
  3. The API immediately leaks the generated filename in the JSON response ("filename": "<file_id>.py").

3.2 The Asynchronous Scanner Window

After the file is saved to disk, the background scanner executes:

t = 0.00 s   POST /upload             File written to disk as <file_id>.py; filename returned
t = 0.00 s   Background thread starts
t ~ 0.15 s   Phase 1: Hash fingerprint latency (time.sleep(0.15))
t ~ 0.50 s   Phase 2: Threat signature latency (time.sleep(0.35))
t ~ 0.50 s   Phase 3: Extension check fails -> deletes file from disk

Because of the ~500ms delay before Phase 3 deletes unauthorized files, the uploaded .py script remains accessible and executable on disk.


Exploitation

By utilizing asynchronous I/O (aiohttp / asyncio), multiple workers upload .txt.py payloads and immediately invoke GET /api/run/<filename> using the leaked filename from the response, easily winning the race against ThreatShield.

4.1 Solver Script

The complete exploit is implemented in solver/solver.py.

python solver/solver.py http://localhost:8888 "cat /flag.txt"

Output:

[*] Target URL   : http://localhost:8888
[*] Command      : cat /flag.txt
[*] Strategy     : Double Extension (.txt.py) + Async TOCTOU Race
[*] Concurrency  : 8 workers (96 attempts max)

[~] Launching race workers...

[+] Race won successfully!
[+] 🚩 Flag captured: INFERNOCTF{d0ubl3_3xtens1on_4ttack??_r34lly!!}

Flag

INFERNOCTF{d0ubl3_3xtens1on_4ttack??_r34lly!!}

Impact & The Revenge Version

Because v1 leaked the disk filename and allowed double-extension uploads, players could bypass UI restrictions and execute arbitrary Python code. This directly inspired the release of Quarantined_REVENGE:

  1. The server never returns the disk filename in /upload.
  2. /api/run/<filename> strictly validates against ^[0-9a-f]{16}\.py$, eliminating double extension naming tricks.