Malicious code detection method, device, computer equipment and storage medium

By converting the code to be detected into pictures and using the image classification model, the problem of low detection accuracy of unknown threats caused by artificial experience lag in the prior art is solved, and efficient automatic identification of unknown malicious code is achieved.

CN113127863BActive Publication Date: 2024-08-27QI AN XIN TECHNOLOGY GROUP INC +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201911417213.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-12-31
Publication Date
2024-08-27
Estimated Expiration
2039-12-31

AI Technical Summary

Technical Problem

When detecting unknown malicious programs, the artificial experience is lagging and incomplete coverage is caused by low detection accuracy of unknown threats.

Method used

Divide the code to be detected into code segments, correspond to the pixel group on the preset template image, determine the color value of the character through the preset mapping rules, convert it into the picture to be detected, enter the image classification model for classification, and determine whether the code is malicious code .

Benefits of technology

Without manual empirical analysis, it improves the accuracy of detection of unknown threats, simplifies data processing, and realizes automatic identification of unknown malicious code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113127863B
    Figure CN113127863B
Patent Text Reader

Abstract

The present invention provides a method, device, computer equipment and storage medium for detecting malicious code. The method for detecting malicious code includes: dividing the code to be detected into multiple code segments, wherein the code segment corresponds to a pixel group on a preset template image, and the pixel group includes a number of pixels; obtaining the character at a predetermined position of the code segment; determining the color value corresponding to the character according to a preset mapping rule; assigning values ​​to the pixels according to the corresponding relationship between the color value corresponding to the character, the code segment where the character is located and the pixel group, and obtaining the image to be detected corresponding to the code to be detected; inputting the image to be detected into a preset image classification model, wherein the image classification model is used to classify the image corresponding to the malicious code and the image corresponding to the non-malicious code; when the image classification model outputs the category information indicating that the image to be detected belongs to the image corresponding to the malicious code, the code to be detected is determined to be malicious code. Through the present invention, the accuracy of detecting unknown threats is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of security threat processing, and in particular to a malicious code detection method, device, computer equipment and storage medium. Background Art

[0002] With the rapid development of computer network technology, especially the increasing application of the Internet, while bringing convenience to people's lives, computer malicious programs are also posing a greater threat to network information security. Once these malicious programs are launched, they will cause damage to computer systems, which may cause minor damage such as tampering with files, affecting system stability, and stealing information, or even paralyzing the system or even destroying the entire hardware of the system, which will seriously threaten the security of information and cause incalculable losses.

[0003] In the prior art, when detecting unknown malicious programs, manual experience is usually required for analysis. However, manual experience has a certain lag and often has incomplete coverage. When detecting malicious programs, the ability to deal with unknown threats is poor, resulting in low accuracy in detecting unknown malicious programs.

[0004] Therefore, providing a malicious code detection method, apparatus, computer device and storage medium to improve the accuracy of detecting unknown threats has become a technical problem that urgently needs to be solved in this field. Summary of the invention

[0005] The purpose of the present invention is to provide a malicious code detection method, device, computer equipment and storage medium to solve the above-mentioned technical problems in the prior art.

[0006] On the one hand, to achieve the above-mentioned purpose, the present invention provides a method for detecting malicious code.

[0007] The malicious code detection method includes: dividing the code to be detected into multiple code segments, wherein the code segment corresponds to a pixel group on a preset template image, and the pixel group includes a plurality of pixels; obtaining a character at a predetermined position of the code segment; determining a color value corresponding to the character according to a preset mapping rule; assigning a value to the pixel according to the color value corresponding to the character, the corresponding relationship between the code segment where the character is located and the pixel group, and obtaining a picture to be detected corresponding to the code to be detected; inputting the picture to be detected into a preset picture classification model, wherein the picture classification model is used to classify pictures corresponding to malicious code and pictures corresponding to non-malicious code; when the picture classification model outputs category information indicating that the picture to be detected belongs to a picture corresponding to malicious code, determining that the code to be detected is malicious code.

[0008] Furthermore, the step of determining the color value corresponding to the character according to a preset mapping rule includes: determining the ASCII code category corresponding to the character; and determining the color value corresponding to the character according to the correspondence between the ASCII category corresponding to the character, the preset ASCII code category and the color.

[0009] Furthermore, according to the correspondence between the ASCII category corresponding to the character, the preset ASCII code category and the color, the step of determining the color value corresponding to the character includes: when the character is greater than 0 and the corresponding ASCII category belongs to the invisible ASCII code, determining that the character corresponds to the first color; when the ASCII category corresponding to the character belongs to the visible ASCII code, determining that the character corresponds to the second color; when the character is less than 255 and does not belong to the ASCII code, determining that the character corresponds to the third color; when the character is equal to 0, determining that the character corresponds to the fourth color; and when the character is equal to 255, determining that the character corresponds to the fifth color, wherein the first color, the second color, the third color, the fourth color and the fifth color are different.

