A method, device and readable storage medium for homology analysis of malicious code
Through sliding windows and feature extraction models, the problem of inconsistent input lengths in malicious code homologous analysis is solved, and efficient malicious code homologous analysis is realized, which is suitable for malicious code of different lengths to prevent code obfuscation and interference.
Patent Information
- Application Number
- CN202110825704.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-21
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2041-07-21
AI Technical Summary
Most of the existing malicious code homologous analysis methods are dynamic methods, which are inefficient and require an independent operating environment, and cannot effectively deal with the problem of inconsistent input lengths of malicious code of different lengths.
By obtaining malicious code samples, disassembly and setting a sliding window, using feature extraction models to extract semantic features, training and adjusting model parameters, we realize homologous analysis of malicious codes of different lengths.
It solves the problem of inconsistent input lengths, improves the efficiency and accuracy of homologous malicious code analysis, and can be applied to malicious code of different lengths to prevent code obfuscation and interference.
Smart Images

Figure CN113935032B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information security, and in particular to a method, device and readable storage medium for homology analysis of malicious codes. Background Art
[0002] Malicious code homology analysis is to analyze the correlation between malicious codes through the internal and external characteristics of malicious codes, as well as the laws of generation and propagation. There are many types of malicious codes, including computer viruses, worms, Trojans, backdoor programs, logic bombs, etc. Each type of malicious code often has similarities in the following aspects: (1) Functional code. In order to achieve the same malicious function, the key code fragments may be similar. These similar code fragments are also called genetic codes. For example, Duqu and Stuxnet have highly similar key functional codes such as DLL injection and RPC service. (2) System function calls. The operation of malicious behavior usually depends on the call of operating system functions. The function name, frequency, sequence, etc. of the call may be similar. (3) Functional behavior. Each type of malicious code has targeted destructive behavior. For example, ransomware can read and write user data, and remote control Trojans can view the screen or camera. The similarity of functional behavior is reflected in files, processes, networks, and registry.
[0003] Most of the existing homology analysis research belongs to dynamic methods, which conduct similarity analysis based on function calls, behavior fragments, etc. in the running state of malicious code. Dynamic methods require an independent running environment and are less efficient. Summary of the invention
[0004] The embodiments of the present invention provide a method, device and readable storage medium for homology analysis of malicious codes, which can be applied to homology analysis of malicious codes of different lengths and solve the problem of inconsistent input lengths caused by different numbers of instructions in the code in the prior art.
[0005] In a first aspect, an embodiment of the present invention provides a method for homology analysis of malicious code, comprising: obtaining a malicious code sample, wherein the malicious code sample includes different types of malicious code; disassembling the malicious code sample to determine a corresponding assembly instruction sequence, wherein the assembly instruction sequence includes a plurality of instructions, and the lengths of the plurality of instructions may be different; setting a sliding window to sequentially slide subsequences in the assembly instruction sequence, wherein each subsequence includes at least three instructions; for the subsequences in each sliding window: based on vectors corresponding to the preceding instruction and the succeeding instruction of the subsequence and the vector corresponding to the malicious code sample, inputting a feature extraction model for prediction; adjusting the vector corresponding to the malicious code sample based on the probability of other instructions in the subsequence output by the feature extraction model, and adjusting the parameters of the feature extraction model; using the trained feature extraction model to extract semantic features of unknown malicious code data to perform homology analysis of the malicious code.
[0006] In a second aspect, an embodiment of the present invention provides a method for homology analysis of malicious code, comprising: obtaining unknown malicious code; extracting semantic features of the unknown malicious code using a feature extraction model trained by the homology analysis method; and classifying the semantic features to achieve homology analysis of the unknown malicious code.
[0007] In a third aspect, an embodiment of the present invention provides a malicious code homology analysis device, comprising a processor, a memory and a communication bus; the communication bus is used to realize the connection and communication between the processor and the memory; the processor is used to execute one or more computer programs stored in the memory to implement the steps of the aforementioned malicious code homology analysis method.
[0008] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, and the computer program implements the steps of the aforementioned method when executed by a processor.
[0009] The feature extraction model proposed in the embodiment of the present invention can be applied to homology analysis of malicious codes of different lengths after training, thereby solving the problem of inconsistent input length caused by different numbers of instructions in the code in the prior art.
[0010] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0012] Figure 1 This is a basic flow chart of an embodiment of the present invention;
[0013] Figure 2 It is a schematic diagram of the overall process of an embodiment of the present invention. DETAILED DESCRIPTION
[0014] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0015] It should be understood that various modifications may be made to the embodiments of the present application. Therefore, the above description should not be considered as limiting, but only as an example of an embodiment. Other modifications within the scope and spirit of the present disclosure will occur to those skilled in the art.
[0016] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments of the present disclosure and, together with the general description of the present disclosure given above and the detailed description of the embodiments given below, serve to explain the principles of the present disclosure.
[0017] These and other characteristics of the present disclosure will become apparent from the following description of a preferred form of embodiment given as a non-limiting example, with reference to the attached drawings.
[0018] It should also be understood that, although the present disclosure has been described with reference to some specific examples, those skilled in the art will be able to realize many other equivalent forms of the present disclosure that have the features of the claims and are therefore within the scope of protection defined thereby.
[0019] The above and other aspects, features and advantages of the present disclosure will become more apparent from the following detailed description when taken in conjunction with the accompanying drawings.
[0020] Specific embodiments of the present disclosure are described hereinafter with reference to the accompanying drawings; however, it should be understood that the embodiments claimed are merely examples of the present disclosure, which may be implemented in a variety of ways. Well-known and / or repeated functions and structures are not described in detail to avoid obscuring the present disclosure with unnecessary or redundant details. Therefore, the specific structural and functional details claimed herein are not intended to be limiting, but merely serve as a basis and representative basis for the claims to teach those skilled in the art to use the present disclosure in a variety of ways with substantially any suitable detailed structure.
[0021] This specification may use the phrases "in one embodiment," "in another embodiment," "in a further embodiment," or "in other embodiments," all of which may refer to one or more of the same or different embodiments according to the present disclosure.
[0022] Based on the semantic mapping relationship between the dynamic and static API sequences of malicious code, the malicious code samples are converted into API-based feature vectors, and the machine learning classifier is trained based on the obtained feature vectors to achieve malicious code detection. However, dynamic API extraction requires a specific operating environment and is complex to implement.
[0023] Based on this, an embodiment of the present invention provides a method for analyzing the homology of malicious code, such as Figure 1 As shown, the following steps are included:
[0024] S101, obtaining malicious code samples, wherein the malicious code samples include different types of malicious code. Specifically, sufficient number of malicious code samples can be collected from public malicious code libraries, such as VirusTotal, vxheaven, etc., according to the seven common malicious code types (Trojan horse, worm, virus, backdoor, rootkit, zombie program and adware) as a data set.
[0025] S102: Disassemble the malicious code sample to determine a corresponding assembly instruction sequence, wherein the assembly instruction sequence includes a plurality of instructions, and the lengths of the plurality of instructions may be different, such as Figure 2 As shown, the malicious code sample can be reverse assembled, thereby obtaining the assembly instruction sequence Seq. Seq is first represented as a vector V p , that is, V p is a semantic feature vector that represents the semantic features of Seq. Seq consists of multiple instructions, Seq = {S q,q∈[0,l]}, where l is the length of the instruction sequence (i.e., Seq) in the sample.
[0026] S103, setting a sliding window to sequentially slide subsequences in the assembly instruction sequence, each subsequence including at least three instructions. Figure 2 As shown, the instruction {S9,S10 ,S 11} is used as an example to illustrate.
[0027] is the subsequence in each sliding window:
[0028] S104: Based on the vectors corresponding to the preceding instruction and the succeeding instruction of the subsequence and the vector corresponding to the malicious code sample, input the vectors into a feature extraction model for prediction.
[0029] In order to make the final semantic features contain the semantic information of the instruction sequence and the sequential relationship between instructions, such as Figure 2 The sliding window shown sets a sliding window on the assembly instruction sequence Seq, and the step size can be set according to actual needs, for example, the step size can be set to 1. For example, the instruction {S9,S 10 ,S 11}, {S9,S 10 ,S 11} is represented by vector Vec(S9), Vec(S 10 ), Vec(S 11 ). Then input the feature extraction model for prediction. The feature extraction model can use a recurrent neural network (RNN), a dense neural network (DNN) or other neural network structures such as KNN, SVM, or a combination of different network structures as the hidden layer. Each slide is based on the subsequence {S q-1 ,S q ,S q+1} to perform prediction tasks. At the same time, the overall code semantic features of the sample are V p , randomly initialize V p . S can be calculated q-1 ,S q+1 The average vector of Vec(S9) and Vec(S 11 ) is the average vector, the average vector is V p The multiplied vector is input into the hidden layer. The prediction target is S q , by V p ,S q-1 ,S q+1 Prediction S q The probability can be expressed as P(S q |Seq,S q-1 ,S q+1 ).
[0030] S105. Adjust the vector corresponding to the malicious code sample based on the probabilities of other instructions in the subsequence output by the feature extraction model, and adjust the parameters of the feature extraction model.
[0031] Based on the above training process, the subsequence is used to train the semantic model. During the training, the parameters of the average pooling layer, the hidden layer, and V p is adjusted to minimize the cross entropy loss of the predicted probabilities.
[0032] After the subsequences in each sliding window are trained, the trained feature extraction model can be used to extract semantic features of unknown malicious code data in step S106 to perform homology analysis of the malicious code. p Optimized for V p ′, at this time V p ′ contains context information and sequential relationships as the code semantic features of the training sample. After training on the entire data set, the parameters of the average pooling layer and hidden layer are fixed as a semantic model to extract the code semantic features of each sample. Finally, the extracted code semantic features can be classified or clustered to achieve homology analysis of malicious code.
[0033] The feature extraction model proposed in the embodiment of the present invention can include the semantic information of the instruction sequence and the order relationship between instructions after training is completed, because a sliding window is set in the training process for continuous sliding. Therefore, the feature extraction model obtained by training can be applied to the homology analysis of malicious codes of different lengths, solving the problem of inconsistent input length caused by different numbers of instructions in the code in the prior art.
[0034] In some embodiments, for each instruction in the assembly instruction sequence:
[0035] Tokenize the operator and operand of the instruction according to the corpus;
[0036] The operator and operand after identification are connected as the vector corresponding to the instruction.
[0037] For example, Seq is composed of multiple instructions, Seq = {S q,q∈[0,l]}, where l is the length of the instruction sequence (i.e., Seq) in the sample. Each instruction S q Also includes the operator op q and operand on q . Thus, op can be q and on q Marked as OP q and ON q , connect to OP qand ON q As S q For example, we can get Vec(S9)-Vec(S 11 ).
[0038] In some embodiments, adjusting the vector corresponding to the malicious code sample and adjusting the parameters of the feature extraction model are based on the reverse gradient information of the output data of the feature extraction model. For example, in training, the parameters of the average pooling layer, the hidden layer and V p The vector V is adjusted based on the reverse gradient information to minimize the cross entropy loss of the predicted probability. p Optimized for V p ′, at this time V p ′ contains context information and sequential relations as the code semantic features of the sample.
[0039] In some embodiments, the method further includes: extracting semantic features of the malicious code samples using a trained feature extraction model; and classifying the malicious code samples based on the extracted semantic features to determine semantic feature categories of several malicious code samples.
[0040] Specifically, after training on the entire data set, the parameters of the average pooling layer and the hidden layer can be fixed as a semantic model to extract the code semantic features of each sample. Then, the code semantic features of the malicious code samples are clustered. Since the malicious code samples contain different types of malicious codes such as Trojan horses, worms, viruses, backdoors, rootkits, zombie programs, and adware, the code semantic features can be clustered in this example, so that the malicious code samples can be used as a reference for homology analysis.
[0041] In some implementations, classifying based on the extracted semantic features of the malicious code samples may include: clustering the semantic features of the malicious code samples using a clustering algorithm; or classifying the semantic features of the malicious code samples using a classification algorithm.
[0042] Specifically, a clustering algorithm or a classification algorithm can be used to classify semantic features. By using a clustering algorithm, the data set is clustered to obtain malicious code groups. Malicious codes in the same group are considered to have homology. The seven types of malicious code listed in the above steps (Trojan horses, worms, viruses, backdoors, rootkits, zombie programs, and adware) can be used as references. Since each type includes many different families, the number of groups obtained by actual clustering is often large. Clustering algorithms can be selected from DBScan, KMeans, KNN, etc. DBScan is used as an example for explanation below.
[0043] The minimum number of cluster samples MinPts is set to k, where k is determined based on the actual data size. According to step (1), the semantic features of all malicious code samples are extracted, and the k-dist values of all samples are calculated based on the semantic features, and then sorted in ascending order. The gradient of the sequence at each k-dist value is calculated, and the k-dist value with the largest gradient is used as the radius Eps of the cluster. For each sample Search for density-reachable samples: If the sample If the number of samples that can reach the density is greater than k, then As a cluster center, the samples whose density can be reached are located in the cluster; otherwise, Search for cluster centers among samples with reachable density until all samples are in the cluster. At this point, the clustering group of malicious code is obtained.
[0044] The K-dist value refers to the distance between a sample's kth nearest neighbor and the sample.
[0045] Density reachable: For two samples a and b, if a is within the cluster radius of b (a∈Eps(b)) and |Eps(b)|≥MinPts, then a and b are directly density reachable a→b. If there is a data link between two samples a and d, a→b→…→d, then a and d are density reachable.
[0046] You can also use a classification algorithm to label the samples in the data set according to the type, divide them into training sets and test sets according to the proportion, select a classification algorithm, such as SVM, LightGBM, GBDT, neural network, etc., use the training set to train the classification model, and the test set can be used for cross-validation.
[0047] In a second aspect, an embodiment of the present invention provides a method for homology analysis of malicious code, comprising: obtaining unknown malicious code; extracting semantic features of the unknown malicious code using a feature extraction model trained by the homology analysis method; and classifying the semantic features to achieve homology analysis of the unknown malicious code.
[0048] In practical applications, homology analysis is performed on unknown malicious code datasets, which can be data from any source such as the Internet, emails, and public libraries. Unknown malicious code can be obtained; the feature extraction model trained by the homology analysis method is used to extract the semantic features of the unknown malicious code; and the semantic features are classified. The specific model prediction and classification methods are described above and will not be repeated here.
[0049] The method disclosed in the present invention extracts code features based on the proposed semantic model, which includes the semantics of the context and the order relationship, can prevent the interference of code obfuscation, and can convert variable-length instruction sequences into fixed-length semantic features, solving the problem of inconsistent input length caused by the different number of instructions in the code.
[0050] In the third aspect, an embodiment of the present invention also provides a malicious code homology analysis device, including a processor, a memory and a communication bus; the communication bus is used to realize the connection and communication between the processor and the memory; the processor is used to execute one or more computer programs stored in the memory to implement the steps of the aforementioned malicious code homology analysis method.
[0051] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the aforementioned method are implemented.
[0052] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0053] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0054] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), including a number of instructions for a terminal (which can be a mobile phone, computer, server or network equipment, etc.) to execute the methods described in each embodiment of the present invention.
[0055] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.
Claims
1. A method for homology analysis of malicious code, characterized in that: include: Obtaining malicious code samples, wherein the malicious code samples include different types of malicious codes; Disassembling the malicious code sample to determine a corresponding assembly instruction sequence, where the assembly instruction sequence includes a plurality of instructions, and the lengths of the plurality of instructions may be different; Setting a sliding window to sequentially slide subsequences in the assembly instruction sequence, each subsequence including at least three instructions; is the subsequence in each sliding window: Based on the vectors corresponding to the preceding and succeeding instructions of the subsequence and the vector corresponding to the malicious code sample, inputting the vectors into a feature extraction model for prediction; Adjusting the vector corresponding to the malicious code sample based on the probabilities of other instructions in the subsequence output by the feature extraction model, and adjusting the parameters of the feature extraction model; Use the trained feature extraction model to extract semantic features of unknown malicious code data to perform homology analysis of the malicious code. Also includes: Using the trained feature extraction model to extract semantic features of the malicious code sample; Classifying the extracted malicious code samples based on their semantic features to determine semantic feature categories of a plurality of malicious code samples; Also includes: For each instruction in the assembly instruction sequence: Tokenize the operator and operand of the instruction according to the corpus; The operators and operands after the tokenization are connected as the vector corresponding to the instruction.
2. The malicious code homology analysis method according to claim 1, wherein: The feature extraction model adopts at least one of the following networks: RNN, DNN, KNN, SVM.
3. The malicious code homology analysis method according to claim 1, wherein: The vector corresponding to the malicious code sample is obtained by expressing the assembly instruction sequence in the form of a vector.
4. The malicious code homology analysis method according to claim 1, wherein: Adjusting the vector corresponding to the malicious code sample and adjusting the parameters of the feature extraction model are based on reverse gradient information of output data of the feature extraction model.
5. The malicious code homology analysis method according to claim 1, wherein: Classification based on the extracted semantic features of the malicious code sample includes: Clustering the semantic features of the malicious code samples using a clustering algorithm; or The semantic features of the malicious code samples are classified using a classification algorithm.
6. A malicious code homology analysis method, characterized in that: include: Obtain unknown malicious code; Extracting semantic features of the unknown malicious code using a feature extraction model trained using the homology analysis method according to any one of claims 1 to 5; The semantic features are classified to achieve homology analysis of the unknown malicious code.
7. A malicious code homology analysis device, characterized in that: including a processor, a memory and a communication bus; The communication bus is used to realize the connection and communication between the processor and the memory; The processor is configured to execute one or more computer programs stored in the memory to implement the steps of the malicious code homology analysis method according to any one of claims 1 to 6.
8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the malicious code homology analysis method according to any one of claims 1 to 6.
