def test_challenge13(): block_size = 16 marker = b'email=' lm = len(marker) userInput1 = (block_size - lm) * b'A' userInput2 = pad(b'admin', 16) userInput3 = pad(b'user', 16) enc_admin_block = getProfile(userInput1 + userInput2)[16:32] test1 = profile_for(userInput1 + userInput2) finder = getProfile(userInput1 + userInput3)[16:32] res = b'' for i in range(16): inp = i * b'A' test = profile_for(inp) encrypted = getProfile(inp) if finder in encrypted: mod_enc = encrypted[:-16] + enc_admin_block res = checkProfile(mod_enc) print("DONE") break print(res) ass(b'role=admin' in res, 'Challenge 13')
def test_encr_decr_round(): padded = pad(text, 16) ciphert = cbc_encrypt(iv, key, padded) #print("ciphertext:", ciphert) plaint = cbc_decrypt(iv, key, ciphert) #print("plaintext:", plaint) plaint = unpad(plaint) assert_equals(plaint, text, "encrypt/decrypt round test")
def test_encr_decr_round_rnd_iv(): iv2 = bytearray(16) iv2[0] = 1 padded = pad(text, 16) ciphert = cbc_encrypt(iv2, key, padded) #print("ciphertext:", ciphert) plaint = cbc_decrypt(iv2, key, ciphert) #print("plaintext:", plaint) plaint = unpad(plaint) assert_equals(plaint, text, "encrypt/decrypt round test - second IV")
def encrypt(binInput): global key if key == None: key = getRandom(16) binInput = binInput.replace(b';', b'').replace(b'=', b'') inp = prep + binInput + app inp = pad(inp, 16) iv = getRandom(16) return iv + cbc_encrypt(iv, key, inp)
def getProfile(email): global key profile = profile_for(email) if type(profile) is not bytes: try: profile = profile.encode() except: profile = bytes(profile) padded = pad(profile, 16) return ecb_encrypt(key, padded)
def encryption_oracle(bin_input): global key global randomPad if key == None: key = getRandom(16) if randomPad == None: randomPad = getRandom(randint(1,16)) bin_input += appText padded = pad(randomPad + bin_input, 16) return ecb_encrypt(key, padded)
def encryption_oracle(bin_input): if type(bin_input) is not bytes: try: bin_input = bin_input.encode() except: pass key = getRandom(16) padded = randomPad(bin_input) algo = "ECB" if randint(0,1): padded = pad(padded, 16) out = ecb_encrypt(key, padded) else: algo = "CBC" iv = getRandom(16) padded = pad(padded, 16) out = cbc_encrypt(iv, key, padded) #print(algo, "encrypt") return out, algo
def encryption_oracle(bin_input): global key bin_input += appText padded = pad(bin_input, 16) return ecb_encrypt(key, padded)
def cbcEncryptIv(key, binInput): padded = pad(binInput, 16) iv = getRandom(16) cipher = cbc_encrypt(iv, key, padded) return iv + cipher