AndroidManifest.xml中含盖的安全问题详解中含盖的安全问题详解
主要介绍了AndroidManifest.xml中含盖的安全问题,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考
下
0x00 关于关于AndroidManifest.xml
AndroidManifest.xml 是每个android程序中必须的文件。它位于整个项目的根目录,Manifest文件提供有关应用程序到Android系统的基本信息,系统必须具有该信息才能运行任何应用程
序的代码。换句话说APP是跑在Android系统上,既然要跑在其上,就必须提供信息给Android System,这些信息就存在AndroidManifest中。AndroidManifest.xml 存放在 app/src/main/ 目录
下。在反编译APK文件后,其文件是以乱码格式存在,需要进行转换才能正常查看。
AndroidManifest.xml的主要功能的主要功能
1. 命名应用程序Java包,软件包名称作为应用程序的唯一标识符;
2. 描述了应用程序的组件,其中包括构成应用程序的Activity,Service,Broadcast Receiver和Content Provider;它还命名实现每个组件并发布其功能的类,例如Intent可以处理的消
息。这些声明通知Android系统的组件及其可以启动的条件;
3. 决定哪些processes主持application;
4. 宣告这个App有哪些权限,它声明应用程序必须拥有的权限才能访问API的受保护部分并与其他应用程序交互。它还声明其他人为了与应用程序的组件交互而需要的权限; 5.它列出
了Instrumentation在应用程序运行时提供概要分析和其他信息的类。这些声明仅在应用程序正在开发中才会存在,并在应用程序发布之前被删除; 6.它声明了应用程序需要的最低级
别的Android API; 7.它列出了应用程序必须链接的库。
<?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风险点分析风险点分析
1、allowBackup设置风险
Android API Level 8 (Android 2.1)及其以上Android系统提供了为应用程序数据的备份和恢复功能,此功能的开关决定于该应用程序中 AndroidManifest.xml 文件中的 allowBackup 属
性值,其属性值默认是 true。当allowBackup的属性值没有显示设置为false时,攻击者可通过 adb backup 和 adb restore 来进行对应用数据的备份和恢复,从而可能获取明文存储的用户
的敏感信息。
android:allowBackup=["true" | "false"]
$ adb backup -nosystem -noshared -apk -f com.example.demo
$ adb restore com.example.demo
-nosystem表示不备份系统应用
-noshared表示不备份应用存储在SD中的数据
-apk表示备份应用APK安装包
-f表示备份的.ab文件路径和文件名,最后是要备份应用的packageName
restore是恢复备份的数据
2、、debuggable设置风险设置风险
该属性用于指定应用程序是否能够被调试,即使是以用户模式运行在设备上的时候,如果设置为true,则可以被调试;但是现在Android版本均默认debuggable的属性值为false,所以建
议使用默认配置。
android:debuggable=["true" | "false"]
3、组件导出风险、组件导出风险
四大组件
Activity
Broadcast Receive
Service
Content Provider
可导出的组件能被第三方APP任意调用,导致敏感信息泄露,并可能被利用于绕过认证、恶意代码注入、sql注入、拒绝服务等攻击;
Activity中exported的默认值
没有intent filter时,默认为false
有intent filter时,默认为true
而intent filter标签代表是主Activity,而每个APP都会有一个主Activity,所以当应用的Activity不必要导出时,或者配置了intent filter标签,建议显示设置android:exported="false"。如果组
件必须要导出给其他应用使用,建议对组件进行权限控制。
Broadcast Receive和Service的默认值都跟Activity的一样。
Content Provider中exported的默认值
当minSdkVersion或者targetSdkVersion小于16时,默认为true 大于17时,默认为false
4、自定义权限风险
在Android系统的安全模型中,应用程序在默认的情况下不可以执行任何对其他应用程序、系统或用户带来负面影响的操作。如果应用需要执行某些操作,就需要声明使用这个操作对应
的权限,也就是在AndroidManifest.xml文件中添加<uses-permission>标记,当然也可以自定义属于自己的permission。但是如果权限控制不当,那么就可能导致各种越权等安全问题。
<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"/>