Hacking and Securing iOS Applications
Jonathan Zdziarski
Copyright 2012 Jonathan Zdziarski
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (.
Nutshell Handbook, the Nutshell Handbook logo, and the OReilly logo are registered trademarks of OReilly Media, Inc. Hacking and Securing iOS Applications , the cover image of a skunk, and related trade dress are trademarks of OReilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and OReilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
O'Reilly Media
Preface
Data is stolen; this is no uncommon occurrence. The electronic information age has made the theft of data a very lucrative occupation. Whether its phishing scams or large-scale data breaches, criminals stand to greatly benefit from electronic crimes, making their investment well worth the risk. When I say that this occurrence is not uncommon, my goal isnt to be dismissive, but rather to alarm you. The chances that your companys applications will be vulnerable to attack are very high. Hackers of the criminal variety have an arsenal of tools at their disposal to reverse engineer, trace, and even manipulate applications in ways that most programmers arent aware. Even many encryption implementations are weak, and a good hacker can penetrate these and other layers that, so many times, present only a false sense of security to the applications developers.
Take everything hackers collectively know about security vulnerability and apply it to a device that is constantly connected to a public network, wrapped up in a form factor that can fit in your pocket and is frequently left at bars. Your companys applications, and the data they protect, are now subject to simpler forms of theft such as pickpocketing, file copies that can take as little as a few minutes alone with a device, or malicious injection of spyware and root kitsall of which can be performed as the devices owner reaches for another drink. One way or another, software on a mobile platform can be easily stolen and later attacked at the criminals leisure, sometimes without the devices owner even knowing, and sometimes without physical access to the device.
This book is designed to demonstrate many of the techniques black hats use to steal data and manipulate software in an attempt to show you, the developer, how to avoid many all too common mistakes that leave your applications exposed to easy attacks. These attacks are not necessarily limited to just the theft of data from the device, but can sometimes even lead to much more nefarious attacks. In this book, youll see an example of how some credit card payment processing applications can be breached, allowing a criminal to not only expose the credit card data stored on the device, but also to manipulate the application to grant him huge credit card refunds for purchases that he didnt make, paid straight from the merchants stolen account. Youll see many more examples, too, of exploits that have made mobile applications not just a data risk, but downright dangerous to those using them. The reader will also gain an understanding of how these attacks are executed, and many examples and demonstrations of how to code more securely in ways that wont leave applications exposed to such attacks.
Audience of This Book
This book is geared toward iOS developers looking to design secure applications. This is not necessarily limited to government or financial applications, but may also pertain to applications with assets or other features that the developer is looking to protect. Youll need a solid foundation of Objective-C coding on iOS to understand a majority of this book. A further understanding of C or assembly language will also help, but is not required.
While this book primarily focuses on iOS, much of the material can also be applied directly to the Mac OS X desktop. Given that both environments run an Objective-C environment and share many of the same tools, youll find much of this book can be used to expose vulnerabilities in your companys desktop applications as well.
Organization of the Material
This book is split into two halves. The first half discusses hacking and exposes the many vulnerabilities in iOS and iOS applications, while the second half covers techniques to better secure applications.
explains the core problem with mobile security, and outlines common myths, misconceptions, and overall flaws in many developers ways of thinking about security.
introduces the reader to many techniques of compromising an iOS device, including jailbreaking. The reader will learn how to build and inject custom code into an iOS device using popular jailbreaking techniques and custom RAM disks.
demonstrates how the filesystem of an iOS device can be stolen in minutes, and how developers cant rely solely on a manufacturers disk encryption. Youll also learn about some common social engineering practices that secure access to a device without the owners knowledge.
covers the forensic data left by the operating system, and what kind of information one can steal from a device.
explains how iOSs keychain encryption and data protection encryption can be defeated, and the inherent problems of each.
demonstrates how the HFS journal can be scraped for deleted files, and provides examples of how to securely delete files so they cannot be recovered.
introduces you to tools for spying on and manipulating the runtime environment, and demonstrates how black hat hackers can manipulate your applications objects, variables, and methods to bypass many layers of security.
introduces you to tools and approaches for disassembling and debugging your application, injecting malicious code, and performing low-level attacks using a number of techniques.
illustrates some of the tools used to hijack SSL sessions, and how to protect your application from falling victim to these attacks.
elaborates on security and describes additional methods to protect your data with proper encryption techniques.
explains how to help prevent forensic data leakage by designing your application to leave fewer traces of information.
explains many best practices to increase the complexity needed for an attack on your applications.
explains techniques used to detect when an application is running on a device jailbroken with some of the popular jailbreaking tools available.
wraps up the book and explains how important it is to understand and strategize like your adversary.
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.