SlideShare a Scribd company logo
1 of 26
Download to read offline
http://www.flickr.com/photos/bcostin/2619263350/

CVE-2013-4787(Master Key Vulnerability) &
Zip implementation of Android
Masata NISHIDA
AVTOKYO2013.5 (16th Feb. 2014)
English Ver.
Who am I?
•

Masata Nishida (西田 雅太)

•

SecureBrain

•

I’m not a malware researcher, I’m just a
software developer.

•

Rubyist

•

@masata_masata
2
Agenda

•

Explanation about CVE-2013-4787 with
source code

•

About Zip implementation of Android

3
CVE-2013-4787
Master Key
Vulnerability

4

http://www.flickr.com/photos/plaisanter/5344873860/
CVE-2013-4787
Master Key Vulnerability

•

Vulnerability in Android OS

•

The Attacker can inject any code into the app without
changing the signature of target application.

⇒ huge impact & user can’t notice this attack.
http://bluebox.com/corporate-blog/bluebox-uncovers-android-master-key/
5
OH CRAP!!

6
Keywords
•

Apk file = Zip file

•

Zip file format

•

Confirming a signature of Apk

7

http://www.flickr.com/photos/mrcam/206628965/
APK File

(Android Application Package)
APK file is Zip file.
It must include executable file for dalvik VM and
manifest file.
classes.dex
sample.apk
(zip file)

DEX file
(Java executable code)

AndroidManifest.xml
manifest file

8
Zip Format
local file header

Local File Header (file infomation)
File Data (compressed data)

File data

local file header

File data

central directory file header
central directory file header

Central Directory File Header
file name, file size,

offset of file data,

compression method…etc

End of central directory record
9
Confirming a signature

•

All applications must be digitally signed.

•

You can’t change any files in the apk
after signing.

•

Android checks the sign when user installs
an new application.

10

http://www.flickr.com/photos/gearys/276917907/
If an apk has duplicated file name entries...

11
APK File

duplicated files

sample.apk
(zip file)

classes.dex
classes.dex

AndroidManifest.xml
AndroidManifest.xml

According to the specification, zip file can
contain duplicated file name entries.
It’s the implementation problem.
12
APK File

duplicated files
classes.dex

sample.apk
(zip file)

bogus file

classes.dex

original file

AndroidManifest.xml

bogus file

AndroidManifest.xml

original file

Inject classes.dex and manifest file into apk,

and install it...
13
You can install the application
includes another code with
original signature!
14
Why?
•

Android OS has a number of zip implementation.
•

checking signature → java.util.zip

•

installing application → C++
•

frameworks/native/libs/utils/ZipFileRO.cpp

•

dalvik/libdex/ZipArchive.cpp

The behavior differences between java
and C++ implementation cause the issue
when an Apk includes duplicate entries.
15
Let’s read source code about parsing central
directory header in zip file.

16

http://www.flickr.com/photos/ajstarks/4196202909/
ZipFileRO & libdex/ZipArchive

•

libdex/ZipArchive is almost the same as ZipFileRO.

•

It parses Central Directory File Header. 

Then it sets the file names into hash table.

17
bool ZipFileRO::parseZipArchive(void)!
{!
:!
:!
const unsigned char* ptr = cdPtr;!
for (int i = 0; i < numEntries; i++) {!
:!
:!
unsigned int fileNameLen, extraLen, commentLen, hash;!

!

fileNameLen = get2LE(ptr + kCDENameLen);!
extraLen = get2LE(ptr + kCDEExtraLen);!
commentLen = get2LE(ptr + kCDECommentLen);!

!

/* add the CDE filename to the hash table */!
hash = computeHash((const char*)ptr + kCDELen, fileNameLen);!
addToHash((const char*)ptr + kCDELen, fileNameLen, hash);!

!

ptr += kCDELen + fileNameLen + extraLen + commentLen;!
:!
:!
}!
:!
:!
}

