SQLi authorization bypass
Now we know that we can put in any code we want and it's going to be executed on the system. So, let's have another look at the statement, which says select * from accounts where username = username
, and password = password
, which we put in the Password
textbox. We will now see whether we can use that to log in without using a password, and we are going to be doing that with the admin. So, username
is going to be admin
, and we don't know what password
is for admin
, so we are going to enter any random password, for example, aaa
. In the code that we were previously running, we put and 1=1
, now instead of and
, we are going to say or 1=1
. So, once we inject the command, it is going to let us log in without even knowing the password of admin
. Our code is going to look as follows:
select * from accounts where username = 'admin' and password='aaa' or 1=1'
When we log in using the admin
Username
and paste aaa' or 1=1
in the Password
textbox, we can see that we logged in successfully...