> For the complete documentation index, see [llms.txt](https://derek-johnson-1.gitbook.io/welcome/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://derek-johnson-1.gitbook.io/welcome/projects/sql-injection.md).

# SQL Injection

### Tutorial Video

{% embed url="<https://www.youtube.com/watch?v=2OPVViV-GQk>" %}

### Requirements

* Computer
* Internet access
* Proxy (if you want to stay anonymous)

### Step 1: Try a commonly used username and password.

```
username: admin password: password123
```

This not surprisingly didn't work and returned the following message.

<figure><img src="https://2268061532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fo71vDQ8YHfe6Cj11Juh6%2Fuploads%2F1i7my6Rg67QghvnJsipv%2FSQLpicture01.jpg?alt=media&amp;token=28836107-d6da-486b-8dba-02cc191530f5" alt=""><figcaption></figcaption></figure>

### Step 2: testing sql syntax

In this step we want to test the sql syntax to see if it is possible to alter how the code executes on the database side.

<figure><img src="https://2268061532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fo71vDQ8YHfe6Cj11Juh6%2Fuploads%2FUuPBoAuYmDiaiYd9wlJd%2FSQLpicture04.jpg?alt=media&amp;token=bc972a69-d5d4-462e-83e7-96f81582a5e4" alt=""><figcaption></figcaption></figure>

```
username: admin' password: password123
```

<figure><img src="https://2268061532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fo71vDQ8YHfe6Cj11Juh6%2Fuploads%2FAEJTGerKn3g9AOPoSSyG%2FSQLpicture02.jpg?alt=media&amp;token=ca08a858-5f7c-470f-906a-f11b7fad0673" alt=""><figcaption></figcaption></figure>

As we can see adding a ' to the end of our username caused a syntax error confirming that we can alter the sql code and how it is executed.

### Step 3: Changing the sql code

With the sql injection, we want to try and alter the sql code to only require a username to return true and authenticate us as the admin user.

```
username: admin'-- password: password123
```

<figure><img src="https://2268061532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fo71vDQ8YHfe6Cj11Juh6%2Fuploads%2FRa8bYo5PJ2J0xyKk7ZAn%2FSQLpicture03.jpg?alt=media&amp;token=de06004d-505e-4e5f-ae69-b208f04ef7f7" alt=""><figcaption></figcaption></figure>

After entering this injection you should be logged in to the website as admin. What the additional '-- does is comments out the rest of our sql code.

<figure><img src="https://2268061532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fo71vDQ8YHfe6Cj11Juh6%2Fuploads%2Fan0FO7kBVjf3XQowV95C%2FSQLpicture05.jpg?alt=media&amp;token=025d876c-84ec-471d-ba3f-d17d05c63e8f" alt=""><figcaption></figcaption></figure>
