Host file check method, electronic device and storage medium

By using snapshot sharing and difference calculation in the host security detection system, the problems of resource occupation and poor stability in traditional methods are solved, and efficient host file detection without agents and intrusions is achieved, which is suitable for elastic scenarios.

WO2024188134A1PCT designated stage expired Publication Date: 2024-09-19HANGZHOU ALICLOUD FEITIAN INFORMATION TECH CO LTD

Patent Information

Application Number
PCT/CN2024/080386
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-03-16
Filing Date
2024-03-06
Publication Date
2024-09-19

AI Technical Summary

Technical Problem

Traditional host file detection methods occupy a lot of resources, have poor service stability, and are complex to deploy. Especially in elastic scenarios, it is difficult to achieve efficient file scanning.

Method used

Through the snapshot sharing function between the host security detection system and the target host, file system snapshots at different times are obtained, and difference calculations are performed to determine whether files have changed, achieving agentless file detection, reducing resource usage, and improving stability.

Benefits of technology

It achieves agentless and non-intrusive host security detection, reduces the occupation of target host resources, improves the stability of detection and ease of deployment, and is suitable for elastic scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024080386_19092024_PF_FP_ABST
    Figure CN2024080386_19092024_PF_FP_ABST
Patent Text Reader

Abstract

Provided in the present application are a host file check method, an electronic device and a storage medium. The host file check method comprises: acquiring a first snapshot and a second snapshot in a target host on the basis of a snapshot sharing function between a host security check system and the target host, wherein the first snapshot is data backup of a file system in the target host at a first time, the second snapshot is data backup of the file system at a second time, and the first time is earlier than the second time; performing difference calculation on the first snapshot and the second snapshot; and on the basis of a difference calculation result, determining whether a file in the file system has changed. By means of the technical solution of the present application, an agentless file check can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Host file detection method, electronic device and storage medium

[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on March 16, 2023, with application number 202310272989.0 and application name “Host file detection method, electronic device and storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the field of cloud security technology, and in particular to a host file detection method, electronic device, and storage medium. Background Art

[0003] In the field of host security, it's often necessary to perform a full scan of all files on a host to check for malicious content. The traditional approach involves deploying a security agent on the host, which periodically scans and traverses the files on the host. This approach has the following drawbacks: 1. It consumes host resources, particularly the CPU (Central Processing Unit) and memory; 2. It is coupled with host services, resulting in poor stability; 3. Deployment is cumbersome, especially in elastic scenarios, requiring deployment on each host.

[0004] Summary of the Invention

[0005] The embodiments of the present application provide a host file detection method, an electronic device, and a storage medium to solve the problems existing in the prior art.

[0006] In a first aspect, an embodiment of the present application provides a host file detection method, which is applied to a host security detection system, comprising:

[0007] Based on the snapshot sharing function between the host security detection system and the target host, a first snapshot and a second snapshot are obtained from the target host; the first snapshot is a data backup of the file system in the target host at a first time, and the second snapshot is a data backup of the file system at a second time, where the first time is earlier than the second time;

[0008] Calculate the difference between the first snapshot and the second snapshot;

[0009] Based on the difference calculation result, it is determined whether the file in the file system of the target host has changed.

[0010] In a second aspect, an embodiment of the present application provides a host file detection device, which is applied to a host security detection system, including:

[0011] An information acquisition module is configured to acquire a first snapshot and a second snapshot of the target host based on a snapshot sharing function between the host security detection system and the target host; the first snapshot is a data backup of the file system of the target host at a first time, and the second snapshot is a data backup of the file system at a second time, the first time being earlier than the second time;

[0012] a difference calculation module, configured to calculate the difference between the first snapshot and the second snapshot;

[0013] The change determination module is used to determine whether a file in the file system of the target host has changed based on the result of the difference calculation.

[0014] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory, wherein the processor implements the method provided in the first aspect of the embodiment of the present application when executing the computer program.

[0015] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the method provided in the first aspect of the embodiment of the present application.

[0016] Compared with the prior art, this application has the following advantages:

[0017] According to the embodiments of the present application, it is possible to obtain snapshots of the target host at different times through snapshot sharing between the host security detection system and the target host, and then determine whether the files in the file system of the target host have changed based on the snapshots at different times, without deploying a security agent program on the target host. Agentless file scanning can be achieved to reduce the resource usage of the target host, have less impact on the services of the target host, have higher stability, and be easier to deploy, and thus agentless and non-invasive host security detection can be achieved based on agentless file detection.

[0018] The above description is only an overview of the technical solution of this application. In order to more clearly understand the technical means of this application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of this application more obvious and easy to understand, the specific implementation methods of this application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In the accompanying drawings, unless otherwise specified, the same reference numerals throughout the multiple drawings represent the same or similar components or elements. These drawings are not necessarily drawn to scale. It should be understood that these drawings only depict some embodiments according to the present application and should not be regarded as limiting the scope of the present application.

[0020] FIG1 is a flow chart of a host file detection method provided in an embodiment of the present application;

[0021] FIG2 is a partial flow diagram of another host file detection method provided by an embodiment of the present application;

[0022] FIG3 is a schematic diagram of a directory tree in an embodiment of the present application;

[0023] FIG4 is a schematic diagram of a Merkle tree of a file system in an embodiment of the present application;

[0024] FIG5 is a schematic diagram of an expression tree in an embodiment of the present application;

[0025] FIG6 is a schematic diagram of a compressed ordered table in an embodiment of the present application;

[0026] Figures 7 to 13 are schematic diagrams showing the principles of constructing a compressed ordered table and calculating hash values ​​for common files in embodiments of the present application;

[0027] Figures 14 to 20 are schematic diagrams showing the principle of calculating the hash value of a directory file in an embodiment of the present application;

[0028] 21 to 29 are schematic diagrams showing the principle of determining the absolute path of each file in an embodiment of the present application;

[0029] FIG30 is a partial flow diagram of another host file detection method provided in an embodiment of the present application;

[0030] 31 to 39 are schematic diagrams illustrating the principle of comparing absolute paths and hash values ​​in a first data table and a second data table in an embodiment of the present application;

[0031] FIG40 is a schematic diagram of the structural framework of a host file detection device provided in an embodiment of the present application; and

[0032] Figure 41 is a schematic diagram of the structural framework of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0033] Hereinafter, only certain exemplary embodiments are briefly described. As will be appreciated by those skilled in the art, the described embodiments may be modified in various ways without departing from the spirit or scope of the present application. Therefore, the drawings and description are to be regarded as illustrative in nature and not restrictive.

[0034] First, some technical terms involved in the embodiments of this application are introduced as follows:

[0035] Agentless: A non-invasive and service-neutral working mode that does not require the deployment of a security agent on the target host.

[0036] A cloud disk snapshot is a backup file of the cloud disk data state at a specific point in time, used to back up or restore the entire cloud disk. It is a convenient and efficient data disaster recovery method, commonly used for data backup, image creation, and application disaster recovery.

[0037] Incremental snapshot: Backs up only the data blocks that have changed since the last snapshot.

[0038] Merkle tree: A data structure widely used in P2P (Peer-to-Peer) systems and blockchain technology. Its most significant feature is that the content of a non-leaf node is the hash value of the content of all its child nodes, which can be used to quickly compare large amounts of data.

[0039] File System Merkle Tree (FSMT): An improved Merkle tree with infinite child nodes and limited path length based on the characteristics of the file system.

[0040] Expression tree: It is a type of tree whose basic structure is that all leaf nodes are operands and non-leaf nodes are operators. When performing post-order traversal, the expression obtained is a postfix expression.

[0041] Postfix expression: also known as reverse Polish notation, a postfix expression places the operator after the operand. This form of expression can be directly calculated by the stack structure and can be directly stored in a table structure.

[0042] Compact Ordered Table (COT): A table structure that stores data that is homogeneous with a file system tree (e.g., FSMT). The order of records in the table is the same as that in a depth-first traversal of the file system.

