def ciphertext_oracle(): ecb_ciphertext = base64.b64decode(open('25.txt', 'r').read()) ecb_key = b'YELLOW SUBMARINE' ecb_cipher = AES.new(ecb_key, AES.MODE_ECB) plaintext = ecb_cipher.decrypt(ecb_ciphertext) cipher = challenge18.CTR(AES.new(key, AES.MODE_ECB), nonce) return cipher.encrypt(plaintext)
def encryptParams(userdata): userdata = userdata.replace(';', '%3B').replace('=', '%3D') x1 = b'comment1=cooking%20MCs;userdata=' x2 = b';comment2=%20like%20a%20pound%20of%20bacon' params = x1 + userdata.encode('ascii') + x2 cipher = challenge18.CTR(AES.new(key, AES.MODE_ECB), nonce) return cipher.encrypt(util.padPKCS7(params, 16))
def edit(ciphertext, offset, newtext): cipher = challenge18.CTR(AES.new(key, AES.MODE_ECB), nonce) cipher.encrypt(b'\x00' * offset) return ciphertext[0:offset] + cipher.encrypt(newtext)
def decryptParamsAndCheckAdmin(encryptedParams): cipher = challenge18.CTR(AES.new(key, AES.MODE_ECB), nonce) paddedParams = cipher.decrypt(encryptedParams) params = challenge15.unpadPKCS7(paddedParams) return params.find(b';admin=true;') != -1
def encryptString(s): cipher = challenge18.CTR(AES.new(key, AES.MODE_ECB), 0) return cipher.encrypt(s)