An interpretable malware detection method based on api sequence prototypes
By using an API sequence prototype-based approach combined with LSTM-attention networks and graph embedding algorithms, a malware classification model is constructed. This solves the problems of large detection errors, difficulty in updating, and inability to handle polymorphic malware in existing technologies, achieving malware detection with high accuracy and interpretability.
Patent Information
- Application Number
- CN202310931716.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-27
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2043-07-27
AI Technical Summary
Existing signature-based malware detection methods suffer from problems such as large errors in manual analysis, difficulty in updating, inability to detect polymorphic and unknown malware, and difficulty in dealing with code obfuscation techniques based on behavior.
We employ an API sequence prototype-based approach, using sequence mining and clustering algorithms to extract API sequence prototypes. These prototypes are then fed into an LSTM-attention network model for training. By combining the N-Gram algorithm and graph embedding algorithm, we construct a malware classification model capable of interpreting detection results.
It achieves high accuracy in malware detection and can interpret the detection results, improving the efficiency and interpretability of the model and effectively dealing with polymorphic and unknown malware.
Smart Images

Figure CN116933262B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of malware detection, and more specifically to an interpretable malware detection method based on API sequence prototypes. Background Technology
[0002] Malware refers to programs such as viruses, worms, and Trojans that perform malicious tasks on computer systems, gaining control by disrupting software processes. While the initial motivations for malware emergence were primarily driven by interest, such as demonstrating security vulnerabilities or showcasing technical capabilities, it now aims to compromise the integrity of computer systems and other electronic devices. Therefore, protecting computer systems and data from accidental or malicious damage, alteration, or leakage, and reducing the chances of computer virus infections are key research areas in the field of cybersecurity today.
[0003] Currently, the mainstream antivirus method uses previously generated signature databases for signature-based antivirus scanning. The effectiveness of this signature-based malware detection largely depends on the available signature database; a larger database generally results in higher detection accuracy. A signature is a short byte string, unique for each known malware type, thus offering a high detection rate for malware and its derivatives. However, this technology has two major problems: First, these signatures are derived from manual analysis, which allows for errors. Furthermore, the daily growth rate of malware is enormous. Manually analyzing such a large number of new malware types would be extremely time-consuming. Moreover, after obtaining new signatures, the database needs to be updated and deployed to all clients using that database. Second, signature-based detection cannot detect polymorphic, mutated, or unknown malware; it can only detect malware whose signatures already exist in the database. This is currently the biggest limitation of signature-based malware detection.
[0004] Currently, behavior-based malware detection is mainly divided into two methods: static analysis detection and dynamic analysis detection. Static analysis obtains software behavior information through code analysis, but it still cannot effectively counter sophisticated code obfuscation techniques. Dynamic analysis, on the other hand, captures and analyzes the behavior of the actual running software, effectively countering code obfuscation techniques and more realistically reflecting the software's intent. No matter how well disguised, behavior will always reveal the malware's intent. Malware needs to call existing system APIs to achieve its intent. Therefore, Windows API calls are one of the software behaviors worth analyzing. Thus, this study analyzes the Windows API call behavior of software in the Windows operating system to achieve malware detection. This involves collecting a large number of malware and non-malware samples, monitoring their Windows API calls, and combining text classification and pattern mining techniques for analysis. This aims to compensate for the shortcomings of signature-based and static analysis-based malware detection. Summary of the Invention
[0005] To address the shortcomings of existing technologies, this invention proposes an interpretable malware detection method based on API sequence prototypes. By mining API sequence prototypes through sequence mining and clustering algorithms and inputting them into an LSTM-attention network model, a high classification accuracy can be achieved, and the classification results can be interpreted.
[0006] To achieve the above objectives, this invention provides an interpretable malware detection method based on API sequence prototypes, comprising the following steps:
[0007] Given a labeled training set of software samples, collect the API sequences of each software during its execution process in the training set of software samples to obtain an API sequence set, and mine the API sequence pattern set from the API sequence set;
[0008] Cluster the API sequence pattern set to obtain several API sequence pattern clusters, and use the center of each API sequence pattern cluster as the API sequence prototype of the API sequence pattern cluster.
[0009] Each API sequence in the API sequence set is converted into a prototype sequence using API sequence prototypes. The prototype sequences and their labels are then input into an LSTM network with an attention mechanism for training to obtain a malware classification model.
[0010] Real-time software is detected using a malware classification model. If the malware classification model classifies the real-time software as malicious, then the API sequence prototypes with the highest attention weights are taken as the reason for the judgment of malware. The attention weights are taken from the malware classification model.
[0011] Furthermore, the N-Gram algorithm is used to mine continuous segments of length N and occurrence frequency greater than σ from the API sequence set as API sequence patterns, forming an API sequence pattern set.
[0012] This invention employs the N-Gram algorithm to mine API sequence pattern sets from API sequence sets, ensuring that crucial information regarding API call order is not lost. Furthermore, it effectively mines API sequence patterns. For example, if malware combines CopyFileA, RegOpenKeyExA, and RegSetValueExA to perform a malicious operation, API sequence pattern clustering and prototype construction gather all API sequence patterns with similar functions, selecting the cluster center API sequence pattern as the API sequence prototype to eliminate the interference of interfering APIs inserted between API sequence patterns.
[0013] Furthermore, the step of clustering the API sequence pattern set to obtain several API sequence pattern clusters, and using the center of each API sequence pattern cluster as the API sequence prototype of the API sequence pattern cluster, includes:
[0014] A clustering algorithm was used to cluster the API sequence pattern set, resulting in K API sequence pattern clusters.
[0015] For each API sequence pattern cluster, calculate the average distance between each API sequence pattern in the cluster and all other API sequence patterns, and take the API sequence pattern with the smallest average distance as the API sequence prototype of that API sequence pattern cluster.
[0016] Furthermore, the step of converting each API sequence in the API sequence set into a prototype sequence using API sequence prototypes includes:
[0017] Each API sequence in the API sequence set is divided into multiple consecutive segments;
[0018] For each consecutive segment corresponding to an API sequence, calculate the distance between the consecutive segment and all API sequence prototypes in turn to obtain the minimum distance and the API sequence prototype corresponding to the minimum distance. If the minimum distance is less than a specified threshold λ, replace the current consecutive segment with the API sequence prototype with the smallest distance to the current consecutive segment; otherwise, discard the consecutive segment.
[0019] The prototype sequence of the API sequence is obtained by replacing or discarding the consecutive segments corresponding to the API sequence.
[0020] Convert each API sequence in the API sequence set into a prototype sequence.
[0021] The prototype sequence of this invention preserves the API call order and discards a large number of redundant APIs, thereby improving the detection efficiency of the model without sacrificing the accuracy of the detection method. Furthermore, the clustering prototype and attention mechanism of the API sequence pattern can be used to interpret the detection results.
[0022] Furthermore, the N-Gram algorithm is used to segment each API sequence in the API sequence set into multiple consecutive segments.
[0023] Furthermore, the step of inputting the prototype sequence into the LSTM network with the fused attention mechanism includes:
[0024] A graph embedding algorithm is used to obtain the representation vector of each API sequence prototype;
[0025] Replace the corresponding API sequence prototype with the representation vector of each API sequence prototype to obtain the vector representation sequence corresponding to the prototype sequence;
[0026] The input layer of an LSTM network with an incorporating attention mechanism includes an embedding layer;
[0027] The prototype sequence is input into the input layer of the LSTM network with the fusion attention mechanism, and the vector representation sequence is used as the initialization parameter of the embedding layer.
[0028] Using the processed vector representation sequence as the initialization parameters of the embedding layer can improve the accuracy of the model.
[0029] Furthermore, the method of using graph embedding algorithm to obtain the representation vector of each API sequence prototype includes:
[0030] Construct a prototype association graph G = (V, E, A) based on the associations between API sequence prototypes, where V is a node set, and each node v in the node set V is a prototype association graph. i Represents an API sequence prototype; A is the weight set, and two nodes v in the node set V. i and v j The weight between them is w ij E is the edge set, and V is the set of nodes where v represents two nodes v. i and v j The weights w between ij If the difference is greater than a specified threshold δ, then there exists an edge ei between them. j ;
[0031] The prototype association graph G is processed using a graph embedding algorithm to obtain each node v in the node set V. i A representation vector g in m dimensions i .
[0032] This invention employs a graph embedding algorithm to learn the hidden information between two nodes connected by an edge, and can represent nodes in a graph as a vector representation containing potential information, thereby mining the semantic information between sequence prototypes.
[0033] Furthermore, the graph embedding algorithm is either DeepWalk or node2vec.
[0034] Compared with existing technologies, the significant advantages of this invention are: 1. It employs a deep learning model and attention mechanism, achieving interpretability of classification results while ensuring model classification accuracy. 2. It uses API sequence prototypes to model software behavior, which better abstracts software behavior and aids in understanding compared to a single API. Attached Figure Description
[0035] Figure 1 This is a flowchart of an interpretable malware detection method based on API sequence prototypes according to the present invention;
[0036] Figure 2 This is a flowchart of the API sequence pattern mining process of the present invention;
[0037] Figure 3 This is the network structure of the malware classification model of the present invention;
[0038] Figure 4 This is an example to explain the malware detection results of this invention. Detailed Implementation
[0039] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0040] Reference Figure 1 An interpretable malware detection method based on API sequence prototypes includes the following steps:
[0041] (1) API sequence pattern mining: Refer to Figure 2 The N-Gram algorithm is used to mine API sequence pattern sets from the API sequence set.
[0042] (1-1) API sequence set acquisition: Given a software set SS, for each software s in it k A sandbox simulation was used to obtain s k API sequence during runtime k The API sequences of all software in SS form the API Sequence Set (ASS).
[0043] (1-2) API Sequence Pattern Mining: Set the API sequence pattern support threshold σ, and use the N-Gram algorithm to mine continuous segments with length N and occurrence frequency greater than σ from ASS as API sequence patterns, forming the API sequence pattern set APS.
[0044] (2) Construction of API sequence prototype set: Cluster the API sequence pattern set and take the center of each cluster as the API sequence prototype of the API sequence pattern cluster. Finally, the graph embedding algorithm is used to obtain the vector representation of each API sequence prototype.
[0045] (2-1) API Sequence Pattern Distance Calculation: Treating an API as a character and an API sequence pattern as a string, the edit distance algorithm is used to calculate the distance between any two API sequence patterns. Let the API sequence pattern p... x and p y The distance between them is d(p) x ,p y ).
[0046] (2-2) API sequence pattern clustering: The API sequence pattern set APS is clustered using a clustering algorithm to obtain K API sequence pattern clusters, denoted as ACS.
[0047] (2-3) API sequence prototype construction: Clustering C for each API sequence pattern in ACS l Calculate C l The average distance d between each API sequence pattern and all other API sequence patterns is used, and the API sequence pattern with the smallest average distance is taken as C. l The API sequence prototype, denoted as r l .
[0048] (2-4) API Sequence Prototype Embedding Representation: First, a prototype association graph G = (V, E, A) is constructed based on the associations between API sequence prototypes. V is a set of nodes, where each node v i Represents an API sequence prototype; A is the weight set, with two nodes v i and v j The weight between them is w ij E is the edge set, with two nodes v i and v j The weights w between ij If the difference is greater than a specified threshold δ, then there exists an edge e between them. ij Two nodes v i and v j The weights w between ijIf the edges are less than or equal to a specified threshold δ, then there is no edge between them. Then, a graph embedding algorithm (such as DeepWalk or node2vec) is used to process G to obtain each node v. i An m-dimensional representation vector g of (i.e., each API sequence prototype) i .
[0049] Replace the corresponding API sequence prototype with the representation vector of each API sequence prototype to obtain the vector representation sequence corresponding to the prototype sequence.
[0050] (3) Malware classification model construction: Design an LSTM network with an attention mechanism and train it to obtain a malware classification model.
[0051] (3-1) Prototype Sequence Transformation: Given a software s k The generated API sequence as k First, the N-Gram algorithm is used to divide as k Divide into multiple consecutive segments; then, for each consecutive segment, ass n The edit distance algorithm is used to calculate the ass. n The minimum distance min_d is obtained by calculating the distance to all API sequence prototypes. n and the corresponding API sequence prototype min_r n If min_d n If it is less than the specified threshold λ, then ass n Replace with min_r n Otherwise discard the ass n Finally, the API sequence will be... k Convert to prototype sequence rs k .
[0052] (3-2) Construction of an LSTM network incorporating an attention mechanism: Design an LSTM network incorporating an attention mechanism, with the network structure as follows: Figure 3 As shown, it includes an input layer, a recurrent layer, an attention layer, and an output layer, which are explained in detail below:
[0053] Input layer: According to step (3-1), input software s k From the prototype sequence rs k This indicates that rs is retained. k If the first L API sequence prototypes are less than L, then zeros are added to the end of the prototype sequence. According to steps (2-4), each API sequence prototype is represented as an m-dimensional representation vector. Therefore, each input software can be represented as an L×m-dimensional matrix IM. k .
[0054] Recurrent layer: LSTM is used for IM k Processing, IMk m-dimensional representation vector of each API sequence prototype in If an LSTM unit is input sequentially, L hidden vectors are obtained according to formula (1).
[0055]
[0056] in, Let t be the latent vector in the representation vector of the API sequence prototype corresponding to the k-th software. Let represent the t-th representation vector in the representation vector of the API sequence prototype corresponding to the k-th software. This represents the (t-1)th latent vector in the representation vector of the API sequence prototype corresponding to the k-th software.
[0057] Attention layer: First, calculate each hidden vector according to formula (2). attention weights Then, according to formula (3), a weighted average is taken of all latent vectors to obtain the software s. k The representation vector z k .
[0058]
[0059]
[0060] in, Representing implicit vectors The corresponding attention weights, q and b are trainable parameter vectors, W is a trainable parameter matrix, T represents the transpose matrix, and z k Indicates the k-th software s k The representation vector.
[0061] Output layer: Input z into a softmax layer to obtain the probability distribution of the classification result.
[0062] (3-3) Malware Classification Model Training: First, a large number of software samples are collected to form a training set. For each software sample in the training set... k s obtained using a sandbox k The API sequence during operation, and obtain each software sample s through steps (1-1) to (3-1). k The corresponding prototype sequence rs k All prototype sequences rs in the sample training set k An LSTM network with an input-fusion attention mechanism is trained to obtain a malware classification model, whose function is to classify malware based on input software. k The corresponding prototype sequence rs k Output sk The type (normal software or a certain type of malware).
[0063] (4) Interpretation of malware classification results: The attention weights are reverse-analyzed, and the contribution of each API sequence prototype to the classification results is calculated as an interpretation.
[0064] (4-1) Malware Classification: Given a piece of software s g First, s g Convert to prototype sequence rs g Then rs g Input the trained malware classification model to obtain the classification results.
[0065] (4-2) Interpretation of classification results: If the software s g If it is malware, then it is determined based on attention weight. The system measures the contribution of each API sequence prototype to the classification result and selects the API sequence prototypes with the highest attention weights as explanations for the malware classification. Furthermore, it allows visualization of malware samples, using the intensity of each API sequence prototype's color to determine its contribution to the detection results. Figure 4 A visualization example explaining the test results is presented.
[0066] The embodiments described above are merely illustrative of one or more implementations of the present invention, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these all fall within the scope of protection of the present invention. Therefore, the scope of protection of this invention should be determined by the appended claims.
Claims
1. A method for detecting interpretable malware based on API sequence prototypes, characterized in that, The interpretable malware detection method based on API sequence prototypes includes the following steps: Given a labeled training set of software samples, collect the API sequences of each software during its execution process in the training set of software samples to obtain an API sequence set, and mine the API sequence pattern set from the API sequence set; Cluster the API sequence pattern set to obtain several API sequence pattern clusters, and use the center of each API sequence pattern cluster as the API sequence prototype of the API sequence pattern cluster. Each API sequence in the API sequence set is converted into a prototype sequence using API sequence prototypes. The prototype sequences and their labels are then input into an LSTM network with an attention mechanism to train a malware classification model. Real-time software is detected using a malware classification model. If the malware classification model classifies the real-time software as malicious, then the API sequence prototypes with the highest attention weights are taken as the reason for the judgment of malware. The attention weights are taken from the malware classification model. in, The step of converting each API sequence in the API sequence set into a prototype sequence using API sequence prototypes includes: Each API sequence in the API sequence set is divided into multiple consecutive segments; For a consecutive segment corresponding to an API sequence, calculate the distance between the consecutive segment and all API sequence prototypes in turn, obtain the minimum distance and the API sequence prototype corresponding to the minimum distance; if the minimum distance is less than a specified threshold... λ If the current continuous segment is replaced with the API sequence prototype that is closest to the current continuous segment, then the continuous segment is discarded. The prototype sequence of each API sequence is obtained by replacing or discarding the consecutive segments corresponding to each API sequence in the API sequence set.
2. The method for detecting interpretable malware based on API sequence prototypes according to claim 1, characterized in that, The N-Gram algorithm is used to mine sequences of length from the API sequence set. N The number of occurrences is greater than σ The continuous segments are used as API sequence patterns to form an API sequence pattern set.
3. The method for detecting interpretable malware based on API sequence prototypes according to claim 1, characterized in that, The process of clustering the API sequence pattern set to obtain several API sequence pattern clusters, and using the center of each API sequence pattern cluster as the API sequence prototype of the cluster, includes: Clustering algorithms are used to cluster the API sequence pattern set to obtain... K API sequence pattern clustering; For each API sequence pattern cluster, calculate the average distance between each API sequence pattern in the cluster and all other API sequence patterns, and take the API sequence pattern with the smallest average distance as the API sequence prototype of that API sequence pattern cluster.
4. The method for detecting interpretable malware based on API sequence prototypes according to claim 1, characterized in that, The N-Gram algorithm is used to divide each API sequence in the API sequence set into multiple consecutive segments.
5. The method for detecting interpretable malware based on API sequence prototypes according to claim 1, characterized in that, The step of inputting the prototype sequence and its label into an LSTM network with a fusion attention mechanism includes: A graph embedding algorithm is used to obtain the representation vector of each API sequence prototype; Replace the corresponding API sequence prototype with the representation vector of each API sequence prototype to obtain the vector representation sequence corresponding to the prototype sequence; The input layer of an LSTM network with an incorporating attention mechanism includes an embedding layer; The prototype sequence is input into the input layer of the LSTM network with the fusion attention mechanism, and the vector representation sequence is used as the initialization parameter of the embedding layer.
6. The method for detecting interpretable malware based on API sequence prototypes according to claim 5, characterized in that, The graph embedding algorithm is used to obtain the representation vector of each API sequence prototype, including: Construct a prototype association graph based on the associations between API sequence prototypes. G = ( V , E , A ),in, V For a set of nodes, node set V Each node in v i Represents a prototype of an API sequence; A For weight set, node set V Two nodes in v i and v j The weights between them are w ij ; E For edge set, node set V Two nodes in v i and v j Weights between w ij Greater than the specified threshold δ Then there is an edge between them. e ij ; Using graph embedding algorithms to analyze prototype association graphs G Processing is performed to obtain a node set. V Each node in v i One m The representation vector g of dimension i .
7. The method for detecting interpretable malware based on API sequence prototypes according to claim 5, characterized in that, The graph embedding algorithm mentioned is either DeepWalk or node2vec.
Citation Information
Patent Citations
Analyzable automatic Android malware detection based on graph embedding
CN113360906A
Small sample malicious software classification method and system based on prototype network
CN115221519A
