Predictable session token
In web applications, a session token is an actual password. If it is obtained from a predictable generator, an attacker can calculate the session of another user, even an admin.
The generator here is a truncated LCG. The internal state is 48-bit, but only the upper 32 bits are shown in the token. That is, after each token, 16 bits remain unknown to us. This is 65,536 variants — one second of work for a computer. It is easy to check a candidate: if our guess is correct, the next token calculated from it will also match the token we have.
Leaked code from the server:
M = 1 << 48
A = 25214903917
C = 11
holat = <maxfiy urugʻ>
def keyingi_token():
global holat
holat = (A * holat + C) % M
return holat >> 16 # 32 bit -> 8 ta hex belgi
# 1-, 2-, 3- tokenlar oddiy foydalanuvchilarga berildi
# 4- va 5- tokenlar admin sessiyasiga tegishli:
kalit = keyingi_token().to_bytes(4, 'big') + keyingi_token().to_bytes(4, 'big')
ct = bytes(b ^ kalit[i % 8] for i, b in enumerate(eslatma))
Captured three consecutive user tokens:
token 1: 5c2b3c69
token 2: 98682cf3
token 3: 94e981ca
In the attached file, the admin note is stored encrypted (in hex format). The key is the 4th and 5th tokens.
Sequence order: token 1 = state_1 >> 16, token 2 = state_2 >> 16, ..., admin key = (token 4) || (token 5), each 4 bytes big-endian.