The Challenge
A PCAP file contains an encrypted transmission. The captures also leaks two fixed-format header values (k and l) whose relationship reveals the encryption key. The flag is a long hex blob (f) somewhere in the traffic, also XOR-encrypted with the same key.
Approach
XOR encryption with a repeating key has a known-plaintext attack: if you know any two values that were XOR’d together (a XOR b = c), then knowing a gives you b = a XOR c. Here k and l are two known-format fields from the packet capture. XORing them gives the repeating key r = k XOR l. The flag f then decrypts as f XOR (r * len(f)//len(r)) — tiling the 8-byte key across the full ciphertext length.
f.split(b'\n\n')[1] extracts the flag from the decrypted payload — the actual data lives after a double newline separator.
Solution
|
|
r = xor(l, k) recovers the 8-byte repeating key. r * (len(f)//len(r)) tiles it to match the length of f (integer multiplication on bytes repeats the sequence). The final XOR decrypts entirely in one line. The split(b'\n\n')[1] strips the packet header and leaves the flag.
What I Learned
XOR with a repeating key is trivially broken with two known-plaintext samples of the same length as the key. Real stream cipher security requires at least ensuring the keystream never repeats. Any protocol that puts fixed-format headers in the ciphertext has handed the attacker a crib from which the full key can be derived.