Beispiel #1
0
    def decrypt_ige(cipher_text, key, iv):
        """
        Decrypts the given text in 16-bytes blocks by using the
        given key and 32-bytes initialization vector.
        """
        if cryptg:
            return cryptg.decrypt_ige(cipher_text, key, iv)

        iv1 = iv[:len(iv) // 2]
        iv2 = iv[len(iv) // 2:]

        aes = pyaes.AES(key)

        plain_text = []
        blocks_count = len(cipher_text) // 16

        cipher_text_block = [0] * 16
        for block_index in range(blocks_count):
            for i in range(16):
                cipher_text_block[i] = \
                    cipher_text[block_index * 16 + i] ^ iv2[i]

            plain_text_block = aes.decrypt(cipher_text_block)

            for i in range(16):
                plain_text_block[i] ^= iv1[i]

            iv1 = cipher_text[block_index * 16:block_index * 16 + 16]
            iv2 = plain_text_block

            plain_text.extend(plain_text_block)

        return bytes(plain_text)
Beispiel #2
0
    def decrypt_ige(cipher_text, key, iv):
        """
        Decrypts the given text in 16-bytes blocks by using the
        given key and 32-bytes initialization vector.
        """
        if cryptg:
            return cryptg.decrypt_ige(cipher_text, key, iv)
        if libssl.decrypt_ige:
            return libssl.decrypt_ige(cipher_text, key, iv)

        iv1 = iv[:len(iv) // 2]
        iv2 = iv[len(iv) // 2:]

        aes = pyaes.AES(key)

        plain_text = []
        blocks_count = len(cipher_text) // 16

        cipher_text_block = [0] * 16
        for block_index in range(blocks_count):
            for i in range(16):
                cipher_text_block[i] = \
                    cipher_text[block_index * 16 + i] ^ iv2[i]

            plain_text_block = aes.decrypt(cipher_text_block)

            for i in range(16):
                plain_text_block[i] ^= iv1[i]

            iv1 = cipher_text[block_index * 16:block_index * 16 + 16]
            iv2 = plain_text_block

            plain_text.extend(plain_text_block)

        return bytes(plain_text)
def generate_Localkey(LocalKey_Block, BaseKey):
    print("\n[+] ======= Generate LocalKey =======\n")

    Localkey_dec_key = load_dec_key(LocalKey_Block)
    print("[DEC_KEY] " + Localkey_dec_key.hex())
    print("")

    AES_KEY, AES_IV = prepare_AES(Localkey_dec_key, BaseKey)
    enc_LocalKey = LocalKey_Block[0x10:]

    LocalKey = cryptg.decrypt_ige(enc_LocalKey, AES_KEY, AES_IV)

    print("[LOCALKEY]")
    print(LocalKey.hex())
    open(o_Localkey_file, "wb").write(LocalKey)
def generate_AuthKey(path):
    if os.path.exists(o_Localkey_file) and os.stat(o_Localkey_file).st_size:
        print("\n[+] ======= Generate AuthKey =======\n")
        LocalKey = open(o_Localkey_file, "rb").read()[0x04:]
        AuthKey_file = open(path, "rb").read()

        cur = 0x00
        header = AuthKey_file[cur:cur + 4]
        print("[HEADER] " + header.decode("utf-8"))
        print("")

        cur += 0x04
        version = AuthKey_file[cur:cur + 4]
        print("[VERSION] " + version.hex())
        print("")

        cur += 0x04
        AuthKey_Block_len = int.from_bytes(AuthKey_file[cur:cur + 4], 'big')
        print("[AUTHKEY_BLOCK_LEN] " + hex(AuthKey_Block_len))
        print("")

        cur += 0x04
        AuthKey_block = AuthKey_file[cur:cur + AuthKey_Block_len]

        AuthKey_dec_key = load_dec_key(AuthKey_block)
        print("[DEC_KEY] " + AuthKey_dec_key.hex())
        print("")

        AES_KEY, AES_IV = prepare_AES(AuthKey_dec_key, LocalKey)

        enc_AuthKey = AuthKey_block[0x10:]

        AuthKey = cryptg.decrypt_ige(enc_AuthKey, AES_KEY, AES_IV)

        print("[AUTHKEY]")
        print(AuthKey.hex())
        open(o_AuthKey_file, "wb").write(AuthKey)

    else:
        print("[!] LOCALKEY NOT FOUND")