A software backdoor detection method based on normalized syntax tree

By using a detection method based on a standardized syntax tree to process software code variants, generate hash signatures and establish a feature library, efficient detection of software backdoors is achieved and the problem of insufficient detection capabilities in the existing technology is solved.

CN118278003BActive Publication Date: 2024-09-27CHINESE PEOPLES LIBERATION ARMY UNIT 61660
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410341849.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-25
Publication Date
2024-09-27
Estimated Expiration
2044-03-25

AI Technical Summary

Technical Problem

Existing technology is difficult to comprehensively detect code variants of software backdoors, resulting in insufficient detection capabilities and the inability to discover more potential problems.

Method used

Using a detection method based on a standardized syntax tree, a syntax tree is generated through lexical and syntax analysis, node filtering, name replacement, branch swapping and instruction sorting are performed to generate a standardized syntax tree, calculate hash signatures and establish a malicious code signature library for Detect similarities of code under test.

Benefits of technology

Effectively handle code variants, improve software backdoor detection capabilities, discover more potential problems, and make up for the shortcomings of traditional detection methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118278003B
    Figure CN118278003B
Patent Text Reader

Abstract

The present invention relates to a software backdoor detection method based on a normalized syntax tree, and belongs to the field of software security. In order to make up for the deficiencies of traditional software component analysis methods in detecting code variants, improve the detection capability of software backdoors, and discover more potential problems, the present invention extracts software source code features by generating a normalized syntax tree model, constructs a malicious code feature library and establishes a corresponding retrieval mechanism, calculates the similarity between the tested software code and the malicious code, thereby realizing the function of software backdoor detection. Through the normalized syntax tree model, the present invention can effectively process various forms of code variants such as adding and reducing blank characters, modifying comments, replacing names, conditional conversions, and word order adjustments, making up for the deficiencies of traditional software component analysis methods in detecting code variants, improving the detection capability of software backdoors, and discovering more potential problems.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of software security, and in particular relates to a software backdoor detection method based on a normalized syntax tree. Background Art

[0002] With the rapid development of information technology, computer software has become an indispensable production tool in today's society. However, the security issues that come with it are also receiving increasing attention, and the detection and protection of software backdoors is one of the important issues. Software backdoors refer to malicious codes that are deliberately implanted into software systems. Attackers can use them to bypass normal security mechanisms, control target systems, or steal private data. They are a high-risk hidden danger that seriously threatens the security of network systems.

[0003] For software backdoor detection, researchers in the security industry have proposed some effective detection methods, such as detection technology based on network protocols and dynamic behavior, detection technology based on traffic monitoring and abnormal transmission, detection technology based on instruction impact, and detection technology based on deep learning, etc. However, due to the complexity and concealment of software backdoors, these methods are difficult to fully solve the problem, and new technical means are needed to strengthen the detection system. Summary of the invention

[0004] 1. Technical issues to be resolved

[0005] The technical problem to be solved by the present invention is to provide a software backdoor detection method to make up for the deficiencies of traditional software component analysis methods in detecting code variants, improve the detection capability of software backdoors, and discover more potential problems.

[0006] (II) Technical solution

[0007] In order to solve the above technical problems, the present invention provides a software backdoor detection method based on a normalized syntax tree, comprising the following steps:

[0008] Step 1: Collect projects related to software backdoors in the open source community and use them as the initial data set after screening;

[0009] Step 2: Mark the code snippets related to the backdoor in the initial data set, obtain the corresponding code files, and build a malicious code library;

[0010] Step 3: Generate the corresponding syntax tree through lexical and grammatical analysis of the code in the malicious code library;

[0011] Step 4: Normalize the syntax tree and generate a standardized syntax tree through node filtering, name replacement, branch swapping, and instruction sorting operations;

[0012] Step 5: Get the code corresponding to the root node of the normalized syntax tree and generate the corresponding hash feature code;

[0013] Step 6: Store the signature code in the database and create an index to generate a malicious code signature library;

[0014] Step 7: For the tested code, generate a hash signature using the same method as steps 3 to 5;

[0015] Step 8: Use the generated hash signature to search and query the malicious code signature database;

[0016] Step 9: When matching backdoor features are retrieved, determine that there is a suspected software backdoor and give the specific code location.

[0017] Preferably, in the first step, projects related to software backdoors are collected from the open source community, and projects whose keywords include {backdoor, shell, malicious} are screened. Then, they are confirmed by manual inspection, and detection tool categories and other irrelevant projects are removed, and the remaining projects are used as the initial data set.

[0018] Preferably, in the second step, for the initial data set, by analyzing the project's problem records, code comments, and submission history, combined with manual labeling, code snippets related to the backdoor are screened out, corresponding code files are obtained, and a malicious code library is formed.

[0019] Preferably, in the third step, for the code in the malicious code library, use the Antlr4 tool to generate a parser of the corresponding language, segment the code through lexical analysis, and divide the code text into lexical units of the smallest strength; through syntax analysis, according to the syntax specifications of a specific programming language, establish a corresponding tree data structure, the root node represents the compilation unit, and the program is disassembled layer by layer from the root node downward, and the leaf nodes represent the basic lexical units; through the Antlr4 tool and the rules and conventions on lexical and grammatical rules, complete the analysis of multiple programming languages ​​and generate a syntax tree.

[0020] Preferably, when the syntax tree is normalized in the fourth step, the following processes are performed in sequence:

[0021] In the syntax tree, comments are represented by separate leaf nodes. Leaf nodes related to comments are pruned from the syntax tree, leaving only code-related content.

[0022] In the syntax tree, variable names, function names, etc. are represented by separate leaf nodes. In this step, the leaf nodes representing variable names are uniformly replaced with variable, function names are uniformly replaced with method, constants are uniformly replaced with const, and type names are uniformly replaced with type.

[0023] Check all judgment condition nodes. The expressions in these judgment condition nodes are used to represent the judgment conditions of the branch statements. If the condition is true, the program will continue to execute the left branch. If the condition is false, the program will continue to execute the right branch. The judgment conditions in the branch nodes are processed uniformly, the leading "not" operator is removed, and the left and right branches of the condition nodes are swapped to keep the semantics unchanged.

[0024] In the syntax tree, starting from the root node, all program statements are processed recursively downward, and nodes with complete program instructions are represented as statement nodes. Statement nodes with the same parent node are sorted according to the dictionary order of the corresponding code string, and the order of each child node is adjusted according to the sorting result, from the root node to the leaf node layer by layer; in the syntax tree, the parent node is the splicing of the child nodes, and the deletion, modification and sorting of the child nodes will be synchronized to the parent node, and finally affect the content of the root node;

[0025] After processing, the normalized form of the syntax tree is obtained, namely the normalized syntax tree.

[0026] Preferably, the normalized syntax tree as a whole represents a complete compilation unit file. In the fifth step, for the child nodes in the normalized syntax tree, the subtrees corresponding to the functions and code blocks are found according to the node level and type, so as to obtain the codes corresponding to the root nodes after normalization at the file, function, and code block levels, respectively. For the codes corresponding to these root nodes, the blank characters and line breaks are removed, and the MD5 value of the code is generated as the hash feature code.

[0027] Preferably, in the sixth step, the file features, function features and code block features stored in the database are respectively formed into three corresponding data tables, and indexes of the corresponding features are established, thereby forming a malicious code feature library.

[0028] Preferably, in the seventh step, for the code under test, the method of steps three to five is also used to generate hash signature codes at three levels: file, function, and code block.

[0029] Preferably, in the ninth step, for the retrieved matching feature codes, results at the file level, function level or code block level are given according to the matching level as suspected software backdoors.

[0030] The present invention also provides a system for implementing the method.

[0031] (III) Beneficial effects

[0032] The present invention extracts software source code features by generating a standardized syntax tree model, constructs a malicious code feature library and establishes a corresponding retrieval mechanism, calculates the similarity between the tested software code and the malicious code, and thus realizes the function of software backdoor detection. The present invention can effectively handle various forms of code variants such as adding or removing blank characters, modifying comments, replacing names, conditional conversion, and word order adjustment by standardizing the syntax tree model, making up for the deficiencies of traditional software component analysis methods in detecting code variants, improving the detection capability of software backdoors, and discovering more potential problems. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] Figure 1 It is the overall flow chart of software backdoor detection based on the standardized syntax tree of the present invention, which is divided into 9 stages, namely, collecting the initial data set, building a malicious code library, generating a syntax tree, normalizing the syntax tree, generating a feature code, building a feature library, generating a feature code of the tested software, feature retrieval, and suspected backdoor determination;

[0034] Figure 2 It is a screenshot of a Java function that includes a software backdoor;

[0035] Figure 3 It is a syntax tree model generated by lexical and grammatical analysis of Java source code. The nodes in it can correspond to specific program structures. Here, taking function as an example, the root node corresponds to function definition. It is disassembled downward by level. The child nodes can correspond to the detailed structure of the program. Finally, the leaf nodes correspond to the basic elements in the code, such as keywords, variable names, function names, comments, etc. The syntax tree of a file or code block also follows the same structure.

[0036] Figure 4 It is the result of normalizing the syntax tree, removing nodes such as whitespace and comments; uniformly replacing elements such as variable names, types, function names, and constants; taking positive values ​​for the conditions of conditional statements and swapping the child nodes of the then and else branches; and sorting program statements, i.e., statement-level nodes, according to the lexicographic order of the corresponding codes. After the above operations, the model is converted to obtain a normalized syntax tree model.

[0037] Figure 5 It is a screenshot of the normalized code text corresponding to the root node;

[0038] Figure 6 yes Figure 5 Code variants. DETAILED DESCRIPTION

[0039] In order to make the purpose, content and advantages of the present invention more clear, the specific implementation methods of the present invention are further described in detail below in conjunction with the drawings and examples.

[0040] The present invention proposes a software backdoor detection method based on a normalized syntax tree, which performs detection by analyzing the similarity between software and malicious code.

[0041] Software component analysis technology is an analysis method that obtains the internal bill of materials by analyzing the composition of software. It is often used in independent research and development rate calculation and homology vulnerability detection. It involves key technologies such as software feature extraction, code clone detection and large-scale data processing. The detection method proposed in the present invention is optimized on the basis of traditional software component analysis, using a normalized syntax tree model to extract software code features, and searching in the malicious code library to calculate the similarity between the tested software code and the malicious code, and realize the function of software backdoor detection. The method can handle various forms of code variants such as adding and removing blank characters, modifying comments, replacing variable names, replacing constant characters, swapping conditional branches and adjusting word order at three levels: files, functions, and code blocks. It can effectively improve the detection accuracy on the basis of traditional detection methods and support software backdoor detection tasks in various scenarios.

[0042] refer to Figure 1 , the technical solution of the present invention comprises the following steps:

[0043] Step 1: Collect projects related to software backdoors in the open source community and use them as the initial data set after screening;

[0044] Step 2: Mark the code snippets related to the backdoor in the initial data set, obtain the corresponding code files, and build a malicious code library;

[0045] Step 3: Generate the corresponding syntax tree through lexical and grammatical analysis of the code in the malicious code library;

[0046] Step 4: Normalize the syntax tree and generate a standardized syntax tree through node filtering, name replacement, branch swapping, and instruction sorting operations;

[0047] Step 5: Get the code corresponding to the root node of the normalized syntax tree and generate the corresponding hash feature code;

[0048] Step 6: Store the signature code in the database and create an index to generate a malicious code signature library;

[0049] Step 7: For the tested code, generate a hash signature using the same method as steps 3 to 5;

[0050] Step 8: Use the generated hash signature to search and query the malicious code signature database;

[0051] Step 9: When matching backdoor features are retrieved, determine that there is a suspected software backdoor and give the specific code location.

[0052] In the first step, we collected software backdoor related projects from open source communities such as GitHub and Gitee, screened the projects with keywords including {backdoor, shell, malicious}, and then confirmed them through manual inspection, removed the detection tool category and other irrelevant projects, and used the remaining projects as the initial data set;

[0053] In the second step, for the initial data set, by analyzing the project's problem records, code comments, and submission history, combined with manual labeling, we screen out code snippets related to the backdoor, obtain the corresponding code files, and form a malicious code library;

[0054] In the third step, for the code in the malicious code library, the Antlr4 tool is used to generate a parser for the corresponding language. The code is segmented through lexical analysis, and the code text is segmented into the smallest lexical units, such as variables, symbols, constants, etc. Through syntax analysis, according to the syntax specifications of a specific programming language, a corresponding tree data structure is established. The root node represents the compilation unit, and the program is disassembled layer by layer from the root node downwards. The leaf nodes represent the basic lexical units. Through the Antlr4 tool and the rules of lexical and grammatical conventions, the analysis of multiple programming languages ​​is completed and a syntax tree is generated.

[0055] When the syntax tree is normalized in the fourth step, in order to cope with various forms of code variants, the following processing is performed in sequence;

[0056] In the syntax tree, comments are represented by separate leaf nodes. Leaf nodes related to comments are pruned from the syntax tree, leaving only code-related content, thus avoiding the impact of comments.

[0057] In the syntax tree, variable names, function names, etc. are represented by separate leaf nodes. In this step, the leaf nodes representing variable names are uniformly replaced with variable, function names are uniformly replaced with method, constants are uniformly replaced with const, and type names are uniformly replaced with type. Through the above replacement, the corresponding syntax trees of codes with different names but the same structure will be converted into completely consistent forms, thus avoiding the impact of personalized naming;

[0058] Check all judgment condition nodes. The expressions in these judgment condition nodes are used to represent the judgment conditions of the branch statement. If the condition is true, the program will continue to execute the left branch. If the condition is false, the program will continue to execute the right branch. In order to handle the program variants caused by replacing the left and right branches, the judgment conditions in the branch nodes are uniformly processed. If there is "!condition", it is changed to "condition", that is, the leading "not" operator is removed, and the left and right branches of the condition node are swapped to keep the semantics unchanged;

[0059] In the syntax tree, starting from the root node, recursively processing all program statements downward, you can get the node corresponding to the complete program instruction, which is represented as a statement node here. The statement nodes with the same parent node are sorted according to the dictionary order of the corresponding code string, and the order of each child node is adjusted according to the sorting result, from the root node to the leaf node layer by layer; in the syntax tree, the parent node is the splicing of the child nodes, and the deletion, modification and sorting of the child nodes will be synchronized to the parent node, and finally affect the content of the root node;

[0060] After the above processing, the normalized form of the syntax tree, that is, the normalized syntax tree, is obtained.

[0061] The normalized syntax tree as a whole represents a complete compilation unit file. In the fifth step, for the child nodes in the normalized syntax tree, the subtrees corresponding to the function and the code block are found according to the node level and type, so as to obtain the code corresponding to the root node after normalization processing at the file, function, and code block levels, respectively. For the code corresponding to these root nodes, the blank characters and line breaks are removed, and the MD5 value of the code is generated as the hash feature code;

[0062] In the sixth step, the file features, function features, and code block features stored in the database are respectively formed into three corresponding data tables, and indexes of the corresponding features are established, thereby forming a malicious code feature library;

[0063] In the seventh step, for the tested code, the same method from step three to step five is used to generate hash signatures at the file, function, and code block levels;

[0064] In the ninth step, for the retrieved matching feature codes, the results at the file level, function level or code block level are given according to the matching level as suspected software backdoors. Example 1

[0065] This embodiment is used to illustrate the process of normalizing a syntax tree. Here, the processing process at the function level is taken as an example. The processing methods at the file level and the code block level are similar.

[0066] Figure 2It is a Java function that includes a software backdoor. Its execution logic is to receive parameters transmitted remotely and then call system commands for execution. The execution condition is to input a signal value that meets the conditions, that is, the start function returns true.

[0067] First, construct the syntax tree model of this code, and after lexical and grammatical analysis, generate Figure 3 structure. Due to the complexity of the model structure, not all leaf nodes are expanded. The solid lines in the figure indicate that the relevant child nodes are expanded, and the dotted lines indicate that the nodes are folded. The elliptical nodes in the figure represent program structures, namely files, functions, code blocks, statements and other program structures; the rectangular nodes represent leaf nodes, namely the basic elements after the program is disassembled, such as variables, symbols, constants, etc. The goal of normalizing the syntax tree is to prune and sort the leaf nodes, namely the basic program elements, while retaining the program features and being compatible with multiple program variants. Changes in leaf nodes will be fed back to their parent nodes and finally to the root node.

[0068] In the syntax tree structure, the child node is the decomposition of the parent node. The content of the parent node can be obtained by splicing the content of the child nodes. During the normalization process, the order of the child nodes and the content of the leaf nodes will be modified, and the impact will be reflected in the parent node and even the entire syntax tree.

[0069] For the above syntax tree structure, normalization is performed and the conversion is performed through the following steps:

[0070] Prune comment-related nodes in the syntax tree, that is, all branches corresponding to comment nodes;

[0071] Replace variable names in leaf nodes such as sig, request, s, etc. with variable; replace function names such as getParameter, start, etc. with method; replace constants such as "sig" with constant; replace types such as String and int with type;

[0072] Here we take the child node of body as an example, which has 4 statements and the corresponding original program is:

[0073] 1 declare statement ->String sig = request.getParameter("sig");

[0074] 2 declare statement ->int s = Integer.parseInt(sig);

[0075] 3 declare statement ->String cmd = request.getParameter("cmd");

[0076] 4 if statement ->if (!start(s)) {…} else {…}

[0077] After replacing the leaf nodes, the program statements corresponding to each statement are updated as follows:

[0078] 1 declare statement ->type variable = variable.method(const);

[0079] 2 declare statement ->type variable = Integer.method(variable);

[0080] 3 declare statement ->type varible = varible.method(const);

[0081] 4 if statement ->if (!method(varible)) {…} else {…}

[0082] Check all conditional judgment nodes. Figure 2 In the if branch, if the judgment condition is !start(s), remove the "!" node and replace the child nodes of "then" and "else". After the replacement, the child node of then becomes [declare,while, ...], and the child node of else becomes [declare];

[0083] In the syntax tree, starting from the root node, all its statement child nodes are sorted in the dictionary order of the corresponding code string. Statement corresponds to a single program statement in the original code. For example, if the child nodes of the body node contain 4 statements, the order after sorting is:

[0084] 4 if statement ->if (!method(varible)) {…} else {…}

[0085] 2 declare statement ->type variable = Integer.method(variable);

[0086] 1 declare statement ->type variable = variable.method(const);

[0087] 3 declare statement ->type varible = varible.method(const);

[0088] After the above steps, a standardized syntax tree is obtained, such as Figure 4 shown. Example 2

[0089] This embodiment is used to explain the process of using a normalized syntax tree to generate a feature code and detect a software backdoor.

[0090] For the standardized syntax tree in Example 1, the leaf nodes are spliced ​​from bottom to top to obtain the standardized code text corresponding to the root node, such as Figure 5 shown.

[0091] It can be seen that the structure of the original code is retained in this code, but some details in the code are hidden through pruning, and the order of program statements is changed through replacement. Finally, remove the blank characters and line breaks in the above code to obtain a new code string, and calculate the MD5 value of the code string as the feature code: 31CED15E13A34C77FF539188A86C0573. The feature code will be stored in the database and the corresponding index will be established.

[0092] for Figure 6 The code variant uses the same method to generate a normalized syntax tree and a feature code. Because the addition and subtraction of blank characters, modification of comments, replacement of variable names, replacement of constant characters, adjustment of conditional branches and word order changes in this code segment relative to the code in Example 1 can all be eliminated by the normalized syntax tree, the feature code finally calculated is still 31CED15E13A34C77FF539188A86C0573. Using this feature value to search in the feature library, it can match the malicious code feature, and it can be determined that there is a possible backdoor code.

