Data exfiltration and code execution on pocket-image-cache.com via Ghostscript
The image caching service used ImageMagick to convert fetched images, which auto-detected PostScript files and passed them to Ghostscript. An attacker could exploit a Ghostscript sandbox bypass to read local files (like /etc/passwd) and potentially write files, leading to code execution.
Originally disclosed on Mozilla
- Fixed in 5 days
- Paid in 5 days
- Disclosed after 5 days
Created attachment 9038482 postscript exploit
I reported this bug via Hackerone (report id #459637), but I was asked to report it here again:
The pocket-image-cache.com seems to fetch images from upstream servers and converts them via imagemagick to jpeg.
imagemagick autodetects the file format and will pass the file to ghostscript if it is detected as a postscript file. Ghostscript is well known for having plenty of security bypasses for it's "sandbox" (-DSAFER). By using one of the security bypasses by Tavis Ormandy (see [1]) I was able to print out a file from the system into the outputted image. This can obviously be used to exfiltrate data from the server, but also to write files and escalate to code execution.
The relevant parts in the attached file are the lines starting at /.forceput { <<>> <<>> 4 index (ignored) 5 index 5 index .policyprocs 1 get exec pop pop pop pop pop pop pop } def
The rest is just to have some valid ps file that would produce an output at all, I wasn't successful with a more simple ps file.
The example is attached, it's a postscript file renamed to .jpg (otherwise the image cache won't fetch it). Then fetching the file with https://pocket-image-cache.com/direct?url=[url]&resize=w509-nc&f=t will lead to a jpeg that includes content of /etc/passwd.
I strongly recommend that you disable postscript decoding in imagemagick via the policy.xml file as described here: https://www.kb.cert.org/vuls/id/332928/
[1] https://www.openwall.com/lists/oss-security/2018/10/16/2
Impact
Attacker can read and write files on pocket-image-cache.com server and use that to gain remote code execution.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker could read and write files on the server and potentially achieve remote code execution.
What the attacker needed
Ability to host a malicious file; service fetches user-supplied URLs
The fix
The report recommends disabling PostScript decoding in ImageMagick via the policy.xml file.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
The website fetched images from other sites and converted them to JPEG using a tool called ImageMagick. ImageMagick can also handle PostScript files, which are like documents that can contain instructions. The attacker uploaded a malicious PostScript file disguised as an image, and because the tool's security sandbox could be bypassed, the attacker could make the server reveal its own files and even run commands.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.