What is a man-in-the-middle attack (for instance in Diffie-Hellman)? I'm new to cryptography and I just started learning about the Diffie-Hellman key agreement. I read that this system is vulnerable to a man-in-the-middle attack when used alone. What kind of attack is this?
in diffie-hellman key exchange algorithm vulnerability's is good defined by RSA lab :

&quot;The Diffie-Hellman key exchange is vulnerable to a man-in-the-middle attack. In this attack, an opponent Carol intercepts Alice's public value and sends her own public value to Bob. When Bob transmits his public value, Carol substitutes it with her own and sends it to Alice. Carol and Alice thus agree on one shared key and Carol and Bob agree on another shared key. After this exchange, Carol simply decrypts any messages sent out by Alice or Bob, and then reads and possibly modifies them before re-encrypting with the appropriate key and transmitting them to the other party. This vulnerability is present because Diffie-Hellman key exchange does not authenticate the participants. Possible solutions include the use of digital signatures and other protocol variants.&quot;

and some simple example of mitm attack :

Alice &quot;Hi Bob, it's Alice. Give me your key.&quot; →     Mallory     Bob
Alice     Mallory &quot;Hi Bob, it's Alice. Give me your key.&quot; →     Bob
Alice     Mallory     ← [Bob's key] Bob
Alice     ← [Mallory's key] Mallory     Bob
Alice &quot;Meet me at the bus stop!&quot; [encrypted with Mallory's key] →     Mallory     Bob
Alice     Mallory &quot;Meet me in the windowless van on 22nd Ave!&quot; [encrypted with Bob's key] →     Bob