Mobile Application Security
Testing and Code Review
19 Nov 2013 – Mobile and Smart Device Security 2013 – Boston, MA Presen sented ted by: Francis Brown & Joe DeMesy Bishop Fox www.bishopfox.com
Mobile Application Security Testing and Code Review 19 Nov 2013 - - PowerPoint PPT Presentation
Mobile Application Security Testing and Code Review 19 Nov 2013 Mobile and Smart Device Security 2013 Boston, MA Presen sented ted by: Francis Brown & Joe DeMesy Bishop Fox www.bishopfox.com Introductions VERY QUICKLY
Testing and Code Review
19 Nov 2013 – Mobile and Smart Device Security 2013 – Boston, MA Presen sented ted by: Francis Brown & Joe DeMesy Bishop Fox www.bishopfox.com
2
VERY QUICKLY…
3
VERY QUICKLY…
4
HACKING MOBILE APPS
king ng iOS Apps
king ng Andro roid id Apps
5
TECHNICAL BRIEF
6
A FEW SCENARIOS
OF APP SECURITY
7
8
EVERY LAST ONE OF ‘EM
9
STATIC ANALYSIS
10
WHAT YOU NEED TO START
11
NETWORK ANALYSIS
12
13
14
15
16
WELL SORT OF…
DECRYPTING BINARIES
17
18
GETTING PLAIN-TEXT BINS
19
/var/root/Documents/Cracked
AWESOME TOOL
20
GETTING PLAIN-TEXT BINS
21
ITUNES METADATA PLIST
22
IOS APP SECURITY
23
DUMPING CLASS INTERFACES
24
ANOTHER AWESOME TOOL
#import <XXUnknownSuperclass.h> // Unknown library @class NSString; @interface XXasymEncryptor : XXUnknownSuperclass { NSString* _publicKeyID; NSString* _privateKeyID; } @property(copy, nonatomic) NSString* privateKeyID; @property(copy, nonatomic) NSString* publicKeyID;
@end
#import <XXUnknownSuperclass.h> // Unknown library @class NSString; @interface XXasymEncryptor : XXUnknownSuperclass { NSString* _publicKeyID; NSString* _privateKeyID; } @property(copy, nonatomic) NSString* privateKeyID; @property(copy, nonatomic) NSString* publicKeyID;
@end
27
#import <Foundation/NSObject.h> @interface FoobarUtil : NSObject { } +(id)getMACUID; +(id)getMACBasedUID; +(id)hashDataToHexString:(char*)hexString length:(int)length; +(id)hashData:(id)data; +(id)iTunesMetadataPlist; +(BOOL)appIsCracked; +(BOOL)deviceIsJailbroken; +(int)deviceCPUFrequency;
28
Me Metho hods
COMMON DETECTION METHODS
29
30
31
32
NO ASSEMBLY REQUIRED
33
34
IOS APP SECURITY
35
XCODE DEVICE CONSOLE
36
WALL OF TEXT
HOOKING MADE EASY
37
38
OBJ-C RUNTIME MANIPULATION
39
iOS App Objective-C Call Native C Call Run Code
40
iOS App Mobile Substrate Objective-C Call Native C Call Run Code
41
IMPLEMENTING THE ATTACK
@class NSString; @interface DeviceSecurity: { BOOL _jbstatus; } @property(assign, nonatomic) BOOL jbstatus; +(BOOL)isJailbroken; @end
42
IMPLEMENTING THE ATTACK
@class NSString; @interface DeviceSecurity: { BOOL _jbstatus; } @property(assign, nonatomic) BOOL jbstatus; +(BOOL)isJailbroken; @end
43
IMPLEMENTING THE ATTACK
#import “substrate.h” %hook DeviceSecurity
%log; // Logos built-in logging return NO; // Return FALSE } %end
44
LOG ALL THE THINGS
$ class-dump-z FoobarApp –H $ ./ios-hooker.py --target Foobar.h –g –s –l [*] Successfully parsed 1 of 1 file(s) [*] Generated 120 function hook(s) [*] Hooks written to: Tweak.xm (8954 bytes) $ make package
GIVES YOU SUPERPOWERS
45
46
language extensions
merged into the REPL
IOS HACKER’S BEST FRIEND
47
ALIEN BLUE APP
48
IOS HACKER’S BEST FRIEND
iphone:~root# cycript –p AlienBlue cy# cy# UIApp @"<UIApplication: 0x8ba2c0>" cy# cy# UIApp.keyWindow.delegate @"<CustomNavigationController: 0x836900>” cy#
49
IOS HACKER’S BEST FRIEND
$ ./slcycript AlienBlue [+] Launching cycript wrapper... [+] Attaching to process AlienBlue with PID 4831 [+] Importing JavaScript helper functions, please wait... cy# cy# ui(UIApp.keyWindow, "Reddits") <UILabel: 0x82f0d0; frame = (132 12; 55 21); text = 'Reddits'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x82f190>>
50
IOS HACKER’S BEST FRIEND
cy# label = new Instance(0x82f0d0) @"<UILabel: 0x82f0d0; frame = (132 12; 55 21); text = 'Reddits'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x82f190>>" cy# cy# label.text @"Reddits" cy# label.text=@"Diggs" @"Diggs" cy#
51
IOS HACKER’S BEST FRIEND
cy# hexdump(label.text,64) " c8 02 20 3f 8c 07 00 06 05 44 69 67 67 73 00 00 .........Diggs.. 12 48 65 6c 76 65 74 69 63 61 4e 65 75 65 2d 42 .HelveticaNeue.B 6f 6c 64 00 00 00 00 00 00 00 00 00 00 00 00 00 old............. c8 02 20 3f ad 07 00 01 b0 2b 84 00 12 00 00 00 ................ " cy# cy# [ label setHidden: 1 ] cy#
52
53
REALISTIC CONSIDERATIONS
54
55
EXPECTO PATRONIS
56
HARDENING YOUR APP
a) http://appminder.nesolabs.de/
57
DEFENSIVE SHELLCODE
58
STATIC ANALYSIS
APK PACKAGES
59
60
EASILY ACQUIRED
61
WHAT YOU NEED TO START
62
BYTECODE REFLECTION
63
MORE THAN JUST INTERFACES
$ dex2jar Foobar.apk dex2jar foobar.apk -> Foobar-dex2jar.jar $ procyon –jar Foobar-dex2jar.jar –o src/ Decompiling com/foobar/Parser... Decompiling com/foobar/XMLWriter... …
64
MORE THAN JUST INTERFACES
65
ANDROID RUNTIME
66
SUBSTRATE FOR ANDROID
67
68
IMPLEMENTING THE ATTACK
69
IMPLEMENTING THE ATTACK
70
IMPLEMENTING THE ATTACK
71
IMPLEMENTING THE ATTACK
72
IMPLEMENTING THE ATTACK
73
IMPLEMENTING THE ATTACK
74
ANOTHER BEAUTIFUL WALL OF TEXT
75
REALISTIC CONSIDERATIONS
76
77
HARDENING YOUR APP
ON MOBILE SECURITY
78
79
BYOD VERTICAL CLOUD INTEGRATION
lie
80
IN A NUTSHELL
81
IF YOU MUST…
security
82
Bishop
http://www.bishopfox.com/
http://foter.com/f/photo/6949896929/479717 0191/