Malicious code detection method and device
By using tag words to explain the reason for the code attribution in the malicious code detection system, the problem of unexplainable detection results in traditional detection methods is solved, and the reliability of malicious code detection is improved.
Patent Information
- Application Number
- CN202410850938.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-11-08
AI Technical Summary
Traditional malicious code detection methods cannot explain the reasons for the detection results, resulting in poor interpretability of the detection results and affecting their reliability.
The malicious code detection system stores the corresponding tag words for at least two preset categories, determine the code attribute category by matching probability, and explain the code attribute reasons based on the corresponding tag words, so as to improve the interpretability of the detection results.
Explain the reasons for the code attribution through tag words, the interpretability of malicious code detection results is improved, the reliability of detection results is enhanced, and security risks are reduced.
Smart Images

Figure CN118916874A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network security technology, and in particular to a malicious code detection method and device. Background Art
[0002] With the rapid development of network technology, the types and quantity of malicious codes have shown explosive growth, resulting in increasing losses caused by malicious codes. In order to reduce the losses caused by malicious codes, malicious code detection is required to detect malicious codes in a timely manner and take corresponding measures.
[0003] However, after performing malicious code detection on the code, the traditional malicious code detection method can only give a detection result of whether the code is malicious code, but the interpretability is poor, resulting in the inability to verify the reliability of the code detection result, thus bringing security risks. Summary of the invention
[0004] In view of this, the present application proposes a malicious code detection method and device, the main purpose of which is to explain the reasons for obtaining malicious code detection results and improve the interpretability of malicious code detection results.
[0005] In order to achieve the above objectives, this application mainly provides the following technical solutions:
[0006] In a first aspect, the present application provides a malicious code detection method, which is applied to a malicious code detection system, wherein the malicious code detection system stores label words corresponding to codes of at least two preset categories, wherein the at least two preset categories include malicious categories and non-malicious categories, and the label words are used to explain why the corresponding code belongs to the corresponding preset category. The malicious code detection method includes:
[0007] When malicious code detection is required for the target code, determining the matching probability between each label word of a preset category and the target code;
[0008] Based on the matching probability, determining a target preset category to which the target code belongs;
[0009] If the target preset category is a malicious category, then based on the label word corresponding to the malicious category, explain the reason why the target code belongs to the malicious category;
[0010] If the target preset category is a non-malicious category, then based on the label word corresponding to the non-malicious category, the reason why the target code belongs to the non-malicious category is explained.
[0011] In a second aspect, the present application provides a malicious code detection device, which is applied to a malicious code detection system, wherein the malicious code detection system stores label words corresponding to codes of at least two preset categories, wherein the at least two preset categories include malicious categories and non-malicious categories, and the label words are used to explain why the corresponding code belongs to the corresponding preset category. The malicious code detection device includes:
[0012] A first determination module is used to determine the matching probability between each label word of a preset category and the target code when malicious code detection is required for the target code;
[0013] A second determination module is used to determine the target preset category to which the target code belongs based on the matching probability;
[0014] A first explanation module, configured to explain, if the target preset category is a malicious category, the reason why the target code belongs to the malicious category based on a label word corresponding to the malicious category;
[0015] The second explanation module is used to explain the reason why the target code belongs to the non-malicious category based on the label word corresponding to the non-malicious category if the target preset category is the non-malicious category.
[0016] In a third aspect, the present application provides a computer-readable storage medium, wherein the storage medium includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the malicious code detection method described in the first aspect.
[0017] In a fourth aspect, the present application provides an electronic device, comprising: a memory for storing a program; and a processor, coupled to the memory, for running the program to execute the malicious code detection method described in the first aspect.
[0018] The malicious code detection method and device provided by the present application store label words corresponding to at least two preset categories of code in a malicious code detection system, so as to explain the reason why the corresponding code belongs to the corresponding preset category through the label words. When it is necessary to perform malicious code detection on the target code, the matching probability of each label word of each preset category stored in the malicious code detection system and the target code is determined, and the target preset category to which the target code belongs is determined based on the matching probability of each label word and the target code. If the target preset category is a malicious category included in the preset categories stored in the malicious code detection system, then based on the label words corresponding to the malicious category, the reason why the target code belongs to the malicious category is explained. If the target preset category is a non-malicious category included in the preset categories stored in the malicious code detection system, then based on the label words corresponding to the non-malicious category, the reason why the target code belongs to the non-malicious category is explained. It can be seen that the solution provided by the present application stores two or more preset categories in the malicious code detection system in advance, and sets corresponding label words for the codes of each preset category. In this way, after malicious code detection is performed on the code to obtain the detection result of the target preset category to which the code belongs, the reason why the code belongs to the target preset category can be explained based on the label words corresponding to the target preset category, thereby improving the interpretability of the detection result that the code belongs to the target preset category, and then facilitating the subsequent verification of the reliability of the detection result that the code belongs to the target preset category based on the explained reasons.
[0019] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0021] Figure 1 A flowchart of a malicious code detection method provided by an embodiment of the present application is shown;
[0022] Figure 2 A schematic diagram showing a process of presetting label words corresponding to codes of at least two preset categories provided by an embodiment of the present application;
[0023] Figure 3 A schematic diagram of a malicious code detection process provided by an embodiment of the present application is shown;
[0024] Figure 4 A schematic diagram of the structure of a malicious code detection device provided by an embodiment of the present application is shown;
[0025] Figure 5 A schematic structural diagram of a malicious code detection device provided in another embodiment of the present application is shown. DETAILED DESCRIPTION
[0026] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0027] Traditional malicious code detection methods (for example, using machine learning models for malicious code detection) can only give a detection result of whether the code is malicious code after malicious code detection, but cannot give the reason for the detection result. The detection result is less interpretable, making it impossible to verify the reliability of the code detection result, thus posing a security risk.
[0028] After research, it was found that if the reasons for obtaining the detection results of the code are explained at the same time, the interpretability of the detection results can be improved, making it easier to verify the reliability of the code detection results based on the reasons.
[0029] Based on the above findings, the present application considers planning two or more preset categories in advance, and planning the corresponding label words for the codes of each preset category, and the label words are used to explain the reason why the corresponding code belongs to the corresponding preset category. In this way, after the malicious code detection is performed on the code to obtain the detection result that the code belongs to the target preset category, the reason why the code belongs to the target preset category can be explained based on the label words corresponding to the target preset category, thereby improving the interpretability of the detection result that the code belongs to the target preset category, and then facilitating the subsequent verification of the reliability of the detection result that the code belongs to the target preset category based on the explained reasons.
[0030] Based on the above considerations, an embodiment of the present application specifically provides a technical solution for malicious code detection, specifically: a malicious code detection system stores label words corresponding to at least two preset categories of codes, at least two preset categories include a malicious category and a non-malicious category, and the label words are used to explain the reason why the corresponding code belongs to the corresponding preset category; when malicious code detection is required for the target code, the matching probability of each label word of the preset category and the target code is determined; based on the matching probability, the target preset category to which the target code belongs is determined; if the target preset category is a malicious category, based on the label words corresponding to the malicious category, the reason why the target code belongs to the malicious category is explained; if the target preset category is a non-malicious category, based on the label words corresponding to the non-malicious category, the reason why the target code belongs to the non-malicious category is explained.
[0031] The technical solution for malicious code detection provided in this embodiment can be applied to any network system to detect malicious code in the code in the network system. The network system can be a cloud system or a local system, and this embodiment does not specifically limit this. Based on the technical solution for malicious code detection provided in this embodiment, this embodiment specifically proposes a malicious code detection method and device, and the malicious code detection method and device provided in this embodiment are specifically described below.
[0032] like Figure 1 As shown, the embodiment of the present application provides a malicious code detection method, which mainly includes the following steps 101 to 104:
[0033] 101. When malicious code detection is required for a target code, the matching probability between each label word of a preset category and the target code is determined.
[0034] The malicious code detection method provided in this embodiment is applied to a malicious code detection system. The malicious code detection system stores label words corresponding to at least two preset categories of code. The label words are used to explain the reason why the corresponding code belongs to the corresponding preset category, so that the malicious code detection system can detect the target preset category to which the code belongs and explain the reason why the code belongs to the target preset category when performing malicious code detection on the code in the associated network system based on the label words corresponding to the stored at least two preset categories of code, thereby improving the interpretability of the malicious code detection results.
[0035] At least two preset categories stored in the malicious code detection system include malicious categories and non-malicious categories. The number of preset categories is related to the classification requirements of malicious code detection, and there are the following two situations: one is that the classification requirement is a two-classification requirement, and two preset categories are stored in the malicious code detection system. Exemplarily, the malicious code detection system stores preset category 1 and preset category 2, wherein preset category 1 is a malicious category, and preset category 2 is a non-malicious category. In this way, after determining the target preset category to which the target code belongs, it is possible to determine whether the target code is malicious code through the target preset category. The other is that the classification requirement is a multi-classification requirement, and more than two preset categories are stored in the malicious code detection system. Exemplarily, the malicious code detection system stores preset categories 1 to preset categories 6, and preset categories 2 to preset categories 6 are computer viruses, Trojans, computer worms, logic bombs, and backdoors, respectively, wherein preset category 1 is a non-malicious category, and preset category 2 to preset category 6 are malicious categories. In this way, after determining the target preset category to which the target code belongs, it is possible not only to determine whether the target code is malicious code through the target preset category, but also to determine what type of malicious code the target code is when it is malicious code.
[0036] The malicious code detection system stores the label words corresponding to each preset category of code. The label words are used to explain why the corresponding code belongs to the corresponding preset category, and the label words are obtained by abstracting the code features of the code belonging to the corresponding preset category. It should be noted that in order to more clearly explain why the code belongs to the target preset category, the label words corresponding to the codes of different preset categories have a clear degree of distinction, that is, the label words corresponding to the codes of different preset categories are different. The label words corresponding to the preset category of code need to be adapted to the language used by the network system associated with the malicious code detection system, so that the malicious code detection system can perform malicious code detection on the code in the network system based on the label words corresponding to the preset category of code.
[0037] The label words corresponding to each preset category of code need to accurately abstract the code features of the corresponding preset category of code. Exemplarily, the malicious code detection system stores label words corresponding to two preset categories of code, wherein one preset category is the malicious category, and the label words corresponding to the malicious category of code include: sensitive data leakage, malicious process injection, and bounce port. The other preset category is the non-malicious category, and the label words corresponding to the non-malicious category of code include: authorized reading and legal input.
[0038] When there is a target code that needs to be detected for malicious code, malicious code detection can be performed on the target code based on label words corresponding to at least two preset categories of code stored in the malicious code detection system.
[0039] Malicious code can be spread through a variety of objects such as emails, web pages, files, applications, and application scripts, so the corresponding codes of these objects can be used as target codes to detect malicious code on the target codes. It should be noted that in order to ensure the accuracy of malicious code detection, after determining the target code, the malicious code detection method can also include the following steps: determining whether the target code is a text code, and if not, converting the target code into text form.
[0040] In order to facilitate the determination of the matching probability between each label word of the preset category and the target code, the target code needs to be in text form. Therefore, if the target code is determined to be a non-text code such as binary form, it is necessary to convert the target code into text form through a preset conversion tool (for example, decompilation software).
[0041] Furthermore, if the target code is determined to be in text form, in order to reduce the interference of data in the target code that is irrelevant to malicious code detection on malicious code detection, these data are deleted from the target code. These data may include but are not limited to comment data in the code.
[0042] When it is determined that malicious code detection is required for the target code, the matching probability between each label word of the preset category and the target code is determined, so as to determine the target preset category to which the target code belongs from the preset categories based on the matching probability between the label word and the target code. The matching probability is used to reflect the matching degree between the corresponding label word and the target code, and the matching probability provides a basis for determining the target preset category to which the code belongs.
[0043] The specific process of determining the matching probability between each tag word of the preset category and the target code may include the following steps 101A to 101C:
[0044] 101A. Detect the occurrence probability of each word-gram related to a code of a preset category in the target word-gram set in the target code.
[0045] The label word is obtained by abstracting the code features of the code belonging to the corresponding preset category. In order to facilitate the clarification of the matching probability between the label word and the target code, a target word element set is preset in the malicious code detection system. The target word element set includes words related to the preset category of code, and the target word element set includes the first word element corresponding to the label word, and the first word element is used to describe the code features abstracted by the corresponding label word. For any label word, the probability of occurrence of the word element corresponding to the label word in the target code determines the matching situation between the label word and the target code. Therefore, it is necessary to detect the probability of occurrence of each word element related to the preset category of code in the target word element set in the target code, so as to determine the probability of occurrence of the first word element corresponding to each label word from the probability of occurrence of the word element, and determine the matching probability of each label word with the target code based on the probability of occurrence of the first word element.
[0046] In order to quickly detect the probability of occurrence of each word related to the preset category of code in the target word set in the target code, the malicious code detection system is preset with a target model, which is used to identify the probability of occurrence of each word related to the preset category of code in the target word set in the code. The type of target model can be selected based on business needs, and this embodiment does not limit this. Exemplarily, the target model can be a large model with prompt learning capabilities including but not limited to the BERT family.
[0047] The specific process of detecting the probability of occurrence of each word in the target word set related to the preset category of code in the target code may include the following steps: inputting the target code into the target model, and identifying the probability of occurrence of each word in the target word set related to the preset category of code in the target code through the target model.
[0048] 101B. Determine the occurrence probability of the first word-gram corresponding to each tag word from the occurrence probabilities of the word-grams.
[0049] The matching probability between the tag word and the target code is determined based on the occurrence probability of the first word unit corresponding to the tag word. Therefore, the occurrence probability of the first word unit corresponding to each tag word needs to be determined from the occurrence probability of the word unit.
[0050] Before determining the occurrence probability of the first word-gram corresponding to each tag word from the occurrence probability of the word-gram, it is necessary to determine the first word-gram corresponding to each tag word. The specific process of determining the first word-gram corresponding to each tag word is to perform the following steps 101B1 to 101B4 for each tag word:
[0051] 101B1. Match the label word with each word in the target word set that is related to the code of the preset category; if the label word matches the word, determine the corresponding word as the first word corresponding to the label word; if the label word does not match the word, execute step 101B2.
[0052] The specific process of matching the tag word with each word related to the code of the preset category in the target word element set is as follows: detect whether there is a word element identical to the tag word in the target word element set; if there is an identical word element, determine the corresponding word element as the first word element corresponding to the tag word; if there is no identical word element, detect whether there is a word element containing the tag word in the target word element set; if there is a word element containing the tag word, determine the corresponding word element as the first word element corresponding to the tag word; if there is no word element containing the tag word, it means that the first word element corresponding to the tag word cannot be determined by matching the tag word with each word element related to the code of the preset category in the target word element set, and it is necessary to determine the first word element corresponding to the tag word through step 101B2. The word element containing the tag word in the target word element set is essentially the tag word existing in the word element in the form of a character substring.
[0053] 101B2. Based on the code features abstracted by the label word, a label word associated with the label word is derived, and the associated label word is matched with each word-element in the target word-element set that is related to the code of a preset category; if the associated label word matches a word-element, the corresponding word-element is determined as the first word-element related to the label word; if the associated label word does not match a word-element, it is determined that there is no related first word-element for the label word.
[0054] The label word is obtained by abstracting the code features of the codes belonging to the corresponding preset categories. If the label word does not match a word in the target word set, the label word associated with the label word can be derived based on the features abstracted by the label word. There are several cases of associated label words: First, the code features abstracted by the label word are the same as the code features abstracted by the associated label word, but the label word and the associated label word use different expressions for the same code features. Second, the code features abstracted by the associated label word are features associated with the code features abstracted by the label word, that is, the code features abstracted by the associated label word are associated with the code features abstracted by the label word.
[0055] The specific process of deriving tag words associated with the tag words based on the code features abstracted by the tag words may include: obtaining a model for deriving tag words, and deriving tag words associated with the tag words through the model based on the tag words and the code features abstracted by the tag words.
[0056] After deriving the associated label word, the associated label word is matched with each word in the target word set that is associated with the code of the preset category. The matching process is basically the same as the process of matching the label word with each word in the target word set that is associated with the code of the preset category in 101B1, so it will not be repeated here.
[0057] If the associated tag word matches a word-gram, the corresponding word-gram is determined as the first word-gram associated with the tag word. If the associated tag word does not match a word-gram, it is determined that there is no first word-gram associated with the tag word.
[0058] Furthermore, considering that some label words may be long words or compound words, and word-grams are usually short words, it is difficult for label words to be matched to word-grams in the preset word-gram set. Therefore, in order to enable label words that are long words or compound words to be matched to the first word-gram, after the above step 101B2 fails to match the word-gram, before determining that the label word does not have a related first word-gram, the malicious code detection method may also include the following steps: split the label word into at least two second word-grams, and match each second word-gram with each word-gram related to the preset category of code in the target word-gram set; if each second word-gram matches the word-gram, the corresponding word-gram is determined as the first word-gram related to the label word; if there is a second word-gram that is not matched to the word-gram, the step of determining that the label word does not have a related first word-gram is executed.
[0059] The specific process of splitting the label word into at least two second word units may be: obtaining a word splitting tool, and splitting the label word into at least two second word units by using the word splitting tool.
[0060] After splitting to obtain the second word-grams, each second word-gram is matched with each word-gram related to the code of the preset category in the target word-gram set. The matching process of each second word-gram is basically the same as the process of matching the label word with each word-gram related to the code of the preset category in 101B1, so it will not be repeated here.
[0061] If each second word-gram is matched to a word-gram, it means that the word-grams matched to all the second word-grams can restore the tag word, so the corresponding word-gram is determined as the first word-gram related to the tag word.
[0062] If there is a second word that is not matched to a word, at this time, if the label word can be split into a combination of second word segments that are different from the previously split second word segments, the label word is split again, and then the re-split second word segments are matched with the word segments in the target word set. If the label word cannot be split again to form a new second word segment combination, it means that all possible second word segments of the label word have not been matched to a word, so the step of determining that there is no related first word segment for the label word is performed.
[0063] Furthermore, considering that the associated label word may also be a long word or a compound word, in order to determine the first word corresponding to the label word as much as possible, after there is a second word that is not matched to a word, before executing the step of determining that there is no related first word for the label word, the malicious code detection method may also include the following steps: split the associated label word into at least two third words, and match each third word with each word related to the preset category of code in the target word set; if each third word is matched to a word, the corresponding word is determined as the first word related to the label word; if there is a third word that is not matched to a word, the step of determining that there is no related first word for the label word is executed.
[0064] After the above step of determining the first word-gram corresponding to the label word, if the first word-gram related to the label word is determined, the occurrence probability of the first word-gram corresponding to each label word is determined from the occurrence probability of the word-gram. If it is determined that there is no corresponding first word-gram for the label word, the preset probability is determined as the matching probability of the label word to ensure that each label word of the preset category can have a corresponding matching probability. The preset probability is used to characterize the mismatch between the label word and the target code, and its specific value can be flexibly set based on business needs, and this embodiment does not limit this.
[0065] In order to facilitate the determination of the occurrence probability of the first word element corresponding to each label word, the target model also has the ability to determine the occurrence probability of the first word element corresponding to each label word from the occurrence probability of the word element. Therefore, the specific execution process of step 101B can be: determining the occurrence probability of the first word element corresponding to each label word from the occurrence probability of the word element through the target model.
[0066] Furthermore, in order to make the target model aware of which label words need to determine the occurrence probability of the first word-unit, the label words corresponding to at least two preset categories of codes stored in the malicious code detection system in this embodiment are preset in the mapper, and the mapper is bound to the target model. In this way, before determining the occurrence probability of the first word-unit corresponding to each label word from the occurrence probability of the word-unit through the target model, each label word corresponding to the preset category is read from the mapper through the target model, so that the target model can learn from the mapper the label words for which the occurrence probability of the corresponding first word-unit needs to be determined.
[0067] This embodiment binds the mapper to the target model, which can achieve zero-sample classification. That is, after selecting the target model, there is no need to fine-tune the target model for the task or modify its parameters. By binding the target model to the mapper, the target model can be informed of all the label words required to determine the target preset category to which the target code belongs, and the probability of occurrence of the first word element corresponding to each label word can be determined from the probability of occurrence of the word element. If the malicious code detection business changes in the future, there is no need to adjust the target model. Based on the label words corresponding to the preset category of code stored in the malicious code detection system after the change, the mapper can be modified to meet the changed malicious code detection business. In this way, only one target model needs to be maintained, which can reduce the storage overhead of storing the target model.
[0068] 101C. Based on the occurrence probability of the first word, determine the matching probability of each tag word and the target code.
[0069] Based on the occurrence probability of the first word, the specific process of determining the matching probability of each label word and the target code is to perform the following steps for each label word:
[0070] If there are multiple first word-grams corresponding to the label word, the average of the occurrence probabilities of the multiple first word-grams corresponding to the label word is determined as the matching probability between the label word and the target code. The occurrence probability of the first word-gram corresponding to the label word in the target code determines the matching situation between the label word and the target code, so the average of the occurrence probabilities of the multiple first word-grams corresponding to the label word is determined as the matching probability between the label word and the target code.
[0071] If the first word element corresponding to the label word is one, the occurrence probability of the first word element corresponding to the label word is directly determined as the matching probability between the label word and the target code.
[0072] 102. Based on the matching probability, determine the target preset category to which the target code belongs. If the target preset category is a malicious category, execute step 103; if the target preset category is a non-malicious category, execute step 104.
[0073] The matching probability between the tag word and the target code reflects the matching degree between the tag word and the target code. The matching probability provides a basis for determining the target preset category to which the code belongs. Therefore, after determining the matching probability between each tag word of the preset category and the target code, the target preset category to which the target code belongs can be determined based on the matching probability. The specific process of determining the target preset category to which the target code belongs based on the matching probability between the tag word and the target code may include the following steps 102A to 102D:
[0074] 102A. Sort each tag word corresponding to at least two preset categories in descending order of matching probability.
[0075] There are multiple label words corresponding to each preset category. The higher the matching probability, the higher the matching degree between the label word and the target code. Therefore, each label word corresponding to all preset categories is sorted in order of matching probability from large to small, so as to intuitively clarify the matching degree between each label word and the target code through sorting.
[0076] 102B, detecting whether the tag words ranked in the first second number of digits correspond to the same preset category, if so, executing step 102C; if not, executing step 102D.
[0077] Considering that if the target code belongs to a preset category, the probability of a certain number of label words in the corresponding label words of the preset category matching the target code will be greater than the probability of matching the label words of other preset categories with the target code, the target preset category to which the target code belongs can be determined by detecting whether the label words ranked in the first second number of positions correspond to the same preset category. The second number is a number calibrated in advance by the matching probability of the label words of each preset category and the sample code belonging to each preset category. Each preset category has a corresponding total number of label words, and the second number is not greater than the minimum total number of label words in the total number of label words.
[0078] If it is detected that the label words ranked in the first second digits correspond to the same preset category, it means that the target code is likely to belong to this preset category, and the preset category can be determined as the target preset category to which the target code belongs, so step 102C is executed.
[0079] If it is detected that the tag words ranked in the first second number of digits do not correspond to the same preset category, it means that the preset category to which the target code belongs cannot be determined yet, and other methods are needed to determine the target preset category to which the target code belongs, so step 102D is executed.
[0080] 102C. Determine the corresponding preset category as the target preset category to which the target code belongs.
[0081] 102D. Summarize the matching probabilities of each tag word corresponding to each preset category to obtain the sum of matching probabilities corresponding to each preset category, and determine the preset category corresponding to the highest matching probability in the matching probability sum as the target preset category to which the target code belongs.
[0082] For any preset category, the sum of the matching probabilities of each tag word corresponding to the preset category can reflect the possibility that the target code belongs to the preset category. The higher the sum of the matching probabilities, the greater the possibility that the target code belongs to the preset category. Therefore, when it is detected that the tag words ranked in the first second number of digits do not correspond to the same preset category, the matching probabilities of each tag word corresponding to each preset category can be further summarized and processed to obtain the sum of the matching probabilities corresponding to each preset category, so as to determine the target preset category to which the target code belongs through the sum of the matching probabilities.
[0083] The matching probability of each tag word corresponding to each preset category is summarized and processed respectively. Methods for obtaining the sum of the matching probabilities corresponding to each preset category may include the following two methods:
[0084] One is to calculate the sum of the matching probabilities of each tag word corresponding to each preset category, and obtain the sum of the matching probabilities corresponding to each preset category. That is, for each preset category, the matching probabilities of each tag word corresponding to the preset category are summed up to obtain the sum of the matching probabilities corresponding to the preset category.
[0085] Another method is to determine the weight of each tag word in the corresponding preset category; based on the corresponding weight, calculate the weighted sum of the matching probability of each tag word corresponding to each preset category, and obtain the sum of the matching probabilities corresponding to each preset category.
[0086] For a preset category, the correlation between each tag word corresponding to the preset category and the preset category may be different. Therefore, in order to more accurately determine the sum of matching probabilities corresponding to each preset category, it is necessary to consider the correlation between the tag word and the corresponding preset category, and the correlation can be reflected by the weight of the tag word in the corresponding preset category.
[0087] The weight of each tag word in the corresponding preset category can be preset in advance. Therefore, for each preset category, when calculating the sum of matching probabilities corresponding to the preset category, the weight of each tag word corresponding to the preset category in the preset category is determined. Based on the matching probability and weight of each tag word, the weighted sum of the matching probabilities of each tag word corresponding to the preset category is calculated to obtain the sum of matching probabilities corresponding to the preset category.
[0088] The above two methods for obtaining the corresponding sum of matching probabilities for each preset category can be flexibly selected based on business needs, and this embodiment is limited to this.
[0089] After obtaining the corresponding sum of matching probabilities for each preset category, the target preset category to which the target code belongs can be determined based on the sum of matching probabilities. The higher the sum of matching probabilities, the greater the possibility that the target code belongs to the corresponding preset category. Therefore, in order to more accurately determine the target preset category to which the target code belongs, the preset category corresponding to the highest sum of matching probabilities in the sum of matching probabilities is determined as the target preset category to which the target code belongs.
[0090] Furthermore, the malicious code detection system may also store the minimum proportions corresponding to at least two preset categories, and the minimum proportion is the proportion of label words whose matching probability is not less than the second probability threshold in the label words corresponding to the preset category. For any preset category, if the proportion of label words whose matching probability is not less than the second probability threshold in the label words corresponding to the preset category is not less than the corresponding minimum proportion of the preset category, it means that the target code belongs to the preset category with a high probability. Therefore, after the above 102B detects that the label words ranked in the first second number of digits do not correspond to the same preset category, and before step 102D, the malicious code detection method may also include the following steps: determine the target proportion of label words whose matching probability is not less than the second probability threshold in the label words corresponding to each preset category, so as to determine the target preset category to which the target code belongs based on the size relationship between the target proportion of each preset category and the corresponding minimum proportion. The situations for determining the target preset category to which the target code belongs include the following three:
[0091] First, if there is a preset category with a target ratio higher than the corresponding minimum ratio, and the preset category with a target ratio higher than the corresponding minimum ratio includes a malicious category, the corresponding malicious category is determined as the target preset category to which the target code belongs.
[0092] There are two situations in which the preset categories with target ratios higher than the corresponding minimum ratio include malicious categories: first, the preset categories with target ratios higher than the corresponding minimum ratio only include malicious categories; second, the preset categories with target ratios higher than the corresponding minimum ratio include malicious categories and non-malicious categories.
[0093] Taking into account that malicious code can cause serious network hazards, when the preset categories with a target ratio higher than the corresponding minimum ratio include malicious categories, the corresponding malicious category will be determined as the target preset category to which the target code belongs. This facilitates timely disposal of the malicious code and reduces the possibility of missing detection of the malicious code.
[0094] Second, if there is a preset category with a target ratio higher than the corresponding minimum ratio, and the preset category with a target ratio higher than the corresponding minimum ratio includes non-malicious categories and does not include malicious categories, the corresponding non-malicious category is determined as the target preset category to which the target code belongs.
[0095] The preset categories whose target ratio is higher than the corresponding minimum ratio include non-malicious categories and do not include malicious categories, indicating that the preset categories whose target ratio is higher than the corresponding minimum ratio are non-malicious categories, and the possibility that the target code belongs to the malicious category is small, so the corresponding non-malicious category is determined as the target preset category to which the target code belongs.
[0096] Third, if there is no preset category whose target ratio is higher than the corresponding minimum ratio, step 102D is executed to summarize the matching probability of each label word corresponding to each preset category to obtain the sum of the matching probabilities corresponding to each preset category.
[0097] If there is no preset category with a target ratio higher than the corresponding minimum ratio, it means that the preset category to which the target code belongs cannot be clearly determined based on the target ratio of the preset category. Therefore, it is necessary to continue to execute step 102D to determine the target preset category to which the target code belongs by summing the corresponding matching probabilities of each preset category.
[0098] 103. Based on the corresponding label words of the malicious category, explain why the target code belongs to the malicious category.
[0099] After determining the target preset category to which the target code belongs based on the matching probability between each label word and the target code, if the target preset category is a malicious category, the reason why the target code belongs to the malicious category is explained based on the label word corresponding to the malicious category, so as to explain the reason why the target code belongs to the malicious category, thereby improving the interpretability of the detection result and facilitating the subsequent verification of the reliability of the detection result based on the explained reason. Furthermore, in practical applications, if it is believed that the explanation of the reason why the target code belongs to the malicious category based only on the label word corresponding to the malicious category is insufficient, then the reason why the target code belongs to the malicious category can be explained based on the matching probability corresponding to the label word corresponding to the malicious category. In this way, the label word and the matching probability used to reflect the matching degree between the label word and the target code jointly explain the reason why the target code belongs to the malicious category, so that the explained reason is more sufficient and it is easier to understand why the target code belongs to the malicious category.
[0100] Taking into account that there are multiple label words corresponding to each preset category and not all label words can provide good explanatory power, before explaining the reason why the target code belongs to the malicious category based on the label words corresponding to the malicious category, it is necessary to select the target label word from the multiple label words corresponding to the target preset category to which the target code belongs, so as to explain the reason why the target code belongs to the malicious category through the target label word of the malicious category.
[0101] The methods for selecting target label words from the label words corresponding to the target preset category can include the following five methods:
[0102] First, among the multiple label words corresponding to the target preset category, the label word whose matching probability reaches a first probability threshold is selected as the target label word.
[0103] The label word is obtained by abstracting the code features of the code belonging to the corresponding preset category. The higher the matching probability between the label word and the target code, the higher the probability that the target code includes the code features abstracted by the label word. Therefore, in order to use a more explanatory label word to explain why the target code belongs to the target preset category, the label word whose matching probability reaches the first probability threshold among the multiple label words corresponding to the target preset category is selected as the target label word. The value of the first probability threshold can be calibrated in advance based on the number of label words in each preset category. This embodiment does not specifically limit the value of the first probability threshold.
[0104] Second, determine the order of multiple label words corresponding to the target preset category, select the label words in the first number of digits as the target label words, and sort them based on the order of label word matching probability from large to small, or sort them based on the order of relevance between the label words and the target preset category from strong to weak.
[0105] Determine the ranking of multiple label words corresponding to the target preset category. The ranking can be performed in the following two ways: First, the higher the matching probability, the higher the matching degree between the label word and the target code. Therefore, the ranking is obtained based on the order of label word matching probability from large to small. Second, the stronger the correlation between the label word and the target preset category, the more the code feature abstracted by the corresponding label word is the key feature in the code. Therefore, the ranking is obtained based on the correlation between the label word and the target preset category from strong to weak.
[0106] After determining the order of multiple label words corresponding to the target preset category, the label words with the higher order can better explain why the target code belongs to the target preset category, so the label words in the first number of digits are selected as the target label words. The value of the first number of digits can be based on business needs, which can be calibrated in advance based on the number of label words in each preset category. This embodiment does not specifically limit the value of the first number of digits.
[0107] Third, all label words corresponding to the target preset category are selected as target label words.
[0108] In order to more comprehensively explain the reason why the target code belongs to the target preset category, all label words corresponding to the target preset category are selected as target label words, so as to use all label words corresponding to the target preset category to explain the reason why the target code belongs to the target preset category.
[0109] Fourth, detect whether the number of label words corresponding to the target preset category is lower than the preset number threshold. If it is lower, all label words corresponding to the target preset category are selected as target label words. If it is not lower, the first or second method of selecting the target label word from the label words corresponding to the target preset category is used to select the target label word. The preset number threshold is not less than the first number.
[0110] When the number of label words corresponding to the target preset category is lower than the preset number threshold, if only some of the label words are used to explain why the target code belongs to the target preset category, it may cause unclear explanation. Therefore, in order to make the explanation clear, all label words corresponding to the target preset category are selected as target label words.
[0111] When the number of label words corresponding to the target preset category is not less than the preset number threshold, in order to reduce the number of label words used to explain why the target code belongs to the target preset category, the first or second method of selecting the target label word from the label words corresponding to the target preset category is used to select the target label word.
[0112] The above four methods of selecting target label words from label words corresponding to target preset categories can be flexibly selected based on business needs, and this embodiment does not limit this.
[0113] After selecting a target label word from a plurality of label words corresponding to the target preset category, a step of explaining the reason why the target code belongs to the malicious category based on the label word corresponding to the malicious category can be performed. This step can be implemented by the following steps 103A to 103B:
[0114] 103A. Based on the target label word of the malicious category, generate interpretation data for interpreting that the target code belongs to the malicious category.
[0115] The label word is used to explain why the corresponding code belongs to the corresponding preset category. Based on the target label word of the malicious category, the explanation data for explaining that the target code belongs to the malicious category is generated. The method for generating the explanation data may include the following four methods:
[0116] First, based on the target label word of the malicious category, the specific process of generating the explanation data for explaining that the target code belongs to the malicious category may include the following steps: constructing an association relationship between the target label word of the malicious category and the corresponding matching probability; determining the association relationship as the explanation data for explaining that the target code belongs to the malicious category.
[0117] The label words are obtained by abstracting the code features of the codes belonging to the corresponding preset categories. The association relationship between the target label words for constructing the malicious category and the corresponding matching probability is determined as the interpretation data for explaining that the target code belongs to the malicious category. In this way, the specific situation that the target code includes the code features abstracted by the corresponding target label words can be indicated from the interpretation data through the matching probability, and the user can know the specific reason why the target code belongs to the malicious category through the association relationship.
[0118] The second method is to generate explanation data for explaining that the target code belongs to the malicious category based on the target label word of the malicious category, which may include the following steps: determining the first network security event corresponding to the malicious category, each malicious category code has a related network security event, and the network security event is an event caused by the code features of the malicious category code when the malicious category code is executed; based on the matching probability of the target label word of the malicious category, estimating the probability of causing the first network security event caused by the code features of the target code when the target code is executed; based on the probability of causing the first network security event, generating explanation data for explaining that the target code belongs to the malicious category.
[0119] For any malicious code, the code features of the malicious code will trigger some network security events when the malicious code is executed, so the first network security event related to each malicious code can be marked in advance. For example, when the malicious code of malicious category 1 is executed, the code features of the malicious code will trigger the leakage of sensitive data of the specified data type, then the first network security event related to the malicious code of category 1 is set as "sensitive data leakage of the specified data type".
[0120] In order to explain the reason why the target code belongs to the malicious category from the dimension of the first network security event triggering situation, the first network security event corresponding to the malicious category is determined, and based on the matching probability of the target label words of the malicious category, the probability of triggering the first network security event caused by the code features of the target code when the target code is executed is estimated.
[0121] The label word is obtained by abstracting the code features of the code belonging to the corresponding preset category. The higher the matching probability between the label word and the target code, the higher the probability that the target code includes the code features abstracted by the corresponding label word, and the higher the probability that the target code includes the code features abstracted by the label word, the higher the probability that the code features will trigger the corresponding first network security event when the target code is executed. Therefore, based on the matching probability of the target label word of the malicious category, the probability of triggering the first network security event caused by the code features of the target code when the target code is executed can be estimated. The estimation method can be: obtaining a model for estimating the probability of triggering the first network security event, taking the correlation between the target label word and the corresponding matching probability as the model input, and estimating the probability of triggering the first network security event when the target code is executed based on the model.
[0122] After obtaining the probability of triggering the first network security event, explanatory data for explaining why the target code belongs to the malicious category can be generated based on the probability of triggering the first network security event, so as to explain why the target code belongs to the target preset category label by explaining the probability of triggering the first network security event in the explanatory data.
[0123] The third type is that based on the target label word of the malicious category, the specific process of generating explanatory data for explaining that the target code belongs to the malicious category may include the following steps: based on the matching probability of the target label word of the malicious category, estimating the second network security event caused by the code characteristics of the target code when the target code is executed, the degree of harm and the probability of triggering the second network security event; based on the second network security event and the corresponding degree of harm and probability of triggering, generating explanatory data for explaining that the target code belongs to the malicious category.
[0124] The network security events caused by the target code, the probability of causing the network security events and the degree of harm can all describe why the target code belongs to the target preset category. Therefore, based on the matching probability of the target label words of the malicious category, the second network security event caused by the code features of the target code when the target code is executed, the degree of harm and the probability of causing the second network security event are estimated to clarify the network harm caused by the target code.
[0125] Based on the matching probability of target label words of malicious categories, the specific process of estimating the second network security event caused by the code features of the target code when the target code is executed, and the degree of harm of the second network security event and the probability of triggering can be: obtaining a model for estimating network security events triggered by codes, taking the correlation between the target label words and the corresponding matching probabilities as model input, and predicting the second network security event that may be triggered when the target code is executed, and the degree of harm of the second network security event and the probability of triggering based on the model.
[0126] Based on the second network security event and the corresponding degree of harm and the probability of triggering, interpretation data is generated to explain that the target code belongs to the target preset category, so as to indicate the network security harm situation that the target code may bring through the second network security event and the corresponding degree of harm and the probability of triggering in the interpretation data, thereby explaining the reason why the target code belongs to the target preset category through these network security harm situations.
[0127] Fourthly, the target label word of the malicious category is determined as the explanation data for explaining that the target code belongs to the malicious category.
[0128] The label word is used to explain why the corresponding code belongs to the corresponding preset category. Therefore, the target label word of the malicious category can be directly determined as the explanatory data used to explain that the target code belongs to the malicious category, so as to reduce the complexity of the explanatory data while ensuring that the explanatory data can explain why the target code belongs to the malicious category.
[0129] The above four methods of generating interpretation data for interpreting that the target code belongs to the malicious category based on the target label words of the malicious category can be used alone or in combination of two or more. This embodiment does not make specific limitations on this and can be flexibly selected based on business needs.
[0130] 103B. Based on the explanation data, explain why the target code is classified as malicious.
[0131] After obtaining the interpretation data, the target code may be interpreted as belonging to a target preset category based on the interpretation data according to the user of the interpretation data.
[0132] If the user is a natural person, such as a technician, a natural language-based explanatory document is generated based on the content in the interpretation data, so that the natural person can know through natural language why the target code belongs to the target preset category.
[0133] If the user is a processing device that needs to use interpretation to perform subsequent processing on the target code, the interpretation data will be converted into interpretation data that can be recognized by the processing device (for example, a file in binary format) so that the processing device can recognize the interpretation data and know why the target code belongs to the target preset category.
[0134] 104. Based on the corresponding label words of the non-malicious category, explain why the target code belongs to the non-malicious category.
[0135] After determining the target preset category to which the target code belongs based on the matching probability between each label word and the target code, if the target preset category is a non-malicious category, the reason why the target code belongs to the non-malicious category is explained based on the label word corresponding to the non-malicious category, so as to explain the reason why the target code belongs to the non-malicious category, thereby improving the interpretability of the detection result and facilitating the subsequent verification of the reliability of the detection result based on the explained reason. Furthermore, in practical applications, if it is believed that the explanation of the reason why the target code belongs to the non-malicious category based only on the label word corresponding to the non-malicious category is insufficient, then the reason why the target code belongs to the non-malicious category can be explained based on the matching probability corresponding to the label word corresponding to the non-malicious category. In this way, the label word and the matching probability used to reflect the matching degree between the label word and the target code jointly explain the reason why the target code belongs to the non-malicious category, so that the explained reason is more sufficient and it is easier to understand why the target code belongs to the non-malicious category.
[0136] Considering that there are multiple label words corresponding to each preset category, and not all label words can play a good explanatory role, before explaining the reason why the target code belongs to the malicious category based on the label words corresponding to the malicious category, it is necessary to select a target label word from the multiple label words corresponding to the target preset category to which the target code belongs, so as to explain the reason why the target code belongs to the non-malicious category through the target label word of the non-malicious category. The method of selecting the target label word from the label words corresponding to the target preset category is referred to the above step 103, which will not be repeated here.
[0137] After selecting a target label word from a plurality of label words corresponding to the target preset category, a step of explaining the reason why the target code belongs to the non-malicious category based on the label words corresponding to the non-malicious category can be performed. This step can be implemented by the following steps 104A to 104B:
[0138] 104A. Based on the target label word of the non-malicious category, generate explanation data for explaining that the target code belongs to the non-malicious category.
[0139] The label word is used to explain why the corresponding code belongs to the corresponding preset category. Based on the target label word of the non-malicious category, the explanation data for explaining that the target code belongs to the non-malicious category is generated. The method of generating the explanation data may include the following three methods:
[0140] First, based on the target label word of the non-malicious category, the specific process of generating the explanation data for explaining that the target code belongs to the non-malicious category may include the following steps: constructing an association relationship between the target label word of the non-malicious category and the corresponding matching probability; determining the association relationship as the explanation data for explaining that the target code belongs to the non-malicious category.
[0141] The label word is obtained by abstracting the code features of the code belonging to the corresponding preset category. The association relationship between the target label word for the non-malicious category and the corresponding matching probability is determined as the interpretation data for explaining that the target code belongs to the non-malicious category. In this way, the specific situation that the target code includes the code features abstracted by the corresponding target label word can be indicated from the interpretation data through the matching probability, and the user can know the specific reason why the target code belongs to the non-malicious category through the association relationship.
[0142] The second method is to generate explanation data for explaining that the target code belongs to the non-malicious category based on the target label word of the non-malicious category. The specific process may include the following steps: based on the matching probability of the target label word of the non-malicious category, estimating the probability of triggering each network security event in the network security event set by the code features of the target code when the target code is executed; based on the triggering probability of each network security event, generating explanation data for explaining that the target code belongs to the non-malicious category.
[0143] The network security events in the network security event set are network security events caused by the code features of the malicious code when the malicious code is executed. When the non-malicious code is executed, the code features of the non-malicious code do not cause network security events in the network security event set, or the probability of causing network security events in the network security event set is extremely low. Therefore, based on the matching probability of the target label words of the non-malicious category, the probability of the code features of the target code causing each network security event in the network security event set when the target code is executed can be estimated, and these triggering probabilities can be used to explain why the target code belongs to the non-malicious category.
[0144] Based on the matching probability of target label words in non-malicious categories, the specific process of estimating the probability of code features of target code triggering each network security event in the network security event set when the target code is executed can be: obtaining a model for estimating network security events triggered by code, taking the association between target label words and corresponding matching probabilities and network security events in the network security event set as model inputs, and predicting the probability of code features of target code triggering each network security event in the network security event set when the target code is executed based on the model.
[0145] After obtaining the triggering probability of each network security event, these triggering probabilities can reflect why the target code does not belong to the malicious category. Therefore, based on the triggering probability of each network security event, explanatory data is generated to explain why the target code belongs to the non-malicious category. These explanatory data can reversely prove the reason why the target code belongs to the non-malicious category through the triggering probability of each network security event.
[0146] The third method is to determine the target label word of the non-malicious category as the explanation data used to explain that the target code belongs to the non-malicious category.
[0147] The label word is used to explain why the corresponding code belongs to the corresponding preset category. Therefore, the target label word of the malicious category can be directly determined as the explanatory data used to explain that the target code belongs to the non-malicious category, so as to reduce the complexity of the explanatory data while ensuring that the explanatory data can explain why the target code belongs to the non-malicious category.
[0148] The above three methods for explaining the reason why the target code belongs to the non-malicious category based on the corresponding label words of the non-malicious category can be used alone or in combination. This embodiment does not make specific limitations on this and can be flexibly selected based on business needs.
[0149] 104B. Based on the explanation data, explain why the target code is classified as non-malicious.
[0150] The specific method for explaining the reason why the target code belongs to the non-malicious category based on the interpretation data is basically the same as the method for explaining the reason why the target code belongs to the malicious category based on the interpretation data in the above step 103B, so it will not be repeated here.
[0151] The malicious code detection method provided by the embodiment of the present application stores label words corresponding to at least two preset categories of code in the malicious code detection system, so as to explain the reason why the corresponding code belongs to the corresponding preset category through the label words. When it is necessary to perform malicious code detection on the target code, the matching probability of each label word of each preset category stored in the malicious code detection system and the target code is determined, and the target preset category to which the target code belongs is determined based on the matching probability of each label word and the target code. If the target preset category is a malicious category included in the preset categories stored in the malicious code detection system, then based on the label words corresponding to the malicious category, the reason why the target code belongs to the malicious category is explained. If the target preset category is a non-malicious category included in the preset categories stored in the malicious code detection system, then based on the label words corresponding to the non-malicious category, the reason why the target code belongs to the non-malicious category is explained. It can be seen that the solution provided by the embodiment of the present application stores two or more preset categories in the malicious code detection system in advance, and sets corresponding label words for the codes of each preset category. In this way, after malicious code detection is performed on the code to obtain the detection result of the target preset category to which the code belongs, the reason why the code belongs to the target preset category can be explained based on the label words corresponding to the target preset category, thereby improving the interpretability of the detection result that the code belongs to the target preset category, and further facilitating the subsequent verification of the reliability of the detection result that the code belongs to the target preset category based on the explained reasons.
[0152] In some embodiments of the present application, in order to be able to more comprehensively explain the reason why the target code belongs to the target preset category, after explaining the reason why the target code belongs to the target malicious category based on the corresponding label words of the target preset category, the malicious code detection method may also include the step of supplementary explanation of the reason why the target code belongs to the target preset category, specifically: determining a non-target preset category to which the target code does not belong in the preset category; based on the matching probability of the corresponding label words of the non-target preset category, generating supplementary explanation data for supplementary explanation of the target code belonging to the target preset category; based on the supplementary explanation data, supplementary explanation of the reason why the target code belongs to the target preset category.
[0153] Based on the label words corresponding to the target preset category, the reason why the target code belongs to the target preset category is explained, mainly from the perspective of the target preset category itself. Therefore, in order to explain the reason why the target code belongs to the target preset category more comprehensively, the present embodiment also determines the non-target preset category to which the target code does not belong in the preset category, so that the reason why the target code belongs to the target preset category can be explained from the perspective of the non-target preset category, which is not itself. In this way, the reason why the target code belongs to the target preset category is explained more comprehensively from the two perspectives of the target preset category itself and non-self.
[0154] There are mutually exclusive or contradictory label words between the non-target preset category label and the target preset category label, so the non-target preset category label is used to supplement the explanation of the target code belonging to the target preset category, which can clearly explain the reason why the target code belongs to the target preset category but not the non-target preset category. Therefore, after determining the non-target preset category label, based on the matching probability of the corresponding label words of the non-target preset category, supplementary explanation data for supplementing the explanation that the target code belongs to the target preset category is generated. The specific process of generating the supplementary explanation data may include: for the non-target preset category, selecting the label words that are mutually exclusive or contradictory with the target preset category from the label words corresponding to the non-target preset category; based on the matching probability of the selected label words, generating supplementary explanation data for explaining that the target code belongs to the target preset category. The process of selecting label words that are mutually exclusive or contradictory with the target preset category from label words corresponding to non-target preset categories can be as follows: the label words corresponding to the non-target preset category and the label words corresponding to the target preset category are input into a model for identifying label words that are mutually exclusive or contradictory between the non-target preset category and the target preset category, and the label words that are mutually exclusive or contradictory with the target preset category among the label words corresponding to the non-target preset category are obtained through the model.
[0155] The supplementary explanatory data can more comprehensively explain the reasons why the target code belongs to the target preset category from the perspective of the target preset category itself and not from its own perspective, so that the supplementary explanatory data can more comprehensively and clearly explain the reasons why the target code belongs to the target preset category.
[0156] The specific method of providing supplementary explanation for the reason why the target code belongs to the target preset category based on the supplementary interpretation data can be found in the interpretation method used in 103B above, so it will not be repeated here.
[0157] In some embodiments of the present application, the malicious code detection method provided in this embodiment may also include a technical solution of label words corresponding to at least two preset categories of codes, and the specific execution process of the technical solution may be the following steps 105 to 107:
[0158] 105. Obtain the sample code corresponding to each preset category.
[0159] After determining at least two preset categories, a certain number of sample codes are obtained, and the number of sample codes corresponding to each preset category needs to be balanced. For example, two preset categories are determined, and the difference between the number of sample codes of the two preset categories is not greater than a preset difference, such as a preset difference of 10.
[0160] 106. Extract corresponding code features from the sample code.
[0161] For each sample code corresponding to a preset category, a code feature corresponding to the preset category is extracted from the sample code, and the code feature is a code feature in the code that can be used or attacked by a malicious party. The specific process of extracting the corresponding code feature from the sample code may include: for each preset category, obtaining a model for extracting code features related to the preset category, and extracting code features related to the preset category from the sample code corresponding to the preset category. Code features may be selected based on business needs. For example, code features may include but are not limited to API names, etc.
[0162] 107. For each preset category, extract the concept words related to the code features corresponding to the preset category in the concept word library corresponding to the preset category as candidate words, and set the label words of the preset category based on the candidate words.
[0163] The concept word library stores at least one concept word corresponding to a code feature, and the concept word is obtained by abstracting the code features of the code belonging to a preset category. Exemplarily, the concept word library is Microsoft Probase.
[0164] For each preset category, the following steps are performed: determining the code features corresponding to the preset category based on the code features abstracted by the label words corresponding to the preset category; and extracting the concept words related to the code features corresponding to the preset category in the concept word library corresponding to the preset category as candidate words.
[0165] After extracting the candidate words, set the label words of the preset category based on the candidate words. The specific process of setting the label words of the preset category based on the candidate words may include the following steps: filter the candidate words corresponding to the preset category, and set the filtered candidate words as the label words corresponding to the preset category.
[0166] Considering that if the number of candidate words in a preset category is small, screening the candidate words corresponding to the preset category will result in too few label words corresponding to the preset category, which may result in the inability to effectively explain the reason why the code belongs to the preset category through the label words. Therefore, before screening the candidate words corresponding to the preset category, the malicious code detection method may also include the following steps: for each preset category, detecting whether the number of candidate words in the preset category is less than the preset number, if it is less, determining all candidate words as label words corresponding to the preset category, if it is not less than, performing the step of screening the candidate words corresponding to the preset category.
[0167] Methods for screening candidate words corresponding to preset categories may include the following two methods:
[0168] One is to select target sample codes for candidate word screening from sample codes corresponding to preset categories; detect the occurrence probability of each word element in a target word element set that is related to the code of the preset category in the target sample code, wherein the target word element set includes word elements related to the code of the preset category, and the target word element set includes target word elements corresponding to the candidate words; determine the occurrence probability of the target word element corresponding to each candidate word from the occurrence probability of the word element; determine the matching probability of each candidate word with the target sample code based on the occurrence probability of the target word element; and screen the candidate words based on the matching probability.
[0169] In order to ensure the accuracy of candidate word screening, the number of selected target sample codes needs to take into account the total amount of sample codes of the corresponding preset category, and the proportion of target sample codes in the sample codes cannot be lower than the preset proportion.
[0170] Detect the occurrence probability of each word related to the preset category code in the target word set in the target sample code; determine the occurrence probability of the target word corresponding to each candidate word from the word occurrence probability; determine the matching probability of each candidate word with the target sample code based on the occurrence probability of the target word. The methods used in these steps can refer to the determination of the matching probability of each label word of the preset category with the target code in the above step 101, so it will not be repeated here.
[0171] After determining the matching probability between each candidate word and the target sample code, the candidate words are screened based on the matching probability, and the screening process may include: sorting the candidate words in descending order of matching probability, and screening the candidate words ranked in the first set number of positions as candidate words for setting the corresponding label words of the preset category. In addition to ensuring that the code features of the code of the corresponding preset category are clearly described, the first set number of label words should also be able to clearly explain the reason why the code belongs to the preset category.
[0172] Another method is to determine the positive score and negative score of each candidate word in a preset category; calculate the sum of the positive score and negative score of each candidate word respectively to obtain the corresponding total score of each candidate word; and screen the candidate words based on the total score.
[0173] The positive score is a score indicating that the candidate word belongs to a preset category and does not belong to other preset categories, and the negative score is a score indicating that the candidate word belongs to other preset categories and does not belong to the preset category. The positive score and the negative score can be calculated by the corresponding Loglikelihood-ratio function.
[0174] The sum of the scores obtained by adding the positive scores and the negative scores can reflect the discrimination of the candidate words under different category labels. The greater the sum of the scores, the greater the discrimination. Therefore, the specific process of screening the candidate words based on the sum of the scores can be: sort the candidate words in descending order of the sum of the scores, and screen the candidate words ranked in the first second set number of positions as the candidate words for setting the label words. In addition to ensuring that the code features of the code of the corresponding preset category are clearly described, the second set number of label words should also be able to clearly explain why the code belongs to the preset category.
[0175] The above two methods for screening candidate words corresponding to the preset categories can be used alone or in combination, which is not specifically limited in this embodiment. When used in combination, one method is used first, and then another method is used to screen the candidate words screened by the method.
[0176] After screening the candidate words corresponding to the preset category, the screened candidate words can not only ensure that the code features of the code of the corresponding preset category are clearly described, but also clearly explain why the code belongs to the preset category. Therefore, the screened candidate words are set as the label words corresponding to the preset category.
[0177] Below Figure 2 To illustrate the process of presetting at least two preset categories of codes corresponding to the label words, from Figure 2It can be seen from the figure that after determining at least two preset categories, a certain number of sample codes corresponding to each preset category are obtained based on the at least two preset categories, and the number of sample codes corresponding to each preset category needs to be balanced. Then for each preset category, the corresponding code features are extracted from the sample codes of the preset category, and the concept words related to the code features corresponding to the preset category in the concept word library corresponding to the preset category are extracted as candidate words to form Figure 2 A set of candidate words is obtained. Then, for each preset category, a target sample code for candidate word screening is selected from the sample code of the preset category, and the occurrence probability of each word related to the code of the preset category in the target word set is detected by the preset target model in the target sample code, and the occurrence probability of the target word corresponding to each candidate word is determined from the word probability, and the matching probability of each candidate word with the target sample code is determined based on the occurrence probability of the target word. Then, the candidate words are screened based on the matching probability, and the screened candidate words are set as the label words corresponding to the preset category. Finally, the label words corresponding to the code of the preset category are preset in the mapper.
[0178] In some embodiments of the present application, the following Figure 3 The schematic diagram of the malicious code detection process shown is used to illustrate the specific execution process of the malicious code detection method provided by this embodiment.
[0179] The malicious code detection system is preset with a target model and a mapper, and the target model is bound to the mapper. The label words corresponding to at least two preset categories of code stored in the malicious code detection system are preset in the mapper. The target model is associated with a target word set, and the target word set includes word elements related to the preset category of code, and the target word set includes a first word element corresponding to the label word, and the first word element is used to describe the code feature abstracted by the corresponding label word. The target model is used to identify the probability of occurrence of each word element in the target word set related to the preset category of code in the code. Figure 3 As shown, the malicious code detection system stores label words corresponding to two preset categories of codes, and the label words corresponding to the two preset categories of codes are preset in the mapper, wherein one preset category is a malicious category, and the label words corresponding to the malicious category of codes include: sensitive data leakage, malicious process injection, and rebound port. The other preset category is a non-malicious category, and the label words corresponding to the non-malicious category of codes include: authorized reading, legal input. The target model has a corresponding prompt template, and the prompt template is "[MASK], [X]", wherein [X] represents the position where the target code is inserted, and [MASK] represents the output position of the probability of occurrence of each word element related to the preset category of code in the target word element set identified by the target model in the target code.
[0180] If there is code to be detected in the malicious code detection system, the code is determined as the target code that needs to be detected. Then the target code is processed using the prompt template "[MASK], [X]" of the target model to form the prompt text "prompt text: [MASK], target code" corresponding to the target code. The prompt text is input into the target model, and the target model is used to identify the probability of occurrence of each word in the target word set related to the preset category of the target code in the target code, and the following is obtained: Figure 3 As shown in the figure, “[MASK]=>[word 1: 0.05, word 2: 0.0003, word 3: 0.0013…]”, where the values 0.05, 0.0003, 0.0013, etc. represent the probability of occurrence of words in the target word set related to the target code of the preset category in the target code. It should be noted that the sum of the probability of occurrence of each word in the target word set related to the target code of the preset category in the target code is 1.
[0181] Then, the target model is used to read each label word corresponding to the preset category from the mapper, and the target model is used to determine the occurrence probability of the first word unit corresponding to each label word from the occurrence probability of the word unit. The matching probability of each label word corresponding to each preset category is summarized and processed to obtain the sum of the matching probabilities corresponding to each preset category, that is, Figure 3 As shown in the figure, "[Sensitive data leakage, malicious process injection, rebound port]: malicious category = > 0.6", "[Authorized reading, legal input]: non-malicious category = > 0.4", where 0.6 and 0.4 are the sum of the matching probabilities of the corresponding preset categories. Then determine the highest matching probability sum in the matching probability sum, and obtain the label word corresponding to the preset category corresponding to the highest matching probability sum, that is, Figure 3 The “[sensitive data leakage, malicious process injection, bounce port], target code” shown in the figure is then searched for the corresponding preset category of [sensitive data leakage, malicious process injection, bounce port] based on the tag words corresponding to the preset category code stored in the mapper. After searching, it is found that the corresponding preset category of [sensitive data leakage, malicious process injection, bounce port] is the malicious category, and the target preset category to which the target code belongs is determined to be the “malicious category”.
[0182] After determining that the target preset category "malicious category" to which the target code belongs, the reason why the target code belongs to the target preset category "malicious category" can be explained based on the corresponding label words "[sensitive data leakage, malicious process injection, rebound port" of the target preset category "malicious category". It can be seen from this that the corresponding label words "[sensitive data leakage, malicious process injection, rebound port" of the "malicious category" clearly indicate the malicious behavior. Based on the corresponding label words "[sensitive data leakage, malicious process injection, rebound port" of the "malicious category", it can be explained that the target code is classified as a "malicious category" because of the malicious behaviors such as sensitive data leakage, malicious process injection, and rebound port.
[0183] Furthermore, on the basis of explaining the reason why the target code belongs to the malicious category based on the corresponding label words of the malicious category, the reason why the target code belongs to the malicious category can also be explained in detail by combining the matching probabilities corresponding to the corresponding label words of the malicious category "sensitive data leakage, malicious process injection, and rebound port". In this way, the label words and the matching probabilities used to reflect the matching degree between the label words and the target code can jointly explain the reason why the target code belongs to the malicious category, so as to provide a more detailed and accurate explanation of the malicious category to which the target code belongs.
[0184] Furthermore, in order to explain more comprehensively why the target code belongs to the malicious category, a non-target preset category "non-malicious category" to which the target code does not belong can be determined in the preset category. Then, based on the matching probability of the corresponding label words "authorized reading, legal input" of the "non-malicious category", supplementary explanation data for supplementary explanation of why the target code belongs to the malicious category is generated, and based on the supplementary explanation data, a supplementary explanation of why the target code belongs to the malicious category is given.
[0185] Furthermore, an embodiment of the present application also provides a malicious code detection device, which is applied to a malicious code detection system, wherein the malicious code detection system stores label words corresponding to codes of at least two preset categories, wherein the at least two preset categories include a malicious category and a non-malicious category, and the label words are used to explain why the corresponding code belongs to the corresponding preset category, such as Figure 4 As shown, the malicious code detection device includes:
[0186] A first determination module 21 is used to determine the matching probability between each label word of a preset category and the target code when malicious code detection is required for the target code;
[0187] A second determination module 22, configured to determine a target preset category to which the target code belongs based on the matching probability;
[0188] A first explanation module 23 is used for explaining the reason why the target code belongs to the malicious category based on the label word corresponding to the malicious category if the target preset category is the malicious category;
[0189] The second explanation module 24 is configured to explain the reason why the target code belongs to the non-malicious category based on a label word corresponding to the non-malicious category if the target preset category is the non-malicious category.
[0190] The malicious code detection device provided by the embodiment of the present application stores label words corresponding to at least two preset categories of codes in the malicious code detection system, so as to explain the reason why the corresponding code belongs to the corresponding preset category through the label words. When it is necessary to perform malicious code detection on the target code, the matching probability of each label word of each preset category stored in the malicious code detection system and the target code is determined, and the target preset category to which the target code belongs is determined based on the matching probability of each label word and the target code. If the target preset category is a malicious category included in the preset categories stored in the malicious code detection system, then based on the label words corresponding to the malicious category, the reason why the target code belongs to the malicious category is explained. If the target preset category is a non-malicious category included in the preset categories stored in the malicious code detection system, then based on the label words corresponding to the non-malicious category, the reason why the target code belongs to the non-malicious category is explained. It can be seen that the solution provided by the embodiment of the present application stores two or more preset categories in the malicious code detection system in advance, and sets corresponding label words for the codes of each preset category. In this way, after malicious code detection is performed on the code to obtain the detection result of the target preset category to which the code belongs, the reason why the code belongs to the target preset category can be explained based on the label words corresponding to the target preset category, thereby improving the interpretability of the detection result that the code belongs to the target preset category, and further facilitating the subsequent verification of the reliability of the detection result that the code belongs to the target preset category based on the explained reasons.
[0191] In some embodiments of the present application, Figure 5 As shown, the malicious code detection device also includes:
[0192] The third interpretation module 25 is used to determine the non-target preset category to which the target code does not belong in the preset category; based on the matching probability of the corresponding label words of the non-target preset category, generate supplementary interpretation data for supplementary explanation that the target code belongs to the target preset category; based on the supplementary interpretation data, provide a supplementary explanation for the reason why the target code belongs to the target preset category.
[0193] In some embodiments of the present application, Figure 5 As shown, each preset category corresponds to multiple label words, and the malicious code detection device also includes:
[0194] A first selection module 26, configured to select a target label word from a plurality of label words corresponding to the target preset category;
[0195] Then, the first interpretation module 23 includes:
[0196] A first generating unit 231 is used to generate interpretation data for explaining that the target code belongs to the malicious category based on the target label word of the malicious category;
[0197] The first interpretation unit 232 is used to interpret the reason why the target code belongs to the malicious category based on the interpretation data.
[0198] In some embodiments of the present application, Figure 5 As shown, the label word is obtained by abstracting the code features of the code belonging to the corresponding preset category. Then, the first generating unit 231 is specifically used to determine the first network security event corresponding to the malicious category. Each malicious category code has a related network security event, and the network security event is an event caused by the code features of the malicious category code when the malicious category code is executed; based on the matching probability of the target label word of the malicious category, the probability of causing the first network security event caused by the code features of the target code when the target code is executed is estimated; based on the probability of causing the first network security event, an explanation data is generated for explaining that the target code belongs to the malicious category.
[0199] and / or,
[0200] The first generating unit 231 is specifically used to estimate, based on the matching probability of the target label word of the malicious category, a second network security event caused by the code features of the target code when the target code is executed, the degree of harm and the probability of triggering the second network security event; based on the second network security event and the corresponding degree of harm and probability of triggering, generate interpretation data for explaining that the target code belongs to the malicious category.
[0201] and / or,
[0202] The first generating unit 231 is specifically used to construct an association relationship between the target label word of the malicious category and the corresponding matching probability; and determine the association relationship as explanation data for explaining that the target code belongs to the malicious category.
[0203] In some embodiments of the present application, Figure 5 As shown, the first selection module 26 is specifically used to select a label word whose matching probability reaches a first probability threshold from a plurality of label words corresponding to the target preset category as a target label word.
[0204] or,
[0205] The first selection module 26 is specifically used to determine the order of multiple label words corresponding to the target preset category, and select the label words located in the first first number of digits as the target label words. The order is obtained based on the order of label word matching probability from large to small, or the order is obtained according to the order of relevance between the label words and the target preset category from strong to weak.
[0206] In some embodiments of the present application, Figure 5 As shown, each preset category corresponds to multiple label words, and the malicious code detection device also includes:
[0207] The second selection module 27 is used to select a target label word from a plurality of label words corresponding to the target preset category.
[0208] Then, the second interpretation module 24 includes:
[0209] A second generating unit 241 is used to generate interpretation data for explaining that the target code belongs to the non-malicious category based on the target label word of the non-malicious category;
[0210] The second interpretation unit 242 is configured to interpret the reason why the target code belongs to the non-malicious category based on the interpretation data.
[0211] In some embodiments of the present application, Figure 5 As shown, the label word is obtained by abstracting the code features of the code belonging to the corresponding preset category. Then, the second generation unit 241 is specifically used to estimate the probability of triggering each network security event in the network security event set by the code features of the target code when the target code is executed based on the matching probability of the target label word of the non-malicious category. The network security events in the network security event set are network security events triggered by the code features of the malicious category code when the malicious category code is executed; based on the triggering probability of each network security event, generate interpretation data for explaining that the target code belongs to the non-malicious category.
[0212] and / or,
[0213] The second generating unit 241 is specifically used to construct an association relationship between the target label word of the non-malicious category and the corresponding matching probability; and determine the association relationship as explanation data for explaining that the target code belongs to the non-malicious category.
[0214] In some embodiments of the present application, Figure 5 As shown, the second selection module 27 is specifically used to select a label word whose matching probability reaches a first probability threshold from a plurality of label words corresponding to the target preset category as a target label word.
[0215] or,
[0216] The second selection module 27 is specifically used to determine the order of multiple label words corresponding to the target preset category, and select the label words located in the first first number of digits as the target label words. The order is obtained based on the order of label word matching probability from large to small, or the order is obtained according to the order of relevance between the label words and the target preset category from strong to weak.
[0217] In some embodiments of the present application, Figure 5 As shown, the label word is obtained by abstracting the code features of the code belonging to the corresponding preset category, then, the first determination module 21 includes:
[0218] A first detection unit 211 is used to detect the occurrence probability of each word-element related to the preset category of code in the target word-element set in the target code, wherein the target word-element set includes words related to the preset category of code, and the target word-element set includes a first word-element corresponding to the label word, and the first word-element is used to describe the code feature abstracted by the corresponding label word;
[0219] A first determining unit 212, configured to determine the occurrence probability of a first word-gram corresponding to each of the tag words from the occurrence probabilities of the word-grams;
[0220] The second determining unit 213 is used to determine the matching probability between each of the tag words and the target code based on the occurrence probability of the first word-gram.
[0221] In some embodiments of the present application, Figure 5 As shown, the label word is obtained by abstracting the code features of the code belonging to the corresponding preset category, then, the first determination module 21 also includes:
[0222] The third determination unit 214 is used for: for each of the label words: matching the label word with each of the label words in the target word set that is related to the code of a preset category; if the label word matches a word, determining the corresponding word as the first word corresponding to the label word; if the label word does not match a word, deriving a label word associated with the label word based on the code feature abstracted by the label word, and matching the associated label word with each of the label words in the target word set that is related to the code of a preset category; if the associated label word matches a word, determining the corresponding word as the first word corresponding to the label word; if the associated label word does not match a word, determining that the label word does not have a corresponding first word.
[0223] In some embodiments of the present application, Figure 5 As shown, the first determining module 21 also includes:
[0224] The fourth determination unit 215 is used to split the label word into at least two second word-grams after the third determination unit 214 fails to match a word-gram and before determining that the label word does not have a related first word-gram, and to match each second word-gram with each word-gram related to a code of a preset category in the target word-gram set; if each second word-gram matches a word-gram, the corresponding word-gram is determined as a first word-gram related to the label word; if there is a second word-gram that does not match a word-gram, the third determination unit 214 is triggered to execute the step of determining that the label word does not have a related first word-gram.
[0225] In some embodiments of the present application, Figure 5 As shown, the first determining module 21 also includes:
[0226] The fifth determination unit 216 is configured to determine a preset probability as the matching probability of the label word if the third determination unit 214 determines that the label word does not have a related first word-element, wherein the preset probability is used to indicate that the label word does not match the target code.
[0227] In some embodiments of the present application, Figure 5 As shown, the malicious code detection system is preset with a target model, and the target model is used to identify the probability of occurrence of each word related to the preset category of code in the target word set in the code,
[0228] Then, the first detection unit 211 is specifically used to input the target code into the target model, and identify the occurrence probability of each word element related to the preset category of code in the target word element set in the target code through the target model;
[0229] The first determining unit 212 is specifically configured to determine the occurrence probability of the first word-gram corresponding to each of the tag words from the occurrence probabilities of the word-grams through the target model.
[0230] In some embodiments of the present application, Figure 5 As shown, the label words corresponding to the codes of the at least two preset categories are preset in the mapper, and the mapper is bound to the target model, then,
[0231] The first determining unit 212 is further configured to read each label word corresponding to a preset category from the mapper through the target model before determining the occurrence probability of the first word-gram corresponding to each label word from the occurrence probability of the word-gram through the target model.
[0232] In some embodiments of the present application, Figure 5As shown, if there are multiple first word-grams corresponding to a label word, the second determination unit 213 is used to determine, for each label word, the average value of the occurrence probabilities of the multiple first word-grams corresponding to the label word as the matching probability between the label word and the target code.
[0233] In some embodiments of the present application, Figure 5 As shown, each preset category corresponds to multiple label words, and the second determination module 22 includes:
[0234] A sorting unit 221, configured to sort each label word corresponding to the at least two preset categories in the order of the matching probability from large to small;
[0235] The second detection unit 222 is used to detect whether the label words ranked in the first second number of digits correspond to the same preset category; if so, the corresponding preset category is determined as the target preset category to which the target code belongs; if not, the sixth determination unit 223 is triggered to summarize the matching probability of each label word corresponding to each preset category, obtain the sum of matching probabilities corresponding to each preset category, and determine the preset category corresponding to the highest sum of matching probabilities in the sum of matching probabilities as the target preset category to which the target code belongs.
[0236] In some embodiments of the present application, Figure 5 As shown, the sixth determination unit 223 is specifically configured to respectively calculate the sum of the matching probabilities of each tag word corresponding to each preset category to obtain the sum of the matching probabilities corresponding to each preset category.
[0237] or,
[0238] The sixth determination unit 223 is specifically used to determine the weight of each tag word in the corresponding preset category; based on the corresponding weight, the weighted sum of the matching probability of each tag word corresponding to each preset category is calculated respectively to obtain the sum of the matching probabilities corresponding to each preset category.
[0239] In some embodiments of the present application, Figure 5 As shown, the malicious code detection system further stores the minimum proportions corresponding to the at least two preset categories, and the minimum proportion is the proportion of label words whose matching probability is not less than the second probability threshold in the label words corresponding to the preset categories. Then, the second determination module 22 further includes:
[0240] The seventh determination unit 224 is used to determine the target proportion of label words whose matching probability is not less than the second probability threshold in the label words corresponding to each preset category after the second detection unit 222 detects that the label words ranked in the first second number of digits do not correspond to the same preset category; if there is a preset category with a target proportion higher than the corresponding minimum proportion, and the preset category with a target proportion higher than the corresponding minimum proportion includes a malicious category, then the corresponding malicious category is determined as the target preset category to which the target code belongs; if there is a preset category with a target proportion higher than the corresponding minimum proportion, and the preset category with a target proportion higher than the corresponding minimum proportion includes a non-malicious category and does not include a malicious category, then the corresponding non-malicious category is determined as the target preset category to which the target code belongs; if there is no preset category with a target proportion higher than the corresponding minimum proportion, then the sixth determination unit 223 is triggered to execute the step of summarizing the matching probability of each label word corresponding to each preset category respectively to obtain the sum of the matching probabilities corresponding to each preset category.
[0241] In some embodiments of the present application, Figure 5 As shown, the malicious code detection device also includes:
[0242] A setting module 28 is used to obtain sample codes corresponding to each preset category; extract corresponding code features from the sample codes; for each of the preset categories, extract concept words related to the code features corresponding to the preset category in the concept word library corresponding to the preset category as candidate words, and set the label words of the preset category based on the candidate words, wherein the concept word library stores at least one concept word corresponding to the code feature, and the concept word is obtained by abstracting the code features of the code belonging to the preset category.
[0243] In some embodiments of the present application, Figure 5 As shown, the setting module 28 includes:
[0244] A screening unit 281, used for screening candidate words corresponding to the preset category;
[0245] The setting unit 282 is used to set the screened candidate words as label words corresponding to the preset category.
[0246] In some embodiments of the present application, Figure 5As shown, the screening unit 281 is specifically used to select a target sample code for candidate word screening from the sample code corresponding to the preset category; detect the occurrence probability of each word element related to the code of the preset category in the target word element set in the target sample code, the target word element set includes word elements related to the code of the preset category, and the target word element set includes target word elements corresponding to the candidate words; determine the occurrence probability of the target word element corresponding to each candidate word from the occurrence probability of the word element; determine the matching probability of each candidate word with the target sample code based on the occurrence probability of the target word element; and screen the candidate words based on the matching probability.
[0247] In some embodiments of the present application, Figure 5 As shown, the screening unit 281 is specifically used to determine the positive score and negative score of each candidate word of the preset category, the positive score is a score indicating that the candidate word belongs to the preset category and does not belong to other preset categories, and the negative score is a score indicating that the candidate word belongs to other preset categories and does not belong to the preset category; respectively calculate the sum of the positive score and the negative score of each candidate word to obtain the corresponding total score of each candidate word; and screen the candidate words based on the total score.
[0248] In some embodiments of the present application, Figure 5 As shown, the malicious code detection device also includes:
[0249] The judging module 29 is used to judge whether the target code is a code in text form; if not, the target code is converted into text form.
[0250] In the malicious code detection device provided in the embodiment of the present application, the detailed explanations used in the operation of each functional module can be referred to the corresponding detailed explanations of the above-mentioned malicious code detection method embodiment, which will not be repeated here.
[0251] Further, according to the above-mentioned embodiment, an embodiment of the present application also provides a computer-readable storage medium, wherein the storage medium includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the above-mentioned malicious code detection method.
[0252] Furthermore, according to the above-mentioned embodiments, an embodiment of the present application also provides an electronic device, which includes: a memory for storing programs; and a processor coupled to the memory for running the program to execute the above-mentioned malicious code detection method.
[0253] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0254] It is understandable that the related features in the above methods and devices can be referenced to each other. In addition, the "first", "second" and the like in the above embodiments are used to distinguish the embodiments, but do not represent the advantages and disadvantages of the embodiments.
[0255] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0256] The algorithm and display provided herein are not inherently related to any particular computer, virtual system or other device. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious to construct the structure required for this type of system. In addition, the application is not directed to any specific programming language either. It should be understood that various programming languages can be utilized to realize the content of the application described herein, and the description of the above specific language is to disclose the preferred embodiment of the application.
[0257] In addition, the memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0258] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0259] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data cutover device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data cutover device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0260] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data switching device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0261] These computer program instructions can also be loaded onto a computer or other programmable data transfer device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0262] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0263] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0264] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0265] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity 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, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0266] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0267] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. A malicious code detection method, It is characterized in that Applied to a malicious code detection system, the malicious code detection system stores label words corresponding to codes of at least two preset categories, the at least two preset categories include malicious categories and non-malicious categories, the label words are used to explain why the corresponding code belongs to the corresponding preset category, the method includes: When malicious code detection is required for the target code, determining the matching probability between each label word of a preset category and the target code; Based on the matching probability, determining a target preset category to which the target code belongs; If the target preset category is a malicious category, then based on the label word corresponding to the malicious category, explain the reason why the target code belongs to the malicious category; If the target preset category is a non-malicious category, then based on the label word corresponding to the non-malicious category, the reason why the target code belongs to the non-malicious category is explained.
2. The method according to claim 1, It is characterized in that The method further comprises: Determining, from the preset categories, a non-target preset category to which the target code does not belong; Based on the matching probability of the corresponding label words of the non-target preset category, generating supplementary explanation data for supplementary explanation that the target code belongs to the target preset category; Based on the supplementary explanation data, a supplementary explanation is given as to why the target code belongs to the target preset category.
3. The method according to claim 1, It is characterized in that There are multiple label words corresponding to each preset category, and the method further includes: selecting a target label word from the multiple label words corresponding to the target preset category; Then, based on the label word corresponding to the malicious category, the reason why the target code belongs to the malicious category is explained, including: Based on the target label word of the malicious category, generating interpretation data for explaining that the target code belongs to the malicious category; Based on the explanation data, the reason why the target code belongs to the malicious category is explained.
4. The method according to claim 3, It is characterized in that The label word is obtained by abstracting the code features of the code belonging to the corresponding preset category. Then, based on the target label word of the malicious category, the explanation data for explaining that the target code belongs to the malicious category is generated, including: Determine a first network security event corresponding to the malicious category, each malicious category code has a related network security event, and the network security event is an event caused by the code features of the malicious category code when the malicious category code is executed; based on the matching probability of the target label word of the malicious category, estimate the probability of the first network security event being caused by the code features of the target code when the target code is executed; based on the probability of the first network security event being caused, generate explanation data for explaining that the target code belongs to the malicious category; and / or, Based on the matching probability of the target label word of the malicious category, estimating the second network security event caused by the code feature of the target code when the target code is executed, the degree of harm and the probability of triggering the second network security event; based on the second network security event and the corresponding degree of harm and probability of triggering, generating interpretation data for explaining that the target code belongs to the malicious category; and / or, Constructing an association relationship between a target label word of the malicious category and a corresponding matching probability; determining the association relationship as explanation data for explaining that the target code belongs to the malicious category.
5. The method according to claim 1, It is characterized in that There are multiple label words corresponding to each preset category, and the method further includes: selecting a target label word from the multiple label words corresponding to the target preset category; Then, based on the label words corresponding to the non-malicious category, the reason why the target code belongs to the non-malicious category is explained, including: Based on the target label word of the non-malicious category, generating interpretation data for interpreting that the target code belongs to the non-malicious category; Based on the explanation data, the reason why the target code belongs to the non-malicious category is explained.
6. The method according to claim 5, It is characterized in that The label word is obtained by abstracting the code features of the code belonging to the corresponding preset category. Then, based on the target label word of the non-malicious category, generating interpretation data for interpreting that the target code belongs to the non-malicious category includes: Based on the matching probability of the target label word of the non-malicious category, estimating the probability of the code feature of the target code triggering each network security event in the network security event set when the target code is executed, the network security events in the network security event set are network security events triggered by the code features of the malicious category code when the malicious category code is executed; based on the triggering probability of each network security event, generating interpretation data for explaining that the target code belongs to the non-malicious category; and / or, Constructing an association relationship between the target label word of the non-malicious category and the corresponding matching probability; determining the association relationship as explanation data for explaining that the target code belongs to the non-malicious category.
7. The method according to claim 3 or 5, It is characterized in that Selecting a target tag word from the tag words corresponding to the target preset category includes: Selecting a label word whose matching probability reaches a first probability threshold from among a plurality of label words corresponding to the target preset category as a target label word; or, Determine the order of multiple label words corresponding to the target preset category, and select the label words located in the first first number of digits as the target label words, wherein the order is obtained based on the order of label word matching probability from large to small, or the order is obtained based on the order of correlation between the label words and the target preset category from strong to weak.
8. The method according to claim 1, It is characterized in that The label word is obtained by abstracting the code features of the code belonging to the corresponding preset category. Then, determining the matching probability of each label word of the preset category and the target code includes: Detecting the occurrence probability of each word-element related to a preset category of code in a target word-element set in the target code, wherein the target word-element set includes words related to a preset category of code, and the target word-element set includes a first word-element corresponding to the label word, wherein the first word-element is used to describe a code feature abstracted by the corresponding label word; Determining the occurrence probability of the first word-gram corresponding to each of the tag words from the occurrence probabilities of the word-grams; Based on the occurrence probability of the first word element, the matching probability between each of the tag words and the target code is determined.
9. The method according to claim 8, It is characterized in that The tag word is obtained by abstracting the code features of the code belonging to the corresponding preset category, then, the method further includes: For each of the label words: match the label word with each label word in the target label word set that is related to a code of a preset category; if the label word matches a label word, determine the corresponding label word as the first label word corresponding to the label word; if the label word does not match a label word, derive a label word associated with the label word based on the code feature abstracted by the label word, and match the associated label word with each label word in the target label word set that is related to a code of a preset category; if the associated label word matches a label word, determine the corresponding label word as the first label word corresponding to the label word; if the associated label word does not match a label word, determine that the label word does not have a corresponding first label word.
10. The method according to claim 9, It is characterized in that After no word-gram is matched, and before determining that the tag word does not have a related first word-gram, the method further includes: Splitting the tag word into at least two second word-grams, and matching each second word-gram with each word-gram associated with a code of a preset category in the target word-gram set; If each second word-gram is matched to a word-gram, the corresponding word-gram is determined as the first word-gram related to the tag word; If there is a second word-gram that is not matched to a word-gram, the step of determining that the tag word does not have a related first word-gram is performed.
11. The method according to claim 9, It is characterized in that The method further comprises: If it is determined that the label word does not have a related first word-element, a preset probability is determined as the matching probability of the label word, and the preset probability is used to represent that the label word does not match the target code.
12. The method according to claim 8, It is characterized in that The malicious code detection system is preset with a target model, and the target model is used to identify the probability of occurrence of each word in the target word set related to the preset category of code in the code, Then, detecting the occurrence probability of each word element in the target word element set related to the code of the preset category in the target code includes: Inputting the target code into the target model, and identifying the occurrence probability of each word associated with a code of a preset category in the target word set in the target code through the target model; The step of determining the occurrence probability of the first word-gram corresponding to each of the tag words from the occurrence probabilities of the word-grams includes: The occurrence probability of the first word-gram corresponding to each of the tag words is determined from the occurrence probabilities of the word-grams through the target model.
13. The method according to claim 12, It is characterized in that The tag words corresponding to the codes of the at least two preset categories are preset in a mapper, and the mapper is bound to the target model. Then, before determining the occurrence probability of the first word unit corresponding to each of the tag words from the occurrence probability of the word units through the target model, the method further includes: Each label word corresponding to a preset category is read from the mapper through the target model.
14. The method according to claim 8, It is characterized in that If there are multiple first word-grams corresponding to the label word, then, based on the occurrence probability of the first word-grams, determining the matching probability between each of the label words and the target code includes: For each of the label words, an average value of the occurrence probabilities of a plurality of first word-units corresponding to the label word is determined as the matching probability between the label word and the target code.
15. The method according to claim 1, It is characterized in that There are multiple label words corresponding to each preset category. Based on the matching probability, determining the target preset category to which the target code belongs includes: Sort each label word corresponding to the at least two preset categories in descending order of the matching probability; Detect whether the tag words ranked in the first second digit correspond to the same preset category; If so, the corresponding preset category is determined as the target preset category to which the target code belongs; If not, the matching probability of each label word corresponding to each preset category is summarized and processed respectively to obtain the sum of matching probabilities corresponding to each preset category, and the preset category corresponding to the highest matching probability in the matching probability sum is determined as the target preset category to which the target code belongs.
16. The method according to claim 15, It is characterized in that The matching probability of each label word corresponding to each preset category is summarized and processed respectively to obtain the sum of the matching probabilities corresponding to each preset category, including: Calculate the sum of the matching probabilities of each label word corresponding to each preset category respectively, and obtain the sum of the matching probabilities corresponding to each preset category; or, Determine the weight of each tag word in the corresponding preset category; based on the corresponding weight, calculate the weighted sum of the matching probability of each tag word corresponding to each preset category, and obtain the sum of the matching probabilities corresponding to each preset category.
17. The method according to claim 15, It is characterized in that The malicious code detection system further stores the minimum proportions corresponding to the at least two preset categories, where the minimum proportion is the proportion of label words whose matching probability is not less than the second probability threshold in the label words corresponding to the preset categories. Then, after detecting that the label words ranked in the first second number of digits do not correspond to the same preset category, the method further includes: Determine a target proportion of label words whose matching probability is not less than a second probability threshold in the label words corresponding to each preset category; If there is a preset category with a target ratio higher than the corresponding minimum ratio, and the preset category with a target ratio higher than the corresponding minimum ratio includes a malicious category, the corresponding malicious category is determined as the target preset category to which the target code belongs; If there is a preset category whose target ratio is higher than the corresponding minimum ratio, and the preset category whose target ratio is higher than the corresponding minimum ratio includes a non-malicious category and does not include a malicious category, then the corresponding non-malicious category is determined as the target preset category to which the target code belongs; If there is no preset category whose target ratio is higher than the corresponding minimum ratio, a step of summarizing the matching probability of each label word corresponding to each preset category is performed to obtain the sum of the matching probabilities corresponding to each preset category.
18. The method according to any one of claims 1 to 6, 8 to 17, It is characterized in that The method further comprises: Get the corresponding sample code for each preset category; Extracting corresponding code features from the sample code; For each of the preset categories, conceptual words related to the code features corresponding to the preset category in the conceptual vocabulary corresponding to the preset category are extracted as candidate words, and label words of the preset category are set based on the candidate words, wherein the conceptual vocabulary stores at least one conceptual word corresponding to a code feature, and the conceptual word is obtained by abstracting the code features of the code belonging to the preset category.
19. The method according to claim 18, It is characterized in that Setting the label word of the preset category based on the candidate word includes: The candidate words corresponding to the preset category are screened, and the screened candidate words are set as label words corresponding to the preset category.
20. The method according to claim 19, It is characterized in that Screening candidate words corresponding to the preset category includes: Selecting a target sample code for candidate word screening from the corresponding sample codes of the preset category; Detecting the occurrence probability of each word-element in a target word-element set related to the code of the preset category in the target sample code, wherein the target word-element set includes word-element related to the code of the preset category, and the target word-element set includes target word-element corresponding to the candidate word; Determining the occurrence probability of the target word element corresponding to each candidate word from the occurrence probability of the word element; Based on the occurrence probability of the target word, determining the matching probability of each candidate word with the target sample code; The candidate words are screened based on the matching probability.
21. The method according to claim 19 or 20, It is characterized in that Screening candidate words corresponding to the preset category includes: Determine a positive score and a negative score for each candidate word of the preset category, wherein the positive score is a score indicating that the candidate word belongs to the preset category and does not belong to other preset categories, and the negative score is a score indicating that the candidate word belongs to other preset categories and does not belong to the preset category; Calculate the sum of the positive score and the negative score of each candidate word respectively to obtain the sum of the scores of each candidate word; The candidate words are screened based on the total score.
22. The method according to any one of claims 1 to 6, 8 to 17, It is characterized in that The method comprises: Determine whether the target code is a code in text form; if not, convert the target code into text form.
23. A malicious code detection device, It is characterized in that Applied to a malicious code detection system, the malicious code detection system stores label words corresponding to codes of at least two preset categories, the at least two preset categories include malicious categories and non-malicious categories, the label words are used to explain why the corresponding code belongs to the corresponding preset category, the device includes: A first determination module is used to determine the matching probability between each label word of a preset category and the target code when malicious code detection is required for the target code; A second determination module is used to determine the target preset category to which the target code belongs based on the matching probability; A first explanation module, configured to explain, if the target preset category is a malicious category, the reason why the target code belongs to the malicious category based on a label word corresponding to the malicious category; The second explanation module is used to explain the reason why the target code belongs to the non-malicious category based on the label word corresponding to the non-malicious category if the target preset category is the non-malicious category.
24. A computer-readable storage medium, It is characterized in that The storage medium includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the malicious code detection method described in any one of claims 1 to claim 22.
25. An electronic device, It is characterized in that The electronic device comprises: Memory, used to store programs; A processor, coupled to the memory, is used to run the program to execute the malicious code detection method described in any one of claims 1 to claim 22.
