示例#1
0
def edit_api(offset, newtext):  # ciphertext, key are taken from
    # global variables, and ciphertext is
    # edited directly
    global ciphertext
    assert (offset >= 0)
    assert (offset + len(newtext) <= len(ciphertext))
    dec = AES_CTR(ciphertext, KEY, NONCE)
    mod = dec[:offset] + newtext + dec[offset + len(newtext):]
    ciphertext = AES_CTR(mod, KEY, NONCE)
示例#2
0
def get_enc():
    with open('data/20.txt', 'r') as f:
        data = f.read().split()

    data = [a.decode('base64') for a in data]

    key = randstr(16)
    nonce = randint(0, 2**64 - 1)

    enc = [AES_CTR(a, key, nonce) for a in data]

    return enc
示例#3
0
VGhpcyBvdGhlciBtYW4gSSBoYWQgZHJlYW1lZA==
QSBkcnVua2VuLCB2YWluLWdsb3Jpb3VzIGxvdXQu
SGUgaGFkIGRvbmUgbW9zdCBiaXR0ZXIgd3Jvbmc=
VG8gc29tZSB3aG8gYXJlIG5lYXIgbXkgaGVhcnQs
WWV0IEkgbnVtYmVyIGhpbSBpbiB0aGUgc29uZzs=
SGUsIHRvbywgaGFzIHJlc2lnbmVkIGhpcyBwYXJ0
SW4gdGhlIGNhc3VhbCBjb21lZHk7
SGUsIHRvbywgaGFzIGJlZW4gY2hhbmdlZCBpbiBoaXMgdHVybiw=
VHJhbnNmb3JtZWQgdXR0ZXJseTo=
QSB0ZXJyaWJsZSBiZWF1dHkgaXMgYm9ybi4=
'''.split()

data = [a.decode('base64') for a in data]

key = randstr(16)
nonce = randint(0, 2**64 - 1)

enc = [AES_CTR(a, key, nonce) for a in data]

print enc
print
print "I am too lazy to solve this by hand, but if you want to do so, above are the encrypted texts."
print "Here are some ideas for solving:"
print "  1. Pair them off"
print "  2. XOR them"
print "  3. Check for frequencies"
print "  4. Check for bigrams"
print "  5. Check for trigrams"
print "  6. ???"
print "  7. Profit!"
示例#4
0
from common import AES_CTR

data = 'L77na/nrFsKvynd6HzOoG7GHTLXsTVu9qvY/2syLXzhPweyyMTJULu/6/kXX0KSvoOLSFQ=='.decode(
    'base64')

print repr(AES_CTR(data, 'YELLOW SUBMARINE', 0))
示例#5
0
from common import AES_ECB_decrypt, AES_CTR, randstr
from random import randint


def get_data():
    with open('data/25.txt', 'r') as f:
        data = f.read().decode('base64')
    key = "YELLOW SUBMARINE"
    return AES_ECB_decrypt(data, key)


KEY, NONCE = randstr(16), randint(0, 1 << 64 - 1)
print "[+] Using KEY, NONCE = %s, 0x%x" % (repr(KEY), NONCE)
ciphertext = AES_CTR(get_data(), KEY, NONCE)


def edit_api(offset, newtext):  # ciphertext, key are taken from
    # global variables, and ciphertext is
    # edited directly
    global ciphertext
    assert (offset >= 0)
    assert (offset + len(newtext) <= len(ciphertext))
    dec = AES_CTR(ciphertext, KEY, NONCE)
    mod = dec[:offset] + newtext + dec[offset + len(newtext):]
    ciphertext = AES_CTR(mod, KEY, NONCE)


def break_ctr(edit):
    from common import xor_str
    enc = ciphertext[:]
    edit(0, '\x00' * len(enc))
示例#6
0
def encryption_oracle(data):
    data = data.replace(';', '').replace('=', '')
    data = "comment1=cooking%20MCs;userdata=" + data
    data = data + ";comment2=%20like%20a%20pound%20of%20bacon"
    return AES_CTR(data, oracle_key, oracle_nonce)
示例#7
0
def decryption_oracle(data):
    dec = AES_CTR(data, oracle_key, oracle_nonce)
    return ';admin=true;' in dec