A tool to check which keychain items are available to an attacker once an iOS device has been jailbroken

Overview

Keychain Dumper

Usage

All that should be needed to use keychain_dumper is the binary that is checked in to the Keychain-Dumper Git repository. This binary has been signed with a self-signed certificate with a "wildcard" entitlement. The entitlement allowed keychain_dumperaccess to all Keychain items in older iOS released. That support seems to have been removed in more recent releases of iOS. Instead, you must now add explicit entitlements that exist on a given device (entitlements can be app-specific). To help with that, this repository includes a updateEntitlements.sh shell script that can be run on-device to grant keychain_dumper all of the entitlements available on the device. Finally, if you either don't trust this binary or are having trouble dumping Keychain items using the below steps, you may can build the tool from source and manually sign the appropriate entitlments into your build of the keychain_dumper binary.

As an aside, the following directions assume the target device has already been jailbroken.

Upload keychain_dumper to a directory of your choice on the target device (I have used /tmp during testing). Also, once uploaded, be sure to validate that keychain_dumper is executable (chmod +x ./keychain_dumper if it isn't) and validate that /private/var/Keychains/keychain-2.db is world readable (chmod +r /private/var/Keychains/keychain-2.db if it isn't).

Note: iOS 11 devices using Electra (or other jailbreaks) may still require a trick to bypass the native sandbox. Compile the binary with the included entitlements.xml, sign it with the developer account certificate/priv_key and copy the binary to /bin or /sbin (which already allows execution).

If you are using the binary from Git you can attempt to dump all of the accessible password Keychain entries by simply running the tool with now flags

./keychain_dumper

Some keychain entries are available regardless of whether the iOS is locked or not, while other entries will only be accessible if the iOS device is unlocked (i.e. a user has entered their pin). If no Keychain entries are displayed, or if you don't want to trust the provided binary, you may need to rerun the tool after building the application from source. Please see the Build section below for details on how to build and sign the application.

By default keychain_dumper only dumps "Generic" and "Internet" passwords. This is generally what you are interested in, as most application passwords are stored as "Generic" or "Internet" passwords. However, you can also pass optional flags to dump additional information from the Keychain. If you run keychain_dumper with the -h option you will get the following usage string:

Usage: keychain_dumper [-e]|[-h]|[-agnick]
<no flags>: Dump Password Keychain Items (Generic Password, Internet Passwords)
-s: Dump All Keychain Items of a selected entitlement group
-a: Dump All Keychain Items (Generic Passwords, Internet Passwords, Identities, Certificates, and Keys)
-e: Dump Entitlements
-g: Dump Generic Passwords
-n: Dump Internet Passwords
-i: Dump Identities
-c: Dump Certificates
-k: Dump Keys

By default passing no option flags is equivalent to running keychain_dumper with the -gn flags set. The other flags largely allow you to dump additional information related to certificates that are installed on the device.

Building

Create a Self-Signed Certificate

Open up the Keychain Access app located in /Applications/Utilties/Keychain Access

From the application menu open Keychain Access -> Certificate Assistant -> Create a Certificate

Enter a name for the certificate, and make note of it, as you will need it later when you sign keychain_dumper. Make sure the Identity Type is “Self Signed Root” and the Certificate Type is “Code Signing”. You don’t need to check the “Let me override defaults” unless you want to change other properties on the certificate (name, email, etc).

Build It

You should be able to compile the project using the included makefile.

make

If all goes well you should have a binary keychain_dumper placed in the same directory as all of the other project files.

Sign It

First we need to find the certificate to use for signing.

make list

Find the 40 character hex string corresponding to the certificate you generated above. You can then sign keychain_dumper.

CER=<40 character hex string for certificate> make codesign

You should now be able to follow the directions specified in the Usage section above. If you don't want to use the wildcard entitlment file that is provided (or you are runnig more modern versions of iOS that don't support a wildcafrd entitlement), you can also sign specific entitlements into the binary. Using the unsigned Keychain Dumper you can get a list of entitelments that exist on your specific iOS device by using the -e flag. For example, you can run Keychain Dumper as follows:

./keychain_dumper -e > /var/tmp/entitlements.xml

