sensepost / sensepost/objection

[bug] iOS Keychain dump false positive (with source code snippet)

Open
#494 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🐛bug
Dominant language
Python
Stars
9.4k
Forks
1k
Avg merge
14d 5h
Merged PRs (30d)
1

Description

Describe the bug
During an iOS app penetration test, I dumped all keychain entries of the app and noticed "accessible_attribute": "kSecAttrAccessibleAlways", which is deprecated and should be considered a vulnerability for sensitive information in the keychain. After feedback from the developers I've been given the code-snippet where the entry is generated/stored and they undoubtedly configure kSecAttrAccessibleWhenUnlockedThisDeviceOnly for the entry.

I assume this frida/objection reports the wrong accessibility attribute.

To Reproduce
Due to an NDA I can not share the application. The relevant source code (redacted/slightly modified):

private func genSav() throws -> SecKey {
    var error: Unmanaged<CFError>?

    guard let accCtrl = SecAccessControlCreateWithFlags(
        kCFAllocatorDefault,
        kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
        [],
        &error
    )

    var attribs: [String: Any] = [
        kSecAttrKeyType as String: kSecAttrKeyTypeEC,
        kSecAttrKeySizeInBits as String: 256,
        kSecAttrTokenID as String: kSecAttrTokenIDSecureEnclave,
        kSecPrivateKeyAttrs as String: [
            kSecAttrIsPermanent as String: true,
            kSecAttrApplicationTag as String: tag,
            kSecAttrAccessControl as String: accCtrl
        ]
    ]

    guard let genKey = SecKeyCreateRandomKey(attribs as CFDictionary, &error)

    return genKey
}

Expected behavior
I would assume the keychain entry should have been reported as kSecAttrAccessibleWhenUnlockedThisDeviceOnly NOT kSecAttrAccessibleAlways.

Evidence / Logs / Screenshots

objection --debug --gadget "target.app" explore
[debug] Agent path is: /usr/local/lib/python3.9/dist-packages/objection/agent.js
[debug] Injecting agent...
Using USB device `iOS Device`
[debug] Attempting to attach to process: `target.app`
[debug] Unable to find process: `target.app`, attempting spawn
[debug] PID `2825` spawned, attaching...
[debug] Resuming PID `2825`
Agent injected and responds ok!
[...]
target.app on (iPhone: 14.4) [usb] # ios keychain dump
Note: You may be asked to authenticate using the devices passcode or TouchID
Save the output by adding `--json keychain.json` to this command
Dumping the iOS keychain...
Created                    Accessible  ACL  Type          Account  Service  Data
-------------------------  ----------  ---  ------------  -------  -------  ------------------------
2021-datetime +0000  Always           kSecClassKey                    (Key data not displayed)

Environment (please complete the following information):

  • Device: iPhone SE
  • OS: iOS 14.4
  • Frida: 15.1.3
  • Objection: 1.11.0
  • Host OS: Kali Rolling

Application
Unfortunately I can't due to the NDA, see the code-snippet above.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the ios keychain dump command and trace how its Accessible value is obtained for the kSecClassKey entry; compare that output with the supplied Swift SecKeyCreateRandomKey attributes. Done means the dump correctly distinguishes kSecAttrAccessibleWhenUnlockedThisDeviceOnly from kSecAttrAccessibleAlways for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, python, swift
Domain
mobile-dev, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.