Пример #1
0
def main():
        if len(sys.argv) < 3:
                key = SAMPLE_KEY
                filename = SAMPLE_FILENAME
        else:
                key = sys.argv[1]
                filename = sys.argv[2]

        f = open(filename, "r")
        ciphertext = ""
        for line in f:
                ciphertext += common.b64decode(line.rstrip())

        print common.aes_cbc_decrypt(ciphertext, key, "\x00" * 16)
        
        
        if False:
                for _ in range(1000):
                        key = common.randbytes(16)
                        pt = common.randbytes(random.randint(1, 64))
                        iv = common.randbytes(16)

                        AFTER = binascii.hexlify(common.aes_cbc_decrypt(common.aes_cbc_encrypt(pt, key, iv), key, iv))

                        PT = binascii.hexlify(common.pkcs7_pad(pt, len(pt) + (16 - (len(pt) % 16))))

                        print PT == AFTER
def get_target():
        global key
        IV = common.randbytes(16)
        text = common.b64decode(random.choice(choices))

        ct = common.aes_cbc_encrypt(text, key, IV)
        return ct, IV
def encryption_oracle(pt):
        global key
        global IV

        sanitized = pt.replace(";", "%%3b").replace("=", "%%3d")

        return common.aes_cbc_encrypt("comment1=cooking%%20MCs;userdata=%s;comment2=%%20like%%20a%%20pound%%20of%%20bacon" % sanitized, key, IV)
def get_target():
    global key
    IV = common.randbytes(16)
    text = common.b64decode(random.choice(choices))

    ct = common.aes_cbc_encrypt(text, key, IV)
    return ct, IV
Пример #5
0
def encryption_oracle(pt):
    global key
    global IV

    sanitized = pt.replace(";", "%%3b").replace("=", "%%3d")

    return common.aes_cbc_encrypt(
        "comment1=cooking%%20MCs;userdata=%s;comment2=%%20like%%20a%%20pound%%20of%%20bacon"
        % sanitized, key, IV)
Пример #6
0
def encryption_oracle(pt):
        key = common.randbytes(16)
        pt = common.randbytes(random.randint(5, 10)) + pt + common.randbytes(random.randint(5, 10))

        if random.randint(0, 1) == 1:
                print "actually doing ECB"
                ret = common.aes_ecb_encrypt(pt, key)
        else:
                print "actually doing CBC"
                ret = common.aes_cbc_encrypt(pt, key, common.randbytes(16))

        return ret