SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST)...

59
DEXCALIBUR Hook it yourself ! Geoges-B. MICHEL - SSTIC 2020

Transcript of SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST)...

Page 1: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

DEXCALIBURHook it yourself !

Geoges-B. MICHEL - SSTIC 2020

Page 2: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

WHO AM I ?

GEORGES-B. MICHEL

▸ Working as Reverse Engineer / Software Security evaluator

▸ Author of Dexcalibur

▸ Passionate by reverse & development

▸ Frida addict

aka @FrenchYeti

(Copyright GTO, feat. Onizuka)

Page 3: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INTRO

WHAT IS DEXCALIBUR ?

▸ Dynamic Application Security Testing (DAST) tool

▸ Free and Open-Source Android RE platform

▸ Extensible, comprehensive, multi-user, GUI

▸ Personal project developed on spare time started 2018

▸ Few contributors (4)

Page 4: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INTRO

HOW IS DEXCALIBUR DIFFERENT ?

▸ Deep integration of various reverse engineering technics

▸ New built-in bytecode static analyzer (no smalisca, no androguard)

▸ Custom Smali VM closer to DVM behavior

▸ Update static analysis (corpus) with instrumentation result

▸ Generate instrumentation thanks to static analysis of bytecode

▸ Designed to be able to analyze obfuscated APK with dynamic loading

▸ Usable with vendor applications depending of undocumented OS feature

▸ Multi-user

▸ More ...

Be aware of a maximum of information about device and application at rest or at runtime. Be autonomous.

Page 5: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INTRO

‣ Is "java.lang.StringSplitter" (for example) an internal class ?

STATIC OBFUSCATION, REAL LIFE

Page 6: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INTRO

‣ Is "java.lang.StringSplitter" (for example) an internal class ?

STATIC OBFUSCATION, REAL LIFE

WHAT HAPPENS ?

Page 7: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INTRO

‣ Is "java.lang.StringSplitter" (for example) an internal class ?

STATIC OBFUSCATION, REAL LIFE

WHAT HAPPENS ?

Page 8: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INTRO

... ~ 124 goto(s) ETC ...

STATIC OBFUSCATION, REAL LIFE

Page 9: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INTRO

PACKER CLASS LOADER

DEX LOADER

APP CLASSES & METHODS

Ciphered secondary .dex file

DECIPHER

INVOKE BY REFLECTION

Ciphered JNI lib

DECIPHER & LOAD

Class loaded from the network(URLClassLoader)

DOWNLOAD,DECIPHER & LOAD

JNI FUNCTIONS

DYNAMIC (MULTI-LEVELS) OBFUSCATION, WHAT CAN I HOOK ?

Clear .dex file & JNI libs

NATIVEFUNCTIONS

Page 10: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INTRO

PACKER CLASS LOADER

DEX LOADER

APP CLASSES & METHODS

Ciphered secondary .dex file

DECIPHER

INVOKE BY REFLECTION

Ciphered JNI lib

DECIPHER & LOAD

Class loaded from the network(NetworkClassLoader)

DOWNLOAD,DECIPHER & LOAD

JNI FUNCTIONS

YOU CAN HOOKONLY WHAT YOU SEE

Clear .dex file & JNI libs

NATIVEFUNCTIONS

DYNAMIC (MULTI-LEVELS) OBFUSCATION, WHAT CAN I HOOK ?

Page 11: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INTRO

PACKER CLASS LOADER

DEX LOADER

APP CLASSES & METHODS

Clear .dex file

Ciphered secondary .dex file

DECIPHER

INVOKE BY REFLECTION

Ciphered JNI lib

DECIPHER & LOAD

Class loaded from the network(NetworkClassLoader)

DOWNLOAD,DECIPHER & LOAD

JNI FUNCTIONS

IT REQUIRES SEVERAL HOOKING SESSIONS

Clear .dex file & JNI libs

NATIVEFUNCTIONS

DYNAMIC (MULTI-LEVELS) OBFUSCATION, WHAT CAN I HOOK ?

Page 12: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INTRO

FINALLY, THE "PERFORMANCE PROBLEM"

▸ Common app

▸ + 42 000 classes

▸ + 250 000 methods

▸ + 650 000 calls

▸ + 3M instructions

(Copyright GTO, feat. Onizuka)

Page 13: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

WHAT IS DEXCALIBUR ?

Page 14: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

NOT JUST A TOOLBOX

STATIC BYTECODE ANALYZER

DYNAMIC BYTECODE ANALYZER

FILE IDENTIFIERS & PARSERS

INSPECTORS (PLUGINS) & SEARCH ENGINE

WEB SERVER, DEVICE MANAGER, UI, …

MINIMALIST SMALI VM

