APFS file system data recovery method, device and electronic device

By decrypting the keybag of containers and partitions, we can find deleted files in the APFS file system, solve the problem of data recovery in the APFS file system, and achieve rapid recovery and extraction of files.

CN111737057BActive Publication Date: 2024-09-17AFIRSTSOFT CO LTD
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202010591596.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-24
Publication Date
2024-09-17
Estimated Expiration
2040-06-24

AI Technical Summary

Technical Problem

Existing technology lacks a method to quickly recover and extract deleted files in the APFS file system, which is limited by its unique file format and high encryption capabilities.

Method used

By determining whether the container and partition are encrypted, decrypt the corresponding keybag, use the AES-XTS or PBKDF2 algorithm to obtain the decryption key, and find and recover deleted files.

Benefits of technology

It realizes the rapid recovery and extraction of deleted files in the APFS file system and overcomes the problem of data recovery under encryption function.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111737057B
    Figure CN111737057B
Patent Text Reader

Abstract

One or more embodiments of the present specification provide a method, device and electronic device for recovering data from an APFS file system, the method comprising determining whether a container is encrypted; if the container is encrypted, decrypting the keybag of the container to obtain the keybag of the partitions corresponding to each partition in the container; determining whether a partition is encrypted; if the partition is encrypted, decrypting the keybag of the partition to obtain the key; using the key to decrypt the blocks in the encrypted partition; searching for deleted files in the decrypted partition, and recovering the deleted files. In the present invention, the keybag of the encrypted container is first decrypted to obtain the keybag of the partition, and then the keybag of the partition is decrypted to obtain the key, and then the encrypted partition is decrypted using the key, the deleted files in the decrypted partition are searched, and the deleted files are recovered, thereby realizing the recovery and extraction of deleted files.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of the present specification relate to the technical field of APFS file system data recovery, and in particular, to an APFS file system data recovery method, device, and electronic device. Background Art

[0002] APFS is the abbreviation of Apple File System. It is the next-generation file system created by Apple for Apple devices to replace the old HFS+ file system. Its characteristics are "optimization of flash memory / SSD storage and encryption as the main function". The core of the system is encryption function, which can run on all platforms including iOS, macOS, tvOS, and watchOS. The system includes multi-key encryption function, with built-in keys for each file, and independent keys for sensitive metadata.

[0003] The inventors have discovered that due to the unique file format and high encryption capabilities of APFS, there is currently a lack of a method for quickly recovering and extracting deleted files in APFS. Summary of the invention

[0004] In view of this, the purpose of one or more embodiments of the present specification is to propose an APFS file system data recovery method, device and electronic device to solve the technical problems in the prior art.

[0005] Based on the above purpose, one or more embodiments of this specification provide an APFS file system data recovery method, including:

[0006] Determine whether the container is encrypted;

[0007] If the container is encrypted, decrypt the keybag of the container to obtain the partition keybag corresponding to each partition in the container;

[0008] Determine whether the partition is encrypted;

[0009] If the partition is encrypted, decrypt the keybag of the partition to obtain the key;

[0010] Decrypt the blocks in the encrypted partition using the key;

[0011] Find the deleted files in the decrypted partition and restore the deleted files.

[0012] As an optional implementation, the determining whether the container is encrypted includes:

[0013] Start from the beginning and traverse the disk to find the first superblock with the "NXSB" flag;

[0014] If the starting id and size of the keybag in the super block are not 0, the container is encrypted.

[0015] As an optional implementation, the determining whether the partition is encrypted includes:

[0016] Find the block with "APSB" flag from the super block;

[0017] If the starting ID and size of the keybag in the block with the "APSB" mark are not 0, the partition is encrypted.

[0018] As an optional implementation, decrypting the keybag of the container to obtain the keybag of the partition corresponding to each partition in the container includes:

[0019] Read the container's keybag data based on the container's keybag's starting id and size;

[0020] The uuid of the container is used as the key, and the read keybag data is decrypted using the AES-XTS algorithm to obtain the keybag of the partition corresponding to each partition in the container.

[0021] As an optional implementation, the keybag of the partition is decrypted to obtain the key, including

[0022] According to the partition's uuid, find the corresponding partition's keybag;

[0023] Read the partition's keybag data based on the partition's keybag starting id and size;

[0024] Use the partition's uuid as the key and use the AES-XTS algorithm to decrypt the keybag data to obtain the decrypted data.

