Exemple #1
0
def encryptionOracle(data):
    extraData = Binary(
        'Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBqdXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK',
        64)
    data = data + extraData

    c = Crypto(data)

    c.encAES_ECB(randomKey)
    return c.data
def createProfileAndProvide(email):
    if isinstance(email, Binary):
        email = email.toAscii()

    profile = profile_for(email)
    c = Crypto(Binary(profile, 128))
    c.encAES_ECB(randomKey)

    cipher = c.data
    return cipher
def encryptionOracle(data):
    randomKey = Binary.random(8 * 16)
    addBefore = Binary.random(random.randrange(5, 11) * 8)
    addAfter = Binary.random(random.randrange(5, 11) * 8)
    data = addBefore + data + addAfter
    IV = Binary.random(8 * 16)

    c = Crypto(data)

    if random.randrange(2):
        c.encAES_ECB(randomKey)
        mode = 'ECB'
    else:
        c.encAES_CBC(randomKey, IV)
        mode = 'CBC'

    return (mode, c.data)
Exemple #4
0
from Tools import Crypto
from Tools import Binary

data = ''

with open('./ch6.txt') as file:
    for line in file:
        data += line.rstrip()

binary = Crypto(data, 64)
keys = binary.decXOR()

binary.xor(Binary(keys[0], 128))
print(binary.data.toAscii())
from Tools import Crypto, Binary

b = Binary('ICE ICE BABY', 128)

print(Binary(Crypto.removePadding(b + Binary('04040404', 16))).toAscii())

try:
    Crypto.removePadding(b + Binary('05050505', 16))
except:
    print('Caught exception')

try:
    Crypto.removePadding(b + Binary('01020304', 16))
except:
    print('Caught exception')

print('Passed!')
from Tools import Crypto
from Tools import Binary

text = 'Burning \'em, if you ain\'t quick and nimble\nI go crazy when I hear a cymbal'
key = Binary('ICE', 128)

e = Crypto(text, 128)

e.xor(key)
result = e.toHex()
expected = '0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f'

if result == expected:
    print('Passed!')
else:
    print(result)
    print(expected)

def decryptProfile(profile):
    c = Crypto(profile.toHex(), 16)
    c.decAES_ECB(randomKey)
    parsedProfile = parseParams(c.toAscii())
    print(parsedProfile)
from Tools import Binary, Crypto

data = ''
key = Binary('YELLOW SUBMARINE', 128)

with open('./ch10.txt') as file:
    for line in file:
        data += line.rstrip()

data = Binary(data, 64)

IV = Binary('0' * 32, 16)
c = Crypto(data)

c.decAES_CBC(key, IV)

print(c.toAscii())
Exemple #9
0
def __main__():
    print(Crypto.decECB(encryptionOracle))
Exemple #10
0
from Tools import Crypto

with open('./ch4.txt') as file:
    bestResult = (0, '', '')
    i = 1

    for line in file:
        d = Crypto(line.rstrip(), 16)
        result = d.decSingleCharXOR()

        if result[0] > bestResult[0]:
            bestResult = result
        i += 1

print(bestResult[2])
from Tools import Crypto
from Tools import Binary

data = ''
key = Binary('YELLOW SUBMARINE', 128)

with open('./ch7.txt') as file:
    for line in file:
        data += line.rstrip()

binary = Crypto(Binary(data, 64))

binary.decAES_ECB(key)

print(binary.toAscii())
from ch12 import encryptionOracle
from Tools import Binary, Crypto
import random

randomPrefix = Binary().random(random.randrange(0, 30 * 8, 8))


def wrapper(data):
    return encryptionOracle(randomPrefix + data)


print(Crypto.decECB(wrapper))