Top Banner
A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group
60

A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Jan 24, 2017

Download

Technology

EC-Council
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

A(not-so-quick)PrimeroniOSEncryptionDavidSchuetz-NCCGroup

Page 2: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Introduction

• DavidSchuetz• SeniorConsultant,NCCGroup• FocusonwebandiOSapplicationtesting• Cryptopuzzles(ShmooCon,VZDBIR,etc.)

• Volunteerconferencesupporttocommunity

Page 3: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

NCCGroup

• BasedinManchester,UK

• ConsultingbusinessmostlyNorthAmerica

• Webandmobileapptesting,pentesting

• RMG,dedicatedCryptographypractice

• Alwayshiring• Stronginternprogram

• NYC,Chicago,Seattle,SanFrancisco,Austin• Evenremote!

Page 4: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Background

Page 5: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

AncientHistory• CNET,May2013,claims“Applecanbypassthesecuritysoftware”:

• Bigbacklog(7weeks,onecasetook4months)

Page 6: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

AncientHistory

• October2014:“Apple’scommitmenttoyourprivacy”

• ChangesiniOS8

• “Applecannotbypassyourpasscode”• “…nottechnicallyfeasible…torespondtogovernmentwarrants”

• Raisedlotsofquestions:

• Whatdoesthatmean?Whatdidtheydobefore?

• Whataboutotherattacks?Forensics?

• Suddenlygotalotmoreimportant

Page 7: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

WhatdoesitMEAN?!?

• Backlogimplies:

• Can’tjustpluginanduseamagickey

• Couldbruteforcepasscodes,conceivably

• “ApplecanaffordaLOTofGPUcrackers…”• Itdoesn’tworkthatway

Page 8: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

SohowdoesiOSencryptionwork?

• It’scomplicated,butalsofairlycomprehensive

• Someearlydetailsfiguredoutbyresearchers

• ExaminingandunderstandingpublishedAPIs

• Reverseengineering,breaking• Applepublishesan“iOSSecurity”paper• BeginninginMay2012

• Updatedannuallyorbetter• Coversencryption,ApplePay,lotsofotherthings

• ThistalkfocusesonEncryption

Page 9: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

BasicsofiOSEncryption

Page 10: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

HowiOSencryptionworksEffaceable

Storage

UIDKey 0x89B

Key 0x835

Stored in Hardware

Dkey

EMF

BAG1

Data Partition

Data FileFile KeyFile Data

Keybag

Class 11 Key

Class 1 KeyClass 2 KeyClass 3 Key

Passcode

Class 4 Key

Entered by User

Keychain File

Keychain Item

Data FileFile KeyFile Data

Passcode Key

Page 11: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Fulldiskencryption

• iPhone3GS/iOS3• DedicatedAESprocessor• LocatedinDMAchannelbetweenCPUandDisk

• Generatearandomkey(EMFkey)

• EncryptEMFkeyusingahardware-derivedkey(0x89b)

• StoreencryptedEMFkeyinspecialdiskarea

• Usethistoencryptfilesystemmetadata

Page 12: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

iOS3-FDEEffaceable

Storage

UIDKey 0x89BStored in

HardwareEMF

Data Partition

Data File

Page 13: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Advantages

• Advantages• Fastwipe• Can’taccess/modifydatadirectly(withoutOS)

• Can’ttransferchipstoanotherdevice• Limitations

• Filesystemaccessgrantsaccesstoeverything

• Noadditionalprotectionswhenlocked

Page 14: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

File-levelencryption

• DataProtectionAPIintroducediniOS4• Randomencryptionkeycreatedforeachfile

• Filekeyisencryptedusingaclasskey• Encryptedfilekeystoredwithfilemetadata

Page 15: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

iOS4-DataProtectionAPI

Data Partition

Data FileFile KeyFile Data

Class 1 Key

Page 16: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Multipleclasses

• Defaultclass:• iOS4-6is“noprotection”• iOS7-9:CompleteuntilFirstAuthentication

• MostsystemappsthroughiOS7stillusedNone

Protection Class Description

None No additional encryption

Complete Unless Open Asymmetric, for locking while writing

Complete Until First User Authentication

Encrypted after reboot, until first time unlocked

Complete Encrypted whenever device is locked

Page 17: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Classkeysinthekeybag

Data Partition

Data FileFile KeyFile Data

Keybag

Class 11 Key

Class 1 KeyClass 2 KeyClass 3 KeyClass 4 Key

Keychain File

Keychain Item

Data FileFile KeyFile Data

Page 18: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

DataProtection:None

• Class4orDisFileProtection“None”class• RandomDkeygenerated

