leaving our zip undone - virusbulletin.com · apk primer: verification & installation startup...

21
Leaving Our ZIP Undone Gregory Panakkal K7 Computing How to Abuse ZIP to Deliver Malware Apps

Upload: dodang

Post on 31-Aug-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

Leaving Our ZIP Undone

Gregory Panakkal K7 Computing

How to Abuse ZIP to Deliver Malware Apps

Page 2: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

APK Primer: ZIP Format

Page 3: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

APK Primer: Layout

Signing Information

Resources

Dalvik Executable

Manifest – Permissions etc.

Page 4: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

APK Primer: Verification & Installation

Startup Script

Installd Service Zygote Process

System Server

Installer com.android.server.pm

AppDirObServer PackageManagerService

App Installation

Installation Prompt

Installation Progress

Final Installation

Status

[Installation Process] Add to Queue

Get Install Location Req Installd Process

Create App Dir / Perm Extract Dex to Cache Dir

Change System Metadata

Page 5: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

APK Primer: Verification & Installation

APK Verification APK Installation

Adios!

Hello.

Page 6: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

MasterKey Vulnerability (#8219321)

Multiple classes.dex! I’ll

pick the last.

I’ll pick the first one I saw. Supposed to be

only one.

It’s like I’ve been ripped apart

Page 7: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

Negative ExtraData (#9695860)

‘U’ Wot ?

I’ll stick to the spec

Oh no! Java just tore through my

eye…

LFH File Name

(“classes.dex”) Extra Field File Data

(Clean classes.dex)

LFH File Name

(“classes.dex”) Extra Field

(Clean classes.dex) File Data

(Bad classes.dex)

“classes. dex \r035\0

Page 8: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

CDH LFH FileNameLen (#9950697) Java just took my head off… Data Pos = LFH Pos + CDH

FileNameLen + LFH ExtraDataLen

Data Pos = LFH Pos + LFH FileNameLen + LFH ExtraDataLen

Page 9: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

APK: Compression Methods

STORE

DEFLATE

Page 10: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

APK: Lost in Translation (C++/Java) Android 4.4+

If Method==Stored RawDataCopy(…)

Else InflateAndCopy(…)

Android 4.4+

If Method==Stored RawDataCopy(…)

Else InflateAndCopy(…)

Android 4.3 and below

If Method==Stored RawDataCopy(…)

Else InflateAndCopy(…)

Android 4.3 and below

If Method==Deflate InflateAndCopy(…)

Else RawDataCopy(…)

I’m having the last laugh here!

Page 11: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

AV Scanning Bypass: Crafted APK Test Results

AntiVirus Strict Checks

Android Relaxed Checks

Page 12: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

AV Scanning Bypass: Structural

Analysis of Original APK Original: Droidsheep_v15_DetectCheck.apk

Page 13: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

AV Scanning Bypass: Structural

Analysis of Crafted APK (Android 4.4+) Crafted: Droidsheep_v15_Crafted_44.apk Java C/C++

If Method==Stored

RawDataCopy(…)

Else

InflateAndCopy(…)

Page 14: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

AV Scanning Bypass: Structural

Analysis of Crafted APK (<=Android 4.3) Crafted: Droidsheep_v15_Crafted_43.apk

Page 15: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

AV Scanning Bypass: Structural

Analysis of Crafted APK (<=Android 4.3) Crafted: Droidsheep_v15_Crafted_43.apk

STORE

Page 16: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

AV Scanning Bypass: Structural

Analysis of Crafted APK (<=Android 4.3) Crafted: Droidsheep_v15_Crafted_43.apk

C/C++

If Method==Stored

RawDataCopy(…)

Else

InflateAndCopy(…)

Java

If Method==Deflate

InflateAndCopy(…)

Else

RawDataCopy(…)

Page 17: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

AV Scanning Bypass - Mitigation

• Suggested Fix (For Android OS Developers)

– Android OS can place a more strict check on the compression method fields. (Issue #69184)

• Suggested Fix (For Antivirus Vendors)

– Heuristically flag files with unsupported compression method

– Extract files based on Android OS assumptions

Page 18: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

Chameleon ZIP

Page 19: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

Chameleon ZIP

Page 20: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

Zipping it Up

• ZIP Format – flexible & versatile. Continuing format abuse expected.

• Crafted APK – Antivirus products (Windows & Android) affected equally.

– IEEE Taggant for APKs – Actively discussed

• Chameleon ZIP – Possible effect on automation systems not evaluated.

Page 21: Leaving Our ZIP Undone - virusbulletin.com · APK Primer: Verification & Installation Startup Script Installd Service Zygote Process System Server Installer com.android.server.pm

Thank You!