> 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-determining-number-of-columns.md).

# Определение количества столбцов для UNION-атаки

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

### Атака SQL-инъекцией UNION: определение числа столбцов, возвращаемых запросом

* **Контекст:** `категория` фильтр уязвим к SQL-инъекции; ответ приложения включает результаты SQL, поэтому `UNION` позволяет внедрить дополнительную видимую строку.
* **Цель:** найти точное число столбцов, возвращаемых исходным запросом, чтобы построить совместимый `UNION SELECT`.
* **Быстрый метод:**

1. **Проверьте с `ORDER BY`** — увеличивайте индекс, пока не возникнет ошибка (ошибка указывает, что индекс превышает число столбцов):

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

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

2. Подтвердите, внедрив строку UNION, содержащую NULL — составьте SELECT UNION с тем же числом столбцов; если приложение отображает внедрённую строку (значения null), число верно. Пример (3 столбца):

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

* Если строка отображается, исходный запрос возвращает 3 столбца. В противном случае скорректируйте число `NULL` и повторите тест.

**Полезные варианты:**

* Используйте константы, чтобы определить отображаемый столбец (полезно, если возвращаются только некоторые столбцы):

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

(Позволяет визуально определить, какие столбцы ответа соответствуют внедрённым столбцам.)

* Если UNION не проходит из-за типов, замените некоторые константы на CAST(NULL AS VARCHAR2) / NULL в зависимости от СУБД или приведите типы с помощью CAST/TO/CHAR.

Ожидаемый результат: отобразится дополнительная строка, содержащая NULL (или константы) → число столбцов определено.


---

# 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-determining-number-of-columns.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.
