Pen Testing ios Apps



Similar documents
Mobile Apps - Hands On

Mobile Application Hacking for ios. 3-Day Hands-On Course. Syllabus

CompTIA Mobile App Security+ Certification Exam (ios Edition) Live exam IOS-001 Beta Exam IO1-001

ABSTRACT' INTRODUCTION' COMMON'SECURITY'MISTAKES'' Reverse Engineering ios Applications

ios Testing Tools David Lindner Director of Mobile and IoT Security

Penetration Testing for iphone Applications Part 1

ios Security Decoded Dave Test Classroom and Lab Computing Penn State ITS Feedback -

Pentesting iphone Applications. Satishb3

Securing ios Applications. Dr. Bruce Sams, OPTIMAbit GmbH

SYLLABUS MOBILE APPLICATION SECURITY AND PENETRATION TESTING. MASPT at a glance: v1.0 (28/01/2014) 10 highly practical modules

Security Testing Guidelines for mobile Apps

Mobile Application Security and Penetration Testing Syllabus

Salesforce1 Mobile Security Guide

Mobile Applications: The True Potential Risks Where to look for information when performing a Pentest on a Mobile Application

Pentesting ios Apps Runtime Analysis and Manipulation. Andreas Kurtz

Pentesting iphone & ipad Apps Hack In Paris 2011 June 17

Mobile Application Hacking for Android and iphone. 4-Day Hands-On Course. Syllabus

Mobile Application Security Testing ASSESSMENT & CODE REVIEW

Pentesting Mobile Applications

ios applications reverse engineering Julien Bachmann

Kaspersky Fraud Prevention: a Comprehensive Protection Solution for Online and Mobile Banking

Developing Secure Mobile Apps

Security Guide. BlackBerry Enterprise Service 12. for ios, Android, and Windows Phone. Version 12.0

SECURING MOBILE APPLICATIONS

Please Complete Speaker Feedback Surveys. SecurityTube.net

Enterprise Application Security Workshop Series

Security Vulnerabilities in 3rd-Party ios Applications

iphone in Business Security Overview

BlackBerry Enterprise Service 10. Secure Work Space for ios and Android Version: Security Note

Advanced ANDROID & ios Hands-on Exploitation

AGENDA. Background. The Attack Surface. Case Studies. Binary Protections. Bypasses. Conclusions

Mobile Application Security: Who, How and Why

Icons: 1024x1024, 512x512, 180x180, 120x120, 114x114, 80x80, 60x60, 58x58, 57x57, 40x40, 29x29

That Point of Sale is a PoS

App Distribution Guide

Secure your ios applications and uncover hidden vulnerabilities by conducting penetration tests

Everything is Terrible

APPLICATION SECURITY: FROM WEB TO MOBILE. DIFFERENT VECTORS AND NEW ATTACK

Example of Standard API

BYOD AND NEXT- GENERATION MOBILE SECURITY

ipad in Business Security

CompTIA Mobile App Security+ Certification Exam (Android Edition) Live exam ADR-001 Beta Exam AD1-001

VMware Horizon Workspace Security Features WHITE PAPER

BYOD Guidance: BlackBerry Secure Work Space

BYPASSING THE ios GATEKEEPER

Ensuring the security of your mobile business intelligence

Lesson 06: Basics of Software Development (W02D2

10 steps to better secure your Mac laptop from physical data theft

Guidance End User Devices Security Guidance: Apple ios 7

MOBILE SECURITY. As seen by FortConsult. Lars Syberg Head of Security Services

End User Devices Security Guidance: Apple ios 8

Deploying iphone and ipad Security Overview

Enterprise Apps: Bypassing the Gatekeeper

eggon SDK for ios 7 Integration Instructions

Security for Mac Computers in the Enterprise

SonicWALL Mobile Connect. Mobile Connect for OS X 3.0. User Guide

SecureDoc Disk Encryption Cryptographic Engine

Security Evaluation CLX.Sentinel

Introduction to iphone Development

Xcode User Default Reference. (Legacy)

Bypassing Local Windows Authentication to Defeat Full Disk Encryption. Ian Haken

Building a Mobile App Security Risk Management Program. Copyright 2012, Security Risk Advisors, Inc. All Rights Reserved

CPSC 226 Lab Nine Fall 2015

Blackbox Android. Breaking Enterprise Class Applications and Secure Containers. Marc Blanchou Mathew Solnik 10/13/

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

Is Drupal secure? A high-level perspective on web vulnerabilities, Drupal s solutions, and how to maintain site security

SENSE Security overview 2014

ios Application Development &

Threat Model for Mobile Applications Security & Privacy

Legal notices. Legal notices. For legal notices, see

Homeland Security Red Teaming

Practical Mac OS X Insecurity

Mobility Introduction Android. Duration 16 Working days Start Date 1 st Oct 2013

White Paper: Multi-Factor Authentication Platform

10 Ways to Not Get Caught Hacking On Your Mac

Windows Server 2008 R2 Boot Manager Security Policy For FIPS Validation

ios App for Mobile Website! Documentation!

Tutorial on Smartphone Security

Computer Security: Principles and Practice

Forensic analysis of iphone backups

company policies are adhered to and all parties (traders,

How To Test For Security On A Mobile Device

Mobile Application Security Study

Securely Yours LLC We secure your information world. www. SecurelyYoursllc.com

Defending Behind The Device Mobile Application Risks

Key & Data Storage on Mobile Devices

Apple Client Management with JAMF. Andrew D Huston Client Infrastructure Group Informa8on Services Kent State University

Mobile Device Security and Encryption Standard and Guidelines

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

What Happens When You Press that Button? Explaining Cellebrite UFED Data Extraction Processes

Customize Mobile Apps with MicroStrategy SDK: Custom Security, Plugins, and Extensions

DTI / Titolo principale della presentazione IPHONE ENCRYPTION. Litiano Piccin. 11 ottobre 2014

Apple ios 8 Security

Ensuring the security of your mobile business intelligence

Transcription:

Pen Testing ios Apps FIRST 2015 Ken van Wyk, @KRvW Berlin, Germany 14-19 June 2015 Ken van Wyk, ken@krvw.com, @KRvW

Topics we ll cover We ll focus on how to break typical ios apps ios topics Application topics Simple analysis Surface of app Static analysis Dynamic analysis Deeper analysis Explore app binary Run-time exploration and exploitation 3

Tools Most tools we ll use are either open source or inexpensive iexplorer for exploring file system on an ios device ios device and a USB cable Preferably jailbroken Cydia Cycript 4

Clear up some misconceptions Apple s ios has been a huge success for Apple Together with Android, they have re-defined mobile telephony Apple has made great advances in security They are still far from really good Not even sure if they re pretty good Software developers still make silly mistakes 5

System Hardening Features Attack surface reduction Stripped down OS No /bin/sh Privilege separation Code signing Data execution prevention (DEP) Vital for return oriented programming No architectural separation of data and code segments Address space layout randomization (ASLR) 6

Application sandboxing By policy, apps are only permitted to access resources in their sandbox Inter-app comms are by established APIs only URLs, keychains (limited) File i/o in ~/Documents only These rules don t always apply to Apple s own apps 7

Hardware encryption Each ios device (as of 3GS) has hardware crypto module Unique AES-256 key for every ios device Sensitive data hardware encrypted Sounds brilliant, right? Well... 8

ios crypto keys GID key - Group ID key UID key - Unique per dev Dkey - Default file key EMF! - Encrypts entire file system and HFS journal Class keys - One per protection class Some derived from UID + Passcode 9

ios NAND (SSD) mapping Block 0 - Low level boot loader Block 1 - Effaceable storage Locker for crypto keys, including Dkey and EMF! Blocks 2-7 - NVRAM parameters Blocks 8-15 - Firmware Blocks 8-(N-15) - File system Blocks (N-15)-N - Last 15 blocks reserved by Apple 10

Built-in file protection classes ios (since 4) supports file protection classes NSFileProtectionComplete NSFileProtectionCompleteU nlessopen NSFileProtectionCompleteU ntilfirstuserauthentication NSFileProtectionNone All but None are derived 11

Built-in file protection limitations Pros Easy to use, with key management done by ios Powerful functionality Always available Zero performance hit Cons For Complete, crypto keying includes UDID + Passcode 4 digit PIN problem 12

Keychains Keychain API provided for storage of small amounts of sensitive data Login credentials, passwords, etc. Credit card data often found here Stored in a SQLite database Encrypted using hardware AES with derived key 13

Jailbreaks Apple s protection architecture is based on a massive digital signature hierarchy Starting from bootloader Through app loader Jailbreak software breaks that hierarchy Current breaks up to 8.1.2 DFU mode allows USB vector for boot loader Older iphones mostly, but 14

Keyboard data All keystrokes are stored Used for auto-correct feature Nice spell checker Key data can be harvested using forensics procedures Passwords, credit cards... Needle in haystack? 15

Screen snapshots Devices routinely grab screen snapshots and store in JPG Used for minimizing app animation It looks pretty WHAT?! It s a problem Requires local access to device, but still... 16

Let s consider the basics We ll cover these (from the mobile top 10) Protecting secrets At rest In transit Input/output validation Authentication Session management Access control Privacy concerns 17

Examples Airline app Stores frequent flyer data in plaintext XML file Healthcare app Stores patient data in plist file But it s base64 encoded for your protection Banking app Framework cache revealed sensitive account data Consumer ticket app Accepted SSL from self signed key Exposed credit card data 18

SQLlite example Let s look at a database app that stores sensitive data into a SQLite db We ll recover it trivially by looking at the unencrypted database file 19

Protecting secrets at rest Encryption is the answer, but it s not quite so simple Where did you put that key? Surely you didn t hard code it into your app Surely you re not counting on the user to generate and remember a strong key Key management is a nontrivially solved problem 20

Static analysis of an app Explore folders./documents./library/caches/*./library/cookies./library/preferences App bundle Hexdump of binary plist files What else? 21

Tools to use Mac tools Finder iexplorer hexdump strings otool otx (otx.osxninja.com) class-dump (iphone.freecoder.org/ classdump_en.html) Emacs (editor) Xcode additional tools Clang (build and analyze) Finds memory leaks and others 22

Exercise - coffee shop attack This one is trivial, but let s take a look In this igoat exercise, the user s credentials are sent plaintext Simple web server running on Mac responds If this were on a public WiFi, a network sniffer would be painless to launch 23

Most common SSL mistake We ve all heard of CAs being attacked That s all important, but... (Certificate pinning can help.) Failing to properly verify CA signature chain Biggest SSL problem by far Study showed 1/3 of Android apps fell to this 24

Testing for SSL problems Goal is to ensure client performs strong certificate verification MITM on the net setup App proxy on laptop (e.g., Burpsuite) Generate SSL cert signed by your own CA Put your CA cert on test ios device Remember to remove fake CA before leaving lab environment! 25

But that s not enough 26

ObjC Run-time is flawed Unlike in C, functions are not called Messages are passed Objects dynamically allocated Within process space, dynamic tampering also possible Message traffic Objects 27

Reverse engineering Attacker wants to learn how your app works Deep internal details Attacker wants to attempt to trick your app into misbehaving Tamper with runtime How? Jailbroken device and some free tools And a lot of time 28

Prerequisite tools and env Mac with OS X and Xcode Jailbroken device evasi0n works great Cydia and friends Cydia installed with evasi0n Shell access OpenSSH - install with Cydia Debugger gdb - install with Cydia Bare minimum essentials 29

Analysis techniques Static analysis Observe attributes of the executable, app files Yes, encrypted (app store) apps too Dynamic analysis Run the app and learn how it works Tampering Trick the run-time env 30

Static analysis Any binary can be examined Usually reveal a map to classes, objects, text, symbols, etc. Common tools otool class-dump-z nm Examples Linked libs, methods otool -L appname otool -l appname List of classes class-dump-z appname Symbol table nm appname 31

It s C underneath the hood Beneath that nice OOP ObjC layer lies a C foundation Pretty much everything in ObjC can be done in C Primitives for doing all the OO stuff objc_msgsend(), objc_getclass() are prime examples This matters to us when analyzing statically or dynamically 32

Encrypted binaries too Basic process Use app loader to decrypt Calculate memory offsets Store process to disk dd is your friend Will also need plutil and gdb HOWTO available http:// www.mandalorian.com/ 2013/05/decrypting-iosbinaries/ 33

Let s take a look 34

Dynamic analysis What can we learn from observing it running? A lot All those messages Memory contents CPU registers You don t have anything to hide, right? 35

Attacking a running app Man in the app (MITA) The most dangerous form of on-host dynamic attack Internal access to everything That ObjC run-time messaging architecture is going to haunt us 36

A few more tools For these, you ll want gdb Cycript (see slide) Network proxy (e.g., Burpsuite) SSLstrip (optional) 37

Message eavesdropping Use gdb to build a simple but effective message eavesdropper Example gdb -q -p PID break obj_msgsend commands x/a $r0 x/s $r1 c 38

Cycript Cycript allows developers to explore and modify running applications on either ios or Mac OS X using a hybrid of Objective-C++ and JavaScript syntax through an interactive console that features syntax highlighting and tab completion From http://www.cycript.org It is an amazing utility for dynamically probing a running app 39

Fun with Cycript Basics # cycript cy# var mystring = [[ NSString alloc ] cy> initwithstring: @ Hello world ]; Hello world cy# [ mystring length ]; 11 Combination of JavaScript and ObjC syntax gives amazing capabilities 40

Cycript (2) Safari example # cycript -p PID cy# var app = [UIApplication sharedapplication]; <UIApplication: 0x22f050> cy# [ app openurl: [ NSURL URLWithString: cy> @ http://www.first.org ]]; 1 cy# app.networkactivityindicatorvisible = YES 41

Cycripting for fun and profit Break client-side logic Alter PINs, booleans, semaphores Replace methods Probe running app data Can be verbose, but you get everything in an object cy# function appls(a){ var x={}; for(i in *a){ try{ x[i] = (*a)[i]; } catch(e){}} return x; } cy# appls(object); 42

Client-side logic You didn t think you could trust client-side logic, did you? 43

Tampering Now let s go beyond mere observation Replace existing methods Change address in gdb Dynamic linker attack Put your library in DYLD_INSERT_LIBRARIES Automate dynamic linking MobileSubstrate 44

Nothing is what it appears Now we can change the entire universe your app runs in (If this doesn t seem bad, go watch The Matrix) 45

Resources Hacking and Securing ios Applications, Jonathan Zdziarski, O Reilly, 2012 Evasi0n, popular jailbreaking tool, http:// www.evad3rs.com/ Copyright 2015 2013 KRvW Associates, LLC 46

Hardening User actions and client configurations Architectural considerations Hardening tips But remember, nothing is perfect. 47

User actions and configurations Strong passcodes help MDMs can manage configurations of entire fleets 48

Architectural considerations Design choices make a huge difference Client cannot be trusted Sensitive data Sensitive functions Security controls Client should provide presentation layer Minimal functionality Processing should be server 49

Hardening tips Non-obvious names Obfuscate functional purpose Disable debugging #define DENY_DEBUG 31 ptrace(deny_debug,0,0,0); Complicate disassembly Compiler optimizer Strip symbols 50

Hardening tips (2) Sensitive code On server, but Write in C or ASM Compile + link in-line Expand loops manually Force your attacker to single step through Don t give away anything 51

Hardening (3) Data storage Encrypt DataProtection API for consumer grade Keys on server Common Crypto Lib Secure file wiping SQLite data wiping Update before delete 52

Tamper detection How do we know? Run-time integrity checks Memory offsets of sensitive objects Sandbox integrity Attempt to fork Size and checksum of /etc/fstab Symbolic links in /Applications Common jailbreak files and apps /Applications/Cydia.app Honeypots in app There ain t a horse that can t be rode or a man that can t be throwed. 53

Tamper response What to do? Remote wipe Phone home Log everything Wipe user data, keys Disable network access Et cetera 54

Kenneth R. van Wyk KRvW Associates, LLC Ken@KRvW.com http://www.krvw.com @KRvW Copyright 2014 2015 KRvW Associates, LLC 55