Пример #1
0
def encryptParams(userdata):
    userdata = userdata.replace(';', '%3B').replace('=', '%3D')
    x1 = b'comment1=cooking%20MCs;userdata='
    x2 = b';comment2=%20like%20a%20pound%20of%20bacon'
    params = x1 + userdata.encode('ascii') + x2
    cipher = challenge10.CBC(AES.new(key, AES.MODE_ECB), iv)
    return cipher.encrypt(util.padPKCS7(params, 16))
Пример #2
0
def encryption_oracle(s):
    global key
    if key is None:
        key = util.randbytes(16)
    cipher = AES.new(key, AES.MODE_ECB)
    s = util.padPKCS7(s + base64.b64decode(encodedSuffix), 16)
    return cipher.encrypt(s)
Пример #3
0
def encryptParams(userdata):
    userdata = userdata.replace(';', '%3B').replace('=', '%3D')
    x1 = b'comment1=cooking%20MCs;userdata='
    x2 = b';comment2=%20like%20a%20pound%20of%20bacon'
    params = x1 + userdata.encode('ascii') + x2
    cipher = challenge18.CTR(AES.new(key, AES.MODE_ECB), nonce)
    return cipher.encrypt(util.padPKCS7(params, 16))
Пример #4
0
def encryption_oracle(s):
    global key
    if key is None:
        key = util.randbytes(16)
    cipher = AES.new(key, AES.MODE_ECB)
    s = util.padPKCS7(s + base64.b64decode(encodedSuffix), 16)
    return cipher.encrypt(s)
Пример #5
0
def oracle_cbc(P):
    request = format_request(P)
    compressed_request = zlib.compress(request.encode('ascii'))
    key = util.randbytes(16)
    iv = util.randbytes(16)
    cipher = AES.new(key, AES.MODE_CBC, iv)
    encrypted_request = cipher.encrypt(util.padPKCS7(compressed_request, 16))
    return len(encrypted_request)
Пример #6
0
def encryption_oracle(s):
    global key
    global prefix
    if key is None:
        key = util.randbytes(16)
    if prefix is None:
        # TODO(akalin): Extend to arbitrary sizes.
        randcount = random.randint(16, 32)
        prefix = util.randbytes(randcount)
    cipher = AES.new(key, AES.MODE_ECB)
    s = util.padPKCS7(prefix + s + base64.b64decode(challenge12.encodedSuffix), 16)
    return cipher.encrypt(s)
Пример #7
0
def encryption_oracle(s):
    key = util.randbytes(16)
    cipher = AES.new(key, AES.MODE_ECB)
    if random.randint(0, 1) == 0:
        print('Encrypting with ECB')
    else:
        print('Encrypting with CBC')
        IV = util.randbytes(16)
        cipher = challenge10.CBC(cipher, IV)
    s = util.randbytes(random.randint(5, 10)) + s + util.randbytes(random.randint(5, 10))
    s = util.padPKCS7(s, 16)
    return cipher.encrypt(s)
Пример #8
0
def encryption_oracle(s):
    global key
    global prefix
    if key is None:
        key = get_random_bytes(16)
    if prefix is None:
        # TODO(akalin): Extend to arbitrary sizes.
        randcount = randint(16, 32)
        prefix = get_random_bytes(randcount)
    cipher = AES.new(key, AES.MODE_ECB)
    s = util.padPKCS7(prefix + s + base64.b64decode(challenge12.encodedSuffix),
                      16)
    return cipher.encrypt(s)
Пример #9
0
def attacker2_process_message(m):
    print('A2', m)
    if re.match(b'^from=Tom&', m):
        message = m[:-16]
        mac1 = m[-16:]
        # Assume attacker can create this account, and that this
        # message fails or otherwise has no effect.
        frontend2_send_message(b'M', [[b'M', b'0'], [b'Mallory', b'1000000']])
        m2 = attacker2_peek_last_sent_message()
        m3 = util.padPKCS7(message, 16) + strxor(mac1, m2[:16]) + m2[16:]
        print('A2', m3)
        backend2_process_message(m3)
    else:
        backend2_process_message(m)
Пример #10
0
def attacker2_process_message(m):
    print('A2', m)
    if re.match(b'^from=Tom&', m):
        message = m[:-16]
        mac1 = m[-16:]
        # Assume attacker can create this account, and that this
        # message fails or otherwise has no effect.
        frontend2_send_message(b'M', [[b'M', b'0'], [b'Mallory', b'1000000']])
        m2 = attacker2_peek_last_sent_message()
        m3 = util.padPKCS7(message, 16) + strxor(mac1, m2[:16]) + m2[16:]
        print('A2', m3)
        backend2_process_message(m3)
    else:
        backend2_process_message(m)
Пример #11
0
def ciphertext_oracle():
    s = base64.b64decode(random.choice(strings))
    iv = util.randbytes(16)
    cipher = challenge10.CBC(AES.new(key, AES.MODE_ECB), iv)
    return (iv, cipher.encrypt(util.padPKCS7(s, 16)))
Пример #12
0
import util

if __name__ == '__main__':
    x = b'YELLOW SUBMARINE'
    expectedY = b'YELLOW SUBMARINE\x04\x04\x04\x04'
    y = util.padPKCS7(x, 20)
    print(y)
    print(expectedY)
    if y != expectedY:
        raise Exception(y + b' != ' + expectedY)
Пример #13
0
def CBC_Mac(passsword, iv, plain):  #return the vaule of the CMAC
    cipher = AES.new(d, AES.MODE_CBC, iv)
    c = cipher.encrypt(util.padPKCS7(plain, 16))
    return c[-16:]
Пример #14
0
def prependAndCollide(s, prefix):
    prefixHash = insecureHash(prefix)
    paddedPrefix = util.padPKCS7(prefix, 16)
    return paddedPrefix + strxor(s[:16], prefixHash) + s[16:]
Пример #15
0
def Collide(before, after):
    afterHash = CBC_Mac(b'YELLOW SUBMARINE', b'\x00' * 16, after)
    padded = util.padPKCS7(after, 16)
    return padded + strxor(before[:16], afterHash) + before[16:]
Пример #16
0
def CBC_MAC(key, iv, p):
    cipher = AES.new(key, AES.MODE_CBC, iv)
    c = cipher.encrypt(util.padPKCS7(p, 16))
    return c[-16:]
Пример #17
0
def encrypt_profile_for(email):
    cipher = AES.new(key, AES.MODE_ECB)
    encoded_profile = util.padPKCS7(profile_for(email), 16)
    return cipher.encrypt(encoded_profile)
Пример #18
0
def prependAndCollide(s, prefix):
    prefixHash = insecureHash(prefix)
    paddedPrefix = util.padPKCS7(prefix, 16)
    return paddedPrefix + strxor(s[:16], prefixHash) + s[16:]
Пример #19
0
def CBC_MAC(key, iv, p):
    cipher = AES.new(key, AES.MODE_CBC, iv)
    c = cipher.encrypt(util.padPKCS7(p, 16))
    return c[-16:]
Пример #20
0
def encrypt_profile_for(email):
    cipher = AES.new(key, AES.MODE_ECB)
    encoded_profile = util.padPKCS7(profile_for(email), 16)
    return cipher.encrypt(encoded_profile)
Пример #21
0
 def encrypt(self, key, iv, message):
     cipher = AES.new(key, AES.MODE_CBC, iv)
     return cipher.encrypt(util.padPKCS7(message.encode('ascii'), 16))