90
Practical iOS App Attack and Defense – Seth Law © 2015 Practical iOS App Attack and Defense CodeMash 2.0.1.5

CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Embed Size (px)

Citation preview

Page 1: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Practical iOS App Attack and Defense – Seth Law © 2015

Practical iOS App Attack and Defense

CodeMash 2.0.1.5

Page 2: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Introduction• Seth Law

– Director of R&D @ nVisium– Developer/Contributor to Swift.nV, SiRATool,

RAFT, Grails.nV– Hacker, AppSec Architect, Security Consultant– Soccer Hooligan

Page 3: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Abusing Trust

Page 4: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 5: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 6: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

DisclaimerHacking of App Store apps is not condoned or encouraged in any way. What you do on your own time is your responsibility. @sethlaw & nVisium take no responsibility if you use knowledge shared in this presentation for unsavory acts.

Page 7: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Agenda• Tools• Application Anatomy• Data Storage• Network Communications• Client Side Injection• Privacy

Page 8: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Requirements• Xcode (developer.apple.com)

– Command-line tools– Xcode-select --install– iOS Simulators

• Jailbroken iDevice (iPhone/iPad/iPod) *– Cydia Tools

• Vulnerable App– Swift.nV - https://github.com/nVisium/Swift.nV

* Only required to “test” apps from the App Store. **

Page 9: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Tools - idb• idb - https://github.com/dmayer/idb

Page 10: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Tools - idb• idb - https://github.com/dmayer/idb

Page 11: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Tools - iFunBox• https://www.i-funbox.com/ifunboxmac

Page 12: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Tools - Cydia Apps • Cycript• OpenSSH• Erica Utilities• Class Dump• GNU Debugger• network-cmds • BigBoss Recommended Tools

Page 13: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Tools - Swift.nV • INTENTIONALLY VULNERABLE• Training Tool - Not for production use

Page 14: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Agenda• Tools• Application Anatomy• Data Storage• Network Communications• Client Side Injection• Privacy

Page 15: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 16: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Application Anatomy

Page 17: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Application Anatomy• .app Directory

–Folder with distributed binary and artifacts–iOS 8

•AppStore Apps - /var/mobile/Containers/Bundle/Application/<APP GUID>/Application.app/

•Pre-installed Apps - /Applications/Application.app/ –iOS 7

•AppStore Apps - /var/mobile/Applications/<APP GUID>/Application.app/

•Pre-installed Apps - /Applications/Application.app/

Page 18: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Application Anatomy• Info.plist

Page 19: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Application Anatomy• Deployed Application Data Directories• iOS 8

• /var/mobile/Containers/Data/Application/<APP_GUID>/• iOS 7

• /var/mobile/Applications/<APP_GUID> Documents/ Library/

Caches/Preferences/...

tmp/

Page 20: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Application Anatomy

Page 21: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Application Anatomy

Page 22: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Application Anatomy

Page 23: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Application Anatomy

Page 24: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Application Anatomy• Library/…

• Other folders may exist for specific purposes• Files not exposed to the user• SyncedPreferences/ - iCloud NSUserDefaults• Cookies/ - Persistent cookie values• Application Support/ - Other App files• FlurryFiles/ - iAd files

• tmp/• Scratch space• Can be cleared by iOS when App not running

Page 25: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Agenda• Tools• Application Anatomy• Data Storage• Network Communications• Client Side Injection• Privacy

Page 26: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 27: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage• M2 in OWASP Mobile Top 10• Anything stored by the App on purpose• Data at rest on a mobile device• Majority of “mobile security” issues in the

news.• Relevant functionality

• Core Data• NSUserDefaults• Keychain• Documents• Cache

Page 28: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Attack!

Page 29: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage - Attack

Page 30: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage - Attack

Page 31: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage - Attack

Page 32: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage - Attack

Page 33: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage - Attack

Page 34: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 35: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage - Defense

Page 36: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage - Defense• Databases – Defenses

• Encryption (SQLCipher)• Rewrites crypto into database controller • Don’t store sensitive data on the device.

• Weaknesses• Key Storage

Page 37: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage - NSUserDefaults• Property Lists - Code

Page 38: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage - Attack• Property Lists

Page 39: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage - Attack• Property Lists - idb

Page 40: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 41: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 42: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 43: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage - Defense• Property List - Countermeasures

– Don’t store sensitive data using NSUserDefaults– When ignoring rule #1, encrypt the data– Use checksums or signatures to validate that

data returned from NSUserDefaults is appropriate– iOS Keychain

– For quick Keychain conversion, use a library– https://github.com/matthewpalmer/Locksmith

Page 44: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage - Defense• Keychain

– Mac OS X/iOS Password Manager– OS enforces security– CAREFUL

• Keychain can be accessed by apps running on jailbroken devices.

• idb – Don’t assume Keychain is secure.– Know your Keychain Attributes.– Layered Security

• The application will be used under the worst possible conditions, protect for THAT instance.

Page 45: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage - Defense• Keychain Analysis – know your attributes