[0025] Extract the salt value, iteration count, and wrapping key from the decrypted data;

[0026] The partition password, salt value, and iteration number of the partition are used as input and substituted into the hash function to generate a hash value;

[0027] Use the AES password wrapping algorithm, use the wrapping key and initial iv to unpack the hash value to obtain the intermediate value and iterative iv;

[0028] Use the AES password wrapping algorithm, use the wrapping key and the iterative iv, unpack the intermediate value again to obtain the key.

[0029] As an optional implementation, the partition password, salt value, and number of iterations of the partition are used as inputs and substituted into a hash function to generate a hash value.

[0030] The partition password, salt value, and number of iterations of the partition are taken as input, and the PBKDF2 algorithm and hash function sha256 are used to generate a hash value.

[0031] As an optional implementation, the searching for deleted files in the decrypted partition includes:

[0032] Find the latest snapshot in the partition;

[0033] The data of the historical snapshots in the partition are compared with the data in the latest snapshot to obtain the deleted files in the partition.

[0034] Corresponding to the APFS file system data recovery device, the present invention further provides an APFS file system data recovery device, comprising:

[0035] A first determination module, used to determine whether the container is encrypted;

[0036] A first decryption module, when the container is encrypted, is used to decrypt the keybag of the container to obtain the keybag of the partition corresponding to each partition in the container;

[0037] The second judgment module is used to judge whether the partition is encrypted;

[0038] A second decryption module, when the partition is encrypted, is used to decrypt the keybag of the partition to obtain the key;

[0039] A third decryption module, used to decrypt the blocks in the encrypted partition using the key;

[0040] The search and recovery module is used to search for deleted files in the decrypted partition and recover the deleted files.

[0041] As an optional implementation, the second decryption module includes

[0042] The search unit is used to find the keybag of the corresponding partition according to the uuid of the partition;

[0043] A reading unit is used to read the keybag data of the partition according to the starting ID and size of the keybag of the partition;

[0044] The first decryption unit is used to use the partition uuid as a key, decrypt the read keybag data using the AES-XTS algorithm, and obtain decrypted data;

[0045] An extraction unit, used to extract the salt value, iteration number and wrapping key from the decrypted data;

[0046] A generating unit, used for taking the partition password, salt value, and iteration number of the partition as input, substituting into the hash function, and generating a hash value;

[0047] A first unpacking unit is used to use the AES cryptographic wrapping algorithm to unpack the hash value using the wrapping key and the initial IV to obtain an intermediate value and an iterative IV;

[0048] The second unpacking unit is used to use the AES cryptographic wrapping algorithm, the wrapping key, and the iterative iv to unpack the intermediate value again to obtain the key.

[0049] Corresponding to the APFS file system data recovery device, the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described above when executing the program.

[0050] From the above description, it can be seen that one or more embodiments of the present specification provide an APFS file system data recovery method, device and electronic device, which first decrypts the keybag of the encrypted container to obtain the keybag of the partition, and then decrypts the keybag of the partition to obtain the key, and then uses the key to decrypt the encrypted partition, searches for deleted files in the decrypted partition, and restores the deleted files, thereby realizing the recovery and extraction of deleted files. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] In order to more clearly illustrate one or more embodiments of the present specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only one or more embodiments of the present specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0052] Figure 1 A logical schematic diagram of an APFS file system data recovery method according to one or more embodiments of this specification;

[0053] Figure 2 A logical diagram of S400 of the APFS file system data recovery method of one or more embodiments of this specification;

[0054] Figure 3 A schematic diagram of an APFS file system data recovery device according to one or more embodiments of the present specification;

[0055] Figure 4 A schematic diagram of a second decryption module of an APFS file system data recovery device according to one or more embodiments of this specification.

[0056] Figure 5 A schematic diagram of an electronic device according to one or more embodiments of the present specification. DETAILED DESCRIPTION

[0057] In order to make the objectives, technical solutions and advantages of the present disclosure more clearly understood, the present disclosure is further described in detail below in combination with specific embodiments and with reference to the accompanying drawings.

[0058] To achieve the above purpose, the embodiments of the present invention provide an APFS file system data recovery method, device and electronic device, which can be applied to Apple series terminals, such as iPhone series, iPad series, iMac series, etc., or terminals connected to Apple series terminals, such as servers, cloud servers, server clusters, etc., without specific limitation. The APFS file system data recovery method provided by the embodiments of the present invention is first described in detail below.

[0059] An embodiment of the present invention provides an APFS file system data recovery method, comprising:

[0060] S100, determining whether the container is encrypted;

[0061] S200: If the container is encrypted, decrypt the keybag of the container to obtain the keybag of the partition corresponding to each partition in the container;

[0062] S300, determining whether the partition is encrypted;

[0063] S400, if the partition is encrypted, decrypt the keybag of the partition to obtain a key;

[0064] S500, decrypting the blocks in the encrypted partition using the key;

[0065] S600: Search for deleted files in the decrypted partition, and restore the deleted files.

[0066] In this embodiment, the keybag of the encrypted container is first decrypted to obtain the keybag of the partition, and then the keybag of the partition is decrypted to obtain the key. The encrypted partition is then decrypted using the key, the deleted files in the decrypted partition are searched, and the deleted files are restored, thereby realizing the recovery and extraction of deleted files.

[0067] Please check Figure 1This embodiment provides an APFS file system data recovery method, including:

[0068] S100: Determine whether the container is encrypted.

[0069] Optionally, S100 includes

[0070] S110, traverse the disk from the beginning to find the first superblock with the "NXSB" mark;

[0071] S120: If the starting ID and the size of the keybag in the super block are not 0, the container is encrypted.

[0072] Among them, super block: The super block is used to store basic information of the container. For example, the super block records the size of each area, and the super block also stores information about unused disk blocks.

[0073] Among them, keybag: key bag, start id represents the block number, and size is the starting offset of keybag.

[0074] S200: If the container is encrypted, decrypt the keybag of the container to obtain the keybag of the partition corresponding to each partition in the container.

[0075] In this embodiment, S200 includes

[0076] S210, reading the keybag data of the container according to the starting ID and size of the keybag of the container;

[0077] Among them, keybag: key bag, start id represents the block number, size is the start offset of keybag, and the content of keybag can be read according to the start offset and size.

[0078] S220. Using the uuid of the container as a key, the read keybag data is decrypted using the AES-XTS algorithm to obtain the keybag of the partition corresponding to each partition in the container.

[0079] Among them, uuid: Universally Unique Identifier, universally unique identifier.

[0080] S300: Determine whether the partition is encrypted.

[0081] In this embodiment, S300 includes

[0082] S310, finding a block with an "APSB" mark from the super block, where the block stores basic information of the partition;

[0083] S320: If the starting ID and the size of the keybag in the block with the "APSB" mark are not 0, the partition is encrypted.

[0084] S400: If the partition is encrypted, decrypt the keybag of the partition to obtain a key.

[0085] In this embodiment, if Figure 2 As shown, S400 includes

[0086] S410, find the keybag of the corresponding partition according to the uuid of the partition;

[0087] Specifically, the keybag of the partition corresponding to the uuid is found from S200.

[0088] S420, read the keybag data of the partition according to the starting ID and size of the keybag of the partition;

[0089] S430, using the partition uuid as a key, decrypting the read keybag data using the AES-XTS algorithm to obtain decrypted data;

[0090] S440, extracting the salt value, the number of iterations, and the package key from the decrypted data;

[0091] Specifically, 0×28 bytes starting from 0×50 bytes of the decrypted data are used as the wrapping key, an 8-byte integer starting from 0×88 bytes is used as the iteration value, and a 16-byte value obtained from 0×90 bytes is used as the salt value.

[0092] S450, taking the partition password, salt value, and number of iterations of the partition as input, substituting them into a hash function to generate a hash value;

[0093] Specifically, the partition password, salt value, and number of iterations of the partition are taken as input, the PBKDF2 algorithm is used, and the hash function uses sha256 to generate a hash value.

[0094] S460, using the AES password wrapping algorithm, using the wrapping key and initial IV, unpacking the hash value to obtain an intermediate value and an iterative IV;

[0095] Among them, the initial iv value is 0.

[0096] S470, using the AES cryptographic wrapping algorithm, using the wrapping key and the iterative iv, unpacking the intermediate value again to obtain the key.

[0097] S500: Decrypt the blocks in the encrypted partition using the key.

[0098] S600: Search for deleted files in the decrypted partition, and restore the deleted files.

[0099] In this embodiment, the searching for deleted files in the decrypted partition in S600 includes:

[0100] S610, find the latest snapshot in the partition;

[0101] S620: Compare the data of the historical snapshots in the partition with the data in the latest snapshot to obtain deleted files in the partition.

[0102] It can be understood that the method can be executed by any device, equipment, platform, or device cluster having computing and processing capabilities.

