Malicious code variant detection method and system based on domain space feature alignment method

By converting malware samples into grayscale images and using deep residual networks to extract features, combined with domain space feature alignment technology, the identification problem of traditional detection methods in the face of complex malware is solved and the accuracy of malware detection is improved. and robustness to adapt to rapidly changing cyber threats.

CN118468272BActive Publication Date: 2024-09-13SHANDONG COMP SCI CENTNAT SUPERCOMP CENT IN JINAN +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410916949.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-10
Publication Date
2024-09-13
Estimated Expiration
2044-07-10

AI Technical Summary

Technical Problem

Traditional malware detection methods are difficult to effectively identify when faced with complex malware encapsulation and encryption technologies, and machine learning-based methods are fragile when fighting against sample attacks, respond slowly to new malware, and consume large amounts of resources. and relies on large amounts of labeled data.

Method used

Using a method based on domain space feature alignment, malware samples are converted into grayscale images, and features are extracted through improved discrete cosine transform and deep residual network to reduce the difference in feature distribution between the source domain and the target domain and improve detection accuracy. and model generalization ability.

Benefits of technology

It improves the detection accuracy of new malware and variants, enhances the robustness and generalization capabilities of the model, reduces system maintenance costs and time, and adapts to rapidly evolving network security threats.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118468272B
    Figure CN118468272B
Patent Text Reader

Abstract

The present invention relates to the field of malicious code detection, and provides a malicious code variant detection method and system based on a domain space feature alignment method. The method includes: performing grayscale image conversion on a source domain sample code and a target domain sample code respectively to obtain a first source domain grayscale image and a first target domain grayscale image; performing contrast enhancement, converting the first source domain grayscale image and the first target domain grayscale image from the spatial domain to the frequency domain, and then using an inverse discrete cosine transform to obtain a second source domain grayscale image and a second target domain grayscale image; using a deep residual network to obtain a source domain feature vector and a target domain feature vector, and then obtaining an output result based on the source domain feature vector; constructing a total optimization target loss based on classification loss and domain space feature alignment loss, and optimizing a deep residual network; based on the code to be detected, inputting into a trained deep residual network to obtain malicious code or normal code. The present invention improves the detection accuracy of new malware and variants.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of malicious code detection, and in particular to a malicious code variant detection method and system based on a domain space feature alignment method. Background Art

