A dynamic detection method and system for encryption algorithm based on Pin tool
By using the Pin tool to trace the instruction stream and register data of executable files, generating function call frames and linked lists, and combining information entropy detection and loop body analysis, the problem of low accuracy in identifying SIMD instructions and optimizing encryption algorithms in existing technologies is solved, achieving more efficient identification of encryption functions.
Patent Information
- Application Number
- CN202410813256.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-24
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2044-06-24
AI Technical Summary
Existing encryption algorithm detection methods based on Pin tools cannot effectively identify encryption algorithms optimized using SimD instructions, resulting in low recognition accuracy.
The Pin tool is used to trace the instruction level of the executable file, extract the instruction stream and register data, generate function call frames and linked lists, and identify the encrypted functions optimized from SIMD instructions through information entropy detection and loop body analysis.
It improves the accuracy and efficiency of identifying the SIMD instruction-optimized encryption algorithm, and the generated function call framework can more accurately find the encryption function.
Smart Images

Figure CN118378288B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network security technology, and in particular to a Pin tool-based encryption algorithm dynamic detection method and system. Background Art
[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.
[0003] The encryption algorithm detection technology based on dynamic execution uses the Pin tool to simulate the virtual machine running the executable file and extracts the instruction stream of the executable file during dynamic execution and the data stream in the register according to the written tool to generate a trace file, and then detects the calling function of the trace file, and then detects the information entropy of the calling function to find the encryption algorithm function.
[0004] Generally speaking, the existing method is to obtain the tracking data through Pin, then perform loop body recognition, and then calculate the information entropy based on the continuous memory read data and write data of the loop body to determine the encryption algorithm. The current Pin-based tracking data extraction does not recognize the encryption algorithm optimized by SIMD instructions, does not recognize and extract the data in the XMM, YMM, and ZMM registers, and the recognition method is relatively simple. There is no recognition method for most encryption algorithms. Therefore, the recognition accuracy of the encryption function is low. Summary of the invention
[0005] In order to solve the technical problems existing in the above-mentioned background technology, the present invention provides a dynamic detection method and system for encryption algorithms based on Pin tools. The present invention increases the recognition of encryption functions optimized by SIMD instructions and extensible instructions, and also generates a function call framework. The encryption function is detected by using this framework, thereby improving the efficiency and accuracy of recognition.
[0006] In order to achieve the above object, the present invention adopts the following technical solution:
[0007] The first aspect of the present invention provides an encryption algorithm dynamic detection method based on a Pin tool.
[0008] A dynamic detection method for encryption algorithms based on a Pin tool, comprising:
[0009] Use the Pin tool to trace the instruction level of the executable file, extract the instruction stream and register data when the executable file is running dynamically, and store these data in the trace file;
[0010] Detect the instructions in the trace file to obtain all the called functions during the execution of the executable file, store the calling addresses of all the called functions and the starting and ending line numbers in the trace file in the function call frame node, and generate a function call frame; store all the called function addresses and the number of calls in the function call linked list, and after each node storing the called function address, generate a new node for storing the node address in the function call frame when the called function is called;
[0011] Based on the function call framework, the calling function is detected in the loop body according to the number of calls of the function call linked list from most to least, and then the information entropy is detected on the loop body to determine whether the information entropy meets the set threshold. If so, find out whether the calling functions of the upper and above levels under the same calling function framework meet the encryption algorithm. If so, repeat the process of finding out whether the calling functions of the upper and above levels under the same calling function framework are encryption algorithms until there is no calling function that meets the encryption algorithm at the same level, or there is no upper function, then this calling function is an encryption function; if the information entropy does not meet the set threshold, then this calling function is a normal function.
[0012] Furthermore, based on the function call framework, the calling function is detected in a loop body according to the number of calls of the function call linked list from most to least, and then the loop body is detected for information entropy to determine whether the information entropy meets the set threshold. If so, the calling function of the upper level and above under the same calling function framework is found to meet the encryption algorithm. If so, the process of repeatedly finding whether the calling function of the upper level and above under the same calling function framework is the encryption algorithm is repeated until there is no calling function that meets the encryption algorithm at the same level, or there is no upper function, then this calling function is an encryption function; if the information entropy does not meet the set threshold, then this calling function is a normal function. The process includes:
[0013] Start the search from the calling function with the most calls, and perform loop body detection on the calling function. If no loop body is found, the calling function is a normal function. If a loop body is found, the calling function is suspected to be an encrypted function. Repeat the loop body search process in the calling function from the most to the least number of calls until the entire calling function file is detected.
[0014] The detection loop body detects the read data and the corresponding read data memory address, the write data and the corresponding write data memory address of the memory, and then sorts the address size of the read data memory address and the address size of the write data memory address respectively, and finds the continuous read memory segment, the data in the read memory segment, the continuous write memory segment and the data in the write memory segment;
[0015] According to the continuous reading of memory segments, reading of data in memory segments, continuous writing of memory segments and data in written memory segments, the information entropy of written data and the information entropy of read data are calculated. If the information entropy meets the set threshold, it is considered that this calling function is a component of the encryption algorithm. At this time, it is necessary to detect the same function calling frame of this calling function and the upper-level calling function of this calling function. If there are other calling functions that meet the encryption algorithm, then find other upper-level functions under the same function calling frame again, and detect again according to the above steps until there is no calling function that meets the encryption algorithm at the same level, or there is no upper-level function, then this function is an encryption function; if the information entropy does not meet the set threshold, this calling function is a normal function.
[0016] Furthermore, the process of calculating the information entropy of written data and the information entropy of read data includes: dividing the information entropy of written data or the information entropy of read data into 256 bytes respectively, calculating the information entropy of the 256 bytes, and then using a sliding window method, sliding 128 bytes each time, and calculating the information entropy again. For those less than 256 bytes, calculate according to the specific bytes, and finally calculate the average information entropy.
[0017] Furthermore, the process of detecting the instructions in the trace file to obtain all the calling functions during the execution of the executable file includes:
[0018] Traverse the trace file to find the call instruction, and record the operation address of the call instruction on the memory and the number of lines in the trace file and store them in the linked list node of the function call linked list; traverse the trace file to find the ret instruction, and record the operation address of the ret instruction on the memory, match the operation address of the call instruction on the memory with the operation address of the ret instruction on the memory, if they match, the calling function is found, otherwise, continue to traverse the next ret instruction until the ret instruction is found, record the number of lines in the trace file corresponding to this ret instruction, record the number of lines of this ret instruction in the matching call node, then the number of lines between the call instruction and the ret instruction is the calling function, and record the number of times each calling function is called; if the corresponding ret instruction is not found until the end of the trace file, it is considered to be a normal jump and recorded; scan the calling function in each recorded node, continue to look for the calling function, until the last calling function is found, and generate a function call linked list.
[0019] Furthermore, the function call linked list includes: this linked list node contains two node pointers, namely down and next, and the address of each called function and the number of times it is called are recorded in the linked list node, and subsequent nodes are generated using the next pointer. Each subsequent node records the node address of the called function in the function call frame when the called function is called, and the down pointer points to the next called function. After counting all the called functions, they are sorted in descending order according to the number of times they are called.
[0020] Furthermore, the process of generating a function call framework includes: extracting a calling function from a trace file as a first-level calling function; extracting a calling function from a first-level calling function as a second-level calling function, and similarly, until the last-level calling function is obtained to obtain a function call framework.
[0021] Furthermore, for encryption algorithms using SIMD optimization, SIMD instructions that need to be detected, and data in the XMM register, YMM register, and ZMM register are analyzed using the same method as above.
[0022] The second aspect of the present invention provides an encryption algorithm dynamic detection system based on the Pin tool.
[0023] A dynamic detection system for encryption algorithms based on Pin tools, comprising:
[0024] A dynamic instruction extraction module is configured to: use a Pin tool to track the instruction level of the executable file, extract the instruction stream and data in the register when the executable file is dynamically running, and store the data in a trace file;
[0025] The function extraction module is configured to: detect the instructions in the trace file to obtain all the calling functions during the execution of the executable file, store the calling addresses of all the calling functions and the starting line numbers and ending line numbers in the trace file in the function calling frame node, and generate a function calling frame; store all the calling function addresses and the calling times in the function calling linked list, and after each node storing the calling function address, generate a new node for storing the node address in the function calling frame when the calling function is called;
[0026] The dynamic detection module is configured as follows: based on the function call framework, according to the number of calls of the function call linked list from most to least, the loop body of the calling function is detected, and then the information entropy of the loop body is detected to determine whether the information entropy meets the set threshold. If so, find out whether the calling functions of the superior and above under the same calling function framework meet the encryption algorithm. If so, repeat the process of finding out whether the calling functions of the superior and above under the same calling function framework are encryption algorithms, until there is no calling function at the same level that meets the encryption algorithm, or there is no superior function, then this calling function is an encryption function; if the information entropy does not meet the set threshold, then this calling function is an ordinary function.
[0027] Furthermore, the dynamic detection module is also configured to:
[0028] Start the search from the calling function with the most calls, and perform loop body detection on the calling function. If no loop body is found, the calling function is a normal function. If a loop body is found, the calling function is suspected to be an encrypted function. Repeat the loop body search process in the calling function from the most to the least number of calls until the entire calling function file is detected.
[0029] The detection loop body detects the read data and the corresponding read data memory address, the write data and the corresponding write data memory address of the memory, and then sorts the address size of the read data memory address and the address size of the write data memory address respectively, and finds the continuous read memory segment, the data in the read memory segment, the continuous write memory segment and the data in the write memory segment;
[0030] According to the continuous reading of memory segments, reading of data in memory segments, continuous writing of memory segments and data in written memory segments, the information entropy of written data and the information entropy of read data are calculated. If the information entropy meets the set threshold, it is considered that this calling function is a component of the encryption algorithm. At this time, it is necessary to detect the same function calling frame of this calling function and the upper-level calling function of this calling function. If there are other calling functions that meet the encryption algorithm, then find other upper-level functions under the same function calling frame again, and detect again according to the above steps until there is no calling function that meets the encryption algorithm at the same level, or there is no upper-level function, then this function is an encryption function; if the information entropy does not meet the set threshold, this calling function is a normal function.
[0031] Furthermore, the dynamic detection module is also configured to: calculate the information entropy of written data and the information entropy of read data, including: divide the information entropy of written data or the information entropy of read data into 256 bytes, calculate the information entropy of these 256 bytes, and then use the sliding window method to slide 128 bytes each time, calculate the information entropy again, and for those less than 256 bytes, calculate according to the specific bytes, and finally calculate the average information entropy.
[0032] Compared with the prior art, the present invention has the following beneficial effects:
[0033] The present invention can extract the EIP of the dynamic runtime instruction of the executable file, the identification mark of the memory reading and writing, the instruction assembly name, the operand, the address of the instruction on the memory operation, the general register data, the data in the xmm register, the data in the ymm register, and the data in the zmm register. By detecting the SIMD instruction set and matching the data in the corresponding register, the encryption algorithm that uses the SIMD instruction for encryption optimization can be identified, and the generated function call framework can improve the accuracy and efficiency of finding the encryption function. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.
[0035] Figure 1 It is a flow chart of the encryption algorithm dynamic detection method based on Pin tool shown in the present invention;
[0036] Figure 2 It is a schematic diagram of instruction information of Pin extraction shown in the present invention;
[0037] Figure 3 It is a schematic diagram of a calling function framework shown in the present invention;
[0038] Figure 4 It is a schematic diagram of a function call chain shown in the present invention;
[0039] In the figure, 1.0, 2.0, 3.0, 1.1, 1.2, 1.3, 2.1, 2.2, 2.3: names of calling function framework nodes. DETAILED DESCRIPTION
[0040] Embodiment 1
[0041] like Figure 1As shown, this embodiment provides a dynamic detection method for encryption algorithms based on the Pin tool. This embodiment uses the method applied to a server as an example. It can be understood that the method can also be applied to a terminal, and can also be applied to a terminal, a server, and a system, and is implemented through the interaction between the terminal and the server. The server can be an independent physical server, or a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network servers, cloud communications, middleware services, domain name services, security services CDN, and big data and artificial intelligence platforms. The terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in this application. In this embodiment, the method includes the following steps:
[0042] Use the Pin tool to trace the instruction level of the executable file, extract the instruction stream and register data when the executable file is running dynamically, and store these data in the trace file;
[0043] Detect the instructions in the trace file to obtain all the called functions during the execution of the executable file, store the calling addresses of all the called functions and the starting and ending line numbers in the trace file in the function call frame node, and generate a function call frame; store all the called function addresses and the number of calls in the function call linked list, and after each node storing the called function address, generate a new node for storing the node address in the function call frame when the called function is called;
[0044] Based on the function call framework, the calling function is detected in the loop body according to the number of calls of the function call linked list from most to least, and then the information entropy is detected on the loop body to determine whether the information entropy meets the set threshold. If so, find out whether the calling functions of the upper and above levels under the same calling function framework meet the encryption algorithm. If so, repeat the process of finding out whether the calling functions of the upper and above levels under the same calling function framework are encryption algorithms until there is no calling function that meets the encryption algorithm at the same level, or there is no upper function, then this calling function is an encryption function; if the information entropy does not meet the set threshold, then this calling function is a normal function.
[0045] like Figure 2As shown, the Pin tool implements instruction-level tracking of executable files, and extracts and records the instruction address of each instruction, the read and write judgment of memory, the instruction name, the virtual address of the instruction's memory operation, the value in the general register, the value in the r8-r15 register; the data in the xmm register, the data in the ymm register, and the data in the zmm register into the trace file.
[0046] like Figure 3 As shown, first scan the trace file to find the call instruction, record the memory operation address of this call instruction and the number of lines in the trace file in the frame node, continue to traverse the trace file to find the ret instruction, record the memory operation address of the ret instruction, match these two memory operation addresses, and if the match is successful, the calling function is found and the number of lines in the trace file is recorded in the node. If the match fails, continue to look for the next ret instruction. If the corresponding ret instruction is not found until the end of the file, then it is considered to be an ordinary jump and needs to be recorded as a calling function. According to the above method, find the direct calling function in the trace file, which is the outermost calling function. Then continue to find its nested calling function according to the above method for the calling function in the newly generated frame node, generate a new node, and continue to find the last calling function and generate a function call framework. Among them, the calling function extracted from the trace file is the first-level calling function in Figure 3 1.0, 2.0, 3.0 are used to represent the calling function extracted from the first-level calling function, that is, the second-level calling function in Figure 3 It is represented by 1.1, 1.2, 1.3, 2.1, 2.2, and 2.3, and similarly, until the last level of calling function is obtained, the function calling framework is obtained.
[0047] like Figure 4 As shown in the figure, the function call linked list records the function call address and call count, and the node address of the calling function in the function call frame. The specific method is that when generating the function call frame, each time a call instruction is found, the address of its call is matched with the address in the function call linked list. If they are the same, the corresponding call count is increased by one, and the node address of the calling function in the calling function frame is recorded in the corresponding node.
[0048] Start searching for the loop body from the most called function call list, record the data read and written by the instructions in the loop body to the continuous memory, and then perform information entropy detection. First, perform loop body detection on the function call list. The detection method is to find the jump instruction in the function call list, and then see whether the jump instruction jumps successfully. The sign of a successful jump instruction is that the instruction address of the next line is equal to the jump address of the jump instruction. If the jump is successful, the entire file can be searched for this instruction address, and the number of occurrences is counted. If it exceeds two times, it is considered to be a loop body. The second loop of this loop body is output to the loop body file, and the number of occurrences is continued to be counted. At this time, the calling function can be divided into suspected encryption functions and ordinary functions. If the loop body is not found in the most called function call list, find the loop body from the second most called function according to the function call list, and repeat the above steps until the loop body is detected or the entire trace file is detected. If a calling function containing a loop body is found, the instructions for reading and writing memory are judged from the loop body, and all the read and write data of the memory during the operation of this function are recorded. Then, the data is sorted according to the memory address corresponding to the data, and the data with continuous addresses are saved. Then, information entropy detection is performed. According to the records of reading and writing data at continuous memory addresses obtained previously, the information entropy of the written data and the information entropy of the read data are calculated. The data is divided into 256 bytes, and the information entropy of this 256 bytes is calculated. Then, the sliding window method is used, and the information entropy is calculated again by sliding 128 bytes each time. For less than 256 bytes, it is calculated according to bytes. Finally, the average information entropy of each byte is calculated. If the information entropy meets the set threshold (the set threshold is 0.7), it is considered to be an encryption algorithm or a component of the encryption algorithm. At this time, it is necessary to detect the calling functions of the same frame and level of this calling function. If there are other calling functions in the same frame and level that meet the encryption algorithm, then find other functions at the upper level under the same frame again, and detect again according to the above steps until there is no calling function at the same level that meets the encryption algorithm, or there is no upper function, then this function is an encryption function; otherwise, this calling function is a normal function.
[0049] Embodiment 2
[0050] This embodiment provides an encryption algorithm dynamic detection system based on a Pin tool.
[0051] A dynamic detection system for encryption algorithms based on Pin tools, comprising:
[0052] A dynamic instruction extraction module is configured to: use a Pin tool to track the instruction level of the executable file, extract the instruction stream and data in the register when the executable file is dynamically running, and store the data in a trace file;
[0053] The function extraction module is configured to: detect the instructions in the trace file to obtain all the calling functions during the execution of the executable file, store the calling addresses of all the calling functions and the starting line numbers and ending line numbers in the trace file in the function calling frame node, and generate a function calling frame; store all the calling function addresses and the calling times in the function calling linked list, and after each node storing the calling function address, generate a new node for storing the node address in the function calling frame when the calling function is called;
[0054] The dynamic detection module is configured as follows: based on the function call framework, according to the number of calls of the function call linked list from most to least, the loop body of the calling function is detected, and then the information entropy of the loop body is detected to determine whether the information entropy meets the set threshold. If so, find out whether the calling functions of the superior and above under the same calling function framework meet the encryption algorithm. If so, repeat the process of finding out whether the calling functions of the superior and above under the same calling function framework are encryption algorithms, until there is no calling function at the same level that meets the encryption algorithm, or there is no superior function, then this calling function is an encryption function; if the information entropy does not meet the set threshold, then this calling function is an ordinary function.
[0055] In some embodiments, the dynamic detection module is further configured to: start searching from the calling function with the most calls, perform loop body detection on the calling function, if no loop body is found, the calling function is a common function, if a loop body is found, the calling function is suspected to be an encrypted function; repeat the loop body search process in the calling function according to the number of calls from most to least, until the entire calling function file is detected;
[0056] The detection loop body detects the read data and the corresponding read data memory address, the write data and the corresponding write data memory address of the memory, and then sorts the address size of the read data memory address and the address size of the write data memory address respectively, and finds the continuous read memory segment, the data in the read memory segment, the continuous write memory segment and the data in the write memory segment;
[0057] According to the continuous reading of memory segments, reading of data in memory segments, continuous writing of memory segments and data in written memory segments, the information entropy of written data and the information entropy of read data are calculated. If the information entropy meets the set threshold, it is considered that this calling function is a component of the encryption algorithm. At this time, it is necessary to detect the same function calling frame of this calling function and the upper-level calling function of this calling function. If there are other calling functions that meet the encryption algorithm, then find other upper-level functions under the same function calling frame again, and detect again according to the above steps until there is no calling function that meets the encryption algorithm at the same level, or there is no upper-level function, then this function is an encryption function; if the information entropy does not meet the set threshold, this calling function is a normal function.
[0058] In some embodiments, the dynamic detection module is also configured to: calculate the information entropy of written data and the information entropy of read data, including: divide the information entropy of written data or the information entropy of read data into 256 bytes, calculate the information entropy of these 256 bytes, and then use the sliding window method to slide 128 bytes each time, calculate the information entropy again, and for those less than 256 bytes, calculate according to the specific bytes, and finally calculate the average information entropy.
[0059] In some embodiments, the function extraction module is further configured to: traverse the trace file to find the call instruction, and record the operation address of the call instruction on the memory and the number of lines in the trace file and store them in the linked list node of the function call linked list; traverse the trace file to find the ret instruction, and record the operation address of the ret instruction on the memory, match the operation address of the call instruction on the memory with the operation address of the ret instruction on the memory, if they match, the calling function is found, otherwise, continue to traverse the next ret instruction until the ret instruction is found, record the number of lines in the trace file corresponding to this ret instruction, record the number of lines of this ret instruction in the matching call node, then the number of lines between the call instruction and the ret instruction is the calling function, and record the number of times each calling function is called; if the corresponding ret instruction is not found until the end of the trace file, it is considered to be a normal jump and recorded; scan the calling function in each recorded node, continue to find the calling function, until the last calling function is found, and generate a function call linked list.
[0060] In some embodiments, the function call linked list includes: this linked list node contains two node pointers, namely down and next, and the address of each called function and the number of times it is called are recorded in the linked list node, and subsequent nodes are generated using the next pointer. Each subsequent node records the node address of the called function in the function call frame when the called function is called, and the down pointer points to the next called function. After counting all the called functions, they are sorted in descending order according to the number of times they are called.
[0061] In some embodiments, the function extraction module is further configured as follows: the calling function extracted from the trace file is a first-level calling function; the calling function extracted from the first-level calling function is a second-level calling function, and similarly, until the last-level calling function is obtained to obtain a function calling framework.
[0062] In some embodiments, for an encryption algorithm using SIMD optimization, SIMD instructions need to be detected, and data in the XMM register, YMM register, and ZMM register are analyzed using the same method as described above.
[0063] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A dynamic detection method for encryption algorithm based on Pin tool, characterized in that: include: Use the Pin tool to trace the instruction level of the executable file, extract the instruction stream and register data when the executable file is running dynamically, and store these data in the trace file; Detect the instructions in the trace file to obtain all the called functions during the execution of the executable file, store the calling addresses of all the called functions and the starting and ending line numbers in the trace file in the function call frame node, and generate a function call frame; store all the called function addresses and the number of calls in the function call linked list, and after each node storing the called function address, generate a new node for storing the node address in the function call frame when the called function is called; Based on the function call framework, according to the number of calls of the function call linked list from most to least, the loop body of the calling function is detected, and then the information entropy of the loop body is detected to determine whether the information entropy meets the set threshold. If so, find out whether the calling functions of the upper and above levels under the same calling function framework meet the encryption algorithm. If so, repeat the process of finding out whether the calling functions of the upper and above levels under the same calling function framework are encryption algorithms, until there is no calling function that meets the encryption algorithm at the same level, or there is no upper function, then this calling function is an encryption function; if the information entropy does not meet the set threshold, then this calling function is a normal function; Based on the function call framework, the calling function is detected in a loop body according to the number of calls of the function call linked list from most to least, and then the information entropy detection is performed on the loop body to determine whether the information entropy meets the set threshold. If so, find out whether the calling functions of the upper and above levels under the same calling function framework meet the encryption algorithm. If so, repeat the process of finding out whether the calling functions of the upper and above levels under the same calling function framework are encryption algorithms, until there is no calling function at the same level that meets the encryption algorithm, or there is no upper function, then this calling function is an encryption function; If the information entropy does not meet the set threshold, the process of calling the function as a normal function includes: Start the search from the calling function with the most calls, and perform loop body detection on the calling function. If no loop body is found, the calling function is a normal function. If a loop body is found, the calling function is suspected to be an encrypted function. Repeat the loop body search process in the calling function from the most to the least number of calls until the entire calling function file is detected. The detection loop body detects the read data and the corresponding read data memory address, the write data and the corresponding write data memory address of the memory, and then sorts the address size of the read data memory address and the address size of the write data memory address respectively, and finds the continuous read memory segment, the data in the read memory segment, the continuous write memory segment and the data in the write memory segment; According to the continuous reading of memory segments, reading of data in memory segments, continuous writing of memory segments and data in written memory segments, the information entropy of written data and the information entropy of read data are calculated. If the information entropy meets the set threshold, it is considered that this calling function is a component of the encryption algorithm. At this time, it is necessary to detect the same function calling frame of this calling function and the upper-level calling function of this calling function. If there are other calling functions that meet the encryption algorithm, then find other upper-level functions under the same function calling frame again, and detect again according to the above steps until there is no calling function that meets the encryption algorithm at the same level, or there is no upper-level function, then this function is an encryption function; if the information entropy does not meet the set threshold, this calling function is a normal function.
2. The method for dynamic detection of encryption algorithms based on Pin tools according to claim 1, characterized in that: The process of calculating the information entropy of written data and the information entropy of read data includes: dividing the information entropy of written data or the information entropy of read data into 256 bytes respectively, calculating the information entropy of the 256 bytes, and then using the sliding window method, sliding 128 bytes each time, and calculating the information entropy again. For those less than 256 bytes, calculate according to the specific bytes, and finally calculate the average information entropy.
3. The method for dynamic detection of encryption algorithms based on Pin tools according to claim 1, characterized in that: The process of detecting the instructions in the trace file to obtain all the calling functions during the execution of the executable file includes: Traverse the trace file to find the call instruction, and record the operation address of the call instruction on the memory and the number of lines in the trace file and store them in the linked list node of the function call linked list; traverse the trace file to find the ret instruction, and record the operation address of the ret instruction on the memory, match the operation address of the call instruction on the memory with the operation address of the ret instruction on the memory, if they match, the calling function is found, otherwise, continue to traverse the next ret instruction until the ret instruction is found, record the number of lines in the trace file corresponding to this ret instruction, record the number of lines of this ret instruction in the matching call node, then the number of lines between the call instruction and the ret instruction is the calling function, and record the number of times each calling function is called; if the corresponding ret instruction is not found until the end of the trace file, it is considered to be a normal jump and recorded; scan the calling function in each recorded node, continue to look for the calling function, until the last calling function is found, and generate a function call linked list.
4. The method for dynamic detection of encryption algorithms based on Pin tools according to claim 3 is characterized in that: The function call linked list includes: this linked list node contains two node pointers, namely down and next, the address of each calling function and the number of times it is called are recorded in the linked list node, and subsequent nodes are generated using the next pointer. Each subsequent node records the node address of the calling function in the function call frame when it is called, and the down pointer points to the next called function. After counting all the calling functions, they are sorted in descending order according to the number of times they are called.
5. The method for dynamic detection of encryption algorithms based on Pin tools according to claim 1, characterized in that: The process of generating a function call framework includes: extracting a calling function from a trace file as a first-level calling function; extracting a calling function from a first-level calling function as a second-level calling function, and similarly, until the last-level calling function is obtained to obtain a function call framework.
6. The method for dynamic detection of encryption algorithms based on Pin tools according to any one of claims 1 to 5, characterized in that: For encryption algorithms using SIMD optimization, SIMD instructions need to be detected, and the data in the XMM register, YMM register, and ZMM register are analyzed using the same method.
7. A dynamic detection system for encryption algorithms based on Pin tools, characterized in that: include: A dynamic instruction extraction module is configured to: use a Pin tool to track the instruction level of the executable file, extract the instruction stream and data in the register when the executable file is dynamically running, and store the data in a trace file; The function extraction module is configured to: detect the instructions in the trace file to obtain all the calling functions during the execution of the executable file, store the calling addresses of all the calling functions and the starting line numbers and ending line numbers in the trace file in the function calling frame node, and generate a function calling frame; store all the calling function addresses and the calling times in the function calling linked list, and after each node storing the calling function address, generate a new node for storing the node address in the function calling frame when the calling function is called; The dynamic detection module is configured as follows: based on the function call framework, according to the number of calls of the function call linked list from most to least, the loop body detection of the calling function is performed, and then the information entropy detection of the loop body is performed to determine whether the information entropy meets the set threshold value. If so, the calling function of the upper level and above under the same calling function framework is found to meet the encryption algorithm. If so, the process of repeatedly finding whether the calling function of the upper level and above under the same calling function framework is the encryption algorithm is repeated until there is no calling function that meets the encryption algorithm at the same level, or there is no upper function, then this calling function is an encryption function; if the information entropy does not meet the set threshold value, then this calling function is a common function; Based on the function call framework, the calling function is detected in a loop body according to the number of calls of the function call linked list from most to least, and then the information entropy detection is performed on the loop body to determine whether the information entropy meets the set threshold. If so, find out whether the calling functions of the upper and above levels under the same calling function framework meet the encryption algorithm. If so, repeat the process of finding out whether the calling functions of the upper and above levels under the same calling function framework are encryption algorithms, until there is no calling function at the same level that meets the encryption algorithm, or there is no upper function, then this calling function is an encryption function; If the information entropy does not meet the set threshold, the process of calling the function as a normal function includes: Start the search from the calling function with the most calls, and perform loop body detection on the calling function. If no loop body is found, the calling function is a normal function. If a loop body is found, the calling function is suspected to be an encrypted function. Repeat the loop body search process in the calling function from the most to the least number of calls until the entire calling function file is detected. The detection loop body detects the read data and the corresponding read data memory address, the write data and the corresponding write data memory address of the memory, and then sorts the address size of the read data memory address and the address size of the write data memory address respectively, and finds the continuous read memory segment, the data in the read memory segment, the continuous write memory segment and the data in the write memory segment; According to the continuous reading of memory segments, reading of data in memory segments, continuous writing of memory segments and data in written memory segments, the information entropy of written data and the information entropy of read data are calculated. If the information entropy meets the set threshold, it is considered that this calling function is a component of the encryption algorithm. At this time, it is necessary to detect the same function calling frame of this calling function and the upper-level calling function of this calling function. If there are other calling functions that meet the encryption algorithm, then find other upper-level functions under the same function calling frame again, and detect again according to the above steps until there is no calling function that meets the encryption algorithm at the same level, or there is no upper-level function, then this function is an encryption function; if the information entropy does not meet the set threshold, this calling function is a normal function.
8. The encryption algorithm dynamic detection system based on Pin tool according to claim 7 is characterized in that: The dynamic detection module is also configured to: calculate the information entropy of written data and the information entropy of read data, including: divide the information entropy of written data or the information entropy of read data into 256 bytes, calculate the information entropy of the 256 bytes, and then use the sliding window method to slide 128 bytes each time, calculate the information entropy again, and for less than 256 bytes, calculate according to the specific bytes, and finally calculate the average information entropy.
