Binary file similarity analysis method, system, device and storage medium
By combining binary function embedding models, similar function nearest neighbor search, and maximum weight matching algorithms, the problem of low accuracy of existing tools in complex scenarios is solved, and efficient and accurate analysis of binary file similarity is achieved.
Patent Information
- Application Number
- CN202410700555.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2044-05-31
AI Technical Summary
Existing binary file similarity analysis tools have low accuracy in complex scenarios involving cross-architecture, cross-compiler, and cross-optimization levels, making it difficult to meet analysis requirements.
By combining binary function embedding model, similar function nearest neighbor search and maximum weight matching algorithm, we can achieve accurate and efficient analysis of binary file similarity through binary file inversion, feature extraction, function embedding and similar function pair matching.
It enables accurate and efficient analysis of binary file similarity in complex scenarios, improving the accuracy and efficiency of the analysis.
Smart Images

Figure CN118568516B_ABST
Abstract
Description
Technical Field
[0001] This 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 Technology
[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 crucial role and directly impact the reliability and security of the entire system.
[0003] Binary file similarity analysis is particularly crucial in the security field. By performing similarity analysis on binary files, potential security threats and vulnerability propagation paths can be effectively identified, allowing for timely implementation of appropriate security measures 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 structures and byte characteristics for analysis, making it difficult to achieve good results in complex scenarios involving cross-architecture, cross-compiler, and cross-optimization levels. In practical applications, due to the diversity and complexity of software development environments, these tools often perform poorly and cannot meet the requirements for 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 shortcomings of existing binary file similarity analysis tools in terms of low accuracy under complex scenarios. This invention combines a binary function embedding model, similarity function nearest neighbor search, and maximum weight matching algorithm to achieve accurate and efficient analysis of binary file similarity.
[0006] This invention provides a binary file similarity analysis method, comprising: performing binary file inversion 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; extracting features from the binary function information of the master file and the comparison file to obtain initial feature vectors of the master file and the comparison file; inputting the initial feature vectors of the master file and the comparison file into a pre-trained binary function embedding model to obtain function embedding feature vectors of the master file and the comparison file output by the binary function embedding model; determining candidate similar function pairs based on the function embedding feature vectors of the master file and the comparison file using a nearest neighbor search algorithm; performing optimal matching on the candidate similar function pairs using a maximum weight matching algorithm, and using the obtained matched similar function pairs as the binary file similarity analysis result.
[0007] According to a binary file similarity analysis method provided by the present invention, the step of 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 the comparison file includes: using a preset binary file reverse engineering 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 the comparison file with reverse engineering attributes; the preset binary file reverse engineering tool includes IDA Pro, Ghidra, and Radare2; the reverse engineering attributes include control flow graphs, assembly code, and constant data; the method further includes: persistently caching the binary function information of the master file and the comparison file on a binary file-by-binary-file basis.
[0008] According to a binary file similarity analysis method provided by the present invention, the step of extracting features from 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 includes: 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 further includes: persistently caching the initial feature vector of the main file and the initial feature vector of the comparison file on a binary file basis.
[0009] According to a binary file similarity analysis method provided by the present invention, the step of 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 the function embedding feature vectors of the main file and the comparison file output by the binary function embedding model includes: 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 multilayer perceptron, a node state iteration module, and a gated aggregation module; the initial feature vectors of the main file and the initial feature vectors of the comparison file are processed by the feature encoding multilayer perceptron, the node state iteration module, and the gated aggregation module within the trained binary function embedding model. Subsequently, the function embedding feature vectors of the main file and 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 number of node state iterations on the node feature-encoded vector to obtain a node state-iterated vector; during each node state iteration, the state vector of the current node is updated according to the state vectors of its neighboring nodes; the gating aggregation module is used to aggregate the node states of the node state-iterated vector and use the resulting node state-aggregated vector as the function embedding feature vector; the method further includes: persistently caching the function embedding feature vectors of the main file and the comparison file on a binary file basis.
[0010] According to a binary file similarity analysis method provided by the present invention, training the binary function embedding model to be trained to obtain the trained binary function embedding model includes: constructing a training dataset of binary functions; the training dataset includes binary function sample pairs with instruction set architecture, compiler and compilation optimization level, and similarity labels of the sample pairs; and training the binary function embedding model to be trained to convergence by a contrastive learning loss function based on the training dataset to obtain the trained binary function embedding model.
[0011] According to a binary file similarity analysis method provided by the present invention, the step of determining candidate similar function pairs based on the function embedding feature vector of the main file and the function embedding feature vector of the comparison file using a nearest neighbor search algorithm includes: constructing a search tree based on all function embedding feature vectors of the comparison file; the search tree includes a first number of tree nodes; searching within the first number of tree nodes based on each function embedding feature vector of the main file using 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; and using the function embedding feature vector of the main file and the function embedding feature vector of the comparison file corresponding to the nearest neighbor node as the candidate similar function pairs.
[0012] According to a binary file similarity analysis method provided by the present invention, the step of performing optimal matching on candidate similar function pairs based on the maximum weight matching algorithm and taking the obtained matched similar function pairs as the binary file similarity analysis result includes: determining 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 pairs based on the function similarity algorithm; determining the weight required by the maximum weight matching algorithm according to the similarity; solving the optimal matching relationship of the candidate similar function pairs based on the maximum weight matching algorithm according to the weight, and taking the similar function pairs with the largest sum of weights in the matching results as the matched similar function pairs; in the matched similar function pairs, each function embedding vector feature of the main file matches only one embedding vector feature in the comparison file.
[0013] This invention also provides a binary file similarity analysis system, comprising: a reverse engineering module 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 for extracting features from the binary function information of the master file and 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 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 to obtain function embedding feature vectors of the master file and the comparison file output by the binary function embedding model; a search module for determining candidate similar function pairs based on the function embedding feature vectors of the master file and the comparison file using a nearest neighbor search algorithm; and a matching module for performing optimal matching on the candidate similar function pairs using a maximum weight matching algorithm, and using the obtained matched similar function pairs as the binary file similarity analysis result.
[0014] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the binary file similarity analysis method described above.
[0015] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the binary file similarity analysis method as described above.
[0016] This invention provides a binary file similarity analysis method, system, device, and storage medium. First, binary file reverse engineering is performed on the main binary file and the binary comparison file. Then, feature extraction is performed on the binary function information of the main file and the comparison file obtained from the reverse engineering. Next, the initial feature vectors of the main file and the comparison file are input into a pre-trained binary function embedding model to obtain the function embedding feature vectors of the main file and the comparison file output by the binary function embedding model. Based on the function embedding feature vectors of the main file and the comparison file, candidate similar function pairs are determined using a nearest neighbor search algorithm. Finally, the optimal matching solution is obtained for the candidate similar function pairs using a maximum weight matching algorithm, resulting in a matched similar function pair. This method enables accurate and efficient analysis of binary file similarity in complex scenarios. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0018] Figure 1 This is a flowchart illustrating a binary file similarity analysis method provided by the present invention.
[0019] Figure 2 This is a schematic diagram illustrating the principle of a binary file similarity analysis method provided by the present invention.
[0020] Figure 3 This is a schematic diagram illustrating the principle of binary file similarity analysis provided by the present invention.
[0021] Figure 4 This is a schematic diagram illustrating the principle of the binary function embedding model based on a gated graph neural network provided by this invention.
[0022] Figure 5 This is a schematic diagram illustrating the principle of training a binary function embedding model based on contrastive learning provided by the present invention.
[0023] Figure 6 This is a schematic diagram of the structure of a binary file similarity analysis system provided by the present invention.
[0024] Figure 7 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this 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, ELF (Executable and Linkable Format) files on Unix, and Mach-O (Mach Object) files on macOS. 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 general conventions in this field, binary code obtained from the same source code using different compilation conditions can be considered similar.
[0027] Traditional binary file similarity analysis methods use 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 for compilation can have a significant impact on the form of the generated binary code, resulting in poor accuracy of such methods.
[0028] Figure 1 This is a flowchart illustrating a binary file similarity analysis method provided by the present invention, as shown below. 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 main binary file and the binary comparison file to obtain the binary function information of the main file and the binary function information of the comparison file.
[0030] Step 102: Extract features from 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.
[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: Based on the function embedding feature vector of the main file and the function embedding feature vector of the comparison file, determine the candidate similar function pairs based on the nearest neighbor search algorithm.
[0033] Step 105: Solve the best matching solution for the candidate similarity function pairs based on the maximum weight matching algorithm, and use the obtained matching similarity function pairs as the binary file similarity analysis results.
[0034] Figure 2 This is a schematic diagram illustrating the principle of a binary file similarity analysis method provided by the present invention, as shown below. Figure 2 As shown, to address the shortcomings of existing binary file similarity analysis methods, this invention proposes a binary file similarity analysis method that combines a binary function embedding model, similar function nearest neighbor search, and maximum weight matching algorithm. This method can fully utilize the feature information of binary functions to accurately and efficiently achieve end-to-end similarity analysis of binary files. Specifically, this invention first reverse-engineers the input main file and the comparison file to obtain the binary function information of the main file and the comparison file, respectively. Then, features are extracted from all binary functions based on expert experience, and the initial feature vectors of the binary functions are mapped to obtain function embedding feature vectors through a pre-trained binary function embedding model. For each function embedding feature vector in the main file, a nearest neighbor search algorithm is used to find the function embedding feature vectors in the comparison file that are 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, and the maximum weight matching algorithm is used to solve for the optimal matching relationship. The obtained matched similar function pairs are used as the binary file similarity analysis results. Finally, the binary file similarity analysis results can be exported to a common database file format. The binary file reverse engineering, feature extraction, and binary function embedding steps can be cached to achieve reuse and acceleration.
[0035] Figure 3 This is a schematic diagram illustrating the principle of binary file similarity analysis provided by the present invention, such as... Figure 3 As shown, the most important part of a binary file is its binary functions. A binary file can be viewed as a graph structure formed 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 between pairs of functions from two files. The similarity score can be calculated using various binary function similarity models. In the final matching results, each function in one file can match at most one function in the other file, and the sum of the similarities of the matched function pairs should be as large as possible.
[0036] As a preferred embodiment, binary file reverse engineering is performed on the binary master file and the binary comparison file to obtain binary function information of the master file and the comparison file. This includes: using a preset binary file reverse engineering 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 the comparison file with reverse engineering attributes; the preset binary file reverse engineering tools include IDA Pro, Ghidra, and Radare2; the reverse engineering attributes include control flow graphs, assembly code, and constant data; the method further includes: persistently caching the binary function information of the master file and the comparison file on a binary file-by-binary basis.
[0037] Since binary files are unreadable, this embodiment requires reverse engineering of the input main file and the comparison file to obtain basic information about the binary files, including file format, target architecture, function call graph, function control flow graph, and instruction bytes in basic blocks. Simultaneously, disassembling the instruction bytes 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 such as malware analysis, vulnerability research, commercial off-the-shelf verification, and privacy protection. It provides excellent quality and performance across various platforms and is compatible with a wide range of processors. Ghidra, a software reverse engineering framework, includes a full suite of high-end software analysis tools, enabling users to analyze coded code on various platforms, including Windows, macOS, and Linux. Its features include disassembly, assembly, decompilation, plotting, and scripting, as well as hundreds of other functions. Ghidra supports various processor instruction sets and executable formats and can run in both interactive and automated modes. Users can also develop their own Ghidra extensions and / or scripts using Java or Python. Radare2 is a reverse engineering and binary analysis framework that includes disassembly, data analysis, patching, data comparison, searching, replacement, virtualization, and more. It also boasts powerful script loading capabilities, can run on almost all major platforms, and supports many CPU architectures, file formats, and scripting languages.
[0039] Reverse engineering binary files is typically time-consuming. Considering that in practical applications a binary file might be subjected to similarity analysis with a large number of other files (e.g., component reuse detection or known files in malware identification), reverse engineering of such files doesn't need to be repeated. A unique identifier is obtained by calculating the SHA-256 hash of the binary file content. During the initial reverse engineering step, the resulting binary function information is persistently stored as a cache, on a file-by-file basis. Subsequent uses simply retrieve the cached result based on the unique identifier. For large-scale analysis, it's first checked if the input file is already cached; if so, the cached result is read directly 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 vectors of the main file and the comparison file. This includes: extracting numerical features representing the semantics of binary code from the binary function information of the main file and the comparison file based on expert experience to obtain the initial feature vectors of the main file and the comparison file; the method also includes: persistently caching the initial feature vectors of the main file and the comparison file on a binary file basis.
[0041] In this embodiment, functions in the binary file are represented as feature vectors. The distance between feature vectors reflects the similarity of the functions; generally, the closer the feature vectors are, the more similar the corresponding functions are. Commonly used vector distance functions include cosine distance (or cosine similarity) and Euclidean distance. No specific limitations are placed on the method for obtaining the function feature vectors.
[0042] For example, for each basic block node in the binary function 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 successor nodes of the basic block. Thus, the nodes of the control flow graph can be represented as 7-dimensional vectors, and the binary function can be represented as an attributed control flow graph (ACFG).
[0043] The initial feature vector of the binary function is persistently stored as a cache in binary files. During large-scale analysis, the input file is first checked to see if it is already cached. If so, the cached result is read directly without reprocessing.
[0044] In a preferred embodiment, the initial feature vectors of the main file and the comparison file are input into a pre-trained binary function embedding model to obtain the function embedding feature vectors of the main file and the comparison file output by the binary function embedding model. This includes: 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 multilayer perceptron, a node state iteration module, and a gated aggregation module; the initial feature vectors of the main file and the comparison file are processed by the feature encoding multilayer perceptron, the node state iteration module, and the gated aggregation module within the trained binary function embedding model to obtain the binary function embeddings. The model outputs function embedding feature vectors from the main file and the alignment file. A feature encoding multilayer perceptron is used to encode node features into the initial feature vectors, resulting in a node-encoded vector. A node state iteration module is used to iterate the node state of the node-encoded vectors for a preset number of rounds, resulting in an iterated vector. During each iteration, the current node's state vector is updated based on the state vectors of its neighbors. A gating aggregation module is used to aggregate the node states of the iterated vectors, and the aggregated vector is used as the function embedding feature vector. The method also includes persistent caching of the function embedding feature vectors from the main file and the alignment file, using binary files as the unit.
[0045] Figure 4 This is a schematic diagram illustrating the principle of the binary function embedding model based on a gated graph neural network provided by this invention, as shown below. Figure 4 As shown, in this embodiment, a gated graph neural network (GGNN) is used to establish a binary function embedding model to embed the ACFG of binary functions, ultimately obtaining the function embedding feature vector. The gated graph neural network model mainly includes a feature encoding multilayer perceptron, a node state iteration module, and a gating aggregation module.
[0046] Let the input binary function be a, the binary function embedding model be φ(·), and the function embedding feature vector obtained from the binary function embedding be h. Then this embedding process can be expressed as h=φ(α).
[0047] Specifically, the input binary function ACFG is processed by a feature encoding MLP (Multi-Layer Perceptron) to encode node features, resulting in a vector of node features. This vector is then iterated through T rounds by a node state iteration module to obtain an iterated vector of node states. In each iteration, the current node state vector... Based on the neighbor node state vector The state vector of the current node is updated by performing a state update on a Gated Recurrent Unit (GRU) using a message-passing MLP.
[0048] The feature vectors embedded in binary functions are persistently stored as a cache in binary files. During large-scale analysis, the input file is first checked to see if it is already cached. If so, the cached results are read directly without reprocessing.
[0049] In this embodiment, the cosine similarity algorithm can be used to measure the similarity between the feature vectors embedded in binary functions. The cosine similarity value ranges from -1 to 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, training the binary function embedding model to be trained to obtain a trained binary function embedding model includes: constructing a training dataset of binary functions; the training dataset includes binary function sample pairs with instruction set architecture, compiler and compilation optimization level, and similar labels of sample pairs; and training the binary function embedding model to be trained to convergence by contrastive learning loss function based on the training dataset to obtain a trained binary function embedding model.
[0051] Figure 5 This is a schematic diagram illustrating the principle of training a binary function embedding model based on contrastive learning provided by this invention, as shown below. Figure 5 As shown, in order to make the function embedding feature vectors output by the binary function embedding model usable for measuring function similarity, a large-scale dataset needs to be constructed to train the parameters of the model. The binary functions in the training set should include combinations of various 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 form similar function pairs.
[0052] In this embodiment, a contrastive learning method is used to train the binary function embedding model. A small batch of ACFG is used as training data, which is passed through the neural network to be trained to obtain function embedding feature vectors. 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, which can be selected based on the effect of cross-validation, and a common value is 0.05. Train the model according to the above loss function until convergence or the upper limit of iteration times is reached.
[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-engineered binary file, the binary function embedding model is used to obtain their function embedding feature vectors. Similar to the binary reverse engineering step, the results of the feature extraction and function embedding steps can be cached for reuse and acceleration.
[0055] As a preferred embodiment, candidate similar function pairs are determined based on the function embedding feature vectors of the main file and the function embedding feature vectors of the comparison file using a nearest neighbor search algorithm, which includes: 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; searching among the first number of tree nodes based on the nearest neighbor search algorithm for each function embedding feature vector in the main file to determine a second number of nearest neighbor nodes; the nearest neighbor nodes are tree nodes whose distance from the function embedding feature vectors of the main file is within a preset distance threshold; the first number is greater than the second number; and function pairs composed of each function embedding feature vector of the main file and the function embedding feature vectors of the comparison file corresponding to the nearest neighbor nodes are used as candidate similar function pairs.
[0056] In this embodiment, function pairs with high similarity in the main file and the comparison file are obtained as candidates for the matching results. Specifically, assuming that there are n binary functions in the main file and m binary functions in the comparison file, n×m groups of function pairs are formed. However, it is unnecessary to use all function pairs as candidates for the matching results, because in the final result, a function can only match at most one function in another file. Some function pairs have too low similarity and can be considered unlikely to be successfully paired. Ignoring these similarities has little impact on the final result, and can also speed up the matching solution process.
[0057] For each function in the main file, only the top k functions (k<m) with higher similarity in the comparison file need to be obtained. To ensure the quality of the matching results, k cannot be too small. In this embodiment, take
[0058] Previously, binary functions were represented as function embedding feature vectors. Obtaining the top k functions with high similarity is the classic nearest neighbor search (or vector retrieval) problem, which can be solved using algorithms such as kd-tree search and ball tree search.
[0059] This embodiment uses a ball-tree search algorithm. First, all binary function embedding feature vectors are normalized, and Euclidean distance is used to measure the proximity of the vectors. Then, all function embedding feature vectors in the comparison file are used to construct a ball tree. Next, a k-nearest neighbor search is performed on each function embedding feature vector in the main file within this ball tree. A small number of data points (nearest neighbor nodes) that are relatively close to the target vector are searched within the tree nodes to form candidate similar function pairs. The ball-tree structure uses a hypersphere to partition the vector space. When a node is found, the search can be accelerated by calculating whether the target vector lies within the hypersphere corresponding to that node. This pruning strategy speeds up the search. After the search is complete, n×k similar function pairs are obtained as input to the matching algorithm.
[0060] As a preferred embodiment, the optimal matching solution for candidate similar function pairs is obtained based on the maximum weight matching algorithm, and the obtained matching similar function pairs are used as the binary file similarity analysis results. This includes: determining the similarity between the function embedding feature vectors of the main file and the function embedding feature vectors of the comparison file in the candidate similar function pairs based on the function similarity algorithm; determining the weights required for the maximum weight matching algorithm based on the similarity; solving the optimal matching relationship of the candidate similar function pairs based on the maximum weight matching algorithm according to the weights, and taking the similar function pairs with the largest sum of weights in the matching results as the matched similar function pairs; in the matched similar function pairs, each function embedding vector feature of the main file matches only one embedding vector feature in the comparison file.
[0061] In this embodiment, a subset is selected from the previously obtained n×k sets of similar function pairs to form a matching relationship (i.e., a function is paired with at most one function in another file), and the sum of the similarity of the matched function pairs is maximized. This can be abstracted as a maximum weight matching problem.
[0062] Let x be the n×k variables to be solved. ab ∈{0,1}, where a represents the a-th function in the main file, b represents the b-th function in the main file, and x ab =1 indicates that the matching result contains a function pair consisting of these two functions, x ab If the value is 0, the matching results will not include the function pair.
[0063] x ab The corresponding weight w abThe similarity between pairs of functions ∈ [0, 1] can be calculated using the following method: The maximum weight problem is a constrained integer programming problem, which can be expressed as follows: This optimization problem already has relevant algorithmic implementations. This embodiment uses the solver provided by the NetworkX library to calculate the optimal matching (i.e., x). ab The value of x can be obtained, and at the same time, all weights in the best match (i.e., x with a value of 1) can be obtained. ab The corresponding w ab ).
[0064] In this embodiment, the best matching result obtained is exported in a common file format. Binary file similarity analysis may be a subtask in applications such as component detection and malware identification; exporting the results in a common format facilitates subsequent processing, analysis, and display. This embodiment selects the SQLite database file format, storing the matching results in a relational table. The table contains successfully matched binary function pairs (names and virtual addresses) in the main file and the comparison file, along with their similarity weights.
[0065] The binary file similarity analysis system provided by this invention is described below. The binary file similarity analysis system described below can be referred to in correspondence with the binary file similarity analysis method described above.
[0066] Figure 6 This is a schematic diagram of the structure of a binary file similarity analysis system provided by the present invention, such as... Figure 6As shown, the present invention also provides a binary file similarity analysis system, comprising: a reverse engineering module 1, used to reverse engineer 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; a feature extraction module 2, used to extract features from the binary function information of the master file and the comparison file to obtain initial feature vectors of the master file and the comparison file; an embedding module 3, used to input the initial feature vectors of the master file and the comparison file into a pre-trained binary function embedding model to obtain function embedding feature vectors of the master file and the comparison file output by the binary function embedding model; a search module 4, used to determine candidate similar function pairs based on the function embedding feature vectors of the master file and the comparison file using a nearest neighbor search algorithm; and a matching module 5, used to perform optimal matching on the candidate similar function pairs based on a maximum weight matching algorithm, and use the obtained matched similar function pairs as the binary file similarity analysis result.
[0067] Figure 7 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 7 As shown, the electronic device may include: a processor 701, a communication interface 702, a 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 logical instructions in the memory 703 to execute a binary file similarity analysis method. This method includes: performing binary file inversion on the main binary file and the binary comparison file to obtain binary function information of the main file and the comparison file; extracting features from the binary function information of the main file and the comparison file to obtain initial feature vectors of the main file and the comparison file; inputting the initial feature vectors of the main file and the comparison file into a pre-trained binary function embedding model to obtain function embedding feature vectors of the main file and the comparison file output by the binary function embedding model; determining candidate similar function pairs based on the function embedding feature vectors of the main file and the comparison file using a nearest neighbor search algorithm; and performing optimal matching on the candidate similar function pairs using a maximum weight matching algorithm, taking the obtained matched similar function pairs as the binary file similarity analysis result.
[0068] Furthermore, the logical instructions in the aforementioned memory 703 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0069] On the other hand, the present invention also provides a computer program product, which includes a computer program that 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. The method includes: performing binary file inversion 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; extracting features from the binary function information of the master file and the comparison file to obtain initial feature vectors of the master file and the comparison file; inputting the initial feature vectors of the master file and the comparison file into a pre-trained binary function embedding model to obtain function embedding feature vectors of the master file and the comparison file output by the binary function embedding model; determining candidate similar function pairs based on a nearest neighbor search algorithm according to the function embedding feature vectors of the master file and the comparison file; performing optimal matching on the candidate 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.
[0070] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program is implemented to perform the binary file similarity analysis method provided by the above methods. The method includes: performing binary file inversion 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; extracting features from the binary function information of the master file and the comparison file to obtain initial feature vectors of the master file and the comparison file; inputting the initial feature vectors of the master file and the comparison file into a pre-trained binary function embedding model to obtain function embedding feature vectors of the master file and the comparison file output by the binary function embedding model; determining candidate similar function pairs based on a nearest neighbor search algorithm according to the function embedding feature vectors of the master file and the comparison file; performing optimal matching on the candidate 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. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0072] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some 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, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A binary file similarity analysis method characterized by, include: The binary master file and the binary comparison file are reverse-engineered to obtain the binary function information of the master file and the binary function information of the comparison file; 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. The initial feature vector of the main file and the initial feature vector of the comparison file are input 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. Based on the function embedding feature vector of the main file and the function embedding feature vector of the comparison file, candidate similar function pairs are determined using a nearest neighbor search algorithm; The optimal matching solution is obtained by using the maximum weight matching algorithm to find the best match for the candidate similarity function pairs, and the obtained matching similarity function pairs are used as the results of binary file similarity analysis. The step of determining candidate similar function pairs based on the function embedding feature vector of the main file and the function embedding feature vector of the comparison file using a nearest neighbor search algorithm includes: A search tree is constructed 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, a search is performed in the first number of tree nodes using 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 in the main file is within a preset distance threshold; the first number is greater than the second number; The function pairs formed by combining the function embedding feature vector of each function in the main file with the function embedding feature vector of the comparison file corresponding to the nearest neighbor node are used as the candidate similar function pairs; The optimal matching solution for the candidate similarity function pairs is obtained using the maximum weight matching algorithm, and the resulting matched similarity function pairs are used as the binary file similarity analysis results, including: 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 pairs is determined based on the function similarity algorithm. The weights required for the maximum weight matching algorithm are determined based on the similarity. Based on the weights, the optimal matching relationship of the candidate similar function pairs is solved using the maximum weight matching algorithm, and the similar function pair with the largest sum of weights in the matching results is taken as the matched similar function pair; in the matched similar function pair, each function embedding vector feature of the main file matches only one embedding vector feature in the comparison file.
2. The binary file similarity analysis method according to claim 1, characterized in that, The process of reversing the binary master file and the binary comparison file to obtain the binary function information of the master file and the binary function information of the comparison file includes: The binary main file and the binary comparison file are reverse engineered using a preset binary file reverse engineering tool to obtain binary function information of the main file and the comparison file with reverse engineering attributes; the preset binary file reverse engineering tool includes IDA Pro, Ghidra and Radare2; the reverse engineering attributes include control flow graph, assembly code and constant data; The method further includes: The binary function information of the main file and the binary function information of the comparison file are persistently cached on a binary file basis.
3. The binary file similarity analysis method of claim 1, wherein, The step of extracting features from the binary function information of the main file and the binary function information of the comparison file to obtain the initial feature vectors of the main file and the comparison file includes: Based on expert experience, numerical features characterizing the semantics of binary code are extracted from 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. The method further includes: The initial feature vectors of the main file and the initial feature vectors of the comparison file are persistently cached on a binary file basis.
4. The binary file similarity analysis method according to claim 1, characterized by, The step of 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 the function embedding feature vectors of the main file and the comparison file output by the binary function embedding model includes: 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 gating 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 multilayer perceptron, the node state iteration module and the gated aggregation module inside the 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. The feature-encoding multilayer perceptron is used to encode the node features of the initial feature vector to obtain a node-encoded vector. The node state iteration module is used to perform a preset number of node state iterations on the vector after the node feature encoding to obtain the node state iteration vector; during each round of node state iteration, the current node's state vector is updated according to the state vectors of its neighboring nodes. The gated aggregation module is used to aggregate the node state vector after the node state iteration, and use the obtained aggregated node state vector as a function embedding feature vector. The method further includes: The function embedding feature vectors of the main file and the function embedding feature vectors of the comparison file are persistently cached on a binary file basis.
5. The binary file similarity analysis method according to claim 4, characterized in that, The process of training the binary function embedding model to be trained to obtain the trained binary function embedding model includes: Construct a training dataset for binary functions; the training dataset includes binary function sample pairs with different instruction set architectures, compilers, and compilation optimization levels, as well as similar labels for the sample pairs; Based on the training dataset, the binary function embedding model to be trained is trained to convergence by comparing and learning the loss function, thus obtaining the trained binary function embedding model.
6. A binary file similarity analysis system, characterized by, include: The reverse module is used to reverse the binary main file and the binary comparison file to obtain the binary function information of the main file and the binary function information of the comparison file. The feature extraction module is used to extract features from 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. An embedding module is 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 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. The search module is used to determine candidate similar function pairs based on the function embedding feature vector of the main file and the function embedding feature vector of the comparison file, using a nearest neighbor search algorithm. The matching module is used to solve the optimal matching problem for the candidate similarity function pairs based on the maximum weight matching algorithm, and the obtained matching similarity function pairs are used as the binary file similarity analysis results. The step of determining candidate similar function pairs based on the function embedding feature vector of the main file and the function embedding feature vector of the comparison file using a nearest neighbor search algorithm includes: A search tree is constructed 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, a search is performed in the first number of tree nodes using 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 in the main file is within a preset distance threshold; the first number is greater than the second number; The function pairs formed by combining the function embedding feature vector of each function in the main file with the function embedding feature vector of the comparison file corresponding to the nearest neighbor node are used as the candidate similar function pairs; The optimal matching solution for the candidate similarity function pairs is obtained using the maximum weight matching algorithm, and the resulting matched similarity function pairs are used as the binary file similarity analysis results, including: 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 pairs is determined based on the function similarity algorithm. The weights required for the maximum weight matching algorithm are determined based on the similarity. Based on the weights, the optimal matching relationship of the candidate similar function pairs is solved using the maximum weight matching algorithm, and the similar function pair with the largest sum of weights in the matching results is taken as the matched similar function pair; in the matched similar function pair, each function embedding vector feature of the main file matches only one embedding vector feature in the comparison file.
7. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the binary file similarity analysis method as described in any one of claims 1 to 5.
8. A non-transitory computer-readable storage medium having stored thereon a computer program, characterized in that, When the computer program is executed by the processor, it implements the binary file similarity analysis method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Cross-instruction-set-architecture binary function similarity checking system and method
CN113900923A
Binary component detection method and system based on neural network and function call graph
CN117454382A
