溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

AndroidManifest.xml中含蓋的安全問題詳解

發(fā)布時間:2020-10-26 04:00:09 來源:腳本之家 閱讀:252 作者:<h1>samli 欄目:移動開發(fā)

0x00 關(guān)于AndroidManifest.xml

AndroidManifest.xml 是每個android程序中必須的文件。它位于整個項目的根目錄,Manifest文件提供有關(guān)應(yīng)用程序到Android系統(tǒng)的基本信息,系統(tǒng)必須具有該信息才能運(yùn)行任何應(yīng)用程序的代碼。換句話說APP是跑在Android系統(tǒng)上,既然要跑在其上,就必須提供信息給Android System,這些信息就存在AndroidManifest中。AndroidManifest.xml 存放在 app/src/main/ 目錄下。在反編譯APK文件后,其文件是以亂碼格式存在,需要進(jìn)行轉(zhuǎn)換才能正常查看。

AndroidManifest.xml的主要功能

  1. 命名應(yīng)用程序Java包,軟件包名稱作為應(yīng)用程序的唯一標(biāo)識符;
  2. 描述了應(yīng)用程序的組件,其中包括構(gòu)成應(yīng)用程序的Activity,Service,Broadcast Receiver和Content Provider;它還命名實現(xiàn)每個組件并發(fā)布其功能的類,例如Intent可以處理的消息。這些聲明通知Android系統(tǒng)的組件及其可以啟動的條件;
  3. 決定哪些processes主持application;
  4. 宣告這個App有哪些權(quán)限,它聲明應(yīng)用程序必須擁有的權(quán)限才能訪問API的受保護(hù)部分并與其他應(yīng)用程序交互。它還聲明其他人為了與應(yīng)用程序的組件交互而需要的權(quán)限; 5.它列出了Instrumentation在應(yīng)用程序運(yùn)行時提供概要分析和其他信息的類。這些聲明僅在應(yīng)用程序正在開發(fā)中才會存在,并在應(yīng)用程序發(fā)布之前被刪除; 6.它聲明了應(yīng)用程序需要的最低級別的Android API; 7.它列出了應(yīng)用程序必須鏈接的庫。
<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mwr.example.sieve">
 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 <uses-permission android:name="android.permission.INTERNET"/>
 <permission android:label="Allows reading of the Key in Sieve" android:name="com.mwr.example.sieve.READ_KEYS" android:protectionLevel="dangerous"/>
 <permission android:label="Allows editing of the Key in Sieve" android:name="com.mwr.example.sieve.WRITE_KEYS" android:protectionLevel="dangerous"/>
 <application android:allowBackup="true" android:debuggable="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
 <activity android:clearTaskOnLaunch="true" android:excludeFromRecents="true" android:exported="true" android:finishOnTaskLaunch="true" android:label="@string/title_activity_file_select" android:name=".FileSelectActivity"/>
 <activity android:excludeFromRecents="true" android:label="@string/app_name" android:launchMode="singleTask" android:name=".MainLoginActivity" android:windowSoftInputMode="adjustResize|stateVisible">
 <intent-filter>
 <action android:name="android.intent.action.MAIN"/>
 <category android:name="android.intent.category.LAUNCHER"/>
 </intent-filter>
 </activity>
 <activity android:clearTaskOnLaunch="true" android:excludeFromRecents="true" android:exported="true" android:finishOnTaskLaunch="true" android:label="@string/title_activity_pwlist" android:name=".PWList"/>
 <activity android:clearTaskOnLaunch="true" android:excludeFromRecents="true" android:finishOnTaskLaunch="true" android:label="@string/title_activity_settings" android:name=".SettingsActivity"/>
 <activity android:clearTaskOnLaunch="true" android:excludeFromRecents="true" android:finishOnTaskLaunch="true" android:label="@string/title_activity_add_entry" android:name=".AddEntryActivity"/>
 <activity android:clearTaskOnLaunch="true" android:excludeFromRecents="true" android:finishOnTaskLaunch="true" android:label="@string/title_activity_short_login" android:name=".ShortLoginActivity"/>
 <activity android:clearTaskOnLaunch="true" android:excludeFromRecents="true" android:finishOnTaskLaunch="true" android:label="@string/title_activity_welcome" android:name=".WelcomeActivity"/>
 <activity android:clearTaskOnLaunch="true" android:excludeFromRecents="true" android:finishOnTaskLaunch="true" android:label="@string/title_activity_pin" android:name=".PINActivity"/>
 <service android:exported="true" android:name=".AuthService" android:process=":remote"/>
 <service android:exported="true" android:name=".CryptoService" android:process=":remote"/>
 <provider android:authorities="com.mwr.example.sieve.DBContentProvider" android:exported="true" android:multiprocess="true" android:name=".DBContentProvider">
 <path-permission android:path="/Keys" android:readPermission="com.mwr.example.sieve.READ_KEYS" android:writePermission="com.mwr.example.sieve.WRITE_KEYS"/>
 </provider>
 <provider android:authorities="com.mwr.example.sieve.FileBackupProvider" android:exported="true" android:multiprocess="true" android:name=".FileBackupProvider"/>
 </application>