• Encryptedwithkey0x835,derivedfromUID

• Encryptedkeystoredineffaceablestorage

Page 19: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

DefaultprotectionkeyEffaceable

Storage

UIDKey 0x89B

Key 0x835

Stored in Hardware

Dkey

EMF

BAG1

Data Partition

Data FileFile KeyFile Data

Keybag

Class 11 Key

Class 1 KeyClass 2 KeyClass 3 KeyClass 4 Key

Keychain File

Keychain Item

Data FileFile KeyFile Data

Page 20: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Classkeyprotection

• Eachclasskeyisalsowrappedorencrypted• Usingtheuser’spasscodekey

• Entirekeybagisencrypted• Usingabagkey(storedineffaceablestorage)

• Whenpasscodeischanged,oldbagkeysdeleted

Page 21: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

PasscodeandkeybagEffaceable

Storage

UIDKey 0x89B

Key 0x835

Stored in Hardware

Dkey

EMF

BAG1

Data Partition

Data FileFile KeyFile Data

Keybag

Class 11 Key

Class 1 KeyClass 2 KeyClass 3 Key

Passcode

Class 4 Key

Entered by User

Keychain File

Keychain Item

Data FileFile KeyFile Data

Passcode Key

Page 22: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

PasscodeKDF

• PBKDF2,usingPasscode,Salt,UID,variableiterations

• Workfactordependsondevice

• Constanttime—approx.80mS/attempt

• A7onwardadda5seconddelay• DependsonUID,whichcan’tbeextractedfromphone

• Notpossibletobringtoyourcrackingcluster

Page 23: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Bruteforcingpasscode• Mustbeperformedonthedevice

• Signedexternalimage

• Usingabootromvulnerability

• 80mSperattempt

• Nowupto5sec,somultiplytableby~62

• Attemptescalation,auto-wipearepartofUI

• Whenbootedfromexternalimage,nolimitsComplexity Time

4-digit numeric 15 min6-digit numeric 22 hours

6-char lowercase 286 days6-char mixed case 50 years

Page 24: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Locking…

• FileProtectionCompletekeyremovedfromRAM

• AllCompleteprotectionfilesnowunreadable

• Otherkeysremainpresent

• AllowsconnectiontoWi-Fi

• Letsyouseecontactinformationwhenphonerings

• [Ioncefoundanedgecasewherethisdoesn’thappen…]

Page 25: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Changingpasscode…

• Thesystemkeybagisduplicated

• Classkeyswrappedusingnewpasscodekey(encryptedwith0x835key,wrappedwithpasscode)

• NewBAGkeycreatedandstoredineffaceablestorage

• OldBAGkeythrownaway• NewkeybagencryptedwithBAGkey

Page 26: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Rebooting…

• FileProtectionCompletekeylostfromRAM

• CompleteuntilFirstAuthenticationkeyalsolost

• Only“FileProtection:None”filesarereadable• AndthenonlybytheOSonthedevice• BecauseFDE

Page 27: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Wipingdevice…

• Effaceablestorageiswiped,destroying:• DKey:All“Fileprotection:none”filesareunreadable

• Bagkey:Allotherclasskeysareunreadable• EMFkey:Can’tdecryptthefilesystemanyway

Page 28: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Playitagain!

• FileisencryptedwithaFileKey• FileKeyencryptedwithClassKey• ClassKeyencryptedwithPasscodeKey• Passcodekeyderivedfrom:

• UID,0x835,Passcode

• KeybagencryptedwithBagKey• EntirediskencryptedwithEMFKey

• EMFkeyencryptedusing0x89b

• 0x89band0x835derivedfromUID

Data Partition

Keybag

Data File

File KeyFile Data

Class Key

BAG1

UID

Passcode

KDF

Passcode Key

Key 0x89B

EMF

Key 0x835

DKey

Disk

EffaceableStorage

System ona Chip(SoC)

Page 29: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

WeaknessandAttacks

Page 30: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

BreakingThroughtheCrypto

• Severalwaystogetaroundtheseprotections• Jailbreakingdevices

• Simplebugsinthesoftware

• Forensictoolsusingobscureorbrokenfeatures

• Specialboot-levelcapabilities

• Collectfromotherlocations(“Tothecloud!”)

Page 31: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Jailbreaking

• Exploitsbugsintheoperatingsystem

• Bypassescodesigning,sandboxes,etc.• Needstomodifyfilesystemtomaintainpersistence

• Jailbreakprocesscannotbypasscryptoonalockeddevice

• Butmayweakenit

• Generallyneedtounlock,install,rebootdevice:

• Jailbreakershavemuchlargerattacksurface

• Anyapporsystemprocessonunlockeddevice

Page 32: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Bugs

• Lockscreenbypasses• Reallyjustmovingfromoneapptoanother

• Cryptoprotectionsarestillinplace

• Limiteddataaccessibility

• Usuallyfixedquickly

• Maliciousapps

• Fromappstore

• Side-loadedwithenterprisecerts

• OS-levelproblems

Page 33: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

ForensicCapabilities

• Nomagicchannelsjustforforensicstools

• Frequentlyusingsamebugsfoundbycommunity

• Methodsandcapabilitiesoftencloselyheld

• Difficulttofullyascertain

• Lockeddevice

• Facesameobstaclesaseveryoneelse

• Unlockeddevice

• Hiddenorlittle-understoodfeatures

• Specialdatabases,logs,etc.

• Treasuretroveofinfo

Page 34: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

BootANewOS

• Multi-stepbootprocess

• LLB(low-levelboot)

• iBoot

• OSboot

• Signaturechecksateachstage

• OSimageencryptedforeachdeviceclass

• Keyderivedfrom“GID”codeinSoC

• Bugsonearlydevicesallowedbypassingsignature

• FixediniPhone4S,iPad2

Page 35: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

TheCloud• Server-sidedatastorageverycommon

• Generous“basic”app-datastorageforfreefromApple

• User-paidiClouddata

• Third-partycloudstorage

• Appvendorservers

• Can’tgetdataonphone?Gotothenet

• ExamplesofiOSdatastoredoniCloud:

• Backups

• Notes,calendarentries,contacts

• App-specificdata

• iClouddrive-iWorkdata,etc.

Page 36: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

MDMorDesktopSync

• SynctoiTunesgetslotsofdata• Butnokeychain,unlessthebackupisencrypted

• USBaccessontrusteddesktop• Usedtoallowaccesstomostalldata

• Nowonlyworksonbetaversionsofsoftware

• Couldcomebackwithoutwarning(bydesignornot)

• MobileDeviceManagement

• Ifenrolledandconfigured,canremotelyunlock• NeedsWi-Fiaccess

• Ifrebootedandnocellulardata—noMDM.

Page 37: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

PrivacyTakesCenterStage

Page 38: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

NewPublicFocus

• EncryptionfeaturesfairlystablesinceiOS4• Whyisthisabigdealnow?

• Softwarechanges• Newhardwarefeatures• Strongerpublicstanceonprivacy• Somewhatdrivenbypost-Snowdenconcerns

Page 39: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

NewDataProtectionDefaults

• iOS7defaults:• 3rdpartyapps:CompleteUntilFirstUnlock

• Systemapps:None(exceptMail)

• NowSystemAppsdefaulttoUntilFirstUnlock

• Mostdataunreadableafterareboot

• AlsolimitedsandboxaccessoverUSB

• Cannolongeraccessallofapp’sfiles• Evenwhenunlocked• Evenwithtrustedcomputer

Page 40: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Seeforyourself

• iOS7phone:• Reboot,Callfromlandline

• Seefullcontactinformation(name,picture,etc.)

• iOS8or9:• Reboot,callfromlandline,justseephonenumber

• Unlock,lockagain,callagain• Nowyouseeeverything

Page 41: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

SecureEnclave

• IntroducedwithiPhone5SandiOS7in2013• Specialsub-processorandstorage

• SeparatehardenedOS• Speciallyencryptedareaondisk

• Handlesmanyofthepasscodefeatures

• Notsurewhetherfailurecountsstoredthere

• Hardcoded5seconddelay

• Additionalfeaturesaddedovertime• Encryptionandpublickeys

• Notverywellunderstoodatthispoint

Page 42: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

PublicCommitmenttoPrivacy

• Drawsalineinthesand• “Wesellproducts,notyourinformation”

• Wantscustomerstobeincontroloftheirdata

• Technicaladviceforstrongsecuritychoices• Promiseoftransparencyregardinggovernmentaccess

Page 43: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

(Intense)SpotlightonSecurity

Page 44: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

TheRoadtoSanBernardino

• Gradualsecurityimprovementsoveryears

• Snowdenrevelations• Publiccommitmenttoprivacyandsecurity

• Beginningsofpushbackfromlawenforcement

• SanBernardinoattack• FBIrequestscourttoorderassistancefromApple

• Strangersaskingmeaboutthecase

Page 45: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

WhatFBIaskedfor

• Awaytobypasspasscodeguessinglimits

• “Customversionofoperatingsystem”

• “Tailoredtojustthisphone”

