From charlesreid1

It is possible to man-in-the-middle an SSH connection.

Here's how.

Background

First, let's discuss how SSH works, then enumerate we'll the different ways of attacking it.

How SSH works

SSH works by creating a secure (SSL) connection between two computers. The process is similar to, but not the same as, the way a browser makes an HTTPS connection.

SSH is ultimately a connection happening at network layer 4 - the transport layer - the TCP layer. SSH sessions are just a series of TCP packets being exchanged. So a MITM attack on SSH looks much like a MITM attack on HTTP, HTTPS, or any other kind of traffic.

Suppose a sheep is connecting to a server. To verify the identity of the server, the server will send its public key (the public "fingerprint" portion of its RSA keys) over to the sheep. (If you encrypt traffic using that public key, only the person in control of the corresponding private key can decrypt it.) The sheep will check whether this is a machine whose hostname or IP address they have connected to before (in .ssh/known_hosts file).

Suppose the sheep has connected to this machine hostname before Then the sheep will compare the public key that was sent by the server to the public key that the sheep saw previously (and recorded in a file). If the two match, it means it's the same machine as before, and the sheep trusts it. The sheep will proceed with the SSH connection. If the public keys do not match, you'll see a big warning message about a possible man-in-the-middle attack, or someone trying to do something nasty. This is because the public key has changed - the same hostname now leads to a different machine. To bypass the message, the sheep must explicitly remove the existing entry from their known hosts file.

This could happen because of a man-in-the-middle attack - similar to the way an attacker might present a fake certificate that doesn't check out with the domain. Or, it could happen because the IT department rerouted some hostnames to different machines.

SSH MITM attack types

A successful MITM attack on SSH can happen a couple of ways:

  • An attack on the protocol, to downgrade the encryption cipher or SSH/SSL version being used
  • An attack that obtains the sheep's private keys

Protocol Attacks

More on protocol attacks goes here.

Key Attacks

See Man in the Middle/SSH/Key Attacks

Links

Keys Treasure Trove

A treasure trove of keys:

Flags