[0043] The embodiments of the present application can be applied to the field of host security, in which periodic security detection of the host is required to determine whether the host has been invaded. Periodic security is mainly achieved through periodic file scanning and detection, that is, periodic scanning and detection of files in the host file system. By detecting the changes in the currently scanned files relative to the files scanned last, the security of the current host can be detected. Traditional file detection solutions require the deployment of a security agent program on the host to obtain the file information of the host. The file detection solution provided by the embodiments of the present application does not require the deployment of a security agent program on the host, and can achieve agentless file detection.

[0044] To facilitate understanding of the technical solutions of the embodiments of the present application, the following describes the related technologies of the embodiments of the present application. The following related technologies can be combined with the technical solutions of the embodiments of the present application as optional solutions, and all of them fall within the scope of protection of the embodiments of the present application.

[0045] An embodiment of the present application provides a host file detection method, which can be applied to a host security detection system. As shown in Figure 1, the method may include the following steps: S101, based on the snapshot sharing function between the host security detection system and the target host, obtaining a first snapshot and a second snapshot in the target host, where the first snapshot may be a data backup between file systems in the target host at a first time, and the second snapshot may be a data backup of the target host file system at a second time, where the first time is earlier than the second time; S102, performing a difference calculation on the first snapshot and the second snapshot; S103, determining whether a file in the file system of the target host has changed based on the result of the difference calculation.

[0046] The target host may be an ECS (Elastic Compute Service) instance, and both the first snapshot and the second snapshot may be cloud disk snapshots.

[0047] The host file scanning method provided in the embodiment of the present application can obtain snapshots of the target host at different times through the snapshot sharing function between the host security detection system and the target host, and then determine whether the files in the file system of the target host have changed based on the difference calculation between the two snapshots, so as to realize real-time security scanning and detection of incremental files of the file system without deploying a security agent program on the target host. Agentless file detection can be realized to reduce the resource usage of the target host, have less impact on the service of the target host, have higher stability, and be easier to deploy.

[0048] In one embodiment, both the first snapshot and the second snapshot can be incremental snapshots. In order to detect intrusion events on the target host in real time, it is usually necessary to periodically scan the target host for files. In actual scenarios, most files on the target host are unchanged and do not require repeated scanning and processing. Therefore, in the embodiment of the present application, the first snapshot and the second snapshot used as the difference calculation objects can both be incremental snapshots. Compared with a full file scan, this can greatly reduce the number of files to be scanned, thereby greatly reducing the amount of calculation and achieving rapid comparison of incremental snapshots.

[0049] In one example, in the above step S101, based on the snapshot sharing function between the host security detection system and the target host, the first snapshot and the second snapshot in the target host are obtained, which can be achieved in the following way: the API (application programming interface) of the host security detection system is used to periodically generate incremental snapshots (first snapshot or second snapshot) of the target host on the user side, i.e., the host side; the target host can share the incremental snapshot to the service account of the host security detection system through the service account on the host side with the user's authorization; the scanner of the host security detection system creates a data disk based on the received incremental snapshot, and mounts the data disk on the scanner, and then can perform security detection on the incremental snapshot received by the scanner through the data disk, and read the incremental snapshot received by the scanner locally through the data disk, that is, convert the remote incremental snapshot into a local incremental snapshot through the data disk.

[0050] In one embodiment, as shown in FIG2 , performing a difference calculation on the first snapshot and the second snapshot in step S102 may include: S201, constructing a first file system tree of the file system based on the first directory structure in the first snapshot, and constructing a second file system tree of the file system based on the second directory structure in the second snapshot; and S202, performing a difference calculation on the first file system tree and the second file system tree. The first file system tree is isomorphic to the first directory structure, and thus can represent the file characteristics of the file system at the first time; the second file system tree is isomorphic to the second directory structure, and thus can represent the file characteristics of the file system at the second time. Based on the first and second file system trees reflecting the file characteristics of the corresponding directory structures, performing a difference calculation based on the file system trees can more accurately and quickly detect changes in the file system.

[0051] Both the first directory structure and the second directory structure can be in the form of a directory tree as shown in FIG3 , which can be generated based on the content of the first snapshot or the second snapshot. In the directory tree shown in FIG3 , / , music, home, abc.mp4, admin, cai, and hello.txt are the file names of seven files, respectively. Among them, / , music, home, cai, and admin are directory files, abc.mp4 and hello.txt are both ordinary files, and among the five directory files, / , music, home, and cai are all non-empty directories, i.e., directory files containing subfiles, and admin is an empty directory, i.e., a directory file that does not contain subfiles. An empty directory is a special type of directory file. When constructing a file system tree based on the directory structure in a snapshot, the directory tree shown in FIG3 can be converted into an isomorphic file system tree.

[0052] In one embodiment, both the first file system tree and the second file system tree may be FSMTs.

[0053] The Merkle tree is a data structure commonly used in blockchain systems. Its basic concept is that the hash value of a parent node depends on the hash values ​​of its child nodes. Changes to the hash value of any node in the tree are propagated upwards to the root node. Conversely, if the hash value of the root node remains unchanged, all nodes in the entire tree remain unchanged. Using a Merkle tree offers several advantages: 1) It allows for quick comparison of differences between two trees, generating a difference tree; 2) only requires information from a limited number of nodes to prove whether a node belongs to the tree; and 3) a tree can be easily split into multiple subtrees for easier storage and computation without affecting the logic of the entire tree.

[0054] The classic Merkle tree is a binary tree with a limited number of nodes. When the number of files in a file system is large, the classic Merkle tree cannot fully reflect the file characteristics of the file system. The embodiment of the present application improves the Merkle tree to form an FSMT with the characteristics of an unlimited number of child nodes and a limited path length, which can fully reflect the file characteristics of the file system. In the FSMT, each intermediate node has M child nodes, where M can be the maximum number of files in a directory specified by the file system. For example, in ext4 (Fourth Extended Filesystem), M is 2 to the power of 32. In the FSMT, the length of the path extending from each intermediate node is N, where N can be the maximum file name length specified by the file system. For example, in ext4, N is 255 bytes.

[0055] FIG4 illustrates a specific example of an improved FSMT according to an embodiment of the present application. The FSMT shown in FIG4 can be derived from the directory tree shown in FIG3 . Directory files in the directory tree can correspond to intermediate nodes in the FSMT. As in FIG3 , the intermediate nodes in FIG4 include nodes corresponding to four hash values: H2, H4, H6, and H7. Ordinary files in the directory tree can correspond to leaf nodes in the file system tree. As in FIG3 , the leaf nodes in FIG4 include nodes corresponding to three hash values: H1, H3, and H5. Each node in the FSMT can be uniquely identified by the path from the root node to the node.

[0056] In Figure 4, H1=Hash(hello.txt) indicates that the hash value H1 of the file hello.txt is obtained by performing a hash operation on the information of the file hello.txt, H2=Hash(cai,H1) indicates that the hash value H2 of the file cai is obtained by performing a hash operation on the information of the file cai and the hash value H1, H3=Hash(admin) indicates that the hash value H3 of the file admin is obtained by performing a hash operation on the information of the file admin, and H4=Hash(home,H3,H2) indicates that the hash value H4 of the file home is obtained. It is obtained by hashing the information of file home, hash value H3 and hash value H2. H5=Hash(abc.mp4) means that hash value H5 of file abc.mp4 is obtained by hashing the information of file abc.mp4. H6=Hash(music,H5) means that hash value H6 of file music is obtained by hashing the information of file music and hash value H5. H7=Hash( / ,H6,H4) means that hash value H7 of file / is obtained by hashing the information of file / , hash value H6 and hash value H4.

[0057] Based on the above method, FSMT is used as the file system tree of the embodiment of the present application, which can not only introduce the advantages of the Merkle tree and quickly compare the two trees, but also more conveniently represent the characteristics of the file system and is suitable for scanning and detection of file systems with a large number of files.

[0058] In one embodiment, the file system tree in the embodiment of the present application can be stored in the form of a data table. For example, the first file system tree can be stored in the form of a first data table, and the second file system tree can be stored in the form of a second data table. Both the first data table and the second data table can be structured data tables. Accordingly, in step S202, performing a difference calculation on the first file system tree and the second file system tree can include performing a difference calculation on the first data table and the second data table.

