Esempio n. 1
0
def get_ciphertexts(plaintexts):
    rand_key = challenge11.get_rand_bytes(16)

    ciphertexts = []
    for plaintext in plaintexts:
        aes_128_ctr = challenge18.AES128CTR(key=rand_key, nonce=0, counter=0)
        ciphertext = aes_128_ctr.crypt(base64.b64decode(plaintext))
        ciphertexts.append(ciphertext)

    return ciphertexts
Esempio n. 2
0
def get_ciphertexts():
    plaintexts = [
        'SSBoYXZlIG1ldCB0aGVtIGF0IGNsb3NlIG9mIGRheQ==',
        'Q29taW5nIHdpdGggdml2aWQgZmFjZXM=',
        'RnJvbSBjb3VudGVyIG9yIGRlc2sgYW1vbmcgZ3JleQ==',
        'RWlnaHRlZW50aC1jZW50dXJ5IGhvdXNlcy4=',
        'SSBoYXZlIHBhc3NlZCB3aXRoIGEgbm9kIG9mIHRoZSBoZWFk',
        'T3IgcG9saXRlIG1lYW5pbmdsZXNzIHdvcmRzLA==',
        'T3IgaGF2ZSBsaW5nZXJlZCBhd2hpbGUgYW5kIHNhaWQ=',
        'UG9saXRlIG1lYW5pbmdsZXNzIHdvcmRzLA==',
        'QW5kIHRob3VnaHQgYmVmb3JlIEkgaGFkIGRvbmU=',
        'T2YgYSBtb2NraW5nIHRhbGUgb3IgYSBnaWJl',
        'VG8gcGxlYXNlIGEgY29tcGFuaW9u',
        'QXJvdW5kIHRoZSBmaXJlIGF0IHRoZSBjbHViLA==',
        'QmVpbmcgY2VydGFpbiB0aGF0IHRoZXkgYW5kIEk=',
        'QnV0IGxpdmVkIHdoZXJlIG1vdGxleSBpcyB3b3JuOg==',
        'QWxsIGNoYW5nZWQsIGNoYW5nZWQgdXR0ZXJseTo=',
        'QSB0ZXJyaWJsZSBiZWF1dHkgaXMgYm9ybi4=',
        'VGhhdCB3b21hbidzIGRheXMgd2VyZSBzcGVudA==',
        'SW4gaWdub3JhbnQgZ29vZCB3aWxsLA==',
        'SGVyIG5pZ2h0cyBpbiBhcmd1bWVudA==',
        'VW50aWwgaGVyIHZvaWNlIGdyZXcgc2hyaWxsLg==',
        'V2hhdCB2b2ljZSBtb3JlIHN3ZWV0IHRoYW4gaGVycw==',
        'V2hlbiB5b3VuZyBhbmQgYmVhdXRpZnVsLA==',
        'U2hlIHJvZGUgdG8gaGFycmllcnM/',
        'VGhpcyBtYW4gaGFkIGtlcHQgYSBzY2hvb2w=',
        'QW5kIHJvZGUgb3VyIHdpbmdlZCBob3JzZS4=',
        'VGhpcyBvdGhlciBoaXMgaGVscGVyIGFuZCBmcmllbmQ=',
        'V2FzIGNvbWluZyBpbnRvIGhpcyBmb3JjZTs=',
        'SGUgbWlnaHQgaGF2ZSB3b24gZmFtZSBpbiB0aGUgZW5kLA==',
        'U28gc2Vuc2l0aXZlIGhpcyBuYXR1cmUgc2VlbWVkLA==',
        'U28gZGFyaW5nIGFuZCBzd2VldCBoaXMgdGhvdWdodC4=',
        'VGhpcyBvdGhlciBtYW4gSSBoYWQgZHJlYW1lZA==',
        'QSBkcnVua2VuLCB2YWluLWdsb3Jpb3VzIGxvdXQu',
        'SGUgaGFkIGRvbmUgbW9zdCBiaXR0ZXIgd3Jvbmc=',
        'VG8gc29tZSB3aG8gYXJlIG5lYXIgbXkgaGVhcnQs',
        'WWV0IEkgbnVtYmVyIGhpbSBpbiB0aGUgc29uZzs=',
        'SGUsIHRvbywgaGFzIHJlc2lnbmVkIGhpcyBwYXJ0',
        'SW4gdGhlIGNhc3VhbCBjb21lZHk7',
        'SGUsIHRvbywgaGFzIGJlZW4gY2hhbmdlZCBpbiBoaXMgdHVybiw=',
        'VHJhbnNmb3JtZWQgdXR0ZXJseTo=',
        'QSB0ZXJyaWJsZSBiZWF1dHkgaXMgYm9ybi4=',
    ]

    rand_key = challenge11.get_rand_bytes(16)

    ciphertexts = []
    check_plaintexts = []
    for plaintext in plaintexts:
        aes_128_ctr = challenge18.AES128CTR(key=rand_key, nonce=0, counter=0)
        ciphertext = aes_128_ctr.crypt(base64.b64decode(plaintext))
        ciphertexts.append(ciphertext)
        check_plaintexts.append(base64.b64decode(plaintext))

    return ciphertexts, check_plaintexts
Esempio n. 3
0
def func1(key):
    strings = [
        "MDAwMDAwTm93IHRoYXQgdGhlIHBhcnR5IGlzIGp1bXBpbmc=",
        "MDAwMDAxV2l0aCB0aGUgYmFzcyBraWNrZWQgaW4gYW5kIHRoZSBWZWdhJ3MgYXJlIHB1bXBpbic=",
        "MDAwMDAyUXVpY2sgdG8gdGhlIHBvaW50LCB0byB0aGUgcG9pbnQsIG5vIGZha2luZw==",
        "MDAwMDAzQ29va2luZyBNQydzIGxpa2UgYSBwb3VuZCBvZiBiYWNvbg==",
        "MDAwMDA0QnVybmluZyAnZW0sIGlmIHlvdSBhaW4ndCBxdWljayBhbmQgbmltYmxl",
        "MDAwMDA1SSBnbyBjcmF6eSB3aGVuIEkgaGVhciBhIGN5bWJhbA==",
        "MDAwMDA2QW5kIGEgaGlnaCBoYXQgd2l0aCBhIHNvdXBlZCB1cCB0ZW1wbw==",
        "MDAwMDA3SSdtIG9uIGEgcm9sbCwgaXQncyB0aW1lIHRvIGdvIHNvbG8=",
        "MDAwMDA4b2xsaW4nIGluIG15IGZpdmUgcG9pbnQgb2g=",
        "MDAwMDA5aXRoIG15IHJhZy10b3AgZG93biBzbyBteSBoYWlyIGNhbiBibG93"
    ]

    choice = base64.b64decode(random.choice(strings))
    choice_padded = challenge9.pkcs7_pad(16, choice)

    iv = challenge11.get_rand_bytes(16)

    ciphertext = challenge10.encrypt_aes_128_cbc(key, iv, choice_padded)

    return choice, ciphertext, iv
Esempio n. 4
0

def func2(key, iv, ciphertext):
    plaintext_padded = challenge10.decrypt_aes_128_cbc(key, iv, ciphertext)

    try:
        plaintext = challenge15.pkcs7_unpad(plaintext_padded)
        return True
    except Exception as err:
        pass

    return False


if __name__ == "__main__":
    rand_key = challenge11.get_rand_bytes(16)
    # choice only used to verify decrypt
    choice, ciphertext, iv = func1(rand_key)

    block_size = 16

    blocks = []
    blocks.append(iv)
    blocks += challenge16.split_into_blocks(ciphertext)

    plainblocks = []
    for block_num in range(0, len(blocks) - 1):
        plainblock = bytearray("\x00") * block_size
        block1 = bytearray(blocks[block_num])
        original_block1 = block1
        block2 = blocks[block_num + 1]
Esempio n. 5
0
import challenge7
import challenge9
import challenge11


def encryption_oracle(random_prefix, attacker_controlled, target_bytes, random_key):
    plainbuf = random_prefix + attacker_controlled + target_bytes
    padded_plainbuf = challenge9.pkcs7_pad(16, plainbuf)

    encbuf = challenge7.encrypt_aes_128_ecb(random_key, padded_plainbuf)

    return encbuf


if __name__ == "__main__":
    random_key = challenge11.get_rand_bytes(16)

    rand_size = random.randint(0, 64)
    random_prefix = challenge11.get_rand_bytes(rand_size)

    block_size = 16
    num_padded_bytes = block_size - 1
    base_block = chr(num_padded_bytes)*num_padded_bytes

    # dictionary of "<byte><0xf padding>" encbufs
    block_dict = {}
    for i in range(256):
        block = chr(i) + base_block
        encbuf = challenge7.encrypt_aes_128_ecb(random_key, block)
        block_dict[encbuf] = chr(i)