</manifest>

0x01 AndroidManifest.xml風(fēng)險點分析

1、allowBackup設(shè)置風(fēng)險

Android API Level 8 (Android 2.1)及其以上Android系統(tǒng)提供了為應(yīng)用程序數(shù)據(jù)的備份和恢復(fù)功能,此功能的開關(guān)決定于該應(yīng)用程序中 AndroidManifest.xml 文件中的 allowBackup 屬性值,其屬性值默認(rèn)是 true。當(dāng)allowBackup的屬性值沒有顯示設(shè)置為false時,攻擊者可通過 adb backup 和 adb restore 來進(jìn)行對應(yīng)用數(shù)據(jù)的備份和恢復(fù),從而可能獲取明文存儲的用戶的敏感信息。

android:allowBackup=["true" | "false"]

$ adb backup -nosystem -noshared -apk -f com.example.demo
$ adb restore com.example.demo
  • -nosystem表示不備份系統(tǒng)應(yīng)用
  • -noshared表示不備份應(yīng)用存儲在SD中的數(shù)據(jù)
  • -apk表示備份應(yīng)用APK安裝包
  • -f表示備份的.ab文件路徑和文件名,最后是要備份應(yīng)用的packageName
  • restore是恢復(fù)備份的數(shù)據(jù)

2、debuggable設(shè)置風(fēng)險

該屬性用于指定應(yīng)用程序是否能夠被調(diào)試,即使是以用戶模式運(yùn)行在設(shè)備上的時候,如果設(shè)置為true,則可以被調(diào)試;但是現(xiàn)在Android版本均默認(rèn)debuggable的屬性值為false,所以建議使用默認(rèn)配置。

android:debuggable=["true" | "false"]

3、組件導(dǎo)出風(fēng)險

四大組件

  • Activity
  • Broadcast Receive
  • Service
  • Content Provider

可導(dǎo)出的組件能被第三方APP任意調(diào)用,導(dǎo)致敏感信息泄露,并可能被利用于繞過認(rèn)證、惡意代碼注入、sql注入、拒絕服務(wù)等攻擊;

Activity中exported的默認(rèn)值

  • 沒有intent filter時,默認(rèn)為false
  • 有intent filter時,默認(rèn)為true

而intent filter標(biāo)簽代表是主Activity,而每個APP都會有一個主Activity,所以當(dāng)應(yīng)用的Activity不必要導(dǎo)出時,或者配置了intent filter標(biāo)簽,建議顯示設(shè)置android:exported="false"。如果組件必須要導(dǎo)出給其他應(yīng)用使用,建議對組件進(jìn)行權(quán)限控制。

Broadcast Receive和Service的默認(rèn)值都跟Activity的一樣。

Content Provider中exported的默認(rèn)值

當(dāng)minSdkVersion或者targetSdkVersion小于16時,默認(rèn)為true 大于17時,默認(rèn)為false

4、自定義權(quán)限風(fēng)險

在Android系統(tǒng)的安全模型中,應(yīng)用程序在默認(rèn)的情況下不可以執(zhí)行任何對其他應(yīng)用程序、系統(tǒng)或用戶帶來負(fù)面影響的操作。如果應(yīng)用需要執(zhí)行某些操作,就需要聲明使用這個操作對應(yīng)的權(quán)限,也就是在AndroidManifest.xml文件中添加<uses-permission>標(biāo)記,當(dāng)然也可以自定義屬于自己的permission。但是如果權(quán)限控制不當(dāng),那么就可能導(dǎo)致各種越權(quán)等安全問題。

