> 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

Notizen zur Erkennung der Spaltenanzahl bei UNION-Angriffen für Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungs-Workflow, Payload-Tests, Burp-Suite-Validierung und Behebungskontext.

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

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

1. **Testen Sie 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ätige dies, indem du eine UNION-Zeile mit NULL einschleust — erstelle ein UNION-SELECT mit derselben Anzahl an Spalten; wenn die Anwendung die eingeschleuste Zeile (Null-Werte) anzeigt, ist die Anzahl korrekt. Beispiel (3 Spalten):

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

* Wenn die Zeile erscheint, liefert die ursprüngliche Abfrage 3 Spalten zurück. Andernfalls passe die Anzahl der `NULL` und erneut testen.

**Nützliche Varianten:**

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

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

(So lässt sich visuell erkennen, welche Spalten der Antwort den eingeschleusten Spalten entsprechen.)

* Wenn UNION aufgrund von Typen fehlschlägt, ersetze einige Konstanten je nach DBMS durch CAST(NULL AS VARCHAR2) / NULL oder passe 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 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/de/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.