append file name into hash table
compute hash value with file name
18
ZipFileRO & libdex/ZipArchive
void ZipFileRO::addToHash(const char* str, int strLen, unsigned int
hash)!
{!
int ent = hash & (mHashTableSize-1);!

!

/*!
     * We over-allocate the table, so we're guaranteed to find an empty
slot.!
     */!
while (mHashTable[ent].name != NULL)!
ent = (ent + 1) & (mHashTableSize-1);!

!

mHashTable[ent].name = str;!
mHashTable[ent].nameLen = strLen;!
}

ZipFileRO finds next empty element and sets the
file name into the hash table, if the hash value
is duplicated.

→ use first item.
19
Zip implementation in Java
public class ZipFile implements Closeable, ZipConstants {!

!
!

!
!

!

private final LinkedHashMap<String, ZipEntry> mEntries = new LinkedHashMap<String, ZipEntry>();!
private void readCentralDir() throws IOException {!
!
:!
!
:!
RAFStream rafStream = new RAFStream(raf, centralDirOffset);!
BufferedInputStream bufferedStream = new BufferedInputStream(rafStream, 4096);!
byte[] hdrBuf = new byte[CENHDR]; // Reuse the same buffer for each entry.!
for (int i = 0; i < numEntries; ++i) {!
ZipEntry newEntry = new ZipEntry(hdrBuf, bufferedStream);!
mEntries.put(newEntry.getName(), newEntry);!
}!
}!

}

Java sets zip entries into HashMap. The file names are
used for the key of HashMap.
duplicated file name → overwrite HashMap → use last item
20
…therefore
•

Checking signature → use last item
•

•

use last zip entry

Installing application → use first item
•

use first zip entry

21

http://www.flickr.com/photos/49121171@N00/6831724767/
When you inject
any classes.dex
before the original
in Apk(zip),Android
uses the injected.
http://unsplash.com/post/57711421529/download-by-may-pamintuan

22
Patch
Android security bug 8219321

Fix Java code.

Throw exception when duplicated entry is found.
23
Appendix:Iffy zip implementation in Android
24

http://www.flickr.com/photos/26207806@N00/1315037834/
Zip implementation in Android

•

Android doesn’t check zip file header in
detail when it installs an application.
•

Ignoring encrypt flag.

•

Only deflate and no compressed are
allowed as compression method.

25
26

More Related Content

What's hot

Dynamic PHP web-application analysis
Dynamic PHP web-application analysisDynamic PHP web-application analysis
Dynamic PHP web-application analysis
ax330d
 
Working with file(35,45,46)
Working with file(35,45,46)Working with file(35,45,46)
Working with file(35,45,46)
Dishant Modi
 
Read write program
Read write programRead write program
Read write program
AMI AMITO
 
Presentation buffer overflow attacks and theircountermeasures
Presentation buffer overflow attacks and theircountermeasuresPresentation buffer overflow attacks and theircountermeasures
Presentation buffer overflow attacks and theircountermeasures
tharindunew
 

What's hot (17)

A Tour of Go - Workshop
A Tour of Go - WorkshopA Tour of Go - Workshop
A Tour of Go - Workshop
 
Files in c
Files in cFiles in c
Files in c
 
Dynamic PHP web-application analysis
Dynamic PHP web-application analysisDynamic PHP web-application analysis
Dynamic PHP web-application analysis
 
Learning go for perl programmers
Learning go for perl programmersLearning go for perl programmers
Learning go for perl programmers
 
Working with file(35,45,46)
Working with file(35,45,46)Working with file(35,45,46)
Working with file(35,45,46)
 
Basics of files and its functions with example
Basics of files and its functions with exampleBasics of files and its functions with example
Basics of files and its functions with example
 
Pulp 3 - Simpler, Better, More awesome
Pulp 3 - Simpler, Better, More awesomePulp 3 - Simpler, Better, More awesome
Pulp 3 - Simpler, Better, More awesome
 
