Pilgrimage

Writeup Hack The Box Pilgrimage

Pilgrimage owned

Port Scanning

First, we perform port scanning on the machine.

Port scanning

We found .git directory on the website.

Exploitation

After we found .git directory, we can dump the directory to get the source code using Git Dumper.

Dumping .git directory

Now, move to Pilgrimage.

Pilgrimage source code.

On index.php, we know that the application using the magick binary to process the image.

Review source code

The "magick" binary itself is ImageMagick, open-source software suite, used for editing and manipulating digital images.

ImageMagick

Search on Google, i found this exploit for ImageMagick 7.1.0-49.

  • https://www.exploit-db.com/exploits/51261

  • https://github.com/voidz0r/CVE-2022-44268

After download the exploit, run this command to generate image with payload.

CVE-2022-44268

Now, upload the image.png to the target.

Upload image with embeded payload

Next, download the converted image, and analyze the converted image using this command:

Get hex value

Convert the hex to text with xxd command.

Convert hex to text

Back to index.php again, we found that the website using sqlite database, stored at /var/db/pilgrimage. We can read the db content using above exploit.

sqlite
Generate payload

Again, upload the image to the website, and download the converted image. Next, get the hex value using xxd command.

Since the hex value is too long, you can save the command into a script.

Inside db.sh, add this line:

Then execute this command.

Now, we can use sqlite database client to read the database content.

Found credentials

Now, we can use the credentials to login into SSH.

Get Low User

Low User

Privilege Escalation

After obtaining low-level user access, we can now upload pspy to the target machine and monitor Linux processes.

Monitor UID 0 proccess

We found a suspicious process with UID 0 (root) that could potentially be our pathway to gaining root access.

This is the content of malwarescan.sh

In summary, this script provides a way to monitor the /var/www/pilgrimage.htb/shrunk/ directory for newly created files using binwalk and automatically deletes files that match specific criteria defined in the blacklist array.

After check the binwalk version, we know that this binwalk is vulnerable to CVE-2022-4510.

Binwalk vulnerable

We can use this script:

Before that, nn our local machine run nc to listen at port 1337.

Upload the script to target machine, and generate the reverse shell payload.

Next, copy the generated image to /var/www/pilgrimage.htb/shrunk/ directory.

Generate payload

Using pspy, we can confirm that the binwalk execute our payload.

Back connect command

Checking our netcat, we received a connection from the target with the root user.

Root

Last updated

Was this helpful?