[0103] It should be noted that the method of one or more embodiments of this specification can be performed by a single device, such as a computer or server. The method of this embodiment can also be applied in a distributed scenario and completed by multiple devices cooperating with each other. In the case of such a distributed scenario, one of the multiple devices can only perform one or more steps in the method of one or more embodiments of this specification, and the multiple devices will interact with each other to complete the described method.

[0104] Please check Figure 3 Corresponding to the APFS file system data recovery method, the present invention also provides an APFS file system data recovery device, including:

[0105] A first determination module 10, used to determine whether the container is encrypted;

[0106] A first decryption module 20, when the container is encrypted, is used to decrypt the keybag of the container to obtain the partition keybag corresponding to each partition in the container;

[0107] The second determination module 30 is used to determine whether the partition is encrypted;

[0108] The second decryption module 40 is used to decrypt the keybag of the partition to obtain the key when the partition is encrypted;

[0109] A third decryption module 50, used to decrypt the blocks in the encrypted partition using the key;

[0110] The search and recovery module 60 is used to search for deleted files in the decrypted partition and recover the deleted files.

[0111] In this embodiment, the keybag of the encrypted container is first decrypted to obtain the keybag of the partition, and then the keybag of the partition is decrypted to obtain the key. The encrypted partition is then decrypted using the key, the deleted files in the decrypted partition are searched, and the deleted files are restored, thereby realizing the recovery and extraction of deleted files.

[0112] As an optional implementation, Figure 4 As shown, the second decryption module 40 includes

[0113] A search unit 41 is used to find the keybag of the corresponding partition according to the uuid of the partition;

[0114] A reading unit 42, configured to read the keybag data of the partition according to the starting ID and size of the keybag of the partition;

[0115] The first decryption unit 43 is used to use the partition uuid as a key to decrypt the read keybag data using the AES-XTS algorithm to obtain decrypted data;

[0116] An extraction unit 44, used to extract a salt value, an iteration number, and a wrapping key from the decrypted data;

[0117] A generating unit 45 is used to take the partition password, salt value, and iteration number of the partition as input, substitute into the hash function, and generate a hash value;

[0118] A first unpacking unit 46 is used to use the AES cryptographic wrapping algorithm to unpack the hash value using the wrapping key and the initial IV to obtain an intermediate value and an iterative IV;

[0119] The second unpacking unit 47 is used to use the AES cryptographic wrapping algorithm, the wrapping key, and the iterative iv to unpack the intermediate value again to obtain the key.

[0120] For the convenience of description, the above devices are described in terms of functions divided into various modules. Of course, when implementing one or more embodiments of this specification, the functions of each module can be implemented in the same or multiple software and / or hardware.

[0121] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in one or more embodiments of this specification should be understood by people with ordinary skills in the field to which this disclosure belongs. The words "first", "second" and similar words used in one or more embodiments of this specification do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprises" and similar words mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects.

[0122] The above is a description of a specific embodiment of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0123] Figure 5 A more specific schematic diagram of the hardware structure of an electronic device provided in this embodiment is shown, and the device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040 are connected to each other through the bus 1050 in the device.

[0124] The processor 1010 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.

[0125] The memory 1020 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 may store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 1020 and are called and executed by the processor 1010.

[0126] The input / output interface 1030 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.

[0127] The communication interface 1040 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through a wired mode (such as USB, network cable, etc.) or a wireless mode (such as mobile network, WIFI, Bluetooth, etc.).

[0128] The bus 1050 includes a path that transmits information between the various components of the device (eg, the processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040).

[0129] It should be noted that, although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040 and the bus 1050, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.

[0130] Those skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present disclosure (including the claims) is limited to these examples. In line with the present disclosure, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of different aspects of one or more embodiments of the present specification as described above, which are not provided in detail for the sake of simplicity.

[0131] One or more embodiments of this specification are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of this specification should be included in the scope of protection of this disclosure.

Claims

