SQL Injection¶
SQL injection vulnerability in WHERE
clause allowing retrieval of hidden data¶
Enumeration¶
- We are given the following webpage
Vulnerability Assessment¶
SQL Query¶
- It is given that the vulnerable SQL query is as below :
SELECT * FROM products WHERE category = 'Gifts' AND released = 1
- Playing around with the category toggle buttons
- leads us to the following
GET
request. - Confirming vulnerability by adding a
'
or in web encoding%27
- The resulting
Internal Server Error
tells us that there is an error in the SQL statement which is expected as with the addition of&27
SQL statement becomes :SELECT * FROM products WHERE category = '' Gifts' AND released = 1
Exploitation¶
- Thus with knowledge of the query as well as the type of request to use, we can inject
'1 OR 1=1 --
and the SQL query will look like below.SELECT * FROM products WHERE category = '' OR 1=1 -- Gifts' AND released = 1
- We force a true statement and commented out what is after the true statement to leak out the entire database.
SQL injection vulnerability allowing login bypass¶
Enumeration¶
- We are given the website and based on the title of the Lab we will simply hop to
My Account
- Which gives us a Login page
Vulnerability Assessment¶
Testing for Request Type¶
- First we will test the parameters to know if it is
GET
orPOST
based. - With this ,we now know that a
POST
request is needed.
Testing for Vulnerable Parameters¶
- We will input
OR 1=1
the Login and Password field individually - The below error is met for both fields hence both fields are likely vulnerable.
We can postulate that the SQL statement is as such
SELECT username,password FROM login WHERE username='$input_username' AND password='$input_password'
Exploitation¶
- Therefore by inputting
'OR 1=1 --
we will give a true statement and bypass the login. The resulting statement will be as follows :SELECT username,password FROM login WHERE username=''OR 1=1 -- AND password='$input_password' SELECT username,password FROM login WHERE username='aa' AND password='' OR 1=1 -- '
- And we managed to bypass the login.