[0010] Further, the first color, the second color, the third color, the fourth color and the fifth color are respectively one of red, yellow, blue, white and black.

[0011] Further, a pixel group includes one pixel.

[0012] Furthermore, before the step of inputting the image to be detected into a preset classification model, the malicious code detection method also includes: obtaining a model training code sample set, wherein the model training code sample set includes multiple code samples, and the code samples include malicious samples and non-malicious samples; dividing the code samples into multiple training code segments, wherein the training code segments correspond to pixel groups; obtaining training characters at predetermined positions of the training code segments; determining color values ​​corresponding to the training characters; assigning values ​​to pixels according to the corresponding relationship between the color values ​​corresponding to the training characters, the training code segments where the training characters are located, and the pixel groups, to obtain the image to be trained corresponding to the code samples; using the image to be trained as the input of the initial classification model, and using the code category corresponding to the code sample as the output of the initial classification model, and training the initial classification model to obtain an image classification model.

[0013] Furthermore, the picture to be trained is used as the input of the initial classification model, and the code category corresponding to the code sample is used as the output of the initial classification model. The step of training the initial classification model includes: setting the initial classification model to include M convolution blocks connected in sequence, and each convolution block includes several convolution layers; using the parameters of the pre-trained model trained by the ImageNet data set to initialize the parameters of the initial classification model to obtain an intermediate classification model; using the picture to be trained as the input of the intermediate classification model, and the code category corresponding to the code sample is used as the output of the intermediate classification model, and freezing the parameters of the 1st to M-1th convolution blocks in the intermediate classification model to train the intermediate classification model.

[0014] On the other hand, to achieve the above objective, the present invention provides a feature code extraction device.

[0015] The feature code extraction device includes: a segmentation module, which is used to divide the code to be detected into multiple code segments, wherein the code segment corresponds to a pixel group on a preset template image, and the pixel group includes a plurality of pixels; an acquisition module, which is used to acquire the character at a predetermined position of the code segment; a mapping module, which is used to determine the color value corresponding to the character according to a preset mapping rule; a conversion module, which is used to assign values ​​to pixels according to the corresponding relationship between the color value corresponding to the character, the code segment where the character is located, and the pixel group, so as to obtain a picture to be detected corresponding to the code to be detected; a classification module, which is used to input the picture to be detected into a preset picture classification model, wherein the picture classification model is used to classify pictures corresponding to malicious code and pictures corresponding to non-malicious code; and a determination module, which is used to determine that the code to be detected is malicious code when the picture classification model outputs category information indicating that the picture to be detected belongs to a picture corresponding to malicious code.

[0016] To achieve the above objectives, the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.

[0017] To achieve the above object, the present invention also provides a computer-readable storage medium on which a computer program is stored, and the computer program implements the steps of the above method when executed by a processor.

[0018] The malicious code detection method, device, computer equipment and storage medium provided by the present invention segment the code to be detected into multiple code segments, correspond each code segment to a pixel group in a preset template image, map the characters at a predetermined position in each code segment to a color value, and correspond to the pixels in the pixel group. After assigning values ​​to the pixels on the preset template image according to the above correspondence, the code to be detected is converted into a picture to be detected. The picture to be detected is input into a picture classification model for classification and recognition. The classification and recognition result of the code to be detected can be determined by the classification and recognition result of the picture to be detected, that is, whether the code to be detected is malicious code. Through the present invention, the code to be detected is first converted into a picture, and then the detection of the code to be detected is achieved by processing the picture. The method of converting the code to the picture is simple, which reduces the data processing amount for identifying malicious code. There is no need to rely on manual experience to analyze the code to be detected, and the detection of unknown threats can be achieved. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] 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:

[0020] Figure 1 A flowchart of a malicious code detection method provided in Embodiment 1 of the present invention;

[0021] Figure 2 A sample download flow chart of the malicious code detection method provided in the second embodiment of the present invention;

[0022] Figure 3 A flowchart of model training in the malicious code detection method provided in the second embodiment of the present invention;

[0023] Figure 4 A schematic diagram of a model in a malicious code detection method provided in Embodiment 2 of the present invention;

[0024] Figure 5 A block diagram of a malicious code detection device provided in Embodiment 3 of the present invention;

