SlideShare a Scribd company logo
iOS Forensics:
Overcoming iPhone Data
      Protection
         Andrey Belenko
      Chief Security Researcher
         Elcomsoft Co. Ltd.




                                  1
Agenda

•   iOS Forensics 101

•   iOS 4 Data Protection

•   iOS Forensics

    •   Passcode

    •   Keychain

    •   Storage



                                     2
Forensics 101


Acquisition ➜ Analysis ➜ Reporting

GOALS:
1. Assuming physical access to the device extract as much
information as practical
2. Leave as little traces/artifacts as practical
                                                            3
iOS Forensics 101

•   Passcode
     •  Prevents unauthorized access to the device
     •  Bypassing passcode is usually enough

•   Keychain
     • System-wide storage for sensitive data
     • Encrypted

•   Storage encryption
     •  iPhone 3Gs and later can encrypt disk data



                                                     4
iOS Forensics 101

•   iOS is modified version of Mac OS X
     •  Familiar environment

•   iOS enforces additional security
     •  Code signing: can’t run unsigned executables
     •  Sandboxing: access to system is limited

•   Acquisition options:
     • Via exposed interfaces (i.e. Sync, Backup)
     • Via circumventing security and running own code



                                                         5
iOS Forensics 101
•   Logical: iOS Backup
     •  Ask device to produce a backup
     •  Device must be unlocked
     •  Device may produce encrypted backup
     •  Limited amount of information

•   Physical: filesystem acquisition
     •  Boot-time exploit to run unsigned code
     •  Device lock state isn’t relevant
     •  Can get all information from the device
     •  Since iOS 4 filesystem is encrypted


                                                  6
Pre-iOS 4 Forensics

•    Device passcode can be bypassed

•    Storage is effectively not encrypted
      •  Device transparently decrypts data

•    Keychain data is encrypted
      • One can either decrypt all or nothing. Usually all.


    Once you have code execution, rest is easy



                                                              7
New in iOS 4
•   Passcode protection is much more robust

•   Storage is encrypted
     •  Metadata is not encrypted
     •  Contents of (almost) every file is encrypted

•   New (and better) Keychain encryption

•   New (and better) iTunes backup format


All these are part of iOS 4 Data Protection


                                                      8
AES Keys
•   All iOS devices have built-in AES processor with 2
    hardcoded keys:
     •   GID Key is shared by all devices of the same kind
     •   UID Key is unique to each and every device
         (hardware key)

•   More keys are computed during startup:
     • Key 0x835 = AES_encrypt (UID, 0101..01)
       (device key)
     • Derived keys depend solely on GID or UID and
       thus are fixed for the particular device


                                                             9
Protection Classes

•   Content is grouped into protection classes:
    •Available only when device is unlocked
    •Available after first device unlock (and until off)
    •Always available

•   Each protection class assigned a master encryption key

•   Master keys are protected by device key and passcode

•   Protected master keys form system keybag
    • New keys created during device restore



                                                             10
System Keybag
•   Stores protected (encrypted) master keys

•   Keybag payload is encrypted before writing to disk

•   Stored in /private/var/keybags/systembag.kb

•   File has NSProtectionNone protection class
    •  Meaning it is encrypted

•   11 protection classes in total
    • All but NSProtectionNone are stored in
      systembag.kb
    • NSProtectionNone is stored in Effaceable Storage


                                                         11
Effaceable Storage

•   Region of flash memory

•   Facilitates storage of small amounts of data with
    ability to quickly erase them

•   Items within effaceable storage are called lockers

•   As of iOS 4: 960 bytes capacity, 3 lockers:
    • ‘BAG1’ – systembag.kb payload key and IV
    • ‘Dkey’ – NSProtectionNone class master key
    • ‘EMF!’ – Filesystem encryption key



                                                         12
Unlocking Keybag
                    Passcode Key        Device Key

                    if (WRAP & 0x2)   if (WRAP & 0x1)
