Stealing unencrypted SSH-agent keys from memory
netspi.com
netspi.com
Is there something novel about this that I'm missing?
"However, this causes the attacker to have to wait for the target to type in their passphrase. This might be hours, days, or weeks, depending on how often the target logs out. This is why obtaining the SSH key from memory is vital to pivoting to other machines in a speedy fashion."
I'm not sure how you would solve this problem while providing the functionality ssh-agent provides, aside from perhaps a HSM or something.
Also you can get a cheap "HSM" by using a smartcard.
But if you can exploit a specific user's program, you can (usually) inspect the memory of other programs managed by that user. You can actually create security policies so secure that a user who exploits the sshd program can't read from the same user's ssh-agent process memory, but that's not practical for most people.
That said, the article is a good reminder of the risk of keeping decrypted keys in a long-running ssh-agent process.
- if its a server and you copy your private key onto it its likely to be compromised one day and the key reused even thus it was encrypted.. since its decrypted in memory when used. plus keystrokes could be captured. if you use this key elsewhere, all other servers are also compromised now..
- you can keep the key in a hardware token, then even if a laptop is remotely compromised your key - and thus servers you're not currently accessing - are safe. its also a little harder to hijack a connection or silently ask the key (generally its not silent with a token)
Obviously if the attacker has access long enough they'll capture the passphrase and private key eventually, but it would be nice to narrow the window.
Right now the best you can probably do is use a gpg smartcard with the ssh-agent/gpg-agent shim stuff, (random tutorial here: https://github.com/herlo/ssh-gpg-smartcard-config/blob/maste...)
Tomorrow, they'll have to get new certs (automatically, after authenticating to the CA using appropriate means).
Here's a tutorial showing cert-based ssh auth: http://neocri.me/documentation/using-ssh-certificate-authent...
Obviously with secure key storage (smart-card) prohibiting accidental loss of the private key, and a working cert-revocation infrastructure it's not necessary in the first place.
So Kerberos? You can do that with Kerberos and the GSS-API in OpenSSH already.
command="/usr/local/backups/backup_server /etc/snapshot_backup_list",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty,from="10.70.0.0/16" ssh-rsa AAAAB...
I wouldn't worry unduly about protecting the keys themselves - since they need to be accessible for unattended operation, there's not much you can do to prevent them from being accessible to an intruder.I feel like ssh-agent is essential to my life but it's badly designed and I have this nagging feeling it's insecure (and articles like this feed this fear).
ssh-agent isn't insecure, it's just not magic. If an attacker gets root access to a box, they can examine the system's memory, and the memory of ssh-agent necessarily contains the unencrypted private keys.
Edit: if you're really concerned about private keys being exfiltrated, you can always use a smartcard (the OpenPGP card[1] in a Gemalto USB Shell Token[2] works well with SSH). But if the smartcard is online all the time, then an intruder can always simply use the smartcard to SSH wherever they want, even if they can't actually get the private key itself.
[1] http://shop.kernelconcepts.de/product_info.php?products_id=4...
[2] http://shop.kernelconcepts.de/product_info.php?products_id=1...
If the attacker has root-access, like in this article, they could also recover your decrypted private keys from the memory used in active connections. (SSH and SSL both)
Edit: Nevermind, you're talking about ssh, not ssh-agent..
Still, with root it would be trivial to attach a debugger to the daemon, et cetera.
If you're just doing batch jobs, then you could have the script remove keys from ssh-agent when it's done. At a certain point you have to presume the integrity of your machine. Otherwise your password can just be keylogged as you're unlocking key.
Here's an example from 2005, which was presented (iirc) at Defcon as well: http://www.blackhat.com/presentations/bh-usa-05/bh-us-05-boi...
In that case, SSH-Jack would just piggyback on existing (user-level) ssh connections, which is also pretty serious, though that's not as exciting as stealing keys.
then again this as been done since the beginning of times sadly, or excitingly, i dont know :)
any tool that promotes awareness of this inherent issue is good anyway IMO
I don't point it out to engage in the "who was first" thing. But to point out that this is very much an applied attack in the real world. Real attackers (includes "forensics analysts", incase you don't consider them "attackers" too) have been using this technique in malware as well as countermeasures/investigations for quite a while, now.
See: http://www.trapkit.de/research/sslkeyfinder/
https://github.com/emonti/yara-ruby/blob/master/samples/sslk...
http://volatility-labs.blogspot.com/2013/05/movp-ii-21-rsa-p...
EDIT: actually a much earlier discussion is from '98 by none other than Shamir
https://www.cs.jhu.edu/~astubble/600.412/s-c-papers/keys2.pd... [PDF]
Do not copy your private key to other systems.
ssh -A is your friend.
If you really want to do secure SSH hopping, use the ProxyCommand directive with `netcat` in your SSH config.[1]
[1]: http://en.wikibooks.org/wiki/OpenSSH/Cookbook/Proxies_and_Ju...
[1] ssh-agent uses some tricks, like making itself setgid, and/or using prctl(PR_SET_DUMPABLE, 0) on Linux to make its memory undumpable.
Your key belongs on your personal device, and agent forwarding enables you to behave as if your key is everywhere you need it to be.