A login form must be bypassed as admin five times; each round adds words to a blacklist shown in /filter.php. Closing the quote and ending the statement with ; skips the password check; once admin itself is banned, SQLite's || builds it from pieces: adm'||'in';. After round 5, filter.php displays its source with the flag in a comment.
- Platform: picoGym (picoCTF 2020 Mini-Competition)
- Category: Web Exploitation
- Difficulty: Beginner
- Tools: browserfilter.php
Challenge description
The database is SQLite (the hint says so), and the page helpfully shows the full query it runs after each attempt.
"Can you beat the filters? Log in as admin" — provided: the login page and
/filter.php
Step 1 — Understand the query
Submit any username and password and the page shows the query it ran:
SELECT * FROM users WHERE username='test' AND password='test'
Your input lands directly between quotes. If the username closes the quote and stops the statement, the AND password=... part never matters. /filter.php lists the words blocked in the current round.
Step 2 — Rounds 1 to 3: close the quote and stop the statement
Round 1 only blocks or, so a comment works:
username: admin';--
password: anything
Rounds 2 and 3 add and, like, =, -- (and then >, <). The comment is gone, but ; still ends the statement, so the rest of the query is ignored:
username: admin';
password: anything
The resulting query is SELECT * FROM users WHERE username='admin';' AND password='anything' — only the part before ; runs.
Step 3 — Rounds 4 and 5: build 'admin' without writing it
Round 4 bans the word admin, and round 5 also bans union. SQLite concatenates strings with ||, so the username can be assembled from two halves that are each allowed:
username: adm'||'in';
password: anything
The query becomes ... WHERE username='adm'||'in';' AND ..., which SQLite evaluates as username='admin'.
Step 4 — Collect the flag
After the fifth successful login, reload /filter.php in the same session. Instead of the blacklist, it now displays its own PHP source, and the flag is in a comment at the bottom.
🚩 picoCTF{ flag intentionally hidden }
The flag is deliberately hidden — follow the method, you've earned it. 💪
Key takeaways
Keyword blacklists keep losing to the many ways SQL can express the same thing:
- Closing the quote and ending the statement (
';) can neutralize the rest of a query - SQLite's
||concatenation rebuilds filtered words from allowed pieces - The fix is parameterized queries, not longer blacklists
Originally published on CTFdojo — join the CTFdojo Discord to discuss writeups and get notified about new ones.
Top comments (0)