3 ms·
Extracting SSH Private Keys From Windows 10 SSH-agent (2018)
- kencausey 6y agoI would argue that the key element is extracting a useful key which appears to have been made possible by an earlier blog from another source (referenced by this blog entry): https://blog.netspi.com/stealing-unencrypted-ssh-agent-keys-from-memory/ https://blog.netspi.com/stealing-unencrypted-ssh-agent-keys-...
- kencausey 6y agoNote that the 2014 blog (with an earlier, now non-functional link) was discussed in 2014: https://news.ycombinator.com/item?id=8065583 https://news.ycombinator.com/item?id=8065583
- teh_klev 6y agoWhilst I don't wish to rain on the author's parade, but from the final screenshot (and what I suspected), they're running these tools as Administrator (root), so they're pretty well elevated privilege-wise. If an attacker has gotten that far on your machine then it's game over even before they start noodling around with the DPAPI to steal keys. I'd love to know (I don't have a suitable machine available at the moment) if they can pull this off as a regular user, my feeling is probably not.
- userbinator 6y agoRaymond Chen had a good article about people who do things like this and call them vulnerabilities: https://devblogs.microsoft.com/oldnewthing/20150923-00/?p=91531 https://devblogs.microsoft.com/oldnewthing/20150923-00/?p=91...
- pletnes 6y agoIf you’re admin, can’t you just rsync the .ssh directory and be done with it?
- speedgoose 6y agoThe private keys can be protected by passphrases.
- crazydoggers 6y agoWhich I can get as admin by installing a program to read your key presses
- Arnavion 6y agoThe key is being read from HKCU. That hive is ACLed to you. You don't need admin to read it, but it also isn't a privilege escalation of any sort since it's your hive to read in the first place.
- jrm4 6y agoSo, then, this still strikes me as bad in a different way, it contributes to the Windows-esque habit of presuming to know whats best for the user -- even when the user is an "administrator." It seems as if the Linux approach is more honest. "You're root? Okay, you can have access to your SSH-keys. Be careful."
- teh_klev 6y agoWell that behaviour can still be configured on Windows with not much effort provided your sysadmins RTFM. It's about how well you secure your machines, regulate behaviour and ensure good platform hygiene, the OS you're running is irrelevant. I speak as a platform agnostic shared hoster guy who managed fleets of Windows and Linux environments, all public facing, and inherited an unholy security mess many years ago, both Windows and Linux, and had to unfuck it all. I could go into detail for the curious.
- azalemeth 6y agoI'm curious. Can you tell us more? While the plural of anecdotes isn't data, I'd like to know some examples of "the good, the bad and the ugly" on both OS fronts.
- formerly_proven 6y ago> It seems as if the Linux approach is more honest. "You're root? Okay, you can have access to your SSH-keys. Be careful." Actually even root will get plenty of permission denied errors on a Linux system configured for security.
- Dylan16807 6y agoThere are three things in the way of getting the keys, and they all seem honest to me. 1. You need admin access to reach the data. 2. The user has to have entered their password to allow DPAPI to unencrypt the data. 3. The data is stored in a binary form because that was the most convenient. The DPAPI stuff wasn't just obfuscation, if that's what you're thinking. The steps you need are going to look roughly the same if you want to access someone's encrypted files on linux. It doesn't transparently decrypt the data, but that's because the encryption isn't built into the registry, not because it's trying to keep it away from you.
- kerng 6y agoThere is an entire research area called offensive security which includes what is possible and what actions stay undetected. Attacker might be root/admin on this machine and gaining access to more creds allows the adversary to move to other machines. So in a sense we know its possible but unless someone abuses these things to demonstrate it, organizations won't care or be able to detect compromises and lateral movement. Real world adversaries do these things, most notably was when Google was throughly compromised by a foreign nation state for instance. Also, it gets even more interesting for malware if its running on a bastion host because then malware has access to all the forwarded keys!
- teh_klev 6y agoI totally take your point, especially the second paragraph, and agree. Maybe it's the deep cynic in me that tends to read these articles as another "oh look Windows bad" write up, rather than analyse what can happen if a stealthy attacker gains access to your machine and covers their footprints. These write ups get passed around in a sensationalised manner with very little thought about or understanding that the OS was functioning correctly given their user privileges.
- djeiasbsbo 6y agoI agree... the whole point is that admin/root can do everything. SSH agent hijacking is as easy as setting the SSH_AUTH_SOCK variable to that of any logged in user. This is why enabling ssh agent forwarding is something that should be evaluated on a per connection basis. You don't want to forward the agent holding your home keys to your work machine where someone else has root access. But then again, the author didn't claim to do anything special, it was just a little demonstration.
- wildmusings 6y agoNote that this is not a vulnerability. You are supposed to be able to extract plaintext secrets with the Data Protection API if you are logged in as the user who the secret belongs to. That is the whole point. I’m not sure the author knows this. He points out that this is useful for post-exploitation data gathering. That is, you’ve already compromised a machine/account and are looking to gather as much potentially useful information as possible. But he puts “securely” in scare quotes, which is not honest because this is secure storage: if you’re not authenticated, the key can’t be read. The encryption key is derived from the user password, so it can’t be defeated by offline reading either.
- Spooky23 6y agoEspecially when you consider that the common practice on Windows is to use less secure alternatives like Putty that are high risk for trojans. Unless they are on smartcards, there's always a way to compromise keys like this.
- TheRealPomax 6y agoThere isn't even a "compromised" situation here: this is literally how it's meant to work. Admin accounts have access to everything, whether that's the registry, or a subdir in your user profile dir. That's the whole point of admin rights. Whether your private key is in a file in an .ssh dir or stored in the registry, admins can always get to them.
- munchbunny 6y agoYou are supposed to be able to extract plaintext secrets with the Data Protection API if you are logged in as the user who the secret belongs to. Yup. It's like saying you're able to read the private key out of ~/.ssh/id_rsa because you're logged in as the user, though with more steps because you need to deserialize the key from the internal representation. If you want this to not be possible even when logged in as the user, then use a hardware token like a smart card or smart-card-capable security key. Could still be useful for post-exploitation as the OP mentions.
- jve 6y ago
- tedunangst 6y agoFor those that don't know, on unix ssh-agent is setgid which should prevent you from attaching to your own process and reading its memory, even as the same user.