> 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/de/web/sql-injection/union-attack-determining-number-of-columns.md).

# Erkennung der Spaltenanzahl bei UNION-Angriffen

### SQL-Injection-UNION-Angriff, Bestimmung der Anzahl der von der Abfrage zurückgegebenen Spalten

* **Hintergrund:** `Kategorie` Filter anfällig für SQL-Injection; Die Anwendungsausgabe enthält SQL-Ergebnisse, daher ein `UNION` ermöglicht das Einschleusen einer zusätzlichen sichtbaren Zeile.
* **Ziel:** die genaue Anzahl der von der ursprünglichen Abfrage zurückgegebenen Spalten finden, um kompatible `UNION SELECT`.
* **Schnelle Methode:**

1. **Teste mit `ORDER BY`** — den Index erhöhen, bis ein Fehler auftritt (der Fehler zeigt an, dass der Index die Anzahl der Spalten überschreitet):

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

* Wenn `ORDER BY N` einen Fehler verursacht, ist die Anzahl der Spalten `< N`.

2. Bestätigen Sie dies, indem Sie eine UNION-Zeile mit NULL einschleusen — erstellen Sie ein UNION-SELECT mit derselben Anzahl an Spalten; wenn die Anwendung die eingeschleuste Zeile (Nullwerte) anzeigt, ist die Anzahl korrekt. Beispiel (3 Spalten):

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

* Wenn die Zeile erscheint, gibt die ursprüngliche Abfrage 3 Spalten zurück. Andernfalls passen Sie die Anzahl der `NULL` an und testen Sie erneut.

**Nützliche Varianten:**

* Verwenden Sie Konstanten, um die angezeigte Spalte zu lokalisieren (nützlich, wenn nur einige Spalten zurückgegeben werden):

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

(Ermöglicht die visuelle Identifizierung, welche Spalten der Antwort den eingeschleusten Spalten entsprechen.)

* Wenn UNION aufgrund von Datentypen fehlschlägt, ersetzen Sie einige Konstanten je nach DBMS durch CAST(NULL AS VARCHAR2) / NULL oder passen Sie die Typen mit CAST/TO/ CHAR an.

Erwartetes Ergebnis: Eine zusätzliche Zeile mit NULL (oder Konstanten) wird angezeigt → Anzahl der Spalten bestimmt.


---

# 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/de/web/sql-injection/union-attack-determining-number-of-columns.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.