• Possible?Maybe.Probably.

• Agoodidea?• Applespentnearly100pagesexplainingwhynot

• FBIeventually….hiredhackers?….

Page 46: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

How’dtheyfinallygetin?

• Manypossibilitieshavebeensuggested

• Mostlyjustspeculation

• Someideasmorelikelythanothers

• Someideasare…outthere.

Page 47: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

ProbableAttackSurfaces

• Cryptography• Extensivelyused• Securityhighlydependentuponthisbeing“safe”

• Hardwareattacks• Ifyoucanholdit,youcanownit• Howmuchdoyouwanttospend?

• Softwarebugs• Theyhappentoeveryone• Alot

Page 48: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

CryptographicAttacks• Tobootahackedimage:

• BreakintoAppleandstealtheirsecretkeys• OtherAppleservicesusetamper-resistantHSM

• Breaksignatureprocess• RSAsignatures

• SHA1hashes

• BootROMbug

• MajorcryptographicbreakinAES

• AllowderivationofUIDandofflinecracking• Allowdirectdecryptionofdatafiles

Page 49: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

HardwareAttacks• De-captheSoC• FindtheUIDandextractit

• CopyencrypteddatafromNAND

• Brute-forcepasscodeonaGPUcluster

• Riskyandexpensive.Norecoverypath.

• Memorychipattacks

• Preventupdatingpasscodefailurecount

• Rollflashbacktopreviouscopywherecount=0

• Racecondition

• DetectfailurebeforeOScanupdatecount

Page 50: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

SoftwareAttacks• Racecondition• Enterpasscode,dosomethingelseREALLYFAST

• Lockscreenbypass• Wouldn’tgetmuchdata

• Couldshowspringboard• Mightshowthatphonehadverylittledataanyway

• Otherattacks• Codeinjection• DFUoriTunesRestoreattacks• Wiredorwirelessattacksurfaces

Page 51: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

LikelySuspects?

• NewBootROMbug

• Boothackedimagecontainingpasscodecracker

• Lockscreenbypass• Limiteddataextraction,butprovideswindow

• Otherbugsinlockscreen• Allowingforinterruptionoftimeoutorfailurecounting

• Attacharobot• Hardware-levelattacksonmemory

• Interruptingdatawritesorrestoringearliercopy

Page 52: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Howmuchcouldtheyget?

• Everything,rightaway?• Needsamajorcryptobug

• Everything,eventually?

• Passcodefailurecountbypasses

• Hardwareorsoftwareattacks

• Simpleintelandgeneralphoneusage?

• Lockscreenbypass

Page 53: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

RemainingQuestions

Page 54: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Questionsfrom2014….

• CanApplebruteforcepasscodes?• Wouldthey?

• Couldtheybeorderedto?• Hasthishappenedalready?

Page 55: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

MoreHardwareQuestions

• CantheSecureEnclavesoftwarebeupdated?• Toalterthepasscodefailureprotections?• Doesitrequiredevicebeunlocked?

• AreanyoftheSEfunctionsinROM?

• Whereisthefailurecountlocated?

• OnSoCorflash?• WillSEcodeenforce10-trylimit?

Page 56: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Conclusion

Page 57: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

GeneralBestPractices

• GoodadviceonApple’sPrivacyandSecuritypages• SelectnewerdeviceswithSecureEnclave• Selectalongpasscode

• Alphanumericisbest

• Evenwith5-seconddelayinSecureEnclave

• UseTouchIDfor“typical”dailyuse• Butdon’tforgetthepasscode!

• Ifyou’rearrested,turnoffphone• Orquicklytrytounlockwithwrongfinger

• Afterafewtries,fingerprintsdisabled

Page 58: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

Conclusion• iOSsecurityhighlydependentuponencryption

• Complexandcomprehensive

• Nopublicly-knownmajordesignflaws

• Bypassingencryptiondependsonbreakingpasscode• Hardwareattacks(potentiallyexpensive)• Softwarebugs(usuallyfixedquickly)• Stillaslowprocess

• Orbreakingcryptoingeneral• WhichbreaksEVERYTHING

• Userscanfightbackwithstrongpasscode

Page 59: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

References

• Apple“iOSSecurity”paper• “iPhonedataprotectionindepth”(Sogeti,HITBAmsterdam2011)

• “EvolutionofiOSDataProtectionandiPhoneForensics:fromiPhoneOStoiOS5”,(Elcomsoft,BlackHatAbuDhabi2011)

Page 60: A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group

ThankYou

DavidSchuetzSeniorConsultant,[email protected]

@DarthNulldarthnull.org