The Challenge
The snack shop stores the session cart (or preference) as a base64-encoded JSON cookie. The backend decodes it and runs SELECT ... WHERE id = <cookie_id>. None of the user-visible fields are injectable — the vulnerability is in the cookie.
Approach
Three-phase UNION-based injection:
- Enumerate tables —
UNION SELECT table_name FROM information_schema.tables WHERE table_schema = database() - Enumerate columns —
UNION SELECT column_name FROM information_schema.columns WHERE table_name = 'flags' - Dump flag —
UNION SELECT flag FROM flags
Each payload is placed in the ID field of the JSON object, the whole JSON is base64-encoded, and the result is set as the cookie value.
Solution
|
|
make_cookie() serialises the dict, base64-encodes it, and returns the cookie value. The 0 UNION SELECT prefix ensures the original row is empty (no real ID=0) so only the injected row is returned.
What I Learned
Cookie values that are base64-decoded and used in SQL queries without parameterisation are SQL-injectable. The encoding layer is not a sanitisation layer. All transport formats — cookies, headers, JSON — must treat their contents as untrusted input and use parameterised queries.