Pilgrimage
A HackTheBox Linux machine created by coopertim13 features:
ImageMagick Vulnerability
Binwalk RCE Vulnerability
Reconnaissance
Port Scanning
We found ports 22 and80 open on the target.
$ sudo nmap -n -Pn -oN ports.nmap -p- -sS -T4 --min-rate 1000 -v <IP>Website
We see the website http://pilgrimage.htb hosted on the target, which we shall add to our host file /etc/hosts, and the usage of Nginx from HTTP response.
$ curl -i http://10.129.250.151
HTTP/1.1 301 Moved Permanently
Server: nginx/1.18.0
Date: Sun, 25 Jun 2023 03:52:11 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: http://pilgrimage.htb/We see that the site provides an image-uploading function for registered users.
We registered a user and uploaded an image for testing, and we first found that we could insert content via the parameters message and status=success.


By reviewing the page /dashboard.php, we also found that
the user name
the original image name
will be embedded in the page /dashboard.php.

Git Repository
By fuzzing, we found the path .git exists.
We can then try to use git-dumper to get the Git repository of source codes of the site.
Initial Access
CVE-2022-44268
We found the usage of the executable magick from the repository we fetched
We can see the version of the executable is ImageMagick 7.1.0-49.
It seems that there's a file read vulnerability we could exploit.
Automation
To automate the process, we write the following Python script to read the file content and store it in file result:
We can read the file on the target now.

SQLite File
We've seen that the site stores user's credentials in the SQLite file /var/db/pilgrimage from the source code file login.php.

We thus get the SQLite file content via the Python script.
Using sqlite3, we can dump the table users and get user Emily's password abigchonkyboi123:
We can later use the credentials found to login to the target via SSH.

Privilege Escalation
Malware Scanning
With systemctl, we found a service named malwarescan is running.
We inspected the script malwarescan.sh and found the usage of inotifywait and binwalk.
The binwalk is of version v2.3.2:

CVE-2022-4510
We found the binwalk of version v2.3.2 has a RCE vulnerability CVE-2022-4510 with a public exploit.
We use the exploit to generate a malicious png file and upload the image to the path /var/www/pilgrimage.htb/shrunk/.
The script malwarescan.sh will extract the malicious png file with binwalk and extract the embedded malicious Python code to the binwalk plugins directory; hence we shall get our reverse shell running with root.

Miscellaneous
CVE-2022-4510
From the pull request, we can see the exploit is achieved by abusing the Python function os.path.join to extract malicious binwalk module to the directory .config/binwalk/plugins which can then be executed and thus lead to RCE.
An attacker could craft a malicious PFS file that would cause binwalk to write outside the extraction directory. I attached a proof-of-concept (poc.zip) that, when extracted from the user's home directory, would extract a malicious binwalk module in .config/binwalk/plugins. This malicious plugin would then be loaded and executed by binwalk, leading to RCE.
Refer to the pull request.
Here's the commit fixing the vulnerability.
Last updated