[0025] Figure 6 This is a hardware structure diagram of a computer device provided in Embodiment 4 of the present invention. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0027] In order to improve the accuracy of detecting unknown threats, the present invention provides a method and device for detecting malicious codes. In the malicious code detection method provided by the present invention, the code to be detected is divided into multiple code segments, each code segment is corresponded to a pixel group on a preset template image, and then the corresponding color value of the character at the predetermined position of the code segment is determined according to a preset mapping rule, so that the pixel can be assigned a value according to the color value corresponding to the character, the correspondence between the code segment where the character is located and the pixel group, so as to realize the conversion of the code to be detected into a picture to be detected; for the picture to be detected, it is input into a preset picture classification model, and the picture classification model can classify the picture corresponding to the malicious code and the picture corresponding to the non-malicious code. When the picture classification model outputs the representation that the picture to be detected belongs to the picture corresponding to the malicious code, it can be determined that the code to be detected is malicious code. Therefore, by classifying the picture to be detected through the picture classification model, the code to be detected can be identified. It can be seen that in the malicious code detection method provided by the present invention, the code segment in the code to be detected is corresponded to the pixel group, and the characteristics of the code segment are reflected by the color of the pixel group, so that the processing of the code to be detected is converted into the processing of the image, and then the image can be classified by the artificial intelligence classification model to determine whether the code to be detected is malicious code. There is no need to rely on manual experience to analyze the code to be detected, and the detection of unknown threats can be achieved. At the same time, the processing of the code to be detected is converted into image processing, which can also reduce the data processing amount for identifying malicious code.

[0028] Specific embodiments of the malicious code detection method, apparatus, computer device, and computer-readable storage medium provided by the present invention will be described in detail below.

[0029] Embodiment 1

[0030] The embodiment of the present invention provides a malicious code detection method, which can be applied to sample identification scenarios. For example, an unknown sample (i.e., code to be detected) is detected by the malicious code detection method to determine whether the unknown sample belongs to malicious code or a white sample. Through this method, automatic malicious code identification is achieved without relying on manual experience to analyze the code to be detected, thereby improving the accuracy of detecting unknown threats. Specifically, Figure 1 The flowchart of the malicious code detection method provided in the first embodiment of the present invention is as follows: Figure 1 As shown, the malicious code detection method provided by this embodiment includes the following steps S101 to S106.

[0031] Step S101: Divide the code to be detected into multiple code segments.

[0032] The code segment corresponds to a pixel group on a preset template image, and the pixel group includes a plurality of pixels.

[0033] Specifically, a template image is preset, and the template image may be composed of M*N pixels. Further, the M*N pixels may be divided into pixel groups, for example, m*n pixels are taken as a pixel group, wherein M, N, m and n are all positive integers, and m is less than or equal to M, and n is less than or equal to N. In one case, the number of divisions of code segments in the code to be detected may be set according to the number of pixel groups on the preset template image. For example, if the preset template image includes P pixel groups, the code to be detected is divided into P code segments in this step. Optionally, the code to be detected is equally divided so that the lengths of the code segments are equal. In another case, the appropriate number of code segments may be set according to the overall length of the code to be detected and the length of the code segment itself, and then the M*N pixels are divided into pixel groups based on the number of code segments. In either case, in this step, after the code to be detected is divided into multiple code segments, each code segment uniquely corresponds to a pixel group on the preset template image, and the arrangement order of the pixel groups corresponds to the sequence of the code segments. Furthermore, all pixel groups on the preset template image correspond to the code segments, so that each pixel group on the subsequently formed image to be detected represents the code segment, avoiding the appearance of invalid pixel groups on the image to be detected.

[0034] Step S102: Acquire the characters at a predetermined position of the code segment.

[0035] Specifically, a character with a specific meaning may be obtained at an appropriate position, or the first character or the last character of the code segment may be directly obtained. In short, in step S102, at least one character is obtained at a predetermined position of each code segment.

[0036] Step S103: Determine the color value corresponding to the character according to a preset mapping rule.

[0037] Specifically, a correspondence between characters and colors, i.e., a mapping rule, is set. Based on the mapping rule, a certain character can be mapped to a color value, thereby mapping the features of the code segment to the features of the image. The mapping rule between characters and color values ​​can be established based on character features such as the value of the character and the position of the character in the character set.

[0038] Step S104: assigning values ​​to pixels according to the color value corresponding to the character, the corresponding relationship between the code segment where the character is located and the pixel group, and obtaining the image to be detected corresponding to the code to be detected.

[0039] Specifically, when assigning values ​​to pixels on a preset template image, the color values ​​of different pixels in the same pixel group are the same. The code segment corresponding to the pixel group is determined based on the correspondence between the pixel group and the code segment, and then the color of the pixel in the pixel group is set to the color value corresponding to the character at the predetermined position in the code segment to achieve the assignment of the pixel. After the color values ​​corresponding to the characters at the predetermined positions in each code segment are assigned to the pixels, the code to be detected is converted into the picture to be detected.

[0040] Step S105: input the image to be detected into a preset image classification model.

[0041] The image classification model is used to classify images corresponding to malicious codes and images corresponding to non-malicious codes.

[0042] After the code to be detected is converted into the image to be detected, the image recognition processing method in the prior art can be used for processing. A preset image classification model is obtained by training a sample set including images corresponding to malicious code and images corresponding to non-malicious code, so that the image classification model can classify images corresponding to malicious code and images corresponding to non-malicious code.

[0043] Specifically, the image classification model may include an input layer, a convolutional layer and an output layer, wherein the input layer is used to receive the image to be detected, the convolutional layer is used to extract the features of the image to be detected, and the output layer is used to output the category corresponding to the code to be detected, that is, whether it is a picture corresponding to malicious code or a picture corresponding to non-malicious code.

[0044] Step S106: When the image classification model outputs category information indicating that the image to be detected belongs to an image corresponding to malicious code, it is determined that the code to be detected is malicious code.

[0045] After the image to be detected is input into the image classification model, the image classification model can output category information representing that the image to be detected belongs to the image corresponding to malicious code, or output category information representing that the image to be detected belongs to the image corresponding to non-malicious code. When the category information representing that the image to be detected belongs to the image corresponding to malicious code is output, it can be determined that the code to be detected is malicious code, and when the category information representing that the image to be detected belongs to the image corresponding to non-malicious code is output, it can be determined that the code to be detected is non-malicious code.

[0046] In the malicious code detection method provided in this embodiment, the code to be detected is segmented into multiple code segments, each code segment is corresponded to a pixel group in a preset template image, and the characters at a predetermined position in each code segment are mapped to a color value, which corresponds to the pixels in the pixel group. After assigning values ​​to the pixels on the preset template image according to the above correspondence, the code to be detected is converted into a picture to be detected. The picture to be detected is input into a picture classification model for classification and recognition. The classification and recognition result of the code to be detected can be determined by the classification and recognition result of the picture to be detected, that is, whether the code to be detected is malicious code. The malicious code detection method provided in this embodiment is used to first convert the code to be detected into a picture, and then the code to be detected is detected by processing the picture. The method of converting the code to the picture is simple, which reduces the amount of data processing for identifying malicious code. There is no need to rely on manual experience to analyze the code to be detected, and detection of unknown threats can be achieved.

[0047] Optionally, in one embodiment, the step of determining the color value corresponding to the character according to a preset mapping rule includes: determining the ASCII code category corresponding to the character; and determining the color value corresponding to the character based on the correspondence between the ASCII category corresponding to the character, the preset ASCII code category and the color.

[0048] Specifically, the code to be detected is composed of control characters, punctuation marks, graphic symbols, characters of various countries and numbers, etc. In a computer, it is usually a binary digital sequence. One character corresponds to a digital unit in the binary digital sequence, that is, an 8-bit binary number. In this embodiment, the 8-bit binary number of the code to be detected can be directly obtained as the ASCII code. After the ASCII code is divided into multiple categories in advance and different categories are set to correspond to different colors, the corresponding ASCII code can be determined in the ASCII code table through the 8-bit binary number corresponding to the character. The category to which this ASCII code belongs is the ASCII code category corresponding to the character, and the color corresponding to the ASCII code category is the color value corresponding to the character, thereby determining the color value corresponding to the character.

[0049] The ASCII code itself is an encoding of characters, and the ASCII code category also reflects the category of the characters. The malicious code detection method provided in this embodiment can directly use the 8-bit binary number of the code to be detected as the ASCII code. Different ASCII code categories correspond to different colors. The mapping relationship is simple, and there is no need to process the code to be detected, which reduces the amount of data processing. At the same time, the color on the image to be detected can represent the category of the characters in the code to be detected, ensuring that the image reflects the characteristics of the code to be detected, and then the code to be detected can be recognized through the recognition processing of the image, thereby improving the accuracy of malicious code detection.

[0050] Optionally, in one embodiment, the step of determining the color value corresponding to the character according to the correspondence between the ASCII category corresponding to the character, the preset ASCII code category and the color includes: when the character is greater than 0 and the corresponding ASCII category belongs to the invisible ASCII code, determining that the character corresponds to the first color; when the ASCII category corresponding to the character belongs to the visible ASCII code, determining that the character corresponds to the second color; when the character is less than 255 and does not belong to the ASCII code, determining that the character corresponds to the third color; when the character is equal to 0, determining that the character corresponds to the fourth color; and when the character is equal to 255, determining that the character corresponds to the fifth color, wherein the first color, the second color, the third color, the fourth color and the fifth color are different.

[0051] Specifically, the minimum value of an 8-bit binary number converted to decimal is 0, and the maximum value is 255, which means that the character is greater than or equal to 0 and less than or equal to 255. Within this range, the corresponding ASCII categories are 3 categories: invisible ASCII codes greater than 0, visible ASCII codes, and non-ASCII codes less than 255. For the two endpoints, that is, equal to 0 and equal to 255, they are set as a category respectively, corresponding to the first color to the fifth color, a total of five colors. Among them, the invisible ASCII code includes control characters, which are not displayed in non-DOS mode. In DOS mode, some 8-bit symbols such as smiley faces and poker cards can be displayed; visible ASCII codes include displayable characters; non-ASCII codes refer to characters other than ASCII codes; characters equal to 0 and characters equal to 255 correspond to different non-character filling contents.

[0052] In malicious codes, invisible ASCII codes, visible ASCII codes, non-ASCII codes less than 255, and filler content have different characteristics from normal codes. Therefore, by using the malicious code detection method provided in this embodiment, the characters of the above five categories are set to different colors, which can reflect the characteristics of the code to be detected about the above categories in the image to be detected, and further improve the accuracy of malicious code detection.

[0053] Optionally, in one embodiment, the first color, the second color, the third color, the fourth color and the fifth color are respectively one of red, yellow, blue, white and black.

[0054] Using the malicious code detection method provided in this embodiment, the colors of the image to be detected include red, yellow, blue, white and black, and the color values ​​of different colors vary greatly, which improves the accuracy of image classification, that is, improves the accuracy of malicious code detection.

[0055] Optionally, in one embodiment, the pixel group includes one pixel. The amount of data input into the image classification model can be reduced, thereby reducing the complexity of the image classification model and improving the detection efficiency of malicious code.

[0056] Optionally, in one embodiment, before the step of inputting the image to be detected into a preset classification model, the malicious code detection method also includes: obtaining a model training code sample set, wherein the model training code sample set includes multiple code samples, and the code samples include malicious samples and non-malicious samples; dividing the code samples into multiple training code segments, wherein the training code segments correspond to pixel groups; obtaining training characters at predetermined positions of the training code segments; determining color values ​​corresponding to the training characters; assigning values ​​to pixels according to the correspondence between the color values ​​corresponding to the training characters, the training code segments where the training characters are located, and the pixel groups, to obtain the image to be trained corresponding to the code sample; using the image to be trained as the input of the initial classification model, and using the code category corresponding to the code sample as the output of the initial classification model, and training the initial classification model to obtain an image classification model.

[0057] In the malicious code detection method provided in this embodiment, known malicious samples and non-malicious samples are obtained, processed separately to form training images, and the initial classification model is trained to form an image classification model that can be used to classify the images to be detected.

[0058] Optionally, in one embodiment, the picture to be trained is used as the input of the initial classification model, and the code category corresponding to the code sample is used as the output of the initial classification model. The step of training the initial classification model includes: setting the initial classification model to include M convolution blocks connected in sequence, each convolution block including several convolution layers; using the parameters of the pre-trained model trained by the ImageNet data set to initialize the parameters of the initial classification model to obtain an intermediate classification model; using the picture to be trained as the input of the intermediate classification model, and the code category corresponding to the code sample is used as the output of the intermediate classification model, freezing the parameters of the 1st to M-1th convolution blocks in the intermediate classification model to train the intermediate classification model.

[0059] In the malicious code detection method provided in this embodiment, when the final image classification model is obtained by training the initial classification model, the pre-trained model trained by the ImageNet data set is first used to initialize the parameters of the initial classification model. The initial classification model after the parameters are initialized is defined as an intermediate classification model. Then, a fine-tuning training method is used to freeze the parameters of the first part of the convolution block of the intermediate classification model, and the intermediate classification model is trained using the image to be trained to improve the accuracy of model training.

[0060] Embodiment 2

[0061] On the basis of the above-mentioned embodiment 1, embodiment 2 of the present invention provides an optimal malicious code detection method, which can be applied to the detection of unknown samples. When an unknown sample (that is, the code to be detected) is obtained, it can be first compared with the feature code of the malicious sample in the feature code library. When the unknown sample matches a feature code in the feature code library, it indicates that the unknown sample belongs to the threat category corresponding to this feature code; when the unknown sample does not match any feature code in the feature code library, the following steps are used to identify the unknown sample.

[0062] 1) First, the original code file of the unknown sample is divided into n segments to obtain n code segments, each of which represents a pixel.

[0063] 2) Then take the first character of each code segment, and use the value of this first character to indicate the color of the corresponding pixel. The specific mapping relationship is shown in Table 1 below.

[0064] Table 1 Character and color correspondence table

[0065] First character value Meaning Corresponding color x<33&x=127 Invisible ASCII code red 33≤x<127 Visible ASCII code blue 127<x<255 Non-ASCII Codes yellow x=0 Minimum black x=255 Maximum White

[0066] 3) Use the color corresponding to the first character to fill in the color of the pixel corresponding to the code segment where it is located.

[0067] By using the above three steps, the code source file of the unknown sample can be converted into an image. After obtaining the image, the trained image classification model can be used for classification and recognition.

[0068] The training process of the above-mentioned image classification model mainly includes sample sampling and downloading, sample preprocessing, model training and model effect verification, which can be described as follows:

[0069] Sample sampling: In the embodiment, malicious sample data and non-malicious sample data generated every day can be collected. In order to better show the characteristics of new samples, an unbalanced sampling method of new and old data is adopted, that is, the proportion of sampling new samples is larger, so that the characteristics of new samples are more obvious in the sample data set, so that the trained model can have a better classification effect on the newly appeared samples. The format of the sampling data is shown in Table 2 below.

[0070] Table 2 Sampling data format

[0071] index Timestamp Document Type MD5 1 2019-9-20 Worm 812f26eede8cd841**********

[0072] Download of samples: Figure 2As shown, first, the MD5 of the sample is automatically obtained one by one from the sampled MD5, and each MD5 identifier uniquely corresponds to the sample file. Then a download request is made to the file in the cloud. If the request is successful, the next step is entered. If the repeated request fails, the file is discarded. After the downloaded sample file is saved, the download identifier fed back by the cloud is used to verify whether the file is successfully downloaded. If it is successfully downloaded, the downloaded file is added to the sample library, otherwise the file is deleted and downloaded again. This step uses the method of multiple requests and verifications to reduce the possibility of download errors and ensure the quality of the sample data set.

[0073] Sample pretreatment: Figure 3 As shown, the binary sample files downloaded from the sample library are processed into images according to the same processing methods as steps 1) to 3) above. This not only reduces the size of the data set for easy storage, but also uses image processing methods to train the classification model. The preprocessed images form a preprocessed file library, and the preprocessed file library is divided into a data set to obtain a training set and a validation set.

[0074] Model training: For the images in the training set, the model is trained using the transfer learning method, that is, the parameters of the trained model are transferred to the new model to help the new model training. Considering that most image data or tasks are related, the knowledge that the model has learned can be shared with the new model in some way through transfer learning, thereby accelerating and optimizing the learning efficiency of the model. Figure 4 As shown, this embodiment adopts the model of vgg16, and the pre-trained data comes from ImageNet. Using the knowledge learned in advance from the ImageNet data set, plus the knowledge of malicious code and normal code obtained from the training data set pictures by fine-tuning methods, malicious code and normal code can be well distinguished. Since the model only needs to use shallow knowledge during fine-tuning, the parameters of convolution blocks 1 to 4 are frozen, and the parameters of convolution block 5 and the fully connected layer are constantly changing with model training. In the process of parameter fine-tuning, in order to prevent the parameters from changing too much and causing the training to not converge, the learning rate of the training is set to a smaller value of 0.0001.

[0075] Model verification: After the model training is completed, the classification effect of the image classification model is verified using the validation set Zhang Gong's pictures. If the accuracy rate is greater than 99%, it proves that the image classification model can be used to detect malicious code.

[0076] Embodiment 3

[0077] Corresponding to the above-mentioned embodiment 1, embodiment 3 of the present invention provides a malicious code detection device. The relevant technical features and corresponding technical effects can be referred to the above-mentioned embodiment 1 and embodiment 2, and will not be repeated here. Figure 5 A block diagram of a malicious code detection device provided in Embodiment 3 of the present invention is shown in FIG. Figure 5 As shown, the device includes: a segmentation module 301, an acquisition module 302, a mapping module 303, a conversion module 304 and a classification module 305.

[0078] Among them, the segmentation module 301 is used to divide the code to be detected into multiple code segments, wherein the code segment corresponds to a pixel group on a preset template image, and the pixel group includes a number of pixels; the acquisition module 302 is used to obtain the character at a predetermined position of the code segment; the mapping module 303 is used to determine the color value corresponding to the character according to a preset mapping rule; the conversion module 304 is used to assign values ​​to pixels according to the color value corresponding to the character, the correspondence between the code segment where the character is located and the pixel group, and obtain the image to be detected corresponding to the code to be detected; the classification module 305 is used to input the image to be detected into a preset image classification model, wherein the image classification model is used to classify the images corresponding to malicious code and the images corresponding to non-malicious code; the determination module 306 is used to determine that the code to be detected is malicious code when the image classification model outputs category information indicating that the image to be detected belongs to the image corresponding to the malicious code.

[0079] Furthermore, the mapping module 303 includes a first determination unit and a second determination unit, the first determination unit is used to determine the ASCII code category corresponding to the character; the second determination unit is used to determine the color value corresponding to the character according to the corresponding relationship between the ASCII category corresponding to the character, the preset ASCII code category and the color.

[0080] Furthermore, when the second determination unit determines the color value corresponding to the character according to the correspondence between the ASCII category corresponding to the character, the preset ASCII code category and the color, the specific steps performed include: when the character is greater than 0 and the corresponding ASCII category belongs to the invisible ASCII code, determining that the character corresponds to the first color; when the ASCII category corresponding to the character belongs to the visible ASCII code, determining that the character corresponds to the second color; when the character is less than 255 and does not belong to the ASCII code, determining that the character corresponds to the third color; when the character is equal to 0, determining that the character corresponds to the fourth color; and when the character is equal to 255, determining that the character corresponds to the fifth color, wherein the first color, the second color, the third color, the fourth color and the fifth color are different.

[0081] Further, the first color, the second color, the third color, the fourth color and the fifth color are respectively one of red, yellow, blue, white and black.

[0082] Further, a pixel group includes one pixel.

[0083] Furthermore, the malicious code detection device also includes a training module, which is used to perform the following steps before the classification module 305 inputs the image to be detected into a preset classification model: obtaining a model training code sample set, wherein the model training code sample set includes multiple code samples, and the code samples include malicious samples and non-malicious samples; dividing the code samples into multiple training code segments, wherein the training code segments correspond to pixel groups; obtaining training characters at predetermined positions of the training code segments; determining color values ​​corresponding to the training characters; assigning values ​​to pixels according to the corresponding relationship between the color values ​​corresponding to the training characters, the training code segments where the training characters are located, and the pixel groups, to obtain the image to be trained corresponding to the code samples; using the image to be trained as the input of the initial classification model, and using the code category corresponding to the code sample as the output of the initial classification model, and training the initial classification model to obtain an image classification model.

[0084] Furthermore, in the training module, the image to be trained is used as the input of the initial classification model, and the code category corresponding to the code sample is used as the output of the initial classification model. When the initial classification model is trained, the specific steps include: setting the initial classification model to include M convolution blocks connected in sequence, each convolution block including several convolution layers; using the parameters of the pre-trained model trained by the ImageNet dataset to initialize the parameters of the initial classification model to obtain an intermediate classification model; using the image to be trained as the input of the intermediate classification model, and the code category corresponding to the code sample is used as the output of the intermediate classification model, freezing the parameters of the 1st to M-1th convolution blocks in the intermediate classification model to train the intermediate classification model.

[0085] Embodiment 4

[0086] This fourth embodiment also provides a computer device, such as a smart phone, tablet computer, laptop computer, desktop computer, rack server, blade server, tower server or cabinet server (including an independent server or a server cluster composed of multiple servers) that can execute programs. Figure 6 As shown, the computer device 01 of this embodiment includes at least but is not limited to: a memory 011 and a processor 012 which can be interconnected via a system bus. Figure 6 It should be pointed out that Figure 6 Only a computer device 01 having components memory 011 and processor 012 is shown, but it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.

[0087] In this embodiment, the memory 011 (i.e., readable storage medium) includes flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 011 can be an internal storage unit of the computer device 01, such as a hard disk or memory of the computer device 01. In other embodiments, the memory 011 can also be an external storage device of the computer device 01, such as a plug-in hard disk equipped on the computer device 01, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. Of course, the memory 011 can also include both the internal storage unit of the computer device 01 and its external storage device. In this embodiment, the memory 011 is generally used to store the operating system and various application software installed on the computer device 01, such as the program code of the malicious code detection device of the third embodiment. In addition, the memory 011 can also be used to temporarily store various types of data that have been output or are to be output.

[0088] In some embodiments, the processor 012 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. The processor 012 is generally used to control the overall operation of the computer device 01. In this embodiment, the processor 012 is used to run the program code stored in the memory 011 or process data, such as a method for detecting malicious code.

[0089] Embodiment 5

[0090] The fifth embodiment also provides a computer-readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a disk, an optical disk, a server, an App application store, etc., on which a computer program is stored, and the program implements a corresponding function when executed by a processor. The computer-readable storage medium of the present embodiment is used to store a detection device for malicious code, and when executed by a processor, the detection method for malicious code of the first embodiment is implemented.

