A C / C++ patch existence detection method based on patch summary comparison
Through a method based on patch summary comparison, control flow anchor nodes and path summaries are used to detect the patch existence status of C/C++ binary programs, solving the problem of inaccurate detection in the existing technology and achieving accurate patches for closed source programs. Presence detection.
Patent Information
- Application Number
- CN202010666867.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-13
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2040-07-13
AI Technical Summary
Existing C/C++ binary program patch detection methods are difficult to reliably detect patch existence status when faced with customized modifications and compilation environment changes, resulting in inaccurate detection results.
Using a method based on patch summary comparison, by calculating the semantic similarity between the target binary file and the reference binary file before/after the patch, using control flow anchor nodes, path summary and patch summary, fine-grained semantic information comparison is performed to Determine the existence status of the patch.
This method can resist customized modifications and compilation environment changes, provide more accurate and reliable patch existence detection results, and is suitable for closed-source C/C++ binary programs.
Smart Images

Figure CN111967013B
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of binary vulnerability analysis, and specifically is a C / C++ patch existence detection method based on patch summary comparison. Background Art
[0002] With the popularity of open source software, a large number of open source C / C++ projects are widely used in closed source software. For example, various equipment manufacturers borrow from open source kernels and customize private kernels, and various commercial software often reference third-party library codes and make some appropriate modifications. While open source code brings convenience, vulnerabilities in open source software are also spread to various closed source software. Open source software can release security patches in a timely manner, but closed source developers often cannot apply the latest security patches in a timely manner or even completely ignore the latest security patches. In this case, patch existence detection for closed source C / C++ binary programs can help security analysts evaluate the security of binary files.
[0003] The existing detection methods that can determine the status of patches are mainly divided into two categories: the first is attack sample testing, which first constructs or collects PoC (Proof of Concept) of a specific vulnerability, then inputs it into the target binary program for dynamic execution, and observes whether the target program can trigger the corresponding vulnerability. The second method uses the feature signature of the patch for matching. This method first extracts the precise signature of the patch code fragment in the binary program, and then searches whether the binary file to be tested contains the corresponding binary signature.
[0004] However, closed-source binaries often make some customized modifications to open-source code, and may use a variety of different compilation options to build binaries, which brings great challenges to the above two methods. First, existing PoCs are often only for certain specific versions of binaries. When it is necessary to dynamically test another customized binary or another version of the program, the existing PoCs often cannot cause the program to trigger the corresponding vulnerability, but this does not mean that the vulnerability has been fixed. On the other hand, customized modifications or different compilation configurations often change the characteristic signatures of the code around the patch, resulting in the inability to reliably detect the existence of the patch by using the patch signature to accurately match whether the same signature exists in the customized binary program.
[0005] Based on the above analysis, it is very necessary to invent a more robust and reliable patch existence detection technology for C / C++ binary programs. Summary of the invention
[0006] In order to overcome the above-mentioned deficiencies of the prior art, the present invention provides a method for detecting the existence of C / C++ binary patches based on patch summary comparison. The present invention uses semantic summary information on patch-related paths to perform patch existence detection, which has strong robustness.
[0007] The core idea of the present invention is to determine the patch status based on semantic similarity. The present invention calculates the similarity between the target binary program and the reference binary file before / after the patch, and considers that the patch status of the target binary program is more similar to the reference binary file that is closer to it. This comparison method is highly resistant to customized modifications in the target binary program, because such modifications will affect the reference binary file version before / after the patch to the same extent. Secondly, the present invention uses the fine-grained semantic information of the patch-related area to perform similarity comparison. Even if the code near the patch undergoes customized changes, these semantic information will still be retained to a large extent. Finally, the present invention carefully selects the areas affected by the patch in the target binary file to ensure that the coverage of the patch-related code is maximized while minimizing the irrelevant code, thereby reducing the detection noise. In order to better introduce the work of the present invention, this section first introduces the definitions of these data structures in the patch summary, including the control flow anchor node, path summary, and patch summary:
[0008] The control flow anchor node is a post-dominator node based on the patch basic block, which can control the relevant path of the patch context.
[0009] The path summary represents the semantic information on the relevant paths of the patch context. It consists of three elements: a path constraint set, a memory state set, and a function call sequence. These elements can robustly represent the contextual semantics of the patch and do not change with code customization or changes in the compilation environment.
[0010] The patch summary is a set of patch-related path summaries controlled by an anchor node, which can represent the semantic information of all patch basic blocks in the patch file. The present invention compares the patch summary of the target binary file with the patch summary of the reference binary file before / after the patch to detect the existence of the patch.
[0011] The technical solution of the present invention is as follows:
[0012] The present invention provides a C / C++ patch existence detection method based on patch summary comparison, and the specific steps are as follows:
[0013] 1) determining anchor nodes in the control flow graph of patch-related functions in the target C / C+ binary file, thereby determining potential patch-related paths in the target binary file;
[0014] 2) Using the anchor node to extract the patch-related path summary information in the target binary file, and compare it with the patch-related path summary information of the reference binary file before / after the patch to calculate the similarity of a single patch path;
[0015] 3) Based on the comparison results of the path summaries controlled by all anchor nodes, the existence status of the patch file is comprehensively judged.
[0016] Compared with the prior art, the present invention has the following beneficial effects:
[0017] The C / C++ binary patch existence detection method based on patch summary comparison designed by the present invention can determine the existence status of the patch through semantic comparison, and this comparison integrates the path summary comparison results of all patch lines in the patch file, so as to achieve fine-grained detection of the patch. Since this comparison is implemented according to the context semantics of the patch, it can resist customized modifications of the target binary file and changes in the compilation environment, thereby providing accurate patch existence detection results for security analysts. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 This is the architecture diagram of the patch detection system based on patch summary comparison.
[0019] Figure 2 Figure 2 shows an example of locating anchor nodes using the same function call.
[0020] Figure 3 An example graph of a target binary path summary.
[0021] Figure 4 It is a comparison graph of the path summary set of a single anchor node. DETAILED DESCRIPTION
[0022] The technical solution of the present invention is described in detail below in conjunction with the accompanying drawings and embodiments.
[0023] The C / C++ patch existence detection method based on patch summary comparison designed by the present invention has an overall architecture diagram as shown in the figure: Figure 1 As shown. It includes: anchor node positioning module, path summary comparison module and patch summary comparison module. The execution process of the present invention is as follows:
[0024] 1) The anchor node location module is used to determine the anchor nodes in the control flow graph of the patch-related functions of the target binary file, thereby determining the potential patch-related paths in the target binary file.
[0025] 2) The path summary comparison module uses a suitable algorithm to compare the similarity between the path summary of the target binary file and the path summary of the reference binary file before / after the patch.
[0026] 3) The patch summary comparison module calculates the similarity between the path summary set dominated by all anchor nodes in the target binary file and the path summary set of the reference binary file before / after the patch, so as to judge the existence of the patch as a whole.
[0027] The following is a further description of each module:
[0028] 1. Anchor node positioning
[0029] The anchor node positioning module is used to determine the most matching anchor node in the target C / C++ binary file without debugging information. The role of the anchor node is to truncate the redundant path after the patch basic block that may exist in the target C / C++ binary file, so as to retain the complete contextual semantics of the patch while discarding the semantic information unrelated to the patch. It is first determined in the reference binary before / after the patch, and each patch basic block corresponds to an anchor node. Through this anchor node, the patch-related path is also determined, that is, the path set between the function entry where the patch is located and the anchor node.
[0030] In order to compare the path summary of the target binary file with the path summary of the reference binary file before / after the patch, it is necessary to first determine the position of the anchor node in the target binary file so as to generate the patch-related path in the target binary file.
[0031] Locating anchor nodes in the target binary file: Since the patch basic blocks in the target binary are unknown, their anchor nodes need to be obtained approximately. Anchor nodes are essentially basic blocks in the control flow graph. The present invention selects basic blocks similar to the anchor nodes of the reference binary before / after the patch in the control flow graph of the target binary as anchor nodes in the target binary. The positioning principles are as follows:
[0032] 1) The termination types of basic blocks are the same, that is, the instructions such as signed / unsigned conditional jumps, unconditional jumps, function calls, and returns are the same. Because these termination instruction types are determined by semantic information, they are independent of the compilation environment and customization.
[0033] 2) The number of global memory accesses in the basic block is the same. Similarly, the semantic information represented by global memory accesses will not change due to customization and compilation environment.
[0034] Through the above two matching principles, for most anchor nodes, the present invention can find a unique correspondence in the target binary file. If there are multiple candidate nodes, the present invention selects the node with the greatest similarity in the calculation of the path summary comparison module. When no suitable anchor node is found, the present invention directly selects the exit of the function where the patch is located as the anchor node of the target binary file.
[0035] Figure 2 As shown, the node marked in yellow is an anchor node in the reference binary before / after the patch. This anchor node determines the relevant path before / after the patch. This anchor node calls a function funcA(), so in the control flow graph of the target binary, through the same funcA function name, the present invention determines a matching anchor node.
[0036] 2. Path summary comparison
[0037] After the anchor node set of the target binary is determined, the present invention can obtain the patch-related path in the target binary. This module compares the summary information of the patch-related path of the target binary with the summary information of the patch-related path of the reference binary before / after the patch, respectively, to determine which reference file the current path is closer to. In order to compare the path summaries, this module first extracts the summary information of the patch-related path in the target binary, and then uses a suitable comparison algorithm to calculate the similarity.
[0038] (1) Extract the summary of the patch path in the target binary
[0039] In order to extract the semantic information of a specific path, the present invention uses symbolic execution technology to approximately simulate program execution and collect relevant semantic information during the execution process. The present invention uses some functions of the symbolic execution tool to record some semantic information in the execution path, which includes: path constraint set, memory state set and function call sequence.
[0040] The present invention directly uses the symbolic values of this information in the symbolic execution engine to represent the final path summary. Figure 3 It shows the summary information of a path in a target binary. The path constraint set is a set of abstract syntax trees consisting of all branch judgment conditions of the execution path. The memory state set is a set of operations for accessing global variables in the execution path. Each element in the set is a key-value pair representing the address and value of the global variable. The function call sequence is the sequence of function names called in the path, and this sequence is sorted according to the order of function calls.
[0041] (2) Comparison algorithm
[0042] The summary information contained in two similar patch-related paths is also similar, and the different parts are caused by the patches. Based on this premise, the present invention calculates the similarity between the path summary of the target binary file and the summary information of the patch-related path of the reference binary before / after the patch, and measures the similarity of the two paths according to the similarity calculation result.
[0043] Similarity of path summaries. As mentioned above, a path summary consists of three elements, including a set of path constraints, a set of memory states, and a function call sequence. The present invention uses the average similarity of these elements as the overall similarity of the path summary. The similarity calculation methods for each element are as follows:
[0044] 1) Similarity of path constraint sets. A path constraint set is a set of abstract syntax tree sets. Therefore, the present invention measures the similarity between two sets of constraints based on set similarity. Specifically, given two sets S = {s1, s2,..., s n}, S′ = {s′1, s′2,..., s′ m}, the similarity between them is defined as:
[0045]
[0046] where m ij represents the mapping relationship between s i and s′ j , and sim(s i , s′ j ) represents the similarity between two elements. The present invention needs to find {m 11 , m 12 ,..., m nm} to complete a one-to-one mapping between the two sets. Assume n < m, and n elements in S′ are uniquely mapped to elements in S. Therefore, if s i is mapped to s′ j , then m ij is recorded as 1, otherwise 0. To determine {m 11 , m 12 ,..., m nm}, the present invention uses the Kuhn-Munkres algorithm to find the mapping relationship that maximizes equation (1). When calculating the similarity of set elements, since the path constraint is an AST tree, the present invention calculates the similarity between two set elements through the edit distance of the tree.
[0047] 2) Similarity of memory state sets. The similarity between memory state sets is also calculated by the set similarity mentioned above to find the maximum similarity. The elements in the memory state set are key-value pairs representing memory. Therefore, when calculating the similarity of set elements, the present invention directly uses the product of the key similarity and the value similarity to represent the similarity of the key-value pairs.
[0048] 3) Similarity of function call sequences. Different from the previous two path summaries, which both use set similarity to measure the maximum similarity of the summaries, the function call sequence is generated according to the order of function calls in the path, that is, the function call sequence is an ordered list. In order to calculate the similarity of two ordered sequences, the present invention uses the edit distance of the list to calculate the similarity of the two function call sequences. Given two function call sequences L and L′, the similarity calculation formula is as follows:
[0049]
[0050] The similarity between path summaries is represented by the average similarity of three elements. Let S, M, and L be the path constraint set, memory state set, and function call sequence in a path summary in the target binary file, respectively, and S', M', and L' are the path summary related elements before or after the patch. Then the similarity between the two path summaries is calculated as follows:
[0051]
[0052] 3. Patch summary comparison
[0053] The patch summary is the path summary set corresponding to all control flow anchor node sets of the patch file. The comparison between the path summary sets determined by a single anchor node can only determine the existence of a single patch basic block, while the overall patch existence status requires the integration of all path summary comparison results.
[0054] like Figure 4 As shown, assuming that the current control flow anchor node is an, it simultaneously determines a set of patch-related paths in the target binary file and the reference binary patch-related paths before / after the patch. Accordingly, the present invention can calculate a set of patch-related path digest sets (PathDigests) in the target binary file. Through the aforementioned set similarity calculation formula and path summary similarity calculation method, the present invention can calculate the similarity sim(an,pre) between this path summary set and the patch-related path summary set before the patch, and the similarity sim(an,post) between this path summary set and the patch-related path summary set after the patch. Then, by comparing the similarities of the two path summary sets, the present invention can determine the reference binary version that is closer to the target binary file. The final patch summary similarity superimposes the path summary set similarity comparison results of all anchor nodes, and gives the final patch existence judgment, and its calculation formula is as follows:
[0055]
[0056]
[0057]
[0058] Wherein anchor represents the set of all anchor nodes, and an is one of the anchor nodes. For an anchor node an, if the similarity between the path summary set of the target binary and the source path summary set after the patch is greater than the similarity between the path summary set of the target binary and the source path summary set before the patch, that is, sim(an,post)>sim(an,pre), then it means that the patch path summary set of the target binary file determined by an is closer to the path summary set after the patch, and the present invention sets the comparison result to 1, otherwise it is set to 0 or -1. It can be seen from the above formula that if the summary information of the patch-related paths determined by more than half of the anchor nodes is closer to the summary information of the patch path of the reference binary after the patch, the present invention considers that the target binary has applied the specified patch file.
[0059] Example 1
[0060] This embodiment designs an anchor node positioning module, which uses the semantic information of the control flow basic block to match the basic blocks with the same semantics in the control flow graph of the target binary, thereby determining the patch-related paths in the target binary file. This embodiment also designs a path summary comparison module, which first collects the semantic summary information in the patch-related paths in the target binary file through symbolic execution technology, and then uses an appropriate matching algorithm to calculate the similarity of the two path summaries. The specific implementation of these two modules is introduced below.
[0061] 1. Anchor node positioning module
[0062] The input of the anchor node positioning module is the anchor node set of the target binary file and the reference binary patch file before / after the patch. The anchor node positioning module matches the anchor nodes of the reference binary patch file with the same semantic information in the target binary file.
[0063] In order to locate the anchor node, the present invention first parses the SYMTAB or KALLSYMS segment of the target binary file. These structures are section segments in the executable file, which are responsible for recording all symbol information such as variables and function names in the executable file. The present invention can find the address of the function where the patch is located in the binary file through these symbol information. Then, the present invention parses the target binary file through the angr tool, and generates a control flow graph of the function where the patch is located according to the symbol information.
[0064] The specific anchor node positioning process is as follows:
[0065] 1) The algorithm selects a single reference anchor node from the anchor node set of the reference binary patch file before / after the patch;
[0066] 2) For a specific reference anchor node, the algorithm uses the angr tool to traverse all basic blocks of the control flow graph of the function where the target binary file patch is located. If the basic block and the reference anchor node have the same termination type instructions (such as signed / unsigned conditional jumps, unconditional jumps, function calls and returns, and other semantically related instructions), and the basic block and the reference anchor node have the same number of global memory accesses, then the present invention considers this basic block to be a patch anchor node of the target binary file.
[0067] 3) Return to 1) until all anchor nodes are located.
[0068] 2. Path Summary Comparison Module
[0069] The path summary comparison module first determines the patch-related paths of the target binary file through the anchor node, and then uses the symbolic execution tool angr to simulate the execution of these paths to collect the semantic information in the patch-related paths. This semantic information is the path summary of the target binary patch. In order to determine the similarity between the binary program and the reference binary file before / after the patch, this module compares the path summary of the target binary patch with the path summary of the reference binary file before / after the patch. The following is a detailed introduction to the generation and comparison algorithm of the patch path summary of the target binary file:
[0070] (1) Summary of patch paths for target binaries
[0071] The present invention uses an open source symbolic execution tool angr to simulate and execute the patch-related paths of the target binary file. Since the execution entry of the present invention is not the program entry in the traditional sense but the entry of the patch-related function, the present invention makes customized modifications to angr so as to initialize the relevant variables inside the specific program. First, angr needs to symbolize the parameters of the function where the patch is located and initialize them to uniquely identified symbolic values (such as arg0); then, for the uninitialized memory and the memory pointed to by the symbolic address, angr assigns a unique symbolic value to it, and for the local memory, angr initializes it to 0 value; finally, since the present invention does not simulate the execution of inter-function calls, angr assigns a unique symbolic value to the return value of these functions. Through these initializations, angr can smoothly collect all path summary information on the path between the function entry and the anchor node of the target binary file. The path summary includes: a path constraint set, a memory state set, and a function call sequence.
[0072] (2) Path summary comparison
[0073] The path summary comparison algorithm calculates the similarity between the patch path summary of the target binary and the patch path summaries before and after the patch, which can be decomposed into the similarity calculations of three elements: the path constraint set, the memory state set, and the function call sequence.
[0074] 1) Similarity of path constraint sets
[0075] As can be seen from the invention content, the path constraint similarity can be transformed into the calculation of set similarity. For the patch path constraint set S of the target binary and the binary patch constraint set S' before (or after) the patch, the maximum similarity between these two sets can be calculated using the Kuhn-Munkres algorithm. However, since the set elements are branch judgment ASTs representing path constraints, the present invention needs to define the similarity metric between ASTs. For this purpose, the present invention uses the existing calculation method of tree edit distance. Specifically, the present invention uses the bipartite graph matching algorithm to calculate the tree edit distance. The present invention finds that although the formats of some AST expressions are different (such as a>b and b<a), their essence is interchangeable. To avoid incorrect matching, the present invention will flip such expressions during the matching process to maintain a unified format.
[0076] 2) Similarity of memory state sets
[0077] Similarly, the memory state set also uses the Kuhn-Munkres algorithm to calculate its maximum similarity. Since the elements of the memory state set are key-value pairs representing memory, for a single element, the present invention uses the product of the key similarity and the value similarity to represent the element similarity.
[0078] 3) Similarity of function call sequences
[0079] For the call sequence L of the patch-related path of the target binary and the call sequence L' of the patch-related path of the binary patch before (or after) the patch, they are both ordered sequences. Therefore, the present invention directly calculates the similarity between the two lists using the list edit distance LED algorithm.
[0080] The present invention implements the detection of the existence of patches by comparing the semantic information on the patch-related paths of the target C / C++ code with the semantic information on the patch-related paths before and after the patch. These semantic summaries can resist the influence of different compilation environments and customized modifications, providing an accurate and reliable detection method for the detection of a large number of closed-source C / C++ binary patches.
Claims
1. A C / C++ patch existence detection method based on patch summary comparison, characterized in that: The specific steps are as follows: 1) determining anchor nodes in the control flow graph of patch-related functions in the target C / C+ binary file, thereby determining potential patch-related paths in the target binary file; 2) Using the anchor node to extract the patch-related path summary information in the target binary file, and compare it with the patch-related path summary information of the reference binary file before / after the patch to calculate the similarity of a single patch path; 3) Based on the comparison results of the path summaries controlled by all anchor nodes, comprehensively judge the existence status of the patch file; Wherein: in step 2), the similarity between the path summary information is represented by the average similarity of the three elements; Let S, M, L be the path constraint set, memory state set and function call sequence in a path summary in the target binary file, respectively, and S', M', L' be the path summary related elements before or after the patch. Then the similarity sim between the two path summaries is calculated as follows: Among them: sim(S,S′), sim(M,M′) and sim(L,L′) represent the similarity of the path constraint set, memory state set and function call sequence respectively.
2. The C / C++ patch existence detection method according to claim 1, characterized in that: In step 1), basic blocks similar to the anchor nodes of the reference binary before / after the patch are selected as anchor nodes in the target binary; The positioning principles are as follows: ① The termination type of the basic blocks is the same, that is, the signed / unsigned conditional jump, unconditional jump, function call and return instructions are the same; ②The number of global memory accesses in the basic block is the same; Based on the above positioning principles, if a unique correspondence is found in the target binary file, it is the anchor node; If multiple candidate nodes are found in the target binary file, the node with the greatest similarity is selected as the anchor node in step 2); If no suitable anchor node is found, the exit of the function where the patch is located is directly selected as the anchor node of the target binary file.
3. The C / C++ patch existence detection method according to claim 1, characterized in that: In step 2), symbolic execution technology is used to approximately simulate program execution, and during the execution process, symbolic execution tools are used to collect semantic information including path constraint sets, memory state sets, and function call sequences. Finally, the symbolic values of these semantic information in the symbolic execution engine are used to represent the path summary.
4. The C / C++ patch existence detection method according to claim 1, characterized in that: In step 2), given two path constraint sets, S = {s1, s2, ..., s n }, S′={s′1,s′2,...,s′ m }, the similarity of the path constraint set sim(S,S ′ ) is defined as: Among them, m ij Represents s i and s′ j The mapping relationship between sim(s i ,s′ j ) represents the similarity between two elements; m ij Obtained by Kuhn-Munkres algorithm; sim(s i ,s′ j ) is calculated by the edit distance of the tree.
5. The C / C++ patch existence detection method according to claim 1, characterized in that: In step 2), the similarity sim(M,M′) of the memory state set is calculated based on the set similarity. An element in the memory state set is a key-value pair representing the memory. When calculating the similarity of elements in the set, the product of the key similarity and the value similarity is used to represent the similarity of the key-value pair.
6. The C / C++ patch existence detection method according to claim 1, characterized in that: In step 2), the function call sequence is generated according to the order of function calls in the path, that is, the function call sequence is an ordered list, so the edit distance of the list is used to calculate the similarity sim(L,L′) between two function call sequences.
7. The C / C++ patch existence detection method according to claim 1, characterized in that: In step 3), assuming that the current control flow anchor node is an, calculate the similarity sim(an,pre) between a set of path summaries in the target binary file and the set of patch-related path summaries before the patch, and the similarity sim(an,post) between the set of path summaries and the set of patch-related path summaries after the patch. Then, by comparing the similarities of the two path summaries, determine the reference binary version that the target binary file is closer to. Finally, the similarity of the patch summaries is superimposed on the similarity comparison results of the path summaries of all anchor nodes, and the final patch existence judgment final result is given. The calculation formula is as follows: Here, anchor represents the set of all anchor nodes, and an is one of the anchor nodes.
