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

Files in c
Files in cFiles in c
Files in cTanujaA3
 
Dynamic PHP web-application analysis
Dynamic PHP web-application analysisDynamic PHP web-application analysis
Dynamic PHP web-application analysisax330d
 
Learning go for perl programmers
Learning go for perl programmersLearning go for perl programmers
Learning go for perl programmersFred Moyer
 
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
 
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 exampleSunil Patel
 
Pulp 3 - Simpler, Better, More awesome
Pulp 3 - Simpler, Better, More awesomePulp 3 - Simpler, Better, More awesome
Pulp 3 - Simpler, Better, More awesomeDennis Kliban
 
Android Presentation
Android Presentation Android Presentation
Android Presentation Nik Sharma
 
世界のどこかで楽しくRubyでお仕事するために
世界のどこかで楽しくRubyでお仕事するために世界のどこかで楽しくRubyでお仕事するために
世界のどこかで楽しくRubyでお仕事するためにKuniaki Igarashi
 
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 PlatformJim Borden
 
Code tacoma command_line
Code tacoma command_lineCode tacoma command_line
Code tacoma command_lineAndrea Urban
 
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 goDvir Volk
 
Read write program
Read write programRead write program
Read write programAMI AMITO
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from DataMosky Liu
 
Presentation buffer overflow attacks and theircountermeasures
Presentation buffer overflow attacks and theircountermeasuresPresentation buffer overflow attacks and theircountermeasures
Presentation buffer overflow attacks and theircountermeasurestharindunew
 

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

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 ...CODE BLUE
 
Master key system part 10
Master key system   part 10Master key system   part 10
Master key system part 10canei2day
 
Master key system forward
Master key system forwardMaster key system forward
Master key system forwardcanei2day
 
Master key system part 21
Master key system   part 21Master key system   part 21
Master key system part 21canei2day
 
Master key system part 12
Master key system   part 12Master key system   part 12
Master key system part 12canei2day
 
Master key system preface
Master key system prefaceMaster key system preface
Master key system prefacecanei2day
 
Master key system part 09
Master key system   part 09Master key system   part 09
Master key system part 09canei2day
 
Master key system landscape
Master key system landscapeMaster key system landscape
Master key system landscapecanei2day
 
Master key system part 20
Master key system   part 20Master key system   part 20
Master key system part 20canei2day
 
Master key system part 17
Master key system   part 17Master key system   part 17
Master key system part 17canei2day
 

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 CVE-2013-4787 Master Key Vulnerability in Android Zip Implementation

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 AnalysisBGA Cyber Security
 
FRIDA 101 Android
FRIDA 101 AndroidFRIDA 101 Android
FRIDA 101 AndroidTony Thomas
 
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 AndroidVlatko Kosturjak
 
Automated malware analysis
Automated malware analysisAutomated malware analysis
Automated malware analysisIbrahim Baliç
 
Cypherock Assessment (1).pdf
Cypherock Assessment (1).pdfCypherock Assessment (1).pdf
Cypherock Assessment (1).pdfPARNIKA GUPTA
 
API Documentation Workshop tcworld India 2015
API Documentation Workshop tcworld India 2015API Documentation Workshop tcworld India 2015
API Documentation Workshop tcworld India 2015Tom Johnson
 
Fighting Malware Without Antivirus
Fighting Malware Without AntivirusFighting Malware Without Antivirus
Fighting Malware Without AntivirusEnergySec
 
.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 2019Alexandre Borges
 
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 AndroidChris Hardy
 
iOS Application Security
iOS Application SecurityiOS Application Security
iOS Application SecurityEgor Tolstoy
 
C interview question answer 1
C interview question answer 1C interview question answer 1
C interview question answer 1Amit Kapoor
 
iOS Swift application architecture
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architectureRomain Rochegude
 
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 2018Andy Davies
 
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_enSunghun Kim
 
Titanium appcelerator best practices
Titanium appcelerator best practicesTitanium appcelerator best practices
Titanium appcelerator best practicesAlessio Ricco
 
Advanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONAdvanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONLyon Yang
 
Virus Bulletin 2015: Exposing Gatekeeper
Virus Bulletin 2015: Exposing GatekeeperVirus Bulletin 2015: Exposing Gatekeeper
Virus Bulletin 2015: Exposing GatekeeperSynack
 
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 Überblickrenebruns
 

Similar to CVE-2013-4787 Master Key Vulnerability in Android Zip Implementation (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

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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 DevelopmentsTrustArc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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...apidays
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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 WorkerThousandEyes
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 

Recently uploaded (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

CVE-2013-4787 Master Key Vulnerability in Android Zip Implementation

  • 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