Export-grade Diffie-Hellman
In the 1990s, US export laws prohibited the export of strong cryptography, so deliberately weakened "EXPORT" modes were added to protocols: for DH, p was only 512 bits. Even after the law was repealed, these modes remained on servers for years.
In 2015, the Logjam attack showed that a man-in-the-middle can "downgrade" the server to DHE_EXPORT during the TLS handshake — and the client will not notice this because the handshake messages are not protected. And with a small p, the discrete logarithm can be solved.
In our record, p has been made even smaller (42 bits for educational purposes), so it can be cracked even on a regular laptop. Session record: tls_yozuv.txt. The task is to decrypt the HTTP request and read the session cookie.
The session key was derived as follows:
import hashlib
def kdf(s: int) -> bytes:
return hashlib.sha256(str(s).encode()).digest() # 32 bayt
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
s = pow(B, a, p) # DH umumiy sir
shifr = AES.new(kdf(s), AES.MODE_CBC, iv).encrypt(pad(sorov, 16))
Here no secret number is given — you must first solve the discrete logarithm.