[0059] For a file system with a large number of files, the corresponding file system tree has almost infinite nodes. When memory resources are limited, it is difficult to store the massive files in the FSMT in memory for computational processing. Storing the file system tree in the form of a structured data table makes the file system tree splittable and easy to persist. The contents of the split files can be stored in memory for computation, and the computation results can be aggregated, making better use of limited memory resources to compute and process the massive files in the FSMT.

[0060] In one embodiment, constructing a first file system tree based on a first directory structure may include traversing each file in the first directory structure and recursively constructing the first file system tree. Similarly, constructing a second file system tree based on a second directory structure may include traversing each file in the second directory structure and recursively constructing the second file system tree. This approach is suitable for scenarios with a small number of files and a small number of file hierarchies.

[0061] In one embodiment, constructing a first file system tree based on a first directory structure in a first snapshot may include: constructing a first expression tree based on the first directory structure in the first snapshot, and constructing the first file system tree based on the first expression tree. Similarly, constructing a second expression tree based on the second directory structure in a second snapshot may include: constructing a second expression tree based on the second directory structure in the second snapshot, and constructing the first file system tree based on the second expression tree. The first expression tree may express the calculation process of constructing the first file system tree, the second expression tree may express the calculation process of constructing the second file system tree, and both the first expression tree and the second expression tree may be constructed based on suffix expressions, so that both the first expression tree and the second expression tree are stored in the form of a data table that can be structured for storage, and further, the first file system tree and the second file system tree constructed based on the first expression tree and the second expression tree may also be stored in the form of a data table that can be structured for storage. This method can be applicable to scenarios with a large amount of file data and a large number of file levels.

[0062] The first expression tree can be isomorphic to the first file system tree, and the second expression tree can be isomorphic to the second file system tree. Similar to the file system tree, the expression tree can also include intermediate nodes and leaf nodes. The intermediate nodes correspond to directory files, and the leaf nodes correspond to ordinary files. Each node can be used as an operator. Figure 5 shows an example diagram of an expression tree. Referring to Figure 5, the expression tree has two operators, a first operator HashDir and a second operator HashFile. The intermediate node can be used as the first operator HashDir, and the leaf node can be used as the second operator HashFile. The first operator HashDir represents a hash operation on the current intermediate node (i.e., the intermediate node corresponding to the first operator). The operation method can be to calculate the hash value of the current intermediate node based on the hash values ​​of all direct child nodes of the current intermediate node and the file information of the current intermediate node. The operand corresponding to the first operator HashDir is the file information of all direct child nodes under the current intermediate node. The second operator HashFile represents a hash operation on the current leaf node (i.e., the leaf node corresponding to the second operator). The operation method can be to calculate the hash value of the current leaf node based on the file information of the current leaf node itself. The operand corresponding to the second operator HashFile is the file information of the current leaf node.

[0063] The traversal of the first expression tree and the second expression tree can be a post-order traversal. The expression tree constructed based on the suffix expression and the post-order traversal method conform to computer processing habits, are convenient for computer processing, and also conform to human reading habits.

[0064] In one embodiment, in step S201, constructing a first file system tree of the file system based on the first directory structure in the first snapshot may include traversing each file in the first directory structure and inserting information about each file into a first data table in the form of a row record. Similarly, constructing a second file system tree of the file system based on the second directory structure in the second snapshot may include traversing each file in the second directory structure and inserting information about each file into a second data table in the form of a row record. In this manner, by traversing the files in the directory structure, row records for each file are generated and inserted into the corresponding data table, thereby obtaining a file system tree stored in the form of a data table, and avoiding missing files.

[0065] In the first data table formed based on the above method, each row record corresponds to a file, and the arrangement order of each file can be consistent with the hierarchical order of each file in the first directory structure of the file system. For the second data table, each row record corresponds to a file, and the arrangement order of each file is consistent with the hierarchical order of each file in the second directory structure of the file system.

[0066] In one embodiment, traversing each file in a first directory structure may include: traversing each file in the first directory structure in a first order, and when the traversed file is a normal file or an empty directory, determining the hash value of the normal file or empty directory; traversing each file in the first directory structure in a second order, and when the traversed file is a non-empty directory, determining the hash value of the non-empty directory. Correspondingly, traversing each file in a second directory structure may include: traversing each file in the second directory structure in the first order, and when the traversed file is a normal file or an empty directory, determining the hash value of the normal file or empty directory; traversing each file in the second directory structure in the second order, and when the traversed file is a non-empty directory, determining the hash value of the non-empty directory. In the first data table and the second data table, the row record of a normal file may include the hash value of the normal file, the row record of an empty directory may include the hash value of the empty directory, and the row record of a non-empty directory may include the hash value of the non-empty directory; the first order may be the order from the root directory to the last layer of sub-files, and the second order is the reverse order of the first order. In the first data table and the second data table, a row record of each file includes a hash value of the file.

[0067] The hash value of a non-empty directory is related to the sub-files under the non-empty directory. Through the first traversal, the hash values ​​of ordinary files and empty directories can be determined first, and then in the second traversal, the hash values ​​of the non-empty directories to which they belong can be further determined based on the hash values ​​of the ordinary files and empty directories that have been determined. The order of the second traversal is set to be opposite to the order of the first traversal, starting from the last layer of sub-files to the root directory, and the hash values ​​of non-empty directories at different levels can be determined layer by layer. The hash value of the non-empty directory of the next level is determined first, and then the hash value of the non-empty directory of the previous level can be determined based on the hash value of the non-empty directory of the next level, and finally the hash values ​​of all files can be determined.

[0068] In one embodiment, traversing each file in a first directory structure may include traversing each file in the first directory structure in a first order and determining the absolute path of each traversed file. Similarly, traversing each file in a second directory structure may include traversing each file in the second directory structure in the first order and determining the absolute path of each traversed file. Both the first data table and the second data table are compressed ordered tables. In the compressed ordered tables, each file record may include the absolute path of the file. Row records of each subfile in the same directory file may include a record for one of the same multiple path prefixes. The first order may be from the root directory to the last subfile. Based on this approach, the absolute path of each file in the directory structure can be determined one by one, avoiding omissions. Furthermore, the absolute paths of each subfile in the same directory file typically have the same path prefix. In cases where the absolute paths have the same path prefix, data storage is implemented in the form of a compressed ordered table. Only one record for the same path prefix can be stored in the data table. That is, the same path prefix is ​​only stored once in the data table. This effectively reduces the repeated storage of the same path prefix, thereby reducing the storage of redundant data and significantly saving storage space.

[0069] In one embodiment, traversing each file in the first directory structure and inserting information about each file into the first data table in the form of a row record may include: traversing each file in the first directory structure using a stack, and sequentially inserting information about each file into the first data table in the form of a row record in the order of traversal. Similarly, traversing each file in the second directory structure and inserting information about each file into the second data table in the form of a row record may include: traversing each file in the second directory structure using a stack, and sequentially inserting information about each file into the second data table in the form of a row record in the order of traversal.

[0070] In the process of determining the hash value, both traversals of the same directory structure can be implemented based on the stack, so that the calculation can be completed by accessing each file only once. During the second traversal, ordinary files can be directly pushed into the stack. When traversing to directory files, the row records of its subfiles can be popped from the top of the stack, the hash value can be calculated and inserted into the corresponding fields of the data table.

[0071] In the process of determining the absolute path, traversal of the same directory structure can be implemented based on a stack, thereby ensuring that the calculation can be completed by accessing each file only once. When traversing the directory structure based on the stack to determine the absolute path of each file, if there is an object at the top of the stack, the number of child files in the parent directory of the top object can be reduced by 1. If the current file traversed is a non-empty directory, the file name and number of child files of the current file can be pushed into the stack as an object. When accessing a file, the stack can contain the full path prefix of the file. From the bottom of the stack to the top of the stack, the file name of the root directory and the parent directory of the current file can be included in turn. If the current file traversed is the last file under its parent directory, all objects with a child file count of 0 can be popped out from the top of the stack, that is, all directories in the stack whose child files have been visited can be popped out.

[0072] In addition, the stack has the feature of first-in, last-out. The last element accessed (popped) is at the bottom. By storing the bottom element of the stack on disk, a logically almost infinite stack can be maintained within limited memory. At the same time, the order in the stack can also implicitly express the hierarchical relationship of each file in the directory structure.

