WHERE clause allowing retrieval of hidden data
Last updated
Last updated
Lab #1 by PortSwigger Web Security Academy:
This lab contains a SQL injection vulnerability in the product category filter. When the user selects a category, the application carries out a SQL query like the following:
To solve the lab, perform a SQL injection attack that causes the application to display details of all products in any category, both released and unreleased.
Upon accessing the lab and filtering on the Pets
category, I noticed a GET parameter named category
in the URL.
To test the applicationβs behavior, I initially tried adding a single quote ('
) by navigating to https://0abe00670490492181da436400ec000b.web-security-academy.net/filter?category='
.
This resulted in an Internal Server Error
, which confirms that the application is indeed vulnerable.
By adding a single quote ('
) to the category
parameter, the application executes the following query against the database:
Letβs try replacing '
with '--
. The key thing here is that the double-dash sequence --
is a comment indicator in SQL, and means that the rest of the query is interpreted as a comment. This effectively removes the remainder of the query, so it no longer includes AND released = 1
.
Expected Query:
URL: https://0abe00670490492181da436400ec000b.web-security-academy.net/filter?category='--
As we can observe, the error disappeared, and the page returned no products. Perfect!
Next, letβs try ' OR 1=1
, which will return the result of the following query:
The modified query will return all items where either the category is empty (''
) or 1=1
. Since 1=1
is always true, the query will return all items.
This solves Lab #1! Congratulations.
However, we wonβt stop here. Letβs go the extra mile and automate the SQLi payload. To begin, download Burp Suite Community Edition and ensure that the Proxy listener is enabled.
Download the FoxyProxy extension and add the Burp Suite proxy address and port.
Enable the Burp proxy and navigate to the interface where Burp is running (127.0.0.1:8080
). Save the CA certificate when prompted.
To prevent Firefox SSL errors when using Burp, import the certificate we just downloaded by going to about:preferences#privacy
in Firefox.
We are now ready to intercept our HTTP(s) traffic through Burp. As shown below, the intercept is on, and we can observe the GET /filter?category=param
request.
To automate this SQL injection payload, we can use the below Python script:
To test our script with the Labβs temporary URL and the payload we initially tested (' OR 1=1--
), you can use the following command:
et voilΓ ! would be very happy :-)