<uses-permission android:name="android.permission.INTERNET"/>
<permission android:label="Allows reading of the Key in Sieve" android:name="com.mwr.example.sieve.READ_KEYS" android:protectionLevel="dangerous"/>
android:protectionLevel=["normal" | "dangerous" | "signature" | "signatureOrSystem"]
  1. normal:這是最低風(fēng)險的權(quán)限,如果應(yīng)用聲明了此權(quán)限,系統(tǒng)直接默認(rèn)該應(yīng)用有此權(quán)限,也不會提示安裝應(yīng)用的用戶授權(quán);
  2. dangerous:系統(tǒng)在安裝此類權(quán)限聲明的應(yīng)用時會提示用戶,但是所有APP都能訪問和共享此權(quán)限;
  3. signature:這種權(quán)限級別叫做高級權(quán)限或者系統(tǒng)權(quán)限,只有當(dāng)發(fā)請求的應(yīng)用和接收此請求的應(yīng)用使用同一簽名文件,并且聲明了該權(quán)限才會授權(quán),并且是默認(rèn)授權(quán),不會提示用戶授權(quán)
  4. signatureOrSystem:這種權(quán)限應(yīng)該盡量避免使用,偏向系統(tǒng)級

0x02 AndroidManifest.xml結(jié)構(gòu)

<?xmlversion="1.0"encoding="utf-8"?>
 
<manifest>
 <application>
 <activity>
 <intent-filter>
 <action/>
 <category/>
 </intent-filter>
 </activity>
 <activity-alias>
 <intent-filter></intent-filter>
 <meta-data/>
 </activity-alias>
 <service>
 <intent-filter></intent-filter>
 <meta-data/>
 </service>
 <receiver>
 <intent-filter></intent-filter>
 <meta-data/>
 </receiver>
 <provider>
 <grant-uri-permission/>
 <meta-data/>
 </provider>
 <uses-library/>
 </application>
 <uses-permission/>
 <permission/>
 <permission-tree/>
 <permission-group/>
 <instrumentation/>
 <uses-sdk/>
 <uses-configuration/>
 <uses-feature/>
 <supports-screens/>
</manifest>

0x03 AndroidManifest.xml分節(jié)介紹

1、manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.woody.test"
 android:sharedUserId="string"
 android:sharedUserLabel="string resource"
 android:versionCode="integer"
 android:versionName="string"
 android:installLocation=["auto" | "internalOnly" | "preferExternal"] >
</manifest>

2、application

<application android:allowClearUserData=["true" | "false"]
 android:allowTaskReparenting=["true" | "false"]
 android:backupAgent="string"
 android:debuggable=["true" | "false"]
 android:description="string resource"
 android:enabled=["true" | "false"]
 android:hasCode=["true" | "false"]
 android:icon="drawable resource"
 android:killAfterRestore=["true" | "false"]
 android:label="string resource"
 android:manageSpaceActivity="string"
 android:name="string"
 android:permission="string"
 android:persistent=["true" | "false"]
 android:process="string"
 android:restoreAnyVersion=["true" | "false"]
 android:taskAffinity="string"
 android:theme="resource or theme" >
</application>

3、activity

<activity android:allowTaskReparenting=["true" | "false"]
 android:alwaysRetainTaskState=["true" | "false"]
 android:clearTaskOnLaunch=["true" | "false"]
 android:configChanges=["mcc", "mnc", "locale",
   "touchscreen", "keyboard", "keyboardHidden",
   "navigation", "orientation", "screenLayout",
   "fontScale", "uiMode"]
 android:enabled=["true" | "false"]
 android:excludeFromRecents=["true" | "false"]
 android:exported=["true" | "false"]
 android:finishOnTaskLaunch=["true" | "false"]
 android:icon="drawable resource"
 android:label="string resource"
 android:launchMode=["multiple" | "singleTop" |
  "singleTask" | "singleInstance"]
 android:multiprocess=["true" | "false"]
 android:name="string"
 android:noHistory=["true" | "false"]
 android:permission="string"
 android:process="string"
 android:screenOrientation=["unspecified" | "user" | "behind" |
   "landscape" | "portrait" |
   "sensor" | "nosensor"]
 android:stateNotNeeded=["true" | "false"]
 android:taskAffinity="string"
 android:theme="resource or theme"
 android:windowSoftInputMode=["stateUnspecified",
   "stateUnchanged", "stateHidden",
   "stateAlwaysHidden", "stateVisible",
   "stateAlwaysVisible", "adjustUnspecified",
   "adjustResize", "adjustPan"] > 
