Exemplo n.º 1
0
def p12():
    target = b64decode(
        'Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkg'
        'aGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBq'
        'dXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUg'
        'YnkK')

    block_size = _detect_block_size(target)
    tmp_ctxt = _encrypt('A' * block_size * 4)
    assert detect_ecb_mode(tmp_ctxt)

    return _crack_blocks(target, 'A' * block_size, block_size)
Exemplo n.º 2
0
def _find_offset(data, block_size, prefix):
    ecb_detect = 'A' * block_size * 3
    ctxt = _encrypt(prefix+ecb_detect+data)

    while detect_ecb_mode(ctxt):
        ecb_detect = ecb_detect[:-1]
        ctxt = _encrypt(prefix+ecb_detect+data)

    ecb_detect += 'A'
    ctxt = _encrypt(prefix+ecb_detect+data)
    pad_offset = len(ecb_detect) % block_size

    for i in range(len(ctxt) / block_size):
        n_0, n_1, n_2 = map(lambda x: block_size * x, range(i, i + 3))
        cur_block, next_block = ctxt[n_0:n_1], ctxt[n_1:n_2]

        if cur_block == next_block:
            return n_0 - pad_offset