Method and device for detecting obfuscated malicious code, electronic equipment and storage medium

By obtaining the abstract syntax tree and data flow graph of obfuscated code, and using the random walk algorithm and self-attention model to detect obfuscated malicious code, this method solves the problem of detecting obfuscated malicious code in existing technologies and achieves effective detection in scenarios where obfuscation is widespread.

CN117892304BActive Publication Date: 2026-11-24HUAZHONG UNIV OF SCI & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410075663.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-18
Publication Date
2026-11-24
Estimated Expiration
2044-01-18

AI Technical Summary

Technical Problem

Existing malware detection technologies fail when code is extensively obfuscated, and conventional malware detection technologies cannot effectively detect obfuscated malware.

Method used

By obtaining the abstract syntax tree and data flow graph of the obfuscated code, a random walk algorithm is used to extract path features from these two, and a self-attention model is combined for detection to ensure the positional relevance of path features in the obfuscated code.

Benefits of technology

Even with extensive code obfuscation, it can effectively detect obfuscated malicious code, avoiding the impact of obfuscation on detection and improving detection accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117892304B_ABST
    Figure CN117892304B_ABST
Patent Text Reader

Abstract

This application discloses a method, apparatus, electronic device, and storage medium for detecting obfuscated malicious code. The method includes: obtaining an abstract syntax tree and a data flow graph of the obfuscated code, consisting of multiple nodes and multiple directed edges; based on a random walk algorithm, traversing multiple nodes and multiple directed edges in the abstract syntax tree to obtain multiple first walk paths corresponding to the abstract syntax tree, and traversing multiple nodes and multiple directed edges in the data flow graph to obtain multiple second walk paths corresponding to the data flow graph; one first walk path corresponds to one second walk path, the nodes contained in the corresponding first walk path and the second walk path are in close positions in the obfuscated code, and the nodes in the corresponding first walk path and the second walk path that are at the same position are in close positions in the obfuscated code; combining the multiple first walk paths and the multiple second walk paths to detect the obfuscated code to determine whether the obfuscated code is malicious code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of software security technology, and in particular to a method, apparatus, electronic device, and storage medium for detecting obfuscated malicious code. Background Technology

[0002] Malicious code detection technology refers to determining whether a given source code is malicious, that is, whether the source code is harmful to a computer. Obfuscated malicious code detection technology refers to determining whether the source code is malicious after it has been obfuscated.

[0003] Current malware detection technologies include obfuscation detection techniques and conventional malware detection techniques. Obfuscation detection techniques determine whether code contains obfuscation. Therefore, their effectiveness relies on the assumption that benign code will not be obfuscated, only malicious code will. Consequently, obfuscation detection techniques will fail when benign code commonly contains obfuscation. Conventional malware detection techniques, on the other hand, generally do not consider code obfuscation or can only handle mild obfuscation. Therefore, in scenarios where code obfuscation is widespread, conventional malware detection techniques also cannot detect obfuscated malware. Summary of the Invention

[0004] The purpose of this application is to provide a method, apparatus, electronic device and storage medium for detecting obfuscated malicious code, which can detect malicious code when the code is widely obfuscated.

[0005] To address the aforementioned technical problems, embodiments of this application provide a method for detecting obfuscated malicious code, comprising the following steps: obtaining an abstract syntax tree (AST) and a data flow graph of the obfuscated code, wherein both the AST and the data flow graph are binary tuples composed of multiple nodes and multiple directed edges, and the nodes in the AST are the same as the nodes in the data flow graph, while the directed edges in the AST are not entirely the same as the directed edges in the data flow graph; and based on a random walk algorithm, traversing multiple nodes and multiple directed edges in the AST to obtain multiple first walks corresponding to the AST. The system iterates through multiple nodes and directed edges in the data flow graph to obtain multiple second traversal paths corresponding to the data flow graph. Each first traversal path corresponds to one second traversal path. Nodes contained in the corresponding first and second traversal paths are located close to each other in the obfuscated code, and nodes at the same position in the corresponding first and second traversal paths are also located close to each other in the obfuscated code. The obfuscated code is then detected by combining the multiple first and second traversal paths to determine whether it is malicious code.