[0073] In the embodiment of the present application, the first data table and the second data table can both be compressed ordered tables. Based on the hash value, each row record in the first data table and the second data table can also include at least one information such as the file name, directory attributes, number of child files, sorting under the parent node, and absolute path of the corresponding file.

[0074] FIG6 shows an example of a compressed ordered table. The compressed ordered table in FIG6 includes 7 rows, each row including a file name (File Name), a directory attribute (IsDiectory), a subfile number (Subfile Num) and a reverse index (Reverse Index). This is only an example of the storage form of a compressed ordered table, and the information of all fields is not shown. Among them, the directory attribute can be represented by "true" or "false", "true" indicates that the node corresponding to the current file is the first operator HashDir, and "false" indicates that the node corresponding to the current file is the second operator HashFile. The reverse index of the current node can indicate the order of the current node under the parent node, for example, whether the current node is the last node under the parent node. If so, the reverse index can be represented as 0, if not, the reverse index can be represented as N-1, where N is the number of subfiles of the parent node of the current node.

[0075] The compressed ordered table, shown in Figure 6, can be split at any location. The resulting fragments are naturally ordered and can be used to represent isomorphic subtrees of the FSMT, facilitating segmented loading into limited memory resources. Furthermore, the compressed ordered table can be quickly created, compared, and traversed within limited memory resources, enabling a forest-like simulation of FSMT construction, comparison, and traversal. This facilitates rapid detection of difference result sets across massive files, improving efficiency and speed, and is suitable for scheduled scanning scenarios in agentless file scanning.

[0076] The construction principle of the compressed ordered list shown in Figure 6 can be referred to the examples of Figures 7 to 13. Figures 7 to 13 are simplified representations and do not show the information of the hash value field. Referring to the example of Figure 7, a compressed ordered list including fields such as file name, directory attributes, number of subfiles, reverse sequence number, and hash value (not shown) can be first constructed. The root node of the directory tree shown in Figure 3 is accessed, and the file name, directory attributes, number of subfiles, and reverse sequence number corresponding to the root node are inserted into the first row of the compressed ordered list. The subfiles of the file at the root node are sorted in reverse order and pushed onto the stack in sequence. Referring to Figures 3 and the FSMT shown in Figures 4, the file name corresponding to the root node is / , and the root node is the first operator HashDir, so the directory attribute is true. The root node file / has two subfiles, music and home, so the number of subfiles is 2. The root node has no parent node, so no data can be inserted in the reverse sequence number. The root node file / is a non-empty directory with subfiles. The hash value needs to be calculated based on the information of all its subfiles and the root node file. The hash value field can be left blank in this traversal.

[0077] With reference to the example of Fig. 8, the top node of the stack can be popped out, and the file name, directory attribute, number of subfiles and reverse sequence number of the node are inserted into the second row of the compressed ordered list, and the subfiles of the file at the node are sorted in reverse order and pushed onto the stack in sequence. With reference to the examples of Fig. 3 and Fig. 4, the file name of the node is home, and the node is the first operator HashDir, so the directory attribute is true, and there are two subfiles cai and admin under the node file home, so the number of subfiles is 2, and the node is not the last child node of its parent node, so the reverse sequence number is 1, and the node file home is a non-empty directory with subfiles. It is necessary to calculate the hash value based on the information of all its subfiles and the node file home. The hash value field can be left blank in this traversal.

[0078] Referring to the example in Figure 9, the top node of the stack is popped again, and the file name, directory attributes, number of subfiles, and reverse sequence number of the node are inserted into the third row of the compressed ordered list. Combining Figures 3 and 4, the file name of the node is admin, and the node is the first operator HashDir, so the directory attribute is true. There are no subfiles under the node file admin, so the number of subfiles is 0. This node is not the last child node of its parent node, so the reverse sequence number is 1. The node file admin is an empty directory. In this traversal, the hash value can be directly calculated based on the file and the corresponding field can be inserted.

[0079] Referring to the example of Figure 10, the top node of the stack is popped out again, and the file name, directory attributes, number of subfiles, and reverse sequence number of the node are inserted into the fourth row of the compressed ordered list. The subfiles of the file at the node are sorted in reverse order and pushed onto the stack in sequence. In conjunction with Figures 3 and 4, the file name of the node is cai, and the node is the first operator HashDir, so the directory attribute is true. There is a subfile hello.txt under the node file cai, so the number of subfiles is 1. The node is the last child node of its parent node, so the reverse sequence number is 0. The node file cai is a non-empty directory, and the hash value needs to be calculated based on the information of all its subfiles and the file. The hash value field can be left blank in this traversal.

[0080] Referring to the example in Figure 11, the top node of the stack is popped again, and the file name, directory attribute, number of subfiles, and reverse sequence number of the node are inserted into the fifth row of the compressed ordered list. Combining Figures 5 and 4, the file name of the node is hello.txt, and the node is the second operator HashFile, so the directory attribute is false. There are no subfiles under the file hello.txt of this node, so the number of subfiles is empty. This node is the last child node of its parent node, so the reverse sequence number is 0. The file hello.txt of this node is a normal file. In this traversal, the hash value can be directly calculated based on this file and the corresponding field can be inserted.

[0081] Referring to the example of Figure 12, the top node of the stack is popped out again, and the file name, directory attributes, number of subfiles, and reverse sequence number of the node are inserted into the sixth row of the compressed ordered list, and the subfiles of the file at the node are pushed onto the stack. In conjunction with Figures 3 and 4, the file name of the node is music, and the node is the first operator HashDir, so the directory attribute is true. There is a subfile abc.mp4 under the node file music, so the number of subfiles is 1. The node is the last child node of its parent node, so the reverse sequence number is 0. The node file music is a non-empty directory, and the hash value needs to be calculated based on the information of all subfiles and the node file music. The hash value field can be left blank in this traversal.

[0082] Referring to the example of Figure 13, the top node of the stack is popped out again, and the file name, directory attribute, number of subfiles and reverse sequence number of the node are inserted into the fifth row of the compressed ordered table. In conjunction with Figures 3 and 4, the file name of the node is abc.mp4, and the node is the first operator HashDir, so the directory attribute is true. There are no subfiles under the node file abc.mp4, so the number of subfiles is empty. The node is the last child node of its parent node, so the reverse sequence number is 0. The node file abc.mp4 is an ordinary file. The hash value can be directly calculated based on the file in this traversal and inserted into the corresponding field. At this point, a compressed ordered table storing the data of each file can be formed, and the hash value of each ordinary file and empty directory can be calculated.

[0083] The directory tree shown in FIG3 can be further traversed in reverse (traversed in the second order). After a compressed ordered table with information of each file inserted is formed through the process shown in FIG7 to FIG13, the file arrangement order of the compressed ordered table is consistent with the file hierarchy order of the directory tree. Traversing the compressed ordered table is equivalent to traversing the directory tree in the DFS manner. Therefore, each file in the compressed ordered table shown in FIG13 can be directly traversed for the second time, and the hash value of the non-empty directory is calculated during the traversal process.

[0084] Taking the calculation of the hash value of a non-empty directory in the compressed ordered table shown in Figure 13 as an example, the calculation principle of the hash value of a non-empty directory can be referred to Figures 14 to 20. Referring to Figure 14, you can first access the file abc.mp4 in the last row of the compressed ordered table shown in Figure 13. It is an ordinary file and has a calculated hash value, so it can be directly pushed into the stack. Referring to Figure 15, continue to access the file music in the sixth row of the compressed ordered table. It is a non-empty directory and contains only one sub-file, namely abc.mp4. The sub-file abc.mp4 can be popped out of the stack, and the hash value of the non-empty directory music is calculated based on the hash value of the sub-file abc.mp4 and the information of the non-empty directory music, and the non-empty directory music is pushed into the stack. Referring to Figure 16, continue to access the file hello.txt in the fifth row of the compressed ordered table. It is an ordinary file and has a calculated hash value, so it can be directly pushed into the stack. Referring to Figure 17, continue to access the file cai in the fourth row of the compressed ordered list, which is a non-empty directory file and contains only one sub-file, namely hello.txt. The sub-file hello.txt can be popped from the stack, and the hash value of the non-empty directory cai is calculated based on the hash value of the sub-file hello.txt and the information of the non-empty directory cai, and the non-empty directory cai is pushed into the stack.

[0085] Referring to Figure 18, we continue to access the file admin in the third row of the compressed ordered list. It is an empty directory and has a calculated hash value, so it can be directly pushed onto the stack. Referring to Figure 19, we continue to access the file home in the second row of the compressed ordered list. It is a non-empty directory and has two sub-files, namely admin and cai. The sub-files admin and cai can be popped out of the stack, and the hash value of the non-empty directory home is calculated based on the hash value of the sub-file admin, the hash value of the sub-file cai, and the information of the non-empty directory home, and the non-empty directory home is pushed onto the stack. Referring to Figure 20, we continue to access the file / in the first row of the compressed ordered list. It is a non-empty directory and has two sub-files, namely home and music. The sub-files home and music can be popped out of the stack, and the hash value of the non-empty directory / is calculated based on the hash value of the sub-file home, the hash value of the sub-file music, and the information of the non-empty directory / , and the non-empty directory / is pushed onto the stack. At this point, the traversal of the entire compressed ordered list is completed, the hash value of each non-empty directory is calculated, and the hash values ​​of all files can be obtained.

[0086] In an example, the directory tree shown in Figure 3 can be traversed forward (traversed in the first order). Since the file arrangement order of the compressed ordered table is consistent with the file hierarchy order of the directory tree, traversing the compressed ordered table is equivalent to traversing the directory tree in the DFS manner. Therefore, each file in the compressed ordered table can be traversed directly, and the absolute path of each file can be determined during the traversal process. The principle can be referred to Figures 21 to 29.

[0087] Referring to Figure 21, you can first access the file / in the first row of the compressed ordered list. It is a non-empty directory and can be directly pushed into the stack, and the absolute path of the file / can be determined to be / . Referring to Figure 22, continue to access the file home in the second row of the compressed ordered list. It is a non-empty directory and can be directly pushed into the stack. The number of unaccessed child files of its parent node (top node of the stack) file / is updated to 1, and the absolute path of the file home can be determined to be / home. In the example of Figure 22, the number of unaccessed child files of the parent node can be updated in the field of the number of child files corresponding to the parent node. In other examples, other fields can be set to update the number of unaccessed child files of the parent node. This embodiment of the present application does not limit this. Referring to Figure 23, continue to access the file admin in the third row of the compressed ordered list. It is an empty directory and is not pushed into the stack. The number of unaccessed child files of its parent node file home can be updated to 1, and the absolute path of the file admin can be determined to be / home / admin. Referring to Figure 24, we continue to access the file cai in the fourth row of the compressed ordered list. Since it is a non-empty directory, it can be directly pushed into the stack. The number of unaccessed child files of its parent node file home is updated to 0, and the absolute path of the file can be determined to be / home / cai. Since the absolute path of the file cai and the absolute path of the file admin have the same path prefix / home, if the path prefix has been stored in the compressed ordered list, it can no longer be stored repeatedly to reduce redundant storage. Referring to Figure 25, we continue to access the file hello.txt in the fifth row of the compressed ordered list. Its absolute path is / home / cai / hello.txt. The reverse sequence number of this file is 0, indicating that it is the last file in its parent node. At this time, referring to Figure 26, all files except the root node file that have been accessed can be popped out of the stack. Since the absolute path of the file hello.txt and the file cai have the same path prefix / home / cai, if the path prefix has been stored in the compressed ordered list, it can no longer be stored repeatedly to reduce redundant storage.

[0088] Referring to Figure 27, we continue to access the file music in the sixth row of the compressed ordered list. Since it is a non-empty directory, it can be directly pushed into the stack. The number of unvisited child files of its parent node file / is updated to 0, and the absolute path of the file music can be determined to be / music. Referring to Figure 28, we continue to access the file abc.mp4 in the seventh row of the compressed ordered list. It can be determined that its absolute path is / music / abc.mp4. Referring to Figure 29, this file is the last file in the compressed ordered list. After the file is accessed, all the child files in the stack can be popped out. Since the absolute path of the file abc.mp4 and the absolute path of music have the same path prefix / music, if the path prefix has been stored in the compressed ordered list, it does not need to be stored repeatedly to reduce redundant storage.

[0089] In one embodiment, the first data table may include identification information of each file in the first directory structure, and the second data table may include identification information of each file in the second directory structure. Accordingly, as shown in FIG30 , performing a difference calculation on the first data table and the second data table may include: S3001, comparing the identification information of each file in the first data table with the identification information of each file in the second data table; S3002, determining whether there are different files in the first data table and the second data table based on the comparison result of the identification information.

[0090] The identification information can be used to uniquely identify a file. By comparing the identification information, the changes in the files corresponding to the two data tables can be accurately perceived and the difference files can be determined.

[0091] In one embodiment, in steps S3001 and S3002, comparing the identification information of each file in the first data table with the identification information of each file in the second data table, and determining whether there are different files in the first data table and the second data table based on the comparison results of the identification information may include: sequentially reading the identification information of each file in the first data table as the first identification information, and sequentially reading the identification information of each file in the second data table as the second identification information; during the sequential reading process, sequentially comparing the first identification information of row N in the first data table with the second identification information of at least one corresponding row in the second data table, and determining whether the first identification information in row N and the corresponding second identification information in each row are equal; if the first identification information in row N and the corresponding second identification information in a row are not equal, determining that there is a different file in the first data table and the second data table. N is a positive integer less than or equal to the total number of rows in the first data table, and the second identification information corresponding to the first identification information in row N in the first data table may include second identification information within a certain range before and after row N in the second data table, for example, second identification information from rows N-1 to N+1.

[0092] Based on the above method, by reading and comparing the identification information in the two data tables line by line, the files of the two data tables can be accurately compared to obtain a comparison result.

[0093] Referring to the previous example, the order of files in the data table can be the same as the order of files in the directory structure. Traversing the data table and reading the corresponding files in sequence is equivalent to traversing the directory structure of the file system in a DFS (depth-first search) manner. Therefore, the directory structure of the file system can be traversed by traversing the files in the data table to complete the comparison of the identification information of each file.

[0094] In one embodiment, the identification information of a file may include the absolute path of the file, and the absolute path is the path from the root directory to the file, so that the first identification information may include the first absolute path, that is, the absolute path of the file in the first data table, and the second identification information may include the first absolute path, that is, the absolute path of the file in the second data table.

[0095] Correspondingly, in the process of sequentially reading, the first identification information of the Nth row in the first data table is sequentially compared with the second identification information of at least one corresponding row in the second data table to determine whether the first identification information of the Nth row and the corresponding second identification information of each row are equal, which may include: comparing the first absolute path of the Nth row with the second absolute path of the Nth row in the second data table to determine whether the first absolute path of the Nth row and the second absolute path of the Nth row are equal; when the first absolute path of the Nth row and the second absolute path of the Nth row are equal, reading the first absolute path of the N+1th row in the first data table and the second absolute path of the N+1th row in the second data table, comparing the first absolute path of the N+1th row with the second absolute path of the N+1th row to determine whether the first absolute path of the N+1th row and the second absolute path of the N+1th row are equal, and the determination method is similar to that of the Nth row; When the first absolute path in row N and the second absolute path in row N are not equal, the first absolute path in row N+1 of the first data table is read, and the first absolute path in row N+1 is compared with the second absolute path in row N, or the second absolute path in row N+1 of the second data table is read, and the first absolute path in row N is compared with the second absolute path in row N+1. For example, when the first absolute path in row N is smaller than the second absolute path in row N, the first absolute path in row N+1 of the first data table may be read further to determine the size relationship between the first absolute path in row N+1 and the second absolute path in row N. When the first absolute path in row N is larger than the second absolute path in row N, the first absolute path in row N+1 of the second data table may be read further to determine the size relationship between the first absolute path in row N and the second absolute path in row N+1.

