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 AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)

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 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

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
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 WoodJuan lago vázquez
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
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, Adobeapidays
 
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 DiscoveryTrustArc
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 

Recently uploaded (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

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