The resulting file can be used in place of the included entitlements.xml file.

Contact & Help

If you find a bug you can open an issue.

Comments
  • keychain_dumper is not finding items on iOS 13.5

    keychain_dumper is not finding items on iOS 13.5

    Hi,

    I am wondering if it's only me (maybe a package I have installed that is causing this), but keychain_dumper is not finding items on iOS 13.5. It does not even prompt for a passcode when I run the tool.

    # ./keychain_dumper -a
    [INFO] No Generic Password Keychain items found.
    [HINT] You should unlock your device!
    [INFO] No Internet Password Keychain items found.
    [HINT] You should unlock your device!
    [INFO] No Identity Keychain items found.
    [HINT] You should unlock your device!
    [INFO] No Certificate Keychain items found.
    [HINT] You should unlock your device!
    [INFO] No Key Keychain items found.
    [HINT] You should unlock your device!
    
    # ls -l /private/var/Keychains/keychain-2.db
    -rw-r--r-- 1 _securityd wheel 1732608 Jun  3 01:13 /private/var/Keychains/keychain-2.db
    

    Tried it with:

    • iPhone X and iPad Pro Gen 2
    • both with iOS version 13.5
    • both jailbroken with checkra1n 0.10.2
    • Used the latest-greatest binary from this repo (~12h old ATM)

    Can someone please confirm/refute this?

    Thanks!

    opened by tileo 47
  • Modified a lot of things tested on iOS 12.1 arm64.

    Modified a lot of things tested on iOS 12.1 arm64.

    • Adapted Key/Cert dumping
    • Fixed errors
    • Added accessible attribute dumping
    • Added ability to dump all Keychain Items of a certain entitlement group
    • Added some colors

    Tested on iOS 12.1 arm64 device.

    opened by mechanico 13
  • Killed: 9 on iOS 5.1.1

    Killed: 9 on iOS 5.1.1

    I just upload "keychain_dumper" via SSH to my iPad 2(it's iPad 2,1) which is running iOS 5.1.1. But once I try to run ./keychain_dumper, It said that "Killed: 9" Then I tried "ldid -S keychain_dumper" and then "./keychain_dumper", I still received a "Killed: 9". I don't have a Mac, so it could be a diffcult thing for me to compile it by myself. So If there is anyway to solve this problem?

    opened by coverxit 8
  • Dumping private key in identity certificates

    Dumping private key in identity certificates

    The tool seems to work great, I was able to dump keychain on a iphone 5S / 7.1.2. However, when dumping identities, the actual private key does not seem to be dumped.

    Example:

    Key
    
    ---
    Entitlement Group: com.apple.apsd
    Label: APSClientIdentity
    Application Label: <20byte identifier>
    Key Class: Private
    Permanent Key: True
    Key Size: 1024
    Effective Key Size: 1024
    For Encryption: False
    For Decryption: True
    For Key Derivation: True
    For Signatures: True
    For Signature Verification: False
    For Key Wrapping: False
    For Key Unwrapping: True
    

    Is it possible to extract the actual 128byte private key DATA also, or am I missing something?

    opened by holiman 7
  • Feature: Add CLI args instead of stdin

    Feature: Add CLI args instead of stdin

    It would be great to be able to script this, but at the moment -s requires user input. Is it possible to change a few of the user args to changes behaviour e.g

    -l : list all entitlements (same as -s but don't ask for 'Select Entitlement Group by Number') -g : dump all entitlements for the group from the numbered list above/ entitlement group ID/name

    Complete process:

    root# keychain_dumper -l
    Entitlement Group [0]: 243LU875E5.com.example.Me
    Entitlement Group [1]: 37CJY58B6M.org.Foo.Bar
    Entitlement Group [2]: 3N5VQ668Y7.com.MyApp
    
    root# keychain_dumper -g 2
    [INFO] 5QRQZ3BQNM.com.MyApp selected.
    

    I would attempt to have a go myself, but make doesn't work for me, separate issue raised.

    opened by bensh 6
  • Accessing keychain items with

    Accessing keychain items with "ThisDevice" protection class

    I received an email from someone asking if I knew how to dump credentials from Google Authenticator, as the user was trying to move to a new phone and had a ton of TOTP codes stored. They noticed that the elements in Google Authenticator weren't accessible. They also mentioned that it appeared these elements had the "ThisDevice" protection class. The full list can be found on https://developer.apple.com/documentation/security/keychain_services/keychain_items/item_attribute_keys_and_values. It wasn't clear to me, but I'm guessing Google is using either kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly or kSecAttrAccessibleWhenUnlockedThisDeviceOnly. I don't see why this would prevent access on the current device, but I'm also not at all familiar with the "ThisDevice" option. It has been a number of years, but I don't recall that being available however many years back when this tool was first written (it very well could have been and I've forgotten though).

    I no longer have a jailbroken phone to test/debug this with. So, I was hoping some recent contributors might have more up to date info about this protection class and whether it is something that we an support or not. /cc @mechanico @0xln @vocaeq

    opened by ptoomey3 6
  • update to build on Yosemite and run on iOS 8

    update to build on Yosemite and run on iOS 8

    Keychain-Dumper is an awesome tool for jailbreaked iOS devices. I made some changes to build on Yosemite and run on iOS 8.

    1. changed Makefile to build more easily
    2. fixed #7
    3. add a build and run gif demo in Readme, for new users.

    Thank you @ptoomey3

    opened by 100apps 6
  • not an issue, but appreciation

    not an issue, but appreciation

    Hi Patrick Toomey,

    I have to say that your code was very helpful to me. I downloaded your binary and ran it on IOS 6 on an iPad 3 where I needed to inspect some of my passwords.

    Worked like a charm, although it was written for IOS 5!

    I would like to send you my warmest thanks - I'm really grateful. Keep up the good work.

    cheers - chris

    opened by ctismer 6
  • issue with make when building

    issue with make when building

    Trying to get a binary that works on iOS 11/12 , so followed the build steps, but it fails on 'make'

    macOS 10.14.6

    $ make
    xcrun --sdk iphoneos --find gcc` -Os -Wimplicit -isysroot `xcrun --sdk iphoneos --show-sdk-path` -arch armv7 -arch armv7s -arch arm64 -c main.m
    main.m:67:10: error: 'launchPath' is unavailable: not available on iOS
        task.launchPath = executablePath;
             ^
    
       note: 
             'launchPath' has been explicitly marked unavailable here
       @property (nullable, copy) NSString *launchPath 
       API_DEPRECATED_WITH_REPLACEMENT("executableU...
                                        ^
       main.m:71:11: error: 'launch' is unavailable: not available on iOS
           [task launch];
                 ^```
    ```/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Versions/C/Headers/NSTask.h:78:1: note: 
             'launch' has been explicitly marked unavailable here
       - (void)launch API_DEPRECATED_WITH_REPLACEMENT("launchAndReturnError:", macos(10.0, API_TO_B...
       ^
       2 errors generated.
       make: *** [main.o] Error 1```
    
    opened by bensh 5
  • iOS 12 support

    iOS 12 support

    This may be a problem with the unc0ver jailbreak (v3.0.0-b46) on iPhone 5s and not a bug in Keychain-Dumper, however trying to run a binary I compiled myself on iOS 12 I'm getting:

    # ./keychain_dumper
    Killed: 9
    

    dmesg output:

    Sandbox: bash(1243) System Policy: deny(1) process-exec* /private/var/root/keychain_dumperSandbox: hook..execve() killing keychain_dumper[pid=1243, uid=0]: (err=1) process-exec denied while updating labe
    
    opened by hubert3 5
  • Symbol not found: _objc_opt_new

    Symbol not found: _objc_opt_new

    #cd /private/var/Keychains/
    #chmod 777 /bin/keychain_dumper
    #/bin/keychain_dumper > keychain-export.txt
    

    dyld: Symbol not found: _objc_opt_new Referenced from: /bin/keychain_dumper (which was built for iOS 13.5) Expected in: /usr/lib/libobjc.A.dylib in /bin/keychain_dumper Abort trap: 6

    The device info : iOS 12.4 iPhone6

    opened by Humenger 4
  • Build issue _objc_release_x19

    Build issue _objc_release_x19

    Is there a specific version of the iPhone SDK this needs to be built with?

    dyld: symbol '_objc_release_x19' not found, expected in '/usr/lib/libobjc.A.dylib', needed by '/private/var/tmp/./keychain_dumper'

    Getting that error when attempting to to run after building using the latest xcode beta (with ios 16 sdk only). Will attempt using the 14.0.1 sdk, but thought it was worth an ask.

    opened by alijnclarke 2
  • iOS 14.2 - IOS 14.5

    iOS 14.2 - IOS 14.5

    I’ve been successfully dumping some keychain data in iOS 13 but in iOS 14 I’ve been unable to dump the data unfortunately with option -g it did not get me any data. From The same specific application. Any advice on how I can make keychain dumper work on IOS 14?

    kind regards

    opened by SupaYoshi 5
  • which was built for iOS 14.4

    which was built for iOS 14.4

    I used checkra1n to jailbreak the device (iphone 6), after that I ssh into the phone and when trying to execute the executable it spits out this error

    dyld: Symbol not found: _objc_opt_new Referenced from: /private/var/tmp/./keychain_dumper (which was built for iOS 14.4) Expected in: dyld shared cache in /private/var/tmp/./keychain_dumper Abort trap: 6

    Also am I supposed to transfer only the executable or the whole directory?

    opened by FikoKaramac 8
  • Malformed key data Detected

    Malformed key data Detected

    What do i when an app is presenting this?

    Label: (null)
    Accessible Attribute: kSecAttrAccessibleWhenUnlocked, protection level 2 (default)
    Application Label: <>
    Application Tag: <xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
    Key Class: Public
    Key Size: 0
    Effective Key Size: 0
    [INFO] Malformed key data detected. Check/Cleanup KeyChain manually.
    
    opened by VeNoMouS 2
  • iOS 14 keychain_dumper does not work anymore

    iOS 14 keychain_dumper does not work anymore

    keychain_dumper does not work anymore on my iPhoneSE with iOS 14. Following happened:

    iPhone-von-MartinSE:/private/var/Keychains root# ./keychain_dumper -a [INFO] No Generic Password Keychain items found. [HINT] You should unlock your device! [INFO] No Internet Password Keychain items found. [HINT] You should unlock your device! [INFO] No Identity Keychain items found. [HINT] You should unlock your device! [INFO] No Certificate Keychain items found. [HINT] You should unlock your device! [INFO] No Key Keychain items found. [HINT] You should unlock your device! iPhone-von-MartinSE:/private/var/Keychains root#

    Although the device is unlocked, jailbroken (by checkra1n), and the keychain_dumper is executable. The command 'keychain_dumper -e' does work, but 'keychain_dumper -s' and entering a number causes the same result as above.

    opened by martin-1337 6
Releases(1.1.0)
Owner
Patrick Toomey
Product Security Engineer at GitHub
Patrick Toomey
Valet lets you securely store data in the iOS, tvOS, or macOS Keychain without knowing a thing about how the Keychain works. It’s easy. We promise.

Valet Valet lets you securely store data in the iOS, tvOS, watchOS, or macOS Keychain without knowing a thing about how the Keychain works. It’s easy.

Square 3.8k Jan 4, 2023
UICKeyChainStore is a simple wrapper for Keychain on iOS, watchOS, tvOS and macOS. Makes using Keychain APIs as easy as NSUserDefaults.

UICKeyChainStore UICKeyChainStore is a simple wrapper for Keychain that works on iOS and OS X. Makes using Keychain APIs as easy as NSUserDefaults. Lo

Kishikawa Katsumi 3.1k Dec 28, 2022
Keychain - Keychain wrapper with swift

Keychain wrapper. Store a value as a generic password: let account = "an-arbitra

Alejandro Ramirez 0 Mar 14, 2022
Simple Swift wrapper for Keychain that works on iOS, watchOS, tvOS and macOS.

KeychainAccess KeychainAccess is a simple Swift wrapper for Keychain that works on iOS and OS X. Makes using Keychain APIs extremely easy and much mor

Kishikawa Katsumi 7.2k Jan 5, 2023
Simple Objective-C wrapper for the keychain that works on Mac and iOS

SAMKeychain SAMKeychain is a simple wrapper for accessing accounts, getting passwords, setting passwords, and deleting passwords using the system Keyc

Sam Soffes 5.4k Jan 8, 2023
A simple wrapper for the iOS Keychain to allow you to use it in a similar fashion to User Defaults. Written in Swift.

SwiftKeychainWrapper A simple wrapper for the iOS / tvOS Keychain to allow you to use it in a similar fashion to User Defaults. Written in Swift. Prov

Jason 1.5k Jan 8, 2023
Example of using TOTP with iCloud Keychain in iOS 15

Installation This example needs Ngrok and Ruby 3.0.3+. Setup project with Makefi

Makeeyaf 0 Dec 31, 2021
A powerful, protocol-oriented library for working with the keychain in Swift.

Locksmith A powerful, protocol-oriented library for working with the keychain in Swift. ?? iOS 8.0+ ?? Mac OS X 10.10+ ⌚️ watchOS 2 ?? tvOS ?? I make

Matthew Palmer 2.9k Dec 21, 2022
A keychain wrapper that is so easy to use that your cat could use it.

A keychain wrapper that is so easy to use that your cat could use it.

HyperRedink 71 Oct 15, 2022
Modern Swift wrapper for Keychain Services API with the benefits of static typing

SwiftyKeychainKit SwiftyKeychainKit is a simple Swift wrapper for Keychain Services API with the benefits of static typing. Define your keys in one pl

Andriy Slyusar 18 Jan 1, 2023
Recover lost keychain passwords with swift

brutalkeychain Recover lost keychain passwords using a simple swift script (so c

Charles Edge 9 Sep 12, 2022
Recover lost keychain passwords with swift

brutalkeychain Recover lost keychain passwords using a simple swift script (so c

Charles Edge 4 Dec 24, 2021
Simple class to check if app has been cracked, being debugged or enriched with custom dylib

iOS-App-Security-Class Simple class to check if iOS app has been cracked, being debugged or enriched with custom dylib and as well detect jailbroken e

Unhandled Exception 74 Mar 11, 2022
A super easy way to check if the installed app has an update available. It is built with simplicity and customisability in mind and comes with pre-written tests.

UpdateAvailableKit This is UpdateAvailableKit: a super easy way to check if the installed app has an update available. It is built with simplicity and

Swapnanil Dhol 22 Jan 5, 2023
Implemented MVVM-C (Coordinator) architecture pattern for the project. Which is satisfying SOLID principles altogether. Protocol oriented development has been followed.

BreakingBad BreakingBad API doc Implemented MVVM-C (Coordinator) architecture pattern for the project. Which is satisfying SOLID principples altogethe

Dhruvik Rao 2 Mar 10, 2022
It's a pet project which has been developed as a code challenge

What is it ❓ It's a pet project which has been developed as a code challenge. It's written purely in Swift without using 3rd party frameworks. You can

iMamad 1 Apr 23, 2022
A Layer-2 framework built over Keychain API which helps in using Keychain in all your Apple devices with easiness and flexibility.

Keychain Manager Keychain Manager is a Layer-2 framework built over Keychain API which helps in using Keychain in all your Apple devices with easiness

Gokul Nair 14 Jan 1, 2023
A UICollectionViewLayout subclass displays its items as rows of items similar to the App Store Feature tab without a nested UITableView/UICollectionView hack.

CollectionViewShelfLayout A UICollectionViewLayout subclass displays its items as rows of items similar to the App Store Feature tab without a nested

Pitiphong Phongpattranont 374 Oct 22, 2022
List a collection of items in a horizontally scrolling view. A scaling factor controls the size of the items relative to the center.

CAROUSEL List a collection of items in a horizontally scrolling view. A scaling factor controls the size of the items relative to the center. We speci

Ramotion 557 Dec 31, 2022
365-day-of-code - This repository has been opened for 365 days to code iOS with Swift

365 day of code This repository has been opened for 365 days to code iOS with Sw

Mehmet ateş 17 Jan 3, 2023