A method, device, electronic device and storage medium for detecting malicious code
By establishing the tags and tag vectors of the code to be inspected and matching them with the malicious sample feature library, the problem of traditional virus detection methods being unable to detect virus variants is solved, and efficient detection and accurate identification of known virus variants are achieved.
Patent Information
- Application Number
- CN202111418201.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-24
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-11-24
AI Technical Summary
Traditional virus detection methods can only detect viruses already in the virus database and cannot effectively detect variants of known viruses.
By determining the basic block data information of the code to be checked, labels and label vectors are established, and matched with the label vectors in the pre-established malicious sample feature library. If they match, the code to be checked is determined to be malicious code.
It realizes the detection of known virus variants, reduces the false alarm rate, and improves detection efficiency and accuracy.
Smart Images

Figure CN114065202B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer network security, and in particular to a malicious code detection method, device, electronic device and storage medium. Background Art
[0002] The traditional method of analyzing and detecting viruses is to first debug a virus sample through manual analysis, extract a feature with special meaning that can characterize its behavior pattern (including special character strings, special behaviors, and specific binaries) based on its behavior pattern, and then compile the features extracted from different virus samples into a virus library. The virus is then detected using the features of the virus samples already in the virus library. Only viruses already in the virus library can be detected. Summary of the invention
[0003] In view of this, an embodiment of the present invention provides a malicious code detection method, device, electronic device and storage medium, which can detect variants of known virus samples.
[0004] To achieve the above object, the embodiments of the present invention adopt the following technical solutions:
[0005] An embodiment of the present invention provides a malicious code detection method, comprising: determining data information of a basic block of a code to be detected; establishing a label for the basic block of the code to be detected based on the data information of the basic block; establishing a label vector of the code to be detected according to a preset label vector establishment rule based on the label of the basic block of the code to be detected; matching the label vector of the code to be detected with a malicious sample label vector in a pre-established malicious sample feature library according to a preset matching rule; if it is determined that the label vector of the code to be detected matches a malicious sample label vector in the malicious sample feature library, then determining that the code to be detected is malicious code.
[0006] According to a specific implementation manner of the embodiment of the present invention, the data information of determining the basic block of the code to be checked includes: determining instruction information and / or application program interface information of the basic block of the code to be checked.
[0007] According to a specific implementation method of an embodiment of the present invention, a label is established for the basic block of the code to be checked based on the data information of the basic block, including: establishing a corresponding label for the basic block of the code to be checked based on the functional characteristics of the data information of the basic block.
[0008] According to a specific implementation method of an embodiment of the present invention, the label of the basic block of the code to be checked is established according to a preset label vector establishment rule to establish a label vector of the code to be checked, including: the label of the basic block of the code to be checked is established according to the order in which the basic blocks are executed in the code to be checked to establish the label vector of the code to be checked.
[0009] According to a specific implementation manner of an embodiment of the present invention, before determining the data information of the basic block of the code to be checked, the method also includes: establishing a basic block label library of known samples based on known samples; and establishing a malicious sample feature library of the malicious sample set based on the basic block label library of the known samples.
[0010] According to a specific implementation method of an embodiment of the present invention, establishing a basic block label library of known samples based on known samples includes: determining data information of at least two basic blocks in the known samples; establishing labels for the at least two basic blocks respectively based on the data information of the at least two basic blocks; and establishing a basic block label library of the known samples based on the labels of the at least two basic blocks.
[0011] According to a specific implementation method of an embodiment of the present invention, the malicious sample feature library of the malicious sample set is established based on the basic block label library of the known samples, including: establishing a malicious sample label vector library of the malicious sample set, and establishing a white sample label vector library of the white sample set; deleting the malicious sample label vectors in the malicious sample label vector library that match those in the white sample label vector library to obtain the malicious sample feature library.
[0012] According to a specific implementation of an embodiment of the present invention, the malicious sample set includes more than two malicious samples, and the more than two malicious samples include a first malicious sample and a second malicious sample; wherein, the establishment of a malicious sample label vector library of the malicious sample set includes: matching each basic block of the first malicious sample with the basic block of the known sample according to a preset matching rule, determining a first basic block that matches the basic block of the known sample from each basic block of the first malicious sample, and establishing a first label for the first basic block; the first label is the same as the label of the basic block that matches the first basic block in the known sample; the labels of each basic block in the first malicious sample are matched with each other; , establish a first malicious sample label vector according to the preset label vector establishment rule; match each basic block of the second malicious sample with the basic block of the known sample according to the preset matching rule, determine the second basic block that matches the basic block of the known sample from each basic block of the second malicious sample, and establish a second label for the second basic block; the second label is the same as the label of the basic block that matches the second basic block in the known sample; establish a second malicious sample label vector according to the preset label vector establishment rule for the label of each basic block in the second malicious sample; and establish a malicious sample label vector library of the malicious sample set based on the established malicious sample label vectors.
[0013] According to a specific implementation manner of an embodiment of the present invention, the white sample set includes more than two white samples, and the more than two white samples include a first white sample and a second white sample; wherein, the establishment of a white sample label vector library of the white sample set includes: matching each basic block of the first white sample with the basic block of the known sample according to a preset matching rule, determining a first basic block that matches the basic block of the known sample from each basic block of the first white sample, and establishing a first label for the first basic block; the first label is the same as the label of the basic block that matches the first basic block in the known sample; and matching the labels of each basic block in the first white sample with the basic block of the known sample. A first white sample label vector is established according to the preset label vector establishment rule; each basic block of the second white sample is matched with the basic block of the known sample according to the preset matching rule, and a second basic block matching the basic block of the known sample is determined from each basic block of the second white sample, and a second label is established for the second basic block; the second label is the same as the label of the basic block matching the second basic block in the known sample; a second white sample label vector is established according to the preset label vector establishment rule for the label of each basic block in the second white sample; and a white sample label vector library of the white sample set is established based on each established white sample label vector.
[0014] In a second aspect, the present invention provides a malicious code detection device, comprising: a basic block extraction module, used to determine data information of a basic block of a code to be detected; a label establishment module, used to establish a label for the basic block of the code to be detected based on the data information of the basic block; a label vector establishment module, used to establish a label vector of the code to be detected according to a preset label vector establishment rule based on the label of the basic block of the code to be detected; a label vector matching module, used to match the label vector of the code to be detected with a malicious sample label vector in a pre-established malicious sample feature library according to a preset matching rule; a malicious code determination module, used to determine that the code to be detected is malicious code if it is determined that the label vector of the code to be detected matches a malicious sample label vector in the malicious sample feature library.
[0015] According to a specific implementation of the embodiment of the present invention, the basic block extraction module is specifically used to: determine the instruction information and / or application program interface information of the basic block of the code to be checked.
[0016] According to a specific implementation of the embodiment of the present invention, the label establishment module is specifically used to: establish a corresponding label for the basic block of the code to be checked based on the functional characteristics of the data information of the basic block.
[0017] According to a specific implementation of the embodiment of the present invention, the label vector establishing module is specifically used to: establish the label vector of the code to be checked according to the order in which the basic blocks of the code to be checked are executed in the code to be checked.
[0018] According to a specific implementation method of an embodiment of the present invention, it also includes: a basic block label library establishment module, which is used to establish a basic block label library of known samples based on known samples; a malicious sample feature library establishment module, which is used to establish a malicious sample feature library of a malicious sample set based on the basic block label library of the known samples.
[0019] According to a specific implementation method of an embodiment of the present invention, the basic block label library establishment module is specifically used to: determine the data information of at least two basic blocks in a known sample; establish labels for the at least two basic blocks based on the data information of the at least two basic blocks; and establish a basic block label library for the known sample based on the labels of the at least two basic blocks.
[0020] According to a specific implementation method of an embodiment of the present invention, the malicious sample feature library establishment module is specifically used to: establish a malicious sample label vector library for a malicious sample set, and establish a white sample label vector library for a white sample set; delete the malicious sample label vectors in the malicious sample label vector library that match those in the white sample label vector library to obtain a malicious sample feature library.
[0021] According to a specific implementation of an embodiment of the present invention, the malicious sample set includes more than two malicious samples, and the more than two malicious samples include a first malicious sample and a second malicious sample; wherein, the establishment of a malicious sample label vector library of the malicious sample set includes: matching each basic block of the first malicious sample with the basic block of the known sample according to a preset matching rule, determining a first basic block that matches the basic block of the known sample from each basic block of the first malicious sample, and establishing a first label for the first basic block; the first label is the same as the label of the basic block that matches the first basic block in the known sample; the labels of each basic block in the first malicious sample are matched with each other; , establish a first malicious sample label vector according to the preset label vector establishment rule; match each basic block of the second malicious sample with the basic block of the known sample according to the preset matching rule, determine the second basic block that matches the basic block of the known sample from each basic block of the second malicious sample, and establish a second label for the second basic block; the second label is the same as the label of the basic block that matches the second basic block in the known sample; establish a second malicious sample label vector according to the preset label vector establishment rule for the label of each basic block in the second malicious sample; and establish a malicious sample label vector library of the malicious sample set based on the established malicious sample label vectors.
[0022] According to a specific implementation manner of an embodiment of the present invention, the white sample set includes more than two white samples, and the more than two white samples include a first white sample and a second white sample; wherein, the establishment of a white sample label vector library of the white sample set includes: matching each basic block of the first white sample with the basic block of the known sample according to a preset matching rule, determining a first basic block that matches the basic block of the known sample from each basic block of the first white sample, and establishing a first label for the first basic block; the first label is the same as the label of the basic block that matches the first basic block in the known sample; and matching the labels of each basic block in the first white sample with the basic block of the known sample. A first white sample label vector is established according to the preset label vector establishment rule; each basic block of the second white sample is matched with the basic block of the known sample according to the preset matching rule, and a second basic block matching the basic block of the known sample is determined from each basic block of the second white sample, and a second label is established for the second basic block; the second label is the same as the label of the basic block matching the second basic block in the known sample; a second white sample label vector is established according to the preset label vector establishment rule for the label of each basic block in the second white sample; and a white sample label vector library of the white sample set is established based on each established white sample label vector.
[0023] In a third aspect, an embodiment of the present invention provides an electronic device, comprising: a shell, a processor, a memory, a circuit board and a power supply circuit, wherein the circuit board is placed inside the space enclosed by the shell, and the processor and the memory are arranged on the circuit board; the power supply circuit is used to supply power to various circuits or devices of the above-mentioned electronic device; the memory is used to store executable program code; the processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the malicious code detection method described in any one of the above-mentioned first aspects.
[0024] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the malicious code detection method described in any one of the first aspects above.
[0025] The embodiments of the present invention provide a malicious code detection method, device, electronic device and storage medium. The function of the basic block of the code to be detected can be obtained by determining the data information of the basic block of the code to be detected. The function of the basic block of the code to be detected can be used to establish a label describing the function of the basic block of the code to be detected. A label vector describing the function of the code to be detected can be established by establishing a rule with a preset label vector and the label of the basic block of the code to be detected. The label vector that can describe the function of the code to be detected is matched with a malicious sample label vector that can describe the function of the malicious code. The code to be detected and the malicious code are functionally detected, so variants of malicious samples obtained by known viruses by modifying local features of malicious codes can be detected. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the embodiments of the present invention 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 only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0027] Figure 1 A schematic diagram of a malicious code detection method according to an embodiment of the present invention;
[0028] Figure 2 It is a schematic diagram of a basic block of an embodiment of the present invention;
[0029] Figure 3 This is a module diagram of a malicious code detection device according to an embodiment of the present invention;
[0030] Figure 4 It is a schematic diagram of a module of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0031] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0032] It should be clear that the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0033] Embodiment 1
[0034] See also Figure 1 and Figure 2 As shown, a malicious code detection method provided by an embodiment of the present invention includes:
[0035] S101, determining data information of a basic block of a code to be checked.
[0036] The code to be checked can be obtained by decompiling the file to be checked.
[0037] A basic block is a section of program code without branch instructions or branch destinations, that is, a sequence of statements executed sequentially by the program.
[0038] S102: Create a label for the basic block of the code to be checked based on the data information of the basic block.
[0039] Labels can be established for the basic blocks of the code to be checked through methods such as manual analysis, experience summary and machine learning; or labels can be established for the basic blocks of the code to be checked by matching the basic blocks with the basic blocks in a pre-established basic block label library and following the strategy of making the basic blocks equal or similar to the basic blocks in the basic block label library.
[0040] A label is a description of the functional characteristics of the data information of a basic block. It can be in the form of text description, hexadecimal data, etc. It can speed up the analyst's understanding of the sample, thereby helping to speed up the analyst's analysis process.
[0041] In addition, based on equal or similar strategies, analysts do not need to repeat the analysis of the code that has already been analyzed, which can reduce the workload of analysts.
[0042] S103: Using the labels of the basic blocks of the code to be checked according to a preset label vector establishment rule to establish a label vector of the code to be checked.
[0043] One code corresponds to one label vector, but one label vector can correspond to multiple codes.
[0044] S104: Match the label vector of the code to be checked with the malicious sample label vector in a pre-established malicious sample feature library according to a preset matching rule.
[0045] The preset matching rule means that the similarity value between the label vector of the code to be checked and the label vector of the malicious sample is determined by an algorithm or string matching method, and the similarity value is compared with a preset threshold: when the similarity value is less than the preset threshold, it is determined that the label vector of the code to be checked does not match the label vector of the malicious sample; when the similarity value is greater than or equal to the preset threshold, it is determined that the label vector of the code to be checked matches the label vector of the malicious sample.
[0046] S105: If it is determined that the label vector of the code to be checked matches a malicious sample label vector in the malicious sample feature library, the code to be checked is determined to be malicious code.
[0047] An embodiment of the present invention provides a malicious code detection method. By determining the data information of the basic block of the code to be detected, the function of the basic block of the code to be detected can be obtained. Through the function of the basic block of the code to be detected, a label describing the function of the basic block of the code to be detected can be established for the basic block of the code to be detected. By setting a preset label vector establishment rule and the label of the basic block of the code to be detected, a label vector describing the function of the code to be detected can be established. The label vector that can describe the function of the code to be detected is matched with a malicious sample label vector that can describe the function of the malicious code. The code to be detected and the malicious code are functionally detected, so variants of malicious samples obtained by known viruses by modifying local features of the malicious code can be detected.
[0048] In order to determine the functions that can be implemented by the basic block, in one embodiment, determining the data information of the basic block of the code to be checked includes: determining instruction information and / or application program interface information of the basic block of the code to be checked.
[0049] The data information of the basic blocks of the code to be checked can be determined by decompiling the code to be checked.
[0050] Determining the basic block application program interface information of the code to be checked refers to determining the application program interface information called by the basic block of the code to be checked.
[0051] Specifically, instructions are codes that tell the computer to perform a specific operation, so by analyzing instruction information, we can determine the functions that a basic block can achieve. Application program interfaces are predefined functional logic that allows a system to receive requests from other systems and return results to the system that sent the request, so the functions of the basic block can also be determined through the functions of the application program interface.
[0052] In one embodiment, establishing a label for the basic block of the code to be checked based on the data information of the basic block includes: establishing a corresponding label for the basic block of the code to be checked based on the functional characteristics of the data information of the basic block.
[0053] That is, the tag is used to characterize the functional characteristics of the data information of the basic block.
[0054] In some examples, the label may be a text description that characterizes the functional characteristics of the data information of the basic block, thereby facilitating the staff to analyze the basic block and the code to be checked.
[0055] Specifically, the data information of the basic blocks can be processed through methods such as manual analysis, experience summary and machine learning to determine the functions of the basic blocks, thereby establishing labels for the basic blocks of the code to be inspected.
[0056] In one embodiment, the step of establishing a label vector of the code to be checked according to a preset label vector establishment rule based on the labels of the basic blocks of the code to be checked includes: establishing the label vector of the code to be checked according to the order in which the basic blocks are executed in the code to be checked.
[0057] It can be understood that a label vector is a vector composed of multiple labels.
[0058] The label vector of the code to be checked can be established by sequentially connecting the labels of the basic blocks of the code to be checked according to the execution order of the basic blocks corresponding to the labels in the code to be checked. Since the label can be a text description of the functional characteristics of the data information of the basic block, the labels of the basic blocks are connected according to the execution order of the basic blocks in the code to be checked, and the label vector of the code to be checked obtained can also be a text description of the functional characteristics of the code to be checked, that is, the label vector can be used to characterize the functional characteristics of the code to be checked.
[0059] In one embodiment, before determining the data information of the basic block of the code to be checked, the method further includes: establishing a basic block label library of known samples based on known samples; and establishing a malicious sample feature library of the malicious sample set according to the basic block label library of known samples.
[0060] Known samples can be white samples, black samples, or samples that cannot be judged as black or white. Because the key to establishing a basic block label library of known samples is to add labels to basic blocks, characterize the functions of basic blocks through labels, and speed up the analysis process of staff, so known samples can be white samples, black samples, or samples that cannot be judged as black or white.
[0061] Here, the basic block label library can be used to establish malicious samples and malicious sample feature libraries, and can also be used to establish label vectors of the code to be checked. Then, by matching the label vector of the code to be checked with the malicious sample feature library, it can be determined whether the code to be checked is malicious code.
[0062] In one embodiment, establishing a basic block label library of known samples based on known samples includes: determining data information of at least two basic blocks in the known samples; establishing labels for the at least two basic blocks based on the data information of the at least two basic blocks; and establishing a basic block label library of the known samples based on the labels of the at least two basic blocks.
[0063] The data information of the basic blocks of the known samples can be determined by decompiling the known samples.
[0064] The first labels of different basic blocks may be different, and the same basic block may have more than two labels.
[0065] The basic block tag library can be used to represent malicious samples, white samples, and code to be checked, and the accuracy of the basic block tag library in representing malicious samples, white samples, and code to be checked is proportional to the number of basic blocks in the basic block tag library. At the same time, the establishment of the basic block library avoids the duplication of work of analysts, and transforms the identification of some code to be checked from manual identification to automatic identification, greatly improving work efficiency.
[0066] See also Figure 2 In one example, a known sample is 191E9FCB2DF403717D5190658B6FC1D3. Through decompilation, there is a basic block at the offset 0x10013170. It can be determined that the data information of the basic block is the hexadecimal data 64a1300000008b400c8b701cad8b58088bc383c03c8b0003c383c0788b00. Through manual analysis, it is determined that the function of the basic block is to obtain the base address of kernelbase.dll, so the label for the basic block is to obtain kernelbase.dll. By analogy, labels can be established for other basic blocks, and then a basic block label library of known samples can be established based on these labeled basic blocks.
[0067] In order to reduce the false alarm rate of the solution provided by the present application when detecting the code to be checked, in one embodiment, a malicious sample feature library of the malicious sample set is established based on the basic block label library of the known samples, including: establishing a malicious sample label vector library of the malicious sample set, and establishing a white sample label vector library of the white sample set; deleting the malicious sample label vectors in the malicious sample label vector library that match those in the white sample label vector library to obtain a malicious sample feature library.
[0068] It is understandable that white samples and malicious samples have different execution purposes, but may have some of the same functions. For example, white samples modify the registry to enhance their own work efficiency, while malicious samples modify the registry to hide themselves. The execution purposes of the two are different, but both have the function of modifying the registry.
[0069] Due to the limitations of the basic block label library itself, the label vectors of a white sample and a malicious sample expressed by the basic block label library may be the same. Therefore, when the label vector obtained by expressing a code to be checked by the basic block label library is the same as the label vector, it cannot be determined that the code to be checked is malicious code. However, since the label vector exists in the malicious sample feature library, the code to be checked will be confirmed as malicious code, thereby generating a false alarm. Therefore, by deleting the malicious sample label vectors in the malicious sample label vector library that match the white sample label vector library, the false alarm rate of the solution provided by the present application when detecting the code to be checked can be reduced.
[0070] In one embodiment, the malicious sample set includes more than two malicious samples, and the more than two malicious samples include a first malicious sample and a second malicious sample; wherein, the establishment of a malicious sample label vector library of the malicious sample set includes: matching each basic block of the first malicious sample with the basic block of the known sample according to a preset matching rule, determining a first basic block that matches the basic block of the known sample from each basic block of the first malicious sample, and establishing a first label for the first basic block; the first label is the same as the label of the basic block that matches the first basic block in the known sample; matching the labels of each basic block in the first malicious sample according to the preset matching rule; A label vector establishment rule is set to establish a first malicious sample label vector; each basic block of the second malicious sample is matched with the basic block of the known sample according to a preset matching rule, and a second basic block matching the basic block of the known sample is determined from each basic block of the second malicious sample, and a second label is established for the second basic block; the second label is the same as the label of the basic block matching the second basic block in the known sample; the label of each basic block in the second malicious sample is established according to the preset label vector establishment rule to establish a second malicious sample label vector; based on the established malicious sample label vectors, a malicious sample label vector library of the malicious sample set is established.
[0071] Each basic block of malicious samples is matched with the basic blocks of known samples according to the equal or similar matching rules.
[0072] The more malicious sample label vectors included in the malicious sample label vector library, the better the effect of detecting the code to be checked by the malicious sample feature library established by cooperating with the malicious sample label vector library and the white sample label vector library, and the lower the false alarm rate of detecting the code to be checked.
[0073] In one embodiment, the white sample set includes more than two white samples, and the more than two white samples include a first white sample and a second white sample; wherein, the establishing of a white sample label vector library of the white sample set includes: matching each basic block of the first white sample with the basic block of the known sample according to a preset matching rule, determining a first basic block matching the basic block of the known sample from each basic block of the first white sample, and establishing a first label for the first basic block; the first label is the same as the label of the basic block matching the first basic block in the known sample; matching the labels of each basic block in the first white sample according to the preset matching rule; A label vector is established according to a rule to establish a first white sample label vector; each basic block of the second white sample is matched with the basic block of the known sample according to a preset matching rule, and a second basic block matching the basic block of the known sample is determined from each basic block of the second white sample, and a second label is established for the second basic block; the second label is the same as the label of the basic block matching the second basic block in the known sample; the label of each basic block in the second white sample is established according to the preset label vector establishment rule to establish a second white sample label vector; based on the established white sample label vectors, a white sample label vector library of the white sample set is established.
[0074] Each basic block of the white sample is matched with the basic block of the known sample according to the equal or similar matching rules.
[0075] The more white sample label vectors included in the white sample label vector library, the better the effect of detecting the code to be checked by the malicious sample feature library established by cooperating with the malicious sample label vector library and the white sample label vector library, and the lower the false alarm rate of detecting the code to be checked.
[0076] Embodiment 2
[0077] See also Figure 3An embodiment of the present invention provides a malicious code detection device, comprising: a basic block extraction module, used to determine data information of a basic block of a code to be detected; a label establishment module, used to establish a label for the basic block of the code to be detected based on the data information of the basic block; a label vector establishment module, used to establish a label vector of the code to be detected according to a preset label vector establishment rule based on the label of the basic block of the code to be detected; a label vector matching module, used to match the label vector of the code to be detected with a malicious sample label vector in a pre-established malicious sample feature library according to a preset matching rule; a malicious code determination module, used to determine that the code to be detected is malicious code if it is determined that the label vector of the code to be detected matches a malicious sample label vector in the malicious sample feature library.
[0078] An embodiment of the present invention provides a malicious code detection device. By determining the data information of the basic block of the code to be detected, the function of the basic block of the code to be detected can be obtained. Through the function of the basic block of the code to be detected, a label describing the function of the basic block of the code to be detected can be established for the basic block of the code to be detected. By setting a preset label vector establishment rule and the label of the basic block of the code to be detected, a label vector describing the function of the code to be detected can be established. The label vector that can describe the function of the code to be detected is matched with the malicious sample label vector that can describe the function of the malicious code. The code to be detected and the malicious code are functionally detected, so variants of malicious samples obtained by known viruses by modifying local features of malicious codes can be detected.
[0079] In one embodiment, the basic block extraction module is specifically used to determine instruction information and / or application program interface information of the basic block of the code to be checked.
[0080] Determining the basic block application program interface information of the code to be checked refers to determining the application program interface information called by the basic block of the code to be checked. Specifically, an instruction is a code that tells the computer to perform a specific operation, so by analyzing the instruction information, the functions that the basic block can achieve can be determined. The application program interface is a predefined function logic that allows a system to receive requests from other systems and return results to the system that sent the request, so the functions that the basic block can achieve can also be determined through the functions of the application program interface.
[0081] In one embodiment, the label creation module is specifically used to create a corresponding label for the basic block of the code to be checked based on the functional characteristics of the data information of the basic block.
[0082] In some examples, the label may be a text description that characterizes the functional characteristics of the data information of the basic block, thereby facilitating the staff to analyze the basic block and the code to be checked.
[0083] In one embodiment, the label vector establishing module is specifically used to establish the label vector of the code to be checked according to the execution order of the basic blocks in the code to be checked.
[0084] The label vector of the code to be checked can be established by sequentially connecting the labels of the basic blocks of the code to be checked according to the execution order of the basic blocks corresponding to the labels in the code to be checked. Since the label can be a text description of the functional characteristics of the data information of the basic block, the labels of the basic blocks are connected according to the execution order of the basic blocks in the code to be checked, and the label vector of the code to be checked obtained can also be a text description of the functional characteristics of the code to be checked, that is, the label vector can be used to characterize the functional characteristics of the code to be checked.
[0085] In one embodiment, it also includes: a basic block label library establishment module, which is used to establish a basic block label library of known samples based on known samples; a malicious sample feature library establishment module, which is used to establish a malicious sample feature library of a malicious sample set based on the basic block label library of the known samples.
[0086] Here, the basic block label library can be used to establish malicious samples and malicious sample feature libraries, and can also be used to establish label vectors of the code to be checked. Then, by matching the label vector of the code to be checked with the malicious sample feature library, it can be determined whether the code to be checked is malicious code.
[0087] In one embodiment, the basic block label library establishment module is specifically used to: determine the data information of at least two basic blocks in a known sample; establish labels for the at least two basic blocks based on the data information of the at least two basic blocks; and establish a basic block label library of the known sample based on the labels of the at least two basic blocks.
[0088] The data information of the basic blocks of the known samples can be determined by decompiling the known samples.
[0089] The same basic block may have more than two labels, and the first labels of different basic blocks may be different.
[0090] In one embodiment, the malicious sample feature library establishment module is specifically used to: establish a malicious sample label vector library for a malicious sample set, and establish a white sample label vector library for a white sample set; delete the malicious sample label vectors in the malicious sample label vector library that match those in the white sample label vector library to obtain a malicious sample feature library.
[0091] It is understandable that white samples and malicious samples have different execution purposes, but may have some of the same functions. For example, white samples modify the registry to enhance their own work efficiency, while malicious samples modify the registry to hide themselves. The execution purposes of the two are different, but both have the function of modifying the registry.
[0092] In one embodiment, the malicious sample set includes more than two malicious samples, and the more than two malicious samples include a first malicious sample and a second malicious sample; wherein, the establishment of a malicious sample label vector library of the malicious sample set includes: matching each basic block of the first malicious sample with the basic block of the known sample according to a preset matching rule, determining a first basic block that matches the basic block of the known sample from each basic block of the first malicious sample, and establishing a first label for the first basic block; the first label is the same as the label of the basic block that matches the first basic block in the known sample; matching the labels of each basic block in the first malicious sample according to the preset matching rule; A label vector establishment rule is set to establish a first malicious sample label vector; each basic block of the second malicious sample is matched with the basic block of the known sample according to a preset matching rule, and a second basic block matching the basic block of the known sample is determined from each basic block of the second malicious sample, and a second label is established for the second basic block; the second label is the same as the label of the basic block matching the second basic block in the known sample; the label of each basic block in the second malicious sample is established according to the preset label vector establishment rule to establish a second malicious sample label vector; based on the established malicious sample label vectors, a malicious sample label vector library of the malicious sample set is established.
[0093] In one embodiment, the white sample set includes more than two white samples, and the more than two white samples include a first white sample and a second white sample; wherein, the establishing of a white sample label vector library of the white sample set includes: matching each basic block of the first white sample with the basic block of the known sample according to a preset matching rule, determining a first basic block matching the basic block of the known sample from each basic block of the first white sample, and establishing a first label for the first basic block; the first label is the same as the label of the basic block matching the first basic block in the known sample; matching the labels of each basic block in the first white sample according to the preset matching rule; A label vector is established according to a rule to establish a first white sample label vector; each basic block of the second white sample is matched with the basic block of the known sample according to a preset matching rule, and a second basic block matching the basic block of the known sample is determined from each basic block of the second white sample, and a second label is established for the second basic block; the second label is the same as the label of the basic block matching the second basic block in the known sample; the label of each basic block in the second white sample is established according to the preset label vector establishment rule to establish a second white sample label vector; based on the established white sample label vectors, a white sample label vector library of the white sample set is established.
[0094] Embodiment 3
[0095] See also Figure 4 An embodiment of the present invention provides an electronic device, comprising: a housing, a processor, a memory, a circuit board and a power supply circuit, wherein the circuit board is arranged inside the space enclosed by the housing, and the processor and the memory are arranged on the circuit board; the power supply circuit is used to supply power to various circuits or devices of the above-mentioned electronic device; the memory is used to store executable program code; the processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the malicious code detection method described in any one of the above-mentioned embodiments.
[0096] Embodiment 4
[0097] An embodiment of the present invention provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement the malicious code detection method described in any one of the above-mentioned embodiments.
[0098] When extracting features with special significance from the behavior patterns of malicious samples, dynamic acquisition is often used, and the pass rate for samples that are dependent on the environment and cannot be directly executed is very low. The method of statically matching API sequences is not comprehensive and accurate enough. The embodiment of the present invention provides a malicious code detection method, device, electronic device and storage medium, which establishes a basic block label library by analyzing known samples; then the malicious samples are expressed by the basic blocks in the basic block label library to obtain a malicious sample label vector library, and the white samples are expressed by the basic blocks in the basic block label library to obtain a white sample label vector library, and the malicious sample feature library is obtained by the malicious sample label vector library and the white sample label vector library; then the code to be checked is expressed by the basic blocks in the basic block label library, and matched with the malicious sample feature library to determine whether the code to be checked is a malicious sample. The basic block information formed by the fine-grained analysis of the code to be checked can more effectively express the behavior and function of the code to be checked, and the code to be checked and the malicious code are functionally detected, which can effectively prevent the malicious sample from being modified by the anti-virus engine to avoid detection.
[0099] It should be noted that, in this article, the emphasis of the scheme described in each embodiment is different, but each embodiment has a certain interrelated relationship. When understanding the scheme of the present invention, each embodiment can refer to each other; in addition, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0100] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims
1. A malicious code detection method, characterized in that: include: Determine the data information of the basic block of the code to be checked; Based on the data information of the basic block, a label is established for the basic block of the code to be checked; The labels of the basic blocks of the code to be checked are used to establish a label vector of the code to be checked according to a preset label vector establishment rule; Matching the label vector of the code to be checked with the malicious sample label vector in a pre-established malicious sample feature library according to a preset matching rule; If it is determined that the label vector of the code to be checked matches a malicious sample label vector in the malicious sample feature library, then the code to be checked is determined to be malicious code; Based on the data information of the basic block, a label is established for the basic block of the code to be checked, including: Based on the functional characteristics of the data information of the basic block, a corresponding label is established for the basic block of the code to be checked; The step of establishing a label vector of the code to be checked by using the label of the basic block of the code to be checked according to a preset label vector establishment rule includes: The labels of the basic blocks of the code to be checked are used to establish a label vector of the code to be checked according to the execution order of the basic blocks in the code to be checked.
2. The malicious code detection method according to claim 1, characterized in that: The data information of the basic block of the code to be checked is determined, including: Determine instruction information and / or application program interface information of a basic block of the code to be checked.
3. The malicious code detection method according to claim 1, characterized in that: Before determining the data information of the basic block of the code to be checked, the method further includes: Based on known samples, a basic block label library of known samples is established; A malicious sample feature library of a malicious sample set is established based on the basic block label library of the known samples.
4. The malicious code detection method according to claim 3, characterized in that: The step of establishing a basic block tag library of known samples based on known samples includes: Determine data information of at least two basic blocks in a known sample; Based on the data information of the at least two basic blocks, respectively establish labels for the at least two basic blocks; A basic block label library of the known samples is established based on the labels of the at least two basic blocks.
5. The malicious code detection method according to claim 3, characterized in that: The step of establishing a malicious sample feature library of a malicious sample set according to the basic block tag library of the known samples includes: Establish a malicious sample label vector library for the malicious sample set, and establish a white sample label vector library for the white sample set; The malicious sample label vectors in the malicious sample label vector library that match those in the white sample label vector library are deleted to obtain a malicious sample feature library.
6. The malicious code detection method according to claim 5, characterized in that: The malicious sample set includes more than two malicious samples, and the more than two malicious samples include a first malicious sample and a second malicious sample; The step of establishing a malicious sample label vector library of a malicious sample set includes: Matching each basic block of the first malicious sample with the basic block of the known sample according to a preset matching rule, determining a first basic block that matches the basic block of the known sample from each basic block of the first malicious sample, and establishing a first label for the first basic block; the first label is the same as the label of the basic block in the known sample that matches the first basic block; The labels of each basic block in the first malicious sample are used according to the preset label vector establishment rule to establish a first malicious sample label vector; Matching each basic block of the second malicious sample with the basic block of the known sample according to a preset matching rule, determining a second basic block matching the basic block of the known sample from each basic block of the second malicious sample, and establishing a second label for the second basic block; the second label is the same as the label of the basic block matching the second basic block in the known sample; The labels of each basic block in the second malicious sample are used to establish a second malicious sample label vector according to the preset label vector establishment rule; Based on the established label vectors of each malicious sample, a malicious sample label vector library of the malicious sample set is established.
7. The malicious code detection method according to claim 5, characterized in that: The white sample set includes more than two white samples, and the more than two white samples include a first white sample and a second white sample; The step of establishing a white sample label vector library of a white sample set includes: Matching each basic block of the first white sample with the basic block of the known sample according to a preset matching rule, determining a first basic block matching the basic block of the known sample from each basic block of the first white sample, and establishing a first label for the first basic block; the first label is the same as the label of the basic block matching the first basic block in the known sample; The labels of each basic block in the first white sample are used according to the preset label vector establishment rule to establish a first white sample label vector; Matching each basic block of the second white sample with the basic block of the known sample according to a preset matching rule, determining a second basic block matching the basic block of the known sample from each basic block of the second white sample, and establishing a second label for the second basic block; the second label is the same as the label of the basic block matching the second basic block in the known sample; The labels of each basic block in the second white sample are used to establish a second white sample label vector according to the preset label vector establishment rule; Based on the established white sample label vectors, a white sample label vector library of the white sample set is established.
8. A malicious code detection device, characterized in that: include: A basic block extraction module is used to determine the data information of the basic block of the code to be checked; A label establishment module, used for establishing a label for the basic block of the code to be checked based on the data information of the basic block; A label vector establishment module, used to establish a label vector of the code to be checked according to a preset label vector establishment rule by using the label of the basic block of the code to be checked; A label vector matching module is used to match the label vector of the code to be checked with the malicious sample label vector in a pre-established malicious sample feature library according to a preset matching rule; A malicious code determination module, configured to determine that the code to be detected is malicious code if it is determined that the label vector of the code to be detected matches a malicious sample label vector in the malicious sample feature library; The label creation module is specifically used for: Based on the functional characteristics of the data information of the basic block, a corresponding label is established for the basic block of the code to be checked; The label vector establishment module is specifically used for: The labels of the basic blocks of the code to be checked are used to establish a label vector of the code to be checked according to the execution order of the basic blocks in the code to be checked.
9. The malicious code detection device according to claim 8, characterized in that: The basic block extraction module is specifically used for: Determine instruction information and / or application program interface information of a basic block of the code to be checked.
10. The malicious code detection device according to claim 8, characterized in that: Also includes: A basic block label library building module is used to build a basic block label library of known samples based on known samples; The malicious sample feature library establishment module is used to establish a malicious sample feature library of a malicious sample set according to the basic block label library of the known samples.
11. The malicious code detection device according to claim 10, characterized in that: The basic block tag library establishment module is specifically used for: Determine data information of at least two basic blocks in a known sample; Based on the data information of the at least two basic blocks, respectively establish labels for the at least two basic blocks; A basic block label library of the known samples is established based on the labels of the at least two basic blocks.
12. The malicious code detection device according to claim 10, characterized in that: The malicious sample feature library establishment module is specifically used to: Establish a malicious sample label vector library for the malicious sample set, and establish a white sample label vector library for the white sample set; The malicious sample label vectors in the malicious sample label vector library that match those in the white sample label vector library are deleted to obtain a malicious sample feature library.
13. The malicious code detection device according to claim 12, characterized in that: The malicious sample set includes more than two malicious samples, and the more than two malicious samples include a first malicious sample and a second malicious sample; The step of establishing a malicious sample label vector library of a malicious sample set includes: Matching each basic block of the first malicious sample with the basic block of the known sample according to a preset matching rule, determining a first basic block that matches the basic block of the known sample from each basic block of the first malicious sample, and establishing a first label for the first basic block; the first label is the same as the label of the basic block in the known sample that matches the first basic block; The labels of each basic block in the first malicious sample are used according to the preset label vector establishment rule to establish a first malicious sample label vector; Matching each basic block of the second malicious sample with the basic block of the known sample according to a preset matching rule, determining a second basic block matching the basic block of the known sample from each basic block of the second malicious sample, and establishing a second label for the second basic block; the second label is the same as the label of the basic block matching the second basic block in the known sample; The labels of each basic block in the second malicious sample are used to establish a second malicious sample label vector according to the preset label vector establishment rule; Based on the established label vectors of each malicious sample, a malicious sample label vector library of the malicious sample set is established.
14. The malicious code detection device according to claim 12, characterized in that: The white sample set includes more than two white samples, and the more than two white samples include a first white sample and a second white sample; The step of establishing a white sample label vector library of a white sample set includes: Matching each basic block of the first white sample with the basic block of the known sample according to a preset matching rule, determining a first basic block matching the basic block of the known sample from each basic block of the first white sample, and establishing a first label for the first basic block; the first label is the same as the label of the basic block matching the first basic block in the known sample; The labels of each basic block in the first white sample are used according to the preset label vector establishment rule to establish a first white sample label vector; Matching each basic block of the second white sample with the basic block of the known sample according to a preset matching rule, determining a second basic block matching the basic block of the known sample from each basic block of the second white sample, and establishing a second label for the second basic block; the second label is the same as the label of the basic block matching the second basic block in the known sample; The labels of each basic block in the second white sample are used to establish a second white sample label vector according to the preset label vector establishment rule; Based on the established white sample label vectors, a white sample label vector library of the white sample set is established.
15. An electronic device, characterized in that: include: A shell, a processor, a memory, a circuit board and a power supply circuit, wherein the circuit board is placed inside the space enclosed by the shell, and the processor and the memory are arranged on the circuit board; the power supply circuit is used to supply power to various circuits or devices of the above-mentioned electronic device; the memory is used to store executable program code; the processor runs the program corresponding to the executable program code by reading the executable program code stored in the memory, and is used to execute the malicious code detection method described in any one of claims 1 to 7.
16. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the malicious code detection method described in any one of claims 1 to 7.