[0096] Correspondingly, when the first identification information in row N is not equal to the second identification information in the corresponding row, determining that there is a difference file in the first data table and the second data table may include: when the first absolute path in row N is not equal to the second absolute path in the corresponding row (for example, row N or row N+1), determining that the file corresponding to the first absolute path in row N is a deleted file or the file corresponding to the second absolute path in the corresponding row is a newly added file. For example, when the first absolute path is smaller than the second absolute path, the file corresponding to the first absolute path may be determined to be a deleted file, and when the first absolute path is larger than the second absolute path, the file corresponding to the second absolute path may be determined to be a newly added file.

[0097] An absolute path can uniquely identify the location of a file. By comparing the absolute paths, it is possible to determine the changed files and the specific change type of the changed files, that is, whether they have been deleted or added.

[0098] In one embodiment, based on the absolute path, the identification information of a file may further include a hash value, so that the first identification information may further include a first hash value, and the second identification information may further identify a second hash value.

[0099] Correspondingly, in the process of sequential reading, the first identification information of the Nth row in the first data table is compared with at least one corresponding row of second identification information in the second data table in sequence to determine whether the first identification information of the Nth row and the corresponding second identification information of each row are equal, which may include: when the first absolute path of the Nth row and the second absolute path of the corresponding row (for example, the Nth row or the N+1th row) are equal, determining whether the first hash value of the Nth row and the second hash value of the same row with the second absolute path (for example, the Nth row or the N+1th row) are equal.

[0100] Correspondingly, when the first identification information in the Nth row and the corresponding second identification information are not equal, determining that there is a difference file in the first data table and the second data table also includes: when the first absolute path in the Nth row and the corresponding second absolute path in the Nth row are equal, and the first hash value in the Nth row and the second hash value in the same row as the second absolute path are not equal, determining that the file corresponding to the second hash value is a modified file.

[0101] The hash value can uniquely identify the file content of a file. Based on the comparison of the hash values, the changed files and the specific change type of the changed files can be determined, that is, whether the files have been modified.

[0102] Figures 31 to 39 show a specific example diagram of comparing the absolute paths and hash values ​​in the first data table and the second data table, where Figure 31 shows the specific contents in the first data table and the second data table. Compared with the first data table, the second data table adds the file new, deletes the file admin, and modifies the file abc.mp4. After line-by-line comparison of Figures 32 to 38, the above three changed files can be identified, and the information of the changed files can be written into the difference result table. The information written into the difference result table may include the file name, directory attributes and a description of the file changes.

[0103] Referring to Figure 32, the absolute path and hash value of the first row in the first data table and the second data table are read respectively. After comparison, it can be seen that the two absolute paths are equal, both are / , indicating that the file / in the first row of the second data table is not a newly added file, and the / in the first data table is not a deleted file. The two hash values ​​are not equal, indicating that the file / has been modified (Modified), and the information of the file / is written into the difference result table.

[0104] Referring to Figure 33, the absolute path and hash value of the second row in the first data table and the second data table are read respectively. After comparison, the two absolute paths are equal, both are / home, which means that the file home in the second row in the second data table is not a newly added file, and the file home in the second row in the first data table is not a deleted file. The two hash values ​​are not equal, indicating that the file home has been modified. The information of the file home is written into the difference result table.

[0105] Referring to Figure 34, the absolute path and hash value of the third row in the first data table and the second data table are read respectively. After comparison, the absolute path of the third row in the first data table is / home / admin, and the absolute path of the third row in the second data table is / home / cai. The former is smaller than the latter, indicating that the file admin in the third row in the first data table is a deleted file. The information of the file admin is written into the difference result table.

[0106] Referring to Figure 35, the absolute path and hash value of the fourth row in the first data table are read and compared with the absolute path and hash value of the third row in the second data table. After comparison, the two absolute paths are equal, indicating that the file cai in the fourth row of the first data table is not a deleted file, and the file cai in the third row of the second data table is not a newly added file. The two hash values ​​are equal, indicating that the file cai in the third row of the second data table is an unmodified file and there is no need to write into the difference result table.

[0107] Referring to Figure 36, continue to read the absolute path and hash value of the next row in the first data table and the second data table, that is, the absolute path and hash value of the fifth row in the first data table, and the absolute path and hash value of the fourth row in the second data table. Since the file in the fifth row of the first data table and the file in the fourth row of the second data table are both sub-files of file cai, and file cai has been verified as an unmodified file in the previous step (refer to Figure 34), it can be determined that the sub-file of file cai has not been modified, so the comparison of these two rows can be skipped and directly go to the next row.

[0108] Referring to Figure 37, continue to read the absolute path and hash value of the next row in the first data table and the second data table, that is, the absolute path and hash value of the sixth row in the first data table, and the absolute path and hash value of the fifth row in the second data table. After comparison, the absolute path of the sixth row in the first data table is / music, and the absolute path of the fifth row in the second data table is / home / new. The former is greater than the latter, indicating that the latter file new is a newly added file (New File). The information of the file new is written into the difference result table.

[0109] Referring to Figure 38, continue to read the absolute path and hash value of the next row (i.e., the sixth row) in the second data table, and compare them with the absolute path and hash value of the sixth row in the first data table. After comparison, the two absolute paths are equal, both are / music, indicating that the two files are not deleted files or newly added files. The two hash values ​​are different, indicating that the file music in the sixth row of the second data table is a modified file, and the information of the file music is written into the difference result table.

[0110] Referring to Figure 39 , we continue to read the absolute path and hash value of the next row (i.e., row 7) in the first and second data tables. After comparison, the two absolute paths are equal, both / music / abc.mp4, indicating that the two files are not deleted or newly added. The two hash values ​​are different, indicating that the file abc.mp4 in row 7 of the second data table is a modified file. The information of file abc.mp4 is written to the difference result table. At this point, the comparison of all files in the first and second data tables is completed, and all changed files are found.

[0111] The host file detection method provided by the embodiment of the present application may further include: determining the security level of the target host based on file changes in the file system of the target host. For example, when it is determined that the file system of the target host has changed, that is, when the changed files in the file system of the target host are found, it can be determined that the security level of the target host is low. When it is determined that the file system of the target host has not changed, that is, when no changed files in the file system of the target host are found, it can be determined that the security level of the target host is high.

[0112] Based on the same technical concept, an embodiment of the present application also provides a host file detection device, which can be applied to a host security detection system. As shown in Figure 40, the device may include: an information acquisition module 4001, a difference calculation module 4002 and a change determination module 4003.

[0113] The information acquisition module 4001 is used to obtain the first snapshot and the second snapshot in the target host based on the snapshot sharing function between the host security detection system and the target host; the first snapshot is a data backup of the file system in the target host at the first time, and the second snapshot is a data backup of the file system at the second time, and the first time is earlier than the second time.

[0114] The difference calculation module 4002 is configured to calculate the difference between the first snapshot and the second snapshot.

[0115] The change determination module 4003 is used to determine whether a file in the file system of the target host has changed based on the result of the difference calculation.

[0116] In one embodiment, the first snapshot and the second snapshot are both incremental snapshots.

[0117] In one embodiment, the difference calculation module 4002 can be configured to: construct a first file system tree of the file system based on the first directory structure in the first snapshot, and construct a second file system tree of the file system based on the second directory structure in the second snapshot; and perform difference calculation on the first file system tree and the second file system tree. The first file system tree is isomorphic to the first directory structure, and the second file system tree is isomorphic to the second directory structure.

[0118] In one embodiment, the first file system tree is stored in the form of a first data table, and the second file system tree is stored in the form of a second data table; both the first data table and the second data table are structured data tables. Accordingly, when performing a difference calculation on the first file system tree and the second file system tree, the difference calculation module 4002 can be used to perform a difference calculation on the first data table and the second data table.

[0119] In one embodiment, the first file system tree and the second file system tree are both file system Merkle trees.

[0120] In one embodiment, when constructing a first file system tree of the file system based on the first directory structure in the first snapshot, the difference calculation module 4002 may be configured to traverse each file in the first directory structure and insert information about each file into the first data table in the form of a row record. When constructing a second file system tree of the file system based on the second directory structure in the second snapshot, the difference calculation module 4002 may be configured to traverse each file in the second directory structure and insert information about each file into the second data table in the form of a row record.

