exfiltrated entropy
Original Writeup on seall.dev
We are given a server.py, client.py, params.py and a PCAP.
We are given some initial parameters:
a = 0xa1d41ebef9c575ac113fcfd5ac8dbda9
b = 0x8dcf3cf766e0b6c30e753416a70e2367
m = 0x100000000000000000000000000000000
Itโs an LCG encryption system:
class LCG:
def __init__(self):
self.state = SEED
self.a = a
self.b = b
self.m = m
def _next(self):
self.state = (self.a * self.state + self.b) % self.m
return self.state
def generate_key(self, l):
return bytes([self._next() & 0xff for _ in range(l)])
def generate_packet_uuid(self):
return hex(self._next())
def encrypt(self, msg):
key = self.generate_key(len(msg))
return xor(msg, key)
def decrypt(self, msg):
return self.encrypt(msg)
The issue is with every _next it sets the state again, so we can predict it with information with the PCAP and decrypt the message.

The blue is the server, so the id we are seeing is the first self._next() for the string as its sent before the output is encrypted, and we can calculate all future ones for the encrypted string from that, meaning we can decrypt outputs.
The state encryption is made with 3 known params (a, b, and m) and the state from the previous execution.
We can start by making a state calculation function:
def calculate_next_state(S_n,a,b,m):
return (a * S_n + b) % m
The function for key generation is using a new state with a & 0xff for each character in the length of the message, so the key covers the full message. The message is then XORโed with this key.
def decode_and_xor(encoded_message, key):
decoded_message = base64.b64decode(encoded_message)
state = int(key,16)
key_bytes = []
for i in range(len(decoded_message)):
state = calculate_next_state(state, a, b, m)
val = state & 0xff
key_bytes.append(val)
key_bytes = bytes(key_bytes)
return xor(decoded_message, key_bytes)
The message is first base64 decoded, then we convert the hexadecimal state to an integer. For each character in the message the state is calculated and then the key is created in key_bytes. The key is then used with the xor function from the pwn library.
Now that the script works, we can use the id from the 2nd server message and the response from the clientโs 2nd message to decode the output:
import base64
from itertools import product
from pwn import xor
from params import *
def calculate_next_state(S_n,a,b,m):
return (a * S_n + b) % m
def decode_and_xor(encoded_message, key):
decoded_message = base64.b64decode(encoded_message)
state = int(key,16)
key_bytes = []
for i in range(len(decoded_message)):
state = calculate_next_state(state, a, b, m)
val = state & 0xff
key_bytes.append(val)
key_bytes = bytes(key_bytes)
return xor(decoded_message, key_bytes)
key = 'eba14c429a64b2251717da016e096091'
encoded_message = 'Ve7i4H2jQpnQaq2QVgLqprnTCzzM8xLx3TzrV/17HYPvkpZOkcLiOWhXSybh+QMNAie+CTVC7lZ928epBo/yMoQ1KfAlfwBckLny2pSb86i8RcHlz/aG9kEjfNy8ek/VKciP0V+Duq1xT9c5cH/Cl5mzM0I1z3bP4B/CMJMf/2eJKzdt+jucTAz7OwONh3twYB/a/R0nzzBG5iKUZe/SE2wSA8lDHCbh8dOP5DIj2cLR+XiIrooI'
result = decode_and_xor(encoded_message, key)
print(f'Key: {key} -> Decoded XOR Result: \n{result.decode(errors='ignore')}')
$ python3 solve.py
Key: eba14c429a64b2251717da016e096091 -> Decoded XOR Result:
uid=1000(user) gid=1000(user) groups=1000(user),20(dialout),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),106(netdev),110(lpadmin),114(bluetooth),116(scanner)
Yay!
Now decoding the huge output we get the flag.
$ python3 solve.py
Key: 8829affbed23334d34016095627ba065 -> Decoded XOR Result:
0โโโโโ000โโโโโ0โโโโโโโโโโโ0โโโโโโโโโโโ000000โโโ0000000000โโโโโ00000โโโ00โโโโ00โโโโ000000000000000000000000000000000โโโโโ00000000000000000000000000000000000000000000000000000000โโโ00000000000000000000000000000000000โโโโโ0000000000
โโโโโ000โโโโโ0โโโโโโโโโโโโโโโโโโโโโโโโโ0000โโโ0000000000โโโโโ00000โโโ00โโโโโ0โโโโโ00000000000000000000000000000000โโโโโ00000000000000000000000000000000000000000000000000000000โโโ00000000000000000000000000000000000โโโโโ00000000000
0โโโโ0000โโโโ0โ000โโโโ00โ00โโโโ0000โโโโ000โโ00000โโโโโ00โโโโโโโ000โโโโ00โโโโ00โโโโ000000000000โโโโโโโโ0000โโโโโโ00โโโโโโโ00000000000000โโโโโโ000โโโโโโ00โโโโโโโโ000โโโโโ0โโโโโ0โโโโ00โโโโโโโโ0000โโโโโโ000โโโโโโ000โโโโโโโ00000000000
0โโโโโโโโโโโโ00000โโโโ00000โโโโโโโโโโโ00โโโ00000โโโโโ00โโโโโโโ000โโโโโ00โโโโ00โโโโ00000000000โโโโโโโโโโ00โโโโโโโโโโโโโโโ00000000000000โโโโโโโโ0โโโโโโโโโโโโโโโโโโ0โโโโโ0โโโโโ0โโโโโ0โโโโโโโโโโ00โโโโโโโโ0โโโโโโโโ0โโโโโโโโ00000000000
0โโโโโโโโโโโโ00000โโโโ00000โโโโโโโโโโโโโโโโโ000โโโโโโโ000โโโโ00000โโโโ00โโโโ00โโโโ000000000000โโโโ0โโโโ0โโโโ0โโโโ00โโโโ00000000000000โโโโ0โโโ0โโโโ0โโโโ0โโโโ0โโโโ00โโโโ00โโโโ00โโโโ00โโโโ0โโโโ0โโโโ0โโโ0โโโโโโโโ0โโโโ0โโโโ00000000000
0โโโโ0000โโโโ00000โโโโ00000โโโโ0000โโโโ00โโโโ000โโโโโโโ00โโโโ0โโโ0โโโโ00โโโโ00โโโโ000000000000โโโโ0โโโโ0โโโโ0โโโโ00โโโโ0โโโ0000000000โโโโ00โโโโโโโ0โโโโ0โโโโ0โโโโ00โโโโโ0โโโ000โโโโ00โโโโ0โโโโ0โโโโ00โโโโโโโโโโ00โโโโ0โโโโ00000000000
0โโโโโ000โโโโโ0000โโโโโ0000โโโโโโโโโโโ0000โโโโโ0โโโโโโ000โโโโโโโ00โโโโโ0โโโโโ0โโโโโ0โโโโโโโโโ0โโโโ0โโโโโโโโโโโโโ000โโโโโโโ00โโโโโโโโโโโโโโโโโ0โโโโโโโโ00โโโโ0โโโโโ00โโโโโโโ0000โโโโโ0โโโโ0โโโโโโโโโโโโโ0โโโโโโโโ0โโโโโโโโโโ0โโโโโโโโโ
โโโโโ000โโโโโ0000โโโโโ0000โโโโโโโโโโโ000000โโโ0โโโโโโ00000โโโโโ00โโโโโ0โโโโโ0โโโโโ0โโโโโโโโโ0โโโโ0โโโโโ00โโโโโโ00000โโโโโ00โโโโโโโโโ00โโโโโโ000โโโโโโ00โโโโ0โโโโโ0000โโโโโ0000โโโโโ0โโโโ0โโโโโ00โโโโโโ000โโโโโโ000โโโโโโโโ0โโโโโโโโโ0
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000โโโโโ00000000000000000000000000โโโโโ00000000000000โโโโโ000000000โโโโโโโโโ0000โโโโโโโโโ000000000000000000000000000000000000000000000000000000000000โโโ000โโโโโ0000000000000000โโโโโโโ00โโโ000000000000000000000000000000000
0000000000โโโโโ00000000000000000000000000โโโโโ00000000000000โโโโโ000000000โโโโโโโโโโโ00โโโโโโโโโโโ0000000000000000000000000000000000000000000000000000000000โโโ000โโโโโ0000000000000000โโโโโโโโโโโโโโ00000000000000000000000000000000
00โโโโโโ000โโโโโโโโ000โโโโโโ00โโโโโ0โโโโ0โโโโโโโ0000000000000โโโโ00000000โโโ00000โโโ00โโโ00000โโโ0000000000000โโโโโ000โโโโโโ000โโโโโโ00โโโโโ0โโโโ0โโโโโโโโ00โโโโ00โโโโโโโ000โโโโโ0โโโโโโโ000โโโโ00โโโโ0000000000000000000000000000000
0โโโโโโโโ00โโโโโโโโโ0โโโโโโโโโโโโโ0โโโโ0โโโโโโโ00000000000000โโโโ0000000โโโโ000000000โโโโ00000000000000000000โโโโโ000โโโโโโโโ0โโโโโโโโโโโโโ0โโโโ0โโโโโโโโโโโโโโโ0โโโโโโโ000โโโโโ0โโโโ000โโโโโโโ0000โโโโโ00000000000000000000000000000
00โโโโโโโ00โโโโ0โโโโโโโโ0โโโโ0โโโโ0โโโโ000โโโโ000000000000000โโโโ0000000โโโโ000000000โโโโ0000โโโโโ0000000000โโโโโโโ0โโโโโโโโ0โโโโ0โโโ00โโโโ0โโโโ00โโโโ0โโโ00โโโโ000โโโโ00000โโโโ0โโโโ00โโโโโโโ000000โโโ000000000000000000000000000000
0โโโโโโโโ00โโโโ0โโโโโโโโ0โโโโ0โโโโ0โโโโ000โโโโ0โโโ00000000000โโโโ000000โโโโโโ00000โโโโโโโโ00โโโโโ000000000000โโโโโโโโโโโโโโ00โโโโ00โโโ0โโโโ0โโโโ00โโโโ000000โโโโ000โโโโ0โโโ0โโโโ0โโโโ00โโโ000000000โโ00000000000000000000000000000000
โโโโโโโโโโ0โโโโโโโโ0โโโโโโโโ00โโโโโโโโโโ00โโโโโโโ00โโโโโโโโโ0โโโโโโโโโโโ0โโโโโโโโโโโ00โโโโโโโโโโโ00โโโโโโโโโ0โโโโโโ0โโโโโโโโ0โโโโโโโโ00โโโโโโโโโโ0โโโโโ00000โโโโโ00โโโโโโโ00โโโโโโโโโ000โโโ000000โโโ000000000000000000000000000000000
0โโโโโโโโ0โโโโโโโโ000โโโโโโ0000โโโโโโโโ0000โโโโโ00โโโโโโโโโ0โโโโโโโโโโโ000โโโโโโโโโ0000โโโโโโโโโ00โโโโโโโโโ0โโโโโโ000โโโโโโ000โโโโโโ0000โโโโโโโโ0โโโโโ00000โโโโโ0000โโโโโ0000โโโโโโโโ00โโโ000000โโโ0000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000โโโ0โโโโ000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000โโโโโโโโ0000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000โโโโโโ00000000000000000000000000000000000000000000000000
Flag: HTB{still_not_convinced_about_LCG_security?}