Skip to content
Mobile Write-up Advanced

Exploit (and Fix) Android "Master Key"

Android's package verification used a Java zip reader that kept only the last duplicate entry, while the runtime loader used a C zip reader that kept the first, so an attacker could add a second entry for a file such as classes.dex or AndroidManifest.xml and have it verified under the original signature but loaded instead. This allowed modifying an APK's code or manifest without breaking its cryptographic signature, potentially granting the modified app the system permissions of the original signer.

saurik.com

Published on saurik.com

Assuming you enjoy this article, I encourage you to read the next one in the series: Android Bug Superior to Master Key.

The author, on saurik.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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the Java zip verifier and the native C zip loader handled duplicate file names differently: the verifier kept the last entry while the loader used the first.

Impact

An attacker could modify an APK's code or manifest without breaking its signature, potentially gaining the permissions of the original signer, including system-level access if the original was signed with a platform key; however, Google Play blocked such apps and non-Play-Store updating was restricted.

What the attacker needed

Ability to install a modified APK; target APK signed with a privileged key; target APK contains the file to be replaced

The fix

The bug should be fixed by making the verifier and loader agree on which duplicate entry to use, for example by rejecting duplicate file entries in zip archives.

How it was found

  1. Take an existing APK file.
  2. Add a new entry to the zip file for a target file such as classes.dex that comes before the original entry.
  3. The package verifier uses the later duplicate entry and the signature still verifies.
  4. The VM or AssetManager loads the earlier duplicate entry, so the modified content is used.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Android apps are signed with a cryptographic key so the system can tell who made them. This bug let someone add a second copy of a file inside an app package; the signature check looked at one copy while the phone actually ran the other. That meant a tampered app could still appear to be signed by the original developer, even the device manufacturer.

What is Mobile?

Flaws specific to Android and iOS apps: exported components, deep links, WebViews and data left on the device.

Similar reports

View all

Same bug class and techniques, clearest first.

Mobile app vulnerabilities

The lesson behind this report.

Flaws specific to Android and iOS apps: exported components, deep links, WebViews and data left on the device.