News for hackers. Stuff that matters.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by aidenn0 on Wednesday July 19, 2023 @02:05PM (#36790649)
Even without this announcement, friends don't let friends forward their ssh agent. It essentially grants that machine access to your private keys. A RCE vulnerability is strictly worse than key exposure, but you probably shouldn't have been using it anyways.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by willbicks on Wednesday July 19, 2023 @02:17PM (#36790842)
I prefer using hardware tokens (in most cases a PKCS#11 smart card) because it means that even with a forwarded SSH agent, every request to use my private key requires a PIN on my client which is verified by the isolated cryptographic processor. It's impossible for my private key to leave that card and get cached anywhere else. While I haven't enabled it on my Yubikey I understand they can do similar.

The downside is that compatibility in edge cases, while much better than I'd expect, is still not perfect. In particular Windows support outside of Putty gets challenging.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by throwawaaarrgh on Wednesday July 19, 2023 @02:41PM (#36791232)
or you could just use the -c option to ssh-add and be prompted every time the key is handed over
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by gorkish on Wednesday July 19, 2023 @02:30PM (#36791063)
The RCE is related to ssh-agent's support for PKCS#11, so, yeah you are right this is a valid method to prevent key access or theft via the agent (I also have to approve every use of my PK), but in this case it's not protecting against the RCE, and the workaround in the meantime is to disable PKCS#11 `ssh-agent -P ''`
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by toast0 on Wednesday July 19, 2023 @04:12PM (#36792499)
The other downside is it's much harder to do bulk operations against a fleet. It's not reasonable to enter a PIN for each access when you need to push something to 1000 nodes. 100 nodes is probably ok, but not great.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by gunapologist99 on Wednesday July 19, 2023 @04:23PM (#36792673)
That won't save you for this RCE!
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by themoonisachees on Thursday July 20, 2023 @05:26AM (#36798406)
It will save his keys though. It's a start.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by gunapologist99 on Thursday July 20, 2023 @12:40PM (#36803118)
It is a start, true, but it's already game over: if I can execute code on your box, then the keys are the least of the treasures I've uncovered.

I can initiate connections, keylog, request or hide confirmations, steal all your other data, piggyback on your authorized SSH connections, etc.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by aidenn0 on Wednesday July 19, 2023 @08:37PM (#36795516)
ssh-agent forwarding does have some use cases with hardware keys. However, most people aren't using hardware keys.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by starfallg on Wednesday July 19, 2023 @02:15PM (#36790804)
Yup, and this is explained in detail in the ssh(1) man page. No-one should be using -A. Using a jump host via -J is the way to go.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by Arnavion on Wednesday July 19, 2023 @02:19PM (#36790864)
One use of -A, namely using the ssh server as a jumphost, is covered by -J. The general use of -A, namely doing operations on the ssh server that require keys from the ssh client, is not.

If I'm on machine foo and I want to connect to bar.example.org and clone a git repo there from baz.example.org, and baz.example.org requires an identity key that is in foo's ssh agent, then -A is the only option.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by GauntletWizard on Wednesday July 19, 2023 @02:29PM (#36791036)
ssh-askpass is a great tool in these situations. It intercedes and allows you to manually control all key usage attempts.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by devnullbrain on Wednesday July 19, 2023 @02:56PM (#36791452)
Ah, a skillful execution of Cunningham's Law
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by Arnavion on Wednesday July 19, 2023 @03:03PM (#36791554)
I'm not sure what relevance ssh-askpass has to what I wrote.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by GauntletWizard on Wednesday July 19, 2023 @05:15PM (#36793515)
Right, this recipe isn't well known.

`ssh-add -c` will cause your ssh agent to pop up with ssh-askpass every time it does an authentication. This is fiddly; You need to have configured your ssh-agent right, and there's a slightly different version to use keychains on macos that's equivalent.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by Arnavion on Wednesday July 19, 2023 @06:44PM (#36794536)
Once again, I'm not sure what relevance this has to the discussion.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by pritambaral on Thursday July 20, 2023 @05:48AM (#36798501)
Some people denounce all use of agent forwarding because, by default, ssh-agent doesn't confirm with the user before signing a request with the users private key. This means, if you ssh into a compromised/malicious host with your agent forwarded, malicious code on that machine can just silently ssh into other servers as you.

This trick has been used in the past by blackhats to escalate from a compromised CI environment to full production takeover.

GauntletWizard probably meant to respond to your parent in this thread.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by gunapologist99 on Wednesday July 19, 2023 @04:25PM (#36792692)
No, you might as well copy the keys over there for all the security you're getting (actually, that's safer given this RCE which compromises both sides, even given that there's no real way to shred the leaked key, but of course I'm not actually suggesting this! they're both really bad.)

Your best option is too easy: just generate a new keypair on foo.

Then you can populate baz.example.org with that public key instead of your own.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by Arnavion on Wednesday July 19, 2023 @05:07PM (#36793397)
>No, you might as well copy the keys over there

Only if the keys are insecure enough to be copied, ie not backed by an HSM, or backed by an HSM but marked exportable.

>for all the security you're getting (actually, that's safer given this RCE which compromises both sides, even given that there's no real way to shred the leaked key, but of course I'm not actually suggesting this! they're both really bad.)

Connecting to a malicious SSH server is already dangeorous with or without this vulnerability, and with or without agent forwarding. Eg a malicious server can modify the shell to emit VT codes to mess up your terminal.

>Your best option is too easy: just generate a new keypair on foo.

Sure, but this creates additional identities that baz.example.org must be taught to trust, which is not always desirable or even an option.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by gunapologist99 on Wednesday July 19, 2023 @05:23PM (#36793627)
> Only if the keys are insecure enough to be copied, ie not backed by an HSM, or backed by an HSM but marked exportable.

Agent forwarding forwards the keys insecurely. If you can launch an agent-forwarded connection, then the HSM is already irrelevant.

> "Connecting to a malicious SSH server" is already dangeorous with or without this vulnerability, and with or without agent forwarding. Eg a malicious server can modify the shell to emit VT codes to mess up your terminal.

yes, but messing up your terminal is not an RCE (and you should be able to fix it with stty sane). It's just an annoyance and just tipped you off that obviously there's something wrong there. :) Obviously you should be checking your host keys etc and ideally you woud never accidentally connect to a malicious server.

However, in the unlucky but perhaps inevitable event that you do connect to a malicious server, you shouldn't risk exposing your entire client workstation! (through this or another RCE) or your SSH private keys! (through normal agent forwarding operation) with agent forwarding.

> Sure, but this creates additional identities that baz.example.org must be taught to trust, which is not always desirable or even an option.

A key is not necessarily an identity. Most platforms permit more than one public key to be associated with a user, including github, gitlab, userify, etc.

However, ideally you are correct -- this would result in a new user account that has limited access to only the things it really needs (principle of least privilege).

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by Arnavion on Wednesday July 19, 2023 @06:41PM (#36794503)
>Agent forwarding forwards the keys insecurely. If you can launch an agent-forwarded connection, then the HSM is already irrelevant.

No? ssh-agent works fine with keys that are not exportable from the HSM. By the very definition it's not possible for anything to export the key, ssh-agent or otherwise.

>yes, but messing up your terminal is not an RCE

It has been, and can be again.

https://www.cyberark.com/resources/threat-research-blog/dont...

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by iudqnolq on Thursday July 20, 2023 @01:30AM (#36797163)
That's not an RCE, it's a DoS.

As the article describes most Windows terminal emulators just call SetWindowText when they get the set window title escape code. For some reason Windows implements that function very inefficiently so if it ends up being called in a tight loop your computer can freeze.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by Arnavion on Thursday July 20, 2023 @11:22AM (#36801851)
Read carefully.

>I was searching for a bug in ANSI characters that respond to a change of the window’s title. One of the things I did was check how the previous bugs were exploited. One of them, CVE-2015-8971 (found by Nicolas Braud-Santoni), was a bug in Terminology 0.7.0 that didn’t filter new line (\n) escape character when changing the window title. It allowed you to modify the window title and then re-insert it into the terminal’s input buffer, resulting in arbitrary terminal input, which then caused code execution.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by gunapologist99 on Thursday July 20, 2023 @12:37PM (#36803071)
Vulnerability in your terminal app, not in SSH, but point taken, there is always that possibility.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by drdaeman on Wednesday July 19, 2023 @04:26PM (#36792716)
Another relatively popular use case is pam_ssh_agent_auth for passwordless-but-authenticated sudo. This, by definition, requires agent forwarding.

(I don't use ssh-agent, I use gpg-agent with an SSH socket - I suppose I'm fine?)

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by pritambaral on Thursday July 20, 2023 @05:42AM (#36798476)
There are uses for `-A` that aren't just for jumping into hosts. I work on code in ephemeral containers and need to use git against remote git servers. If I had to use a key local to the container, I'd have to constantly add new keys to my git servers.

Of course, I have secured by agent from abuse. I use gpg-agent as my ssh agent and make it visually confirm every use of my private key.

I even set up those containers to use forwarded GIT_{AUTHOR,COMMITTER}_{NAME,EMAIL} envs. So other people can work on the same container as me and git commits we make are still attributed correctly.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by salawat on Wednesday July 19, 2023 @02:54PM (#36791433)
Real talk though.

How do you manage ssh chaining then? Unique set of keys per user per machine?

Short of scp'ing your private key over from your starting box, I can't really think of another way. Then again, if it's not your box, (you don't own the hardware have sole monopoly of root), you probably shouldn't be ssh'ing from it anyway. I've always held there are no true secrets on a computer... Until multi-billion dollar companies decide to collude anyway.

Anywho, honest question. I'm a big fan of ssh roaming, never realized that ssh-agent was a thing, but after reading this, if I were to use it, I'd most certainly be doing it witout pkcs11 built in. Shotgunning shared libs for side-effects is absolutely mad. Need to slot that into my source code reading list.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by jcotton42 on Wednesday July 19, 2023 @02:58PM (#36791477)
Depending on your usecase, ProxyJump may suffice https://www.redhat.com/sysadmin/ssh-proxy-bastion-proxyjump
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by aidenn0 on Wednesday July 19, 2023 @02:59PM (#36791488)
> How do you manage ssh chaining then

ProxyJump in the .ssh/config file. If your SSH is too old to support ProxyJump, you should probably upgrade, but this works as well:

   ProxyCommand ssh -q -W %h:%p jumpost
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by salawat on Wednesday July 19, 2023 @03:54PM (#36792243)
Noted... Guess I know what I'm doing today!

Edit: Nevermind, tried it, not sufficient for my use case.

I tend to do a lot of mesh-y bouncing around between servers, and -J seems to be more intended for a star/hub&spoke topology. Common ssh priv-key to all machines, or alternatively, a unique set of priv_keys per user per dest machine is about the way to go. You still have privilege escalations to worry about, but thems the breaks.

It's a neat trick, I'll give it that.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by gunapologist99 on Wednesday July 19, 2023 @04:28PM (#36792732)
Just generate a new keypair there on your bounce box then. Don't do -A because this RCE means that not only do you lose your keys, but you lose your laptop, too!
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by lxgr on Wednesday July 19, 2023 @07:02PM (#36794721)
What if you don’t trust the box enough to store a private key, though?
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by themoonisachees on Thursday July 20, 2023 @05:28AM (#36798417)
A box you can't trust to hold your keys could just as easily put a ssh -A command in your bashrc and use your agent to perform stuff on any servers your key is accepted on.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by pritambaral on Thursday July 20, 2023 @09:22AM (#36800053)
Not if your agent supports and is configured to confirm each use. See ssh-add -c.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by aidenn0 on Wednesday July 19, 2023 @04:56PM (#36793227)
It's not limited to star topologies; You can use ProxyJump for any topology that includes fixed routes from a client to a host. Just add a separate host entry for each machine.

4 server example (this assumes your client can connect to only host C) with the following topology:

    C -> B -> A
     \-> D

ssh configuration snippet:

    Host A
      ProxyJump B

    Host B
      ProxyJump C

    Host D
      ProxyJump C
This example is a tree-like topolgy, but you can use host aliases (i.e. add a HostName that is different from the host entry) to define any fixed route to any machine you like.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by saltcured on Wednesday July 19, 2023 @06:52PM (#36794629)
For me, the main use of agent-forwarding is that I need to use a command that expects to use SSH to get between leaf nodes. For example git or rsync CLIs that need to manipulate the local filesystem and tunnel their own protocol over SSH to talk to another remote server.

At times, I've wished for something like uMatrix but for ssh-agent forwarding, so I could have policies for which peer-to-peer authentications should be allowed for which keys and whether these specific uses should require interactive confirmation.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by aidenn0 on Thursday July 20, 2023 @09:13AM (#36799955)
I now have a design in my head for something like that using ssh certificates. Since I have zero use for such a thing I would probably build it wrongly though.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by TechBro8615 on Wednesday July 19, 2023 @03:34PM (#36791976)
I think SSH agent forwarding is a fairly common setup with VSCode Remote, where the developer wants to forward their keys to the remote dev server so that they can perform Git operations using their credentials.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by gunapologist99 on Wednesday July 19, 2023 @04:22PM (#36792659)
Easy fix: generate private keys on the remote dev server and then use those keys instead of your own with git.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by lxgr on Wednesday July 19, 2023 @06:55PM (#36794655)
This exposes your private keys to a potentially less-trusted dev server. It also just doesn’t work with hardware tokens for the same reason.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by TechBro8615 on Wednesday July 19, 2023 @07:12PM (#36794815)
Is it possible to configure SSH agent forwarding to only forward some specific private keys? Although I guess that wouldn't protect you from the root problem of a vulnerable OpenSSH client.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by lxgr on Wednesday July 19, 2023 @07:21PM (#36794909)
> Is it possible to configure SSH agent forwarding to only forward some specific private keys?

Not sure about that, but you can configure it so that it asks you for confirmation before every private key usage, so I suspect you could script a solution around that confirmation mechanism?

> Although I guess that wouldn't protect you from the root problem of a vulnerable OpenSSH client.

Yes – in the end, your SSH client, the terminal emulator it's running in etc. are ultimately software too that could be remotely exploited.

I think in this particular case, there was a certain mismatch of threat expectations between the attack surfaces of ssh (the client, exposed to lots of potentially malicious input) and ssh-agent (mostly accepting input from semi-trusted processes on the same host – except for agent forwarding, of course).

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by jyxent on Wednesday July 19, 2023 @08:44PM (#36795568)
You can restrict keys when added so that they are only available on specific hosts: https://www.openssh.com/agent-restrict.html