Cracking macOS password hashes: dscl, shadow plists, and the keychain
How to pull a macOS login or keychain hash out with dscl, tell the three generations apart, and crack each one with the right hashcat mode and John format.
A Mac carries at least two different crackable artifacts that people lump together as "the macOS hash," and they need different extraction steps and different hashcat modes. Here is how to tell them apart and pull each one correctly.
Three generations of login password hash
Apple has used three incompatible schemes to store the local login password, and the OS version tells you which one you are looking at:
- macOS 10.4-10.6: salted SHA-1, 48 hex characters (8 hex salt + 40 hex digest). This is macOS 10.4-10.6, hashcat mode
122, John formatxsha. - macOS 10.7 (Lion): salted SHA-512, 136 hex characters (8 hex salt + 128 hex digest). This is macOS 10.7, hashcat mode
1722, John formatxsha512. - macOS 10.8 and later: a PBKDF2-HMAC-SHA512 construction with a tunable iteration count, serialized as
$ml$<iterations>$<salt>$<hash>. This is the modern PBKDF2-SHA512 construction, hashcat mode40018. That number is new: the hashcat wiki renumbered the old mode7100to40018as part of its 2025 cleanup of five-digit module IDs, though7100still works as an accepted alias if your build or notes predate the change.
All three live in the local directory service, not in a flat /etc/shadow file the way Linux does it.
Pulling the hash with dscl
Since macOS 10.14, System Integrity Protection blocks even root from reading the directory service's backing plists directly off disk. The supported way around that, which still works as of current macOS releases, is to ask the directory service for the attribute through its own API via dscl:
sudo dscl . -read /Users/jdoe dsAttrTypeNative:ShadowHashData
Run that as root (locally, or from a live/recovery boot if you need to bypass a locked account) and it prints the account's ShadowHashData entry. On 10.8+ that value is base64-encoded binary plist data wrapping the SALTED-SHA512-PBKDF2 dictionary (iterations, salt, and entropy); on 10.4-10.7 systems it is the hex xsha/xsha512 string directly.
Converting the 10.8+ plist blob into something hashcat or John accepts is fiddly to do by hand because the format has changed release to release (notably again in 10.15 Catalina), so in practice people script it or lean on an existing converter: John the Ripper's jumbo build ships mac2john.py for exactly this, and its output format is <user>:$pbkdf2-hmac-sha512$<iterations>.<salt>.<entropy>:<uid>:<gid>:... — keep only the $pbkdf2-hmac-sha512$... field for hashcat's $ml$-prefixed mode 40018 input, or feed the whole line straight to John.
Cracking the login hash
Once you have the hash in the right format, the commands are ordinary:
# macOS 10.4-10.6
hashcat -m 122 -a 0 hash.txt rockyou.txt
john --format=xsha --wordlist=rockyou.txt hash.txt
# macOS 10.7
hashcat -m 1722 -a 0 hash.txt rockyou.txt
john --format=xsha512 --wordlist=rockyou.txt hash.txt
# macOS 10.8+
hashcat -m 40018 -a 0 hash.txt rockyou.txt
john --format=pbkdf2-hmac-sha512 --wordlist=rockyou.txt hash.txt
The three generations age very differently. The 10.4-10.6 salted SHA-1 and 10.7 salted SHA-512 schemes are single-round constructions — fast, GPU-friendly, closer in spirit to the salted hashes covered elsewhere than to a real KDF. The 10.8+ PBKDF2 construction is a genuine key-derivation function with an iteration count baked into the hash, so throughput drops by orders of magnitude and a weak password is still the only realistic way in. Add a rule set for any of the three — wordlists and rules that work covers which ones pull their weight — rather than betting on a blind brute force.
The keychain is a separate target
The login password and the keychain are linked but distinct. macOS derives a key from the login password to protect the user's login keychain (~/Library/Keychains/login.keychain-db), which stores Wi-Fi passwords, saved website and app credentials, and certificates. If you can copy that file off the machine — from a backup, a forensic image, or local access — you do not need the OS at all to attack it.
Extract the hash with John's keychain2john.py against the keychain file:
python2 keychain2john.py login.keychain-db > keychain.hash
That produces a line starting with $keychain$*, matching the macOS keychain format. Crack it at hashcat mode 23100 or with John's keychain format:
hashcat -m 23100 -a 0 keychain.hash rockyou.txt
john --format=keychain --wordlist=rockyou.txt keychain.hash
Recovering the keychain password here is exactly as good as recovering the login password — in practice it usually is the same password, since most users never set a separate keychain password and macOS keeps them in sync automatically.
What this means in practice
If you have sudo or physical/recovery access to a live Mac, dscl plus a converter is the direct path to the login hash. If you only have a disk image, a Time Machine backup, or an exported keychain file, you can skip the login hash entirely and go straight after login.keychain-db with keychain2john.py — it is often the faster win, since keychain files get backed up and copied around far more loosely than the directory service database. Either way, confirm the OS version or the file you are holding before you pick a mode: feeding a 10.8+ $ml$ hash to -m 122 will not crack, it will just reject the line and cost you a debugging session you did not need.