Top Banner
iCloud Keychain and iOS 7 Data Protection Andrey Belenko Sr. Security Engineer @ viaForensics Alexey Troshichev @hackappcom founder
61
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: 7.3. iCloud keychain-2

iCloud Keychain and

iOS 7 Data ProtectionAndrey Belenko

Sr. Security Engineer @ viaForensics !

Alexey Troshichev@hackappcom founder

Page 2: 7.3. iCloud keychain-2

What is iCloud?

Page 3: 7.3. iCloud keychain-2

What’s inside?

• Documents

• Photos

• Backups (SMS, application data, etc)

• Keychain

Page 4: 7.3. iCloud keychain-2

Hacker’s view

Page 5: 7.3. iCloud keychain-2

Bruteforce protection?

Page 6: 7.3. iCloud keychain-2

Bruteforce protection?

Page 7: 7.3. iCloud keychain-2

Bruteforce protection?

Page 8: 7.3. iCloud keychain-2

Find My iPhone

Page 9: 7.3. iCloud keychain-2

Brought to you by hackapp.com

!

github.com/hackappcom/ibrute

@hackappcom

Page 10: 7.3. iCloud keychain-2

iCloud KeychainImage: Apple Inc.

Page 11: 7.3. iCloud keychain-2

Motivation

http://support.apple.com/kb/HT4865

Page 12: 7.3. iCloud keychain-2

Intercepting SSL

SSL Proxy (Burp, Charles, …)

Root CA cert Proxy settings

Page 13: 7.3. iCloud keychain-2

Authentication

GET /authenticateAppleID, Password

DsID, mmeAuthToken, fmipAuthToken

icloud.com

Page 14: 7.3. iCloud keychain-2

/getAccountSettings

Page 15: 7.3. iCloud keychain-2

/getAccountSettings

Page 16: 7.3. iCloud keychain-2
Page 17: 7.3. iCloud keychain-2
Page 18: 7.3. iCloud keychain-2

Setup Options

Page 19: 7.3. iCloud keychain-2

The Big Picture

*.keyvalueservice.icloud.com

*.escrowproxy.icloud.com

Keychain items (encrypted) Keybag (encrypted)

Some Secret

Page 20: 7.3. iCloud keychain-2

Key-Value Store• Not new

• Used extensively by many apps e.g. to keep preferences in sync across devices

• iCloud Keychain utilises two stores:

• com.apple.security.cloudkeychainproxy3• Syncing between devices

• com.apple.sbd3 (securebackupd3)• Copy to restore if no other devices

Page 21: 7.3. iCloud keychain-2

Escrow Proxy• New; Designed to store precious secrets

• Need to know iCSC to recover escrowed data

• Need to receive SMS challenge

• Must successfully complete SRP auth

• User-Agent: com.apple.lakitu (iOS/OS X)

Image: mariowiki.com

Page 22: 7.3. iCloud keychain-2

Key-Value Store com.apple.security.cloudkeychainproxy3

S(usrPwd, D2_pub)

S(D2_priv, (D1_pub, D2_pub))

S(D1_priv, D1_pub)S(userPwd, D1_pub)

S(D1_priv, (D1_pub, D2_pub))S(userPwd, (D1_pub, D2_pub))

Page 23: 7.3. iCloud keychain-2

Key-Value Store com.apple.sbd3

Key Description

com.apple.securebackup.enabled Is Keychain data saved in KVS?

com.apple.securebackup.record Keychain records, encrypted

SecureBackupMetadata iCSC complexity, timestamp, country

BackupKeybag Keybag protecting Keychain records

BackupUsesEscrow Is keybag password escrowed?

BackupVersion Version, currently @“1”

BackupUUID UUID of the backup

Page 24: 7.3. iCloud keychain-2

4-digit iCSC [Default]

Page 25: 7.3. iCloud keychain-2

4-digit iCSC [Default]

Random PasswordBL7Z-EBTJ-UBKD-X7NM-4W6D-J2N4

Page 26: 7.3. iCloud keychain-2

4-digit iCSC [Default]

Random PasswordBL7Z-EBTJ-UBKD-X7NM-4W6D-J2N4

Keychain PasswordsyMa9ohCJ

tzzcVhE7

sDVoCnb

Backup KeybagKey 1

Key 2

Key 3

AES-GCM 256 bit

Page 27: 7.3. iCloud keychain-2

4-digit iCSC [Default]

Random PasswordBL7Z-EBTJ-UBKD-X7NM-4W6D-J2N4

Keychain PasswordsyMa9ohCJ

tzzcVhE7

sDVoCnb

Backup KeybagKey 1

Key 2

Key 3

AES-GCM 256 bit

AES-Wrap Keys RFC 3394

Page 28: 7.3. iCloud keychain-2

4-digit iCSC [Default]

Random PasswordBL7Z-EBTJ-UBKD-X7NM-4W6D-J2N4

Keychain PasswordsyMa9ohCJ

tzzcVhE7

sDVoCnb

Backup KeybagKey 1

Key 2

Key 3

AES-GCM 256 bit

AES-Wrap Keys RFC 3394

*.keyvalueservice.icloud.com

Page 29: 7.3. iCloud keychain-2

4-digit iCSC [Default]

Random PasswordBL7Z-EBTJ-UBKD-X7NM-4W6D-J2N4

iCloud Security Code1234 PBKDF2

SHA-256 x 10’000

Keychain PasswordsyMa9ohCJ

tzzcVhE7

sDVoCnb

Backup KeybagKey 1

Key 2

Key 3

AES-GCM 256 bit

AES-Wrap Keys RFC 3394

*.keyvalueservice.icloud.com

Page 30: 7.3. iCloud keychain-2

4-digit iCSC [Default]

Random PasswordBL7Z-EBTJ-UBKD-X7NM-4W6D-J2N4

iCloud Security Code1234 PBKDF2

SHA-256 x 10’000

AES-CBC 256 bit

*.escrowproxy.icloud.com

Keychain PasswordsyMa9ohCJ

tzzcVhE7

sDVoCnb

Backup KeybagKey 1

Key 2

Key 3

AES-GCM 256 bit

AES-Wrap Keys RFC 3394

*.keyvalueservice.icloud.com

Page 31: 7.3. iCloud keychain-2

Secure Remote Password

• Zero-knowledge password proof scheme

• Combats sniffing/MITM

• One password guess per connection attempt

• Password verifier is not sufficient for impersonation

• Escrow Proxy uses SRP-6a

Page 32: 7.3. iCloud keychain-2

Key Negotiationa ← random, A ← g^a

b ← random, B ← kv + g^b

u ← H(A, B) u ← H(A, B)x ← H(SALT, Password)

S ← (B - kg^x) ^ (a + ux)K ← H(S)

S ← (Av^u) ^ bK ← H(S)

Key VerificationM ← H(H(N) ⊕ H(g), H(ID), SALT, A, B, K)

(Aborts if M is invalid)

ID, A

SALT, B

M

H(A, M, K)

Password verifier:!SALT ← randomx ← H(SALT,Password)v ← g^x

Agreed-upon parameters:!H – one-way hash functionN, g – group parametersk ← H(N, g)

Page 33: 7.3. iCloud keychain-2

Key Negotiationa ← random, A ← g^a

b ← random, B ← kv + g^b

u ← H(A, B) u ← H(A, B)x ← H(SALT, Password)

S ← (B - kg^x) ^ (a + ux)K ← H(S)

S ← (Av^u) ^ bK ← H(S)

Key VerificationM ← H(H(N) ⊕ H(g), H(ID), SALT, A, B, K)

(Aborts if M is invalid)

ID, A, SMS CODE

SALT, B

M, SMS CODE

H(A, M, K)

Password verifier:!SALT ← randomx ← H(SALT,Password)v ← g^x

Agreed-upon parameters:!H – SHA-256N, g – RFC 5054 w. 2048-bit groupk ← H(N, g)

Page 34: 7.3. iCloud keychain-2

