MITM Attack on Diffie-Hellman:
In a Man-in-the-Middle attack, an attacker (say, Mallory) intercepts and alters the messages between Alice and Bob:
-
Alice sends her public key
A
to Bob. -
Mallory intercepts
A
and sends her own keyM1 = g^m1 mod p
to Bob. -
Bob replies with his key
B
, which Mallory intercepts and replaces with her keyM2 = g^m2 mod p
and sends it to Alice. -
Now:
-
Alice computes a shared key with
M2
, thinking it’s Bob’s key. -
Bob computes a shared key with
M1
, thinking it’s Alice’s key. -
Mallory computes both shared keys (with
m1
andm2
) and can now decrypt, read, modify, and re-encrypt messages between Alice and Bob without their knowledge.
-
Thus, Mallory has successfully positioned herself between Alice and Bob, undermining the confidentiality of the communication.
How to Prevent MITM in Diffie-Hellman:
To overcome this vulnerability, authentication mechanisms must be employed along with the Diffie-Hellman protocol:
1. Digital Signatures:
-
Alice and Bob sign their public values using their private keys.
-
These signatures are verified by the other party using the sender’s public key.
-
Even if an attacker intercepts and replaces values, they cannot forge valid signatures without the private keys.
2. Public Key Infrastructure (PKI):
-
Use certificates issued by trusted Certificate Authorities (CAs) to authenticate public keys.
-
Ensures that the key really belongs to the stated entity.
3. Use of Authenticated Diffie-Hellman (e.g., STS Protocol):
- The Station-to-Station (STS) protocol combines DH key exchange with public key signatures and encryption to provide mutual authentication and protect against MITM.
4. Use of Pre-Shared Keys (PSK):
- In environments where both parties know a shared secret ahead of time, DH values can be authenticated using Message Authentication Codes (MACs) based on the PSK.
Conclusion:
While the standard Diffie-Hellman protocol provides secure key exchange, it is inherently vulnerable to man-in-the-middle attacks if not combined with an authentication mechanism. To prevent MITM attacks, it is essential to integrate digital signatures, PKI, or authenticated DH variants.