Example #1
0
 def test_odd_oracle(self):
     '''Non deterministic test, spikes the oracle to detect its mode.'''
     spike = b'0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
     #10 is arbitrary
     for _ in range(10):
         echo, ecb = aes.odd_encryption_oracle(spike, True)
         if aes.count_block_repeats(echo, 16):
             assert ecb == 1, 'oracle test failed to detect ECB mode'
         else:
             assert ecb == 0, 'oracle test failed to detect CBC mode'
Example #2
0
def find_aes_ecb_ciphers(cipher_address):
    '''Pulls lines from a file, returns likely AES_ECB crypts.'''
    cipher_file = open(os.getcwd() + "/" + cipher_address, "rb")
    cipher_lines = cipher_file.readlines()
    #strip trailing \n
    cipher_lines = [lines.strip() for lines in cipher_lines]
    cipher_file.close()
    #check for an repeated blocks (32 hex characters)
    repeat_lines = []
    for cipher in cipher_lines:
        if aes.count_block_repeats(cipher, 32) > 0:
            repeat_lines.append(cipher)
    #if that's not good enough, check if LOC hamming distances peak at 32 chars.
    return repeat_lines