I’m going through the SQL Injection Fundamentals module and I am unable to obtain the flag for the exercise in the “Subverting Query Logic” section despite performing a successful bypass. There’s no flag on the page:
It’s actually a bug in my payload, not the application itself! Should’ve scrutinized it more closely but for some reason I thought the exercise itself got broken somehow, LOL.
Thanks to Ryan from the support team who gave a detailed explanation:
Hi there, I’m Ryan.
This is not a bug. This is exactly what is expected to happen.
You entering the username as tom does not mean you will be logged in as tom. This is an expected consequence of the query logic.
SELECT * FROM logins (WHERE username=‘tom’ AND password = ‘admin’) OR ‘1’=‘1’ is the query that got ran. There are no cases where the username is tom and the password is admin, so this WHERE always fails. However, the OR 1=1 matches on the very first row (which is the admin account), and thus you are logged in as admin.
This is not a bag, it’s just that when the symbol ' is added at the beginning, it treats it as a string. To fix this, the starting and ending ' symbols need to be removed.