Attribute Data is...

kSecAttrAccessibleWhenUnlocked Only accessible when device is unlocked.

kSecAttrAccessibleAfterFirstUnlock Accessible while locked. But if the device is restarted it must first be unlocked for data to be accessible again.

kSecAttrAccessibleAlways Always accessible.

kSecAttrAccessibleWhenUnlockedThisDeviceOnly

Only accessible when device is unlocked. Data is not migrated via backups.

kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly

Accessible while locked. But if the device is restarted it must first be unlocked for data to be accessible again. Data is not migrated via backups.

kSecAttrAccessibleAlwaysThisDeviceOnly

Always accessible. Data is not migrated via backups.

Page 46: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Data Storage - Defense• Keychain Analysis – know your attributes

Attribute Data is...

kSecAttrAccessibleWhenUnlocked Only accessible when device is unlocked.

kSecAttrAccessibleAfterFirstUnlock Accessible while locked. But if the device is restarted it must first be unlocked for data to be accessible again.

kSecAttrAccessibleAlways Always accessible.

kSecAttrAccessibleWhenUnlockedThisDeviceOnly

Only accessible when device is unlocked. Data is not migrated via backups.

kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly

Accessible while locked. But if the device is restarted it must first be unlocked for data to be accessible again. Data is not migrated via backups.

kSecAttrAccessibleAlwaysThisDeviceOnly

Always accessible. Data is not migrated via backups.

Page 47: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Agenda• Tools• Application Anatomy• Data Storage• Network Communications• Client Side Injection• Privacy

Page 48: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Network Communications• M3 - Insufficient Transport Layer

Protection• Are network communications

secure?• Encryption (or not)• Key Handling• Ciphers• Proxy Communication

Page 49: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 50: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 51: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

CodeMash Scanner?

Page 52: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Become a Sponsor!

Page 53: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Network Communications• LIVE DEMO

• Device: Jailbroken iPod Touch• Proxy: Burp Suite Pro • App: CodeMash Scanner

Page 54: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Volunteers?

Page 55: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Whoops

Page 56: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Network Communications• Issues Exploited during demo• Proxied Communications

• Do NOT require Jailbreak• Corporations implement proxies all the time• Accepting a proxy’s CA cert == full access to traffic

• Certificate Pinning• App doesn’t insure traffic isn’t being messed with.• Can be defeated with jailbroken device

• Web Service Vulnerabilities• Missing Function Level Access Control• Insecure Direct Object Reference

Page 57: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Network Communications

Page 58: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 59: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Network Communications• Defense

– Good: Use an Internal Certificate Authority and create certificates for all environments.

– Better: Buy actual certificates for all environments– Best: Pin the Certificate within the application to

public certificate or CA.continueWithoutCredentialForAuthenticationChallenge == BAD

Page 60: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Agenda• Tools• Application Anatomy• Data Storage• Network Communications• Client Side Injection• Privacy

Page 61: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 62: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Client Side Injection• M7 - Client Side Injection• Fuzzing all application inputs

• Text Fields• URLSchemes• Stored Data (DBs, PLists, etc)

• Multiple Types• XSS/HTML • XML/JSON • ...

Page 63: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Injection• Text Field Injection

–Manually intensive

Page 64: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Client Side Injection• URLScheme Injection

• Safari FTW!• Still manual• location bar• Fuzz URL values• Info.plist

Page 65: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Client Side Injection

Page 66: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Client Side Injection

Page 67: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Client Side Injection• Demo - Injection with Swift.nV

Page 68: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 69: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Client Side Injection• Defense

• Input Validation• Don’t trust the user• Input Validation• Output Encoding• Input Validation

Page 70: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Client Side Injection

Page 71: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Agenda• Tools• Application Anatomy• Data Storage• Network Communications• Client Side Injection• Privacy

Page 72: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 73: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 74: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Privacy• Revealing of PII• Location Information• Shoulder surfing• Physical Access

• Background screenshots• Borrowed Phone attacks

• Backups/Logs

Page 75: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

FRIENDS DON’T LET FRIENDS LEAVE THEIR PHONE BEHIND

Page 76: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 77: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 78: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Background Screenshots

Page 79: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 80: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Logs

Page 81: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Logs

Page 82: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

iOS Backup Analyzer

Page 83: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

iOS Backup Analyzer

Page 84: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 85: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Privacy - Defense• Mask mask mask• No NSLog in production apps• What is stored on the device is

also stored in the backup

Page 86: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense
Page 87: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Agenda• Tools• Application Anatomy• Data Storage• Network Communications• Client Side Injection• Privacy

Page 88: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Other Mobile Concerns• Authentication• Authorization• Binary Protections• Cryptography• Unintended Functionality• Untrusted Input

Page 89: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Conclusion

Security is hard.

Try harder.

Page 90: CodeMash 2.0.1.5 - Practical iOS App Attack & Defense

Thanks• Questions?

• Contact:• Seth Law• Email: [email protected]• Twitter: @sethlaw