News for hackers. Stuff that matters.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by berkle4455 on Wednesday July 19, 2023 @02:20PM (#36790883)
What's a better solution if you want to be able to SSH across multiple machines? Do you need to always close the current connection to get back to localhost prior to a fresh SSH?

e.g. how would I ssh into foo, and then later into bar, or perhaps pull some code from github onto foo that is authenticated by my key?

    localhost -> foo -> bar
    localhost -> foo -> github access
It seems like the answer is either: a) ssh -A, or b) install my private key on foo.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by slt2021 on Wednesday July 19, 2023 @02:37PM (#36791180)
I use hashi corp's stack: Boundary + Vault for ssh credential injection

https://developer.hashicorp.com/boundary/tutorials/credentia...

it completely replaces the need for bastion hosts and ssh-agent at scale (I'm a hashicorp's paying customer)

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by wahern on Wednesday July 19, 2023 @06:03PM (#36794108)
I wrote a macOS app that supports using Vault Transit Engine keys with OpenSSH, as well as GnuPG and PKCS#11. (OpenSSH is supported via both the agent protocol and PKCS#11.) You can even use an Apple T2 (Secure Enclave) key for peer mTLS authentication to the Vault server. https://www.keymux.com/

Using this teams can share an SSH key without exposing the key; nor do you need to configure certificate PKI, use jump hosts, or otherwise change your existing software or workflows.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by totallywrong on Wednesday July 19, 2023 @02:34PM (#36791120)
You can set up an ssh tunnel on localhost to any port on bar or github via foo.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by cassianoleal on Wednesday July 19, 2023 @02:31PM (#36791074)
As others have pointed out already, JumpHost or -J is the preferred way.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by gunapologist99 on Wednesday July 19, 2023 @04:13PM (#36792517)
I agree!

The Github example complicates things, but the correct solution is actually another key:

Generate a separate private key on foo and place that one in github, ideally per project as a deploy key.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by lxgr on Wednesday July 19, 2023 @07:37PM (#36795041)
Please stop calling this the "correct" solution. It might work for you; it's not a general rule or widely accepted best practice.

Generating a key per host is just a different security model than key forwarding, and arguably a worse one if key forwarding is done defensively (i.e. forward a separate key, with only those permissions you would give to a key present on the connected host itself).

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by pritambaral on Thursday July 20, 2023 @09:29AM (#36800149)
> Generate a separate private key on foo ...

That is a TERRIBLE idea, if foo can be compromised. Even if you secure the private key with a passphrase, it still needs to be loaded into foo's memory, by a binary resident on foo, which can be used to exfiltrate that private key.

If you're confident foo cannot be compromised, then the whole point is moot anyway.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by aberoham on Wednesday July 19, 2023 @02:43PM (#36791272)
Teleport is far and away the leading solution in this area — certificate based end-to-end bastion style topology with many nice features including support for kubectl.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by throwawaaarrgh on Wednesday July 19, 2023 @02:43PM (#36791280)
Make an ssh connection to foo with a port forward. Then make an ssh connection to bar through foo. Keys stay on your machine. I'm pretty sure there's built in features to do this.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by gunapologist99 on Wednesday July 19, 2023 @04:10PM (#36792467)
That won't work for a connection to github that's being initiated from foo.

The best solution in that situation is a separate key that's private to foo.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by lxgr on Wednesday July 19, 2023 @07:34PM (#36795017)
No, the best solution would be partial key forwarding of one or several separate keys only scoped to git access.
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by gunapologist99 on Wednesday July 19, 2023 @04:33PM (#36792832)
Better options:

c) use proxyjump (-J) to access bar (https://www.man7.org/linux/man-pages/man1/ssh.1.html), and/or

d) generate a new private key on foo and use that to access github.

You might think that's a crazy waste of time compared to forwarding, but it's actually much, much safer and actually only takes a moment:

    ssh-keygen -t ed25519
    cat ~/.ssh/id_ed25519.pub
and then just paste that in Github.

See also https://userify.com/docs/jumpbox for more jumpbox docs.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by lxgr on Wednesday July 19, 2023 @07:33PM (#36795001)
> d) generate a new private key on foo and use that to access github.

> [...] only takes a moment [...]

Not every org's policy allows adding unaudited ad-hoc SSH keys.

> [...] much, much safer [...]

Definitely not always, if the hosts you store these keys on are not as hardened as you local machine (or a hardware key connected to it).

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by gunapologist99 on Thursday July 20, 2023 @12:36PM (#36803052)
> Not every org's policy allows adding unaudited ad-hoc SSH keys.

Then audit them and get them in the process. Agent forwarding is too big of a risk.

> Definitely not always, if the hosts you store these keys on are not as hardened as you local machine (or a hardware key connected to it).

Once you use agent forwarding, the keys are no longer protected on your local machine. (Ironically, this RCE is precisely because of the requirement to whitelist hardware keys!)

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by berkle4455 on Wednesday July 19, 2023 @08:03PM (#36795262)
I need to read the source, I’m confused how -J actually works. Is the bastion doing auth and the downstream machines trusting? Or does it auth first and then forwarding a :22 connection from downstream back to localhost? Or something else entirely?
Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by momentoftop on Thursday July 20, 2023 @04:19AM (#36798042)
Just my understanding of the manpage and TCP forwarding (-L): an SSH connection will be established to the jump host, which then establishes a connection on port 22 to the destination. The local machine now has a forwarded connection to the destination and uses that to establish a second SSH connection between them.

Between local and jump host, there will be two layers of encryption. The jump host decrypts the outer layer, and the two ends the inner layer.

Re:Remote Code Execution in OpenSSH’s forwarded SSH-agent by pritambaral on Thursday July 20, 2023 @09:26AM (#36800099)
Just use a different, secure SSH Agent. I use gpg-agent and make it confirm every use of my private keys with me. Gpg-agent supports signing with a preloaded private key and nothing else, so it is immune to this attack and many others.