Blind SQLi: Authentication Bypass
Blind SQLi
Unlike in-band SQL injection, where the results of the attack appear directly on screen, blind SQLi gives little to no feedback confirming whether an injected query worked. This is because the error messages have been disabled, even though the injection still works. It may be surprising, but that small amount of feedback is all we need to enumerate an entire database.
Authentication Bypass
One of the most straightforward blind SQLi techniques is bypassing an authentication method such as a login form. Here we are not interested in retrieving data from the database; we just want past the login.
Login forms backed by a user database are often written so that the application does not care about the content of the username and password, only whether the two form a matching pair in the users table. In plain terms, the application asks the database "do you have a user with username bob and password bob123?", and the database answers yes or no (true/false). That answer decides whether the application lets you through.
Given that, there is no need to enumerate a valid username/password pair. We just need a query that replies with a yes/true.
Practical
Level Two of the SQL Injection examples shows exactly this. In the box labelled "SQL Query" the query to the database is:
Just put %username% and %password% in the respective fields.
select * from users where username='%username%' and password='%password%' LIMIT 1;
N.B. The %username% and %password% values come from the login form fields; the initial values in the SQL Query box are blank because the fields start empty.
To turn this into a query that always returns true, enter the following into the password field:
Instead of a password, put this in to always equal true and bypass authentication.
' OR 1=1;--
Which Turns the SQL Query into the Following
select * from users where username='' and password='' OR 1=1;
Because 1=1 is always true and we used an OR operator, the query always returns true. That satisfies the application's logic that a valid username/password combination was found and access should be allowed.