Top Banner
UNIVERSITY DRINKING BANS
6

DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Dec 19, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

DECOMPILING ANDROIDGodfrey Nolan

1DevDay 11/5/11

Page 2: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Intro

• What is a Decompiler?• Why Android?• Decompilers • Protect Yourself• Raising the Bar

Page 3: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

SPAM #1

Page 4: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

What is a Decompiler

• Reverse Engineers apps into source code • Many languages can be decompiled

• Java, C#, VB.Net., Visual Basic

• Others can only be disassembled• C, C++, Objective-C

• Java and .Net particularly at risk• Because of JVM and CLR design

• Why use decompilers?• Curiosity, Hacking, Learning, Fair Use

Page 5: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Why Java

• Exploits JVM Design• Originally interpreted not compiled • Lots more symbolic information than binaries• Data and method separation• Simple classfile structure• Very few opcodes

Page 6: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Why Java

Page 7: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Why JavaClassfile {

int magic,

short minor_version,

short major_version,

short constant_pool_count,

cp_info constant_pool[constant_pool_count],

short access_flags,

short this_class,

short super_class,

short interfaces_count,

interface_info interfaces[interfaces_count],

short fields_count,

field_info fields[field_count],

short methods_count,

method_info methods[methods_count],

short attribute_count,

attr_info attributes[attributes_count]

}

Page 8: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Why Java

Page 9: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Why Android

• Client side code• Easy access to apk’s

• Download apk to sd card using Astro File Mgr• Download from xdadevelopers forum• Download using ‘adb pull’ on jailbroken phone

• Nobody is using obfuscation• 1 out of 20 apks downloaded were protected

• Easy to convert apk to Java to decompile

Page 10: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Why Android

Page 11: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Why Android

java –jar dex2jar.jar com.riis.mobile.apkjd-gui com.riis.mobile.apk.dex2jar

Page 12: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Why Android

• Dex file• Different structure• Different opcodes• Register based not stack based• Multiple JVMs on device

Page 13: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Why Android

Page 14: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Why Android

Page 15: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Why not iPhone?

•Objective-C• Compiled not interpreted• Much less information• Fat binaries approach

•Can still be disassembled• strings and otool unix commands• Other tools like IDA Pro

Page 16: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Why Android

• Jailbreak/Root phone • Use Z4Root• Uses RageAgainstTheCage Trojan exploit• Not available on Android Marketplace ;-)

• Using Android SDK platform tools• Turn on USB debugging• Find apk using adb shell• Download using adb pull

Page 17: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Why Android

Page 18: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Why Android

• Even easier is the apk-tool• Install APK-tool

• Download apk • Right click

Page 19: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Decompilers

• Jive• Mocha• JAD• SourceAgain• JD-GUI

Page 20: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Possible Exploits

• Web Service API keys exposed• Database logins• Credit Card information• Fake apps

Page 21: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Possible Exploits

Page 22: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Possible Exploits

Page 23: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Possible Exploits

public static final String USER_NAME = "BC7E9322-0B6B-4C28B4";public static final String PASSWORD = "waZawuzefrabru96ebeb";

Page 24: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Protect Yourself

• Protect code before releasing• Hard to recover once it’s been made available

• Obfuscators• ProGuard• DashO

• Native Code• Use C++ and JNI• 99.99% of Android devices run on ARM processor• Use digital signature checking to protect lib

Page 25: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Protect Yourself

• ProGuard:• Detects and removes unused classes, fields, methods,

and attributes. • Optimizes bytecode and removes unused instructions. • Renames remaining classes, fields, and methods using

short meaningless names. • Preverifies the processed code for Java.

• Enable in default.properties files• proguard.config=proguard.cfg

Page 26: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Protect Yourself

• DashO (basic):• Improvement over ProGuard's naming by using strange

characters and heavily reusing the same names at different scopes.

• Does much more involved control flow obfuscation than ProGuard, reordering code operations to make them very difficult to understand and often breaking decompilers. 

• Supports string encryption to render important string data unreadable to attackers. 

Page 27: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Protect Yourself

• DashO (advanced):• Supports tamper detection, handling, and reporting to

prevent users from changing the compiled code, even while debugging, and to alert you if it happens.

• Can automatically inject Preemptive's Runtime Intelligence functionality for remote error reporting.

Page 28: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Protect Yourself• DashO demo

Page 29: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Protect Yourself - Decompiled

Page 30: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Protect Yourself - ProGuard

Page 31: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Protect Yourself – DashO

Page 32: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Protect Yourself – JNI

jstring Java_com_getPassword(JNIEnv* env, jobject thiz){

char *password = “waZawuzefrabru96ebeb”;

return (*env)->NewStringUTF(env, password);}

Page 33: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Protect Yourself – JNI

Page 34: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Protect Yourself – JNI

Page 35: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Links• http://viralpatel.net/blogs/2009/01/tutorial-java-class-file-fo

rmat-revealed.html• http://code.google.com/p/z4root/• http://code.google.com/p/android-apktool/• http://www.dalvikvm.com/

Page 36: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

Raising the Bar• APK’s are available• Tools are easy to use• Turn on ProGuard• Investigate other obfuscators• Hide keys using JNI• Don’t put sensitive information unencrypted in APKs

Page 37: DECOMPILING ANDROID Godfrey Nolan 1DevDay 11/5/11.

SPAM #2• RIIS LLC

• Southfield, MI

• Clients• Fandango• DTE• Comerica• BCBSM

• Mobile Development• DTE Outage Maps• Broadsoft Front Office Assistant

• Contact Information• [email protected]