def main(): # Fast recovery from AES_128 import xor_data enc = get_encrypted_data() length = len(enc) print '[+] Length of data = %d' % length print '[+] Recovering data' modification_string = 'x'*length new_enc = edit(enc, 0, modification_string) data = xor_data(xor_data(enc, new_enc), modification_string) print data print '[+] Finished recovering data'
def main(): # Fast recovery from AES_128 import xor_data enc = get_encrypted_data() length = len(enc) print '[+] Length of data = %d' % length print '[+] Recovering data' modification_string = 'x' * length new_enc = edit(enc, 0, modification_string) data = xor_data(xor_data(enc, new_enc), modification_string) print data print '[+] Finished recovering data'
def crack(e_oracle, d_oracle): injection_string = ';admin=true;' constant_regions = get_constant_regions(e_oracle, len(injection_string)) central_oracle = get_central_oracle(e_oracle) joke_string = 'X'*len(injection_string) modified_ciphertext = xor_data(xor_data(joke_string, injection_string), central_oracle(joke_string)) attack = '' attack += constant_regions[0] attack += modified_ciphertext attack += constant_regions[1] if d_oracle(attack) == True: print "[+] Cracked using %s" % repr(attack) else: print "[-] Failed using %s" % repr(attack)
def crack(e_oracle, d_oracle): injection_string = ';admin=true;' constant_regions = get_constant_regions(e_oracle, len(injection_string)) central_oracle = get_central_oracle(e_oracle) joke_string = 'X' * len(injection_string) modified_ciphertext = xor_data(xor_data(joke_string, injection_string), central_oracle(joke_string)) attack = '' attack += constant_regions[0] attack += modified_ciphertext attack += constant_regions[1] if d_oracle(attack) == True: print "[+] Cracked using %s" % repr(attack) else: print "[-] Failed using %s" % repr(attack)
def crack(e_oracle, d_oracle): block_size = get_len_of_block_cipher(e_oracle) print "[+] Block size = %d" % block_size input_plaintext = 'x'*(3*block_size) encrypted = e_oracle(input_plaintext) try: modified_encrypted = encrypted[0:block_size] + '\x00'*block_size + encrypted[0:block_size] + encrypted[block_size*2:] d_oracle(modified_encrypted) print "[-] An error should've occured. It didn't. Thereby, an error occurred." except PaddingException: print "[-] Something somewhere went terribly wrong" except ValueError as e: # This is where we attack recovered_plaintext = str(e) key = xor_data(recovered_plaintext[0:block_size], recovered_plaintext[block_size*2:block_size*3]) if verify_key(key): print "[+] Cracked key = %s" % repr(key) else: print "[+] Cracking failed with = %s" % repr(key)
def crack(e_oracle, d_oracle): block_size = get_len_of_block_cipher(e_oracle) print "[+] Block size = %d" % block_size input_plaintext = 'x' * (3 * block_size) encrypted = e_oracle(input_plaintext) try: modified_encrypted = encrypted[ 0:block_size] + '\x00' * block_size + encrypted[ 0:block_size] + encrypted[block_size * 2:] d_oracle(modified_encrypted) print "[-] An error should've occured. It didn't. Thereby, an error occurred." except PaddingException: print "[-] Something somewhere went terribly wrong" except ValueError as e: # This is where we attack recovered_plaintext = str(e) key = xor_data(recovered_plaintext[0:block_size], recovered_plaintext[block_size * 2:block_size * 3]) if verify_key(key): print "[+] Cracked key = %s" % repr(key) else: print "[+] Cracking failed with = %s" % repr(key)