Contents
Introduction
Overview of This Book
How This Book Is Organized
Who Should Read This Book
Tools You Will Need
What's on the Website
Chapter 1 Mobile Application (In)security
The Evolution of Mobile Applications
Mobile Application Security
Summary
Chapter 2 Analyzing iOS Applications
Understanding the Security Model
Understanding iOS Applications
Jailbreaking Explained
Understanding the Data Protection API
Understanding the iOS Keychain
Understanding Touch ID
Reverse Engineering iOS Binaries
Summary
Chapter 3 Attacking iOS Applications
Introduction to Transport Security
Identifying Insecure Storage
Patching iOS Applications with Hopper
Attacking the iOS Runtime
Understanding Interprocess Communication
Attacking Using Injection
Summary
Chapter 4 Identifying iOS Implementation Insecurities
Disclosing Personally Identifiable Information
Identifying Data Leaks
Memory Corruption in iOS Applications
Summary
Chapter 5 Writing Secure iOS Applications
Protecting Data in Your Application
Avoiding Injection Vulnerabilities
Securing Your Application with Binary Protections
Summary
Chapter 6 Analyzing Android Applications
Creating Your First Android Environment
Understanding Android Applications
Understanding the Security Model
Reverse-Engineering Applications
Summary
Chapter 7 Attacking Android Applications
Exposing Security Model Quirks
Attacking Application Components
Accessing Storage and Logging
Misusing Insecure Communications
Exploiting Other Vectors
Additional Testing Techniques
Summary
Chapter 8 Identifying and Exploiting Android Implementation Issues
Reviewing Pre-Installed Applications
Exploiting Devices
Infiltrating User Data
Summary
Chapter 9 Writing Secure Android Applications
Principle of Least Exposure
Essential Security Mechanisms
Advanced Security Mechanisms
Slowing Down a Reverse Engineer
Summary
Chapter 10 Analyzing Windows Phone Applications
Understanding the Security Model
Understanding Windows Phone 8.x Applications
Building a Test Environment
Analyzing Application Binaries
Summary
Chapter 11 Attacking Windows Phone Applications
Analyzing for Data Entry Points
Attacking Transport Security
Attacking WebBrowser and WebView Controls
Identifying Interprocess Communication Vulnerabilities
Attacking XML Parsing
Attacking Databases
Attacking File Handling
Patching .NET Assemblies
Summary
Chapter 12 Identifying Windows Phone Implementation Issues
Identifying Insecure Application Settings Storage
Identifying Data Leaks
Identifying Insecure Data Storage
Insecure Random Number Generation
Insecure Cryptography and Password Use
Identifying Native Code Vulnerabilities
Summary
Chapter 13 Writing Secure Windows Phone Applications
General Security Design Considerations
Storing and Encrypting Data Securely
Secure Random Number Generation
Securing Data in Memory and Wiping Memory
Avoiding SQLite Injection
Implementing Secure Communications
Avoiding Cross-Site Scripting in WebViews and WebBrowser Components
Secure XML Parsing
Clearing Web Cache and Web Cookies
Avoiding Native Code Bugs
Using Exploit Mitigation Features
Summary
Chapter 14 Analyzing BlackBerry Applications
Understanding BlackBerry Legacy
Understanding BlackBerry 10
Understanding the BlackBerry 10 Security Model
BlackBerry 10 Jailbreaking
Using Developer Mode
The BlackBerry 10 Device Simulator
Accessing App Data from a Device
Accessing BAR Files
Looking at Applications
Summary
Chapter 15 Attacking BlackBerry Applications
Traversing Trust Boundaries
Summary
Chapter 16 Identifying BlackBerry Application Issues
Limiting Excessive Permissions
Resolving Data Storage Issues
Checking Data Transmission
Handling Personally Identifiable Information and Privacy
Ensuring Secure Development
Summary
Chapter 17 Writing Secure BlackBerry Applications
Securing BlackBerry OS 7.x and Earlier Legacy Java Applications
Securing BlackBerry 10 Native Applications
Securing BlackBerry 10 Cascades Applications
Securing BlackBerry 10 HTML5 and JavaScript (WebWorks) Applications
Securing Android Applications on BlackBerry 10
Summary
Chapter 18 Cross-Platform Mobile Applications
Introduction to Cross-Platform Mobile Applications
Bridging Native Functionality
Exploring PhoneGap and Apache Cordova
Summary
Title page
Copyright
Dedication
About the Authors
About the Technical Editor
Credits
Acknowledgments
EULA
List of Tables
Chapter 2
Table 2.1
Table 2.2
Table 2.3
Table 2.4
Table 2.5
Table 2.6
Table 2.7
Chapter 6
Table 6.1
Table 6.2
Table 6.3
Table 6.4
Table 6.5
Chapter 7
Table 7.1
Table 7.2
Chapter 9
Table 9.1
List of Illustrations
Chapter 1
Figure 1.1
The incidence of some common mobile application vulnerabilities recently tested by the authors
Figure 1.2
OWASP Top 10 Mobile Risks
Chapter 2
Figure 2.1
The secure boot chain
Figure 2.2
The user sees this privacy prompt when an application tries to access the address book.
Figure 2.3
Users can access Privacy settings if they want to grant access to a resource.
Figure 2.4
The data protection key hierarchy
Figure 2.5
The Mach-O file format
Chapter 3
Figure 3.1
Configuring Burp Suite to listen on all interfaces
Figure 3.2
Configuring your device to use a proxy
Figure 3.3
Capturing cipher suites using Wireshark
Figure 3.4
Installing the Burp certificate on your device
Figure 3.5
Install profile view
Figure 3.6
Snoop-it filesystem monitoring
Figure 3.7
Jailbreak check in sample application
Figure 3.8
Hopper disassembler
Figure 3.9
Locating strings in Hopper
Figure 3.10
Finding references to strings in Hopper
Figure 3.11
Disassembly of the viewDidLoad delegate
Figure 3.12
Pseudo-code view in Hopper
Figure 3.13
Pseudo-code view of clickedButtonAtIndex in Hopper
Figure 3.14
Pseudo-code view of sub_b1fc function in Hopper
Figure 3.15
Modifying an instruction in Hopper
Figure 3.16
Running the example application after bypassing the jailbreak detection
Figure 3.17
A breakdown of an Objective-C interface
Figure 3.18
A breakdown of Swift class
Figure 3.19
Bypassing the Password Manager lock screen
Figure 3.20
Pivoting to internal networks in Kaseya BYOD
Figure 3.21
View of the Snoop-it application
Figure 3.22
The Snoop-it Objective-C classes view
Figure 3.23
Registering a URL scheme in Xcode
Figure 3.24
An app extension can indirectly communicate and share resources with the containing app.
Chapter 4
Figure 4.1
Accessing application snapshots with iExplorer
Figure 4.2
A snapshot can capture a registration page.
Chapter 6
Figure 6.1
From this Android SDK Manager interface you can install SDK platforms and tools.
Figure 6.2
You can customize your emulator configuration. Here is just one example.
Figure 6.3
The main activity of the drozer agent displaying the embedded server toggle.
Figure 6.4
The main activity of the clock application
Figure 6.5
A list of running services on a device and the applications they belong to
Figure 6.6
A simple manifest file showing the general structure
Figure 6.7
The runtime selection activity available on Android 4.4
Figure 6.8
The simplified structure of a zip file containing a single file entry.
Figure 6.9
The required permissions displayed when looking at the permission details on the Twitter application.
Figure 6.10
The prompt displayed by SuperSU to allow an application access to root context.
Figure 6.11
The options available on Cydia Impactor to make use of code-signing bugs to obtain system and root.
Figure 6.12
Graph view showing the disassembly of a DEX file in IDA.
Figure 6.13
Viewing decompiled application code in JD-GUI
Figure 6.14
Viewing decompiled application code in JEB
Figure 6.15
Viewing decompiled application code in Jadx-gui
Chapter 7
Figure 7.1
A high-level overview of various testing perspectives of an Android application
Figure 7.2
The vulnerable Sieve password manager application
Figure 7.3
Exported activity that leads to the disclosure of all accounts within Sieve
Figure 7.4
Device lock screen requiring a password and then this being removed after the exploit is run
Figure 7.5
An illustration of how a toast could be used to perform unintended actions on underlying activities
Figure 7.6
The recent applications being shown on a device
Figure 7.7
Fragment loaded inside the Settings activity that allows the PIN to be changed without providing the existing one
Figure 7.8
Sieve allows the Settings activity to be opened without logging in
Figure 7.9
Finding SQL injection using drozer’s WebContentResolver web interface
Figure 7.10
Call initiated from exploiting a broadcast receiver in com.android.phone
Figure 7.11
Activity started by entering *#*#4636#*#* in the dialer
Figure 7.12
SuperSU prompt requesting permission to run droidwall.sh as root
Figure 7.13
An error in Wireshark when you try to open the generated capture file
Figure 7.14
Loading libencrypt.so into IDA
Figure 7.15
The application backup activity
Figure 7.16
Root Checker displaying that the device is rooted
Figure 7.17
Root Checker now displaying that the device is not rooted
Figure 7.18
The main activity of Cydia Substrate running on an Android device
Figure 7.19
Burp is able to proxy Twitter API traffic after loading Android SSL TrustKiller
Figure 7.20
The configuration available in Introspy
Chapter 8
Figure 8.1
The prompt shown to the user when a device with USB debugging is connected to his computer
Figure 8.2
A screenshot of a Sony Xperia Z2 before and after having the password lock screen removed
Figure 8.3
Showing the Forgot pattern? button and the resulting screen by pressing it
Figure 8.4
The Android Device Manager Lock functionality and the resulting screen of the locked device
Figure 8.5
A Samsung Galaxy S3 device visiting the exploit page and receiving the exploit files
Figure 8.6
Setting up the drozer MitM helper extension for JavaScript injection
Figure 8.7
Burp extension showing that an injection has taken place
Figure 8.8
Setting up the drozer MitM helper extension to replace APKs and then invoke them
Figure 8.9
The prompt shown to the user after a valid response is obtained from the server
Figure 8.10
The configuration of the Custom URI Handler Injection section of the drozer Burp plug-in
Figure 8.11
The drozer exploit page attempting to perform social engineering to get the user to click the reload button
Figure 8.12
A screen recording of capturing the user's lock screen pattern
Chapter 10
Figure 10.1
Windows Phone 8.x chamber architecture
Figure 10.2
Stack frame with cookies
Figure 10.3
: SEH chain
Figure 10.4
Unzipped non-Store XAP package
Figure 10.5
Splash screen for a Samsung Windows Phone 8 device
Figure 10.6
Creating a new WP8 project
Figure 10.7
Application Deployment tool
Figure 10.8
Developer Registration tool
Figure 10.9
Sideloading the Interop Unlock helper app
Figure 10.10
Setting the MaxUnsignedApp registry key
Figure 10.11
Setting the PortalUrlProd registry key
Figure 10.12
Applying the Full Filesystem access hack using SamWP8 tools
Figure 10.13
Browsing the filesystem
Figure 10.14
Home Screen with Spavlin’s MBN Applied
Figure 10.15
Configuration of checkboxes and radio buttons
Figure 10.16
Browsing an app’s Install directory in Explorer
Figure 10.17
Opening a .NET assembly from a device’s filesystem
Chapter 11
Figure 11.1
Viewing XAML files in .NET reflector
Figure 11.2
The proxy settings disabled
Figure 11.3
Proxy settings configured
Figure 11.4
Burp Suite captures web traffic from a Windows Phone device
Figure 11.5
Exporting Burp Suite CA Certificate
Figure 11.6
Installing the certificate onto the device
Figure 11.7
.NET reflector showing XAML pages in a Windows Phone 8 application
Figure 11.8
.NET reflector showing an XAML page’s OnNavigatedTo() implementation
Figure 11.9
The Native Toast Notification Launcher sending a toast message
Figure 11.10
The XAML screen launched after you tap the toast notification
Figure 11.11
Names parsed out from the XML document
Figure 11.12
Out-of-memory exception reported by Visual Studio due to a “billion laughs” attack
Figure 11.13
Result of external entity resolution of the “secret file” in a message box
Figure 11.14
SQLite syntax error
Figure 11.15
EncryptAndSaveData() in .NET reflector
Figure 11.16
Reversed CIL code in .NET reflector and Reflexil
Figure 11.17
Deleting an instruction in Reflexil
Figure 11.18
Modified CIL code after deleting instructions
Figure 11.19
New disassembly for SaveAndEncryptData() after patching the method
Figure 11.20
Editing an existing instruction in Reflexil
Figure 11.21
Patching a method in C#
Chapter 12
Figure 12.1
Accessing an __ApplicationSettings file on a device’s filesystem
Figure 12.2
Browsing an app’s INetCookies directory on a device
Figure 12.3
Original image of the Linux mascot, Tux the Penguin
Figure 12.4
Recovered image of Tux the Penguin
Chapter 14
Figure 14.1
The Developer Mode menu
Figure 14.2
Elcomsoft cracking the BlackBerry backup encryption
Figure 14.3
Sachesi helps you access BAR files
Figure 14.4
Splitting the firmware image using Sachesi
Figure 14.5
Extracting the application using Sachesi
Figure 14.6
The extracted application
Figure 14.7
Rename the original BAR file
Figure 14.8
Result of extracting the BAR file
Figure 14.9
Example MANIFEST.MF file
Figure 14.10
BAR root directory
Figure 14.11
Contents of the native directory
Figure 14.12
The bar-descriptor.xml file
Figure 14.13
The Assets subdirectory
Figure 14.14
Example QML file
Figure 14.15
The MANIFEST.MF file for a WebWorks application
Figure 14.16
The entry point for a WebWorks application
Figure 14.17
The BARs native subdirectory
Figure 14.18
The jnext directory
Chapter 15
Figure 15.1
Container separation in BlackBerry Balance
Figure 15.2
An example file browser application
Chapter 16
Figure 16.1
Disassembly of vulnerable function in IDA Pro
Guide
Cover
Table of Contents
Chapter
Pages
xxxi
xxxii
xxxiii
xxxiv
xxxv
xxxvi
xxxvii
xxxviii
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
258
259
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
386
387
388
389
390
391
392
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
583
584
585
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
673
675
676
677
678
679
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750