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:

$ sudo ./keychaindump [*] Searching process 15 heap range 0x7fa809400000-0x7fa809500000 [*] Searching process 15 heap range 0x7fa809500000-0x7fa809600000 [*] Searching process 15 heap range 0x7fa809600000-0x7fa809700000 [*] Searching process 15 heap range 0x7fa80a900000-0x7fa80ac00000 [*] Found 17 master key candidates [*] Trying to decrypt wrapping key in /Users/juusosalonen/Library/Keychains/login.keychain [*] Trying master key candidate: b49ad51a672bd4be55a4eb4efdb90b242a5f262ba80a95df [*] Trying master key candidate: 22b8aa80fa0700605f53994940fcfe9acc44eb1f4587f1ac [*] Trying master key candidate: 1d7aa80fa0700f002005043210074b877579996d09b70000 [*] Trying master key candidate: a0a20000000200f7474d400000700d01a980fa00007f085e [*] Trying master key candidate: 180000000000000000000000000000000000000007000001 [*] Trying master key candidate: 0000b107000001000000803e970aa8710ae567eff7ff0000 [*] Trying master key candidate: 796a63507e6c2a84d9f095fae2896058dfe029cd0f7105da [*] Trying master key candidate: 16ac866d636215c01e337e942f48cfed12d7c45bfab8dbf7 [*] Trying master key candidate: 070020539baab0d1d6a3aa80fa006877ed57f80fa0000000 [*] Trying master key candidate: 88edbaf22819a8eeb8e9b75120c0775de8a4d7da842d4a4a [+] Found master key: 88edbaf22819a8eeb8e9b75120c0775de8a4d7da842d4a4a [+] Found wrapping key: e9acc39947f1996df940fceb1f458ac74b877579f54409b7 xxxxxxx:192.168.1.1:xxxxxxx xxxxxxx:news.ycombinator.com:xxxxxxx xxxxxxx@gmail.com:login.facebook.com:xxxxxxx xxxxxxx@gmail.com:smtp.google.com:xxxxxxx xxxxxxx@gmail.com:imap.google.com:xxxxxxx xxxxxxx@gmail.com:api.heroku.com:xxxxxxx xxxxxxx:www.freechess.org:xxxxxxx xxxxxxx:twitter.com:xxxxxxx xxxxxxx@gmail.com:www.google.com:xxxxxxx xxxxxxx:imap.gmail.com:xxxxxxx ...

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.

Post updated to add sentence about locking and unlocking keychain.