Android 安全之 WebViewUXSS 漏洞

1,170 阅读3分钟

0X01 前言

XSS是我们比较熟悉的一种攻击方式,包括存储型XSS、反射型XSS、DOM XSS等,但UXSS(通用型XSS)另外一种不同的漏洞类型,主要体现在漏洞的载体和影响范围上。

XSS问题源于某一个WEB站点或应用存在安全问题,但受同源策略的约束,攻击者只能访问存在漏洞的站点的回话信息,无法访问其他域的回话信息。

UXSS则主要源于浏览器或浏览器扩展程序的安全缺陷,不需要网站本身存在漏洞也可以触发漏洞,攻击者可以获取到浏览器打开和缓存的所有页面(不同域)的会话信息,因此UXSS漏洞的杀伤力极强。

由于Google把WebKit移植到了Android上,并将其作为WebView组件封装在SDK中,但一些之前出现在PC版chrome的WebKit漏洞在SDK中并未修复,因此历史的悲剧在android上再一次上演:

查看图片

相关漏洞可以上https://bugs.chromium.org/p/chromium/issues/list搜索。下文介绍几个对应的漏洞。

0X02 CVE-2011-3881

WebKit, as used in Google Chrome before 15.0.874.102 and Android before 4.4, allows remote attackers to bypass the Same Origin Policy and conduct Universal XSS (UXSS) attacks via vectors related to

(1) the DOMWindow::clear function and use of a selection object,

(2) the Object::GetRealNamedPropertyInPrototypeChain function and use of an __proto__ property,

(3) the HTMLPlugInImageElement::allowedToLoadFrameURL function and use of a javascript: URL,

(4) incorrect origins for XSLT-generated documents in the XSLTProcessor::createDocumentFromSource function, and

(5) improper handling of synchronous frame loads in the ScriptController::executeIfJavaScriptURL function.

该漏洞主要由于HTMLPlugInImageElement::allowedToLoadFrameURL函数中对Javascript URL地址校验不足,对源检测不全导致的跨域问题:

POC:

    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";

}

0X03 CVE-2014-6041

The Android WebView in Android before 4.4 allows remote attackers to bypass the Same Origin Policy via a crafted attribute containing a \u0000 character, as demonstrated by an onclick="window.open ('\u0000javascript:  sequence to the Android Browser application 4.2.1 or a third-party web browser.

由于很多厂商都是直接使用系统自带的WebView,这将该漏洞的影响进一步扩大化,致使当时很多主流的应用纷纷中枪。

POC:

 a=document.createElement('script');

  a.id='AA';

  a.src='\u0000https://js.stripe.com/v2/';

  document.body.appendChild(a);

  setTimeout(function(){if(typeof(document.getElementById('AA'))!=='undefined'){alert(Stripe);}

else{alert(2);}}, 400);

return false;">

0X04 检测

这类漏洞可以通过动态的方式进行自动化的检测,相关检测样例可以从https://bugs.chromium.org/p/chromium/issues/detail?id=xxx(bugid)中查询到。

0X05 安全建议

前面提到的这些UXSS漏洞都已经在Android 4.4中修复,同时它也提供了自动升级webkit的功能,以便及时修复漏洞。

用户:

1)        尽量采用最新版的Android系统

2)        尽量不要随意点击安全性未知的链接

厂商:

1)        客户端使用onPageStarted (WebView view, String url, Bitmap favicon)方法在跳转前进行跨域判断

2)        使用最新的Webkit内核,但APK的size会变大,并且后续需要跟进Google Webkit官方进行更新。

3)        客户端对iframe object标签属性进行过滤

0X06 参考

http://drops.wooyun.org/tools/3186

https://bugs.chromium.org/p/chromium/issues/list

https://security.tencent.com/index.php/blog/msg/70

手机管家团队推出保护开发者的御安全服务,其中漏洞扫描、应用加固、SO加固均达到业内领先水平,能够帮助企业软件发现潜在漏洞风险、防逆向、防篡改、防二次打包。有需求的团队可以登录御安全官网(http://yaq.qq.com/)试用,或联系我们。

(腾讯御安全团队原创,转载请注明来源)