Ejemplo n.º 1
0
def encrypt_user_data_cbc(user_data):
    user_data = user_data.replace(";", "")
    user_data = user_data.replace("=", "")
    plaintext = "comment1=cooking%20MCs;userdata=" + user_data + ";comment2=%20like%20a%20pound%20of%20bacon"

    to_encrypt = pad_to_mod_16(string_to_bytearray(plaintext))
    return encrypt_aes_cbc(to_encrypt, oracle_key, iv)
Ejemplo n.º 2
0
def cbc_encryption_oracle():
    messages_encrypted = []
    for message in messages:
        message_to_encrypt = base64_to_bytearray(message)
        message_to_encrypt_padded = pad_to_mod_16(message_to_encrypt)

        ciphertext = encrypt_aes_cbc(message_to_encrypt_padded, ORACLE_KEY, ORACLE_IV)
        messages_encrypted.append(ciphertext)

    return messages_encrypted
Ejemplo n.º 3
0
def encrypt_user_data_cbc(user_data):
    user_data = user_data.replace(";", "")
    user_data = user_data.replace("=", "")

    prefix = "comment1=cooking%20MCs;userdata="
    suffix = ";comment2=%20like%20a%20pound%20of%20bacon"

    plaintext = string_to_bytearray(prefix + user_data + suffix)

    to_encrypt = pad_to_mod_16(plaintext)
    ciphertext = encrypt_aes_cbc(to_encrypt, oracle_key, iv)

    return ciphertext
Ejemplo n.º 4
0
def encryption_oracle_ecb_cbc(bt):
    key = crypto_random_bytes(16)
    iv = crypto_random_bytes(16)
    mode = choice(['ecb', 'cbc'])

    begin_pad = crypto_random_bytes(random_integer(5, 10))
    end_pad = crypto_random_bytes(random_integer(5, 10))
    to_encrypt = pad_to_mod_16(begin_pad + bt + end_pad)

    if mode == 'ecb':
        ciphertext = encrypt_aes_128_ecb(to_encrypt, key)
    else:
        ciphertext = encrypt_aes_cbc(to_encrypt, key, iv)

    # do not cheat, use mode for validation only
    return ciphertext, mode
Ejemplo n.º 5
0
    def send_encrypted_message(self, message):
        key = self.hkdf()
        iv = crypto_random_bytes(16)

        ciphertext = encrypt_aes_cbc(message, key, iv)
        return ciphertext, iv