Android Presentation
Android Presentation Android Presentation
Android Presentation
 
世界のどこかで楽しくRubyでお仕事するために
世界のどこかで楽しくRubyでお仕事するために世界のどこかで楽しくRubyでお仕事するために
世界のどこかで楽しくRubyでお仕事するために
 
Keep Your Arms and Legs Inside the Platform
Keep Your Arms and Legs Inside the PlatformKeep Your Arms and Legs Inside the Platform
Keep Your Arms and Legs Inside the Platform
 
Code tacoma command_line
Code tacoma command_lineCode tacoma command_line
Code tacoma command_line
 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about go
 
Read write program
Read write programRead write program
Read write program
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from Data
 
Introduction to c part 4
Introduction to c  part  4Introduction to c  part  4
Introduction to c part 4
 
Presentation buffer overflow attacks and theircountermeasures
Presentation buffer overflow attacks and theircountermeasuresPresentation buffer overflow attacks and theircountermeasures
Presentation buffer overflow attacks and theircountermeasures
 
Secure code 3rd_party_libs
Secure code 3rd_party_libsSecure code 3rd_party_libs
Secure code 3rd_party_libs
 

Viewers also liked (11)

Backdoors with the MS Office file encryption master key and a proposal for a ...
Backdoors with the MS Office file encryption master key and a proposal for a ...Backdoors with the MS Office file encryption master key and a proposal for a ...
Backdoors with the MS Office file encryption master key and a proposal for a ...
 
Master key system part 10
Master key system   part 10Master key system   part 10
Master key system part 10
 
Master key system forward
Master key system forwardMaster key system forward
Master key system forward
 
Master key system part 21
Master key system   part 21Master key system   part 21
Master key system part 21
 
Master key system part 12
Master key system   part 12Master key system   part 12
Master key system part 12
 
Master key system preface
Master key system prefaceMaster key system preface
Master key system preface
 
Master key system part 09
Master key system   part 09Master key system   part 09
Master key system part 09
 
Master key system landscape
Master key system landscapeMaster key system landscape
Master key system landscape
 
Master key system part 20
Master key system   part 20Master key system   part 20
Master key system part 20
 
Master key system part 17
Master key system   part 17Master key system   part 17
Master key system part 17
 
The Secret in Nutshell
The Secret in NutshellThe Secret in Nutshell
The Secret in Nutshell
 

Similar to AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)

Cypherock Assessment (1).pdf
Cypherock Assessment (1).pdfCypherock Assessment (1).pdf
Cypherock Assessment (1).pdf
PARNIKA GUPTA
 
C interview question answer 1
C interview question answer 1C interview question answer 1
C interview question answer 1
Amit Kapoor
 
Flash security past_present_future_final_en
Flash security past_present_future_final_enFlash security past_present_future_final_en
Flash security past_present_future_final_en
Sunghun Kim
 
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im ÜberblickEin Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick
renebruns
 

Similar to AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability) (20)

IstSec'14 - İbrahim BALİÇ - Automated Malware Analysis
IstSec'14 - İbrahim BALİÇ -  Automated Malware AnalysisIstSec'14 - İbrahim BALİÇ -  Automated Malware Analysis
IstSec'14 - İbrahim BALİÇ - Automated Malware Analysis
 
FRIDA 101 Android
FRIDA 101 AndroidFRIDA 101 Android
FRIDA 101 Android
 
Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to Android
 
Automated malware analysis
Automated malware analysisAutomated malware analysis
Automated malware analysis
 
Cypherock Assessment (1).pdf
Cypherock Assessment (1).pdfCypherock Assessment (1).pdf
Cypherock Assessment (1).pdf
 
API Documentation Workshop tcworld India 2015
API Documentation Workshop tcworld India 2015API Documentation Workshop tcworld India 2015
API Documentation Workshop tcworld India 2015
 
Fighting Malware Without Antivirus
Fighting Malware Without AntivirusFighting Malware Without Antivirus
Fighting Malware Without Antivirus
 