[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.

[0003] Traditional malware detection methods are mainly divided into two categories: static analysis and dynamic analysis. Static analysis identifies malicious behaviors by analyzing the code structure and signature matching of malware. The advantages of this method are fast and low resource consumption, but its biggest disadvantage is that it is difficult to cope with the increasingly complex malware packaging and encryption technologies. Dynamic analysis identifies malicious behaviors by executing malware in a controlled environment and monitoring its behavior in real time. This method can capture malicious behaviors that static methods cannot identify, but it consumes a lot of resources and reacts slowly to new malware.

[0004] In recent years, with the development of machine learning technology, machine learning-based malware detection methods have received widespread attention. These methods can extract discriminative features from a large number of malware samples by analyzing and learning them, thereby predicting the properties of unknown samples. However, such methods usually rely on a large amount of labeled data, and the generalization ability and accuracy of the model are still limited when faced with the rapidly evolving distribution of malware features. In particular, in the case of adversarial sample attacks, traditional supervised learning models show obvious vulnerabilities. Summary of the invention

[0005] In order to solve the technical problems existing in the above-mentioned background technology, the present invention provides a malicious code variant detection method and system based on the domain space feature alignment method. The present invention converts the malware sample into a grayscale image and performs feature enhancement, uses a deep residual network to extract features, and then reduces the feature distribution difference between the source domain and the target domain through feature alignment technology. In this way, not only the detection accuracy of new malware and variants is improved, but also the generalization ability and robustness of the model are enhanced, providing a new technical solution for the field of network security.

[0006] In order to achieve the above object, the present invention adopts the following technical solution:

[0007] A first aspect of the present invention provides a malicious code variant detection method based on a domain space feature alignment method.

[0008] The malicious code variant detection method based on the domain space feature alignment method includes:

[0009] Obtaining a source domain sample code and a target domain sample code, and performing grayscale image conversion on the source domain sample code and the target domain sample code respectively to obtain a first source domain grayscale image and a first target domain grayscale image;

[0010] The first source domain grayscale image and the first target domain grayscale image are respectively contrast enhanced by using improved discrete cosine transform, and the first source domain grayscale image and the first target domain grayscale image are converted from the spatial domain to the frequency domain to obtain a source domain frequency domain image and a target domain frequency domain image; the source domain frequency domain image and the target domain frequency domain image are converted from the frequency domain to the spatial domain by using inverse discrete cosine transform to obtain a second source domain grayscale image and a second target domain grayscale image;

[0011] A deep residual network is used to extract features from the second source domain grayscale image and the second target domain grayscale image, respectively, to obtain a source domain feature vector and a target domain feature vector, and then an output result is obtained according to the source domain feature vector;

[0012] The classification loss is calculated based on the difference between the true label of the source domain sample and the output result, and the domain space feature alignment loss is calculated based on the covariance matrix of the source domain feature vector and the target domain feature vector. Based on the classification loss and the domain space feature alignment loss, the total optimization target loss is constructed to optimize the deep residual network.

[0013] Based on the code to be detected, grayscale image conversion and feature enhancement are performed in sequence, and then input into the trained deep residual network to obtain malicious code or normal code.

[0014] Furthermore, the improved discrete cosine transform is: selecting a threshold ; Threshold-based , define a mask ; Perform frequency domain filtering and apply a mask to the filtered DCT coefficients .

[0015] Furthermore, the threshold for:

[0016] ;

[0017] Among them, M and N both represent the size of the image. Represents a predefined constant.

[0018] Furthermore, the mask for:

[0019] ;

[0020] in, and are all constants; and It is a frequency index in the frequency domain, which is used to indicate the specific position or frequency component of the image in the frequency domain; M Indicates the width of the image.

[0021] Furthermore, a mask is applied to the filtered DCT coefficients , expressed by the following formula:

[0022] ;

[0023] in, represents the filtered DCT coefficients, represents the DCT coefficient, and It is a frequency index in the frequency domain, which is used to indicate the specific position or frequency component of the image in the frequency domain.

[0024] Furthermore, the deep residual network is as follows: the initial processing starts with a convolution layer with a 7x7 convolution kernel to capture the basic features of the input image; then, the features are standardized and nonlinearly processed through batch normalization and ReLU activation function ReLU(), and then the feature dimension is reduced through maximum pooling; the network core is composed of multiple residual blocks, each residual block contains three convolution layers: a 1x1 convolution for dimensionality reduction, a 3x3 convolution for spatial feature extraction, and another 1x1 convolution for restoring feature dimension, and batch normalization and ReLU activation function are applied after each layer; adaptive average pooling is used to compress the feature map to global features, and the global features are flattened and then passed through a linear layer for final classification output.

[0025] Furthermore, the classification loss is:

[0026] ;

[0027] in, Represents a given feature When , the model predicts the correct category probability.

[0028] Furthermore, the domain space feature alignment loss is:

[0029] ;

[0030] in, represents the covariance matrix of the source domain eigenvector, represents the covariance matrix of the target domain feature vector, represents the dimension of the feature vector, is the square root of the sum of the squares of all the elements of the matrix.

[0031] Furthermore, the total optimization target loss is:

[0032] ;

[0033] ;

[0034] in, represents the total optimization target loss, represents the classification loss, represents the domain space feature alignment loss, is a dynamically adjusted parameter; In the definition of represents the current training iteration number, Indicates the total number of iterations.

[0035] A second aspect of the present invention provides a malicious code variant detection system based on a domain space feature alignment method.

[0036] The malicious code variant detection system based on the domain space feature alignment method includes:

[0037] An acquisition and preprocessing module, used for acquiring a source domain sample code and a target domain sample code, and performing grayscale image conversion on the source domain sample code and the target domain sample code respectively, to obtain a first source domain grayscale image and a first target domain grayscale image;

[0038] The enhancement module is used to perform contrast enhancement on the first source domain grayscale image and the first target domain grayscale image by using improved discrete cosine transform, convert the first source domain grayscale image and the first target domain grayscale image from the spatial domain to the frequency domain, and obtain a source domain frequency domain image and a target domain frequency domain image; and convert the source domain frequency domain image and the target domain frequency domain image from the frequency domain to the spatial domain by using inverse discrete cosine transform, and obtain a second source domain grayscale image and a second target domain grayscale image;

[0039] A feature extraction module is used to use a deep residual network to extract features from the second source domain grayscale image and the second target domain grayscale image, respectively, to obtain a source domain feature vector and a target domain feature vector, and then obtain an output result based on the source domain feature vector;

[0040] The loss optimization module is used to calculate the classification loss according to the difference between the true label of the source domain sample and the output result, and calculate the domain space feature alignment loss according to the covariance matrix of the source domain feature vector and the target domain feature vector; based on the classification loss and the domain space feature alignment loss, the total optimization target loss is constructed to optimize the deep residual network;

[0041] The detection module is used to perform grayscale image conversion and feature enhancement in sequence based on the code to be detected, and then input it into the trained deep residual network to obtain malicious code or normal code.

[0042] Compared with the prior art, the present invention has the following beneficial effects:

[0043] The advantage of the present invention is that it combines advanced image processing technology and deep learning algorithms to improve the accuracy and efficiency of malware detection. First, by converting the binary data of malware into grayscale images, the present invention uses a graphical approach to highlight the characteristics of malicious code, which is more effective in identifying variants and unknown malware than traditional signature-based detection techniques. In addition, the data enhancer enhances the image contrast through discrete cosine transform (DCT) and inverse transform to better capture the subtle features of malware, which helps improve the model's ability to migrate and generalize between different data distributions.

[0044] The present invention adopts a classification detector based on the domain space feature alignment method, which can effectively classify malware families without a large amount of labeled data and the emergence of new malicious code variants. This method reduces the dependence on expert knowledge and manpower, and significantly reduces the maintenance cost and time of the system. The system optimizes the feature differences between the source domain and the target domain through feature alignment technology, further enhancing the adaptability and robustness of the model to emerging malware.

[0045] In summary, the present invention provides an efficient, accurate and cost-effective solution for dealing with rapidly evolving network security threats, especially in the field of malware detection, which has important practical value and broad application prospects. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.

[0047] Figure 1 It is a framework diagram of a malicious code variant detection method based on a domain space feature alignment method shown in the present invention;

[0048] Figure 2 Schematic diagram of the deep residual network enhancement process based on source domain-target domain feature alignment shown in the present invention;

[0049] Figure 3 It is a comparison diagram of the effectiveness of the multi-classification data enhancement method shown in the present invention;

[0050] Figure 4 4 is a comparison chart of the effectiveness of the binary classification data enhancement method shown in the present invention. DETAILED DESCRIPTION

[0051] Terminology explanation:

[0052] Domain adaptation is a branch of transfer learning, which aims to improve the performance of the model in the target domain by minimizing the distribution difference between the source domain (the dataset used in the training phase) and the target domain (the dataset encountered in actual applications). In the context of malware detection, domain adaptation technology can make the detection model better adapt to unseen malware samples, especially showing good results in the detection of new and variant malware.

[0053] Embodiment 1

[0054] The present embodiment provides a malicious code variant detection method based on the domain space feature alignment method. The present embodiment uses the method applied to the server as an example for illustration. It is understandable that the method can also be applied to the terminal, and can also be applied to a terminal, a server and a system, and is implemented through the interaction between the terminal and the server. The server can be an independent physical server, or a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network servers, cloud communications, middleware services, domain name services, security services CDN, and big data and artificial intelligence platforms. The terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in this application. In the present embodiment, the method includes the following steps:

[0055] Obtaining a source domain sample code and a target domain sample code, and performing grayscale image conversion on the source domain sample code and the target domain sample code respectively to obtain a first source domain grayscale image and a first target domain grayscale image;

[0056] The first source domain grayscale image and the first target domain grayscale image are respectively contrast enhanced by using improved discrete cosine transform, and the first source domain grayscale image and the first target domain grayscale image are converted from the spatial domain to the frequency domain to obtain a source domain frequency domain image and a target domain frequency domain image; the source domain frequency domain image and the target domain frequency domain image are converted from the frequency domain to the spatial domain by using inverse discrete cosine transform to obtain a second source domain grayscale image and a second target domain grayscale image;

[0057] A deep residual network is used to extract features from the second source domain grayscale image and the second target domain grayscale image, respectively, to obtain a source domain feature vector and a target domain feature vector, and then an output result is obtained according to the source domain feature vector;

[0058] The classification loss is calculated based on the difference between the true label of the source domain sample and the output result, and the domain space feature alignment loss is calculated based on the covariance matrix of the source domain feature vector and the target domain feature vector. Based on the classification loss and the domain space feature alignment loss, the total optimization target loss is constructed to optimize the deep residual network.

[0059] Based on the code to be detected, grayscale image conversion and feature enhancement are performed in sequence, and then input into the trained deep residual network to obtain malicious code or normal code.

[0060] The present invention converts malware samples into grayscale images and performs feature enhancement, uses a deep residual network to extract features, and then uses feature alignment technology to reduce the feature distribution differences between the source domain and the target domain. In this way, not only the detection accuracy of new malware and variants is improved, but also the generalization ability and robustness of the model are enhanced, providing a new technical solution for the field of network security.

[0061] Below, the technical solutions in the present invention will be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments of the present invention. It should be understood that the present invention is not limited to the example embodiments described herein. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. It should also be noted that, for the convenience of description, only the parts related to the present invention are shown in the accompanying drawings, rather than all of them.

[0062] like Figure 1 As shown, the malicious code variant detection method based on the domain space feature alignment method described in this embodiment includes: first, preprocessing known and unknown malware samples to meet the needs of model training and verification. Then, through a data conversion module, the binary file of the malware is converted into a grayscale image. This conversion process includes mapping the byte sequence to the grayscale value, which provides a basis for the subsequent image processing steps. Data enhancement processing enhances the key features of the malicious code generated image by applying techniques such as image standardization and contrast adjustment, thereby improving the recognition efficiency of the classification model. The malware classification detector adopts a multi-layer convolutional neural network structure, including multiple convolutional layers with shared weights, average pooling layers, and fully connected layers. It not only learns and extracts features, but also optimizes model performance through classification loss (Lcls) and feature loss (Ldisc). Finally, the processed data is classified into different malware families, each family represents a specific type of malicious behavior and threat, and effectively enhances the network security protection capabilities of critical infrastructure. This system effectively automatically classifies various emerging and variant malware by combining advanced image processing technology and deep learning technology, greatly improving the security protection efficiency in fields such as industrial control systems.

[0063] The detailed plan is as follows:

[0064] S1: Data preprocessing

[0065] First, convert the malicious code sample into an input format that is readable by the model. Consider converting the malicious code binary sample into a grayscale image. The reason is that in the process of converting to an image, the original binary data undergoes certain preprocessing, such as mapping bytes to grayscale values. This conversion itself is a feature extraction that can help highlight certain characteristics of the malicious code. First, read the binary data according to the byte sequence and map each byte to a decimal value in the range of [0-255], and then store this value in a one-dimensional array. For example, '0110000' will be mapped to 96. Each value in the array corresponds to a pixel in the grayscale image. Then rearrange it with the recommended fixed width and variable height according to the size of the file.

[0066] S2: Data feature enhancement

[0067] Images initially exist in the spatial domain, i.e., pixel values. Direct manipulation of pixels to enhance contrast in the spatial domain is often limited because it is difficult to focus on both local details and global contrast of the image at the same time. Therefore, the present invention turns to the frequency domain, which represents images in a different way that allows for more targeted adjustments to the features of the image. The cornerstone of the feature engineering strategy is the application of a discrete cosine transform (DCT) to generate a frequency domain representation of the malware binary image. The DCT helps separate the image into a spectrum of different meanings, laying the foundation for targeted contrast enhancement. The present invention's method uses a two-dimensional DCT, defined as:

[0068] ;

[0069] in, Representation in the spatial domain The pixel intensity at the coordinates, is the DCT coefficient in the frequency domain. and corresponds to the dimensions of the image, and is the normalization coefficient, expressed as:

[0070] .

[0071] This transformation redistributes image energy across the entire frequency spectrum, laying the foundation for selective enhancement.

[0072] Specifically, suppose there is a grayscale image generated by malware ,in and Represent the coordinates of the image in the spatial domain, and each pixel ranges from [0,255]. Convert this image from the spatial domain to the frequency domain. In the frequency domain, the low-frequency part of the image usually contains most of the image energy and main information, while the high-frequency part contains the details and edge information of the image. For malware images, special attention is paid to how to use this frequency domain information to enhance the contrast of the image, thereby highlighting the similarity of the instruction sequence.

[0073] For each DCT coefficient , calculate an enhancement coefficient, the purpose of which is to increase the influence of high-frequency coefficients while retaining the main features of the image to highlight more subtle differences. This step can be specifically described as the following process: First, perform frequency domain filtering: select a threshold ,

[0074] ;

[0075] is a predefined constant that helps determine how much of the spectrum is considered low frequency.

[0076] based on , define a mask ,have:

[0077] .

[0078] As a mask to adjust the contrast, and It is the frequency index in the frequency domain, which is used to indicate the specific position or frequency component of the image in the frequency domain. (width of the image) is used as a reference size. and As a constant, it is to ensure that the overall brightness and contrast of the image are not over-expanded, avoiding overexposure or distortion of the image. For low-frequency components, a smaller , to avoid over-enhancement; for high-frequency components, choose a relatively large , to emphasize the details and edges of the image. Then apply a mask to the filtered DCT coefficients:

[0079] .

[0080] Finally, perform an inverse DCT transform: Use the inverse discrete cosine transform (IDCT) to convert the frequency domain image back to the spatial domain. The formula for the inverse transform is:

[0081] .

[0082] This method effectively redistributes image energy across the entire spectrum, emphasizing certain frequencies based on their importance to the image content, thereby enhancing contrast. This method allows for selective enhancement, retaining key features while highlighting details, and retaining as many features of the contrast-enhanced image as possible for further analysis and classification.

[0083] S3: Malicious code variant detection

[0084] For the task of this invention, we first formulate the problem. :Depend on malware samples, each from one of the known families . The dataset can be represented as:

[0085] ;

[0086] in, is a malware image from the source domain, Is indicative of a malware family These images are usually processed to extract numerical features that are useful for image-based classification tasks.

[0087] For the target domain : Includes possible from known and unknown series Malware samples. Due to the rapid evolution and development of malicious code, new malicious code variants usually show characteristic deviations from known data:

[0088] ;

[0089] Here Indicates a possible improved or rarely observed malware family The malware images of the target domain are malware images from the source domain. The objectives of the present invention include: 1) first improving the generalization of the model through data augmentation; 2) minimizing the feature distribution difference between the source domain and the target domain. This can be achieved by optimizing the following objective function:

[0090] ;

[0091] in, Indicates that the parameter is The feature extraction network represents the difference between the source domain and target domain feature distribution, is a regularization parameter used to adjust the importance of alignment.

[0092] 3) The present invention needs to ensure the performance of the model on the classification task, that is, correctly classify malware samples in the source domain and the target domain:

[0093] ;

[0094] in, Represents a deep residual network Model for classification, is the loss function used to evaluate the error between the prediction and the true label, represents the estimated labels of target domain samples (if available), is a regularization parameter used to balance the importance of source and target domain classification.

[0095] Ultimately, the present invention hopes to achieve feature alignment and improve the generalization ability of the target domain while maintaining the classification accuracy of the source domain. Therefore, the comprehensive objective function adopted for the model can be expressed as:

[0096] .

[0097] The specific implementation process of the research problem of the present invention is as follows Figure 2 As shown. First, we use a deep residual network based on the improved ResNet architecture. . Tailored for malware image feature extraction tasks. The initial processing starts with a convolutional layer with a large convolution kernel (7x7) to capture the basic features of the input image. Subsequently, batch normalization and ReLU activation function ReLU() are used to normalize and nonlinearize the features, and max pooling is used to reduce the feature dimension and reduce computational complexity. The core of the network consists of multiple residual blocks, each of which contains three convolutional layers: a 1x1 convolution for dimensionality reduction, a 3x3 convolution for spatial feature extraction, and another 1x1 convolution for restoring the feature dimension. Batch normalization and ReLU activation function are applied after each layer. Residual connections are implemented by element-wise addition, which helps to solve the gradient vanishing problem in deep network training. Finally, adaptive average pooling is used to compress the feature map into a global feature, which is flattened and passed through a linear layer for the final classification output.