[0006] Embodiments of this application also provide a detection device for obfuscated malicious code, comprising: a feature acquisition module, used to acquire an abstract syntax tree and a data flow graph of the obfuscated code, wherein both the abstract syntax tree and the data flow graph are tuples composed of multiple nodes and multiple directed edges, and the nodes in the abstract syntax tree are the same as the nodes in the data flow graph, while the directed edges in the abstract syntax tree are not completely identical to the directed edges in the data flow graph; and a path traversal module, used to traverse multiple nodes and multiple directed edges in the abstract syntax tree based on a random walk algorithm to obtain multiple first traversal paths corresponding to the abstract syntax tree. The system traverses multiple nodes and directed edges in the data flow graph to obtain multiple second traversal paths corresponding to the data flow graph. Each first traversal path corresponds to one second traversal path. Nodes contained in the corresponding first and second traversal paths are located close to each other in the obfuscated code, and nodes at the same position in the corresponding first and second traversal paths are also located close to each other in the obfuscated code. A code detection module combines the multiple first and second traversal paths to detect the obfuscated code, thereby determining whether the obfuscated code is malicious.

[0007] Embodiments of this application also provide an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the above-described method for detecting obfuscated malicious code.

[0008] Embodiments of this application also provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method for detecting obfuscated malicious code.

[0009] In some optional embodiments, the step of traversing multiple nodes and directed edges in the abstract syntax tree (AST) based on a random walk algorithm to obtain multiple first walk paths corresponding to the AST, and traversing multiple nodes and directed edges in the data flow graph to obtain multiple second walk paths corresponding to the data flow graph, includes: selecting a node from the multiple nodes of the AST as the starting point of the first walk, where each first starting point corresponds to at least one first walk path; and representing the nodes according to the first starting point and the directed edges of the AST. Connectivity is assessed by selecting a node from all nodes in the abstract syntax tree except for the first walk start point as the remaining node in the first walk path; simultaneously, a node from all nodes in the data flow graph is selected as the second walk start point, where each second walk start point corresponds to at least one second walk path; based on the node connectivity represented by the second walk start point and multiple directed edges of the data flow graph, a node from all nodes in the data flow graph except for the second walk start point is selected as the remaining node in the second walk path.

[0010] In some optional embodiments, there are multiple first and second walk start points. The method further includes: after determining the first and second walk start points, sorting the multiple first walk start points of the abstract syntax tree and the multiple second walk start points of the data flow graph according to the order in which the nodes are traversed in the preorder traversal of the abstract syntax tree and the data flow graph; and sorting the first walk paths corresponding to each first walk start point of the abstract syntax tree and the second walk paths corresponding to each second walk start point of the data flow graph according to the order of the first and second walk start points. In this application, sorting the first walk paths ensures the positional correlation between the features of the abstract syntax tree and the features of the data flow graph.

[0011] In some optional embodiments, the random walk algorithm is controlled by a preset elasticity coefficient, which includes the number of rounds of walking the abstract syntax tree and the data flow graph, the number of first and second walk paths obtained in each round of walking, and the maximum length of each first and second walk path.

[0012] In some optional embodiments, each node includes a node type attribute and a node value attribute. The step of detecting the obfuscated code by combining the multiple first walk paths and the multiple second walk paths includes: converting the multiple first walk paths and the multiple second walk paths into a first three-dimensional vector and a second three-dimensional vector, respectively; wherein the first three-dimensional vector includes the following three dimensions: the number of first walk paths, the maximum length of the first walk paths, and the sum of the vector lengths of the node type attribute and the node value attribute of each node; the second three-dimensional vector includes the following three dimensions: the number of second walk paths, the maximum length of the second walk paths, and the sum of the vector lengths of the node type attribute and the node value attribute of each node; and the obfuscated code is detected by combining the first three-dimensional vector and the second three-dimensional vector.

[0013] In some optional embodiments, the step of detecting the obfuscated code by combining the first three-dimensional vector and the second three-dimensional vector includes: inputting the first three-dimensional vector and the second three-dimensional vector into a first self-attention model and a second self-attention model, respectively, to obtain a first feature vector and a second feature vector; wherein the first self-attention model and the second self-attention model are both composed of n self-attention layers and m convolutional layers with pooling; and combining the first feature vector and the second feature vector to detect the obfuscated code.

[0014] In some optional embodiments, the first walk starting point is the same in each round of the abstract syntax tree, and the second walk starting point is the same in each round of the data flow graph. This application can guarantee the positional relevance between walk paths in different rounds.

[0015] The method for detecting obfuscated malicious code provided in the embodiments of this application has the following beneficial effects:

[0016] Since obfuscated code is obtained by obfuscating the original code, its abstract syntax tree (AST) is the closest representation to the original code. A data flow graph (DLP) can be seen as a way to annotate the AST to facilitate understanding. Therefore, this application simultaneously obtains the AST and DLP of the obfuscated code. Combining the characteristics of the AST and DLP—namely, the first and second traversal paths obtained by traversing the AST and DLP respectively—the obfuscated code is detected to determine whether it is malicious. This avoids the impact of obfuscation on code detection and effectively detects obfuscated malicious code even in scenarios where obfuscation is widespread. Furthermore, considering that the features of the abstract syntax tree and the data flow graph are two different types of code features, in order to combine the two to achieve the detection of obfuscated malicious code, each first walk path of the abstract syntax tree in this application corresponds to a second walk path of the data flow graph. The nodes contained in the corresponding first walk path and the second walk path are in close positions in the obfuscated code, and the nodes in the same position in the corresponding first walk path and the second walk path are in close positions in the obfuscated code. This makes the features of the abstract syntax tree and the features of the data flow graph positionally related, which is more conducive to their combination for the detection of obfuscated code. Attached Figure Description

[0017] One or more embodiments are illustrated by way of example with reference to the accompanying drawings, and these illustrative descriptions do not constitute a limitation on the embodiments.

[0018] Figure 1 This is a flowchart of a method for detecting obfuscated malicious code according to an embodiment of this application;

[0019] Figure 2 This is a schematic diagram of a detection device for obfuscated malicious code according to an embodiment of this application;

[0020] Figure 3 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Detailed Implementation

[0021] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the various embodiments of this application will be described in detail below with reference to the accompanying drawings. However, those skilled in the art will understand that many technical details have been provided in the various embodiments of this application to help readers better understand this application. However, the technical solutions claimed in this application can be implemented even without these technical details and various changes and modifications based on the following embodiments. The division of the various embodiments below is for the convenience of description and should not constitute any limitation on the specific implementation of this application. The various embodiments can be combined with and referenced by each other without contradiction.

[0022] One embodiment of this application relates to a method for detecting obfuscated malicious code, applied to an electronic device, wherein the electronic device can be a terminal or a server. In this embodiment and the following embodiments, the electronic device is described using a server as an example. The implementation details of the method for detecting obfuscated malicious code in this embodiment are described below. The following implementation details are provided for ease of understanding and are not essential for implementing this solution.

[0023] The specific process of the method for detecting obfuscated malicious code in this embodiment can be as follows: Figure 1 As shown, it includes:

[0024] Step 101: Obtain the abstract syntax tree and data flow graph of the obfuscated code. Both the abstract syntax tree and the data flow graph are tuples composed of multiple nodes and multiple directed edges. The nodes in the abstract syntax tree are the same as the nodes in the data flow graph, but the directed edges in the abstract syntax tree are not exactly the same as the directed edges in the data flow graph.

[0025] Specifically, obfuscated code is obtained after obfuscation of the original code. An abstract syntax tree (AST) is a tree-like representation of the abstract syntactic structure of the code, where each node represents a structure within the code. The AST of the obfuscated code is the closest representation to the original code. A data flow graph can be seen as a way to annotate the AST to facilitate understanding. Therefore, this application obtains the AST and data flow graph of the obfuscated code. Both the AST and the data flow graph consist of a pair of nodes and directed edges. The nodes in the AST are the same as those in the data flow graph, but the directed edges are not entirely the same. For example, multiple nodes form a node G, and multiple directed edges form an edge set V. Both the AST and the data flow graph can be represented as a pair of nodes G and edges V. The data flow graph uses the same node set G as the AST, ensuring the positional relevance between the data flow graph and the AST.

[0026] Step 102: Based on the random walk algorithm, traverse multiple nodes and directed edges in the abstract syntax tree to obtain multiple first walk paths corresponding to the abstract syntax tree, and traverse multiple nodes and directed edges in the data flow graph to obtain multiple second walk paths corresponding to the data flow graph; wherein, one first walk path corresponds to one second walk path, the nodes contained in the corresponding first walk path and second walk path are in close positions in the obfuscated code, and the nodes in the corresponding first walk path and second walk path that are at the same position are in close positions in the obfuscated code.

[0027] Specifically, based on the random walk algorithm, a walk is performed in the abstract syntax tree, that is, by walking multiple nodes and multiple directed edges in the abstract syntax tree, multiple paths corresponding to the abstract syntax tree can be obtained, which serve as the first walk path. Similarly, based on the random walk algorithm, a walk is performed in the data flow graph, that is, by walking multiple nodes and multiple directed edges in the data flow graph, multiple paths corresponding to the data flow graph can be obtained, which serve as the second walk path.