[0093] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A software backdoor detection method based on a normalized syntax tree, characterized in that: The following steps are involved: Step 1: Collect projects related to software backdoors in the open source community and use them as the initial data set after screening; Step 2: Mark the code snippets related to the backdoor in the initial data set, obtain the corresponding code files, and build a malicious code library; Step 3: Generate the corresponding syntax tree through lexical and grammatical analysis of the code in the malicious code library; Step 4: Normalize the syntax tree and generate a standardized syntax tree through node filtering, name replacement, branch swapping and instruction sorting operations; Step 5: Get the code corresponding to the root node of the normalized syntax tree and generate the corresponding hash feature code; Step 6: Store the signature code in the database and create an index to generate a malicious code signature library; Step 7: For the tested code, generate a hash signature using the same method as steps 3 to 5; Step 8: Use the generated hash signature to search and query the malicious code signature database; Step 9: When matching backdoor features are retrieved, determine the existence of a suspected software backdoor and give the specific code location; In the first step, we collected software backdoor related projects from the open source community, screened the projects with the keywords {backdoor, shell, malicious}, and then confirmed them through manual inspection, removed the detection tool and other irrelevant projects, and used the remaining projects as the initial data set; When normalizing the syntax tree in the fourth step, the following processes are performed in sequence: (1) In the syntax tree, comments are represented by separate leaf nodes. Leaf nodes related to comments are pruned from the syntax tree, leaving only code-related content. (2) In the syntax tree, variable names and function names are represented by separate leaf nodes. In this step, the leaf nodes representing variable names are uniformly replaced with variable, function names are uniformly replaced with method, constants are uniformly replaced with const, and type names are uniformly replaced with type. (3) Check all judgment condition nodes. The expressions in these judgment condition nodes are used to represent the judgment condition of the branch statement. If the condition is true, the program will continue to execute the left branch. If the condition is false, the program will continue to execute the right branch. The judgment conditions in the branch nodes are processed uniformly, the leading "not" operator is removed, and the left and right branches of the condition nodes are swapped to keep the semantics unchanged; (4) In the syntax tree, starting from the root node, all program statements are processed recursively downward, and nodes with complete program instructions are represented as statement nodes. Statement nodes with the same parent node are sorted according to the dictionary order of the corresponding code string, and the order of each child node is adjusted according to the sorting result, from the root node to the leaf node layer by layer; in the syntax tree, the parent node is the splicing of the child nodes, and the deletion, modification and sorting operations of the child nodes will be synchronized to the parent node, and ultimately affect the content of the root node; After processing, the normalized form of the syntax tree is obtained, namely the normalized syntax tree.

2. The method according to claim 1, characterized in that In the second step, for the initial data set, by analyzing the project's problem records, code comments, and submission history, combined with manual labeling, we screen out code snippets related to the backdoor, obtain the corresponding code files, and form a malicious code library.

3. The method according to claim 1, characterized in that In the third step, for the code in the malicious code library, use the Antlr4 tool to generate a parser for the corresponding language, segment the code through lexical analysis, and divide the code text into the smallest lexical units; through syntax analysis, according to the syntax specifications of a specific programming language, establish a corresponding tree data structure, the root node represents the compilation unit, and the program is disassembled layer by layer from the root node downwards, and the leaf nodes represent the basic lexical units; through the Antlr4 tool and the rules of lexical and grammatical conventions, complete the analysis of multiple programming languages ​​and generate a syntax tree.

4. The method according to claim 1, characterized in that The normalized syntax tree as a whole represents a complete compilation unit file. In the fifth step, for the child nodes in the normalized syntax tree, the subtrees corresponding to the functions and code blocks are found according to the node level and type, so as to obtain the codes corresponding to the root nodes after normalization at the file, function and code block levels respectively. For the codes corresponding to these root nodes, the blank characters and line breaks are removed, and the MD5 value of the code is generated as the hash signature code.

5. The method according to claim 4, characterized in that In the sixth step, the file features, function features, and code block features stored in the database are respectively formed into three corresponding data tables, and indexes of the corresponding features are established to form a malicious code feature library.

6. The method according to claim 5, characterized in that In the seventh step, for the code under test, the same method as steps three to five is used to generate hash signatures at the file, function, and code block levels.

7. The method according to claim 6, characterized in that In the ninth step, for the retrieved matching feature codes, the results at the file level, function level or code block level are given according to the matching level as suspected software backdoors.

8. The method according to any one of claims 1 to 7, characterized in that This method is applied in the field of software component analysis technology.

9. A system for implementing the method according to any one of claims 1 to 8.