Chapter 4
Parser exploitation and remote code execution
ImageTragick, ExifTool metadata execution, Zip Slip, and PHP phar deserialization.
Sometimes your upload passes every check because it really is a valid image or PDF. The trouble starts a second later, when a background worker opens those bytes with an old C library to resize a thumbnail or strip metadata.
Two parser bugs worth remembering
Section titled “Two parser bugs worth remembering”Both of these happened on real production stacks that thought they only accepted harmless images.
ImageTragick command injection
Section titled “ImageTragick command injection”In 2016, researchers discovered delegate command injection in ImageMagick, tracked as CVE-2016-3714. When ImageMagick parsed files with specific delegate directives, it passed unsanitized text to shell commands.
push graphic-contextviewbox 0 0 640 480fill 'url(https://example.com/"|id")'pop graphic-contextAn attacker uploaded this payload as an .mvg file or inside a disguised .jpg.
When the server generated a thumbnail, ImageMagick executed the shell command.
ExifTool DjVu parsing flaw
Section titled “ExifTool DjVu parsing flaw”In 2021, CVE-2021-22204 revealed arbitrary code execution in ExifTool during DjVu format parsing. A crafted JPEG image containing DjVu metadata executed commands when ExifTool extracted metadata. This vulnerability affected GitLab instances through attachment processing, leading to mass server compromises under CVE-2021-22205. The root issue was an unpatched dependency in a pipeline that processed user images.
Target library inventory
Section titled “Target library inventory”Identify every library in the processing chain to search for documented CVEs.
| Processing task | Common software components | Typical vulnerability classes |
|---|---|---|
| Thumbnail generation | ImageMagick, GraphicsMagick, libvips | Command injection, heap buffer overflows |
| Metadata extraction | ExifTool, libexif | Parser memory corruption, shell execution |
| Document previews | Ghostscript, LibreOffice, FFmpeg | PostScript sandbox bypasses, code execution |
| Malware scanning | ClamAV | Archive extraction bugs, denial of service |
| Document pipelines | Apache POI, PDFBox | XML entity expansion, memory exhaustion |
Archive vulnerabilities
Section titled “Archive vulnerabilities”Zip archives are structured protocols containing path metadata. When applications accept archives, specialized attack vectors become available.
Zip Slip arbitrary file write
Section titled “Zip Slip arbitrary file write”The Zip Slip flaw occurs when an extractor writes files without verifying target path boundaries. An archive can contain file entries with directory traversal characters.
../../../../../../var/www/html/shell.phpIf the extractor concatenates this path directly to an output folder, it writes outside the intended directory.
This enables attackers to overwrite system configurations or place a web shell inside webroot.
Tools such as evilarc generate these traversal entries.
Denial of service with compression bombs
Section titled “Denial of service with compression bombs”A compression bomb, such as 42.zip, expands from a few kilobytes into petabytes of uncompressed data.
If an application decompresses archives without byte limits, storage and memory exhaust quickly.
In authorized security testing, report compression bomb risks as an architectural observation without detonating the payload.
Nested archives
Section titled “Nested archives”Attackers nest multiple layers of archives to evade antivirus scanning engines. Some security scanners inspect only the first archive layer, allowing nested payloads to pass uninspected.
PHP phar deserialization
Section titled “PHP phar deserialization”PHP supports stream wrappers, including the phar:// wrapper for PHP archives.
When any filesystem function accesses a phar archive, PHP deserializes the archive metadata automatically.
If an application permits image uploads and subsequently calls functions like file_exists on user input, deserialization occurs.
Tools like phpggc generate gadget chains for popular frameworks.
- Generate a serialized payload using
phpggc. - Convert the payload into a valid image polyglot.
- Upload the file through the avatar upload form.
- Trigger a backend filesystem call that uses the
phar://wrapper on the uploaded path.
This mechanism was the core vulnerability in the 2019 Instagram remote code execution bug bounty finding. A profile picture upload provided the storage foundation for the deserialization chain.
Media transcoders and server-side request forgery
Section titled “Media transcoders and server-side request forgery”Video and audio uploads often pass through a transcoder such as FFmpeg. The transcoder reads a container file and converts it to another format. Some container formats can reference external resources by URL or by file path. A crafted playlist or manifest can make the transcoder fetch an internal address. This turns a media upload into a server-side request forgery primitive.
The classic case is an HLS playlist uploaded where the server expects a video. The playlist lists segment URLs, and the transcoder fetches each one. Point a segment at an internal address and read the response from the rendered output.
#EXTM3U#EXT-X-MEDIA-SEQUENCE:0#EXTINF:10.0,http://169.254.169.254/latest/meta-data/iam/security-credentials/#EXT-X-ENDLISTSome builds also honor a file:// segment and read local files into the output.
Test both the external URL path and the local file path.
Stop once one internal response proves the server fetched your address.
Decompression and pixel bombs
Section titled “Decompression and pixel bombs”A parser can be forced to allocate huge memory from a tiny input. Two file shapes cause this, and both are denial of service findings.
A decompression bomb is a small archive or image that expands to a vast size. A nested archive or a highly compressed image can exhaust memory on open.
A pixel flood is an image with a small file size but enormous declared dimensions.
A header that claims 64000 x 64000 pixels forces a large buffer during decode.
Report these as resource exhaustion, not code execution. Prove the effect with one request that spikes memory or stalls the worker, then stop.
Next, Chapter 5 covers second-order injection, where a safe-looking file still detonates later.
File UploadFor authorized testing only.