[0121] In one embodiment, when traversing each file in a first directory structure, the difference calculation module 4002 can be used to: traverse each file in the first directory structure in a first order, and when the traversed file is an ordinary file or an empty directory, determine the hash value of the ordinary file or empty directory; traverse each file in the first directory structure in a second order, and when the traversed file is a non-empty directory, determine the hash value of the non-empty directory. When traversing each file in a second directory structure, the difference calculation module 4002 can be used to: traverse each file in the second directory structure in a first order, and when the traversed file is an ordinary file or an empty directory, determine the hash value of the ordinary file or empty directory; traverse each file in the second directory structure in a second order, and when the traversed file is a non-empty directory, determine the hash value of the non-empty directory. In the first data table and the second data table, the row records of ordinary files include the hash values ​​of ordinary files, the row records of empty directories include the hash values ​​of empty directories, and the row records of non-empty directories include the hash values ​​of non-empty directories. The first order is the order from the root directory to the last layer of sub-files, and the second order is the reverse order of the first order.

[0122] In one embodiment, when traversing each file in the first directory structure, the difference calculation module 4002 can be used to: traverse each file in the first directory structure in a first order, and determine the absolute path of each traversed file. When traversing each file in the second directory structure, the difference calculation module 4002 can be used to: traverse each file in the second directory structure in a first order, and determine the absolute path of each traversed file. Both the first data table and the second data table can be compressed ordered tables. In the compressed ordered tables, the row record of each file can include the absolute path of the file. The row record of each subfile under the same directory file can include a record with the same path prefix. The first order is the order from the root directory to the last layer of subfiles.

[0123] In one embodiment, when traversing each file in the first directory structure, the difference calculation module 4002 can be configured to: traverse each file in the first directory structure using a stack, and insert information about each file into the first data table in the form of row records in the order of traversal. When traversing each file in the second directory structure, the difference calculation module 4002 can be configured to: traverse each file in the second directory structure using a stack, and insert information about each file into the second data table in the form of row records in the order of traversal. Both the first data table and the second data table can be compressed ordered tables.

[0124] In one embodiment, the first data table includes identification information of each file in the first directory structure, and the second data table includes identification information of each file in the second directory structure. Accordingly, when performing a difference calculation on the first data table and the second data table, the difference calculation module 4002 can be configured to: compare the identification information of each file in the first data table with the identification information of each file in the second data table; and determine whether there are different files in the first data table and the second data table based on the comparison result of the identification information.

[0125] In one embodiment, the difference calculation module 4002 can be used to: sequentially read the identification information of each file in the first data table as the first identification information, and sequentially read the identification information of each file in the second data table as the second identification information; in the process of sequential reading, the first identification information of the Nth row in the first data table is compared with at least one corresponding row of second identification information in the second data table to determine whether the first identification information of the Nth row and the corresponding second identification information of each row are equal, where N is a positive integer less than or equal to the total number of rows in the first data table; when the first identification information of the Nth row and the corresponding row of second identification information are not equal, it is determined that there is a difference file in the first data table and the second data table.

[0126] In one embodiment, the first identification information includes a first absolute path, and the second identification information includes a second absolute path. Correspondingly, the difference calculation module 4002 can be used to: compare the first absolute path in row N with the second absolute path in row N in the second data table to determine whether the first absolute path in row N is equal to the second absolute path in row N; if the first absolute path in row N is equal to the second absolute path in row N, read the first absolute path in row N+1 in the first data table and the second absolute path in row N+1 in the second data table, and compare the first absolute path in row N+1 with the second absolute path in row N+1; if the first absolute path in row N is not equal to the second absolute path in row N, read the first absolute path in row N+1 in the first data table, and compare the first absolute path in row N+1 with the second absolute path in row N, or read the second absolute path in row N+1 in the second data table, and compare the first absolute path in row N with the second absolute path in row N+1; if the first absolute path in row N is not equal to the second absolute path in the corresponding row, determine that the file corresponding to the first absolute path in row N is a deleted file or the file corresponding to the second absolute path in the corresponding row is a newly added file.

[0127] In one embodiment, the first identification information further includes a first hash value, and the second identification information further includes a second hash value. Accordingly, the difference calculation module 4002 can be used to: when the first absolute path in line N and the second absolute path in the corresponding line are equal, determine whether the first hash value in line N and the second hash value in the same line with the second absolute path are equal; when the first absolute path in line N and the second absolute path in the corresponding line are equal, and the first hash value in line N and the second hash value in the same line with the second absolute path are not equal, determine that the file corresponding to the second hash value is a modified file.

[0128] The functions of each module in the host file detection device provided in the embodiment of the present application can be referred to the corresponding description in the above method, and have corresponding beneficial effects, which will not be repeated here.

[0129] Based on the same technical concept, an embodiment of the present application further provides an electronic device, as shown in FIG41 . The electronic device includes a memory 4101 and a processor 4102. The memory 4101 stores a computer program executable on the processor 4102. When the processor 4102 executes the computer program, any of the methods described in the aforementioned embodiments is implemented. The number of the memory 4101 and the processor 4102 may be one or more.

[0130] The electronic device also includes:

[0131] The communication interface 4103 is used to communicate with external devices and perform data exchange transmission.

[0132] If the memory 4101, processor 4102, and communication interface 4103 are implemented independently, the memory 4101, processor 4102, and communication interface 4103 can be interconnected via a bus and communicate with each other. This bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. This bus can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, FIG41 shows only one thick line, but this does not mean that there is only one bus or only one type of bus.

[0133] Optionally, in a specific implementation, if the memory 4101, the processor 4102 and the communication interface 4103 are integrated on a chip, the memory 4101, the processor 4102 and the communication interface 4103 can communicate with each other through an internal interface.

[0134] An embodiment of the present application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any one of the methods provided in the embodiments of the present application.

[0135] An embodiment of the present application also provides a chip, which includes a processor for calling and executing instructions stored in the memory from the memory, so that a communication device equipped with the chip executes any one of the methods provided in the embodiment of the present application.

[0136] An embodiment of the present application also provides a chip, including: an input interface, an output interface, a processor and a memory. The input interface, the output interface, the processor and the memory are connected through an internal connection path. The processor is used to execute the code in the memory. When the code is executed, the processor is used to execute any one of the methods provided in the embodiment of the application.

[0137] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc. It is worth noting that the processor may be a processor that supports the Advanced RISC Machines (ARM) architecture.

[0138] Furthermore, optionally, the above-mentioned memory may include a read-only memory and a random access memory. The memory may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may include a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may include a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available. For example, static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM) and direct RAM bus random access memory (DR RAM).

[0139] In the above embodiments, all or part of the embodiments may be implemented using software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments may be implemented in the form of a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the present application are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another.

[0140] In the description of this specification, the reference terms "one embodiment," "some embodiments," "example," "specific example," or "some examples" mean that the specific features, structures, materials, or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. Moreover, the specific features, structures, materials, or characteristics described may be combined in any appropriate manner in any one or more embodiments or examples. In addition, those skilled in the art may combine and combine different embodiments or examples described in this specification, as well as features of different embodiments or examples, unless they are mutually inconsistent.

[0141] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features being referred to. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. Throughout the description of this application, "plurality" means two or more, unless otherwise specifically defined.

[0142] Any process or method described in the flowchart or otherwise described herein can be understood to represent a module, segment or portion of code comprising one or more executable instructions for implementing the steps of a specific logical function or process. The scope of the preferred embodiments of the present application includes other implementations in which the functions may be performed in a different order than shown or discussed, including performing the functions substantially simultaneously or in reverse order depending on the functions involved.

[0143] The logic and / or steps described in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, apparatus or device (such as a computer-based system, a system including a processor or other system that can fetch instructions from an instruction execution system, apparatus or device and execute instructions), or used in combination with such instruction execution systems, apparatuses or devices.

[0144] It should be understood that various parts of the present application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in a memory and executed by a suitable instruction execution system. All or part of the steps of the above embodiment method can be completed by instructing the relevant hardware through a program, which can be stored in a computer-readable storage medium. When the program is executed, it includes one or a combination of the steps of the method embodiment.

