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) |
| Verified against | thomasbui's picoCTF Mini 2020 writeup |
| Category | Web Exploitation |
| Difficulty | Beginner |
| Tools | browser filter.php |
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
Stuck? Try a hint before reading the solution
The page shows the SQL query it builds from your input. Can you end it early?
Close the quote and add ;. When admin is banned, SQLite's || can build it.
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.
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.
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'.
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.
The flag is deliberately hidden — follow the method, you've earned it. 💪
Keyword blacklists keep losing to the many ways SQL can express the same thing:
';) can neutralize the rest of a query|| concatenation rebuilds filtered words from allowed piecesNew to CTFs? Start here: beginner's guide to CTFs — what a CTF is, the categories, the tools and a step-by-step plan.
Discuss this writeup with the community on the CTFdojo Discord.
Join the Discord →