</activity>

4、intent-filter

<intent-filter android:icon="drawable resource"
 android:label="string resource"
 android:priority="integer" >
<action />
<category />
<data />
</intent-filter>

5、meta-data

<meta-data android:name="string"
  android:resource="resource specification"
  android:value="string"/>

6、activity-alias

<activity-alias android:enabled=["true" | "false"]
  android:exported=["true" | "false"]
  android:icon="drawable resource"
  android:label="string resource"
  android:name="string"
  android:permission="string"
  android:targetActivity="string">
 
<intent-filter/>
<meta-data/>
</activity-alias>

7、service

<service android:enabled=["true" | "false"]
android:exported[="true" | "false"]
android:icon="drawable resource"
android:label="string resource"
android:name="string"
android:permission="string"
android:process="string">
</service>

8、receiver

9、provider

<provider android:authorities="list"
android:enabled=["true" | "false"]
android:exported=["true" | "false"]
android:grantUriPermissions=["true" | "false"]
android:icon="drawable resource"
android:initOrder="integer"
android:label="string resource"
android:multiprocess=["true" | "false"]
android:name="string"
android:permission="string"
android:process="string"
android:readPermission="string"
android:syncable=["true" | "false"]
android:writePermission="string">
<grant-uri-permission/>
<meta-data/>
</provider>

10、uses-library 11、supports-screens

<supports-screens android:smallScreens=["true" | "false"]
   android:normalScreens=["true" | "false"]
   android:largeScreens=["true" | "false"]
   android:anyDensity=["true" | "false"] />

12、uses-configuration和uses-feature

<uses-configuration android:reqFiveWayNav=["true" | "false"]
   android:reqHardKeyboard=["true" | "false"]
   android:reqKeyboardType=["undefined" | "nokeys" | "qwerty" | "twelvekey"]
   android:reqNavigation=["undefined" | "nonav" | "dpad" | "trackball" | "wheel"]
   android:reqTouchScreen=["undefined" | "notouch" | "stylus" | "finger"] />
 
<uses-feature android:glEsVersion="integer"
  android:name="string"
  android:required=["true" | "false"] />

13、uses-sdk

<uses-sdk android:minSdkVersion="integer"
  android:targetSdkVersion="integer"
  android:maxSdkVersion="integer"/>

14、instrumentation

<instrumentation android:functionalTest=["true" | "false"]
   android:handleProfiling=["true" | "false"]
   android:icon="drawable resource"
   android:label="string resource"
   android:name="string"
   android:targetPackage="string"/>

15、<permission>、<uses-permission>、<permission-tree />、<permission-group />區(qū)別

最常用的當(dāng)屬<uses-permission>,當(dāng)我們需要獲取某個權(quán)限的時候就必須在我們的manifest文件中聲明,此<uses-permission>與<application>同級,具體權(quán)限列表請看此處

通常情況下我們不需要為自己的應(yīng)用程序聲明某個權(quán)限,除非你提供了供其他應(yīng)用程序調(diào)用的代碼或者數(shù)據(jù)。這個時候你才需要使用<permission> 這個標(biāo)簽。很顯然這個標(biāo)簽可以讓我們聲明自己的權(quán)限。比如:

<permission android:name="com.teleca.project.MY_SECURITY" . . . />

那么在activity中就可以聲明該自定義權(quán)限了,如:

<application . . .>
 <activity android:name="XXX" . . . >
   android:permission="com.teleca.project.MY_SECURITY"> </activity>
 </application>

當(dāng)然自己聲明的permission也不能隨意的使用,還是需要使用<uses-permission>來聲明你需要該權(quán)限<permission-group> 就是聲明一個標(biāo)簽,該標(biāo)簽代表了一組permissions,而<permission-tree>是為一組permissions聲明了一個namespace。這兩個標(biāo)簽可以看之前的系列文章。

到此這篇關(guān)于AndroidManifest.xml中含蓋的安全問題的文章就介紹到這了,更多相關(guān)AndroidManifest.xml中含蓋的安全問題內(nèi)容請搜索億速云以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持億速云!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI