Mobile Application Security Testing ASSES SESSMENT NT & CODE - - PowerPoint PPT Presentation

mobile application security testing
SMART_READER_LITE
LIVE PREVIEW

Mobile Application Security Testing ASSES SESSMENT NT & CODE - - PowerPoint PPT Presentation

Mobile Application Security Testing ASSES SESSMENT NT & CODE REVIEW EW st 2014 Sept. t. 31 31 st Presenters ITAC 2014 Bishop Fox Francis Brown Partner Joe DeMesy Security Associate 2 2 Int ntrodu roductions ctions


slide-1
SLIDE 1

Mobile Application Security Testing

ASSES SESSMENT NT & CODE REVIEW EW

Sept.

  • t. 31

31st

st 2014

slide-2
SLIDE 2

2

Bishop Fox

  • Francis Brown

Partner

  • Joe DeMesy

Security Associate

ITAC 2014

Presenters

2

slide-3
SLIDE 3

3

  • Hi, I’m Fran
  • Partner at Bishop Fox
  • You may remember me

from such hacks as:

  • RFID Thief
  • Diggity Search Tool

Suite

  • Sharepoint

Hacking

FRANCIS CIS BROW OWN

Int ntrodu roductions ctions

slide-4
SLIDE 4

4

  • Hi, I’m Joe
  • Associate at Bishop

Fox

  • I like computers
  • That run a POSIX OS*
  • Phones are cool too
  • Open source projects:
  • Root the Box
  • iSpy

JOE DEME MESY

Int ntrodu roductions ctions

slide-5
SLIDE 5

5

Breaking eaking iOS App pps s –

  • Static analysis
  • Dynamic analysis
  • The future of iOS assessments
  • Protections & counter-measures

Breaking eaking Andro droid id App pps s –

  • Static Analysis
  • Dynamic Analysis
  • Protections & counter-measures

COVERED RED TODAY AY

Age gend nda

slide-6
SLIDE 6

6

Scenar narios ios

  • Online Finance
  • Point of Sale
  • Streaming Media
  • Mobile Device

Management (MDM)

  • Games (cheating, etc.)

OUR TARG RGETS TS

App Se Secur curity ity Requir equiremen ements ts

slide-7
SLIDE 7

THE GO GOLDEN DEN RULE

APPL PLICATION ICATION SECURITY URITY

slide-8
SLIDE 8

8

  • They have complete

control

  • Do not trust them
  • Design applications

and APIs accordingly

EVERY LAST ONE OF ‘EM EM

Us User ers s are e Evil

slide-9
SLIDE 9

IOS OS DYNAMIC YNAMIC ANALYSIS ALYSIS

BREAKING REAKING IOS APPL PLICATIONS ICATIONS

slide-10
SLIDE 10

10 10

  • Mac & Xcode
  • HTTP Proxy
  • Burp Suite Pro ($300)
  • MitM Proxy ($0)
  • ARM Disassembler (optional)
  • Hopper ($90)
  • IDA Pro ($600+)
  • Jailbroken iOS Device
  • SSH access

WHAT T YOU NEED TO START ART

iOS OS Prerequisites erequisites

slide-11
SLIDE 11

INTERCEP TERCEPTIN TING G HTTP TP TRAFFIC AFFIC

BREAKING REAKING MOBIL ILE APPL PLICATIONS ICATIONS

slide-12
SLIDE 12

12 12

PROXY XY SETT TTIN INGS

HT HTTP TP Proxy xy Se Setup tup

slide-13
SLIDE 13

13 13

INTE TERCE RCEPT PTIN ING HTTP TPS TRAFFIC IC

HT HTTP TP Proxy xy Se Setup tup

slide-14
SLIDE 14

14 14

INTE TERCE RCEPT PTIN ING HTTP TPS TRAFFIC IC

HT HTTP TP Proxy xy Se Setup tup

slide-15
SLIDE 15

15 15

Root Intermediate Leaf

CERTIF RTIFICATE ICATE VALI LIDAT DATION ION

Th The e SS SSL L Ce Certi tificat ficate e Ch Chain ain

slide-16
SLIDE 16

16 16

Root Intermediate #1 Intermediate #2 Intermediate #3 Leaf

CERTIF RTIFICATE ICATE VALI LIDAT DATION ION

SS SSL Ce Certi tificat ficate e Ch Chain in

slide-17
SLIDE 17

17 17

ADDING DING A TRUS USTE TED ROOT CERTI RTIFICATE ICATE

Bur urp p Su Suite te Pro

slide-18
SLIDE 18

18 18

ADDING DING A TRUS USTE TED ROOT CERTI RTIFICATE ICATE

Bur urp p Su Suite te Pro

slide-19
SLIDE 19

19 19

ADDING DING A TRUS USTE TED ROOT CERTI RTIFICATE ICATE

Bur urp p Su Suite te Pro

slide-20
SLIDE 20

20 20

ADDING DING A TRUS USTE TED ROOT CERTI RTIFICATE ICATE

Bur urp p Su Suite te Pro

slide-21
SLIDE 21

21 21

INTE TERCE RCEPT PTIN ING HTTP TPS TRAFFIC IC

HT HTTP TP Proxy xy Se Setup tup

slide-22
SLIDE 22

22 22

SECURE URE TRAF AFFIC IC INTE TERCEP CEPTION TION

HT HTTP TP Proxy xy Se Setup tup

slide-23
SLIDE 23

23 23

INTE TERCE RCEPT PTIN ING HTTP TPS TRAFFIC IC

HT HTTP TP Proxy xy Se Setup tup

slide-24
SLIDE 24

24 24

ACME Root ACME Intermediate Application Leaf

NON-BROWS ROWSER R CERTIF TIFICATE ICATE VALID IDATI ATION

ACM CME E Ce Certificate tificate Pinning nning

slide-25
SLIDE 25

IOS OS DYNAMIC YNAMIC ANALYSIS ALYSIS

BREAKING REAKING IOS APPL PLICATIONS ICATIONS

slide-26
SLIDE 26

26 26

  • Signed Binaries
  • Modifying binaries
  • Code injection
  • Runtime modification
  • App Sandbox
  • Debugging
  • Filesystem access

WHY WE NEED TO JAIL ILBRE REAK AK

Op Operating erating Sy System stem Se Secur curity ity Model del

slide-27
SLIDE 27

DEMONST MONSTRATION RATION

CODE INJ NJECTION CTION TECHN HNIQ IQUE UES

slide-28
SLIDE 28

APP P ST STOR ORE E ENCRYP CRYPTION TION

BREAKING REAKING IOS APPL PLICATIONS ICATIONS

slide-29
SLIDE 29

29 29

  • Encrypted Binaries
  • AppStore
  • Clutch
  • Rasticrac
  • No Encryption
  • Provisioned Device
  • Test Flight, etc.

GETT TTIN ING G PLAIN AINTEXT XT BIN INS

Binary nary Enc ncryption yption

slide-30
SLIDE 30

30 30

  • Open source (GitHub)
  • Decrypts iOS applications and repackages them
  • Saves apps in:
  • /var/root/Documents/Cracked
  • Saves apps as .ipa files (they’re just ZIPs)
  • Use: clutch <app name>

DECRY CRYPT PTIN ING G IOS BINARIE INARIES

Cl Clut utch ch Us Usage ge

slide-31
SLIDE 31

31 31

  • Foobar.ipa
  • iTunesMetadata.

plist

  • iTunesArtwork
  • Payload/
  • Foobar.app
  • Foobar

NOT DELI LICIO CIOUS US BEER

Th The e IPA PA Arch chiv ive e Fo Format mat

slide-32
SLIDE 32

32 32

SOFTWARE WARE VERSION ION BUNDLE ID

iTu Tune nes s Metadat etadata

slide-33
SLIDE 33

33 33

I AM IN YOUR BIN INARIES ARIES CHANGING GING YOUR CODE

ARM M Disass sassemb embly ly

slide-34
SLIDE 34

34 34

I AM IN UR BINARIES MODIF’IN UR UR CODE DEZ

ARM M Dec ecompiler

  • mpiler
slide-35
SLIDE 35

35 35

JAIL ILBREAK AK DETEC TECTION TION BYPAS YPASSES

XO XOR is s Not t Ob Obfusc uscation ation

slide-36
SLIDE 36

36 36

ASSEMBLE INSTRUCT TRUCTION ION

Modify difying ing ARM M Ass ssem embly bly

slide-37
SLIDE 37

37 37

