Last active
January 25, 2023 15:24
-
-
Save tkeetch/b1b21f621813ff11a75930f80f1c9e5b to your computer and use it in GitHub Desktop.
Tamuro challenge - Plaintext Checksums
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We know nothing about the contents of these encrypted messages other than it's a stream cipher | |
using the same private encryption key with each message and foolishly, the crc is of the | |
plaintext, not the ciphertext. Extract the keystream and use it to decrypt the secret flag. | |
flag (hex string) = 22360906580dc6f4d26fc4b0d8327932d87cf1 | |
Message Format: stream_cipher(k, msg) || crc32-big_endian(msg) | |
CRC Check = 0xfc891918 (crc-32-bzip2) | |
Encrypted messages: | |
d6e06a975295f388 | |
c23c5d20bfe8712d73ce | |
8ec42d8623d774d58be529 | |
8a74715ad68b1dd2583dea166bc660182b980294 | |
6440124b5f091178d03351b1a4c3677a | |
89941795df97acb1e035348a6196be | |
3e8054579212eb | |
9c707e4b02ea | |
f2915b8f677ed6b156dd16dcc9b1f3af94 | |
b1f23a80d7 | |
08cb3dfbc775bc54142ae71d | |
ec343da5662aebf3a9 | |
ca78c3124c9d18557d3c1d403427cfed3d0f5f1d1d32d324 | |
42994ab15e58e6b84be7932ba0 | |
683013518ae498ab5c09d1a80fe9d101a2b5b77ec2c4 | |
a61c3d1944ceb50c03ce5d3255287fcd074c481b1fa6fd | |
2e60cad541d270fb66bdc1c0c84b9d39e9f5 | |
d176a7e8b2425c963913dff7b9f67abd4be2d1 | |
aae2cc53aa0d67f72eaf4facbf001cc5054e5a0048542c7570 | |
a86eb94e6fa27910b241b67d355cceaa3fc2e3365a | |
76c7e67ae482e28fcd825a9a5e86 | |
Challenge generation code, with secrets removed, is in the next file, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flag = "DELETED" | |
import binascii | |
import secrets | |
import random | |
import crcmod | |
def generate_encryption_key(): | |
return secrets.token_bytes(256 // 8) | |
def encrypt(k, m): | |
raise Exception("DELETED CODE") | |
def crc32(m): | |
crc_function = crcmod.mkCrcFun(0x104C11DB7, rev=False, initCrc=0, xorOut=0xFFFFFFFF) | |
return int(crc_function(m)).to_bytes(4, byteorder='big') | |
def checksum_and_encrypt(k, m): | |
if isinstance(m, str): | |
m = bytes(m, 'latin1') | |
return (encrypt(k, m) + crc32(m)) | |
def generate_flag(secret_key): | |
encrypted_flag = binascii.hexlify(encrypt(secret_key, bytes(flag, 'ascii'))).decode('ascii') | |
print("flag = {}".format(encrypted_flag)) | |
return encrypted_flag | |
def generate_encrypted_messages(secret_key): | |
c = [] | |
msg_lengths = list(range(1, len(flag)+3)) | |
random.shuffle(msg_lengths) | |
print("Format: stream_cipher(k, msg) || crc32-big_endian(msg)") | |
print("CRC Check = {} (crc-32-bzip2)".format(hex(int.from_bytes(crc32(bytes("123456789", 'ascii')), byteorder='big')))) | |
print("Encrypted messages:") | |
for msg_length in msg_lengths: | |
p = secrets.token_bytes(msg_length) | |
m = checksum_and_encrypt(secret_key, p) | |
c.append(m) | |
print(" " + binascii.hexlify(m).decode('ascii')) | |
print("\n\n\n") | |
return c | |
if __name__ == "__main__": | |
secret_key = generate_encryption_key() | |
encrypted_flag = generate_flag(secret_key) | |
msgs = generate_encrypted_messages(secret_key) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment