beginners guide to reverse engineering android apps · session id: beginners guide to reverse...

22
SESSION ID: Beginners Guide to Reverse Engineering Android Apps STU-W02B Pau Oliva Fora Sr. Mobile Security Engineer viaForensics @pof

Upload: others

Post on 26-Jul-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

SESSION ID:

Beginners Guide to Reverse Engineering Android Apps

STU-W02B

Pau Oliva Fora Sr. Mobile Security Engineer

viaForensics @pof

Page 2: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Agenda

Anatomy of an Android app

Obtaining our target apps

Getting our hands dirty: reversing the target application

Demo using Santoku Linux

2

Page 3: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

Anatomy of an Android app

Page 4: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Anatomy of an Android app

Simple ZIP file, renamed to “APK” extension

App resources

Signature

Manifest (binary XML)

4

Page 5: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

Obtaining our target apps

Page 6: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Getting the APK from the phone

Backup to SD Card: APKOptic

Astro file manager

etc…

6

Page 7: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Getting the APK from the phone

Using ADB (Android Debug Bridge): adb shell pm list packages

adb pull /data/app/package-name-1.apk

7

Page 8: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Downloading the APK from Google Play

Using unofficial Google Play API: https://github.com/egirault/googleplay-api

Using a web service or browser extension: http://apps.evozi.com/apk-downloader/

http://apify.ifc0nfig.com/static/clients/apk-downloader/

8

Page 9: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Downloading the APK from Google Play

Using unofficial Google Play API: https://github.com/egirault/googleplay-api

Using a web service or browser extension: http://apps.evozi.com/apk-downloader/

http://apify.ifc0nfig.com/static/clients/apk-downloader/

9

Page 10: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

Getting our hands dirty: reversing the target application

Page 11: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Disassembling

DEX Smali

11

Page 12: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Apktool

apktool - https://code.google.com/p/android-apktool/ Multi platform, Apache 2.0 license

Decode resources to original form (and rebuild after modification)

Transforms binary Dalvik bytecode (classes.dex) into Smali source

12

Page 13: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Smali

13

Page 14: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Decompiling – Java Decompiler

DEX JAR JAVA

14

Page 15: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Dex2Jar

dex2jar - https://code.google.com/p/dex2jar/ Multi platform, Apache 2.0 license

Converts Dalvik bytecode (DEX) to java bytecode (JAR)

Allows to use any existing Java decompiler with the resulting JAR file

15

Page 16: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Java Decompilers

Jd-gui - http://jd.benow.ca/ Multi platform

closed source

JAD - http://varaneckas.com/jad/ Multi platform

closed source

Command line

Others: Dare, Mocha, Procyon, …

16

Page 17: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Decompiling – Android (Dalvik) decompiler

DEX JAVA

17

Page 18: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Dalvik Decompilers

Transforming DEX to JAR looses important metadata that the decompiler could use. Pure Dalvik decompilers skip this step, so they produce better output

Unfortunately there are not as many choices for Android decompilers as for Java decompilers: Open Source: Androguard’s DAD - https://code.google.com/p/androguard/

Commercial: JEB - http://www.android-decompiler.com/

Others?

18

Page 19: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

Demo – Santoku

Page 20: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Demo – Santoku Linux

Santoku Linux - https://santoku-linux.com/ Mobile Forensics

Mobile Malware analysis

Mobile application assessment

20

Page 21: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Summary

APK files are ZIP files, can be extracted with any unzip utility

Apktool helps extracting binary resources, and allows repacking

Dex2jar converts Dalvik Bytecode to Java Bytecode

Pure Android decompilers are better

Santoku Linux has all the tools you need to reverse engineering mobile apps

21

Page 22: Beginners Guide to Reverse Engineering Android Apps · SESSION ID: Beginners Guide to Reverse Engineering Android Apps . STU-W02B . Pau Oliva Fora . Sr. Mobile Security Engineer

#RSAC

Q&A | Contact | Feedback

Thanks for listening…

@pof

github.com/poliva

[email protected]

22