[+] Author: evi1m0#sec.ly.com
[+] Team: n0tr00t security team
[+] From: http://www.n0tr00t.com
[+] Create: 2017-01-09
编写过 Chrome 扩展的开发人员都应该清楚在 crx 后缀的包中, manifest.json 配置清单文件提供了这个扩展的重要信息,crx 后缀文件可以直接使用 unzip 解压,Windows 下的安装后解压的路径在:
C:\Users\Administrator\AppData\Local\Google\Chrome\User Data\Default\Extensions
,MacOS 在:cd ~/Library/Application\ Support/Google/Chrome/Default/Extensions
,其中 manifest.json 的样例:
➜ 0.7.0_0 cat manifest.json
{
"background": {
"scripts": [ "background.js" ]
},
"content_scripts": [ {
"all_frames": true,
"js": [ "content.js" ],
"matches": [ "http://*/*", "https://*/*", "ftp://*/*", "file:///*" ],
"run_at": "document_end"
} ],
"description": "Validates and makes JSON documents easy to read. Open source.",
"homepage_url": "https://github.com/teocci/JSONView-for-Chrome",
"icons": {
"128": "assets/images/jsonview128.png",
"16": "assets/images/jsonview16.png",
"48": "assets/images/jsonview48.png"
},
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApA/pG/flimvWWAeUelHGaQ+IJajQm01JkfK0EYOJPyfsdTkHLwD3Aw16N3zuFkmwz09DcGDT+ehww7GSpW7RpbX5kHrovsqyHXtwt+a2Sp8bYFFdpRPj3+HG6366kNkwttDHMtsDkwuKaBtrQofQe5Ud9mKu9h1FDPwc2Qql9vNtvOqKFhV+EOD0vD2QlliB6sKCteu4nYBlFEkh6pYWRaXdAYSKYdE1SYIuQzE3dk11+KCaAC1T6GffL3sia8n5brVX7Qd+XtXyBzuM54w5e3STwK7uLMhLGDIzHoTcldzWUUflfwuI86VQIFBxPbvXJKqFFFno+ZHs/S+Ra2SPmQIDAQAB",
"manifest_version": 2,
"minimum_chrome_version": "21",
"name": "JSON Viewer",
"permissions": [ "clipboardWrite", "http://*/", "contextMenus", "https://*/", "ftp://*/" ],
"short_name": "JSONViewer",
"update_url": "https://clients2.google.com/service/update2/crx",
"version": "0.7.0",
"web_accessible_resources": [ "assets/options.html", "assets/csseditor.html", "assets/css/jsonview.css", "assets/css/jsonview-core.css", "assets/css/content_error.css", "assets/images/options.png", "assets/images/close_icon.gif", "assets/images/error.gif" ]
}
可以看到关于这个扩展的 content_scripts, desc, homepage, icons 等等配置信息,其中 manifest_version 字段标明现在的 rule 为 2.0 版本,在 2012 年 Chrome 便将 1.0 manifest.json 配置版本的扩展禁止新建在应用市场中,但允许更新,直到 2014 年彻底禁用所有的 version 1.0 版本扩展/应用并更新至 2.0,其中一大部分原因是由于新版规则上安全性的提升。
在多年前的 ChromeExtensions 探测中我们可以直接探测静态资源文件来判断是否存在,在上面的更新变动中可以看到,如果访问资源则必须在 web_accessible_resources 中声明 LIST (可以使用通配符),拿 json-view 举例:
"web_accessible_resources": [ "assets/options.html", "assets/csseditor.html", "assets/css/jsonview.css", "assets/css/jsonview-core.css", "assets/css/content_error.css", "assets/images/options.png", "assets/images/close_icon.gif", "assets/images/error.gif" ]
访问他们资源的 URL 格式如下:
'chrome-extension://' + id + web_accessible_resources
在测试的过程中我们发现大量的扩展禁止了 iframe 内嵌访问,这里我们可以使用 script 加载页面的差异化来判断是否存在文件:
<script src="chrome-extension://aimiinbnnkboelefkjlenlgimcabobli/assets/options.html" onload="alert('json-view!')" onerror="alert(':(')"></script>
我们编写了爬虫获取整个谷歌商店中的扩展应用(id, name, starts, users, category, url),分类如下:
'ext/10-blogging',
'ext/15-by-google',
'ext/12-shopping',
'ext/11-web-development',
'ext/1-communication',
'ext/7-productivity',
'ext/38-search-tools',
'ext/13-sports',
'ext/22-accessibility',
'ext/6-news',
'ext/14-fun',
'ext/28-photos'
截至 2017年初 谷歌商店扩展应用总数量为 42658 ,我们将这些 crx 全部进行下载分析其 manifest.json 的编写规则,发现 12032 个扩展可以探测,在之后的实际测试过程中也发现探测应用的成功率为 1/3 ~ 1/4 ,比较客观,保存的 JSON 格式如下:
{"web_accessible_resources": ["19.png", "48.png", "i/4000.png"], "name": "Facepad for Facebook\u2122", "stars": 497, "id": "cgaknhmchnjaphondjciheacngggiclo", "url": "https://chrome.google.com/webstore/detail/facepad-for-facebook/cgaknhmchnjaphondjciheacngggiclo", "category": "ext/10-blogging", "users": "11,686"},
{"web_accessible_resources": ["reload.js"], "name": "Refresh for Twitter", "stars": 184, "id": "hdpiilkeoldobfomlhipnnfanmgfllmp", "url": "https://chrome.google.com/webstore/detail/refresh-for-twitter/hdpiilkeoldobfomlhipnnfanmgfllmp", "category": "ext/10-blogging", "users": "31,796"},
{"web_accessible_resources": ["main.css", "lstr.js", "script.js", "images/close.png", "images/back.png", "images/icon19.png", "images/play.png", "images/stop.png", "images/prev.png", "images/down.png", "images/next.png", "images/delete.png", "classes/GIFWorker.js"], "name": "MakeGIF Video Capture", "stars": 309, "id": "cnhdjbfjheoohmhpakglckehdcgfffbl", "url": "https://chrome.google.com/webstore/detail/makegif-video-capture/cnhdjbfjheoohmhpakglckehdcgfffbl", "category": "ext/10-blogging", "users": "55,360"},
{"web_accessible_resources": ["js/move.js"], "name": "Postagens Megafilmes 2.1", "stars": 0, "id": "ekennogbnkdbgejohplipgcneekoaanp", "url": "https://chrome.google.com/webstore/detail/postagens-megafilmes-21/ekennogbnkdbgejohplipgcneekoaanp", "category": "ext/10-blogging", "users": "2,408"},
...
通过编写脚本可以加载并探测本地扩展是否存在,虽然需要触发大量的请求来探测,但由于是访问本地资源其速度仍然可以接受,我们过滤出 users 1000 以上的扩展来进行筛选探测( testing 函数动态创建并删除不成功的 dom 探测节点):
http://server.n0tr00t.com/chrome/ext_probe.html
...
// json data parse
$.get("ext1000up.json" + "?_=" + new Date().valueOf(), function(ext){
for (let n in ext.data) {
var id = ext.data[n].id;
var name = ext.data[n].name;
var war = ext.data[n].web_accessible_resources;
var curl = ext.data[n].url;
testing(id, name, war, curl);
}
$('#loading').remove();
})
...