Keybag (locked)                                         Keybag (unlocked)
    Protected Key
                                         DECRYPT                Key
     WRAP = 1
    Protected Key
                      UNWRAP                                    Key
     WRAP = 2
    Protected Key
                      UNWRAP             DECRYPT                Key
     WRAP = 3
    Protected Key
                                         DECRYPT                Key
     WRAP = 1
    Protected Key
                      UNWRAP             DECRYPT                Key
     WRAP = 3
         ...                                                     ...




                                                                            13
Escrow Keybag
•   “Usability feature”
    • Allows iTunes to unlock the device

•   Contains same master keys as system keybag

•   Created when device (unlocked) is connected to
    the iTunes for the first time

•   Stored on the computer side

•   Protected by 256 bit random “passcode”
    • “Passcode” is stored on the device

•   Escrow keybag gives same powers as knowing the
    passcode
                                                     14
iOS 4 Key Hierarchy
         Must be done on the device                                     Passcode


                                                      UID Key             KDF


    EMF Key             Decrypt         Key 89B       Key 835         Passcode Key

Effaceable Storage

          ‘EMF!’                             System Keybag (locked)
          ‘Dkey’
                                                   Class A Key (#1)
         ‘BAG1’                                                          Unlock
                                                   Class B Key (#2)
                                                   Class C Key (#3)
                                                   Class D Key (#4)
                                                     Class Key #5
     systembag.kb             Decrypt                                 System Keybag
                                                           …
                                                                        (unlocked)
                                                     Class Key #11


                                                                                      15
iOS 4 Key Hierarchy
         Must be done on the device                                          Passcode
         Required to decrypt files/keychain

                                                           UID Key             KDF


    EMF Key              Decrypt             Key 89B       Key 835         Passcode Key

Effaceable Storage

          ‘EMF!’                                  System Keybag (locked)
          ‘Dkey’
                                                        Class A Key (#1)
         ‘BAG1’                                                               Unlock
                                                        Class B Key (#2)
                                                        Class C Key (#3)
                                                        Class D Key (#4)
                                                          Class Key #5
     systembag.kb              Decrypt                                     System Keybag
                                                                …
                                                                             (unlocked)
                                                          Class Key #11


                                                                                           16
iOS 4 Key Hierarchy
         Must be done on the device                                          Passcode
         Required to decrypt files/keychain
         Sufficient for key reconstruction
                                                           UID Key             KDF


    EMF Key              Decrypt             Key 89B       Key 835         Passcode Key

Effaceable Storage

          ‘EMF!’                                  System Keybag (locked)
          ‘Dkey’
                                                        Class A Key (#1)
         ‘BAG1’                                                               Unlock
                                                        Class B Key (#2)
                                                        Class C Key (#3)
                                                        Class D Key (#4)
                                                          Class Key #5
     systembag.kb               Decrypt                                    System Keybag
                                                                …
                                                                             (unlocked)
                                                          Class Key #11


                                                                                           17
iOS 4 Key Hierarchy
         Must be done on the device                                          Passcode
         Required to decrypt files/keychain
         Sufficient for key reconstruction
                                                           UID Key             KDF


    EMF Key              Decrypt             Key 89B       Key 835         Passcode Key

Effaceable Storage

          ‘EMF!’                                  System Keybag (locked)
          ‘Dkey’
                                                        Class A Key (#1)
         ‘BAG1’                                                               Unlock
                                                        Class B Key (#2)
                                                        Class C Key (#3)
                                                        Class D Key (#4)
                                                          Class Key #5
     systembag.kb               Decrypt                                    System Keybag
                                                                …
                                                                             (unlocked)
                                                          Class Key #11


                                                                                           18
iOS 4 Key Hierarchy
         Must be done on the device                                          Passcode
         Required to decrypt files/keychain
         Sufficient for key reconstruction
                                                           UID Key             KDF


    EMF Key              Decrypt             Key 89B       Key 835         Passcode Key

Effaceable Storage

          ‘EMF!’                                  System Keybag (locked)
          ‘Dkey’
                                                        Class A Key (#1)
         ‘BAG1’                                                               Unlock
                                                        Class B Key (#2)
                                                        Class C Key (#3)
                                                        Class D Key (#4)
                                                          Class Key #5
     systembag.kb               Decrypt                                    System Keybag
                                                                …
                                                                             (unlocked)
                                                          Class Key #11


                                                                                           19
iOS 4 Key Hierarchy
         Must be done on the device                                          Passcode
         Required to decrypt files/keychain
         Sufficient for key reconstruction
                                                           UID Key             KDF


    EMF Key              Decrypt             Key 89B       Key 835         Passcode Key

Effaceable Storage

          ‘EMF!’                                  System Keybag (locked)
          ‘Dkey’
                                                        Class A Key (#1)
         ‘BAG1’                                                               Unlock
                                                        Class B Key (#2)
                                                        Class C Key (#3)
                                                        Class D Key (#4)
                                                          Class Key #5
     systembag.kb               Decrypt                                    System Keybag
                                                                …
                                                                             (unlocked)
                                                          Class Key #11


                                                                                           20
iOS 4 Key Hierarchy
         Must be done on the device                                          Passcode
         Required to decrypt files/keychain
         Sufficient for key reconstruction
                                                           UID Key             KDF


    EMF Key              Decrypt             Key 89B       Key 835         Passcode Key

Effaceable Storage

          ‘EMF!’                                  System Keybag (locked)
          ‘Dkey’
                                                        Class A Key (#1)
         ‘BAG1’                                                               Unlock
                                                        Class B Key (#2)
                                                        Class C Key (#3)
                                                        Class D Key (#4)
                                                          Class Key #5
     systembag.kb               Decrypt                                    System Keybag
                                                                …
                                                                             (unlocked)
                                                          Class Key #11


                                                                                           21
Pre-iOS 4 Passcode
•   Lockscreen (i.e. UI) is the only protection

•   Passcode is stored in the keychain
    • Passcode itself, not its hash

•   Can be recovered or removed instantly
    • Remove record from the keychain
    • And/or remove setting telling UI to ask for the
      passcode




                                                        22
23
iOS 4 Passcode
•   Passcode is used to compute passcode key
    • Computation tied to hardware key
    • Same passcode will yield different passcode keys
      on different devices!

•   Passcode key required to unlock all but 3 master
    keys in system keybag

    •   Most files are NSProtectionNone thus don’t
        need passcode
    •   Most keychain items are accessible
        WhenUnlocked or AfterFirstUnlock thus DO
        require passcode

                                                         24
iOS 4 Passcode

•   Passcode-to-Key transformation is slow

•   Offline bruteforce currently not possible
    • Requires extracting hardware key

•   On-device bruteforce is slow
    •2 p/s on iPhone 3G, 7 p/s on iPad

•   System keybag contains hint on password
    complexity



                                               25
iOS 4 Passcode


• 0 – digits only, length = 4 (simple passcode)




                                                  26
iOS 4 Passcode


• 0 – digits only, length = 4 (simple passcode)
• 1 – digits only, length != 4




                                                  27
iOS 4 Passcode


• 0 – digits only, length = 4 (simple passcode)
• 1 – digits only, length != 4
• 2 – contains non-digits, any length



                                                  28
iOS 4 Passcode


• 0 – digits only, length = 4 (simple passcode)
• 1 – digits only, length != 4
• 2 – contains non-digits, any length

        Can at least identify
          weak passcodes
                                                  29
Demo



       30
Pre-iOS 4 Keychain
•   SQLite3 Database, only passwords are encrypted

•   All items are encrypted with the device key (0x835)
    and random IV

•   Key is unique for each device and is fixed for lifetime
    of the device

•   Key can be extracted (computed) for offline use

•   All past and future keychain items from the device can
    be decrypted using that key
                   Encrypted with Key 0x835
         IV                   Data            SHA-1 (Data)
0
                   16
                                                             31
iOS 4 Keychain
•   SQLite3 Database, only passwords are encrypted

•   Available protection classes:
    •       kSecAttrAccessibleWhenUnlocked (+ ...ThisDeviceOnly)
    •       kSecAttrAccessibleAfterFirstUnlock (+ ...ThisDeviceOnly)
    •       kSecAttrAccessibleAlways (+ ...ThisDeviceOnly)

•   Random key for each item

•   Item key is protected with corresponding
    protection class master key


        0          Class       Wrapped Item Key        Encrypted Item
0              4           8                      48



                                                                        32
Pre-iOS 4 Storage

•   No encryption before iPhone 3GS

•   Starting with iPhone 3GS:
    • Encryption uses EMF key for everything
    • Provides fast wipe, not confidentiality
    • Transparent to applications
    • Filesystem acquisition is not affected




                                               33
iOS 4 Storage

•   Available protection classes:
    •   NSProtectionNone
    •   NSProtectionComplete

•   If no protection class is specified, EMF key is used
    •   Filesystem metadata and unprotected files
    •   Transparent encryption and decryption (same as pre-iOS 4)

•   If protection class is specified, per-file random key is used
    •   Key protected with master key is stored
        com.apple.system.cprotect extended attribute




                                                                    34
iOS 4 Storage

•   Acquired raw image has everything decrypted with
    EMF key
    • Filesystem metadata is OK
    • File contents are not

•   Restoring file data requires reverse transformations:
    • Encrypt with EMF key to get correct ciphertext
    • Decrypt with file key to get plaintext




                                                           35
iOS 4 Forensics
         Must be done on the device                                           Passcode
         Required to decrypt files/keychain
         Sufficient for offline key reconstruction
                                                            UID Key             KDF


    EMF Key              Decrypt             Key 89B        Key 835         Passcode Key

Effaceable Storage

          ‘EMF!’                                   System Keybag (locked)
          ‘Dkey’
                                                         Class A Key (#1)
         ‘BAG1’                                                                Unlock
                                                         Class B Key (#2)
                                                         Class C Key (#3)
                                                         Class D Key (#4)
                                                           Class Key #5
     systembag.kb               Decrypt                                     System Keybag
                                                                 …
                                                                              (unlocked)
                                                           Class Key #11


                                                                                            36
iOS 4 Forensics
•   Acquiring disk image is not enough for iOS 4+
    • Content protection keys must also be extracted
      from the device during acquisition
    • Effaceable Storage contents are also needed to
      decrypt dd images.

•   Passcode or escrow keybag is needed for a
    complete set of master keys

•   In real world it might be a good idea to extract
    source data and compute protection keys offline


                                                       37
Conclusion

•   iPhone physical analysis is possible again

•   Physical acquisition requires boot-time exploit

•   Passcode is usually not a problem

•   Both proprietary and open-source tools for iOS 4
    forensics available




                                                       38
Questions?


             39
iOS Forensics:
Overcoming iPhone Data
      Protection
      a.belenko@elcomsoft.com

      @andreybelenko

      www.elcomsoft.com




                                40

More Related Content

PPTX
The Rise of Ransomware
PDF
Cyber threat intelligence ppt
PPTX
Role of Forensic Triage In Cyber Security Trends 2021
PPT
File Carving
PPTX
Firewall presentation
PPT
Introduction to computer forensic
PPTX
EDR vs SIEM - The fight is on
PDF
Nozomi networks-solution brief
The Rise of Ransomware
Cyber threat intelligence ppt
Role of Forensic Triage In Cyber Security Trends 2021
File Carving
Firewall presentation
Introduction to computer forensic
EDR vs SIEM - The fight is on
Nozomi networks-solution brief

What's hot (20)

PPT
IDS and IPS
PPSX
Next-Gen security operation center
PPTX
Network forensics and investigating logs
PPTX
Snort IDS/IPS Basics
PPTX
IoT - Attacks and Solutions
PDF
What is Cyber Security? | Introduction to Cyber Security | Cyber Security Tra...
PDF
Mobile Security
PPTX
Network security
PPTX
Network forensic
PDF
Android malware presentation
PDF
Final Project Report-SIEM
PDF
Database forensics
PPTX
iOS-Application-Security-iAmPr3m
PPTX
Web Browser Artifacts
PPTX
Forensic Investigation of Android Operating System
PPTX
Virtual machines and containers
PPTX
Network intrusion detection system and analysis
PDF
Machine Learning in Malware Detection
PPTX
Network Security
PDF
Ransomware
IDS and IPS
Next-Gen security operation center
Network forensics and investigating logs
Snort IDS/IPS Basics
IoT - Attacks and Solutions
What is Cyber Security? | Introduction to Cyber Security | Cyber Security Tra...
Mobile Security
Network security
Network forensic
Android malware presentation
Final Project Report-SIEM
Database forensics
iOS-Application-Security-iAmPr3m
Web Browser Artifacts
Forensic Investigation of Android Operating System
Virtual machines and containers
Network intrusion detection system and analysis
Machine Learning in Malware Detection
Network Security
Ransomware
Ad

Similar to iOS Forensics: Overcoming iPhone Data Protection (20)

PDF
iOS and BlackBerry Forensics
PDF
CNIT 128 2. Analyzing iOS Applications (Part 2)
PDF
Belenko, sklyarov dark and bright sides of i cloud (in)security
PDF
iPhone Data Protection in Depth
ODP
Synapse india iphone apps presentation oncracking and analyzing apple icloud
PPTX
iOS Forensics
PDF
IOS Encryption Systems
PDF
iOS Application Penetation Test
PDF
iOS secure app development
PDF
Mobile Device Encryption Systems
PDF
“Secure Password Managers” and “Military-Grade Encryption” on Smartphones:...
PDF
Mr. Andrey Belenko - secure password managers and military-grade encryption o...
PPTX
How to do Cryptography right in Android Part Two
PDF
Maemo 6 Platform Security
PDF
Troopers14 Advanced Smartphone forensics - Vladimir Katalov
PPTX
Ярослав Воронцов — Пара слов о mobile security.
PPTX
Hacking and Securing iOS Applications by Satish Bomisstty
PDF
Hacking and Securing iOS Applications
PPTX
"Mobile security: iOS", Yaroslav Vorontsov, DataArt
PPTX
Ethereum Security 101
iOS and BlackBerry Forensics
CNIT 128 2. Analyzing iOS Applications (Part 2)
Belenko, sklyarov dark and bright sides of i cloud (in)security
iPhone Data Protection in Depth
Synapse india iphone apps presentation oncracking and analyzing apple icloud
iOS Forensics
IOS Encryption Systems
iOS Application Penetation Test
iOS secure app development
Mobile Device Encryption Systems
“Secure Password Managers” and “Military-Grade Encryption” on Smartphones:...
Mr. Andrey Belenko - secure password managers and military-grade encryption o...
How to do Cryptography right in Android Part Two
Maemo 6 Platform Security
Troopers14 Advanced Smartphone forensics - Vladimir Katalov
Ярослав Воронцов — Пара слов о mobile security.
Hacking and Securing iOS Applications by Satish Bomisstty
Hacking and Securing iOS Applications
"Mobile security: iOS", Yaroslav Vorontsov, DataArt
Ethereum Security 101
Ad

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
Teaching material agriculture food technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Cloud computing and distributed systems.
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
cuic standard and advanced reporting.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
Unlocking AI with Model Context Protocol (MCP)
Teaching material agriculture food technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The Rise and Fall of 3GPP – Time for a Sabbatical?
The AUB Centre for AI in Media Proposal.docx
Cloud computing and distributed systems.
Reach Out and Touch Someone: Haptics and Empathic Computing
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Spectral efficient network and resource selection model in 5G networks
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Understanding_Digital_Forensics_Presentation.pptx
Encapsulation_ Review paper, used for researhc scholars
sap open course for s4hana steps from ECC to s4
Per capita expenditure prediction using model stacking based on satellite ima...
cuic standard and advanced reporting.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
“AI and Expert System Decision Support & Business Intelligence Systems”

iOS Forensics: Overcoming iPhone Data Protection

  • 1. iOS Forensics: Overcoming iPhone Data Protection Andrey Belenko Chief Security Researcher Elcomsoft Co. Ltd. 1
  • 2. Agenda • iOS Forensics 101 • iOS 4 Data Protection • iOS Forensics • Passcode • Keychain • Storage 2
  • 3. Forensics 101 Acquisition ➜ Analysis ➜ Reporting GOALS: 1. Assuming physical access to the device extract as much information as practical 2. Leave as little traces/artifacts as practical 3
  • 4. iOS Forensics 101 • Passcode • Prevents unauthorized access to the device • Bypassing passcode is usually enough • Keychain • System-wide storage for sensitive data • Encrypted • Storage encryption • iPhone 3Gs and later can encrypt disk data 4
  • 5. iOS Forensics 101 • iOS is modified version of Mac OS X • Familiar environment • iOS enforces additional security • Code signing: can’t run unsigned executables • Sandboxing: access to system is limited • Acquisition options: • Via exposed interfaces (i.e. Sync, Backup) • Via circumventing security and running own code 5
  • 6. iOS Forensics 101 • Logical: iOS Backup • Ask device to produce a backup • Device must be unlocked • Device may produce encrypted backup • Limited amount of information • Physical: filesystem acquisition • Boot-time exploit to run unsigned code • Device lock state isn’t relevant • Can get all information from the device • Since iOS 4 filesystem is encrypted 6
  • 7. Pre-iOS 4 Forensics • Device passcode can be bypassed • Storage is effectively not encrypted • Device transparently decrypts data • Keychain data is encrypted • One can either decrypt all or nothing. Usually all. Once you have code execution, rest is easy 7
  • 8. New in iOS 4 • Passcode protection is much more robust • Storage is encrypted • Metadata is not encrypted • Contents of (almost) every file is encrypted • New (and better) Keychain encryption • New (and better) iTunes backup format All these are part of iOS 4 Data Protection 8
  • 9. AES Keys • All iOS devices have built-in AES processor with 2 hardcoded keys: • GID Key is shared by all devices of the same kind • UID Key is unique to each and every device (hardware key) • More keys are computed during startup: • Key 0x835 = AES_encrypt (UID, 0101..01) (device key) • Derived keys depend solely on GID or UID and thus are fixed for the particular device 9
  • 10. Protection Classes • Content is grouped into protection classes: •Available only when device is unlocked •Available after first device unlock (and until off) •Always available • Each protection class assigned a master encryption key • Master keys are protected by device key and passcode • Protected master keys form system keybag • New keys created during device restore 10
  • 11. System Keybag • Stores protected (encrypted) master keys • Keybag payload is encrypted before writing to disk • Stored in /private/var/keybags/systembag.kb • File has NSProtectionNone protection class • Meaning it is encrypted • 11 protection classes in total • All but NSProtectionNone are stored in systembag.kb • NSProtectionNone is stored in Effaceable Storage 11
  • 12. Effaceable Storage • Region of flash memory • Facilitates storage of small amounts of data with ability to quickly erase them • Items within effaceable storage are called lockers • As of iOS 4: 960 bytes capacity, 3 lockers: • ‘BAG1’ – systembag.kb payload key and IV • ‘Dkey’ – NSProtectionNone class master key • ‘EMF!’ – Filesystem encryption key 12
  • 13. Unlocking Keybag Passcode Key Device Key if (WRAP & 0x2) if (WRAP & 0x1) Keybag (locked) Keybag (unlocked) Protected Key DECRYPT Key WRAP = 1 Protected Key UNWRAP Key WRAP = 2 Protected Key UNWRAP DECRYPT Key WRAP = 3 Protected Key DECRYPT Key WRAP = 1 Protected Key UNWRAP DECRYPT Key WRAP = 3 ... ... 13
  • 14. Escrow Keybag • “Usability feature” • Allows iTunes to unlock the device • Contains same master keys as system keybag • Created when device (unlocked) is connected to the iTunes for the first time • Stored on the computer side • Protected by 256 bit random “passcode” • “Passcode” is stored on the device • Escrow keybag gives same powers as knowing the passcode 14
  • 15. iOS 4 Key Hierarchy Must be done on the device Passcode UID Key KDF EMF Key Decrypt Key 89B Key 835 Passcode Key Effaceable Storage ‘EMF!’ System Keybag (locked) ‘Dkey’ Class A Key (#1) ‘BAG1’ Unlock Class B Key (#2) Class C Key (#3) Class D Key (#4) Class Key #5 systembag.kb Decrypt System Keybag … (unlocked) Class Key #11 15
  • 16. iOS 4 Key Hierarchy Must be done on the device Passcode Required to decrypt files/keychain UID Key KDF EMF Key Decrypt Key 89B Key 835 Passcode Key Effaceable Storage ‘EMF!’ System Keybag (locked) ‘Dkey’ Class A Key (#1) ‘BAG1’ Unlock Class B Key (#2) Class C Key (#3) Class D Key (#4) Class Key #5 systembag.kb Decrypt System Keybag … (unlocked) Class Key #11 16
  • 17. iOS 4 Key Hierarchy Must be done on the device Passcode Required to decrypt files/keychain Sufficient for key reconstruction UID Key KDF EMF Key Decrypt Key 89B Key 835 Passcode Key Effaceable Storage ‘EMF!’ System Keybag (locked) ‘Dkey’ Class A Key (#1) ‘BAG1’ Unlock Class B Key (#2) Class C Key (#3) Class D Key (#4) Class Key #5 systembag.kb Decrypt System Keybag … (unlocked) Class Key #11 17
  • 18. iOS 4 Key Hierarchy Must be done on the device Passcode Required to decrypt files/keychain Sufficient for key reconstruction UID Key KDF EMF Key Decrypt Key 89B Key 835 Passcode Key Effaceable Storage ‘EMF!’ System Keybag (locked) ‘Dkey’ Class A Key (#1) ‘BAG1’ Unlock Class B Key (#2) Class C Key (#3) Class D Key (#4) Class Key #5 systembag.kb Decrypt System Keybag … (unlocked) Class Key #11 18
  • 19. iOS 4 Key Hierarchy Must be done on the device Passcode Required to decrypt files/keychain Sufficient for key reconstruction UID Key KDF EMF Key Decrypt Key 89B Key 835 Passcode Key Effaceable Storage ‘EMF!’ System Keybag (locked) ‘Dkey’ Class A Key (#1) ‘BAG1’ Unlock Class B Key (#2) Class C Key (#3) Class D Key (#4) Class Key #5 systembag.kb Decrypt System Keybag … (unlocked) Class Key #11 19
  • 20. iOS 4 Key Hierarchy Must be done on the device Passcode Required to decrypt files/keychain Sufficient for key reconstruction UID Key KDF EMF Key Decrypt Key 89B Key 835 Passcode Key Effaceable Storage ‘EMF!’ System Keybag (locked) ‘Dkey’ Class A Key (#1) ‘BAG1’ Unlock Class B Key (#2) Class C Key (#3) Class D Key (#4) Class Key #5 systembag.kb Decrypt System Keybag … (unlocked) Class Key #11 20
  • 21. iOS 4 Key Hierarchy Must be done on the device Passcode Required to decrypt files/keychain Sufficient for key reconstruction UID Key KDF EMF Key Decrypt Key 89B Key 835 Passcode Key Effaceable Storage ‘EMF!’ System Keybag (locked) ‘Dkey’ Class A Key (#1) ‘BAG1’ Unlock Class B Key (#2) Class C Key (#3) Class D Key (#4) Class Key #5 systembag.kb Decrypt System Keybag … (unlocked) Class Key #11 21
  • 22. Pre-iOS 4 Passcode • Lockscreen (i.e. UI) is the only protection • Passcode is stored in the keychain • Passcode itself, not its hash • Can be recovered or removed instantly • Remove record from the keychain • And/or remove setting telling UI to ask for the passcode 22
  • 23. 23
  • 24. iOS 4 Passcode • Passcode is used to compute passcode key • Computation tied to hardware key • Same passcode will yield different passcode keys on different devices! • Passcode key required to unlock all but 3 master keys in system keybag • Most files are NSProtectionNone thus don’t need passcode • Most keychain items are accessible WhenUnlocked or AfterFirstUnlock thus DO require passcode 24
  • 25. iOS 4 Passcode • Passcode-to-Key transformation is slow • Offline bruteforce currently not possible • Requires extracting hardware key • On-device bruteforce is slow •2 p/s on iPhone 3G, 7 p/s on iPad • System keybag contains hint on password complexity 25
  • 26. iOS 4 Passcode • 0 – digits only, length = 4 (simple passcode) 26
  • 27. iOS 4 Passcode • 0 – digits only, length = 4 (simple passcode) • 1 – digits only, length != 4 27
  • 28. iOS 4 Passcode • 0 – digits only, length = 4 (simple passcode) • 1 – digits only, length != 4 • 2 – contains non-digits, any length 28
  • 29. iOS 4 Passcode • 0 – digits only, length = 4 (simple passcode) • 1 – digits only, length != 4 • 2 – contains non-digits, any length Can at least identify weak passcodes 29
  • 30. Demo 30
  • 31. Pre-iOS 4 Keychain • SQLite3 Database, only passwords are encrypted • All items are encrypted with the device key (0x835) and random IV • Key is unique for each device and is fixed for lifetime of the device • Key can be extracted (computed) for offline use • All past and future keychain items from the device can be decrypted using that key Encrypted with Key 0x835 IV Data SHA-1 (Data) 0 16 31
  • 32. iOS 4 Keychain • SQLite3 Database, only passwords are encrypted • Available protection classes: • kSecAttrAccessibleWhenUnlocked (+ ...ThisDeviceOnly) • kSecAttrAccessibleAfterFirstUnlock (+ ...ThisDeviceOnly) • kSecAttrAccessibleAlways (+ ...ThisDeviceOnly) • Random key for each item • Item key is protected with corresponding protection class master key 0 Class Wrapped Item Key Encrypted Item 0 4 8 48 32
  • 33. Pre-iOS 4 Storage • No encryption before iPhone 3GS • Starting with iPhone 3GS: • Encryption uses EMF key for everything • Provides fast wipe, not confidentiality • Transparent to applications • Filesystem acquisition is not affected 33
  • 34. iOS 4 Storage • Available protection classes: • NSProtectionNone • NSProtectionComplete • If no protection class is specified, EMF key is used • Filesystem metadata and unprotected files • Transparent encryption and decryption (same as pre-iOS 4) • If protection class is specified, per-file random key is used • Key protected with master key is stored com.apple.system.cprotect extended attribute 34
  • 35. iOS 4 Storage • Acquired raw image has everything decrypted with EMF key • Filesystem metadata is OK • File contents are not • Restoring file data requires reverse transformations: • Encrypt with EMF key to get correct ciphertext • Decrypt with file key to get plaintext 35
  • 36. iOS 4 Forensics Must be done on the device Passcode Required to decrypt files/keychain Sufficient for offline key reconstruction UID Key KDF EMF Key Decrypt Key 89B Key 835 Passcode Key Effaceable Storage ‘EMF!’ System Keybag (locked) ‘Dkey’ Class A Key (#1) ‘BAG1’ Unlock Class B Key (#2) Class C Key (#3) Class D Key (#4) Class Key #5 systembag.kb Decrypt System Keybag … (unlocked) Class Key #11 36
  • 37. iOS 4 Forensics • Acquiring disk image is not enough for iOS 4+ • Content protection keys must also be extracted from the device during acquisition • Effaceable Storage contents are also needed to decrypt dd images. • Passcode or escrow keybag is needed for a complete set of master keys • In real world it might be a good idea to extract source data and compute protection keys offline 37
  • 38. Conclusion • iPhone physical analysis is possible again • Physical acquisition requires boot-time exploit • Passcode is usually not a problem • Both proprietary and open-source tools for iOS 4 forensics available 38
  • 40. iOS Forensics: Overcoming iPhone Data Protection a.belenko@elcomsoft.com @andreybelenko www.elcomsoft.com 40