Escrowed Data Recovery

*Dis

play

pur

pose

s on

ly

Page 35: 7.3. iCloud keychain-2

Escrowed Data Recovery/get_records

List of escrowed records

*Dis

play

pur

pose

s on

ly

Page 36: 7.3. iCloud keychain-2

Escrowed Data Recovery/get_records

List of escrowed records

/get_sms_targetsList of phone numbers*

*Dis

play

pur

pose

s on

ly

Page 37: 7.3. iCloud keychain-2

Escrowed Data Recovery/get_records

List of escrowed records

/get_sms_targetsList of phone numbers*

/generate_sms_challengeOK

*Dis

play

pur

pose

s on

ly

Page 38: 7.3. iCloud keychain-2

Escrowed Data Recovery/get_records

List of escrowed records

/get_sms_targetsList of phone numbers*

/generate_sms_challengeOK

/srp_init [DsID, A, SMS CODE][UUID, DsID, SALT, B]

*Dis

play

pur

pose

s on

ly

Page 39: 7.3. iCloud keychain-2

Escrowed Data Recovery/get_records

List of escrowed records

/get_sms_targetsList of phone numbers*

/generate_sms_challengeOK

/srp_init [DsID, A, SMS CODE][UUID, DsID, SALT, B]

/recover [UUID, DsID, M, SMS CODE][IV, AES-CBC(KSRP, Escrowed Record)]

*Dis

play

pur

pose

s on

ly

Page 40: 7.3. iCloud keychain-2

Escrow Proxy EndpointsEndpoint Description

get_club_cert [?] Obtain certificateenroll Submit escrow record

get_records List escrowed recordsget_sms_targets List SMS numbers for escrowed records

generate_sms_challenge Generate and send challenge codesrp_init First step of SRP protocolrecover Second step of SRP protocol

alter_sms_target Change SMS number

Page 41: 7.3. iCloud keychain-2

Escrow Record

Random PasswordBL7Z-EBTJ-UBKD-X7NM-4W6D-J2N4

iCloud Security Code1234 PBKDF2

SHA-256 x 10’000

AES-CBC 256 bit

*.escrowproxy.icloud.com

Keychain PasswordsyMa9ohCJ

tzzcVhE7

sDVoCnb

Backup KeybagKey 1

Key 2

Key 3

AES-Wrap Keys RFC 3394

AES-GCM 256 bit

*.keyvalueservice.icloud.com

Page 42: 7.3. iCloud keychain-2

Escrow Record

Random PasswordBL7Z-EBTJ-UBKD-X7NM-4W6D-J2N4

iCloud Security Code1234 PBKDF2

SHA-256 x 10’000

AES-CBC 256 bit

*.escrowproxy.icloud.com

Key ← PBKDF2-SHA256(iCSC, 10’000)

EscrowRecord ← AES-CBC(Key, RandomPassword)

Page 43: 7.3. iCloud keychain-2

Escrow RecordKey ← PBKDF2-SHA256(iCSC, 10’000)

EscrowRecord ← AES-CBC(Key, RandomPassword)

Page 44: 7.3. iCloud keychain-2

• This is stored by Apple

Escrow RecordKey ← PBKDF2-SHA256(iCSC, 10’000)

EscrowRecord ← AES-CBC(Key, RandomPassword)

Page 45: 7.3. iCloud keychain-2

• This is stored by Apple

• iCSC is 4 digits by default

Escrow RecordKey ← PBKDF2-SHA256(iCSC, 10’000)

EscrowRecord ← AES-CBC(Key, RandomPassword)

Page 46: 7.3. iCloud keychain-2

• This is stored by Apple

• iCSC is 4 digits by default

Escrow RecordKey ← PBKDF2-SHA256(iCSC, 10’000)

EscrowRecord ← AES-CBC(Key, RandomPassword)

Page 47: 7.3. iCloud keychain-2

• This is stored by Apple

• iCSC is 4 digits by default

Escrow RecordKey ← PBKDF2-SHA256(iCSC, 10’000)

