Exemplo n.º 1
0
def encryption_oracle(plaintext):
    random_key = get_random_bytes(16)
    random_iv = get_random_bytes(16)
    # print("Random key:", random_key)
    # print("Random iv:", random_iv)
    random_length = randint(5, 10)
    # print("Random length addition:",random_length)
    random_addition = get_random_bytes(random_length)
    # print("Random addition:", random_addition)
    plaintext = random_addition + plaintext + random_addition
    # print("Plaintext:", plaintext)
    choice = randint(1, 2)
    print("Choice:", choice)

    ciphertext = b""
    cipher_ecb = ecb_module()
    cipher_cbc = cbc_module(random_iv, random_key)

    if choice == 1:
        print("Encryption engine: ECB")
        ciphertext = cipher_ecb.ecb_encrypt(plaintext, random_key)

    elif choice == 2:
        print("Encryption engine: CBC")
        ciphertext = cipher_cbc.cbc_encrypt(plaintext)

    return ciphertext
Exemplo n.º 2
0
def cbc_oracle(ciphertext, iv):
    cipher = cbc_module(iv, key)
    plaintext = cipher.cbc_decrypt(ciphertext)
    try:
        validate_padding(plaintext)
        return True
    except:
        return False
Exemplo n.º 3
0
def decrypt_parameters_and_check_admin(input_string):
    cipher = cbc_module(iv, key)
    plaintext = cipher.cbc_decrypt(input_string)
    if b";admin=true;" in plaintext:
        print("Plaintext:", plaintext)
        return True
    else:
        return False
Exemplo n.º 4
0
def decrypt_and_check_ascii(input_string):
    cipher = cbc_module(iv, key)
    plaintext = cipher.cbc_decrypt(input_string)
    for i in plaintext:
        if int(i) > 127:
            print('*** ERROR: High-ASCII values found ***\n{0}'.format(
                plaintext))
            return plaintext

    return True
Exemplo n.º 5
0
def encrypt_parameters(input_string):

    # Quote out '=' and ';' from input string and convert to bytes
    input_string = bytes(
        input_string.replace(';', '%3B').replace('=', '%3D'), 'utf-8')

    parameters_string = prefix + input_string + suffix

    cipher = cbc_module(iv, key)
    ciphertext = cipher.cbc_encrypt(parameters_string)
    return ciphertext
Exemplo n.º 6
0
def encrypt_parameters(input_string):
    prefix = b"comment1=cooking%20MCs;userdata="
    suffix = b";comment2=%20like%20a%20pound%20of%20bacon"

    # Quote out '=' and ';' from input string and convert to bytes
    input_string = bytes(
        input_string.replace(';', '%3B').replace('=', '%3D'), 'utf-8')

    parameters_string = prefix + input_string + suffix

    cipher = cbc_module(iv, key)
    ciphertext = cipher.cbc_encrypt(input_string)

    return ciphertext
Exemplo n.º 7
0
def cbc_encrypt_random_line():
    random_line = target_list[randint(0, 9)]
    cipher = cbc_module(iv, key)
    ciphertext = cipher.cbc_encrypt(random_line)
    return ciphertext, iv
Exemplo n.º 8
0
 def decrypt(self, iv, key, ciphertext):
     cipher = cbc_module(iv, key)
     plaintext = cipher.cbc_decrypt(ciphertext)
     padding = int.from_bytes(plaintext[-1:], 'big')
     plaintext = plaintext[:-padding]
     return plaintext
Exemplo n.º 9
0
 def encrypt(self, iv, key, plaintext):
     cipher = cbc_module(iv, key)
     ciphertext = cipher.cbc_encrypt(plaintext)
     return ciphertext