PRODU ODUCE CE NEW W EXECUT UTAB ABLE

Modify difying ing ARM M Ass ssem embly bly

slide-38
SLIDE 38

OB OBJECTIVE ECTIVE-C HEADER ADERS

STATI ATIC C ANAL ALYSIS YSIS

slide-39
SLIDE 39

39 39

OBJECTIVE CTIVE-C CLAS ASS INTE TERF RFACES ACES

Cl Class ss Dum ump

slide-40
SLIDE 40

#import <XXUnknownSuperclass.h> // Unknown library @class NSString; @interface XXasymEncryptor : XXUnknownSuperclass { NSString* _publicKeyID; NSString* _privateKeyID; } @property(copy, nonatomic) NSString* privateKeyID; @property(copy, nonatomic) NSString* publicKeyID;

  • (id)privateQueryDict;
  • (id)publicQueryDict;
  • (void)decryptWithPrivateKey;
  • (void)encryptWithPublicKey;
  • (void)KeysPlease;
  • (id)decryptData:(id)data;
  • (id)encryptData:(id)data;
  • (id)init;

@end

slide-41
SLIDE 41

#import <XXUnknownSuperclass.h> // Unknown library @class NSString; @interface XXasymEncryptor : XXUnknownSuperclass { NSString* _publicKeyID; NSString* _privateKeyID; } @property(copy, nonatomic) NSString* privateKeyID; @property(copy, nonatomic) NSString* publicKeyID;

  • (id)privateQueryDict;
  • (id)publicQueryDict;
  • (void)decryptWithPrivateKey;
  • (void)encryptWithPublicKey;
  • (void)KeysPlease;
  • (id)decryptData:(id)data;
  • (id)encryptData:(id)data;
  • (id)init;

@end

Hmmmm…

slide-42
SLIDE 42

MOB OBILE ILE SU SUBSTRAT STRATE

CODE INJ NJECTION CTION TECHN HNIQ IQUE UES

slide-43
SLIDE 43

43 43

MESSAGE AGE PASSIN ING

Th The e Ob Objective ective-C C Runtime untime

iOS App Call Type? Native C Obj C

  • bjc_msgSend

Execute Code

slide-44
SLIDE 44

44 44

MESSAGE AGE PASSIN ING

Th The e Ob Objective ective-C C Runtime untime

iOS App Call Type? Native C Execute Code Obj C

  • bjc_msgSend

Mobile Substrate

(Our code runs here)

slide-45
SLIDE 45

45 45

BYPASSIN PASSING G COMMON ON DETE TECTION CTION METH THOD ODS

Jailbr break eak Det etec ection tion Co Code de

  • Fork()
  • Stat() / Lstat()
  • Cydia
  • /apt/
  • Etc
  • dyld_count()
  • dyld_get_image_name()
slide-46
SLIDE 46

46 46

BYPASSING COMMON DETECTION METHODS

Jailbr break eak Det etec ection tion Co Code de

@class NSString; @interface DeviceSecurity: { BOOL _jbstatus; } @property(assign, nonatomic) BOOL jbstatus; +(BOOL)isJailbroken; @end

slide-47
SLIDE 47

47 47

CLASS AND METHOD HOOKING

Th Theos eos + Lo + Logos gos + Mo + Mobi bile le Su Substrat bstrate

#import "substrate.h" %hook DeviceSecurity

  • (BOOL) isJailbroken {

%log; // Logos built-in logging return NO; // Return FALSE } %end

slide-48
SLIDE 48

48 48

“TRUST ME” BYPASS

Ce Certifi tificat cate e Bypasse passes

#import "substrate.h" /* New function definition */ OSStatus new_SecTrustEvaluate(SecTrustRef trust, SecTrustResultType *result) { *result = kSecTrustResultProceed; return errSecSuccess; } %ctor { /* Hook the function */ MSHookFunction((void *)SecTrustEvaluate, (void *)new_SecTrustEvaluate, (void **)&original_SecTrustEvaluate); }

slide-49
SLIDE 49

CY CYCR CRIPT PT

RUNT NTIM IME MODI DIFICATION ICATION

slide-50
SLIDE 50

50 50

  • JavaScript REPL
  • JavaScript + Cycript

language extensions

  • Objective-C runtime

is merged into the REPL

  • Attach to running

apps

RUNTIM TIME MODI DIFICATION ICATION TECHNIQUE HNIQUES

Cy Cycr cript pt is s Black ck Magic gic

slide-51
SLIDE 51

51 51

ATTACHING TO A PROCESS

Cy Cycr cript pt Basics sics

iphone:~root# cycript –p AlienBlue cy# UIApp @"<UIApplication: 0x8ba2c0>" cy# UIApp.keyWindow.delegate @"<CustomNavigationController: 0x836900>" cy# ui(UIApp.keyWindow, "Foobar") <UILabel: 0x82f0d0; frame = (132 12; 55 21); text = 'Foobar'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x82f190>>

slide-52
SLIDE 52

52 52

ATTACHING TO A PROCESS

Cy Cycr cript pt Basics sics

cy# var label = new Instance(0x82f0d0) @"<UILabel: 0x82f0d0; frame = (132 12; 55 21); text = 'Reddits'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x82f190>>” cy# label.text @"Foobar" cy# label.text = @"Barfoo" @"Barfoo"

slide-53
SLIDE 53

DEMONST MONSTRATION RATION

CYCRIPT RIPT IN ACTIO ION

slide-54
SLIDE 54
slide-55
SLIDE 55

ISP SPY

WELCO LCOME ME TO THE FUTURE RE

slide-56
SLIDE 56

56 56

Under Activ tive Develo lopme pment nt

  • Easy to use Web GUI
  • Class dumps / Instance

tracking

  • Automatic jailbreak-detection

bypasses

  • Automatic SSL certificate

pinning bypasses

  • Re-implemented
  • bjc_msgSend
  • Automatic detection of

vulnerable function calls

  • Easy to use soft-breakpoints
  • More on the way!

YOUR ONE-STOP-SHO HOP P FOR IOS HACKIN ING

iSp Spy Ass ssess essmen ent t Fr Framework mework

slide-57
SLIDE 57

DEMONST MONSTRATION RATION

ISPY IN ACTIO ION

slide-58
SLIDE 58

58 58

GITHUB REPOS

iSp Spy

https://github.com/BishopFox

slide-59
SLIDE 59

CO COUNTER NTER- MEASURES SURES

PROTEC TECTIN TING IOS APPL PLICATIONS ICATIONS

slide-60
SLIDE 60

60 60

1. Security code

1. Assembly and/or C 2. Inline functions 3. Objective-C obfuscation

2. Certificate pinning

1. Whitelist root authorities

3. Change release

  • Metaforic – Commercial
  • AppMinder – BSD Licensed

a) http://appminder.nesolabs.de/

ON DISK K & IN MEMORY RY

Defense efense Aga gains inst t th the e Dark rk Arts ts

slide-61
SLIDE 61

61 61

FREE ‘N EASY OBFUSCATION

AppMind Minder er

slide-62
SLIDE 62

ANDROID DROID APP P SE SECU CURITY RITY

JAVA VA JAVA VA JAVA A JAVA VA JAVA VA JAVA

slide-63
SLIDE 63

63 63

  • Linux / Mac / Windows
  • HTTP Proxy
  • Burp Suite Pro ($300)
  • MitM Proxy ($0)
  • ADT Eclipse Bundle
  • Substrate plug-in
  • Procyon (Java decompiler)
  • Dex2jar (bytecode converter)
  • Rooted Device
  • Cydia Substrate

WHAT T YOU NEED TO START ART

And ndroid

  • id Prerequisites

erequisites

slide-64
SLIDE 64

64 64

  • APKs are signed
  • Not encrypted
  • APK Extractor
  • Direct Download

GOOGLE LE PLAY AY STORE RE

And ndroid

  • id Applicat

ication

  • n Package

ckages

slide-65
SLIDE 65

65 65

GETT TTIN ING G SOURCE CE CODE DE

Dec ecompili

  • mpiling

ng Dalvi lvik Bytecode tecode

slide-66
SLIDE 66

66 66

TWO STEP DECO COMP MPIL ILATI ATION

Dex ex2jar 2jar + + Procyon cyon

$ dex2jar Foobar.apk dex2jar foobar.apk -> Foobar-dex2jar.jar $ procyon –jar Foobar-dex2jar.jar –o src/ Decompiling com/foobar/Parser... Decompiling com/foobar/XMLWriter...

slide-67
SLIDE 67

67 67

SOURCE RCE SORTA TA

Dec ecompiled

  • mpiled And

ndroid

  • id Co

Code de

slide-68
SLIDE 68

DYNAMIC NAMIC ANALYS ALYSIS IS

ON ANDRO DROID ID

slide-69
SLIDE 69

69 69

APPL PLICATION ICATION INSTANTIAT TANTIATION ION

Th The e And ndroi roid d Zy Zygot gote

slide-70
SLIDE 70

70 70

ANDR DROID ID FUNCTION CTION HOOKIN ING

Cy Cydi dia Su Subs bstra tration tion

Method to hook Class to hook

slide-71
SLIDE 71

71 71

ANDR DROID ID FUNCTION CTION HOOKIN ING

Cy Cydi dia Su Subs bstra tration tion

slide-72
SLIDE 72

72 72

ANDR DROID ID FUNCTION CTION HOOKIN ING

Cy Cydi dia Su Subs bstra tration tion

slide-73
SLIDE 73

73 73

ANDR DROID ID FUNCTION CTION HOOKIN ING

Cy Cydi dia Su Subs bstra tration tion

slide-74
SLIDE 74

74 74

ANDR DROID ID FUNCTION CTION HOOKIN ING

Cy Cydi dia Su Subs bstra tration tion

slide-75
SLIDE 75

75 75

ANDR DROID ID FUNCTION CTION HOOKIN ING

Cy Cydi dia Su Subs bstra tration tion

slide-76
SLIDE 76

76 76

ANDR DROID ID FUNCTION CTION HOOKIN ING

Cy Cydi dia Su Subs bstra tration tion

slide-77
SLIDE 77

77 77

RESUL ULTS

And ndroid

  • id LogCa

gCat

Filter by tag

slide-78
SLIDE 78

CO COUNTER NTER- MEASURES SURES

PROTEC TECTIN TING ANDRO DROID ID APPL PLICATIONS ICATIONS

slide-79
SLIDE 79

79 79

  • Security subroutines
  • C / C++ (NDK)
  • Assembly
  • Inline functions
  • Avoid kernel calls if

possible

  • Java bytecode obfuscation
  • Certificate pinning

DREAM AMIN ING G OF ELECT CTRIC RIC SHEEP

And ndroid

  • id Applicat

ication

  • n Se

Secu curity rity

slide-80
SLIDE 80

CO CONCL CLUSION SIONS S

MOBIL ILE APPL PLICAT CATION N SECUR CURITY ITY

slide-81
SLIDE 81

81 81

  • MDM is Mobile

Device Management

  • Client-side enforcement
  • Devices lie

lie

BYOD OD VERTICAL RTICAL CLOUD UD INTE TEGRAT RATION WITH H APT SYNE NERGY RGY

Manag nagemen ement t Not t Se Secur curity ity

slide-82
SLIDE 82

82 82

  • Client-side enforcement
  • Your architecture is probably broken, fix

that instead

  • If the business model dictates that

you must…

  • Perhaps the revenue model

depends on it

  • Perhaps you have to integrate with

legacy code

  • Perhaps there’s some other crazy

reason for on-device security

IN A NUT SHELL …

Mobil bile e Se Secu curity rity

slide-83
SLIDE 83

83 83

YOU CAN TRY, BUT IT IS NOT GOING TO WORK …

Client-side Enforcement

83

slide-84
SLIDE 84

Go Good d Hunt nting ng!

slide-85
SLIDE 85

bishopfox.com contact@bishopfox.com @bishopfox on the Twitters github.com/BishopFox We’re hiring!

Contact Us

slide-86
SLIDE 86
  • Int

nternet ernet Imag age: e: Lob

  • bStoR

toR/Wikimed Wikimedia ia

  • iPhone
  • ne Image:

age: Zach ch Vega ga/Wikim /Wikimedi dia

  • Ha

Hacke ker r Imag age: e: cha hanpipat/FreeD npipat/FreeDigi igitalP talPhotos. hotos.net net

  • Loc
  • ck Ima

mage ge: : Stuart rt Miles les/Fre FreeD eDigi igitalP talPhotos.n hotos.net et

  • Binary

nary Imag age: e: no noegr grana anado do/Flic Flickr kr Creative eative Com

  • mmons

mons

Image age Ci Citati tations

  • ns