[0098] The deep residual network is parameterized Operation, from the source domain and target domain Specifically, for each sample in the source domain , deep residual network Output a feature vector:

[0099] ;

[0100] Similarly, for each sample in the target domain , output:

[0101] .

[0102] After feature extraction, two embedding spaces are defined: classification space and feature alignment space. Samples are classified and aligned respectively through the two embedding spaces, so that the classifier can achieve correct classification as much as possible while adapting to the changes between samples in different domains.

[0103] The classification loss is calculated in the classification space based on the difference between the true label of the source domain sample and the model prediction result. The classification loss is:

[0104] ;

[0105] in, Represents a given feature When , the model predicts the correct category probability.

[0106] For the feature alignment space, calculate the covariance matrix of the source domain feature vector and the covariance matrix of the target domain eigenvector , used to quantify and analyze the linear relationship between data features and their variability:

[0107] ;

[0108] ;

[0109] in, and Represents the number of samples in the source domain and the target domain respectively, and Represents the feature vector extracted by the feature extraction model for the source domain and the target domain, and is the mean of the eigenvectors in their respective domains. Minimizing the difference between the two covariance matrices is taken as an optimization goal, specifically through the loss function This loss function forces the model to learn to adjust its performance in the target domain while maintaining the performance in the source domain:

[0110] ;

[0111] in, represents the dimension of the feature vector, It is the square root of the sum of the squares of all elements of the matrix. Loss function It is set up to reduce classification errors caused by domain differences, so that the model can still maintain high performance when facing different test environments.

[0112] When the model needs to optimize multiple loss functions at the same time, how to adjust the relative importance of these loss functions is the key to improving the overall performance of the model. This invention introduces a dynamically adjusted parameter , which is used to control the balance between classification loss and feature alignment loss:

[0113] ;

[0114] in, Indicates the current iteration number. Represents the total number of iterations. This parameter is automatically adjusted during the training process to ensure that different learning objectives can be adaptively emphasized at different training stages. Therefore, the overall optimization goal for the model is:

[0115] .

[0116] S4: Evaluation and Validation

[0117] The present invention uses the dataset Microsoft Malware Classification Challenge (BIG 2015) as a multi-classification experimental dataset, which is provided by Kaggle and contains nearly 500GB of malware samples divided into 9 different families. Each sample contains the original binary file and the parsed bytecode and assembly code files. This dataset is used to evaluate and compare the performance of different malware classification methods, aiming to promote research and progress in the field of malware detection and classification. Malware Analysis Datasets (MDA) is a binary classification dataset provided by IEEE Dataport, which contains a large number of original images of malware PE files. The images contain existing PE malware examples and benign software examples. The present invention uses Accuracy, F1, Precision, Recall and AUC values ​​as performance evaluation indicators for malicious code variant detection. The AUC value is used on the test dataset and its basic truth value to evaluate the performance of the malicious code detection method of the present invention.