IMPROVES ATRUNTIME CONTROLS &

CUSTOMIZE

DEXCALIBUR

DEX DISASSEMBLER Baksmali

INSTRUMENTATION TOOL

WHAT IS DEXCALIBUR ?

binwalkrabin2fileztsd...

Page 15: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

HOW IT WORKS ?

Page 16: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

HOW IT WORKS ?

TARGET DEVICEENROLLMENT

APPLICATIONSTATIC ANALYSIS

RUNTIME ANALYSIS

ANDROIDSTATIC ANALYSIS

INSPECTORS (PLUGINS)

Feedback

listen listenlisten1 time / device

Fully automated , 1-2 min

Page 17: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

HOW IT WORKS ? - ENROLLMENT PHASE

TARGET DEVICEENROLLMENT

APPLICATIONSTATIC ANALYSIS

RUNTIME ANALYSIS

ANDROIDSTATIC ANALYSIS

INSPECTORS (PLUGINS)

listen listenlisten

DEVICEProfiling

DEVICE PROFILE> device ID, ...> all permissions : - vendor - android - app-specific> TEE vendor + client> framework files> arch, SoC, fs, ... FRIDA HELPER

Installfrida

frida-server

OFFICIAL FRIDA REPOSITORY

frida-gadget

1 time / device

Page 18: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

1 time / device

TARGET DEVICEENROLLMENT

APPLICATIONSTATIC ANALYSIS

RUNTIME ANALYSIS

ANDROIDSTATIC ANALYSIS

INSPECTORS (PLUGINS)

listen listenlisten

HOW IT WORKS ? - ANDROID FRAMEWORK ANALYSIS PHASE

STATIC ANALYSIS

3

DEVICE ApplicationGraph DB

Statically built

3 Create APIgraph

BOOT.OAT(Optional)

OAT -> DEX

1

DEODEX/DEX DISASSEMBLER

2

Android frameworkInternals

ANDROID API/STUB ANDROID.JAR

Android standard API

Page 19: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

HOW IT WORKS ? - ANDROID FRAMEWORK ANALYSIS PHASE

click to generate + deploy a hook

Page 20: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

1 time / device

TARGET DEVICEENROLLMENT

APPLICATIONSTATIC ANALYSIS

RUNTIME ANALYSIS

ANDROIDSTATIC ANALYSIS

INSPECTORS (PLUGINS)

listen listenlisten

HOW IT WORKS ? - APPLICATION STATIC ANALYSIS PHASE

Fully automated , 30 sec

Page 21: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

TARGET DEVICEENROLLMENT

APPLICATIONSTATIC ANALYSIS

RUNTIME ANALYSIS

ANDROIDSTATIC ANALYSIS

INSPECTORS (PLUGINS)

listen listenlisten

HOW IT WORKS ? - APPLICATION STATIC ANALYSIS PHASE

UNCOMPRESS APKAPK FILE

DEVICEPull Application data/data/data/xxx …

3

Files identified & categorized:key stores, libs, properties, xml,shared pref, cache, …Undetected / high entropy files are tagged

4

FILE ANALYZER

Parse APK content2

1

Page 22: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

TARGET DEVICEENROLLMENT

APPLICATIONSTATIC ANALYSIS

RUNTIME ANALYSIS

ANDROIDSTATIC ANALYSIS

INSPECTORS (PLUGINS)

listen listenlisten

HOW IT WORKS ? - APPLICATION STATIC ANALYSIS PHASE

UNCOMPRESS APKAPK FILE

STATIC ANALYSIS

2

ApplicationGraph

Statically built

3 Update appgraph

Files identified & categorized:Additional Class or Dex files

DEX DISASSEMBLER

1

Page 23: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

TARGET DEVICEENROLLMENT

APPLICATIONSTATIC ANALYSIS

RUNTIME ANALYSIS

ANDROIDSTATIC ANALYSIS

INSPECTORS (PLUGINS)

listen listenlisten

๏ Heuristics search patterns and request instrumentation

๏ HookManager generate scriptsource code of the hook ...

๏ .. and spawn/attach to application

๏ Intercepted data send back from device to Dexcalibur

๏ Data gathered broadcasted to plugins

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

Fully automated , 1-5 min

1 time / device

Page 24: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

DYNAMIC LOADER

DYNAMIC DEX/CLASS LOADINGREFLECTION

KEY STORE

FILE DETECTION (JKS, BKS, ...)OPEN / GET KEY / ...

FILE SYSTEM

FILE DESCRIPTORS LOOKUP

IO STREAMS

STREAM TRACING

To retrieve file path from stream instance

Get signature of methods :

‣ File.<init>() ‣ File.read*() ‣ File.write*() ‣ ...

Request instrumentationgeneration

STATIC ANALYZER

