Share this story

A software developer has released an open-source app for the Mac that, when run with administrator privileges, dumps all the passwords belonging to other people currently logged on to the machine.

Within hours of the release of Keychaindump by Helsinki-based Juuso Salonen, other Mac experts were downplaying its significance. "News flash, root can also format your hard drive, news at 11," OS X serial hacker Charlie Miller wrote on Twitter, referring to the "root" account that by definition has unfettered privileges in operating systems. "Root is totally a dick, he stole my prom date in high school!" another exploit developer known as thegrugq responded.

Their point is that the Keychaindump's ability to root out passwords isn't a vulnerability or even an oversight by Apple engineers. It's a necessary design with parallels that can be found in any advanced operating system, including Microsoft Windows and various distributions of Linux. Labeling it as a "bug" or a "vulnerability" is like claiming a meat slicer is flawed because it can saw through the finger of the person using it.

That said, Salonen's software and an accompanying blog post appear to be the first time anyone has documented the inner workings of the widely used Mac Keychain and released attack code built on those findings. Salonen says his app is "far from perfect," but he also says it "seems to work well" at scouring the internal memory of Macs for the passcodes all currently logged-in account owners enter to access passwords stored on their personal keychains. And that includes the passcode for the root user.

"If I'm writing a virus, I will use this code," said Rob Graham, who as CEO of penetration testing firm Errata Security regularly writes software exploits to test the security of his clients. "We've always known it's possible. It's just a matter of someone actually writing code for that part of the keychain."

One application for such code would be for malware writers who want to collect as much information as possible on the people using a targeted Mac. By dumping the entire contents of a user's keychain, the passwords for virtually every WiFi network, e-mail account, and website account are quickly in the hands of the attacker. With the rise of the Flashback malware that infected an estimated 650,000 Macs or new strains of Mac-based espionage trojans targeting Chinese dissidents, it's not hard to imagine code like Salonen's being employed to give them powerful new capabilities.

What's more, the password extraction method is significantly faster than attempting to brute-force crack a strong account password. That's because OS X stores account passwords using the PBK2F2 key derivation function, which, as Ars recently explained, was designed to thwart cracking attacks by requiring large amounts of time and computing resources to convert plaintext into cryptographic hashes.

"Encrypted many times over," in "Russian-doll fashion"

According to Salonen, keychain files are "encrypted many times over" in a fashion similar to the way one Russian doll fits inside the next. The OS X system uses a variety of keys, including one derived from the account password belonging to the user who owns the password keychain. Once a user has unlocked that list, the password is converted into a 24-byte master key and stored in a part of computer memory reserved for a security process known as "securityd." With a little more research, the developer found a common structure in this memory region that points to the master key. It contains an 8-byte size field with the value of "0x18 (24 in hex)."

Keychaindump uses what's known as pattern recognition to search for the pointer and then test the following value to see if it's a master key. A Master key will reveal an intermediate key called a "wrapping key." Using a hard-coded "obfuscation key," the wrapping key in turn reveals an encrypted "credential key," which, at last, reveals the user's plaintext password. Salonen credited fellow developer Matt Johnston for the research into the decryption steps.

Running the code produced the following output, where actual passwords and usernames were replaced with x's:

As we made clear earlier in this post, there's no vulnerability here. Aside from following longstanding security advice to use lower-privileged accounts whenever possible and log out of those accounts when they're not in use, there's not much anyone can do to prevent these types of attacks. Update: Salonen points out in his blog post users can take additional steps to lock and unlock their keychain; Apple has more here.

None of this, however, means Salonen's app, which runs on OS X Lion and Mountain Lion, isn't of value, either to black-hat hackers or the white-hats who work to stop them.

Cool...I knew there was a reason why I never used Keychain on my Macs.

I use 1password...so I'm waiting for the day when that will be cracked then my myriad of 16+ character jibberish passwords I have strewn across the internet will be rendered useless. Then I'm fucked.

Don't use the same password on different sites. checkDon't use common words or phrases that a dictionary database can brute-force easily. checkUse a password manager to keep track of all those different passwords. Um...sure...unless...um...that gets hacked somehow....um...

There's nothing in Goofball_Jones's post to indicate it was meant to be humorous. The very first sentence shows a fundamental misunderstanding (because this isn't a reason not to use Keychain and no other manager would help) and then it goes on from there. "Lolol cabin in Montana", that's the height of wit on a tech site? Talking about root kits always has potential for some fun technical discussions, disappointing that's missing from both comments and article. Now that I think about it perhaps it would be possible to segment some memory to be off limits for reading even by root without hardware, and protect the kernel as well, but that's over my head beyond speculation.

Reader: "WHERE DO YOU GET OFF CALLING IT DARK IN HERE??!! HYPERBOLE MUCH? CLEARLY THERE IS NOT A COMPLETE ABSENCE OF PHOTONS SINCE I CAN STILL SEE SO AT THE MOST YOU SHOULD CALL IT DIM...THOUGH EVEN THAT IS RELATIVE. WAY TO RESORT TO SENSATIONALISM! I SWEAR...THE QUALITY OF REPORTING ON ARS HAS GONE WAY DOWNHILL EVER SINCE THEY SOLD OUT TO CONDE. THAT'S IT #%$#@ YOU AND YOUR @$#^* SITE. I AM NEVER READING THIS TRIPE AGAIN, @%#@*! THIS WILL BE MY LAST COMMENT EVER!!

Author: ...

Reader: Oh, also, you said 'in' twice. THIS WILL BE MY LAST COMMENT EVER!

Edit: I have accused Ars of sensationalism and poor reporting myself (and stand by my statements) so this is somewhat self-deprecating.