Static key and forward secrecy
Diffie-Hellman is used in two different modes. In ephemeral (DHE) mode, a new secret number is chosen for each session and it is deleted after the session ends. In static mode, the server keeps a single b for years.
What is the difference? In static mode, there is no forward secrecy (perfect forward secrecy). An attacker who compromises the server today and steals b can also decrypt and read all traffic recorded several years ago — because that same single secret number was used in all sessions.
This is exactly what happened: the server's static secret number was leaked, and four old sessions are lying in the archive (arxiv.txt). Each message contains a part of the flag.
Each session was encrypted like this:
import hashlib
def kdf(s: int) -> bytes:
return hashlib.sha256(str(s).encode()).digest() # 32 bayt
s = pow(A_i, b, p) # server tomonda
kalit = kdf(s)
ochiq = bytes(c ^ kalit[i % 32] for i, c in enumerate(shifr))
Concatenate the four parts in order (from 1 to 4): BAYROQ{DH_statik_kalit_<b1><b2><b3><b4>}