1. A method for recovering APFS file system data. It is characterized in that include: Determine whether the container is encrypted; the determination of whether the container is encrypted includes traversing the disk from the beginning to find the first super block with an "NXSB" mark; if the starting ID and size of the keybag in the super block are not 0, the container is encrypted; If the container is encrypted, decrypt the keybag of the container to obtain the partition keybag corresponding to each partition in the container; decrypting the keybag of the container to obtain the partition keybag corresponding to each partition in the container includes: reading the keybag data of the container according to the starting ID and size of the keybag of the container; using the uuid of the container as the key, decrypting the read keybag data using the AES-XTS algorithm to obtain the partition keybag corresponding to each partition in the container; Determine whether the partition is encrypted; the determining whether the partition is encrypted includes finding a block with an "APSB" mark from the super block; if the starting ID and the size of the keybag in the block with the "APSB" mark are not 0, the partition is encrypted; If the partition is encrypted, decrypt the keybag of the partition to obtain the key; Decrypt the blocks in the encrypted partition using the key; Finding deleted files in the decrypted partition and restoring the deleted files; The decrypting of the keybag of the partition to obtain the key includes: finding the keybag of the corresponding partition according to the uuid of the partition; Read the partition's keybag data based on the partition's keybag starting id and size; Use the partition's uuid as the key and use the AES-XTS algorithm to decrypt the keybag data to obtain the decrypted data. Extract the salt value, iteration count, and wrapping key from the decrypted data; The partition password, salt value and iteration number of the partition are used as input, substituted into the hash function, and a hash value is generated; Use the AES password wrapping algorithm, use the wrapping key and initial iv to unpack the hash value to obtain the intermediate value and iterative iv; Use the AES password wrapping algorithm, use the wrapping key and the iterative iv, unpack the intermediate value again to obtain the key.

2. The APFS file system data recovery method according to claim 1, It is characterized in that The partition password, salt value and number of iterations of the partition are taken as input and substituted into the hash function to generate the hash value, which includes taking the partition password, salt value and number of iterations of the partition as input, using the PBKDF2 algorithm and the hash function sha256 to generate the hash value.

3. The APFS file system data recovery method according to claim 1, It is characterized in that The searching for deleted files in the decrypted partition includes finding the latest snapshot in the partition; The data of the historical snapshots in the partition are compared with the data in the latest snapshot to obtain the deleted files in the partition.

4. An APFS file system data recovery device, It is characterized in that include: A first determination module is used to determine whether the container is encrypted; the determination of whether the container is encrypted includes traversing the disk from the beginning to find the first super block with an "NXSB" mark; if the starting ID and size of the keybag in the super block are not 0, the container is encrypted; The first decryption module is used to decrypt the keybag of the container to obtain the keybag of the partition corresponding to each partition in the container when the container is encrypted; the decrypting the keybag of the container to obtain the keybag of the partition corresponding to each partition in the container includes: reading the keybag data of the container according to the starting ID and size of the keybag of the container; Using the container's uuid as the key, the read keybag data is decrypted using the AES-XTS algorithm to obtain the partition keybag corresponding to each partition in the container; The second judgment module is used to judge whether the partition is encrypted; the judgment whether the partition is encrypted includes finding a block with an "APSB" mark from the super block; if the starting ID and size of the keybag in the block with the "APSB" mark are not 0, the partition is encrypted; A second decryption module, when the partition is encrypted, is used to decrypt the keybag of the partition to obtain the key; A third decryption module, used to decrypt the blocks in the encrypted partition using the key; A search and recovery module, used to search for deleted files in the decrypted partition and recover the deleted files; The second decryption module includes a search unit, which is used to find the keybag of the corresponding partition according to the uuid of the partition; A reading unit is used to read the keybag data of the partition according to the starting ID and size of the keybag of the partition; The first decryption unit is used to use the partition uuid as a key, decrypt the read keybag data using the AES-XTS algorithm, and obtain decrypted data; An extraction unit, used to extract the salt value, iteration number and wrapping key from the decrypted data; A generating unit, used for taking the partition password, salt value and iteration number of the partition as input, substituting into the hash function, and generating a hash value; A first unpacking unit is used to use the AES cryptographic wrapping algorithm to unpack the hash value using the wrapping key and the initial IV to obtain an intermediate value and an iterative IV; The second unpacking unit is used to use the AES cryptographic wrapping algorithm, the wrapping key, and the iterative iv to unpack the intermediate value again to obtain the key.

5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, the method according to any one of claims 1 to 3 is implemented.

Citation Information

Patent Citations

  • System for cracking and restoring iPhone encrypted backup files

    CN102750495A

  • Massive data storage method based on file granularity

    CN104657459A

  • Construction method of multi-tenant big data platform based on container

    CN106569895A

  • Data recovery method for APFS file system

    CN110232004A

  • A method of recovering damaged data and deleted data in APFS based on interval block

    CN110297729A