示例#1
0
def crack_message(poracle, iv, ciphertext):
    blocks = [iv]
    block_size = len(iv)
    for i in range(len(ciphertext) / block_size):
        blocks.append(ciphertext[i * block_size:(i + 1) * block_size])

    cracked_blocks = []

    for i in range(1, len(blocks)):
        cracked_blocks.append(crack_block(poracle, blocks[i - 1], blocks[i]))

    return pkcs_7_unpad(''.join(cracked_blocks))
示例#2
0
def crack_message(poracle, iv, ciphertext):
  blocks = [iv]
  block_size = len(iv)
  for i in range(len(ciphertext) / block_size):
    blocks.append(ciphertext[i*block_size:(i+1)*block_size])

  cracked_blocks = []

  for i in range(1,len(blocks)):
    cracked_blocks.append(crack_block(poracle,blocks[i-1],blocks[i]))

  return pkcs_7_unpad(''.join(cracked_blocks))
示例#3
0
def crack(oracle):
    block_length = len_of_cipher_block(oracle)
    print 'Block-length : ' + str(block_length)

    if (verify_ECB_mode(oracle, block_length)):
        print 'ECB mode verified'

    #real decryption starts
    oracle = rm_random_chrs(oracle, block_length)
    msg = ''
    for i in range(0, len(oracle(''))):
        try:
            msg += find_nxt_chr(oracle, block_length, msg)
            print msg
        except:
            pass

    return pkcs_7_unpad(msg)
示例#4
0
def crack(oracle):
  block_size = get_len_of_block_cipher(oracle)
  print "[+] Identified block size = " + str(block_size)
  if not verify_ECB_mode(oracle, block_size):
    print "[-] Not ECB encryption oracle"
    return
  else:
    print "[+] Verified ECB encryption"

  complete_message_len = len(oracle(''))

  message = ''
  for i in range(complete_message_len):
    try:
      message += pull_next_letter(oracle, block_size, message)
    except:
      break

  return pkcs_7_unpad(message)
示例#5
0
def crack(oracle):
    block_size = get_len_of_block_cipher(oracle)
    print "[+] Identified block size = " + str(block_size)
    if not verify_ECB_mode(oracle, block_size):
        print "[-] Not ECB encryption oracle"
        return
    else:
        print "[+] Verified ECB encryption"

    complete_message_len = len(oracle(''))

    message = ''
    for i in range(complete_message_len):
        try:
            message += pull_next_letter(oracle, block_size, message)
        except:
            break

    return pkcs_7_unpad(message)
示例#6
0
def crack(data,oracle):
	no_of_blocks=len(data)/16
	blocks=[random_IV]
	for block_no in range(no_of_blocks):
		blocks.append(data[block_no*16:(block_no+1)*16])
	
	msg=''
	for i in range(1,len(blocks)):
		block_msg=''
		for j in range(16):
			try:
				block_msg=find_nxt_chr(data,blocks[i-1],blocks[i],block_msg,oracle)+block_msg
			except:
				pass
		msg+=block_msg

	return (msg)

if __name__ == '__main__':
	msg=[]
	
	while True:
		try:
			if (len(msg)==10):
				break
			cracked_msg=pkcs_7_unpad(crack(encryption_oracle(),padding_oracle))
			if ( not (cracked_msg in msg)):
				msg.append(cracked_msg)
				print cracked_msg
		except:
			print 'EX'
示例#7
0
#! /usr/bin/env python

from AES_128 import pkcs_7_unpad, PaddingException

cases = [
    "ICE ICE BABY\x04\x04\x04\x04", "ICE ICE BABY\x05\x05\x05\x05",
    "ICE ICE BABY\x01\x02\x03\x04"
]

for i in range(len(cases)):
    try:
        print "Case %d passed. String = %s" % (i, repr(pkcs_7_unpad(cases[i])))
    except PaddingException:
        print "Case %d went wrong. Caught PaddingException." % i
示例#8
0
#! /usr/bin/env python

from AES_128 import pkcs_7_unpad, PaddingException

cases = [
  "ICE ICE BABY\x04\x04\x04\x04",
  "ICE ICE BABY\x05\x05\x05\x05",
  "ICE ICE BABY\x01\x02\x03\x04"
]

for i in range(len(cases)):
  try:
    print "Case %d passed. String = %s" % (i, repr(pkcs_7_unpad(cases[i])))
  except PaddingException:
    print "Case %d went wrong. Caught PaddingException." % i