Zero Effort Private Key Compromise: Abusing SSH-Agent for Lateral Movement
grahamhelton.com
grahamhelton.com
In my world, I use this routinely, precisely to detect a connection using a hijacked session, as described in the article. It does not detect the agent hijacking itself, it only detects new connections -- it pops up for all connections, both intended and unintended.
I know we're all supposed to do defense in depth, but I confess to having a bit of a jaundiced view of attacks that begin, "first, become root on a machine in the target domain....". Containment is a good idea, but if you're at the point where you're doing containment of compromised root accounts "inside", things have gone pretty far wrong already.
Connecting to a compromised machine with `ssh -A` (agent forwarding) lets the attacker use your credentials for ssh sessions elsewhere. It's almost explained in the man page.
Avoid the agent forwarding and you are fine.
Example scenario:
I'm on my laptop and I use ssh-agent with my key stored on a HSM device. I use it many many times every hour to interact with my git servers and jumping to other machines. It's kn my laptop so I don't want to fiddle with further restrictions.
I also have to ssh on a remote machine where I would like to restrict agent forwarding to only perform for a selected hosts (mostly so I can git pull from private repos)
Can I do this with one agent?
Your private keys are more likely to be compromised when you store them on untrusted systems. SSH-Agent allows you to avoid that risk.
Another mitigation is to use a dedicated agent per private key (or group of keys) to prevent forwarding keys to destinations that don't need them.
SSH agent restriction (ssh-add -h) looks promising, but support isn't widespread and it doesn't cover all use cases.
The article assumes a remote attacker, but the attacker can more easily be your boss or team. Keep this in mind whenever you forward your agent and plan accordingly.
I'm a big fan of tools like secretive[1] that can help solve this problem by using biometrics to shift the UX/security trade-off and thus make it feasible to always require some kind of authentication to sign a token with a key.
I'm not aware of any tools that do the same for Linux, and a quick Google search doesn't turn up much[2]. It does look like you can at least get a notification[3], though.
This could provide another layer of protection on the user's endpoint device in addition the network monitoring called out in the article. Defense in depth, and all that.
[1] https://github.com/maxgoedjen/secretive
[2] https://unix.stackexchange.com/questions/705144/unlock-an-ss...
[3] https://www.insecure.ws/2013/09/25/ssh-agent-notification.ht...
SSH keys are also not “just long passwords” at all.
To start (but it would be a longer discussion), passwords can be captured as you type them into a compromised host, SSH keys can't. Also SSH keys can reside on a security device (TPM, smartcard, HSM, security token, whatever) and this way they can _never_ be captured, barring exploits on those hardware devices, even if your workstation is compromised. Some hardware security devices have features like touch-to-authorize, or even biometrics, for every single usage. SSH keys can be _used_ while unlocked, but not from a compromised remote site (unless you do agent forwarding, which this article is all about), and never captured from there. Passwords have literally _none_ of the above features.
Forwarding usually bad. SSH Keys otherwise good. Passwords so bad they're not worth comparing to anything.
(and yeah, there's stuff even better than SSH keys)
And I'll notice when it's blinking but it shouldn't be and just unplug it :)
Just no.