As part of my daily routine, I was SSH'ing to one of the corporate servers. However this time I was presented with following message

Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
Please contact your system administrator.
Add correct host key in /Users/<user>/.ssh/known_hosts to get rid of this message.
Offending key in /Users/<user>/.ssh/known_hosts:43
RSA host key for <SERVER> has changed and you have requested strict checking.
Host key verification failed.

Please explain as to MiTM attacks are possible in this scenario.


If an attacker gets control over one of the routers between you and the machine you are connecting to, they can redirect your IP packets to some other machine, which would then claim to be the real target. It might forward both your authentication and the following traffic.

Obviously, that machine would learn your password if you use one, see what you are doing on the remote machine, and could alter all data sent in any directions. Everything a man in the middle attack allows to do (which is different from passively observing the traffic).

  • It isn't obvious to me that my password could be compromised. Surely my SSH client won't transmit my password. Surely my SSH client hashes my password together with some kind of single-use random token that it gets from the server. – nobar Jun 22 '14 at 5:18
  • If you use a password, the server you log in to needs to be sent that password in a form that it can use to check against its /etc/shadow, in whatever form it hashes passwords for that file. Since the server (assuming a standard user account installation) does not know your password in clear text, it cannot ask for some uniquely hashed version in a challenge-response way; the protocol must send the password such that the sshd sees the clear text password. Not a problem usually: ssh can do without passwords, using public keys. – Christopher Creutzig Jun 27 '14 at 5:28

MITM attacks happen to be LAN attacks. When the traffic flows on wire, it uses physical addresses for communications. When you initiate a connection, any connection, let us say SSH connection, then in that case first your machine checks if it knows MAC address of server IP, if knows, starts to send data packets, else, it tries to get the mac address. When you connect for the first time to any ssh server its key is stored on your box. Now coming to MITM, it is manipulation of ARP (poisoning of arp). Means an attacker adds fixious entries in your machine saying IP of server is his mac, now when u connect to your ssh server, your machine opens connection to attacker box and as the fingerprint of server key is different and does not match the previous, you get warning. This does not mean, that this attack cannot be done over different networks, it can be, An attacker just needs to be in the data flow between the client and server.

Being in data flow, an attacker can do anything, get your password in clear test, what u felt encrypted, replay the ssh to server to compromise the server etc etc

  • 1
    MitM attacks can be done not only in local networks via ARP poisoning as you describe. TOR outproxies and proxy servers are other common places for MitM attacks. Finally, there could be all sorts of nasty stuff going on on the network gear between you and the intended machine, because it's rarely patched with security updates and in general nobody really bothers pentesting it. – Shnatsel Dec 10 '13 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.