[0118] Accuracy=(TP+TN) / (TP+TN+FP+FN);

[0119] Recall = TP / (TP+FN);

[0120] Precision = TP / (TP+FP);

[0121] F1=2×Precision×Recall / (Precision+Recall).

[0122] S5: Experimental Results

[0123] Figure 3 and Figure 4 The accuracy impact of feature-enhanced data compared to original data on four deep learning models (CNN, AlexNet, VGG16, ResNet50) is shown. The results show that feature-enhanced data significantly improves accuracy on all models, confirming the important role of data preprocessing and feature engineering in improving model performance. In particular, for CNN models, feature enhancement brings the most significant performance improvement, and advanced models such as ResNet50 also show excellent performance on feature-enhanced data, highlighting the key value of optimizing data input in deep learning applications. These findings emphasize that in security-sensitive areas such as malware detection, proper data processing can significantly improve the accuracy and reliability of models.

[0124] As shown in Table 1, in the Microsoft Malware Classification Challenge dataset, the method of the present invention outperforms the source-only, DSAN and DAN methods in all indicators. Specifically, the method of the present invention achieves the highest values ​​in accuracy, precision, recall and F1 score. This shows that the method of the present invention can more effectively extract features and improve classification performance when processing different data distributions.

[0125] Table 1 Verification of multi-classification data feature alignment method

[0126]

[0127] In the binary classification data set, different data amounts have a significant impact on the model performance, as shown in Table 2. When the data amount is small (1000 samples), the method of the present invention has shown obvious advantages. As the data amount increases to 2000 samples, the method of the present invention has significant improvements in various indicators, proving that more data helps the model learn more accurate features. When the data amount is further increased to 4000 samples, the method of the present invention achieves the best in all indicators, demonstrating its powerful ability and robustness in processing large-scale data. In contrast, the improvement of other methods under different data amounts is not as significant as that of the method of the present invention, especially when the data amount is large, the performance gap is more obvious.

[0128] Table 2 Verification of binary data feature alignment method

[0129]

[0130] Embodiment 2

[0131] This embodiment provides a malicious code variant detection system based on a domain space feature alignment method.

[0132] The malicious code variant detection system based on the domain space feature alignment method includes:

[0133] An acquisition and preprocessing module, used for acquiring a source domain sample code and a target domain sample code, and performing grayscale image conversion on the source domain sample code and the target domain sample code respectively, to obtain a first source domain grayscale image and a first target domain grayscale image;

[0134] The enhancement module is used to perform contrast enhancement on the first source domain grayscale image and the first target domain grayscale image by using improved discrete cosine transform, convert the first source domain grayscale image and the first target domain grayscale image from the spatial domain to the frequency domain, and obtain a source domain frequency domain image and a target domain frequency domain image; and convert the source domain frequency domain image and the target domain frequency domain image from the frequency domain to the spatial domain by using inverse discrete cosine transform, and obtain a second source domain grayscale image and a second target domain grayscale image;

[0135] A feature extraction module is used to use a deep residual network to extract features from the second source domain grayscale image and the second target domain grayscale image, respectively, to obtain a source domain feature vector and a target domain feature vector, and then obtain an output result based on the source domain feature vector;

[0136] The loss optimization module is used to calculate the classification loss according to the difference between the true label of the source domain sample and the output result, and calculate the domain space feature alignment loss according to the covariance matrix of the source domain feature vector and the target domain feature vector; based on the classification loss and the domain space feature alignment loss, the total optimization target loss is constructed to optimize the deep residual network;

[0137] The detection module is used to perform grayscale image conversion and feature enhancement in sequence based on the code to be detected, and then input it into the trained deep residual network to obtain malicious code or normal code.

[0138] In some embodiments, the enhancement module is further used to: select a threshold ; Threshold-based , define a mask ; Perform frequency domain filtering and apply a mask to the filtered DCT coefficients , construct an improved discrete cosine transform.

[0139] Among them, the threshold for:

[0140] ;

[0141] Among them, M and N both represent the size of the image. Represents a predefined constant.

[0142] The mask for:

[0143] ;

[0144] in, and are constants, and It is the frequency index in the frequency domain, which is used to indicate the specific position or frequency component of the image in the frequency domain. M Indicates the width of the image.

[0145] In some embodiments, the enhancement module is further configured to: apply a mask to the filtered DCT coefficients , expressed by the following formula:

[0146] ;

[0147] in, represents the filtered DCT coefficients, represents the DCT coefficient, and It is a frequency index in the frequency domain, which is used to indicate the specific position or frequency component of the image in the frequency domain;

[0148] In some embodiments, the feature extraction module is also used for: initial processing starts with a convolution layer with a 7x7 convolution kernel to capture the basic features of the input image; then, the features are standardized and nonlinearly processed through batch normalization and ReLU activation function ReLU(), and then the feature dimension is reduced through maximum pooling; the network core is composed of multiple residual blocks, each residual block contains three convolution layers: a 1x1 convolution for dimensionality reduction, a 3x3 convolution for spatial feature extraction, and another 1x1 convolution for restoring feature dimension, and batch normalization and ReLU activation function are applied after each layer; adaptive average pooling is used to compress the feature map into global features, and the global features are flattened and passed through a linear layer for final classification output.

[0149] In some embodiments, the total optimization objective loss is:

[0150] ;

[0151] ;

[0152] in, represents the total optimization target loss, represents the classification loss, represents the domain space feature alignment loss, is a dynamically adjusted parameter; In the definition of represents the current training iteration number, Indicates the total number of iterations.

[0153] In one or more embodiments, the classification loss is:

[0154] ;

[0155] in, Represents a given feature When , the model predicts the correct category probability.

[0156] In one or more implementations, the domain space feature alignment loss is:

[0157] ;

[0158] in, represents the covariance matrix of the source domain eigenvector, represents the covariance matrix of the target domain feature vector, represents the dimension of the feature vector, is the square root of the sum of the squares of all the elements of the matrix.

[0159] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. Malicious code variant detection method based on domain space feature alignment method, It is characterized in that include: Obtaining a source domain sample code and a target domain sample code, and performing grayscale image conversion on the source domain sample code and the target domain sample code respectively to obtain a first source domain grayscale image and a first target domain grayscale image; The first source domain grayscale image and the first target domain grayscale image are respectively contrast enhanced by using improved discrete cosine transform, and the first source domain grayscale image and the first target domain grayscale image are converted from the spatial domain to the frequency domain to obtain a source domain frequency domain image and a target domain frequency domain image; the source domain frequency domain image and the target domain frequency domain image are converted from the frequency domain to the spatial domain by using inverse discrete cosine transform to obtain a second source domain grayscale image and a second target domain grayscale image; A deep residual network is used to extract features from the second source domain grayscale image and the second target domain grayscale image, respectively, to obtain a source domain feature vector and a target domain feature vector, and then an output result is obtained according to the source domain feature vector; The classification loss is calculated based on the difference between the true label of the source domain sample and the output result, and the domain space feature alignment loss is calculated based on the covariance matrix of the source domain feature vector and the target domain feature vector; Based on the classification loss and domain space feature alignment loss, the total optimization target loss is constructed to optimize the deep residual network; Based on the code to be detected, grayscale image conversion and feature enhancement are performed in sequence, and then input into the trained deep residual network to obtain malicious code or normal code.

