Live data from Hacker News

Stop MitM on the first SSH connection, on any VPS or cloud provider

joachimschipper.nl

31–40 of 80 posts

Re: Stop MitM on the first SSH connection, on any VPS or cloud provider

#31

I'm supposed to believe MitM with the same exact keypair is somehow possible? Private keys are never exchanged. Did everybody forget how crypto works? Yes you implicitly trust the public key on first login.... then just... immediately compare it with what's on your box? Might as well seal your doors with duct tape to prevent ghosts from entering your home because this is equally effective.

How do you compare? What trusted channel do you use to retrieve the real public key?

Re: Stop MitM on the first SSH connection, on any VPS or cloud provider

#32
post #29

Earlier quoted context omitted.

You get a box and someone is sitting on its IP address (in the middle), proxying to the real one, so everything is getting logged. Other comments say that this mitm stops working when you use public key authentication.

> Other comments say that this mitm stops working when you use public key authentication. It doesn't completely stop working; a MITM can still pretend to be the server, it just can't authenticate to the real server on your behalf. You could be doing all your work in a fake server controlled by the attacker, while the real server sits there untouched.

If that were the case then I don't think the OP approach works either.

Re: Stop MitM on the first SSH connection, on any VPS or cloud provider

#33
post #28
post #4

Earlier quoted context omitted.

Couldn’t the MITM ssh server just forward the client’s fingerprint to the legitimate server? If so, the legitimate server wouldn’t have anything in their logs that would help detect such an attack. OpenSSH does log other telemetry though.

> Couldn’t the MITM ssh server just forward the client’s fingerprint to the legitimate server? The client sends not only the public key, but also a signature, and that signature depends on the output from the key exchange, so it's "bound" to the shared keys negotiated between the client and the server. If the MITM server does separate key exchanges with the client (pretending to be the real server) and the server (pr…

Let me see if I understand correctly: Client takes its own public key and the server's public key and creates this signature.

MITM can take its public key and the client's public key and send the resulting signature to the server instead of forwarding what it received from the client.

Do pretty much the same exact thing: MITM PK + Server's PK -> Client. Now client has a signature as well. The signatures that client and server have are different but that is OK as long as MITM can see and change all communication.

It has been a while since I went through the details of the protocol, so I must be missing something. What is it?

Re: Stop MitM on the first SSH connection, on any VPS or cloud provider

#34
> The technique appears to be new: I haven't found a proper write-up of this, nor of any other provider-independent solution.

Maybe I'm missing something but SSH already has a built-in solution for this, key-certs. Just sign the server key with a private CA key you trust.

Re: Stop MitM on the first SSH connection, on any VPS or cloud provider

#35
post #31

I'm supposed to believe MitM with the same exact keypair is somehow possible? Private keys are never exchanged. Did everybody forget how crypto works? Yes you implicitly trust the public key on first login.... then just... immediately compare it with what's on your box? Might as well seal your doors with duct tape to prevent ghosts from entering your home because this is equally effective.

How do you compare? What trusted channel do you use to retrieve the real public key?

Public keys go over untrusted channels. That's why they're public.

I'm not confident you understand how crypto works.

You do realize the entire threat model here is a house of cards perched atop someone else's software hosted on someone else's hardware all of which you implicitly trust and discard in favor of some unlikely cloak and dagger interception scheme.

Re: Stop MitM on the first SSH connection, on any VPS or cloud provider

#36
post #31

Earlier quoted context omitted.

How do you compare? What trusted channel do you use to retrieve the real public key?

Public keys go over untrusted channels. That's why they're public . I'm not confident you understand how crypto works. You do realize the entire threat model here is a house of cards perched atop someone else's software hosted on someone else's hardware all of which you implicitly trust and discard in favor of some unlikely cloak and dagger interception scheme.

Public keys can go over channels that an attacker can read. They cannot go over channels that an attacker can modify. (Which would include the SSH connection itself, until such time as you’ve verified the key through a trustworthy channel.)

Re: Stop MitM on the first SSH connection, on any VPS or cloud provider

#37
> inject a temporary SSH host (private) key via cloud-init...

Reading the comments here I'm tempted to believe that if cloud-init is available and if we consider Heztner (and OVH etc.) provides a secure access to cloud-init (i.e. the box running cloud-init is really the box you think it is), then there are many different ways to solve this problem.

Re: Stop MitM on the first SSH connection, on any VPS or cloud provider

#38
post #36

Earlier quoted context omitted.

Public keys go over untrusted channels. That's why they're public . I'm not confident you understand how crypto works. You do realize the entire threat model here is a house of cards perched atop someone else's software hosted on someone else's hardware all of which you implicitly trust and discard in favor of some unlikely cloak and dagger interception scheme.

Public keys can go over channels that an attacker can read. They cannot go over channels that an attacker can modify . (Which would include the SSH connection itself, until such time as you’ve verified the key through a trustworthy channel.)

A public key is useless without the private key. Which the attacker in this unlikely scenario doesn't have.

So you login the first time and they either match, or they don't. If they don't you start over. The end.

Ignore the fact that most people will probably use the box to host a poorly coded vulnerable service anyway.

Re: Stop MitM on the first SSH connection, on any VPS or cloud provider

#39
post #9

It baffles me why VPS providers don't display the fingerprints on their dashboards or expose them through the API.

A few do. Though a more common way of securing the loop is to take the desired user public key during the build process. Assuming you trust that the host control panel (or API server) hasn't been hacked, which you are assuming anyway if you trust a host fingerprint given to you that way, that should be as secure. For a small bit of extra assurance, to protect from an extra very unlikely attack, generate a new key pai…

AFAIK this is not secure. The SSH protocol doesn’t require the server to know the client’s public key for the connection to succeed. Instead, the client actively sends its public key to the server while authenticating, and the server just decides whether to allow a connection or not. OpenSSH will typically match the client’s key against a fixed list of keys, but nothing stops a rogue server from allowing connections from any client key. In fact, OpenSSH itself can be configured to do this using AuthorizedKeysCommand.

Re: Stop MitM on the first SSH connection, on any VPS or cloud provider

#40

but how real is this threat? you buy a box from hetzner or some VPS provider and its rooted when you try to ssh ?

The box itself is probably fine. It's the path between you and it. In shared infrastructure one compromised hop somewhere upstream is enough and now you're SSHing into the wrong thing without realizing it.
Post reply on HN