[0028] In some embodiments, from multiple nodes of the abstract syntax tree, a node is selected as the first traversal starting point of the abstract syntax tree, and a first traversal starting point corresponds to at least one first traversal path; based on the node connectivity represented by the first traversal starting point and multiple directed edges of the abstract syntax tree, a node is selected as the remaining node in the first traversal path from all nodes of the abstract syntax tree other than the first traversal starting point; simultaneously, from multiple nodes of the data flow graph, a node is selected as the second traversal starting point of the data flow graph, and a second traversal starting point corresponds to at least one second traversal path; based on the node connectivity represented by the second traversal starting point and multiple directed edges of the data flow graph, a node is selected as the remaining node in the second traversal path from all nodes of the data flow graph other than the second traversal starting point.

[0029] The process of walking through an abstract syntax tree (AST) is similar to that of walking through a data flow graph. This example uses an AST to illustrate the process in detail:

[0030] First, from the multiple nodes of the Abstract Syntax Tree (ABST), a node is selected as the starting point for the walk of the ABST. The walk begins from this node. Each starting point corresponds to at least one first walk path; that is, a node can be used repeatedly as the starting point. Different first walk paths may have the same starting point, differing only in the presence or order of the remaining nodes. After determining the starting point of the first walk path, the remaining nodes within that path need to be determined. Based on the node connectivity represented by the starting point and the directed edges of the ABST, nodes other than the starting point are selected from all nodes in the ABST to serve as the remaining nodes in the first walk path. Directed edges describe nodes with node connectivity. Based on the determined starting point and its corresponding directed edges, nodes connected to the starting point are searched and added to the first traversal path corresponding to that starting point. The next node to be added to the first traversal path is the node connected to the node connected to the starting point. This process is repeated until no nodes are connected (i.e., the node's out-degree is 0). When searching for nodes connected to the starting point, if multiple nodes exist, a node is randomly selected and added to the first traversal path corresponding to that starting point.

[0031] In some embodiments, there are multiple first and second walk start points. After determining the first and second walk start points, the multiple first walk start points of the abstract syntax tree and the multiple second walk start points of the data flow graph are sorted according to the order in which the nodes are traversed in the preorder traversal of the abstract syntax tree and the data flow graph. According to the arrangement order of the first and second walk start points, the first walk paths corresponding to the first walk start points of the abstract syntax tree and the second walk paths corresponding to the second walk start points of the data flow graph are sorted.

[0032] Using the abstract syntax tree as an example again:

[0033] From the multiple nodes of the Abstract Syntax Tree (ABST), multiple nodes can be selected as the starting points for the walks in the ABST, i.e., there are multiple starting points. These multiple starting points form a sequence of starting points for the ABST. The objects contained in a sequence must have an order. Therefore, in this embodiment, after determining multiple starting points, the multiple starting points are sorted according to the order in which the nodes in the ABST are traversed in preorder. Since the multiple starting points have an order, the first walk paths corresponding to each of the multiple starting points also have an order. Therefore, after determining the first walk paths corresponding to each of the multiple starting points, the first walk paths corresponding to each starting point in the ABST are sorted according to the order of the starting points.

[0034] In this embodiment, the multiple starting points of the abstract syntax tree and the first traversal paths corresponding to each of the multiple starting points are sorted, and the multiple starting points of the data flow graph and the second traversal paths corresponding to each of the multiple starting points are also sorted, so that there is a positional correlation between the first traversal paths and the second traversal paths, which is convenient for subsequent combination for the detection of obfuscated code.

[0035] In some embodiments, the starting point of the walk can be randomly selected. In some embodiments, the selection type of the starting point specifically includes: function parameters, constants, and global variables of the obfuscated code. That is, the first walk path in this embodiment is a path starting from the function parameters, constants, and global variables of the obfuscated code, realizing the tracking of the data flow of the function parameters, constants, and global variables of the obfuscated code. In addition, to ensure the efficiency of data flow tracing, the chain tracing range of the data flow is limited to the basic block in which the variable is located. When a connection is detected between the variable and an object outside the basic block, the two are connected, and then the chain tracing ends.

[0036] In some embodiments, the random walk algorithm is controlled by a preset elasticity coefficient, which includes the number of rounds of walking the abstract syntax tree and data flow graph, the number of first and second walk paths obtained in each round, and the maximum length of each first and second walk path. A larger elasticity coefficient results in more comprehensive extraction of first and second walk paths, while a smaller elasticity coefficient results in fewer extracted first and second walk paths. Those skilled in the art can set the elasticity coefficient according to actual needs; for example, the maximum length of each first and second walk path can be set to 32, and the number of first and second walk paths obtained can both be 256.

[0037] In the specific implementation, since the elasticity coefficient controls the maximum length of the walking path during the walking process, when selecting a node as a remaining node in the first walking path, the selection of the last node in the first walking path does not only depend on the node's out-degree being 0, but also on the maximum length of the first walking path. That is to say, in this embodiment, when selecting a node as a remaining node in the first walking path, if the length of the first walking path has reached the maximum length, even if the node's out-degree is not 0, the addition of nodes to the first walking path will be stopped.

[0038] In one example, the first walk starting point is the same in each round of the abstract syntax tree (API), and the second walk starting point is the same in each round of the data flow graph (DLP). If the number of rounds is greater than one, meaning the above walk process needs to be executed multiple times, then in each round, it is necessary to first determine the walk starting point for that round. The fact that the walk starting point is the same in each round of the API and the DLP ensures the positional relevance of the walk paths between different rounds, that is, the positional relevance of the first walk path and the positional relevance of the second walk path between different rounds.

[0039] The above embodiments describe in detail the walking process of the abstract syntax tree. This walking process is also applicable to the walking of the data flow graph, and will not be repeated here.

[0040] After obtaining multiple first walk paths corresponding to the abstract syntax tree and multiple second walk paths corresponding to the data flow graph through the walk, for these multiple first walk paths and multiple second walk paths, since the first walk paths and the second walk paths are generated through the same node set G, the only difference being the edge set V used, therefore, one first walk path corresponds to one second walk path. The nodes contained in the corresponding first walk path and the second walk path are in close positions in the obfuscated code, and the nodes in the same position in the corresponding first walk path and the second walk path are in close positions in the obfuscated code. Since both the first walk path and the second walk path are sorted according to the order of the walk starting point, the corresponding first walk path and the second walk path have the same starting point, thus ensuring the positional correlation between the first walk path and the second walk path. It is understandable that in multiple first walk paths, some of the nodes contained in the first walk paths are located in similar positions in the obfuscated code, and in multiple second walk paths, some of the nodes contained in the second walk paths are also located in similar positions in the obfuscated code. That is, some first walk paths also have positional correlations, and some second walk paths also have positional correlations.

[0041] Step 103: Combine multiple first roaming paths and multiple second roaming paths to detect the obfuscated code in order to determine whether the obfuscated code is malicious code.

[0042] Specifically, since the first walk path has the characteristics of an abstract syntax tree and the second walk path has the characteristics of a data flow graph, in order to combine the two for obfuscated code detection, the first and second walk paths first need to adopt the same representation method. Specifically, multiple first walk paths and multiple second walk paths are converted into a first three-dimensional vector and a second three-dimensional vector, respectively. The first three-dimensional vector contains the following three dimensions: the number of first walk paths, the maximum length of the first walk path, and the sum of the vector lengths of the node type attribute and the node value attribute of each node. The second three-dimensional vector contains the following three dimensions: the number of second walk paths, the maximum length of the second walk path, and the sum of the vector lengths of the node type attribute and the node value attribute of each node.

[0043] Taking the feature of an abstract syntax tree—multiple first walk paths—as an example, the representation of multiple first walk paths is as follows (i.e., the first three-dimensional vector is obtained in the following way):

[0044] A first walk path P can consist of multiple nodes g, i.e., P = (g1, g2, g3, ..., gn), where each node g has two attributes: a node type attribute and a node value attribute. The node type attribute is represented using one-hot encoding of dimension c, where c is the number of node types. Regarding the node value attribute, for identifier type nodes, the node value needs to be normalized and then represented using a character-level frequency vector. The dimension of the frequency vector is equal to the sum of the number of legal characters, digits, and symbols in the identifier, which is 63. Let the number of first walk paths be k, and the maximum length of the first walk path be l. Then, a single first walk path can be represented as a first two-dimensional vector: (l, 63 + c), and multiple first walk paths can be represented as a first three-dimensional vector: (k, l, 63 + c).

[0045] It is understandable that the conversion method for multiple second walk paths can also refer to the above method. Let the number of first walk paths be m and the maximum length of the first walk path be n. Then, a second walk path can be specifically represented as a second two-dimensional vector: (n, 63+c), and multiple first walk paths can be specifically represented as a first three-dimensional vector: (m, n, 63+c).

[0046] After using the same representation method for the first and second traversal paths to obtain the first and second three-dimensional vectors, the obfuscated code can be detected by combining the first and second three-dimensional vectors.

[0047] Specifically, the first and second 3D vectors are input into the first and second self-attention models, respectively, to obtain the first and second feature vectors. Both the first and second self-attention models consist of n self-attention layers and m convolutional layers with pooling. The obfuscated code is detected by combining the first and second feature vectors. The self-attention mechanism is used to process the first and second 3D vectors, assigning them different weights. The sum of the weighted first and second 3D vectors is taken as the final code feature of the obfuscated code. This feature is used to detect the obfuscated code and determine whether it is malicious. It can be understood that this code feature is a combination of the abstract syntax tree and data flow graph of the obfuscated code, making the detection results more accurate.

[0048] In a specific example, both the first and second self-attention models mentioned above are trained using a dataset containing both malicious and benign code, with a dataset size of at least 2000 entries. The values ​​of n and m in the first and second self-attention models can be 1 and 3 respectively. In this case, the outputs of the first and second self-attention models are both one-dimensional vectors of length 512, and the sum of these vectors is also a 512-dimensional one-dimensional vector.

[0049] In this embodiment, since obfuscated code is obtained by obfuscating the original code, its abstract syntax tree is the closest representation to the original code description. The data flow graph can be regarded as a description method of annotating the abstract syntax tree to facilitate understanding of the abstract syntax tree. Therefore, in this application, the abstract syntax tree and data flow graph of the obfuscated code are obtained, and the obfuscated code is detected by combining the features of the abstract syntax tree and the data flow graph, namely the first traversal path and the second traversal path obtained by traversing the abstract syntax tree and the data flow graph, respectively, to determine whether the obfuscated code is malicious code. This can avoid the influence of obfuscation in the code on code detection, and can effectively detect obfuscated malicious code even in scenarios where obfuscation is widespread. Furthermore, considering that the features of the abstract syntax tree and the data flow graph are two different types of code features, in order to combine the two to achieve the detection of obfuscated malicious code, each first walk path of the abstract syntax tree in this application corresponds to a second walk path of the data flow graph. The nodes contained in the corresponding first walk path and the second walk path are in close positions in the obfuscated code, and the nodes in the same position in the corresponding first walk path and the second walk path are in close positions in the obfuscated code. This makes the features of the abstract syntax tree and the features of the data flow graph positionally related, which is more conducive to their combination for the detection of obfuscated code.

[0050] It should be noted that the method for detecting obfuscated malicious code described in any of the above embodiments can not only detect whether obfuscated code is malicious code, but also detect whether ordinary code that has not been obfuscated is malicious code. The embodiments of this application do not limit the type of code.

[0051] The steps of the various methods described above are only for clarity. In practice, they can be combined into one step or some steps can be split into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this patent. Adding insignificant modifications or introducing insignificant designs to the algorithm or process, but without changing the core design of the algorithm and process, are also within the scope of protection of this patent.

[0052] Another embodiment of this application relates to a detection device for obfuscated malicious code. The implementation details of this embodiment's obfuscated malicious code detection device are described below. The following implementation details are provided for ease of understanding and are not essential for implementing this solution. A schematic diagram of this embodiment's obfuscated malicious code detection device can be seen as follows: Figure 2 As shown, it includes: feature acquisition module 201, path traversal module 202, and code detection module 203.

[0053] Specifically, the feature acquisition module 201 is used to acquire the abstract syntax tree and data flow graph of the obfuscated code. Both the abstract syntax tree and the data flow graph are tuples composed of multiple nodes and multiple directed edges. The nodes in the abstract syntax tree are the same as the nodes in the data flow graph, but the directed edges in the abstract syntax tree are not exactly the same as the directed edges in the data flow graph.

[0054] The path traversal module 202 is used to traverse multiple nodes and multiple directed edges in the abstract syntax tree based on a random walk algorithm to obtain multiple first traversal paths corresponding to the abstract syntax tree, and to traverse multiple nodes and multiple directed edges in the data flow graph to obtain multiple second traversal paths corresponding to the data flow graph; wherein, one first traversal path corresponds to one second traversal path, the nodes contained in the corresponding first traversal path and the second traversal path are in close positions in the obfuscated code, and the nodes in the corresponding first traversal path and the second traversal path that are at the same position are in close positions in the obfuscated code.

[0055] In one example, the path traversal module 202 is further configured to select a node as the starting point of the traversal of the abstract syntax tree from multiple nodes of the abstract syntax tree, wherein a starting point corresponds to at least one first traversal path; and select a node as the remaining node in the first traversal path from all nodes of the abstract syntax tree other than the starting point, based on the node connectivity represented by the starting point and multiple directed edges of the abstract syntax tree.

[0056] The code detection module 203 is used to combine multiple first traversal paths and multiple second traversal paths to detect obfuscated code in order to determine whether the obfuscated code is malicious code.

[0057] In one example, each node contains a node type attribute and a node value attribute. The code detection module 203 is also used to convert multiple first traversal paths and multiple second traversal paths into a first three-dimensional vector and a second three-dimensional vector, respectively. The first three-dimensional vector contains the following three dimensions: the number of first traversal paths, the maximum length of the first traversal paths, and the sum of the vector lengths of the node type attribute and the node value attribute of each node. The second three-dimensional vector contains the following three dimensions: the number of second traversal paths, the maximum length of the second traversal paths, and the sum of the vector lengths of the node type attribute and the node value attribute of each node. By combining the first three-dimensional vector and the second three-dimensional vector, obfuscated code is detected.

[0058] It is not difficult to see that this embodiment is a device embodiment corresponding to the above method embodiments, and this embodiment can be implemented in conjunction with the above method embodiments. The relevant technical details and technical effects mentioned in the above embodiments are still valid in this embodiment, and will not be repeated here to reduce repetition. Accordingly, the relevant technical details mentioned in this embodiment can also be applied to the above embodiments.

[0059] It is worth mentioning that all modules involved in this embodiment are logical modules. In practical applications, a logical unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. Furthermore, to highlight the innovative aspects of this application, this embodiment does not introduce units that are not closely related to solving the technical problems proposed in this application; however, this does not mean that other units are absent in this embodiment.

[0060] Another embodiment of this application relates to an electronic device, such as... Figure 3 As shown, it includes: at least one processor 301; and a memory 302 communicatively connected to the at least one processor 301; wherein the memory 302 stores instructions executable by the at least one processor 301, the instructions being executed by the at least one processor 301 to enable the at least one processor 301 to perform the obfuscated malicious code detection method in the above embodiments.

[0061] The memory and processor are connected via a bus, which can include any number of interconnecting buses and bridges, connecting various circuits of one or more processors and memories. The bus can also connect various other circuits, such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and will not be described further herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be a single element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices over a transmission medium. Data processed by the processor is transmitted over the wireless medium via an antenna, which further receives data and transmits it to the processor.

[0062] The processor manages the bus and general processing, and also provides various functions, including timing, peripheral interfaces, voltage regulation, power management, and other control functions. Memory is used to store data used by the processor during operation.

[0063] Another embodiment of this application relates to a computer-readable storage medium storing a computer program. When executed by a processor, the computer program implements the method embodiments described above.

[0064] That is, those skilled in the art will understand that all or part of the steps in the methods of the above embodiments can be implemented by a program instructing related hardware. This program is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0065] Those skilled in the art will understand that the above embodiments are specific embodiments for implementing this application, and in practical applications, various changes can be made to them in form and detail without departing from the spirit and scope of this application.

