def decrypt_and_check_url(ciphertext):
    plaintext = decrypt_aes_cbc(ciphertext, oracle_key, iv)
    plaintext = unpad_pkcs7(plaintext)

    for c in plaintext:
        if chr(c) not in string.printable:
            raise Exception(plaintext)

    return True
Exemplo n.º 2
0
def attack_message(message):
    blocks = chunks_of_bytearray(message, BLOCK_SIZE)

    plaintext = []
    for ix, _ in enumerate(blocks):
        plaintext_block = attack_block(blocks, ix)
        plaintext.extend(plaintext_block)

    return unpad_pkcs7(bytearray(plaintext))
Exemplo n.º 3
0
def main():
    s1 = string_to_bytearray("ICE ICE BABY\x04\x04\x04\x04")
    s2 = string_to_bytearray("ICE ICE BABY\x05\x05\x05\x05")
    s3 = string_to_bytearray("ICE ICE BABY\x01\x02\x03\x04")

    assert valid_pkcs7_padding(s1) == True
    assert valid_pkcs7_padding(s2) == False
    assert valid_pkcs7_padding(s3) == False

    unpad_pkcs7(s1)

    try:
        unpad_pkcs7(s2)
        raise Exception("challenge 2.15 failed.")
    except ValueError as e:
        pass

    try:
        unpad_pkcs7(s3)
        raise Exception("challenge 2.15 failed.")
    except ValueError as e:
        pass

    print("challenge 2.15 completed.")
Exemplo n.º 4
0
def decrypt_and_check_admin(ciphertext):
    plaintext = decrypt_aes_cbc(ciphertext, oracle_key, iv)
    plaintext = unpad_pkcs7(plaintext)
    return b';admin=true;' in plaintext
Exemplo n.º 5
0
def decrypt_encoded_profile(encoded_profile):
    plaintext = decrypt_aes_128_ecb(encoded_profile, oracle_key)
    profile = unpad_pkcs7(plaintext)
    return parse_url_params(profile.decode())