What is a MITM attack and how can you prevent it?

A MITM(Man-in-the-Middle) attack is a type of attack where the hacker places himself in between the communication of two parties in order to steal the information they are sharing with each other.

Suppose there are two parties, A and B, communicating. Then the hacker joins this communication. He impersonates as party B to A and impersonates as party A in front of B. The data from both the parties are sent to the hacker and the hacker redirects the data to the destination party after stealing the data required.

While the two parties think that they are communicating with each other, in reality, they are communicating with the hacker.

You can prevent MITM attack by using the following practices: