Ejemplo n.º 1
0
def encrypted_query(userdata):
    query = str1 + bytes(quote(userdata).encode('ascii')) + str2
    ciphertext = aes_cbc(pkcs7_pad_plaintext(query, 16),
                         secret_key,
                         iv,
                         operation='encrypt')
    return ciphertext
Ejemplo n.º 2
0
def encryption_oracle(input_data):

    input_data = input_data + base64.b64decode(unknown_plaintext)

    # Pad the input data to multiple of block size
    input_data = pkcs7_pad_plaintext(input_data, 16)

    return aes_ecb(input_data, secret_key, operation='encrypt')
Ejemplo n.º 3
0
def generate_session_token():
    string = secrets.choice(strings)
    plaintext = base64.b64decode(string)
    padded_plaintext = pkcs7_pad_plaintext(plaintext, block_size)

    iv = secrets.token_bytes(16)
    ciphertext = aes_cbc(padded_plaintext, secret_key, iv, operation='encrypt')

    return iv, ciphertext
Ejemplo n.º 4
0
def encryption_oracle(input_data):
    # Generate random key
    key = secrets.token_bytes(16)

    # Add 5-10 random bytes before and after the plaintext
    input_data = secrets.token_bytes(secrets.randbelow(6)+5) + input_data + secrets.token_bytes(secrets.randbelow(6)+5)

    # Pad the input data to multiple of block size
    input_data = pkcs7_pad_plaintext(input_data, 16)

    # Select AES mode and encrypt
    if secrets.randbelow(2) == 0:
        print('Oracle chose ECB mode')
        return aes_ecb(input_data, key, operation='encrypt')
    else:
        print('Oracle chose CBC mode')
        iv = secrets.token_bytes(16)
        return aes_cbc(input_data, key, iv, operation='encrypt')
Ejemplo n.º 5
0
def encrypt_profile(input_data):
    ciphertext = aes_ecb(pkcs7_pad_plaintext(input_data.encode('ascii'), 16),
                         secret_key,
                         operation='encrypt')
    return ciphertext