Small subgroup attack
The server operates with a static secret number b and calculates s = A^b mod p for each client. However, it does not check at all the A received from the client — it does not ask whether it belongs to the valid subgroup. This opens the way for a small subgroup attack.
Attack idea. For each small prime divisor q of p-1, it is easy to find an element whose order is exactly q: h = x^((p-1)/q) mod p. If we send such a h to the server as a "public key", it will return h^b mod p — and this value will be just one of q variants.
So for each q we find b mod q by a simple brute force search. Once several qs have been collected, the Chinese Remainder Theorem fully recovers b.
p = 40167493143745308581148297108932034641207127923
p - 1 = 2 * 64433 * 101599 * 115303 * 171539 * 172633 * 898503240609530729603
g = 2
B = 7085201723015972897117026080381749830131540601
Here q₁..q₅ are the five small prime factors in the expansion above; the last large factor is useless for an attack (the subgroup in it is too large). The server's random number generator is weak: the secret number lies in the range b < q₁·q₂·q₃·q₄·q₅, which means the five small moduli together completely determine it. The attack log is in the file jurnal.txt: each line contains the sent h and the s = h^b mod p returned by the server.
Find the server's static secret number b.
Flag: BAYROQ{DH_kichik_guruh_<b>}. Check: must be pow(g, b, p) == B.