[0145] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing module, or each unit may exist physically separately, or two or more units may be integrated into a single module. The aforementioned integrated modules may be implemented in the form of hardware or in the form of software functional modules. If the aforementioned integrated modules are implemented in the form of software functional modules and sold or used as independent products, they may also be stored in a computer-readable storage medium. The storage medium may be a read-only memory, a magnetic disk, or an optical disk, etc.

[0146] The above is merely an exemplary embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any person skilled in the art can easily conceive of various modifications or substitutions within the technical scope described in this application, and such modifications or substitutions should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.

Claims

1. A host file detection method, characterized in that: Applied to host security detection system, including: Based on the snapshot sharing function between the host security detection system and the target host, a first snapshot and a second snapshot in the target host are obtained; the first snapshot is a data backup of the file system in the target host at a first time, and the second snapshot is a data backup of the file system at a second time, and the first time is earlier than the second time; performing a difference calculation on the first snapshot and the second snapshot; It is determined whether the file in the file system has changed based on the result of the difference calculation.

2. The host file detection method according to claim 1, characterized in that: The first snapshot and the second snapshot are both incremental snapshots.

3. The host file detection method according to claim 1, characterized in that: The performing difference calculation on the first snapshot and the second snapshot includes: Building a first file system tree of the file system based on the first directory structure in the first snapshot, and building a second file system tree of the file system based on the second directory structure in the second snapshot; the first file system tree is isomorphic to the first directory structure, and the second file system tree is isomorphic to the second directory structure; A difference calculation is performed on the first file system tree and the second file system tree.

4. The host file detection method according to claim 3, characterized in that: The first file system tree is stored in the form of a first data table, and the second file system tree is stored in the form of a second data table; both the first data table and the second data table are structured storage data tables; The performing difference calculation on the first file system tree and the second file system tree includes: A difference calculation is performed on the first data table and the second data table.

5. The host file detection method according to claim 3 or 4, characterized in that: The first file system tree and the second file system tree are both file system Merkle trees.

6. The host file detection method according to claim 4, characterized in that: The first data table includes identification information of each file in the first directory structure, and the second data table includes identification information of each file in the second directory structure; The performing difference calculation on the first data table and the second data table includes: Comparing identification information of each file in the first data table with identification information of each file in the second data table; Determine whether there are different files in the first data table and the second data table based on the comparison result of the identification information.

7. The host file detection method according to claim 6, characterized in that: The step of comparing identification information of each file in the first data table with identification information of each file in the second data table, and determining whether there are different files in the first data table and the second data table based on the comparison result of the identification information, includes: sequentially reading identification information of each file in the first data table as first identification information, and sequentially reading identification information of each file in the second data table as second identification information; In the process of sequentially reading, the first identification information of the Nth row in the first data table is sequentially compared with at least one corresponding row of second identification information in the second data table to determine whether the first identification information of the Nth row and each corresponding row of second identification information are equal; N is a positive integer less than or equal to the total number of rows in the first data table; When the first identification information of the Nth row and the corresponding row of second identification information are not equal, it is determined that there is a difference file between the first data table and the second data table.

8. The host file detection method according to claim 7, characterized in that: The first identification information includes a first absolute path, and the second identification information includes a second absolute path; In the process of sequentially reading, sequentially comparing the first identification information of the Nth row in the first data table with at least one corresponding row of second identification information in the second data table to determine whether the first identification information of the Nth row and each corresponding row of second identification information are equal, including: Compare the first absolute path in the Nth row with the second absolute path in the Nth row in the second data table to determine whether the first absolute path in the Nth row is equal to the second absolute path in the Nth row; When the first absolute path of the Nth row and the second absolute path of the Nth row are equal, reading the first absolute path of the N+1th row in the first data table and the second absolute path of the N+1th row in the second data table, and comparing the first absolute path of the N+1th row with the second absolute path of the N+1th row; In the case where the first absolute path of the Nth row and the second absolute path of the Nth row are not equal, the first absolute path of the N+1th row in the first data table is read, and the first absolute path of the N+1th row is compared with the second absolute path of the Nth row, or the second absolute path of the N+1th row in the second data table is read, and the first absolute path of the Nth row is compared with the second absolute path of the N+1th row; In the case where the first identification information of the Nth row and the corresponding row of second identification information are not equal, determining that there is a difference file between the first data table and the second data table includes: When the first absolute path in the Nth row and the corresponding second absolute path in the Nth row are not equal, it is determined that the file corresponding to the first absolute path in the Nth row is a deleted file or the file corresponding to the second absolute path in the Nth row is a newly added file.

9. The host file detection method according to claim 8, characterized in that: The first identification information further includes a first Hash value, and the second identification information further includes a second Hash value; In the process of sequentially reading, the first identification information of the Nth row in the first data table is sequentially compared with at least one corresponding row of second identification information in the second data table to determine whether the first identification information of the Nth row and each corresponding row of second identification information are equal, further comprising: In the case where the first absolute path of the Nth row and the corresponding second absolute path of the row are equal, determining whether the first hash value of the Nth row and the second hash value of the same row of the second absolute path are equal; When the first identification information of the Nth row and the corresponding second identification information are not equal, determining that there is a difference file between the first data table and the second data table, further comprising: When the first absolute path in the Nth row is equal to the second absolute path in the corresponding row, and the first hash value in the Nth row is not equal to the second hash value in the same row as the second absolute path, it is determined that the file corresponding to the second hash value is a modified file.

10. The host file detection method according to claim 4, characterized in that: The step of constructing a first file system tree of the file system based on the first directory structure in the first snapshot includes: Traversing each file in the first directory structure, and inserting information of each file into the first data table in the form of a row record; The step of constructing a second file system tree of the file system based on the second directory structure in the second snapshot includes: Each file in the second directory structure is traversed, and information of each file is inserted into the second data table in the form of a row record.

11. The host file detection method according to claim 10, characterized in that: The traversing each file in the first directory structure includes: Traversing each file in the first directory structure in a first order, and when the traversed file is a common file or an empty directory, determining a hash value of the common file or the empty directory; Traversing each file in the first directory structure in a second order, and when the traversed file is a non-empty directory, determining a hash value of the non-empty directory; The traversing each file in the second directory structure includes: Traversing each file in the second directory structure in the first order, and when the traversed file is a common file or an empty directory, determining a hash value of the common file or the empty directory; Traversing each file in the second directory structure in the second order, and when the traversed file is a non-empty directory, determining a hash value of the non-empty directory; In the first data table and the second data table, the row record of the common file includes the hash value of the common file, the row record of the empty directory includes the hash value of the empty directory, and the row record of the non-empty directory includes the hash value of the non-empty directory; The first order is the order from the root directory to the last layer of sub-files, and the second order is the reverse order of the first order.

12. The host file detection method according to claim 10, characterized in that: The traversing each file in the first directory structure includes: Traversing each file in the first directory structure in a first order, and determining an absolute path of each traversed file; The traversing each file in the second directory structure includes: Traversing each file in the second directory structure in a first order, and determining an absolute path of each traversed file; The first data table and the second data table are both compressed ordered tables, in which a row record of each file includes an absolute path of the file, and a row record of each sub-file under the same directory file includes a record of a path prefix among the same multiple path prefixes; The first order is the order from the root directory to the last layer of sub-files.

13. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory, wherein the processor implements the method according to any one of claims 1 to 12 when executing the computer program.

14. A computer-readable storage medium, characterized in that: A computer program is stored, and when the computer program is executed by a processor, the method according to any one of claims 1 to 12 is implemented.

Citation Information

Patent Citations

  • Quick file comparison method, system and client side

    CN102693302A

  • Data recovery method, device and equipment and storage medium

    CN112380057A

  • Backup method and system of NAS file system and storage medium

    CN114546980A

  • Host file detection method, electronic equipment and storage medium

    CN116305126A

  • Lockless synchronization of LSM tree metadata in a distributed system

    US20200201822A1

Cited By

  • File comparison method and device, electronic equipment and storage medium

    CN119476253A

  • Fingerprint generation method and device of virtual evaluation model based on Hash operation and medium

    CN121072693A