HOOK MANAGER

RUNNING APP

DEVICE

Page 25: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

STATIC ANALYZER

HOOK MANAGER

RUNNING APP

DEVICE

Page 26: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INSPECTOR "DYNAMIC LOADER"Hook Listeners : - "InMemoryDexClassLoader.load()"- "defineClass" from classes implementing "ClassLoader"

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

STATIC ANALYZER

HOOK MANAGER

RUNNING APP

DEVICE

Page 27: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INSPECTOR "DYNAMIC LOADER"Hook Listeners : - "InMemoryDexClassLoader.load()"- "defineClass" from classes implementing "ClassLoader"

Hook trigged

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

STATIC ANALYZER

HOOK MANAGER

RUNNING APP

DEVICE

Page 28: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INSPECTOR "DYNAMIC LOADER"Hook Listeners : - "InMemoryDexClassLoader.load()"- "defineClass" from classes implementing "ClassLoader"

Hook trigged

Notify hook listeners

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

STATIC ANALYZER

HOOK MANAGER

RUNNING APP

DEVICE

Page 29: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INSPECTOR "DYNAMIC LOADER"Hook Listeners : - "InMemoryDexClassLoader.load()"- "defineClass" from classes implementing "ClassLoader"

Hook trigged

Notify hook listenersEVENTBUS

New Dex bytecode discovered

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

STATIC ANALYZER

HOOK MANAGER

RUNNING APP

DEVICE

Page 30: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INSPECTOR "DYNAMIC LOADER"Hook Listeners : - "InMemoryDexClassLoader.load()"- "defineClass" from classes implementing "ClassLoader"

Hook trigged

Notify hook listenersEVENTBUS

New Dex bytecode discovered

New Dex bytecode discovered

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

STATIC ANALYZER

HOOK MANAGER

RUNNING APP

DEVICE

Page 31: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INSPECTOR "DYNAMIC LOADER"Hook Listeners : - "InMemoryDexClassLoader.load()"- "defineClass" from classes implementing "ClassLoader"

Hook trigged

Notify hook listenersEVENTBUS

New Dex bytecode discovered

New string "blabla" parsed

New Dex bytecode discovered

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

STATIC ANALYZER

HOOK MANAGER

RUNNING APP

DEVICE

Page 32: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INSPECTOR "DYNAMIC LOADER"Hook Listeners : - "InMemoryDexClassLoader.load()"- "defineClass" from classes implementing "ClassLoader"

Hook trigged

Notify hook listenersEVENTBUS

New Dex bytecode discovered

New string "blabla" parsed

INSPECTOR "DATA CLASSIFIER"

Event Listener "disass.string.new" New string "blabla" parsed

New Dex bytecode discovered

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

STATIC ANALYZER

HOOK MANAGER

RUNNING APP

DEVICE

Page 33: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INSPECTOR "DYNAMIC LOADER"Hook Listeners : - "InMemoryDexClassLoader.load()"- "defineClass" from classes implementing "ClassLoader"

Hook trigged

Notify hook listenersEVENTBUS

New Dex bytecode discovered

New string "blabla" parsed

INSPECTOR "DATA CLASSIFIER"

Event Listener "disass.string.new" New string "blabla" parsed

New Dex bytecode discovered

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

STATIC ANALYZER

HOOK MANAGER

RUNNING APP

DEVICE

Page 34: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INSPECTOR "DYNAMIC LOADER"Hook Listeners : - "InMemoryDexClassLoader.load()"- "defineClass" from classes implementing "ClassLoader"

Hook trigged

Notify hook listenersEVENTBUS

New Dex bytecode discovered

New string "blabla" parsed

INSPECTOR "DATA CLASSIFIER"

Event Listener "disass.string.new" New string "blabla" parsed

New Dex bytecode discovered

Tag string "blabla"

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

STATIC ANALYZER

HOOK MANAGER

RUNNING APP

DEVICE

Page 35: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

Page 36: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

CASE #1 AUTOMATING ANALYSIS OF DEX/ODEX/CLASS FILE LOADED DYNAMICALLY

Page 37: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

INSPECTOR

STATIC ANALYZER

HOOK MANAGER

Requests instrumentation for each constructors and some methods

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

Requests all classes ??? satisfying :

ClassLoader

???

extends (directly or not)

Target platform : Android API 25 (Nougat)

Custom class loaders

Page 38: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

HOW IT WORKS ? - RUNTIME ANALYSIS PHASE

ClassLoader

???

extends

Request Result :

Page 39: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

GENERATE HOOK CLASS LOADERS

ANALYZING DEX FILE LOADED DYNAMICALLY

Page 40: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

GENERATE HOOK CLASS LOADERS

ANALYZING DEX FILE LOADED DYNAMICALLY

Page 41: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

ANALYZING DEX FILE LOADED DYNAMICALLY

PARAMS & RETURNS

VALUES

DYNAMIC INSTRUMENTATION

DATA READ/WRITE SECONDARY

DEX & LIBS

STACK TRACERUNTIME CONTEXT

FILE ANALYSIS

LIBS & DEX

CLASS GRAPH

STATIC ANALYSIS

ANDROIDINTERNALS

CALLS

DEX LOADING API INSTRUMENTED

DEXFILE CONSTRUCTORS TRIGGERED

START APP

HOOKS ASK IF DEX FILES ARE ALREADY KNOWN

Dex File already analyzed ?

COPY OR GET DEX FILEANALYZE DEX & UPDATE DB

ANALYZING DEX FILE LOADED DYNAMICALLY

Page 42: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

AFTER 1ST RUN

ANALYZING DEX FILE LOADED DYNAMICALLY

Page 43: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

AFTER 1ST RUN

ANALYZING DEX FILE LOADED DYNAMICALLY

Page 44: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

AFTER 1ST RUN

ANALYZING DEX FILE LOADED DYNAMICALLY

(Copyright GTO, feat. Onizuka)

Page 45: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

CASE #2 DYNAMIC UPDATE OF XREF WITH INVOKED METHODS

Page 46: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

METHOD INVOKED DYNAMICALLY

‣ Method.invoke()

‣ Class.getMethod()

From a static point-of-view, only two methods are called :

Smali code

DYNAMIC UPDATE OF XREF FROM WITH INVOKED METHODS

Page 47: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

DYNAMIC UPDATE OF XREF WITH INVOKED METHODS

GRAPHS

PARAMS & RETURNVALUES

STATIC ANALYSIS

DYNAMIC INSTRUMENTATION

ANDROIDINTERNALS

CALLSSTATIC VALUES

DATA READ/WRITE SECONDARY

DEX & LIBS

STACK TRACERUNTIME CONTEXT

REFLECTION API INSTRUMENTEDSTART APP

HOOK TRIGGERED

HOOK SHOWS STACK TRACE

HOOK GATHERS METHOD INFO

HEURISTIC ENGINE UPDATE DB

DYNAMIC UPDATE OF XREF FROM WITH INVOKED METHODS

Page 48: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

BEFORERUNTIME

AFTER RUNTIME

METHOD INVOKED DYNAMICALLY

DYNAMIC UPDATE OF XREF FROM WITH INVOKED METHODS

Page 49: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

AND MORE ...

Page 50: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

SOME COMMON PROBLEMS

▸ Always TRUE / FALSE predicate

▸ Useless Goto(s)

▸ Implicit exceptions thrown (NPE, IOB, ..)

▸ Wrapped function

▸ ...

BYTECODE SIMPLIFICATION BY PARTIAL EXECUTION

Page 51: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

A- REMOVING USELESS GOTO(S) - BEFOREBYTECODE SIMPLIFICATION BY PARTIAL EXECUTION

Page 52: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

A- REMOVING USELESS GOTO(S) - BEFOREBYTECODE SIMPLIFICATION BY PARTIAL EXECUTION

Page 53: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

A- REMOVING USELESS GOTO(S) - AFTERBYTECODE SIMPLIFICATION BY PARTIAL EXECUTION

Page 54: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

JADX

B- HELP TO DETECT IMPLICIT EXCEPTIONBYTECODE SIMPLIFICATION BY PARTIAL EXECUTION

Page 55: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

JADX

WRONG

Always throws AndroidVerifier exceptionat runtime

B- HELP TO DETECT IMPLICIT EXCEPTIONBYTECODE SIMPLIFICATION BY PARTIAL EXECUTION

Page 56: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

JADX

WRONG

Always throws AndroidVerifier exceptionat runtime

static { HVRQbvhaFlYdeGD("3780b8133459f5a028d742efbcfc7d2d"); throw new AndroidVerifier();}

TRUE PATH

B- HELP TO DETECT IMPLICIT EXCEPTIONBYTECODE SIMPLIFICATION BY PARTIAL EXECUTION

Page 57: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

END

AND FINALLY ... HOW TO INSTALL DEXCALIBUR ?

$ npm install dexcalibur

FROM NPM ...

$ dexcalibur

WITH USER-FRIENDLY UI AND AUTOMATIC INSTALL OF DEPENDENCIES:

Page 58: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

DEXCALIBUR

Thanks

(Copyright GTO, feat. Onizuka)

Page 59: SSTIC 2020 final noanim...INTRO WHAT IS DEXCALIBUR ? Dynamic Application Security Testing (DAST) tool Free and Open-Source Android RE platform Extensible, comprehensive, multi-user,

Q&A