.NET MALWARE THREAT: INTERNALS AND REVERSING DEF CON USA 2019
.NET MALWARE THREAT: INTERNALS AND REVERSING DEF CON USA 2019.NET MALWARE THREAT: INTERNALS AND REVERSING DEF CON USA 2019
.NET MALWARE THREAT: INTERNALS AND REVERSING DEF CON USA 2019
 
Introduction to MonoTouch and Monodroid/Mono for Android
Introduction to MonoTouch and Monodroid/Mono for AndroidIntroduction to MonoTouch and Monodroid/Mono for Android
Introduction to MonoTouch and Monodroid/Mono for Android
 
iOS Application Security
iOS Application SecurityiOS Application Security
iOS Application Security
 
iOS Application Exploitation
iOS Application ExploitationiOS Application Exploitation
iOS Application Exploitation
 
C interview question answer 1
C interview question answer 1C interview question answer 1
C interview question answer 1
 
iOS Swift application architecture
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architecture
 
Inspecting iOS App Traffic with JavaScript - JSOxford - Jan 2018
Inspecting iOS App Traffic with JavaScript - JSOxford - Jan 2018Inspecting iOS App Traffic with JavaScript - JSOxford - Jan 2018
Inspecting iOS App Traffic with JavaScript - JSOxford - Jan 2018
 
Flash security past_present_future_final_en
Flash security past_present_future_final_enFlash security past_present_future_final_en
Flash security past_present_future_final_en
 
Titanium appcelerator best practices
Titanium appcelerator best practicesTitanium appcelerator best practices
Titanium appcelerator best practices
 
What is c language
What is c languageWhat is c language
What is c language
 
Advanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONAdvanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCON
 
