> For the complete documentation index, see [llms.txt](https://dev-angelist.gitbook.io/writeups-and-walkthroughs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev-angelist.gitbook.io/writeups-and-walkthroughs/portswigger-web-security-academy/server-side-vulnerabilities/sql-injection/sql-injection-vulnerability-in-where-clause-allowing-retrieval-of-hidden-data.md).

# SQL injection vulnerability in WHERE clause allowing retrieval of hidden data

https\://portswigger.net/web-security/learning-paths/server-side-vulnerabilities-apprentice/sql-injection-apprentice/sql-injection/lab-retrieve-hidden-data

## Description

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:

`SELECT * FROM products WHERE category = 'Gifts' AND released = 1`

To solve the lab, perform a SQL injection attack that causes the application to display one or more unreleased products.

## Solution

<figure><img src="https://677614291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRWtuMw6xkkeDjZfkcWC%2Fuploads%2FThvJgWcM8XxpMnWtoPQ1%2Fimage.png?alt=media&amp;token=88383d98-403d-4a54-a178-bbbb8882eea2" alt=""><figcaption></figcaption></figure>

There're some products filtered into categories: All, clothing, gift, etc..

Clicking on one of them (eg. Gift) we can see that there's direct referrement to a value: `category=Gifts` it is a signal that it should be injectable

<figure><img src="https://677614291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRWtuMw6xkkeDjZfkcWC%2Fuploads%2FZ27Ya4jadXGwHvD6tFlU%2Fimage.png?alt=media&amp;token=19d6b81c-cf8f-4f76-bf9b-dcc0d48ae4e1" alt=""><figcaption></figcaption></figure>

Adding this payload: `' OR 1=1 --`  we can comment the last part of query and display all results solving the lab:

<figure><img src="https://677614291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRWtuMw6xkkeDjZfkcWC%2Fuploads%2FLcQkKrVgnO1Xbit631wA%2Fimage.png?alt=media&amp;token=e6db2f91-64ef-43f0-9032-3a2ac65d3397" alt=""><figcaption></figcaption></figure>

<figure><img src="https://677614291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRWtuMw6xkkeDjZfkcWC%2Fuploads%2FvokJYzugTsea0tysM8LM%2Fimage.png?alt=media&amp;token=40845794-ef9d-450a-85bc-660c85acd9d4" alt=""><figcaption></figcaption></figure>
