def findCollision(message, prefix): extra = (7 - len(prefix))%16 if extra == 0: extra = 16 for extraPadding in itertools.product([chr(c) for c in xrange(0x30, 0x7b)], repeat=extra): new_prefix = prefix + "".join(list(extraPadding)) print new_prefix prefixHash = h2a(hash(new_prefix)) mid_part = h2a(xor_ascii_strings(prefixHash, message[:16])) if not all(ord(c)>=32 and ord(c)<127 for c in mid_part): continue mal_message = h2a(pad_pkcs_7(a2h(new_prefix)) + h2a(xor_ascii_strings(prefixHash, message[:16])) + message[16:] return mal_message return "" def solver(): message = "alert('MZA who was that?');\n" h = hash(message) prefix = b"alert('Ayo, the Wu is back!'); //" collision = findCollision(message, prefix) print "[+] Found one." print a2h(collision) return if __name__=='__main__': solver()
def oracle(msg): key = generate_key() iv = generate_key() request = build_request(msg) compressed_request = zlib.compress(request) encrypted_request = aes_cbc.infra.encrypt_manual(pad_pkcs_7(a2h(compressed_request)), key, iv) return len(encrypted_request)
def encryption_oracle(plaintext): global KEY global prefix if KEY is None: KEY = crypty.generate_key() if prefix is None: # I am getting integer between 0 to 100 prefix = crypty.generate_key(key_size=randint(0, 100)) print "[*] Using Prefix of size : %d" % (len(prefix) / 2) plaintext = crypty.pad_pkcs_7(prefix + plaintext + crypty.convert_b64_to_hex(suffix)) return aes_ecb.infra.encrypt(plaintext, KEY)
def encrypt_manual(hex_string, key, iv): """ Manually AES-128-CBC Encrypts the input hex string using key, iv and AES-128-ECB :param hex_string: Hex string :param key: Hex string :param iv: Hex string :return: hex string """ assert len(iv) == len(key) blocks = crypty.get_blocks(hex_string, block_size=16) ciphertext = "" for block in blocks: if len(crypty.h2a(block)) % 16 is not 0: block = crypty.pad_pkcs_7(block, block_size=16) xor_block = crypty.xor_hex_strings(block, iv) iv = ecb_cipher.infra.encrypt(xor_block, key) ciphertext += iv return ciphertext
def simplePadMessageFn(message_hex): return h2a(pad_pkcs_7(message_hex, block_size=8))
def hash(message): message = pad_pkcs_7(a2h(message)) return aes_cbc.infra.encrypt_manual(message, a2h("YELLOW SUBMARINE"), "00"*16)
def solve(): print crypty.pad_pkcs_7(crypty.a2h("YELLOW SUBMARINE"), block_size=20)
def encrypt_profile(profile): global key if key is None: key = crypty.generate_key() ciphertext = ecb_cipher.infra.encrypt(crypty.pad_pkcs_7(crypty.a2h(profile)), key) return (key,ciphertext)
def encryption_oracle(plaintext): global KEY if KEY is None: KEY = crypty.generate_key() plaintext = crypty.pad_pkcs_7(plaintext+crypty.convert_b64_to_hex(suffix)) return aes_ecb.infra.encrypt(plaintext, KEY)