Code semantic image-based Internet of Things virus variant family classification method
By extracting and constructing code semantic images, and using convolutional neural networks to classify IoT virus families, it solves the problem of low classification accuracy caused by existing methods that ignore code semantic features, and achieves accurate determination of IoT virus variant families.
Patent Information
- Application Number
- CN202410855363.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-10-01
AI Technical Summary
Existing IoT virus family classification methods ignore code semantic features, resulting in low classification accuracy. Attackers can avoid detection by changing file structure features.
By disassembling IoT virus samples, extracting key opcode streams, constructing N-gram semantic features, converting them into opcode sequence vectors, and converting them into code semantic images, using convolutional neural networks for image classification to determine virus variant families category.
It improves the ability to accurately determine IoT virus variant families and solves the problem of low classification accuracy caused by existing methods that ignore code semantic features.
Smart Images

Figure CN118736306A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of cyberspace security technology, and in particular to a method for classifying Internet of Things virus variant families based on code semantic images. Background Art
[0002] As the scale of IoT devices continues to expand, the targets of viruses have shifted from traditional computers to IoT device platforms, triggering the widespread spread of a large number of IoT viruses and their family variants. At the same time, most of the newly emerged IoT virus samples are variants of existing viruses. They often come from the same virus family and have highly similar code structures and features. Correct family classification of IoT viruses is helpful for studying the evolution trend of virus families, and is also conducive to discovering new IoT viruses and tracing their origins.
[0003] Therefore, the family classification of IoT viruses has attracted widespread attention from academia and industry. At present, the commonly used virus family classification methods can be divided into static analysis and dynamic analysis. Static analysis mainly analyzes the execution logic and semantics of malicious code by extracting information such as opcodes, API call graphs, and function calls, and performs detailed and fine-grained analysis of the structure and content of the code, so as to effectively classify the malicious code into families. Dynamic analysis requires executing malware samples in a virtual environment, and then collecting and analyzing behavioral information such as function calls, file operations, and registry modification records to determine the family category of the virus. Since dynamic analysis observes the actual behavior of malicious code, it can more effectively identify and classify obfuscated and encrypted malicious code. However, considering the time and resources required for dynamic analysis, static analysis is more conducive to analyzing the exponentially growing number of IoT virus samples and their variants.
[0004] At the same time, with the rapid development of deep learning and image processing technology in recent years, a static family analysis method that converts virus files into visual images has emerged. Compared with traditional static and dynamic methods, this method has the advantages of being simple and easy to implement, low computational complexity, and high classification accuracy. However, the visualization scheme currently proposed is to convert the entire PE format binary malicious code file into an image, and the feature information contained in the image mainly lies in the overall structure of the file. The code segment image only occupies a very small part of the entire malicious code image and is a compiled "black box feature", which causes the specific semantic information contained in the code segment to be ignored. This defect will cause malicious codes with similar file structures to be mistakenly classified into the same family category, but in fact they do not belong to the same family. Malicious code makers may also deliberately change their own file structure features to avoid detection. Therefore, it is not enough to perform family analysis on IoT viruses based solely on file binary images. Summary of the invention
[0005] In order to solve the above technical problems, the present invention provides a method for classifying IoT virus variant families based on code semantic images, comprising the following steps:
[0006] S1. Disassemble IoT virus samples and extract key operation code streams;
[0007] S2, extract N-gram semantic features of key operation code stream;
[0008] S3, converting the operation code N-gram features into an operation code sequence vector;
[0009] S4, converting the operation code sequence vector into a code semantic image;
[0010] S5. Construct a convolutional neural network to perform image classification, and then determine the family category of the IoT virus variant. The classification result output by the convolutional neural network is the family category of the virus variant.
[0011] The technical solution further defined in the present invention is:
[0012] Furthermore, in step S1, the IoT virus sample in ELF format is disassembled to convert its code segment into assembly code and generate an assembly file; in the assembly file, ".text" or "CODE" is used to identify each line of code, the code structure includes an opcode and an operand, and only the opcode is used as a feature; after the opcode extraction operation is performed on the assembly code in the virus assembly file, an opcode stream is obtained.
[0013] As described above, in the method for classifying IoT virus variant families based on code semantic images, in step S1, the specific method for extracting the key operation code stream is as follows: according to the probability of occurrence of each operation code in the sample, m key operation codes are selected as analysis targets; for the set O consisting of all operation codes in the training set, the set element o i The probability calculation for is as follows:
[0014]
[0015] Among them, freq(o i |x i ) means that in sample x i Medium opcode o i Frequency of occurrence, sample x i belongs to the training set X.
[0016] As described above, in the method for classifying IoT virus variant families based on code semantic images, in step S2, a sliding window of size 2 is used to extract a series of 2-gram operation code sequences, each of which has a length of 2, and the frequency of occurrence of each sequence is counted.
[0017] As described above, in the method for classifying IoT virus variant families based on code semantic images, in step S3, the m selected key operation codes are used to construct m 2 opcode sequences of length 2, and then for each sequence os i Assign a weight w i , get an m 2 Dimensional opcode sequence vector:
[0018] V={(os1, w1), (os2, w2),..., (os n , W n )},n=m 2 .
[0019] As described above, in the method for classifying IoT virus variant families based on code semantic images, in step S3, the TF-GR algorithm is used to calculate the weight w i , that is, calculate the word frequency tf of the opcode sequence i And the product of information gain rate Gain-ratio:
[0020] w i =tf i ×GR(X,os i )
[0021] Among them, GR(X,os i ) represents the operation code sequence os i Information gain rate for malware training set X.
[0022] As described above, in the method for classifying IoT virus variant families based on code semantic images, in step S3, if there are k opcode sequences in the virus sample, each opcode sequence is i The frequency of occurrence is represented by , then the tf of each virus file i and GR(X,os i ) is calculated as follows:
[0023]
[0024] Among them, H(X) and H(os i ) represent the data set X and the operation code sequence os respectively. i The information entropy of i ) represents the data set X in the operation code sequence os i The conditional entropy under .
[0025] As described above, in the method for classifying IoT virus variant families based on code semantic images, in step S4, the weights in the opcode sequence vector are standardized so that their sizes fall within the pixel value range. The standardized processing formula is:
[0026]
[0027] Among them, max(w i ) represents the maximum value of all directional weights of the opcode sequence vector.
[0028] As described above, in a method for classifying IoT virus variant families based on code semantic images, in step S4, the image is regarded as a pixel matrix, and the screened m key operation codes are used as the horizontal axis and the vertical axis of the image, respectively, so as to construct a code semantic image matrix with a size of m*m; the two-dimensional coordinates of each pixel point in the matrix are represented as an operation code sequence with a length of 2, the operation code sequence vector is mapped into an image, and the sequence in each element of the vector is mapped to the position of a specific pixel point in the image matrix, and the weight corresponding to the sequence is represented as the pixel value of the point.
[0029] As described above, in a method for classifying IoT virus variant families based on code semantic images, in step S5, the convolutional neural network includes two convolutional layers with ReLU activation functions, the convolution kernel sizes are both 3*3, and the numbers are 16 and 32 respectively; a pooling layer is executed after each convolution layer for downsampling, and the pooling window is 2*2; and a Flat layer is used to convert multi-dimensional nodes into one-dimensional nodes as input of the fully connected layer D1, and the fully connected layer D1 uses 256 nodes.
[0030] The beneficial effects of the present invention are:
[0031] In the present invention, the existing visualization-based virus variant family classification technology is improved. The existing technical method mainly considers the global structural characteristics of the virus software file. The attacker can use obfuscation technology to hide the structural characteristics of the virus file, thereby achieving the effect of family judgment escape; the present invention proposes for the first time to construct the semantic characteristics of the code segment as a grayscale image, and use a convolutional neural network to classify the obtained image, which can solve the problem of low classification accuracy caused by ignoring the semantic characteristics of the code in the existing method, and realize accurate judgment of the IoT virus variant family. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 It is a schematic diagram of the overall process of the present invention;
[0033] Figure 2 This is a schematic diagram of some operation code flows of IoT virus samples in an embodiment of the present invention;
[0034] Figure 3Schematic diagram of a convolutional neural network in an embodiment of the present invention. DETAILED DESCRIPTION
[0035] This embodiment provides a method for classifying IoT virus variant families based on code semantic images. Figure 1 As shown, the following steps are included:
[0036] S1. Disassemble the IoT virus samples and extract the key operation code stream.
[0037] Disassemble the IoT virus sample in ELF format to convert its code segment into assembly code and generate an assembly file; in the assembly file, use ".text" or "CODE" to identify each line of code, and the code structure includes opcodes and operands; since the opcode part is invariant in the virus software deformation, only the opcode is used as a feature, and the operand is not concerned; after extracting the opcode from the assembly code in the virus assembly file, the opcode stream is obtained, such as Figure 2 shown.
[0038] There are a large number of rare opcodes in the opcode stream of IoT virus samples. The N-gram sequences they form only appear in a few virus samples and may be used by virus software makers for code obfuscation. Therefore, in order to avoid the impact of rare opcodes on the N-gram feature capacity, before extracting the opcode sequence, we first select the key m opcodes as the analysis target based on the probability of each opcode appearing in the sample; for the set O composed of all opcodes in the training set, the set element o i The probability calculation for is as follows:
[0039]
[0040] Among them, freq(o i |x i ) means that in sample x i Medium opcode o i Frequency of occurrence, sample x i belongs to the training set X.
[0041] S2. Extract N-gram semantic features of key operation code streams.
[0042] For the streamlined opcode stream, a sliding window of size 2 is used to extract a series of 2-gram opcode sequences, each of which has a length of 2, and the frequency of occurrence of each sequence is counted.
[0043] like Figure 2The partial opcode stream of the IoT virus sample shown in the figure, if the opcode 'shl' does not belong to the m key opcodes screened, the final generated opcode sequence is: os1 = (and, sub), os2 (sub, xor), os3 = (xor, inc), os4 = (inc, lea), ..., os 12 =(cmp,jmp), and the frequency of each sequence is 1.
[0044] S3. Convert the operation code N-gram features into an operation code sequence vector.
[0045] The m key operation codes are used to construct m 2 opcode sequences of length 2, and then for each sequence os i Assign a weight w i , get an m 2 Dimensional opcode sequence vector:
[0046] V={(os1, w1), (os2, w2),..., (os n , W n )},n=m 2 .
[0047] Weight w i The calculation uses an algorithm called TF-GR, that is, the word frequency tf of the opcode sequence i And the product of information gain rate Gain-ratio:
[0048] w i =tf i ×GR(X,os i )
[0049] Among them, GR(X,os i ) represents the operation code sequence os i Information gain rate for malware training set X; if there are k opcode sequences in the virus sample, each opcode sequence i The frequency of occurrence is represented by , then the tf of each virus file i and GR(X,os i ) is calculated as follows:
[0050]
[0051] Among them, H(X) and H(os i ) represent the data set X and the operation code sequence os respectively. i The information entropy of i ) represents the data set X in the operation code sequence os i The conditional entropy under .
[0052] If the data set X has l different families f c , c = 1, 2, ..., l, and the opcode sequence os appears in all virus samples i The total number of num has s different values j (os i ), j=1,2,...,s, then H(X), H(X|os i ), H(os i ) are calculated according to the following formulas:
[0053]
[0054] S4. Convert the opcode sequence vector into a code semantic image.
[0055] The weights in the opcode sequence vector are normalized so that their size falls within the pixel value range. The normalization formula is:
[0056]
[0057] Among them, max(w i ) represents the maximum value of all directional weights of the opcode sequence vector.
[0058] If the image is regarded as a pixel matrix, as shown in Table 1 below, the selected m key opcodes can be used as the horizontal and vertical axes of the image respectively, thereby constructing a code semantic image matrix of size m*m; the two-dimensional coordinates of each pixel point in the matrix can be exactly expressed as an opcode sequence of length 2, so the opcode sequence vector can be mapped into an image, and the sequence in each element of the vector can be mapped to the position of a specific pixel point in the image matrix, and the weight corresponding to the sequence can be expressed as the pixel value of the point.
[0059]
[0060] Table 1 Code semantic image matrix
[0061] S5. Construct a convolutional neural network to perform image classification, and then determine the family category of the IoT virus variant. The classification result output by the convolutional neural network is the family category of the virus variant.
[0062] like Figure 3As shown in the figure, the opcode image is used as the input of the convolutional neural network model to extract deep features of the code semantic image; the convolutional neural network contains 2 convolutional layers with ReLU activation function, the convolution kernel size is 3*3, and the number is 16 and 32 respectively; at the same time, a pooling layer is executed after each convolution layer for downsampling, and the pooling window is 2*2; since the output of the pooling layer is multi-dimensional, it is necessary to use the Flat layer to convert the multi-dimensional nodes into one-dimensional nodes as the input of the fully connected layer D1, and the fully connected layer D1 uses 256 nodes; the classification result output by the convolutional neural network model is used as the family category of the virus variant.
[0063] From the relevant research on existing static analysis, it can be found that the semantic information of the code segment is the most important target basis for representing the characteristics of the IoT virus sample. Therefore, it is extremely important for the security of the IoT to design a method for classifying IoT virus variant families based on code semantic images. The method of this embodiment improves the existing visualization-based virus variant family classification technology. The existing technical method mainly considers the global structural characteristics of the virus software file. The attacker can use obfuscation technology to hide the structural characteristics of the virus file, thereby achieving the effect of family judgment escape; the present invention proposes for the first time to construct the semantic characteristics of the code segment as a grayscale image, and use a convolutional neural network to classify the obtained image, which can solve the problem of low classification accuracy caused by the existing method ignoring the semantic characteristics of the code, and achieve accurate judgment of the IoT virus variant family.
[0064] In addition to the above embodiments, the present invention may also have other implementation modes. Any technical solution formed by equivalent replacement or equivalent transformation falls within the protection scope required by the present invention.
Claims
1. A method for classifying IoT virus variant families based on code semantic images, characterized by: The following steps are involved: S1. Disassemble IoT virus samples and extract key operation code streams; S2, extract the N-gram semantic features of the key operation code stream; S3, converting the operation code N-gram features into an operation code sequence vector; S4, converting the operation code sequence vector into a code semantic image; S5. Construct a convolutional neural network to perform image classification, and then determine the family category of the IoT virus variant. The classification result output by the convolutional neural network is the family category of the virus variant.
2. According to claim 1, a method for classifying IoT virus variant families based on code semantic images is characterized by: In the step S1, the IoT virus sample in the ELF format is disassembled to convert its code segment into assembly code and generate an assembly file; in the assembly file, ".text" or "CODE" is used to identify each line of code, the code structure includes an operation code and an operand, and only the operation code is used as a feature; after the operation code is extracted from the assembly code in the virus assembly file, an operation code stream is obtained.
3. According to claim 1, the method for classifying IoT virus variant families based on code semantic images is characterized by: In step S1, the specific method of extracting the key operation code stream is: select the key m operation codes as the analysis target according to the probability of each operation code in the sample; for the set O composed of all operation codes in the training set, the set element o i The probability calculation for is as follows: Among them, freq(o i |x i ) means that in sample x i Medium opcode o i Frequency of occurrence, sample x i belongs to the training set X.
4. The method for classifying IoT virus variant families based on code semantic images according to claim 1 is characterized in that: In step S2, a series of 2-gram operation code sequences are extracted using a sliding window of size 2, each sequence having a length of 2, and the frequency of occurrence of each sequence is counted.
5. The method for classifying IoT virus variant families based on code semantic images according to claim 1 is characterized in that: In step S3, the selected m key operation codes are used to construct m 2 opcode sequences of length 2, and then for each sequence os i Assign a weight w i , get an m 2 Dimensional opcode sequence vector: V={(os1,w1),(os2,w2),...,(os n ,w n )},n=m 2 。 6. The method for classifying IoT virus variant families based on code semantic images according to claim 5 is characterized by: In step S3, the weight w is calculated using the TF-GR algorithm. i , that is, calculate the word frequency tf of the opcode sequence i And the product of information gain rate Gain-ratio: w i =tf i ×GR(X,os i ) Among them, GR(X,os i ) represents the operation code sequence os i Information gain rate for malware training set X.
7. The method for classifying IoT virus variant families based on code semantic images according to claim 6 is characterized by: In step S3, if there are k opcode sequences in the virus sample, each opcode sequence i The frequency of occurrence is expressed as n i Indicates that the tf of each virus file i and GR(X,os i ) is calculated as follows: Among them, H(X) and H(os i ) represent the data set X and the operation code sequence os respectively. i The information entropy of i ) represents the data set X in the operation code sequence os i The conditional entropy under .
8. The method for classifying IoT virus variant families based on code semantic images according to claim 1 is characterized by: In step S4, the weights in the operation code sequence vector are normalized so that their magnitudes fall within the pixel value range. The normalization formula is: Among them, max(w i ) represents the maximum value of all directional weights of the opcode sequence vector.
9. The method for classifying IoT virus variant families based on code semantic images according to claim 8 is characterized by: In step S4, the image is regarded as a pixel matrix, and the screened m key operation codes are used as the horizontal axis and the vertical axis of the image respectively, so as to construct a code semantic image matrix with a size of m*m; the two-dimensional coordinates of each pixel point in the matrix are represented as an operation code sequence with a length of 2, the operation code sequence vector is mapped into an image, and the sequence in each element in the vector is mapped to the position of a specific pixel point in the image matrix, and the weight corresponding to the sequence is represented as the pixel value of the point.
10. The method for classifying IoT virus variant families based on code semantic images according to claim 1, characterized in that: In step S5, the convolutional neural network includes two convolutional layers with ReLU activation functions, the convolution kernel size is 3*3, and the number is 16 and 32 respectively; a pooling layer is executed after each convolution layer for downsampling, and the pooling window is 2*2; and a Flat layer is used to convert multi-dimensional nodes into one-dimensional nodes as the input of the fully connected layer D1, and the fully connected layer D1 uses 256 nodes.