Claims

1. A method for detecting obfuscated malicious code, characterized in that, include: Obtain the abstract syntax tree and data flow graph of the obfuscated code. Both the abstract syntax tree and the data flow graph are tuples composed of multiple nodes and multiple directed edges. The nodes in the abstract syntax tree are the same as the nodes in the data flow graph, and the directed edges in the abstract syntax tree are not exactly the same as the directed edges in the data flow graph. Based on the random walk algorithm, multiple nodes and multiple directed edges in the abstract syntax tree are traversed to obtain multiple first walk paths corresponding to the abstract syntax tree, and multiple nodes and multiple directed edges in the data flow graph are traversed to obtain multiple second walk paths corresponding to the data flow graph. Among them, a first walk path corresponds to a second walk path, the nodes contained in the corresponding first walk path and the second walk path are in close positions in the obfuscated code, and the nodes in the corresponding first walk path and the second walk path that are at the same position are in close positions in the obfuscated code. By combining the multiple first traversal paths and the multiple second traversal paths, the obfuscated code is detected to determine whether the obfuscated code is malicious code; Each node contains a node type attribute and a node value attribute. The detection of the obfuscated code, combining the multiple first traversal paths and the multiple second traversal paths, includes: The plurality of first traversal paths and the plurality of second traversal paths are respectively converted into a first three-dimensional vector and a second three-dimensional vector; wherein, the first three-dimensional vector contains the following three dimensions: the number of first traversal paths, the maximum length of the first traversal paths, and the sum of the vector lengths of the node type attribute and the node value attribute of each node; the second three-dimensional vector contains the following three dimensions: the number of second traversal paths, the maximum length of the second traversal paths, and the sum of the vector lengths of the node type attribute and the node value attribute of each node; The first three-dimensional vector and the second three-dimensional vector are respectively input into the first self-attention model and the second self-attention model to obtain the first feature vector and the second feature vector; wherein, the first self-attention model and the second self-attention model are both composed of n self-attention layers and m convolutional layers with pooling; The obfuscated code is detected by combining the first feature vector and the second feature vector.

2. The method for detecting obfuscated malicious code according to claim 1, characterized in that, The random walk algorithm traverses multiple nodes and directed edges in the abstract syntax tree to obtain multiple first walk paths corresponding to the abstract syntax tree, and traverses multiple nodes and directed edges in the data flow graph to obtain multiple second walk paths corresponding to the data flow graph, including: From the multiple nodes of the abstract syntax tree, select a node as the first starting point of the abstract syntax tree, where a first starting point corresponds to at least one first traversal path; based on the node connectivity represented by the first starting point and the multiple directed edges of the abstract syntax tree, select a node as the remaining node in the first traversal path from all nodes of the abstract syntax tree other than the first starting point. Simultaneously, from multiple nodes in the data flow graph, a node is selected as the second walk start point of the data flow graph, and a second walk start point corresponds to at least one second walk path; based on the node connectivity represented by the second walk start point and multiple directed edges of the data flow graph, a node is selected from all nodes in the data flow graph other than the second walk start point as the remaining node in the second walk path.

3. The method for detecting obfuscated malicious code according to claim 2, characterized in that, There are multiple first and second wandering starting points, and the method further includes: After determining the first and second starting points of the walk, the multiple first starting points of the abstract syntax tree and the multiple second starting points of the data flow graph are sorted according to the order in which the nodes of the abstract syntax tree and the data flow graph are traversed in preorder. Based on the order of the first and second starting points of each walk, the first walk paths corresponding to the first starting points of the abstract syntax tree and the second walk paths corresponding to the second starting points of the data flow graph are sorted respectively.

4. The method for detecting obfuscated malicious code according to claim 3, characterized in that, The random walk algorithm is controlled by a preset elasticity coefficient, which includes the number of rounds of walking the abstract syntax tree and the data flow graph, the number of first and second walk paths obtained in each round of walking, and the maximum length of each first and second walk path.

5. The method for detecting obfuscated malicious code according to claim 4, characterized in that, In each round of the abstract syntax tree, the first starting point used is the same, and in each round of the data flow graph, the second starting point used is the same.

6. A detection device for obfuscated malicious code, characterized in that, include: The feature acquisition module is used to acquire the abstract syntax tree and data flow graph of the obfuscated code. The abstract syntax tree and the data flow graph are both tuples composed of multiple nodes and multiple directed edges. The nodes in the abstract syntax tree are the same as the nodes in the data flow graph, and the directed edges in the abstract syntax tree are not exactly the same as the directed edges in the data flow graph. The path traversal module is used to traverse multiple nodes and multiple directed edges in the abstract syntax tree based on a random walk algorithm to obtain multiple first traversal paths corresponding to the abstract syntax tree, and to traverse multiple nodes and multiple directed edges in the data flow graph to obtain multiple second traversal paths corresponding to the data flow graph. Among them, a first walk path corresponds to a second walk path, the nodes contained in the corresponding first walk path and the second walk path are in close positions in the obfuscated code, and the nodes in the corresponding first walk path and the second walk path that are at the same position are in close positions in the obfuscated code. The code detection module is used to combine the multiple first roaming paths and the multiple second roaming paths to detect the obfuscated code, so as to determine whether the obfuscated code is malicious code; Each node contains a node type attribute and a node value attribute. The code detection module is specifically used for: The plurality of first traversal paths and the plurality of second traversal paths are respectively converted into a first three-dimensional vector and a second three-dimensional vector; wherein, the first three-dimensional vector contains the following three dimensions: the number of first traversal paths, the maximum length of the first traversal paths, and the sum of the vector lengths of the node type attribute and the node value attribute of each node; the second three-dimensional vector contains the following three dimensions: the number of second traversal paths, the maximum length of the second traversal paths, and the sum of the vector lengths of the node type attribute and the node value attribute of each node; The first three-dimensional vector and the second three-dimensional vector are respectively input into the first self-attention model and the second self-attention model to obtain the first feature vector and the second feature vector; wherein, the first self-attention model and the second self-attention model are both composed of n self-attention layers and m convolutional layers with pooling; The obfuscated code is detected by combining the first feature vector and the second feature vector.

7. An electronic device, characterized in that, include: At least one processor; as well as, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the detection method for obfuscated malicious code as described in any one of claims 1 to 5.

8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the method for detecting obfuscated malicious code as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Code searching method based on multi-dimensional matching

    CN114186017A

  • Software defect prediction method, system and equipment based on information fusion and medium

    CN115617694A