Escalating XSS in phantomjs image rendering to SSRF
A user-supplied header parameter was rendered as HTML inside a PhantomJS-generated image, allowing HTML and JavaScript injection. Because PhantomJS loaded the page from a file:// origin, the attacker could use XHR to read local files on the server, including /etc/passwd.
Published on buer.haus
I recently came across across a request on a bounty program that took user input and generated an image for you to download. After a little bit of a journey, I was able to escalate from XSS inside of an image all the way to arbitrary local-file read on the server.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the header value was inserted into the HTML template without encoding, and PhantomJS rendered it from a file:// origin with access to local files.
Impact
An attacker could read arbitrary local files on the server, including sensitive source files and system files.
What the attacker needed
Access to the download endpoint; no account needed
How it was found
- Send a request to the download endpoint with HTML in the header parameter.
- Confirm the HTML renders in the generated image.
- Use an iframe pointing at your own server to identify PhantomJS from the User-Agent.
- Use document.write in an onerror handler to get consistent script execution.
- Load an external script and use XHR to read local files such as /etc/passwd.
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 write-up has not been written yet. The Original tab links to the source.
The site let people put text into a picture it generated, and that text was treated as a web page rather than plain text. The tool making the picture ran on the server and could open files stored on that server, so injected code could read them. This is called cross-site scripting, or XSS: making a site run code you supplied.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.