Virus Bulletin 2015: Exposing Gatekeeper
Virus Bulletin 2015: Exposing GatekeeperVirus Bulletin 2015: Exposing Gatekeeper
Virus Bulletin 2015: Exposing Gatekeeper
 
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im ÜberblickEin Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)

  • 1. http://www.flickr.com/photos/bcostin/2619263350/ CVE-2013-4787(Master Key Vulnerability) & Zip implementation of Android Masata NISHIDA AVTOKYO2013.5 (16th Feb. 2014) English Ver.
  • 2. Who am I? • Masata Nishida (西田 雅太) • SecureBrain • I’m not a malware researcher, I’m just a software developer. • Rubyist • @masata_masata 2
  • 3. Agenda • Explanation about CVE-2013-4787 with source code • About Zip implementation of Android 3
  • 5. CVE-2013-4787 Master Key Vulnerability • Vulnerability in Android OS • The Attacker can inject any code into the app without changing the signature of target application. ⇒ huge impact & user can’t notice this attack. http://bluebox.com/corporate-blog/bluebox-uncovers-android-master-key/ 5
  • 7. Keywords • Apk file = Zip file • Zip file format • Confirming a signature of Apk 7 http://www.flickr.com/photos/mrcam/206628965/
  • 8. APK File (Android Application Package) APK file is Zip file. It must include executable file for dalvik VM and manifest file. classes.dex sample.apk (zip file) DEX file (Java executable code) AndroidManifest.xml manifest file 8
  • 9. Zip Format local file header Local File Header (file infomation) File Data (compressed data) File data local file header File data central directory file header central directory file header Central Directory File Header file name, file size,
 offset of file data,
 compression method…etc End of central directory record 9
  • 10. Confirming a signature • All applications must be digitally signed. • You can’t change any files in the apk after signing. • Android checks the sign when user installs an new application. 10 http://www.flickr.com/photos/gearys/276917907/
  • 11. If an apk has duplicated file name entries... 11
  • 12. APK File duplicated files sample.apk (zip file) classes.dex classes.dex AndroidManifest.xml AndroidManifest.xml According to the specification, zip file can contain duplicated file name entries. It’s the implementation problem. 12
  • 13. APK File duplicated files classes.dex sample.apk (zip file) bogus file classes.dex original file AndroidManifest.xml bogus file AndroidManifest.xml original file Inject classes.dex and manifest file into apk,
 and install it... 13
  • 14. You can install the application includes another code with original signature! 14
  • 15. Why? • Android OS has a number of zip implementation. • checking signature → java.util.zip • installing application → C++ • frameworks/native/libs/utils/ZipFileRO.cpp • dalvik/libdex/ZipArchive.cpp The behavior differences between java and C++ implementation cause the issue when an Apk includes duplicate entries. 15
  • 16. Let’s read source code about parsing central directory header in zip file. 16 http://www.flickr.com/photos/ajstarks/4196202909/
  • 17. ZipFileRO & libdex/ZipArchive • libdex/ZipArchive is almost the same as ZipFileRO. • It parses Central Directory File Header. 
 Then it sets the file names into hash table. 17
  • 18. bool ZipFileRO::parseZipArchive(void)! {! :! :! const unsigned char* ptr = cdPtr;! for (int i = 0; i < numEntries; i++) {! :! :! unsigned int fileNameLen, extraLen, commentLen, hash;! ! fileNameLen = get2LE(ptr + kCDENameLen);! extraLen = get2LE(ptr + kCDEExtraLen);! commentLen = get2LE(ptr + kCDECommentLen);! ! /* add the CDE filename to the hash table */! hash = computeHash((const char*)ptr + kCDELen, fileNameLen);! addToHash((const char*)ptr + kCDELen, fileNameLen, hash);! ! ptr += kCDELen + fileNameLen + extraLen + commentLen;! :! :! }! :! :! } append file name into hash table compute hash value with file name 18
  • 19. ZipFileRO & libdex/ZipArchive void ZipFileRO::addToHash(const char* str, int strLen, unsigned int hash)! {! int ent = hash & (mHashTableSize-1);! ! /*!      * We over-allocate the table, so we're guaranteed to find an empty slot.!      */! while (mHashTable[ent].name != NULL)! ent = (ent + 1) & (mHashTableSize-1);! ! mHashTable[ent].name = str;! mHashTable[ent].nameLen = strLen;! } ZipFileRO finds next empty element and sets the file name into the hash table, if the hash value is duplicated.
 → use first item. 19
  • 20. Zip implementation in Java public class ZipFile implements Closeable, ZipConstants {! ! ! ! ! ! private final LinkedHashMap<String, ZipEntry> mEntries = new LinkedHashMap<String, ZipEntry>();! private void readCentralDir() throws IOException {! ! :! ! :! RAFStream rafStream = new RAFStream(raf, centralDirOffset);! BufferedInputStream bufferedStream = new BufferedInputStream(rafStream, 4096);! byte[] hdrBuf = new byte[CENHDR]; // Reuse the same buffer for each entry.! for (int i = 0; i < numEntries; ++i) {! ZipEntry newEntry = new ZipEntry(hdrBuf, bufferedStream);! mEntries.put(newEntry.getName(), newEntry);! }! }! } Java sets zip entries into HashMap. The file names are used for the key of HashMap. duplicated file name → overwrite HashMap → use last item 20
  • 21. …therefore • Checking signature → use last item • • use last zip entry Installing application → use first item • use first zip entry 21 http://www.flickr.com/photos/49121171@N00/6831724767/
  • 22. When you inject any classes.dex before the original in Apk(zip),Android uses the injected. http://unsplash.com/post/57711421529/download-by-may-pamintuan 22
  • 23. Patch Android security bug 8219321 Fix Java code.
 Throw exception when duplicated entry is found. 23
  • 24. Appendix:Iffy zip implementation in Android 24 http://www.flickr.com/photos/26207806@N00/1315037834/
  • 25. Zip implementation in Android • Android doesn’t check zip file header in detail when it installs an application. • Ignoring encrypt flag. • Only deflate and no compressed are allowed as compression method. 25
  • 26. 26