# Researching Polymorphic Images for XSS on Google Scholar

DevFeed: [Researching Polymorphic Images for XSS on Google Scholar](<https://devfeed.tech/articles/researching-polymorphic-images-for-xss-on-google-scholar-92000.md>)

Original publisher: [Read original article](<https://blog.doyensec.com/2020/04/30/polymorphic-images-for-xss.html>)

Published: 2020-04-29T22:00:00Z

Content type: article

Language: en

Sources: [Doyensec](<https://devfeed.tech/sources/doyensec.md>)

Topics: [XSS](<https://devfeed.tech/topics/xss.md>), [Image processing](<https://devfeed.tech/topics/image-processing.md>), [Image](<https://devfeed.tech/topics/image.md>), [web graphics](<https://devfeed.tech/topics/web-graphics.md>), [Single-page application (SPA)](<https://devfeed.tech/topics/spa.md>)

Tags: [auditing](<https://devfeed.tech/tags/auditing.md>), [automation](<https://devfeed.tech/tags/automation.md>), [bypass](<https://devfeed.tech/tags/bypass.md>), [csp](<https://devfeed.tech/tags/csp.md>), [doyensec](<https://devfeed.tech/tags/doyensec.md>), [doyensecurity](<https://devfeed.tech/tags/doyensecurity.md>), [exiftool](<https://devfeed.tech/tags/exiftool.md>), [exploit](<https://devfeed.tech/tags/exploit.md>), [exploitation](<https://devfeed.tech/tags/exploitation.md>), [google](<https://devfeed.tech/tags/google.md>), [hacking](<https://devfeed.tech/tags/hacking.md>), [image-processing](<https://devfeed.tech/tags/image-processing.md>), [imagemagick](<https://devfeed.tech/tags/imagemagick.md>), [images](<https://devfeed.tech/tags/images.md>), [infosec](<https://devfeed.tech/tags/infosec.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [jpeg](<https://devfeed.tech/tags/jpeg.md>), [lets](<https://devfeed.tech/tags/lets.md>), [libraries](<https://devfeed.tech/tags/libraries.md>), [location](<https://devfeed.tech/tags/location.md>), [metadata](<https://devfeed.tech/tags/metadata.md>), [offensive](<https://devfeed.tech/tags/offensive.md>), [payload](<https://devfeed.tech/tags/payload.md>), [pentest](<https://devfeed.tech/tags/pentest.md>), [pentester](<https://devfeed.tech/tags/pentester.md>), [reverse-engineering](<https://devfeed.tech/tags/reverse-engineering.md>), [scholar](<https://devfeed.tech/tags/scholar.md>), [security](<https://devfeed.tech/tags/security.md>), [techniques](<https://devfeed.tech/tags/techniques.md>), [upload](<https://devfeed.tech/tags/upload.md>), [vulnerability](<https://devfeed.tech/tags/vulnerability.md>), [xss](<https://devfeed.tech/tags/xss.md>)

## AI overview

The excerpt describes how polymorphic images could preserve XSS payloads through Google Scholar's image processing, despite metadata stripping and re-encoding. It tests common image libraries and outlines two approaches: embedding payloads in metadata, which may survive when EXIF fields are retained but is lost in some conversions, and placing payloads in image data, whose survival depends on transformations. Google Scholar produced JPGs, so the PNG technique was not applicable; for JPGs, the author found a byte pattern that preserved initial ECS bytes through processing. The excerpt notes that results vary by library and transformation, and that some techniques may also conceal web shells or JavaScript content.

## Source excerpt

A few months ago I came across a curious design pattern on Google Scholar. Multiple screens of the web application were fetched and rendered using a combination of location.hash parameters and XHR to retrieve the supposed templating snippets from a relative URI, rendering them on the page unescaped. This is not dangerous per se, unless the platform lets users upload arbitrary content and serve it from the same origin, which unfortunately Google Scholar does, given its image upload functionality. While any penetration tester worth her salt would deem the exploitation of the issue trivial, Scholar's image processing backend was applying different transformations to the uploaded images (i.e. stripping metadata and reprocessing the picture). When reporting the vulnerability, Google's VRP team did not consider the upload of a polymorphic image carrying a valid XSS payload possible, and instead requested a PoC||GTFO. Given the age of this technique, I first went through all past "well-known" techniques to generate polymorphic pictures, and then developed a test suite to investigate the behavior of some of the most popular libraries for image processing (i.e. Imagemagick, GraphicsMagick, Libvips). This effort led to the discovery of some interesting caveats. Some of these methods can also be used to conceal web shells or Javascript content to bypass "self" CSP directives. Payload in EXIF The easiest approach is to embed our payload in the metadata of the image. In the case of JPEG/JFIF, these pieces of metadata are stored in application-specific markers (called APPX), but they are not taken into account by the majority of image libraries. Exiftool is a popular tool to edit those entries, but you may find that in some cases the characters will get entity-escaped, so I resorted to inserting them manually. In the hope of Google's Scholar preserving some whitelisted EXIFs, I created an image having 1.2k common EXIF tags, including CIPA standard and non-standard tags. While tha