IOS Application Security Testing Cheat Sheet

Introduction
This cheat sheet provides a checklist of tasks to be performed when testing an iOS application. When assessing a mobile application several areas should be taken into account: client software, the communication channel and the server side infrastructure. Testing an iOS application usually requires a jailbroken device. (A device that not pose any restrictions on the software that can be installed on it.)



Information gathering
 Observe application behavior Determine the application’s data states (at rest, in transit or on display) and sensitivity  Identify access methods Identify what frameworks are in use Identify server side APIs that are in use Identify what protocols are in use Identify other applications or services with which the application interacts Decrypt Appstore binaries: the .ipa will be decrypted at runtime by the kernel’s mach loader. Cydia has two applications available: Crackulous, AppCrack and Clutch. Also, you can use GDB. The “cryptid” field of the LC_ENCRYPTION_INFO identifies if the application is encrypted or not. Use otool –l | grep –A 4 LC_ENCRYPTION_INFO</li> Determine the architecture the application was compiled for: otool –f or lipo -info .</li> Get information about what functions, classes and methods are referenced in the application and in the dynamically loaded libraries. Use nm </li> List the dynamic dependencies. Use otool –L Dump the load commands for the application. Use otool –l </li> Dump the runtime information from the compiled application. Identify each class compiled into the program and its associated methods, instance variables and properties. Use class-dump-z. That can be put that into a .h file which can be used later to create hooks for method swizzling or to simply make the methods of the app easier to read.</li> Dump the keychain using dump_keychain to reveal application specific credentials and passwords if stored in the keychain. </li> </ul> Determine the security features in place: <ul> Locate the PIE (Position Independent Executable) - an app compiled without PIE (using the “–fPIE –pie” flag) will load the executable at a fixed address. Check this using the command: otool –hv </li> Stack smashing protection - specify the –fstack-protector-all compiler flag. A “canary” is placed on the stack to protect the saved base pointer, saved instruction pointer and function arguments. It will be verified upon the function return to see if it has been overwritten. Check this using: otool –I –v | grep stack. If the application was compiled with the stack smashing protection two undefined symbols will be present: “___stack_chk_fail” and “___stack_chk_guard”.</li> </ul>

Application traffic analysis
<ul> Analyze error messages</li> Analyze cacheable information</li> Transport layer security (TLS version; NSURLRequest object )</li> Attack XML processors</li> SQL injection</li> Privacy issues (sensitive information disclosure)</li> Improper session handling</li> Decisions via untrusted inputs</li> <li>Broken cryptography</li> <li>Unmanaged code</li> <li>URL Schemes</li> <li>Push notifications</li> <li>Authentication</li> <li>Authorization</li> <li>Session management</li> <li>Data storage</li> <li>Data validation (input, output)</li> <li>Transport Layer protection – are the certificates validated, does the application implement Certificate Pinning</li> <li>Denial of service</li> <li>Business logic</li> <li>UDID or MAC ID usage (privacy concerns)</li> </ul>

Runtime analysis
<ul> <li>Disassemble the application (gdb)</li> <li>Analyze file system interaction</li> <li>Use the .h file generated with class-dump-z to create a method swizzling hook of some interesting methods to either examine the data as it flow through or create a "stealer" app.</li> <li>Analyze the application with a debugger (gdb): inspecting objects in memory and calling functions and methods; replacing variables and methods at runtime.</li> <li>Investigate CFStream and NSStream</li> <li>Investigate protocol handlers (application: openURL - validates the source application that instantiated the URL request) for example: try to reconfigure the default landing page for the application using a malicious iframe.</li> <li>Buffer overflows and memory corruption</li> <li>Client side injection</li> <li>Runtime injections</li> <li>Having access to sources, test the memory by using Xcode Schemes</li> </ul>

Insecure data storage
<ul> <li>Investigate log files(plugging the device in and pulling down logs with Xcode Organizer)</li> <li>Insecure data storage in application folder (var/mobile/Applications), caches, in backups (iTunes)</li> <li>Investigate custom created files</li> <li>Analyze SQLlite database</li> <li>Investigate property list files</li> <li>Investigate file caching</li> <li>Insecure data storage in keyboard cache</li> <li>Investigate Cookies.binarycookies</li> <li>Analyze iOS keychain (/private/var/Keychains/keychain-2.db) – when it is accessible and what information it contains; data stored in the keychain can only be accessible if the attacker has physical access to the device.</li> <li>Check for sensitive information in snapshots</li> <li>Audit data protection of files and keychain entries (To determine when a keychain item should be readable by an application check the data protection accessibility constants)</li> </ul>

Related Articles
<ul> <li>http://www.slideshare.net/jasonhaddix/pentesting-ios-applications</li> <li>https://www.owasp.org/index.php/Projects/OWASP_Mobile_Security_Project_-_Security_Testing_Guide</li> <li>http://pen-testing.sans.org/blog/pen-testing/2011/10/13/mobile-application-assessments-attack-vectors-and-arsenal-inventory#</li> <li>http://www.securitylearn.net/2012/09/07/penetration-testing-of-iphone-applications-part-3/</li> <li>Jonathan Zdziarski “Hacking and securing iOS applications” (ch. 6,7,8)</li> <li>http://www.mdsec.co.uk/research/iOS_Application_Insecurity_wp_v1.0_final.pdf</li> </ul>

= Authors and Primary Editors = Oana Cornea - oanacornea123[at]gmail.com

Jason Haddix - jason.haddix[at]hp.com

= Other Cheatsheets =