[0091] 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.

[0092] 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.

[0093] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above 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.

[0094] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A method for detecting malicious code, characterized in that: include: Dividing the code to be detected into a plurality of code segments, wherein the code segment corresponds to a pixel group on a preset template image, and the pixel group includes a plurality of pixels; Obtaining a character at a predetermined position of the code segment; Determine the color value corresponding to the character according to a preset mapping rule; Assign values ​​to the pixels according to the color value corresponding to the character, the corresponding relationship between the code segment where the character is located and the pixel group, and obtain the image to be detected corresponding to the code to be detected; Inputting the image to be detected into a preset image classification model, wherein the image classification model is used to classify images corresponding to malicious code and images corresponding to non-malicious code; When the image classification model outputs category information indicating that the image to be detected belongs to an image corresponding to malicious code, it is determined that the code to be detected is malicious code.

2. The method for detecting malicious code according to claim 1, characterized in that: The step of determining the color value corresponding to the character according to a preset mapping rule comprises: Determine the ASCII code category corresponding to the character; and The color value corresponding to the character is determined according to the ASCII code category corresponding to the character and the corresponding relationship between the preset ASCII code category and the color.

3. The method for detecting malicious code according to claim 2, characterized in that: The step of determining the color value corresponding to the character according to the corresponding relationship between the ASCII category corresponding to the character and the preset ASCII code category and the color comprises: When the character is greater than 0 and the corresponding ASCII category belongs to the invisible ASCII code, determining that the character corresponds to the first color; When the ASCII category corresponding to the character belongs to a visible ASCII code, determining that the character corresponds to a second color; When the character is less than 255 and does not belong to the ASCII code, determining that the character corresponds to a third color; When the character is equal to 0, determining that the character corresponds to a fourth color; and When the character is equal to 255, it is determined that the character corresponds to a fifth color, wherein the first color, the second color, the third color, the fourth color and the fifth color are different.

4. The method for detecting malicious code according to claim 3, characterized in that: The first color, the second color, the third color, the fourth color and the fifth color are respectively one of red, yellow, blue, white and black.

5. The method for detecting malicious code according to claim 1, characterized in that: The pixel group includes one pixel.

6. The method for detecting malicious code according to claim 1, characterized in that: Before the step of inputting the image to be detected into a preset classification model, the malicious code detection method further includes: Obtain a model training code sample set, wherein the model training code sample set includes a plurality of code samples, and the code samples include malicious samples and non-malicious samples; Dividing the code sample into a plurality of training code segments, wherein the training code segments correspond to the pixel groups; Obtaining a training character at a predetermined position of the training code segment; Determine the color value corresponding to the training character; Assigning values ​​to the pixels according to the color value corresponding to the training character, the corresponding relationship between the training code segment where the training character is located and the pixel group, and obtaining a to-be-trained picture corresponding to the code sample; The image to be trained is used as the input of an initial classification model, the code category corresponding to the code sample is used as the output of the initial classification model, and the initial classification model is trained to obtain the image classification model.

7. The method for detecting malicious code according to claim 6, characterized in that: The image to be trained is used as the input of the initial classification model, and the code category corresponding to the code sample is used as the output of the initial classification model. The step of training the initial classification model includes: Setting the initial classification model to include M convolution blocks connected in sequence, each of the convolution blocks including a plurality of convolution layers; Initializing the parameters of the initial classification model using the parameters of the pre-trained model trained by the ImageNet dataset to obtain an intermediate classification model; The image to be trained is used as the input of the intermediate classification model, the code category corresponding to the code sample is used as the output of the intermediate classification model, and the parameters of the 1st to M-1th convolution blocks in the intermediate classification model are frozen to train the intermediate classification model.

8. A malicious code detection device, characterized in that: include: A segmentation module, used for dividing the code to be detected into a plurality of code segments, wherein the code segment corresponds to a pixel group on a preset template image, and the pixel group includes a plurality of pixels; An acquisition module, used for acquiring characters at predetermined positions of the code segment; A mapping module, used to determine the color value corresponding to the character according to a preset mapping rule; A conversion module, used for assigning values ​​to the pixels according to the color value corresponding to the character, the corresponding relationship between the code segment where the character is located and the pixel group, to obtain a picture to be detected corresponding to the code to be detected; A classification module, used for inputting the to-be-detected image into a preset image classification model, wherein the image classification model is used for classifying images corresponding to malicious codes and images corresponding to non-malicious codes; The determination module is used to determine that the code to be detected is malicious code when the image classification model outputs category information indicating that the image to be detected belongs to an image corresponding to malicious code.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.