# Pilgrimage

<details>

<summary>resources</summary>

GitDump:

<https://github.com/Ebryx/GitDump>

Pspy64:

<https://github.com/DominicBreuker/pspy>

</details>

### Phase 1 - Reconnaisance

First, we scan using `nmap`:

![](/files/6JouU9icEwpTIL2KDvaW)

So we have a webpage on port `80`, with a redirect to `pilgrimage.htb`.\
This means that to access the page, we need add `pilgrimage.htb` to the `/etc/hosts` file:

![](/files/WrY8KD1lQqlRCJyeJggk)

It's a website running an "image shrinker":

![](/files/JVSTuinRuQBKyG4Fc9Kn)

Then, we scan the website using `gobuster`:

![](/files/VrqpDTpGMFgepSnJCspR)

We find a `.git` directory on the site:

![](/files/ZyQAbAWRiCAKMUU8Thex)

It is forbidden, so let's use the `GitDump` tool to extract the git code:

![](/files/XQ8lE7OafmvHVnI5Lx36)

![](/files/YlQ7epXRTwfLqtMdFP70)

And we have the `git`  files:

![](/files/6mLAln1Kj2PdOgPbIVnz)

### Getting the foothold

First, we investigate the files. the `magick` immediately stands out, so we check to see what it is:

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

`ImageMagick 7.1.0-49`, after a bit of googling we find a vulnerability:

![](/files/xIhiACDC5Ke1AshbANXs)

{% embed url="<https://www.exploit-db.com/exploits/51261>" %}

First, we test the exploit:

![](/files/qLUPvN9Em0reloWq7nNp)

We upload the file:

![](/files/R3vaKeDSW7VI76uf85X3)

![](/files/D8MZEMW4TP8EpfawkM55)

We download the file, and run `exiftool`:

![](/files/cFVGLdqHPmPLGMiPtYeE)

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

There's a very long string under the `Raw Profile Type`, so we plug it into `CyberChef`:

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

The exploit works. It is only an arbitrary file read exploit, so it won't directly give us a shell.

After a bit of looking, we find this code in the `register.php` we found using `GitDump`:

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

It accesses the `/var/db/pilgrimage` database file, so that will be our target.\
We run the exploit again:

![](/files/261B2U0GvmEi9s3A3sGp)

We follow the same downloading steps, and run `exiftool` again:

<figure><img src="/files/32xP3stkI42KuJZaox9m" alt=""><figcaption></figcaption></figure>

Note: the file only begins after the first dot, so we remove the `20480.` from our input in this case:

![](/files/IeLMBn0kKg6xe0UU30bd)

We copy the `raw profile type` output to a file named `test`, and use `xxd` to decode the hex:

![](/files/2jcb1vu6nh7OGRfQl1yA)

This is an `SQLite3` database. First, we'll see how the databse is created:

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

We have found the credentials for `emily` (`emily:abigchonkyboi123`)

![](/files/C0f2Jx2S260u05gjz2iG)

The credentials work for SSH.

### Phase 2 - privelege escalation

First, we upload `pspy64` to the system for information. For this, we'll use the `python3 http.server` module:

![](/files/rjK0fe1bPH5yPn8IYCZZ)

We upload it to the target machine:

![](/files/d2qtVKC18CG2wH43Ls9B)

Then, we can check what's running on the system using `pspy64`:

![](/files/089UVYXb77sq0NxqRCbI)

malwarescan.sh:

![](/files/e34bfqxHRNfxzjAlYCLZ)

<details>

<summary>Full code + added comments</summary>

```
#!/bin/bash
blacklist=("Executable script" "Microsoft executable")
# Monitors the "shrunk/" directory, waiting for a file to be created to activate.
/usr/bin/inotifywait -m -e create /var/www/pilgrimage.htb/shrunk/ | while read FILE; do
        filename="/var/www/pilgrimage.htb/shrunk/$(/usr/bin/echo "$FILE" | /usr/bin/tail -n 1 | /usr/bin/sed -n -e 's/^.*CREATE //p')"
        #runs the vulnerable versoin of binwalk on the file within "shrunk/"
        binout="$(/usr/local/bin/binwalk -e "$filename")"
        for banned in "${blacklist[@]}"; do
                if [[ "$binout" == *"$banned"* ]]; then
                        /usr/bin/rm "$filename"
                        break
                fi
        done
done

```

</details>

The code monitors the `shrunk/` directory of the website, activating when a new file appears. When it activates, it pipes the output into the next command;\
In this command, the original filename is extracted.\
Then, `binwalk`  is ran un the file, where the output is scanned for some keywords.

We notice the file will run `binwalk` as root, so let's check the version:

![](/files/Mjm8r2CCITTxY9diumcZ)

After a bit of googling, we find that this `binwalk` version is vulnerable to an RCE exploit:

{% embed url="<https://www.exploit-db.com/exploits/51249>" %}

Because the code will run any new file in the `shrunk/` directory through `binwalk` , we only need to create an image with the payload inside of the directory to get our reverse shell back.

### Exploitation

We copy the code locally, and save it as `binwalk_exploit.py` . Then we give it any image file as input, our HackTheBox VPN IP address, and the listening port.

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

Before we upload the shell, we open a listener on the port we specified earlier:

![](/files/IsFNQdZxfxIpJFgOBGPF)

To upload the image, we use the `python3 http.server` module, in the same directory as the image we created:

![](/files/cPtaK0uOGqTOA4C5iW4J)

Then, we upload the image to the machine:

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

And we get a reverse shell back, as root:

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


---

# Agent Instructions: 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:

```
GET https://eduw.gitbook.io/writeups/hackthebox/pilgrimage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
