Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python IOS 10.1.1解密和加密iphone备份?_Python_Ios_Iphone_Encryption - Fatal编程技术网

如何使用python IOS 10.1.1解密和加密iphone备份?

如何使用python IOS 10.1.1解密和加密iphone备份?,python,ios,iphone,encryption,Python,Ios,Iphone,Encryption,所以我越来越接近了,但我似乎还不能让这行代码正常工作:key=manifest[kb].unwrapKeyForClassrecord.protection\u class,record.encryption\u key[4:] 附件是我到目前为止拥有的代码,但我仍然不知道在备份中在哪里可以找到这些信息。希望有人能给我指出正确的方向 from hashlib import md5 from Crypto.Cipher import AES from Crypto import Random im

所以我越来越接近了,但我似乎还不能让这行代码正常工作:key=manifest[kb].unwrapKeyForClassrecord.protection\u class,record.encryption\u key[4:]

附件是我到目前为止拥有的代码,但我仍然不知道在备份中在哪里可以找到这些信息。希望有人能给我指出正确的方向

from hashlib import md5
from Crypto.Cipher import AES
from Crypto import Random
import os
import re
import sqlite3
from keystore.keybag import Keybag
from util import readPlist, makedirs
import sys
import plistlib

showinfo = ["Device Name", "Display Name", "Last Backup Date", "IMEI",
            "Serial Number", "Product Type", "Product Version", "iTunes Version"]

def extract_backup(backup_path, output_path, password=""):
    if not os.path.exists(backup_path + "/Manifest.plist"):
        print "Manifest.plist not found"
        return
    manifest = readPlist(backup_path + "/Manifest.plist")

    info = readPlist( backup_path + "/Info.plist")
    for i in showinfo:
        print i + " : " + unicode(info.get(i, "missing"))

    print "Extract backup to %s ? (y/n)" % output_path
    if raw_input() == "n":
        return

    print "Backup is %sencrypted" % (int(not manifest["IsEncrypted"]) * "not ")

    if manifest["IsEncrypted"] and password == "":
        print "Enter backup password : "
        password = raw_input()

    if (manifest["IsEncrypted"]):
        manifest["password"] = password
        manifest["kb"] = Keybag.createWithBackupManifest(manifest, password)
        makedirs(output_path)
        plistlib.writePlist(manifest, output_path + "/Manifest.plist")

        decrypt_backup10(backup_path, output_path, manifest)

def extract_all():
    if sys.platform == "win32":
        mobilesync = os.environ["APPDATA"] + "/Apple Computer/MobileSync/Backup/"
    elif sys.platform == "darwin":
        mobilesync = os.environ["HOME"] + "/Library/Application Support/MobileSync/Backup/"
    else:
        print "Unsupported operating system"
        return
    print "-" * 60
    print "Searching for iTunes backups"
    print "-" * 60

    for udid in os.listdir(mobilesync):
        extract_backup(mobilesync + "/" + udid, udid + "_extract")

def decrypt_backup10(backup_path, output_path, manifest):
    connection = sqlite3.connect(backup_path + "/Manifest.db")
    try:
        connection.row_factory = sqlite3.Row
        cursor = connection.cursor()

        for record in cursor.execute("SELECT * FROM Files"):
            extract_file(backup_path, output_path, record, manifest, kb)
    except:
        connection.close()

def extract_file(backup_path, output_path, record, manifest):
    # read backup file
    try:
        fileID = record["fileID"]
        filename = os.path.join(backup_path, fileID[:2], fileID)
        f1 = file(filename, "rb")
        print(filename)
    except(IOError), e:
        #print(e)
        print "WARNING: File %s (%s) has not been found" % (filename, record["relativePath"])
        return

    # write output file
    output_path = os.path.join(output_path, fileID[:2], fileID)
    ensure_dir_exists(output_path)

    print("Writing %s" % output_path)
    f2 = file(output_path, 'wb')

    aes = None
    if manifest["IsEncrypted"] and manifest["kb"]:
        key = manifest["kb"].unwrapKeyForClass(record.protection_class, record.encryption_key[4:])
        if not key:
            warn("Cannot unwrap key")
            return
        aes = AES.new(key, AES.MODE_CBC, "\x00"*16)

    while True:
        data = f1.read(8192)
        if not data:
            break
        if aes:
            data2 = data = aes.decrypt(data)
        f2.write(data)

    f1.close()
    if aes:
        c = data2[-1]
        i = ord(c)
        if i < 17 and data2.endswith(c*i):
            f2.truncate(f2.tell() - i)
        else:
            warn("Bad padding, last byte = 0x%x !" % i)

    f1.close()
    f2.close()

def ensure_dir_exists(filename):
    if not os.path.exists(os.path.dirname(filename)):
        os.makedirs(os.path.dirname(filename))

def main():
    extract_backup(input, output, password)

if __name__ == "__main__":
    main()