Binary file similarity analysis method, system and equipment and storage medium
By combining the binary function embedding model, similar function nearest neighbor search and maximum weight matching algorithm, the problem of low accuracy of binary file similarity analysis tools in the existing technology in complex scenarios is solved, and accurate and accurate analysis of binary file similarity is achieved. Efficient analysis.
Patent Information
- Application Number
- CN202410700555.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-05-31
AI Technical Summary
Existing binary file similarity analysis tools have low accuracy in complex scenarios and cannot meet the binary file similarity analysis requirements in complex scenarios across architectures, cross-compilers, and cross-optimization levels.
Binary function embedding model, similar function nearest neighbor search and maximum weight matching algorithm are used to determine similar function pairs through binary file reverse engineering, feature extraction, function embedding and nearest neighbor search, and the best matching solution is performed through the maximum weight matching algorithm to achieve binary file Accurate and efficient similarity analysis.
It achieves accurate and efficient analysis of binary file similarities in complex scenarios. It can effectively identify the similarity of binary files under cross-architecture, cross-compiler, and cross-optimization levels, improving the accuracy and efficiency of analysis.
Smart Images

Figure CN118568516A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer security technology, and in particular to a binary file similarity analysis method, system, device and storage medium. Background Art
[0002] Binary files are the primary form of binary code, containing program execution instructions and data. They are information carriers that computers can directly recognize and execute. In the modern software ecosystem, binary files play a vital role and directly impact the reliability and security of the entire system.
[0003] Binary file similarity analysis is particularly critical in the security field. By performing similarity analysis on binary files, we can effectively identify potential security threats and vulnerability propagation paths, so that appropriate security measures can be taken in a timely manner to ensure the normal operation of the system.
[0004] However, existing binary file similarity analysis tools (such as BinDiff and Diaphora) have certain limitations. These tools often only utilize simple code structure and byte features for analysis, and struggle to achieve good results in complex scenarios across architectures, compilers, and optimization levels. In practice, due to the diversity and complexity of software development environments, these tools often perform poorly and fail to meet the requirements of binary file similarity analysis. Summary of the Invention
[0005] This invention provides a binary file similarity analysis method, system, device, and storage medium to address the low accuracy of existing binary file similarity analysis tools in complex scenarios. By combining a binary function embedding model, similarity function nearest neighbor search, and a maximum weight matching algorithm, this method achieves accurate and efficient analysis of binary file similarity.
[0006] The present invention provides a binary file similarity analysis method, comprising: performing binary file reverse engineering on a binary main file and a binary comparison file to obtain binary function information of the main file and binary function information of the comparison file; performing feature extraction on the binary function information of the main file and the binary function information of the comparison file to obtain an initial feature vector of the main file and an initial feature vector of the comparison file; inputting the initial feature vector of the main file and the initial feature vector of the comparison file into a pre-trained binary function embedding model to obtain a function embedding feature vector of the main file and a function embedding feature vector of the comparison file output by the binary function embedding model; determining an alternative similar function pair based on a nearest neighbor search algorithm according to the function embedding feature vector of the main file and the function embedding feature vector of the comparison file; performing optimal matching solution on the alternative similar function pair based on a maximum weight matching algorithm, and using the obtained matched similar function pair as a binary file similarity analysis result.
[0007] According to a binary file similarity analysis method provided by the present invention, binary file reverse engineering is performed on a binary main file and a binary comparison file to obtain binary function information of the main file and binary function information of the comparison file, including: using a preset binary file reverse tool to perform binary file reverse engineering on the binary main file and the binary comparison file to obtain binary function information of the main file and binary function information of the comparison file with reverse attributes; the preset binary file reverse tool includes IDA Pro, Ghidra and Radare2; the reverse attributes include control flow graph, assembly code and constant data; the method also includes: persistently caching the binary function information of the main file and the binary function information of the comparison file in units of binary files.
[0008] According to a binary file similarity analysis method provided by the present invention, feature extraction is performed on the binary function information of the main file and the binary function information of the comparison file to obtain the initial feature vector of the main file and the initial feature vector of the comparison file, including: extracting numerical features representing the semantics of binary code from the binary function information of the main file and the binary function information of the comparison file based on expert experience to obtain the initial feature vector of the main file and the initial feature vector of the comparison file; the method also includes: persistently caching the initial feature vector of the main file and the initial feature vector of the comparison file in units of binary files.
[0009] According to a binary file similarity analysis method provided by the present invention, the initial feature vector of the main file and the initial feature vector of the comparison file are input into a pre-trained binary function embedding model to obtain the function embedding feature vector of the main file and the function embedding feature vector of the comparison file output by the binary function embedding model, including: training the binary function embedding model to be trained to obtain the trained binary function embedding model; the binary function embedding model is a gated graph neural network model; the gated graph neural network model includes a feature encoding multi-layer perceptron, a node state iteration module and a gated aggregation module; the initial feature vector of the main file and the initial feature vector of the comparison file are processed by the feature encoding multi-layer perceptron, the node state iteration module and the gated aggregation module inside the trained binary function embedding model Afterwards, the function embedding feature vector of the main file and the function embedding feature vector of the comparison file output by the binary function embedding model are obtained; the feature encoding multi-layer perceptron is used to perform node feature encoding on the initial feature vector to obtain the vector after node feature encoding; the node state iteration module is used to perform a preset round of node state iteration on the vector after node feature encoding to obtain the vector after node state iteration; during each round of node state iteration, the state vector of the current node is updated according to the state vector of the neighboring node; the gated aggregation module is used to perform node state aggregation on the vector after node state iteration, and the obtained node state aggregation vector is used as the function embedding feature vector; the method also includes: persistently caching the function embedding feature vector of the main file and the function embedding feature vector of the comparison file in units of binary files.
[0010] According to a binary file similarity analysis method provided by the present invention, the binary function embedding model to be trained is trained to obtain the trained binary function embedding model, including: constructing a training data set of binary functions; the training data set includes binary function sample pairs of instruction set architecture, compiler and compilation optimization level, and similarity labels of the sample pairs; based on the training data set, the binary function embedding model to be trained is trained to convergence by comparing the learning loss function to obtain the trained binary function embedding model.
[0011] According to a binary file similarity analysis method provided by the present invention, the method determines alternative similar function pairs based on the function embedding feature vector of the main file and the function embedding feature vector of the comparison file based on a nearest neighbor search algorithm, including: constructing a search tree based on all the function embedding feature vectors of the comparison file; the search tree includes a first number of tree nodes; based on each function embedding feature vector in the main file, searching the first number of tree nodes based on the nearest neighbor search algorithm to determine a second number of neighbor nodes; the neighbor nodes are tree nodes whose distance from the function embedding feature vector of the main file is within a preset distance threshold; the first number is greater than the second number; and using function pairs consisting of each function embedding feature vector of the main file and the function embedding feature vector of the comparison file corresponding to the nearest node as the alternative similar function pairs.
[0012] According to a binary file similarity analysis method provided by the present invention, the method performs optimal matching on the alternative similar function pairs based on a maximum weight matching algorithm, and uses the obtained matched similar function pairs as the binary file similarity analysis results, including: determining the similarity between the function embedding feature vector of the main file in the alternative similar function pair and the function embedding feature vector of the comparison file based on a function similarity algorithm; determining the weight required by the maximum weight matching algorithm based on the similarity; solving the optimal matching relationship of the alternative similar function pairs based on the maximum weight matching algorithm based on the weight, and using the similar function pair with the largest sum of weights in the matching results as the matched similar function pair; each function embedding vector feature of the main file in the matched similar function pair is matched only with an embedded vector feature in one of the comparison files.
[0013] The present invention also provides a binary file similarity analysis system, comprising: a reverse module, used to perform binary file reverse engineering on a binary main file and a binary comparison file, to obtain binary function information of the main file and binary function information of the comparison file; a feature extraction module, used to perform feature extraction on the binary function information of the main file and the binary function information of the comparison file, to obtain an initial feature vector of the main file and an initial feature vector of the comparison file; an embedding module, used to input the initial feature vector of the main file and the initial feature vector of the comparison file into a pre-trained binary function embedding model, to obtain a function embedding feature vector of the main file and a function embedding feature vector of the comparison file output by the binary function embedding model; a search module, used to determine an alternative similar function pair based on a nearest neighbor search algorithm according to the function embedding feature vector of the main file and the function embedding feature vector of the comparison file; a matching module, used to perform optimal matching solution on the alternative similar function pair based on a maximum weight matching algorithm, and use the obtained matched similar function pair as the binary file similarity analysis result.
[0014] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the binary file similarity analysis method described above is implemented.
[0015] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the computer program implements any of the above-mentioned binary file similarity analysis methods.
[0016] The present invention provides a binary file similarity analysis method, system, device and storage medium. First, binary file reverse engineering is performed on a binary main file and a binary comparison file. Then, feature extraction is performed on the binary function information of the main file and the binary function information of the comparison file obtained by reverse engineering. Then, the initial feature vector of the main file and the initial feature vector of the comparison file obtained are input into a pre-trained binary function embedding model to obtain the function embedding feature vector of the main file and the function embedding feature vector of the comparison file output by the binary function embedding model. According to the function embedding feature vector of the main file and the function embedding feature vector of the comparison file, alternative similar function pairs are determined based on a nearest neighbor search algorithm. Based on the maximum weight matching algorithm, the optimal matching solution is performed on the alternative similar function pairs to obtain matched similar function pairs. Accurate and efficient analysis of binary file similarity can be achieved in complex scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the present invention or the prior art, a brief introduction is given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0018] Figure 1 The present invention provides a flowchart of a binary file similarity analysis method.
[0019] Figure 2 The figure is a schematic diagram of the principle of a binary file similarity analysis method provided by the present invention.
[0020] Figure 3 This is a schematic diagram of the binary file similarity analysis principle provided by the present invention.
[0021] Figure 4 It is a schematic diagram of the principle of the binary function embedding model based on the gated graph neural network provided by the present invention.
[0022] Figure 5 It is a schematic diagram of the principle of binary function embedding model training based on contrastive learning provided by the present invention.
[0023] Figure 6 It is a structural diagram of a binary file similarity analysis system provided by the present invention.
[0024] Figure 7 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0025] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0026] It should be noted that binary files are files stored in a format that can be directly understood and executed by a computer, such as PE (Portable Executable) files on Windows platforms, ELF (Executable and Linkable Format) files on Unix platforms, and Mach-O (Mach Object) files on macOS platforms. Binary files use 0s and 1s to represent instructions and data, are not readable, and are difficult to write directly. They are usually compiled from source code (such as C / C++ language code). According to the general settings in this field, binary codes generated from the same source code using different compilation conditions can be considered similar.
[0027] Traditional binary file similarity analysis methods use methods such as function call graph matching, control flow graph matching, instruction sequence alignment, and byte hashing to find similar parts between binary files. However, differences in the instruction set architecture, compiler, and compilation optimization level used in compilation have a huge impact on the generated binary code morphology, resulting in poor accuracy of such methods.
[0028] Figure 1 This is a flow chart of a binary file similarity analysis method provided by the present invention. Figure 1 As shown, the method includes the following steps 101, 102, 103, 104 and 105.
[0029] Step 101: Perform binary file reverse engineering on the binary master file and the binary comparison file to obtain binary function information of the master file and binary function information of the comparison file.
[0030] Step 102: Perform feature extraction on the binary function information of the main file and the binary function information of the comparison file to obtain an initial feature vector of the main file and an initial feature vector of the comparison file.
[0031] Step 103: Input the initial feature vector of the main file and the initial feature vector of the comparison file into the pre-trained binary function embedding model to obtain the function embedding feature vector of the main file and the function embedding feature vector of the comparison file output by the binary function embedding model.
[0032] Step 104 : Determine candidate similar function pairs based on a nearest neighbor search algorithm according to the function embedding feature vector of the main file and the function embedding feature vector of the comparison file.
[0033] Step 105 : performing optimal matching on the candidate similarity function pairs based on the maximum weight matching algorithm, and taking the obtained matched similarity function pairs as the binary file similarity analysis results.
[0034] Figure 2 This is a schematic diagram of the principle of a binary file similarity analysis method provided by the present invention, such as Figure 2 As shown, to address the shortcomings of existing binary file similarity analysis methods, the present invention proposes a binary file similarity analysis method that combines a binary function embedding model, a similar function nearest neighbor search, and a maximum weight matching algorithm. This method fully utilizes the feature information of binary functions to accurately and efficiently implement end-to-end similarity analysis of binary files. Specifically, the present invention first performs binary file reverse engineering on the input primary file and comparison file, respectively, to obtain binary function information for the primary file and the comparison file. Features are then extracted from all binary functions based on expert experience, and the initial binary function feature vectors are mapped using a pre-trained binary function embedding model to obtain function embedding feature vectors. For each function embedding feature vector in the primary file, a nearest neighbor search algorithm is used to find a function embedding feature vector in the comparison file that is closest to it, forming candidate similar function pairs. For all candidate similar function pairs, weights are calculated based on the cosine similarity between the function embedding feature vectors. The maximum weight matching algorithm is then used to determine the best matching relationship, and the resulting matched similar function pairs are used as the binary file similarity analysis results. Finally, the binary file similarity analysis results can be exported into a common database file format. The binary file reversal, feature extraction, and binary function embedding steps can be cached to achieve reuse acceleration.
[0035] Figure 3 This is a schematic diagram of the binary file similarity analysis principle provided by the present invention, such as Figure 3 As shown, the most important component of a binary file is binary functions. A binary file can be viewed as a graph structured by function calls. Binary file similarity analysis aims to find matching relationships between functions in two files. Circles represent binary functions, arrows represent function call relationships, and dashed lines indicate similarity relationships between pairs of functions from two files. These similarity values can be calculated using various binary function similarity models. In the final matching output, each function in one file can match at most one function in the other file, and the sum of the similarities of these matching function pairs is as large as possible.
[0036] As a preferred embodiment, binary file reverse engineering is performed on a binary main file and a binary comparison file to obtain binary function information of the main file and binary function information of the comparison file, including: using a preset binary file reverse tool to perform binary file reverse engineering on the binary main file and the binary comparison file to obtain binary function information of the main file and binary function information of the comparison file with reverse attributes; the preset binary file reverse tools include IDA Pro, Ghidra and Radare2; the reverse attributes include control flow graphs, assembly codes and constant data; the method also includes: persistently caching the binary function information of the main file and the binary function information of the comparison file in units of binary files.
[0037] Because binary files are unreadable, this embodiment requires reverse engineering the input master file and comparison file to obtain basic information about the binary file, including the file format, target architecture, function call graph, function control flow graph, and instruction bytes in basic blocks. Disassembling the instruction bytes also yields assembly code, improving code readability and facilitating subsequent processing and feature extraction. Constant data includes string constants and numeric constants used in the code.
[0038] Tools available for reverse engineering binary files include IDA Pro, Ghidra, and Radare2. IDA Pro, a programmable interactive disassembler and debugger, offers advantages for malware analysis, vulnerability research, commercial off-the-shelf verification, and privacy protection. It provides exceptional quality and performance across various platforms and is compatible with a wide range of processors. Ghidra, a software reverse engineering framework, includes a comprehensive suite of high-end software analysis tools, enabling users to analyze encoded code on various platforms, including Windows, macOS, and Linux. Features include disassembly, assembly, decompilation, plotting, scripting, and hundreds of other functions. Ghidra supports various processor instruction sets and executable formats and can run in both user-interactive and automated modes. Users can also develop their own Ghidra extensions and / or scripts in Java or Python. Radare2 is a reverse engineering and binary analysis framework that includes disassembly, data analysis, patching, data comparison, search, replace, and virtualization. It also features robust scripting capabilities, runs on nearly all major platforms, and supports a wide range of CPU architectures, file formats, and script languages.
[0039] The reverse engineering process of binary files is usually time-consuming. Considering that in actual applications, a binary file may be analyzed for similarity with a large number of other files, such as known files in component reuse detection or malware identification, the reverse operation of such files does not need to be repeated. By calculating SHA-256 on the binary file content to obtain a unique identifier, the obtained binary function information is persistently stored as a cache in units of binary files when the reverse step is performed for the first time. When it is used again, the cached result can be directly retrieved and read based on the unique identifier. When performing large-scale analysis, first check whether the input file is already cached. If so, the cached result is directly read without reprocessing.
[0040] As a preferred embodiment, feature extraction is performed on the binary function information of the main file and the binary function information of the comparison file to obtain the initial feature vector of the main file and the initial feature vector of the comparison file, including: extracting numerical features representing the semantics of the binary code from the binary function information of the main file and the binary function information of the comparison file based on expert experience to obtain the initial feature vector of the main file and the initial feature vector of the comparison file; the method also includes: persistently caching the initial feature vector of the main file and the initial feature vector of the comparison file in units of binary files.
[0041] In this embodiment, functions in a binary file are represented as feature vectors. The distance between feature vectors can reflect the degree of similarity between functions. Generally, the closer the feature vector distance, the more similar the corresponding functions. Commonly used vector distance functions include cosine distance (or cosine similarity) and Euclidean distance. There is no specific limitation on the method for obtaining function feature vectors.
[0042] For example, for each basic block node in a binary function's control flow graph, seven initial feature vectors selected by expert experience are extracted: the number of string constants, the number of numeric constants, the number of transfer instructions, the number of call instructions, the number of arithmetic instructions, the total number of instructions, and the number of basic block successor nodes. This allows the nodes of the control flow graph to be represented as a 7-dimensional vector, and the binary function can now be represented as an attributed control flow graph (ACFG).
[0043] The initial feature vectors of binary functions are persistently stored in binary files as cache. During large-scale analysis, we first check whether the input file is already cached. If so, we directly read the cached results without reprocessing.
[0044] As a preferred embodiment, the initial feature vector of the main file and the initial feature vector of the comparison file are input into a pre-trained binary function embedding model to obtain the function embedding feature vector of the main file and the function embedding feature vector of the comparison file output by the binary function embedding model, including: training the binary function embedding model to be trained to obtain a trained binary function embedding model; the binary function embedding model is a gated graph neural network model; the gated graph neural network model includes a feature encoding multi-layer perceptron, a node state iteration module and a gated aggregation module; the initial feature vector of the main file and the initial feature vector of the comparison file are processed by the feature encoding multi-layer perceptron, the node state iteration module and the gated aggregation module inside the trained binary function embedding model to obtain a binary function embedding The model outputs a function-embedded feature vector of the main file and a function-embedded feature vector of the comparison file; a feature encoding multilayer perceptron is used to perform node feature encoding on the initial feature vector to obtain a vector after node feature encoding; a node state iteration module is used to perform a preset round of node state iteration on the vector after node feature encoding to obtain a vector after node state iteration; during each round of node state iteration, the state vector of the current node is updated according to the state vector of the neighboring node; a gated aggregation module is used to perform node state aggregation on the vector after node state iteration, and the obtained node state aggregation vector is used as the function-embedded feature vector; the method also includes: persistently caching the function-embedded feature vector of the main file and the function-embedded feature vector of the comparison file in units of binary files.
[0045] Figure 4 This is a schematic diagram of the principle of the binary function embedding model based on the gated graph neural network provided by the present invention, such as Figure 4 As shown, in this embodiment, a binary function embedding model is established using a gated graph neural network (GGNN) to embed the ACFG of the binary function, ultimately obtaining a function embedding feature vector. The gated graph neural network model mainly includes a feature encoding multilayer perceptron, a node state iteration module, and a gated aggregation module.
[0046] Suppose the input binary function is a, the binary function embedding model is represented by φ(·), and the function embedding feature vector obtained by embedding the binary function is h, then this embedding process can be expressed as h = φ(α).
[0047] Specifically, the ACFG of the input binary function is subjected to node feature encoding by the feature encoding MLP (Multi-Layer Perceptron) to obtain the node feature encoded vector; the node feature encoded vector is iterated by the node state iteration module for T rounds to obtain the node state iterated vector, wherein, in each round of iteration, the current node state vector According to the neighbor node state vector The state is updated by the message passing MLP GRU (Gated Recurrent Unit) to obtain the updated state vector of the current node
[0048] Binary functions are embedded in feature vectors and persistently stored in binary files as cache. During large-scale analysis, the first step is to check whether the input file is already cached. If so, the cached result is directly read without reprocessing.
[0049] In this embodiment, the cosine similarity algorithm can be used to measure the similarity between binary function embedding feature vectors. The cosine similarity value is [-1, 1], where a value of 1 indicates complete similarity and a value of -1 indicates complete dissimilarity. The similarity calculation method between two binary functions a and b is as follows:
[0050] As a preferred embodiment, a binary function embedding model to be trained is trained to obtain a trained binary function embedding model, including: constructing a training data set of binary functions; the training data set includes binary function sample pairs of instruction set architecture, compiler and compilation optimization level, and similar labels of the sample pairs; according to the training data set, the binary function embedding model to be trained is trained to convergence by comparing the learning loss function to obtain a trained binary function embedding model.
[0051] Figure 5 This is a schematic diagram of the principle of binary function embedding model training based on contrastive learning provided by the present invention, such as Figure 5 As shown in Figure 1, in order to use the function embedding feature vectors output by the binary function embedding model to measure function similarity, a large-scale dataset is needed to train the model's parameters. The binary functions in the training set should include a variety of instruction set architectures (X86, ARM, MIPS), compilers (GCC, Clang), and compilation optimization levels (O0, O1, O2, O3). Binary code is generated from the source code using different compilation conditions, and binary functions corresponding to the same source code are considered similar function pairs.
[0052] This example uses contrastive learning to train a binary function embedding model. During training, a mini-batch of ACFGs is used as training data. Function embedding feature vectors are obtained by passing them through the neural network to be trained. Model training involves adjusting the parameters in the neural network so that the embedding vectors of similar functions are as close as possible and the embedding vectors of dissimilar functions are as far apart as possible.
[0053] For N pairs of similar functions (a1, b1), (a2, b2), …, (a N , b N ), when i = j, a i and b j are similar functions; when i ≠ j, a i and b j are not similar. The loss function used for contrastive learning training is as follows: where τ is a hyperparameter used to control the model's attention to difficult samples and can be selected based on the effect of cross-validation. A common value is 0.05. Train the model according to the above loss function until convergence or reach the upper limit of the number of iterations.
[0054] The trained binary function embedding model is used in the binary function embedding step of the present invention. For all functions in the reverse binary file, use this binary function embedding model to obtain their function embedding feature vectors. Similar to the binary reverse step, the results of the feature extraction and function embedding steps can be cached for easy reuse and acceleration.
[0055] As a preferred embodiment, based on the function embedding feature vectors of the main file and the comparison file, determine alternative similar function pairs based on the nearest neighbor search algorithm, including: constructing a search tree according to all the function embedding feature vectors of the comparison file; the search tree includes a first number of tree nodes; based on each function embedding feature vector in the main file, search in the first number of tree nodes based on the nearest neighbor search algorithm to determine a second number of nearest neighbor nodes; the nearest neighbor nodes are tree nodes whose distance from the function embedding feature vector of the main file is within a preset distance threshold; the first number is greater than the second number; form function pairs by combining each function embedding feature vector of the main file with the function embedding feature vectors of the comparison file corresponding to the nearest neighbor nodes as alternative similar function pairs.
[0056] In this embodiment, obtain function pairs with higher similarity in the main file and the comparison file as alternatives for the matching results. Specifically, assume there are n binary functions in the main file and m binary functions in the comparison file, then n × m groups of function pairs are formed. However, it is unnecessary to use all function pairs as alternatives for the matching results because in the final result, one function can at most match one function in another file, and the similarity of some function pairs is too low and can be considered unlikely to be successfully paired. Ignoring these similarities has little impact on the final result and can speed up the matching solution.
[0057] For each function in the main file, only need to obtain the top k functions (k < m) with higher similarity to it in the comparison file. To ensure the quality of the matching results, k cannot be too small. In this embodiment, take
[0058] Binary functions have been previously represented as function embedding feature vectors. Obtaining the top k functions with the highest similarity is a classic nearest neighbor search (or vector retrieval) problem, which can be solved using algorithms such as kd-tree search and ball tree search.
[0059] In this embodiment, a ball tree search algorithm is used. First, all binary function embedding feature vectors are normalized, and the proximity of the vectors is measured using Euclidean distance. Then, all function embedding feature vectors in the comparison file are constructed into a ball tree. A k-nearest neighbor search is then performed on each function embedding feature vector in the main file in the ball tree. A small number of data points (neighboring nodes) that are close to the tree nodes of the search tree are queried to form candidate similar function pairs. The ball tree structure uses a hypersphere to partition the vector space. When a node is searched, the decision to continue the search is made by calculating whether the target vector is within the hypersphere corresponding to the node. This pruning strategy can speed up the search. After the search is completed, a total of n×k groups of similar function pairs are obtained as input to the matching algorithm.
[0060] As a preferred embodiment, the best matching of the alternative similar function pairs is solved based on the maximum weight matching algorithm, and the obtained matched similar function pairs are used as the binary file similarity analysis results, including: determining the similarity between the function embedding feature vector of the main file in the alternative similar function pair and the function embedding feature vector of the comparison file based on the function similarity algorithm; determining the weight required by the maximum weight matching algorithm according to the similarity; solving the best matching relationship of the alternative similar function pairs based on the maximum weight matching algorithm according to the weight, and taking the similar function pair with the largest sum of weights in the matching results as the matched similar function pair; each function embedding vector feature of the main file in the matched similar function pair is only matched with the embedding vector feature in one comparison file.
[0061] In this embodiment, a subset is selected from the n×k groups of similar function pairs obtained previously to form a matching relationship (i.e., one function is paired with at most one function in another file), and the sum of the similarities of the matched function pairs is as large as possible, which can be abstracted as a maximum weight matching problem.
[0062] Suppose the n×k variables to be solved are x ab ∈{0, 1}, where a represents the ath function in the main file, b represents the bth function in the main file, and x ab =1 means that the matching result contains the function pair consisting of these two functions, x ab =0, the matching result does not include this function pair.
[0063] x ab The corresponding weight w ab∈[0, 1] can be calculated by the similarity of the function pair, and the calculation method is as follows: The maximum weight problem is a constrained integer programming problem and can be expressed as follows: This optimization problem has been solved with related algorithms. In this embodiment, the best match (i.e., x ab The value of x is 1), and all weights of the best match can be obtained at the same time (i.e., x ab The corresponding w ab ).
[0064] In this embodiment, the best matching result is exported to a common file format. Similarity analysis of binary files may be used as a subtask for applications such as component detection and malware identification. Exporting the results in a common format facilitates subsequent processing, analysis, and presentation. In this embodiment, the SQLite database file format is selected to store the matching results in the form of a relational table. The table contains the successfully matched binary function pairs (name and virtual address) in the master file and the comparison file, along with their similarity weights.
[0065] The following describes a binary file similarity analysis system provided by the present invention. The binary file similarity analysis system described below and the binary file similarity analysis method described above can refer to each other.
[0066] Figure 6 This is a schematic diagram of the structure of a binary file similarity analysis system provided by the present invention. Figure 6As shown, the present invention also provides a binary file similarity analysis system, including: a reverse module 1, used to perform binary file reverse engineering on a binary main file and a binary comparison file to obtain binary function information of the main file and binary function information of the comparison file; a feature extraction module 2, used to perform feature extraction on the binary function information of the main file and the binary function information of the comparison file to obtain an initial feature vector of the main file and an initial feature vector of the comparison file; an embedding module 3, used to input the initial feature vector of the main file and the initial feature vector of the comparison file into a pre-trained binary function embedding model to obtain a function embedding feature vector of the main file and a function embedding feature vector of the comparison file output by the binary function embedding model; a search module 4, used to determine an alternative similar function pair based on a nearest neighbor search algorithm according to the function embedding feature vector of the main file and the function embedding feature vector of the comparison file; a matching module 5, used to perform optimal matching solution on the alternative similar function pair based on a maximum weight matching algorithm, and use the obtained matched similar function pair as the binary file similarity analysis result.
[0067] Figure 7 An example of a physical structure diagram of an electronic device is shown below. Figure 7 As shown, the electronic device may include: a processor (processor) 701, a communication interface (Communications Interface) 702, a memory (memory) 703 and a communication bus 704, wherein the processor 701, the communication interface 702, and the memory 703 communicate with each other through the communication bus 704. The processor 701 can call the logic instructions in the memory 703 to execute the binary file similarity analysis method, which includes: performing binary file reverse engineering on the binary main file and the binary comparison file to obtain binary function information of the main file and binary function information of the comparison file; performing feature extraction on the binary function information of the main file and the binary function information of the comparison file to obtain an initial feature vector of the main file and an initial feature vector of the comparison file; inputting the initial feature vector of the main file and the initial feature vector of the comparison file into a pre-trained binary function embedding model to obtain a function embedding feature vector of the main file and a function embedding feature vector of the comparison file output by the binary function embedding model; determining an alternative similar function pair based on a nearest neighbor search algorithm according to the function embedding feature vector of the main file and the function embedding feature vector of the comparison file; performing optimal matching solution on the alternative similar function pair based on a maximum weight matching algorithm, and using the obtained matched similar function pair as the binary file similarity analysis result.
[0068] In addition, the logic instructions in the above-mentioned memory 703 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0069] On the other hand, the present invention also provides a computer program product, which includes a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the binary file similarity analysis method provided by the above methods, which includes: performing binary file reverse engineering on a binary main file and a binary comparison file to obtain binary function information of the main file and binary function information of the comparison file; performing feature extraction on the binary function information of the main file and the binary function information of the comparison file to obtain an initial feature vector of the main file and an initial feature vector of the comparison file; inputting the initial feature vector of the main file and the initial feature vector of the comparison file into a pre-trained binary function embedding model to obtain a function embedding feature vector of the main file and a function embedding feature vector of the comparison file output by the binary function embedding model; determining an alternative similar function pair based on a nearest neighbor search algorithm according to the function embedding feature vector of the main file and the function embedding feature vector of the comparison file; performing optimal matching solution on the alternative similar function pair based on a maximum weight matching algorithm, and using the obtained matched similar function pair as the binary file similarity analysis result.
[0070] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the binary file similarity analysis method provided by the above-mentioned methods, the method comprising: performing binary file reverse engineering on a binary main file and a binary comparison file to obtain binary function information of the main file and binary function information of the comparison file; performing feature extraction on the binary function information of the main file and the binary function information of the comparison file to obtain an initial feature vector of the main file and an initial feature vector of the comparison file; inputting the initial feature vector of the main file and the initial feature vector of the comparison file into a pre-trained binary function embedding model to obtain a function embedding feature vector of the main file and a function embedding feature vector of the comparison file output by the binary function embedding model; determining an alternative similar function pair based on a nearest neighbor search algorithm according to the function embedding feature vector of the main file and the function embedding feature vector of the comparison file; performing optimal matching solution on the alternative similar function pairs based on a maximum weight matching algorithm, and using the obtained matched similar function pairs as the binary file similarity analysis result.
[0071] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.
[0072] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, or of course, by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the existing technology can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or certain parts of the embodiments.
[0073] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A binary file similarity analysis method, characterized in that: include: Perform binary file reverse engineering on the binary master file and the binary comparison file to obtain binary function information of the master file and binary function information of the comparison file; Performing feature extraction on the binary function information of the master file and the binary function information of the comparison file to obtain an initial feature vector of the master file and an initial feature vector of the comparison file; Inputting the initial feature vector of the master file and the initial feature vector of the comparison file into a pre-trained binary function embedding model, obtaining the function embedding feature vector of the master file and the function embedding feature vector of the comparison file output by the binary function embedding model; Determine candidate similar function pairs based on a nearest neighbor search algorithm according to the function embedding feature vector of the master file and the function embedding feature vector of the comparison file; The best matching solution is performed on the candidate similarity function pair based on the maximum weight matching algorithm, and the obtained matching similarity function pair is used as the binary file similarity analysis result.
2. The binary file similarity analysis method according to claim 1, characterized in that: The performing binary file reversal on the binary master file and the binary comparison file to obtain binary function information of the master file and binary function information of the comparison file includes: Using a preset binary file reverse tool to perform binary file reverse engineering on the binary master file and the binary comparison file, to obtain binary function information of the master file and binary function information of the comparison file with reverse attributes; the preset binary file reverse tool includes IDA Pro, Ghidra and Radare2; the reverse attributes include control flow graph, assembly code and constant data; The method further comprises: The binary function information of the main file and the binary function information of the comparison file are persistently cached in units of binary files.
3. The binary file similarity analysis method according to claim 1, characterized in that: The step of extracting features from the binary function information of the master file and the binary function information of the comparison file to obtain an initial feature vector of the master file and an initial feature vector of the comparison file includes: Extracting numerical features representing the semantics of binary codes from the binary function information of the master file and the binary function information of the comparison file according to expert experience, and obtaining an initial feature vector of the master file and an initial feature vector of the comparison file; The method further comprises: The initial feature vector of the main file and the initial feature vector of the comparison file are persistently cached in units of binary files.
4. The binary file similarity analysis method according to claim 1, characterized in that: The step of inputting the initial feature vector of the master file and the initial feature vector of the comparison file into a pre-trained binary function embedding model to obtain the function embedding feature vector of the master file and the function embedding feature vector of the comparison file output by the binary function embedding model comprises: The binary function embedding model to be trained is trained to obtain the trained binary function embedding model; the binary function embedding model is a gated graph neural network model; the gated graph neural network model includes a feature encoding multilayer perceptron, a node state iteration module and a gated aggregation module; After the initial feature vector of the master file and the initial feature vector of the comparison file are processed by the feature encoding multilayer perceptron, the node state iteration module and the gated aggregation module inside the trained binary function embedding model, the function embedding feature vector of the master file and the function embedding feature vector of the comparison file output by the binary function embedding model are obtained; The feature encoding multilayer perceptron is used to perform node feature encoding on the initial feature vector to obtain a node feature encoded vector; The node state iteration module is used to perform a preset round of node state iteration on the vector after the node feature encoding to obtain the vector after the node state iteration; during each round of node state iteration, the state vector of the current node is updated according to the state vector of the neighboring node; The gated aggregation module is used to perform node state aggregation on the vector after the node state iteration, and embed the obtained node state aggregated vector as a function into a feature vector; The method further comprises: The function embedding feature vector of the main file and the function embedding feature vector of the comparison file are persistently cached in units of binary files.
5. The binary file similarity analysis method according to claim 4, characterized in that: The step of training the binary function embedding model to be trained to obtain the trained binary function embedding model includes: Constructing a training data set of binary functions; the training data set includes binary function sample pairs of instruction set architecture, compiler and compilation optimization level, and similarity labels of the sample pairs; According to the training data set, the binary function embedding model to be trained is trained until convergence by comparing the learning loss function to obtain the trained binary function embedding model.
6. The binary file similarity analysis method according to claim 1, characterized in that: The step of determining candidate similar function pairs based on a nearest neighbor search algorithm according to the function embedding feature vector of the main file and the function embedding feature vector of the comparison file comprises: Construct a search tree according to all the function embedding feature vectors of the comparison file; the search tree includes a first number of tree nodes; according to each function embedding feature vector in the master file, search in the first number of tree nodes based on the nearest neighbor search algorithm to determine a second number of nearest neighbor nodes; the nearest neighbor nodes are tree nodes whose distances from the function embedding feature vector of the master file are within a preset distance threshold; the first number is greater than the second number; A function pair consisting of each function embedding feature vector of the main file and the function embedding feature vector of the comparison file corresponding to the neighboring node is used as the candidate similar function pair.
7. The binary file similarity analysis method according to any one of claims 1 to 6, characterized in that: The method of performing optimal matching on the candidate similarity function pairs based on the maximum weight matching algorithm and using the obtained matched similarity function pairs as the binary file similarity analysis result includes: Determine the similarity between the function embedding feature vector of the main file and the function embedding feature vector of the comparison file in the candidate similar function pair based on a function similarity algorithm; Determining the weight required by the maximum weight matching algorithm according to the similarity; According to the weights, the best matching relationship of the alternative similarity function pairs is solved based on the maximum weight matching algorithm, and the similarity function pair with the largest sum of weights in the matching results is used as the matched similarity function pair; each function embedded vector feature of the main file in the matched similarity function pair is matched only with an embedded vector feature in the comparison file.
8. A binary file similarity analysis system, characterized in that: include: A reverse module, used for performing binary file reverse engineering on a binary master file and a binary comparison file to obtain binary function information of the master file and binary function information of the comparison file; A feature extraction module, used for performing feature extraction on the binary function information of the master file and the binary function information of the comparison file to obtain an initial feature vector of the master file and an initial feature vector of the comparison file; An embedding module, used for inputting the initial feature vector of the master file and the initial feature vector of the comparison file into a pre-trained binary function embedding model, and obtaining the function embedding feature vector of the master file and the function embedding feature vector of the comparison file output by the binary function embedding model; A search module, configured to determine candidate similar function pairs based on a nearest neighbor search algorithm according to the function embedding feature vector of the master file and the function embedding feature vector of the comparison file; The matching module is used to perform optimal matching on the candidate similarity function pairs based on a maximum weight matching algorithm, and use the obtained matched similarity function pairs as the binary file similarity analysis results.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the binary file similarity analysis method according to any one of claims 1 to 7 is implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the binary file similarity analysis method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Cross-instruction-set-architecture binary function similarity checking system and method
CN113900923A
Binary function similarity detection method and system based on composite feature model
CN115526251A
Binary component detection method and system based on neural network and function call graph
CN117454382A