EscrowRecord ← AES-CBC(Key, RandomPassword)

Can you spot the problem yet?

Page 48: 7.3. iCloud keychain-2

Escrow RecordKey ← PBKDF2-SHA256(iCSC, 10’000)

• Offline iCSC guessing is possible

• Almost instant recovery [for default settings]

• iCSC decrypts keybag password

• Keybag password unlocks keybag keys

• Keybag keys decrypt Keychain items

Page 49: 7.3. iCloud keychain-2

Apple, or other adversary with access to stored data, can near-

instantly decrypt “master” password and read synced iCloud

Keychain records !

(for default settings)

Page 50: 7.3. iCloud keychain-2

Setup Options

Page 51: 7.3. iCloud keychain-2

Complex iCSC

Keychain PasswordsyMa9ohCJ

tzzcVhE7

sDVoCnb

Random PasswordBL7Z-EBTJ-UBKD-X7NM-4W6D-J2N4

iCloud Security Codecorrect horse battery staple PBKDF2

SHA-256 x 10’000

AES-CBC 256 bit

Backup KeybagKey 1

Key 2

Key 3

*.escrowproxy.icloud.com

AES-Wrap Keys RFC 3394

AES-GCM 256 bit

*.keyvalueservice.icloud.com

Page 52: 7.3. iCloud keychain-2

Complex iCSC

• Mechanics are the same as with simple iCSC

• Offline password recovery attack is still possible, although pointless if password is complex enough

Page 53: 7.3. iCloud keychain-2

Setup Options

Page 54: 7.3. iCloud keychain-2

Random PasswordBL7Z-EBTJ-UBKD-X7NM-4W6D-J2N4

Keychain PasswordsyMa9ohCJ

tzzcVhE7

sDVoCnb

Backup KeybagKey 1

Key 2

Key 3

AES-Wrap Keys RFC 3394

AES-GCM 256 bit

*.keyvalueservice.icloud.com

iCloud Security Codecorrect horse battery staple PBKDF2

SHA-256 x 10’000

AES-CBC 256 bit

*.escrowproxy.icloud.com

Random iCSC

Page 55: 7.3. iCloud keychain-2

Random PasswordBL7Z-EBTJ-UBKD-X7NM-4W6D-J2N4

Keychain PasswordsyMa9ohCJ

tzzcVhE7

sDVoCnb

Backup KeybagKey 1

Key 2

Key 3

AES-Wrap Keys RFC 3394

AES-GCM 256 bit

*.keyvalueservice.icloud.com

iCloud Security Codecorrect horse battery staple PBKDF2

SHA-256 x 10’000

AES-CBC 256 bit

*.escrowproxy.icloud.com

Random iCSC

Page 56: 7.3. iCloud keychain-2

Random PasswordBL7Z-EBTJ-UBKD-X7NM-4W6D-J2N4

Keychain PasswordsyMa9ohCJ

tzzcVhE7

sDVoCnb

Backup KeybagKey 1

Key 2

Key 3

AES-Wrap Keys RFC 3394

AES-GCM 256 bit

*.keyvalueservice.icloud.com

Random iCSC

Page 57: 7.3. iCloud keychain-2

Random iCSC

• Escrow Proxy is not used

• Random iCSC (or derived key) stored on the device [haven’t verified]

Page 58: 7.3. iCloud keychain-2

Setup OptionsiCloud

Keychain

Keychain Sync

Keychain Backup

Master Password

EscrowNo iCloud Security Code

Random iCloud Security CodeComplex iCloud Security CodeSimple iCloud Security Code

Page 59: 7.3. iCloud keychain-2

Conclusions

Image: Apple Inc.

Page 60: 7.3. iCloud keychain-2

Conclusions

• Trust your vendor but verify his claims

• Never ever use simple iCloud Security Code

• Do not think that SMS Apple sends you is a 2FA

• Yet, iCK is reasonably well engineered although not without shortcomings

Page 61: 7.3. iCloud keychain-2

Thank You! Questions are welcome :-)

!

!@abelenko @hackappcom