PortSwiggerMedium

Blind SQL injection with conditional responses

Remon Nagy·10 min read·Case file

Target
Blind SQL injection with conditional responses
Objective
To solve the lab, log in as the administrator user.
Time to read
10 min
Skills
BurpsuiteCTFSQLi
  1. 01Overview
Open on PortSwigger ↗

01Overview

Lab: Blind SQL injection with conditional responses

The main idea in this lab is how check response from server and find the difference between responses in server response to decide if this application vulnerable to blind sql injection or not so first thing that we intercept the request and send it to repeater

Fig. 1

as we see in the normal request there is welcome back message in the server response so let's try to check if this message will be change if we change the request or not

Fig. 2

as we see in this request we send boolean sql query and it's false becuse 1 dosn't equal 2 and by looking to response there is no match with serever response for welcome message but if we change and statment to be ' and '1'='1'-- we will get welcome message again in response as screen shoot below

so we now sure that is Blind SQL injection in this app so let's move on and try to get user name from database but first we need to confirm that there is table users in database or not by using this query ' AND (SELECT 'a' from users LIMIT 1)='a'-- This query check if there is a table called users or not by checking the response that come from the server we get our welcome message so that indicate that this table exist in database

So let's move on again but now we want to check if user name administrator exist on users table or not so we will use this query

Fig. 3
Fig. 4
  • ' AND (SELECT username from users where username = 'administrator')='administrator'--
Fig. 5

as screen shoot the response come with our welcome message and that confirm there is user administrator in users table so let's move on and try to get the password from data base but first we need to know what is password length for user administrator so we will use this query

' AND (SELECT username from users where username = 'administrator' and length(password) > 1) ='administrator'--

by using this query we try to guess how many char in administrator password so we try one and get our welcome message again

Fig. 6
Fig. 7
  • when we try password length more than 30 we didn't get our welcome message back on response so we now know that the password less than 30 and more than 1 charachter so we will send the requerst to intruder to get the actual password length
Fig. 8

as we see we send the request to the intruder and clear all § sign from the requestr and ad it only to the number we need to change as screen shoot then we will go to payload tab and set payload type to numbers and set number range from 1 to 30 becuase we know that password less than 30 and more than 1 and step 1 because we need to increase this number by in every request as screen shoot below then click strat attack

Fig. 9
Fig. 10
  • by looking in the result we will find that we have to length for requests we send and when we try to find our welcome back message Boom we find it so we know now that the request length 5550 ( in my case ) has the welcome back message
Fig. 11

but when we search on the other lengnth for our welcome back message we didn't find it so by looking to the result we see that the length change in request number 20 and that mean the password length is 20 charachter so let's move on and find it !

so to find the password we will use substring function in sql query to try to guess the password charachter query will be like this

' AND (SELECT substring(password,1,1) from users where username = 'administrator')='1

in this query we try to find the first charachter in password by guess it so if first charachter equales 1 we will see our welcome message if not we didn't get this message

Fig. 12

as we see there is no welcome message in this response that mean that the first password charachter is not 1 so by trying continue by 2 and 3,4,5,6 we get our welcome message as screen shoot below

' AND (SELECT substring(password,2,1) from users where username = 'administrator')='6

that mean we will guess the second charachter in the password and so on with every charachter untill we complete it to do this we will send this request to the intruder and use cluster bomb as attack type and clear all § sign and add it to the numbers we need to change to be like that

' AND (SELECT substring(password,§1§,1) from users where username =

'administrator')='§6§

and for first payload we will set it to numbers and set from number 1 to number 20 becuase password length is 20 and for second payload we will set it to bruteforce and set min length to 1 and max length to 1 becuase we need to change only one charachter to see if equal password or not

Fig. 13
Fig. 14

and then click start attack... by looking to the result we see that we have two length for responses and if we look to every each of the we will find that there is welcome back message in responses like screen shoot

Fig. 15
Fig. 16

so by looking to payload number column we see that it is payload number zero that mean the first charachter in password = 6 and so on let's get all off charachter by order payload on with payload two and in my case password is [hidden] mnt** get this password and login to administrator account and booom lab has been solved

Lab statusSolved ✓

Now open the lab and solve it yourself. Reading a solution is not the same as finding it.

Written for practice on PortSwigger's own lab. Never use these techniques on systems you are not authorized to test.
Remon NagyPenetration tester & cybersecurity instructor · LPT (Master), CPENT, CEH

More coming

Don't miss the next file