def enc_oracle(): global key global iv cipher = ch10.CBC(AES.new(key, AES.MODE_ECB), iv) plaintext = binascii.a2b_base64( random.choice(strings) ) padded = ch9.pad_PCKS7(plaintext, 16) return cipher.encrypt(padded)
def enc_oracle(plaintext): global key if key is None: key = ch11.rand_bytes(16) cipher = AES.new(key, AES.MODE_ECB) plaintext += binascii.a2b_base64(postfix) #plaintext = ch11.rand_padding(plaintext) plaintext = ch9.pad_PCKS7(plaintext, 16) return cipher.encrypt(plaintext)
def enc_userdata(s): global key global IV prefix = "comment1=cooking%20MCs;userdata=" suffix = ";comment2=%20like%20a%20pound%20of%20bacon" cipher = ch10.CBC(AES.new(key, AES.MODE_ECB), IV) s = s.replace(';', '%3B').replace('=', '%3D') s = (prefix + s + suffix).encode('utf-8') s = ch9.pad_PCKS7(s, 16) return cipher.encrypt(s)
def oracle(plaintext, num_bytes): key = rand_bytes(num_bytes) cipher = AES.new(key, AES.MODE_ECB) plaintext = rand_padding(plaintext) plaintext = ch9.pad_PCKS7(plaintext, num_bytes) if random.randint(0, 1) == 1: print("Using CBC") IV = rand_bytes(num_bytes) cipher = ch10.CBC(cipher, IV) else: print("Using ECB") return cipher.encrypt(plaintext)
def enc_oracle(plaintext): global key global prefix global num blk_sz = 16 if key == None: key = gen_key(blk_sz) if prefix == None: num = random.randint(8, 64) prefix = gen_prefix(num) cipher = AES.new(key, AES.MODE_ECB) plaintext = prefix + plaintext + binascii.a2b_base64(ch12.postfix) plaintext = ch9.pad_PCKS7(plaintext, blk_sz) return cipher.encrypt(plaintext)
def profile_encrypt(profile_str, key): cipher = AES.new(key, AES.MODE_ECB) return cipher.encrypt( ch9.pad_PCKS7(profile_str.encode(), 16) )