RSA_pubkey_small_n = b"""
-----BEGIN PUBLIC KEY-----
MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgBJut++Q7fjnrCzax5d8fuJIux4u
l7bRrm9Il5iYmwE1JSkTUITtSXnGfAA4+H5kPTnv6D7KR3ii0IuKicAQStOsof/s
7ul3etw72y+v1BMZhj92cq/+ZdaLbhLVkhMlwreuuzPxui7Y7wQXhIJCf20TS/zE
oZGmi6usbfkw3G19AgMBAAE=
-----END PUBLIC KEY-----
"""

key = b'YELLOW SUBMARINE'
iv = Random.new().read(AES.block_size)

two_time_pad_key = Random.new().read(len(plaintext2))

ecb_cipher = AES.new(key, AES.MODE_ECB)
ecb_ciphertexts = [ecb_cipher.encrypt(ca.pkcs7_pad(plaintext, AES.block_size))]
ecb_cipher = AES.new(key, AES.MODE_ECB)
ecb_ciphertexts.append(
    ecb_cipher.encrypt(ca.pkcs7_pad(plaintext2, AES.block_size)))

cbc_cipher = AES.new(key, AES.MODE_CBC, iv)
cbc_ciphertexts = [cbc_cipher.encrypt(ca.pkcs7_pad(plaintext, AES.block_size))]
cbc_cipher = AES.new(key, AES.MODE_CBC, iv)
cbc_ciphertexts.append(
    cbc_cipher.encrypt(ca.pkcs7_pad(plaintext2, AES.block_size)))

mb_xor_ciphertexts = [
    ca.sxor(plaintext, b"\xfa\x4e\x77\x01\x43" * len(plaintext))
]
mb_xor_ciphertexts.append(
    ca.sxor(plaintext2, b"\xfa\x4e\x77\x01\x43" * len(plaintext2)))
Esempio n. 2
0
def my_encryption_oracle(plaintext):
    return cipher.encrypt(
        ca.pkcs7_pad(
            b'A' * random.randint(1, AES.block_size) + plaintext + suffix,
            AES.block_size))
Esempio n. 3
0
def my_encryption_oracle(plaintext):
    return cipher.encrypt(
        ca.pkcs7_pad(prefix + plaintext + suffix, AES.block_size))
import ca3 as ca
from Crypto.Cipher import AES
from Crypto import Random

from binascii import hexlify

key = iv = Random.new().read(AES.block_size)

cipher = AES.new(key, mode=AES.MODE_CBC, IV=iv)
second_cipher_because_yolo = AES.new(key, mode=AES.MODE_CBC, IV=iv)

ciphertext = cipher.encrypt(
    ca.pkcs7_pad(b'Check out the mic while the DJ revolves it (ICE ICE BABY)',
                 AES.block_size))


def decryption_oracle(ciphertext):
    return second_cipher_because_yolo.decrypt(ciphertext)


print('Key and IV are %s and %s' % (hexlify(key), hexlify(iv)))
retrieved_iv = ca.retrieve_iv(decryption_oracle, ciphertext, AES.block_size)
print('Ciphertext is %s' % hexlify(ciphertext))
plaintext = decryption_oracle(ciphertext)
print('Produced plaintext is %s' % hexlify(plaintext))
print('First block of produced plaintext is %s' %
      hexlify(plaintext[:AES.block_size]))
print('Second block of produced plaintext is %s' %
      hexlify(plaintext[AES.block_size:AES.block_size * 2]))
print('Retrieved IV is %s' % hexlify(retrieved_iv))
Esempio n. 5
0
from Crypto.Cipher import AES
from Crypto import Random
import ca3 as ca
from time import sleep

plaintext = b'I am the very model of a modern major-general'
plaintext = ca.pkcs7_pad(plaintext, AES.block_size)
print("Plaintext is " + str(plaintext))

key = b'YELLOW SUBMARINE'  #<3 matasano crypto challenges
iv = Random.new().read(AES.block_size)


def my_padding_oracle(ciphertext):
    dat_cipher = AES.new(key, AES.MODE_CBC, iv)
    try:
        ca.pkcs7_padding_remove(dat_cipher.decrypt(ciphertext), AES.block_size)
        return True
    except:
        return False


cipher = AES.new(key, AES.MODE_CBC, iv)
ciphertext = cipher.encrypt(plaintext)

print('Running the attack with known IV:')
result = ca.padding_oracle_decrypt(my_padding_oracle,
                                   ciphertext,
                                   block_size=AES.block_size,
                                   verbose=True,
                                   iv=iv)