2. According to claim 1, the malicious code variant detection method based on the domain space feature alignment method, It is characterized in that The improved discrete cosine transform is: select a threshold ; Threshold-based , define a mask ; Perform frequency domain filtering and apply a mask to the filtered DCT coefficients .

3. The malicious code variant detection method based on the domain space feature alignment method according to claim 2, It is characterized in that The threshold for: ; Among them, M and N both represent the size of the image. Represents a predefined constant.

4. The malicious code variant detection method based on the domain space feature alignment method according to claim 2, It is characterized in that The mask for: ; in, and are all constants; and It is a frequency index in the frequency domain, which is used to indicate the specific position or frequency component of the image in the frequency domain; M Indicates the width of the image.

5. The malicious code variant detection method based on the domain space feature alignment method according to claim 2, It is characterized in that Apply a mask to the filtered DCT coefficients , expressed by the following formula: ; in, represents the filtered DCT coefficients, represents the DCT coefficient, and It is a frequency index in the frequency domain, which is used to indicate the specific position or frequency component of the image in the frequency domain.

6. The malicious code variant detection method based on the domain space feature alignment method according to claim 1, It is characterized in that The deep residual network is as follows: the initial processing starts with a convolution layer with a 7x7 convolution kernel to capture the basic features of the input image; then, the features are standardized and nonlinearly processed through batch normalization and ReLU activation function ReLU(), and then the feature dimension is reduced through maximum pooling; the network core is composed of multiple residual blocks, each residual block contains three convolution layers: a 1x1 convolution for dimensionality reduction, a 3x3 convolution for spatial feature extraction, and another 1x1 convolution for restoring feature dimension, and batch normalization and ReLU activation function are applied after each layer; adaptive average pooling is used to compress the feature map to global features, and the global features are flattened and then passed through a linear layer for final classification output.

7. The malicious code variant detection method based on the domain space feature alignment method according to claim 1, It is characterized in that The classification loss is: ; in, Represents a given feature When , the model predicts the correct category probability.

8. The method for detecting malicious code variants based on the domain space feature alignment method according to claim 1, It is characterized in that The domain space feature alignment loss is: ; in, represents the covariance matrix of the source domain eigenvector, represents the covariance matrix of the target domain feature vector, represents the dimension of the feature vector, is the square root of the sum of the squares of all the elements of the matrix.

9. The malicious code variant detection method based on the domain space feature alignment method according to claim 1, It is characterized in that The total optimization target loss is: ; ; in, represents the total optimization target loss, represents the classification loss, represents the domain space feature alignment loss, is a dynamically adjusted parameter; In the definition of represents the current training iteration number, Indicates the total number of iterations.

10. Malicious code variant detection system based on domain space feature alignment method, It is characterized in that include: An acquisition and preprocessing module, used for acquiring a source domain sample code and a target domain sample code, and performing grayscale image conversion on the source domain sample code and the target domain sample code respectively, to obtain a first source domain grayscale image and a first target domain grayscale image; The enhancement module is used to perform contrast enhancement on the first source domain grayscale image and the first target domain grayscale image by using improved discrete cosine transform, convert the first source domain grayscale image and the first target domain grayscale image from the spatial domain to the frequency domain, and obtain a source domain frequency domain image and a target domain frequency domain image; and convert the source domain frequency domain image and the target domain frequency domain image from the frequency domain to the spatial domain by using inverse discrete cosine transform, and obtain a second source domain grayscale image and a second target domain grayscale image; A feature extraction module is used to use a deep residual network to extract features from the second source domain grayscale image and the second target domain grayscale image, respectively, to obtain a source domain feature vector and a target domain feature vector, and then obtain an output result based on the source domain feature vector; The loss optimization module is used to calculate the classification loss based on the difference between the true label of the source domain sample and the output result, and to calculate the domain space feature alignment loss based on the covariance matrix of the source domain feature vector and the target domain feature vector; Based on the classification loss and domain space feature alignment loss, the total optimization target loss is constructed to optimize the deep residual network; The detection module is used to perform grayscale image conversion and feature enhancement in sequence based on the code to be detected, and then input it into the trained deep residual network to obtain malicious code or normal code.