148 points · by vuln · 8y ago · 63 comments
https://blog.ropnop.com/content/images/2018/05/base64_decode...
https://blog.ropnop.com/content/images/2018/05/base64_decode...
This is probably a good reason to use burner keys for proof of concepts.
All keys used were burner keys anyway.
The only reason I blurred and obfuscated where I could was just for "best practice" not for real security. I knew if I didn't people would comment that I should've ;)
That and following good practise even when not actually necessary due to other mitigations, you obviously hint to less experienced readers what good practise is.
With people discussing reverse-engineering the pixelated images to access the keys, the merits of masks, security, etc it seemed like a lesson worth sharing for everyone's benefit here that an email wouldn't have accomplished.
Stick to the block-of-constant-colour method used in the first few screenshots. It's ugly but safer!
It is helpful for post-exploitation toolkits to have this functionality.
https://man.openbsd.org/ssh-agent:
> The agent will never send a private key over its request channel. Instead, operations that require a private key will be performed by the agent, and the result will be returned to the requester. This way, private keys are not exposed to clients using the agent.
This sounds like a pretty gaping security hole by Microsoft. I would not assume loading private keys to an "ssh-agent" means giving any process (browser, email client etc.) running on the same machine access to the unencrypted values!
It doesn't.
> AFAIK the whole point of ssh-agent is that the private keys are NOT extractable by other processes.
Any process with sufficient privileges (i.e., root) can extract the private key from ssh-agent on Linux as well.
Good time to point out that we open sourced [0] all of this so I have some guesses as to how soleblaze might have "reverse engineered" it :-)
> To do that, we simply start the ssh-agent service (as Administrator) and use ssh-add to store our private key.
Did Microsoft do some major surgery on the ssh-agent program or am I missing something else? If the agent is started as Administrator, why can I connect to it with my user privileges? And if I do, can other users on the same system do so, too, accessing the same set of keys?
[1] https://blogs.msdn.microsoft.com/powershell/2017/12/15/using...
The service itself sometimes controls which user can access which data, but in this case since the encrypted keys are stored in the Current User Registry Hive (NTUSER.DAT) it likely doesn't need to, filesystem permissions handle that.
Plus even if another user gained access to your registry hive, the data is encrypted with your context via the Data Protection APIs.
If somebody finds a flaw in their admin ssh-agent process they potentially have a way to access other people's key or maybe even escalate their privileges.
I actually don't know. I was thinking the same thing. Hopefully they have a good reason, because you're right about the attack surface issue.
Sure, but ssh-agent does not. That's what I was alluding to with "major surgery".
Also, while the encrypted keys are stored in the file system or registry, the agent process necessarily has them in unencrypted form. That's the reason for loading keys into the agent in the first place.
To have an ssh-agent that can run as a privileged system service with multiple unprivileged clients, you need to extend it to have some notion of client identity and per-user key space. The standard OpenSSH ssh-agent doesn't have that. Users run their own instance each and if you can connect to it, you can use the keys loaded into it. All of them.
The agent code at github.com/PowerShell/openssh-portable doesn't look any different to me, at least from a cursory glance.
Thus, the decision to run it as a system service seems odd to me.
edit: are they hooking into the agent as a PKCS11 provider/"smartcard" and the plaintext keys never even hit the agent's in-memory table, to be queried by all connected clients?
No, that's what DPAPI handles. His DPAPI call works because he's decrypting his own credentials.
PS: Also one agent process for all users on machine vs each user running a ssh-agent process
1. You can choose to have the keys encrypted with a password (same for Windows as for Linux)
2. The key, whether encrypted or unencrypted, are for both platforms stored on disk in the user profile (see first screenshot)
3. This talks about ssh-agent, which you can use to cache the the unencrypted key so that you don't have to type the encryption password every time you want to use the key. On Linux, this is just stored in memory, whereas in Windows, it's stored (encrypted) in the registry as well.
https://msdn.microsoft.com/en-us/library/ms995355.aspx#winda...
Other non-administrator users can't read these registry keys, it's encrypted with the login password (as is common with macOS Keychain and GNOME/KDE's credential stores) so even other administrators can't decrypt it.
On Linux, administrators (root) can extract the keys from ssh-agent. This is actually no less secure and usually more secure.
This is a cool demo of how to do it on Windows, and there's a reason the author didn't call it a vulnerability - it's working as designed and this form of attack is outside the intended threat model.
I don't understand how the situation is different. Of course you can extract the keys from a running ssh-agent since the whole point is not having to provide your password every time so they have to have access to the private key one way or an other. How is the situation different on Windows? Surely when the user is logged an administrator with access to the full RAM and storage will be able to piece everything together (like TFA does for instance)?
On the other hand if you really can't trust your admin you have a huge problem anyway, even with a HSM you could be phished very easily.
Actually overall I'd say that this Windows method is slightly less secure because it means that the Windows keychain thingy is a single point of failure, if somebody compromises it they have access to everything including the ssh keys in the registry.
Of course there may be ways to get an even more advanced level of access than administrator, such as the system account, but honestly Windows does lock some things down really hard at the kernel level and Data Protection decryption based on in-RAM credentials might be one. I don't know modern Windows internals to that level.
There's nothing that seems architecturally unsound about how Microsoft implemented this. DPAPI is a reasonable way to protect the keys "at rest" in the registry. The OP was able to extract the keys because he has the credentials for the user from whom he is extracting the keys.
Short of storing the keys in the memory of a dedicated crypto-processor outside the host computer (and performing the cryptographic operations there) the plaintext of the private keys will have to be recoverable to the user.
ssh-agent signs requests, tokens, etc on your behalf. You never see the private key.
Edit: If your point was specifically about this from EvanAnderson's comment
>A user needs to be able to retrieve the plaintext of their SSH private keys.
then the "user" there is the abstract identity used to locate and decrypt the private key, not the human invoking ssh-agent.