Program attack risk detection method and device, storage medium and electronic equipment
By detecting the heap block control information of the target program and generating corresponding attack constraints, combined with path constraints, the problem of low efficiency of program attack risk detection in the existing technology is solved, and efficient detection of hidden attack risks of the thread cache allocator is achieved.
Patent Information
- Application Number
- CN202410423650.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-09
- Publication Date
- 2024-09-10
AI Technical Summary
Program attack risk detection efficiency in the prior art is low, and it is difficult to effectively detect whether a software program has the risk of thread cache allocator hidden attack.
By detecting the heap control information generated by the target program after inputting specific input information, it generates heap attack constraints and pointer attack constraints, and tests whether the target program has the risk of thread cache allocator concealment attack. It uses target path constraints, heap attack constraints and The combination of pointer attack constraints effectively detects thread cache allocator hidden attack risks.
It improves the efficiency of program attack risk detection, can effectively determine whether the target program has thread cache allocator hidden attack risks, and solves the problem of low detection efficiency in the existing technology.
Smart Images

Figure CN118627077A
Abstract
Description
Technical Field
[0001] The present application relates to the field of financial technology, and specifically, to a method and device for detecting program attack risks, a storage medium, and an electronic device. Background Art
[0002] Software program security vulnerabilities have always been not only an important way for viruses and worms to spread, but also the focus of network attacks and defenses. Most network intrusions are based on software program security vulnerabilities. Attackers can use these security vulnerabilities to access unauthorized system resources, and then destroy important data information in the system, thus posing a great threat to information system security. Therefore, one of the core issues in the field of information security is the various software vulnerabilities in computer systems. In the construction of large-scale information systems in the financial field, some software programs need to be purchased from outside. It may be difficult to obtain the source code of these software programs for internal security audits and security assessments. If security risk detection cannot be performed well, potential security risks will be introduced to the system.
[0003] Currently, the way to detect whether a software program has security risks is to construct a fuzz testing tool. By inputting some random or carefully constructed test cases into the written fuzz testing tool to observe the response of the software program to the input data, problems in the code of the software program can be discovered. This method of constructing test cases in a random or artificial way is not targeted. When an anomaly occurs, the tester needs to analyze the data that caused the anomaly, which leads to problems such as long testing time and low efficiency.
[0004] Currently, no effective solution has been proposed to address the problems of low detection efficiency of program attack risks in related technologies. Summary of the invention
[0005] The main purpose of this application is to provide a method and device for detecting program attack risks, a storage medium and an electronic device to solve the problem of low detection efficiency of program attack risks in related technologies.
[0006] In order to achieve the above object, according to one aspect of the present application, a method for detecting program attack risks is provided. The method comprises:
[0007] Detecting heap control information generated by a target program after inputting target input information, wherein the target program is a program to be tested for a risk of hidden attack on a thread cache allocator, the target input information is input information that allows the target program to crash, and the heap control information is used to indicate the control behavior of the target program on the heap;
[0008] In a case where the heap control information is used to indicate that the target program has a heap vulnerability, generating a heap attack constraint and a pointer attack constraint for the target program;
[0009] Generate target attack information that satisfies the target path constraint, the heap block attack constraint, and the pointer attack constraint at the same time, wherein the target path constraint is used to describe the constraint condition at the path branch in the target program, the attack information that satisfies the heap block attack constraint is used to control the heap block in the input program, and the attack information that satisfies the pointer attack constraint is used to control the pointer in the input program;
[0010] The target attack information is used to test whether the target program has a thread cache allocator hidden attack risk.
[0011] Optionally, generating a heap attack constraint and a pointer attack constraint for the target program includes:
[0012] Detecting whether the target program has a heap block that meets a target heap block control condition, wherein the heap block that meets the target heap block control condition is allowed to be controlled by the thread cache allocator hidden attack;
[0013] In the case where it is detected that the target program has a target heap block that satisfies the target heap block control condition, constructing the heap block attack constraint according to the target heap block, wherein the attack information that satisfies the heap block attack constraint is used to control the target heap block in the target program;
[0014] Detecting whether a target pointer corresponding to the target heap block is a pointer that satisfies a pointer control condition, wherein the target pointer is a pointer in the target heap block that points to a next heap block, and a pointer that satisfies the pointer control condition allows being controlled by information input from outside the target program;
[0015] When it is detected that the target pointer is a pointer that satisfies the pointer control condition, the pointer attack constraint is constructed according to the target pointer, wherein the attack information that satisfies the pointer attack constraint is used to control the target pointer in the target program.
[0016] Optionally, the detecting whether the target program has a heap block that meets the target heap block control condition includes:
[0017] Detecting whether the target program has a heap block that satisfies a first heap block control condition, a second heap block control condition, and a third heap block control condition at the same time, wherein the heap block that satisfies the first heap block control condition is a heap block that has been released in the target program, the heap block that satisfies the second heap block control condition is a heap block that has been stored in an allocator linked list of a thread cache allocator in the target program, the allocator linked list is a linked list maintained by the thread cache allocator and is used to store heap blocks that the thread cache allocator allows to control, and the heap block that satisfies the third heap block control condition is a heap block that has a successor heap block in the target program;
[0018] When it is detected that the target program has a heap that satisfies the first heap control condition, the second heap control condition, and the third heap control condition at the same time, it is determined that the target program has a heap that satisfies the target heap control condition.
[0019] Optionally, the detecting whether the target pointer corresponding to the target heap block is a pointer that satisfies a pointer control condition includes:
[0020] Acquire a tainted area in the target program that is affected by the symbolic seed file, wherein the tainted area is obtained by symbolically executing the target program using target input information as the symbolic seed file, and the target input information is input information that allows the target program to crash;
[0021] In a case where the stain area includes the target pointer, the target pointer is determined to be a pointer that satisfies the pointer control condition.
[0022] Optionally, before generating the heap attack constraint and the pointer attack constraint for the target program, the method further includes:
[0023] Detecting whether the target program has a first heap block vulnerability according to the heap block control information, wherein the first heap block vulnerability is used to indicate that the target program has a risk of overflowing written data from the heap block;
[0024] Detecting whether the target program has a second heap block vulnerability according to the heap block control information, wherein the second heap block vulnerability is used to indicate that the target program has a risk that a released heap block continues to be used;
[0025] Detecting whether the target program has a third heap block vulnerability according to the heap block control information, wherein the third heap block vulnerability is used to indicate that the target program has a risk of heap blocks being repeatedly released;
[0026] When it is detected that the target program has the first heap block vulnerability, and / or the second heap block vulnerability, and / or the third heap block vulnerability, it is determined that the heap block control information is used to indicate that the target program has the heap block vulnerability.
[0027] Optionally, detecting whether the target program has a first heap block vulnerability according to the heap block control information includes: detecting whether a heap block boundary of a heap block in the target program is exceeded by the written data according to the heap block control information; and determining that the target program has a first heap block vulnerability when detecting that a heap block boundary of the heap block in the target program is exceeded by the written data;
[0028] The detecting whether the target program has a second heap block vulnerability according to the heap block control information includes: detecting whether there is a dereference operation on a dangling pointer in the target program according to the heap block control information, wherein the dangling pointer is a pointer pointing to a released heap block or an uninitialized heap block, and the dereference operation is used to access the heap block position of the corresponding dangling pointer; when it is detected that the dereference operation on the dangling pointer exists in the target program, determining that the target program has a second heap block vulnerability;
[0029] The detecting whether the target program has a third heap block vulnerability according to the heap block control information includes: obtaining a reference pointer of the heap block to be released according to the heap block control information, and detecting whether there is a history pointer identical to the reference pointer in a history pointer set, wherein the history pointers in the history pointer set are pointers corresponding to the heap blocks that have been currently released; when it is detected that there is a history pointer identical to the reference pointer in the history pointer set, it is determined that the target program has a third heap block vulnerability.
[0030] Optionally, the detecting of the heap block control information generated by the target program after inputting the target input information includes:
[0031] Extracting a heap block control function capable of controlling the heap block from the control function of the target program;
[0032] Detecting the current execution phase of the heap block control function;
[0033] In the case of detecting that the heap block control function is currently in a pre-execution stage and / or a post-execution stage, reading register information from a register corresponding to the heap block control function, wherein the register is used to store the heap block information corresponding to the heap block control function in the pre-execution stage and / or the post-execution stage;
[0034] The stack block control information is generated according to the register information.
[0035] In order to achieve the above-mentioned purpose, according to another aspect of the present application, a device for detecting program attack risks is provided. The device comprises:
[0036] A first detection module is used to detect heap block control information generated by a target program after inputting target input information, wherein the target program is a program to be tested for a risk of hidden attack on a thread cache allocator, the target input information is input information that allows the target program to crash, and the heap block control information is used to indicate the control behavior of the target program on the heap block;
[0037] A first generating module, configured to generate a heap attack constraint and a pointer attack constraint for the target program when the heap control information indicates that the target program has a heap vulnerability;
[0038] A second generation module is used to generate target attack information that satisfies a target path constraint, the heap block attack constraint, and the pointer attack constraint at the same time, wherein the target path constraint is used to describe the constraint condition at the path branch in the target program, the attack information that satisfies the heap block attack constraint is used to control the heap block in the input program, and the attack information that satisfies the pointer attack constraint is used to control the pointer in the input program;
[0039] A testing module is used to use the target attack information to test whether the target program has a thread cache allocator hidden attack risk.
[0040] Through this application, the following steps are adopted: when it is necessary to test whether the target program has a hidden attack risk of the thread cache allocator, the target program is detected to generate heap control information after inputting the target input information that allows the target program to crash, and the heap control information can indicate the control behavior of the target program on the heap. After that, when the heap control information is used to indicate that the target program has a heap vulnerability, the heap attack constraint and the pointer attack constraint are generated for the target program, and the target attack information that satisfies the target path constraint, the heap attack constraint and the pointer attack constraint is generated. Since the target path constraint can describe the constraint conditions at the path branch in the target program, the attack information that satisfies the heap attack constraint can control the heap in the input program, and the attack information that satisfies the pointer attack constraint can control the pointer in the input program. Therefore, the target attack information is input into the target program to efficiently test whether the target attack information can control the heap in the target program and whether the pointer in the target program can be controlled, thereby determining whether the target program has a hidden attack risk of the thread cache allocator, and solving the problem of low detection efficiency of program attack risks in the related technology. Thus, the technical effect of improving the detection efficiency of program attack risks is achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0042] Figure 1 is a flow chart of a method for detecting program attack risks provided in an embodiment of the present application;
[0043] Figure 2 is a schematic diagram of a system for detecting program attack risks provided according to an embodiment of the present application;
[0044] Figure 3 is a schematic diagram of a program attack risk detection process according to an embodiment of the present application;
[0045] Figure 4 is a schematic diagram of a device for detecting program attack risks according to an embodiment of the present application;
[0046] Figure 5 is a schematic diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0047] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0048] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0049] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0050] For the convenience of description, some nouns or terms involved in the embodiments of the present application are explained below:
[0051] Heap overflow vulnerability: A heap overflow vulnerability refers to a situation where, when a program is running, the size or format of the input data is not properly verified, resulting in data that exceeds the allocated memory area being written to the heap block, thereby overwriting the original data or modifying the state of the program at runtime, and even executing malicious code in the program.
[0052] Double Free Attack: Double Free attack is a common memory vulnerability that exploits memory management errors in a program. Double Free vulnerability occurs when a program attempts to release memory that has already been released. An attacker can cause a program crash or execute arbitrary code by releasing the same memory address multiple times. An attacker usually uses a pointer to release a block of memory first, and then uses another pointer to release the same block of memory. Since the memory has already been released, the second release operation may cause the program to crash or execute arbitrary code. An attacker can use this vulnerability to bypass security checks, tamper with data, or perform other malicious operations.
[0053] Use after free vulnerability: also known as UAF vulnerability, is a common memory security issue, which usually occurs when the program releases memory but still uses the memory pointer. Specifically, the program uses dynamic memory allocation functions (such as malloc, calloc, realloc, etc.) to allocate memory, and after releasing the memory during program execution, it continues to use the memory pointer, causing the program to have undefined behavior, which may be exploited by attackers and cause UAF vulnerabilities. Attackers usually use UAF vulnerabilities to execute malicious code, such as injecting code into the released memory or modifying the data in the memory, thereby performing illegal operations, obtaining sensitive information or controlling the system. UAF vulnerabilities are often a type of security vulnerability that is difficult to detect and fix, so it is very important for programmers and security experts to understand the working principles and prevention methods of UAF vulnerabilities.
[0054] tcache mechanism: tcache mechanism is a cache mechanism in glibc for optimizing the efficiency of heap memory allocation. tcache is the abbreviation of Thread-Caching Allocator, which means thread cache allocator. tcache groups memory blocks of the same size into a group, and each group of memory blocks forms a one-way linked list. In each thread, tcache consists of multiple one-way linked lists, each of which corresponds to a memory block of a certain size. When the program calls malloc to request memory, glibc will first check whether there is a free memory block of the corresponding size available in tcache. If there is an available memory block in tcache, glibc will allocate memory directly from tcache, which is much faster than allocating memory from the heap. When the program calls free to release memory, glibc will insert the memory block into tcache. If tcache is full, it will insert the memory block into the unallocated memory linked list of the heap block. Since tcache is maintained in each thread, each thread has its own tcache. The tcache mechanism can reduce the need for synchronization between threads and improve the concurrent performance of the allocator. Although the tcache mechanism optimizes memory allocation and release efficiency, it also brings some security risks. For example, when there are multiple pointers to the same memory block in the tcache, attackers may exploit this situation to implement a Double Free vulnerability. In addition, attackers can also use the pointers stored in the tcache to forge some illegal memory blocks, thereby implementing attacks such as Heap Exploitation.
[0055] Tcache stashing attack: Thread cache allocator hidden attack, Tcache stashing attack (Tcache hidden attack) is a vulnerability exploitation technique for the Tcache allocator in the glibc library. Tcache is a memory allocator in the glibc library that manages the allocation and release of small blocks of memory. Tcache stores the released small blocks of memory in a specific cache so that they can be quickly reused the next time they are allocated.
[0056] The Tcache stashing attack is based on the following two vulnerabilities:
[0057] Double Free vulnerability: An attacker releases a memory block that has been released in a specific way, causing the memory block to be reinserted into the Tcache linked list.
[0058] Use-after-Free vulnerability: An attacker exploits a freed memory block and continues to operate on it. This may cause the memory to be in an unstable state and be exploited in subsequent allocation operations.
[0059] By exploiting these two vulnerabilities, an attacker can perform a Tcache stashing attack. The following are the general steps of the attack:
[0060] Step 1): Allocate a block of memory and free it twice, creating a Double Free vulnerability.
[0061] Step 2): Reallocate the memory block and put it into the Tcache linked list.
[0062] Step 3): Free the memory block for the first time, then reallocate and continue to use the memory block. This implements the Use-after-Free vulnerability.
[0063] Step 4): Exploit the Use-after-Free vulnerability to modify the pointer of a freed memory block in the Tcache linked list to point it to a memory block controlled by the attacker.
[0064] Step 5): When a subsequent allocation request occurs, the Tcache allocator will take the memory block controlled by the attacker from the Tcache linked list and allocate it to the requester.
[0065] In this way, attackers can control memory blocks allocated to other applications and perform potential malicious actions, such as modifying critical data and executing arbitrary code.
[0066] Fuzz testing: Fuzz testing is a method of discovering software failures by providing unexpected inputs and monitoring abnormal results. Fuzz testing is generally an automatic or semi-automatic process that involves repeatedly manipulating the target software and providing it with input data. In fuzz testing, you first construct an abnormal input data, then test it according to the set test mode, and monitor the test results. By analyzing the anomalies, you can find errors that may cause vulnerability attacks.
[0067] Symbolic Execution: Symbolic execution is a program analysis technique that can automatically explore all possible paths of a program without executing the actual program code. In symbolic execution, the input of the program is treated as symbolic variables rather than specific numerical values. When the program executes to a branch statement, the symbolic executor generates two different path conditions, each corresponding to the two possible results of the branch statement. The symbolic executor solves these path conditions and generates a set of inputs that meet these path conditions, which can be used as test cases for the program. Unlike traditional manually written test cases, symbolic execution technology can automatically generate inputs, cover all possible paths in the program, and can find some difficult-to-find errors, such as memory leaks, null pointer references, etc. At the same time, symbolic execution technology can also help program developers understand the behavior of the program, discover hidden logical errors in the program, and perform code audits, etc.
[0068] Seed input: In symbolic execution, seed input refers to the initial input of the program, which is used to start the symbolic execution process. In symbolic execution, the input of the program is no longer a specific numerical value, but a symbolic variable represented by a symbol, that is, the value of the variable is unknown, but can be represented by a symbolic variable. Symbolic execution uses these symbolic variables to represent the input in the program in order to explore all possible paths of program execution.
[0069] Directed symbolic execution: Directed symbolic execution is a program analysis technique based on symbolic execution. Compared with traditional symbolic execution techniques, directed symbolic execution can more efficiently find vulnerabilities in programs and generate more accurate test cases. In traditional symbolic execution, the execution path of the program is automatically explored and generated by the symbolic executor. This automated exploration method may result in a large number of path explorations, many of which may not have practical significance. In directed symbolic execution, the execution path of the program is controlled by user-specified guiding conditions. These guiding conditions can be assertions, error handling codes, or user-defined conditions in the program. The directed symbolic executor will only perform path exploration when these guiding conditions are met, thereby reducing the number of path explorations. Directed symbolic execution technology can also use known program semantic information to guide path exploration. For example, known preconditions, postconditions, or constraints in the program can be used to limit the search space of symbolic execution. These restrictions can significantly improve the efficiency of the symbolic executor.
[0070] Taint analysis: Taint analysis is a program analysis technique used to track the flow and use of sensitive data in a program. Taint analysis can identify vulnerabilities and potential security issues in a program, helping developers and security experts quickly discover and fix security vulnerabilities. The core idea of taint analysis is to mark sensitive data during program execution, which is called "taint". When sensitive data is used, its taint will also be passed to other related variables and functions, forming a taint chain. By tracing the taint chain, the use and security of sensitive data in the program can be determined.
[0071] Constraint Solver: A constraint solver is a computer program that solves problems with constraints. These problems can be mathematical, logical, or other types of problems, and usually involve multiple variables and multiple constraints. The main goal of a constraint solver is to find a combination of variable values that satisfies all the constraints, or to determine if such a solution exists. To do this, constraint solvers use a range of algorithms and techniques, including search algorithms, pruning algorithms, constraint propagation, and more.
[0072] It should be noted that the relevant information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for display, data for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties. For example, an interface is set between this system and the relevant user or organization. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or organization through the interface, and obtain relevant information after receiving the consent information fed back by the aforementioned user or organization.
[0073] The collected information involved in this disclosure is information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of the relevant data comply with the relevant laws, regulations and standards of the relevant countries and regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0074] The present invention is described below in conjunction with preferred implementation steps. Figure 1 is a flow chart of a method for detecting program attack risks provided in an embodiment of the present application, such as Figure 1 As shown, the method comprises the following steps:
[0075] Step S102, detecting the heap control information generated by the target program after inputting the target input information, wherein the target program is a program to be tested for the risk of hidden attack on the thread cache allocator, the target input information is input information that allows the target program to crash, and the heap control information is used to indicate the control behavior of the target program on the heap;
[0076] Step S104, generating a heap attack constraint and a pointer attack constraint for the target program when the heap control information indicates that the target program has a heap vulnerability;
[0077] Step S106, generating target attack information that satisfies the target path constraint, the heap block attack constraint, and the pointer attack constraint at the same time, wherein the target path constraint is used to describe the constraint condition at the path branch in the target program, the attack information that satisfies the heap block attack constraint is used to control the heap block in the input program, and the attack information that satisfies the pointer attack constraint is used to control the pointer in the input program;
[0078] Step S108: Use the target attack information to test whether the target program has a thread cache allocator hidden attack risk.
[0079] Through the above steps, when it is necessary to test whether the target program has a hidden attack risk of the thread cache allocator, the heap control information generated by the target program after the target input information that allows the target program to crash is detected. The heap control information can indicate the control behavior of the target program on the heap. After that, when the heap control information is used to indicate that the target program has a heap vulnerability, a heap attack constraint and a pointer attack constraint are generated for the target program, and target attack information that satisfies the target path constraint, the heap attack constraint and the pointer attack constraint is generated. Since the target path constraint can describe the constraint conditions at the path branch in the target program, the attack information that satisfies the heap attack constraint can control the heap in the input program, and the attack information that satisfies the pointer attack constraint can control the pointer in the input program. Therefore, by inputting the test target attack information into the target program, it is possible to efficiently test whether the target attack information can control the heap in the target program and whether it can control the pointer in the target program, thereby determining whether the target program has a hidden attack risk of the thread cache allocator, and solving the problem of low detection efficiency of program attack risks in the related technology. Thus, the technical effect of improving the detection efficiency of program attack risks is achieved.
[0080] In the technical solution provided in the above step S102, Figure 2 is a schematic diagram of a system for detecting program attack risks provided in accordance with an embodiment of the present application, such as Figure 2As shown, the program attack risk detection system is specifically a tcache stashing attack detection system, which consists of eight modules: a fuzzy testing module, a symbolic execution module, an API function hooking module, a heap vulnerability detection module, a heap block data controllability detection module, a key pointer controllability detection module, a constraint solver and an attack verification module. The tcache stashing attack detection system is used to execute the program attack risk detection method.
[0081] Optionally, in this embodiment, the target input information is input information that allows the target program to crash, and the target input information can be obtained by, but is not limited to, the fuzzy testing module. The fuzzy testing module performs fuzz testing on the target program, generates a binary input file that can cause the target program to crash, and determines the binary input file as the target input information.
[0082] Optionally, in this embodiment, the heap block control information generated by the target program after inputting the target input information can be detected by, but not limited to, an API function hooking module. The API function hooking module can be implemented by hooking API (Application Programming Interface) functions related to heap memory management such as malloc, calloc, realloc, and free. Key information is obtained by obtaining the value of a specific register at the function entry and return.
[0083] For example, when the malloc function returns, the function is hooked. The RAX register corresponding to the malloc function stores the requested heap block pointer. By reading the value in the RAX register, the starting address of the heap block data area can be obtained. Without changing the program behavior, the creation, writing, and release of the heap (heap block) are monitored. Through register data transfer, the parameters of related functions are obtained, such as the relevant data of the newly created heap block, including the starting address of the newly created heap block data area, the length of the newly created heap block data area, the pointer value of the newly created heap block address, the initialization data of the newly created heap block, and the adjacent block information of the newly created block.
[0084] In addition to monitoring the creation, writing, and release of heap blocks, the API function hooking module can also monitor the status of heap blocks and tcache, including whether the heap block is in a released state, whether it is on the tcache linked list, whether there are subsequent heap blocks, and the size of the released heap block on the tcache linked list and the number of released heap blocks on the linked list of that size.
[0085] In the scheme proposed in this application, in order to perform taint analysis and symbolic execution later, it is necessary to symbolize the external input. By hooking the API function of the external input, the introduction of symbolic variables is realized. For example, when the input of the read function needs to be symbolized, the function is hooked at the entrance of the read function, and the key information such as the address and length of the external data read in is obtained by reading the values of the RSI and RDX registers (under a 64-bit system), and then the data area is marked as a symbolic value. By introducing symbolic variables, the existing heap block write and release operations are monitored during the dynamic operation of the program, and the controllable data length is calculated. During the analysis process, each time the symbolized area is accessed, the symbolized area will be maintained and updated. Specifically, the memory area mapped by the program process will be obtained first, and then the memory area will be searched and traversed, and the values of the memory area will be read in sequence to determine whether its content is a symbolic value, and the starting address and length of the symbolized area will be gradually determined.
[0086] Optionally, in this embodiment, the heap block control information may include but is not limited to the information obtained by the above-mentioned API function hook module monitoring the creation, writing, release and other behaviors of the heap block, as well as the information obtained by monitoring the status of the heap block and tcache, memory allocation information and information used to indicate the pollution of the heap memory by external input.
[0087] Optionally, in this embodiment, the thread cache allocator hidden attack is a tcache stashing attack. The tcache stashing attack detection system can run the program attack risk detection method proposed in this application to detect whether the target program has the risk of being attacked by the thread cache allocator hidden attack.
[0088] In an exemplary embodiment, the stack block control information generated by the target program after the target input information is input can be detected in the following manner but is not limited to: extracting a stack block control function that controls the stack blocks from the control function of the target program; detecting the current execution stage of the stack block control function; when it is detected that the stack block control function is currently in the pre-execution stage and / or the post-execution stage, reading register information from the register corresponding to the stack block control function, wherein the register is used to store the stack block information corresponding to the stack block control function in the pre-execution stage and / or the post-execution stage; and generating the stack block control information according to the register information.
[0089] Optionally, in this embodiment, the heap block control function includes the above-mentioned heap memory management related API (Application Programming Interface) functions such as malloc, calloc, realloc and free.
[0090] Optionally, in this embodiment, when it is detected that the stack block control function is currently in the pre-execution stage and / or the post-execution stage, register information is read from the register corresponding to the stack block control function. The specific implementation method may be to perform a hook operation on the stack block control function through an API function hook module.
[0091] In the technical solution provided in the above step S104, the heap attack constraint may be, but is not limited to, generated by the heap data controllability detection module, and the pointer attack constraint may be, but is not limited to, generated by the key pointer controllability detection module.
[0092] In an exemplary embodiment, heap block attack constraints and pointer attack constraints can be generated for the target program in the following manner, but not limited to: detecting whether the target program has a heap block that satisfies a target heap block control condition, wherein the heap block that satisfies the target heap block control condition allows being controlled by the thread cache allocator hidden attack; in the case where it is detected that the target program has a target heap block that satisfies the target heap block control condition, constructing the heap block attack constraint according to the target heap block, wherein the attack information that satisfies the heap block attack constraint is used to control the target heap block in the target program; detecting whether the target pointer corresponding to the target heap block is a pointer that satisfies a pointer control condition, wherein the target pointer is a pointer in the target heap block used to point to the next heap block, and the pointer that satisfies the pointer control condition allows being controlled by information input from outside the target program; in the case where it is detected that the target pointer is a pointer that satisfies the pointer control condition, constructing the pointer attack constraint according to the target pointer, wherein the attack information that satisfies the pointer attack constraint is used to control the target pointer in the target program.
[0093] Optionally, in this embodiment, it is possible but not limited to detecting whether the target program has a heap block that satisfies the target heap block control condition through a heap block data controllability detection module, and when it is detected that the target program has a target heap block that satisfies the target heap block control condition, constructing the heap block attack constraint based on the target heap block.
[0094] In an exemplary embodiment, it is possible but not limited to detect whether the target program has a heap block that satisfies the target heap block control condition in the following manner: detect whether the target program has a heap block that simultaneously satisfies the first heap block control condition, the second heap block control condition and the third heap block control condition, wherein the heap block that satisfies the first heap block control condition is a heap block that has been released in the target program, the heap block that satisfies the second heap block control condition is a heap block that has been stored in the allocator linked list of the thread cache allocator in the target program, the allocator linked list is a linked list maintained by the thread cache allocator for storing the heap blocks that the thread cache allocator allows to be controlled, and the heap block that satisfies the third heap block control condition is a heap block that has a successor heap block in the target program; when it is detected that the target program has a heap block that simultaneously satisfies the first heap block control condition, the second heap block control condition and the third heap block control condition, it is determined that the target program has a heap block that satisfies the target heap block control condition.
[0095] Optionally, in this embodiment, the above-mentioned can be but not limited to detecting whether the target program has a heap block that meets the target heap block control condition through a heap block data controllability detection module. Specifically, the heap block data controllability detection module judges the heap block that may have a vulnerability. If the heap block meets: 1) the heap block is a released heap block (equivalent to the above-mentioned first heap block control condition); 2) the heap block is placed on the linked list of tcache (equivalent to the above-mentioned second heap block control condition); 3) the heap block must have a successor heap block (equivalent to the above-mentioned third heap block control condition); these three conditions, it can be considered that the heap block meets the requirements of the tcache stashing attack for heap block control, and then the heap block data controllability detection module is used to construct the tcache stashing attack attack constraint.
[0096] Optionally, in this embodiment, the heap attack constraint is a tcache stashing attack constraint.
[0097] In an exemplary embodiment, it is possible but not limited to detecting whether the target pointer corresponding to the target heap block is a pointer that satisfies the pointer control condition in the following manner: obtaining a tainted area in the target program that is affected by the symbolic seed file, wherein the tainted area is obtained by symbolically executing the target program using target input information as the symbolic seed file, and the target input information is input information that allows the target program to crash; when the tainted area includes the target pointer, determining that the target pointer is a pointer that satisfies the pointer control condition.
[0098] Optionally, in this embodiment, it is possible but not limited to detect whether the target pointer corresponding to the target heap block is a pointer that satisfies the pointer control condition through a key pointer controllability detection module. On the basis that the heap block data controllability detection module detects that the target heap block satisfies the heap block data controllability, it is further possible to detect whether the memory area where the key data pointer (next pointer, equivalent to the above-mentioned target pointer) of the target heap block is symbolized (i.e., determine whether the tainted area includes the target pointer) through a key pointer controllability detection module. If the key data pointer is symbolized, it means that the key data pointer can be controlled by external input, and an attack payload constraint (payload constraint) can be constructed in the current area, constraining the value of the next area to be any memory address that you want to apply for, and realizing arbitrary address writing to hijack the program control flow to the attack payload. In the process of arranging the attack payload, the symbolized area will be traversed first. If it has executable permission and the length of the symbolized area is greater than the length of the attack payload, the value of the area will be constrained to the value of the attack payload.
[0099] Optionally, in this embodiment, the pointer attack constraint is a payload constraint.
[0100] Optionally, in this embodiment, the tainted area is obtained by symbolically executing the target program using the target input information as the symbolic seed file, and the symbolic execution of the target program can be performed by, but is not limited to, a symbolic execution module. The symbolic execution module marks the binary input file output by the fuzz test module as symbolic tainted data, inputs it into the target program as a symbolic seed file, and drives the target program to perform dynamic symbolic execution. During the dynamic operation, all memory areas affected by the symbolic input are marked as tainted areas. By checking the symbolic properties of the memory, the tainted data can be tracked, analyzed and judged, and the labeled data can be provided for subsequent further detection and construction of data constraints. In addition, in order to improve the risk detection efficiency of the system, during the dynamic symbolic execution process, the symbolic execution module collects the running path of the target program during the dynamic operation. By generating path constraints and using guided symbolic execution technology, the heap overflow error position in the target program can be quickly located and the target program can be dynamically run to the location where the heap overflow vulnerability exists along the determined path pointed to by the symbolic seed file we constructed.
[0101] In an exemplary embodiment, before generating heap attack constraints and pointer attack constraints for the target program, the following methods may be used but are not limited to: detecting whether the target program has a first heap block vulnerability based on the heap block control information, wherein the first heap block vulnerability is used to indicate that the target program has a risk of write data overflowing from the heap block; detecting whether the target program has a second heap block vulnerability based on the heap block control information, wherein the second heap block vulnerability is used to indicate that the target program has a risk of continued use of released heap blocks; detecting whether the target program has a third heap block vulnerability based on the heap block control information, wherein the third heap block vulnerability is used to indicate that the target program has a risk of repeated release of heap blocks; in the case of detecting that the target program has the first heap block vulnerability, and / or the second heap block vulnerability, and / or the third heap block vulnerability, determining that the heap block control information is used to indicate that the target program has the heap block vulnerability.
[0102] Optionally, in this embodiment, it is possible but not limited to detect whether the target program has a first heap block vulnerability, a second heap block vulnerability and a third heap block vulnerability according to the heap block control information through a heap vulnerability detection module. The heap vulnerability detection module obtains the heap block control information obtained by the API function hooking module to hook the API function, and obtains the pollution of the heap memory area of the target program by the input of the external symbolic seed file through the symbol memory search algorithm. The first heap block vulnerability can be but not limited to a heap overflow vulnerability, the second heap block vulnerability can be but not limited to a UAF vulnerability, and the third heap block vulnerability can be but not limited to a Double Free vulnerability.
[0103] In an exemplary embodiment, it is possible but not limited to detecting whether the target program has a first heap block vulnerability according to the heap block control information in the following manner: detecting whether a heap block boundary of a heap block in the target program is exceeded by the written data according to the heap block control information; in the case of detecting that a heap block boundary of a heap block in the target program is exceeded by the written data, determining that the target program has a first heap block vulnerability;
[0104] It is possible but not limited to detecting whether the target program has a second heap block vulnerability according to the heap block control information in the following manner: detecting whether there is a dereference operation on a dangling pointer in the target program according to the heap block control information, wherein the dangling pointer is a pointer pointing to a released heap block or an uninitialized heap block, and the dereference operation is used to access the heap block position of the corresponding dangling pointer; when it is detected that the dereference operation on the dangling pointer exists in the target program, determining that the target program has a second heap block vulnerability;
[0105] It is possible but not limited to detecting whether the target program has a third heap block vulnerability based on the heap block control information in the following manner: obtaining a reference pointer of the heap block to be released according to the heap block control information, and detecting whether there is a historical pointer identical to the reference pointer in a historical pointer set, wherein the historical pointers in the historical pointer set are pointers corresponding to the heap blocks that have been currently released; when it is detected that there is a historical pointer identical to the reference pointer in the historical pointer set, it is determined that the target program has a third heap block vulnerability.
[0106] Optionally, in this embodiment, for heap overflow vulnerability detection: the heap vulnerability detection module checks whether the length of the symbolized data exceeds the boundary of the corresponding heap block, and determines whether the heap block overflows (i.e., detects whether the heap block boundary of the heap block in the target program is exceeded by the written data).
[0107] For UAF vulnerability detection: the heap vulnerability detection module detects the dangling pointer list, observes whether there are paths and operations in the target program that dereference the dangling pointer and attempt to access illegal memory (i.e., detects whether there is a dereference operation on the dangling pointer in the target program).
[0108] For Double Free vulnerability detection: The heap vulnerability detection module hooks the free function, and the heap blocks released by the program are stored in the freed heap block set free_chunk. Before the heap block is about to be released, the current heap block pointer (the reference pointer of the heap block to be released) is compared with the heap block pointer (historical pointer) in the released heap block set (historical pointer set). If they are the same, it means that there is a Double Free vulnerability. In order to prevent the released heap block from being allocated and then released, the program compares the current heap block with the heap block in the released heap block set after the new heap block is successfully created. If they are the same, the heap block information is deleted from the released heap block set.
[0109] In the technical solution provided in the above step S106, target attack information that satisfies the target path constraint, the heap attack constraint and the pointer attack constraint can be generated by a constraint solver, but is not limited to it. Constraint solver: The tcache stashing attack constraint (heap attack constraint), payload constraint (pointer attack constraint) and path constraint (target path constraint) established and output in the above process are combined and solved, and data constraint conditions of the test case are established. The constraint solver is used to solve the data constraint conditions to obtain a binary input file that can trigger the tcache stashing attack attack, and the binary input file that can trigger the tcache stashing attack attack is determined as the target attack information.
[0110] In the technical solution provided in the above step S108, the target attack information can be used to test whether the target program has a risk of hidden attack on the thread cache allocator through an attack test module, but is not limited to the attack test module. The attack test module dynamically runs the target program, uses the binary input file (target attack information) obtained by the constraint solver to attack the target program, verifies whether the hidden attack on the thread cache allocator is successful, and completes the corresponding report.
[0111] Optionally, in this embodiment, in order to better understand the process of detecting the above-mentioned program attack risks, the detection process of the above-mentioned program attack risks is described below in combination with an optional embodiment, but it is not used to limit the technical solution of the embodiment of the present application.
[0112] In this embodiment, a method for detecting program attack risks is provided. Figure 3 is a schematic diagram of a program attack risk detection process according to an embodiment of the present application, such as Figure 3 As shown, it mainly includes the following steps:
[0113] Step S301: Perform fuzz testing on the program to be detected to obtain a binary input file (equivalent to target input information) that can cause the target program to crash;
[0114] Step S302: using a symbolic execution module, marking the binary input file as symbolic tainted data, inputting it into the target program as a symbolic seed file, and driving the target program to perform dynamic symbolic execution;
[0115] Step S303: collecting and obtaining path constraints (equivalent to target path constraints) during the dynamic operation of the target program during the symbolic execution process;
[0116] Step S304: Obtain heap block information, tcache memory status information, memory allocation information, and pollution of heap memory by external input (equivalent to heap block control information) through the API function hook module;
[0117] Step S305: symbolically analyze the location where the program crashed, monitor the memory write and heap block release operations, and check whether there are heap block vulnerabilities such as heap overflow, UAF or Double Free;
[0118] Step S306: Determine the heap block that may have a vulnerability. If the heap block meets the following conditions: 1) the heap block is a released heap block (equivalent to the first heap block control condition); 2) the heap block is placed on the tcache linked list (equivalent to the second heap block control condition); 3) the heap block must have a successor heap block (equivalent to the third heap block control condition); if the three conditions are met, it can be considered that the heap block meets the requirements of the tcache stashing attack attack on the heap block control, and the tcachestashing attack attack constraint (equivalent to the heap block attack constraint) is output;
[0119] Step S307: Detect whether the memory area where the key data pointer (equivalent to the target pointer) is located is symbolized. If the pointer data is symbolized, it means that the pointer data is controllable, and a payload constraint (equivalent to a pointer attack constraint) can be constructed in the current area;
[0120] Step S308: The constraint solver combines and solves the tcache stashing attack constraint, the payload constraint, and the path constraint to obtain a binary input file (equivalent to target attack information) that can trigger the tcache stashing attack.
[0121] Step S309: Use the attack file generated by the constraint solver to perform attack simulation test, and complete the detection and analysis report of the tcache stashing attack (thread cache allocator hidden attack) risk of the target program.
[0122] The program attack risk detection method provided by the embodiment of the present application, when it is necessary to test whether the target program has a program with a hidden attack risk of a thread cache allocator, detect the heap control information generated by the target program after inputting the target input information that allows the target program to crash, the heap control information can indicate the control behavior of the target program on the heap, and then when the heap control information is used to indicate that the target program has a heap vulnerability, generate heap attack constraints and pointer attack constraints for the target program, and generate target attack information that satisfies the target path constraint, the heap attack constraint and the pointer attack constraint at the same time, because the target path constraint can describe the constraint conditions at the path branch in the target program, the attack information that satisfies the heap attack constraint can control the heap in the input program, and the attack information that satisfies the pointer attack constraint can control the pointer in the input program, so the target attack information is input into the target program to efficiently test whether the target attack information can control the heap in the target program and whether it can control the pointer in the target program, and then determine whether the target program has a hidden attack risk of a thread cache allocator, and solve the problem of low detection efficiency of program attack risks in the related art. Then the technical effect of improving the detection efficiency of program attack risks is achieved.
[0123] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0124] The embodiment of the present application also provides a program attack risk detection device. It should be noted that the program attack risk detection device of the embodiment of the present application can be used to execute the program attack risk detection method provided in the embodiment of the present application. The program attack risk detection device provided in the embodiment of the present application is introduced below.
[0125] Figure 4 Schematic diagram of a device for detecting program attack risks according to an embodiment of the present application. Figure 4 As shown, the device comprises:
[0126] A first detection module 402 is used to detect heap block control information generated by a target program after inputting target input information, wherein the target program is a program to be tested for a risk of hidden attack on a thread cache allocator, the target input information is input information that allows the target program to crash, and the heap block control information is used to indicate the control behavior of the target program on the heap block;
[0127] A first generating module 404 is used to generate a heap attack constraint and a pointer attack constraint for the target program when the heap control information indicates that the target program has a heap vulnerability;
[0128] A second generating module 406 is used to generate target attack information that satisfies the target path constraint, the heap block attack constraint, and the pointer attack constraint at the same time, wherein the target path constraint is used to describe the constraint condition at the path branch in the target program, the attack information that satisfies the heap block attack constraint is used to control the heap block in the input program, and the attack information that satisfies the pointer attack constraint is used to control the pointer in the input program;
[0129] The testing module 408 is used to use the target attack information to test whether the target program has a thread cache allocator hidden attack risk.
[0130] Optionally, in the program attack risk detection device provided in the embodiment of the present application, the first generating module includes:
[0131] A first detection unit is used to detect whether the target program has a heap block that meets the target heap block control condition, wherein the heap block that meets the target heap block control condition is allowed to be controlled by the thread cache allocator hidden attack;
[0132] A first construction unit is configured to construct the heap block attack constraint according to the target heap block when it is detected that the target program has a target heap block that satisfies the target heap block control condition, wherein the attack information that satisfies the heap block attack constraint is used to control the target heap block in the target program;
[0133] a second detection unit, configured to detect whether a target pointer corresponding to the target heap block is a pointer that satisfies a pointer control condition, wherein the target pointer is a pointer in the target heap block that points to a next heap block, and a pointer that satisfies the pointer control condition is allowed to be controlled by information input from outside the target program;
[0134] The second construction unit is used to construct the pointer attack constraint according to the target pointer when it is detected that the target pointer is a pointer that satisfies the pointer control condition, wherein the attack information that satisfies the pointer attack constraint is used to control the target pointer in the target program.
[0135] Optionally, in the program attack risk detection device provided in the embodiment of the present application, the first detection unit is further configured to:
[0136] Detecting whether the target program has a heap block that satisfies a first heap block control condition, a second heap block control condition, and a third heap block control condition at the same time, wherein the heap block that satisfies the first heap block control condition is a heap block that has been released in the target program, the heap block that satisfies the second heap block control condition is a heap block that has been stored in an allocator linked list of a thread cache allocator in the target program, the allocator linked list is a linked list maintained by the thread cache allocator and is used to store heap blocks that the thread cache allocator allows to control, and the heap block that satisfies the third heap block control condition is a heap block that has a successor heap block in the target program;
[0137] When it is detected that the target program has a heap that satisfies the first heap control condition, the second heap control condition, and the third heap control condition at the same time, it is determined that the target program has a heap that satisfies the target heap control condition.
[0138] Optionally, in the program attack risk detection device provided in the embodiment of the present application, the second detection unit is further used to:
[0139] Acquire a tainted area in the target program that is affected by the symbolic seed file, wherein the tainted area is obtained by symbolically executing the target program using target input information as the symbolic seed file, and the target input information is input information that allows the target program to crash;
[0140] In a case where the stain area includes the target pointer, the target pointer is determined to be a pointer that satisfies the pointer control condition.
[0141] Optionally, in the program attack risk detection device provided in the embodiment of the present application, the device further includes:
[0142] A second detection module is used to detect whether the target program has a first heap block vulnerability according to the heap block control information before generating the heap block attack constraint and the pointer attack constraint for the target program, wherein the first heap block vulnerability is used to indicate that the target program has a risk of overflowing written data from the heap block;
[0143] A third detection module is used to detect whether the target program has a second heap block vulnerability according to the heap block control information, wherein the second heap block vulnerability is used to indicate that the target program has a risk of continued use of a released heap block;
[0144] a fourth detection module, configured to detect whether the target program has a third heap block vulnerability according to the heap block control information, wherein the third heap block vulnerability is used to indicate that the target program has a risk of heap blocks being repeatedly released;
[0145] A determination module is used to determine that the heap block control information is used to indicate that the target program has the heap block vulnerability when it is detected that the target program has the first heap block vulnerability, and / or the second heap block vulnerability, and / or the third heap block vulnerability.
[0146] Optionally, in the program attack risk detection device provided in the embodiment of the present application,
[0147] The second detection module includes: a third detection unit, configured to detect whether a heap block boundary of a heap block in the target program is exceeded by the written data according to the heap block control information; a first determination unit, configured to determine that a first heap block vulnerability exists in the target program when it is detected that a heap block boundary of the heap block in the target program is exceeded by the written data;
[0148] The third detection module includes: a fourth detection unit, which is used to detect whether there is a dereference operation on a dangling pointer in the target program according to the heap block control information, wherein the dangling pointer is a pointer pointing to a released heap block or an uninitialized heap block, and the dereference operation is used to access the heap block position of the corresponding dangling pointer; a second determination unit, which is used to determine that the target program has a second heap block vulnerability when it is detected that there is a dereference operation on the dangling pointer in the target program;
[0149] The fourth detection module includes: a fifth detection unit, which is used to obtain a reference pointer of the heap block to be released according to the heap block control information, and detect whether there is a historical pointer identical to the reference pointer in the historical pointer set, wherein the historical pointer in the historical pointer set is a pointer corresponding to the heap block that has been currently released; and a third determination unit, which is used to determine that the target program has a third heap block vulnerability when it is detected that there is a historical pointer identical to the reference pointer in the historical pointer set.
[0150] Optionally, in the program attack risk detection device provided in the embodiment of the present application, the first detection module includes:
[0151] An extraction unit, used to extract a heap block control function capable of controlling a heap block from the control function of the target program;
[0152] A sixth detection unit, used to detect the current execution stage of the heap block control function;
[0153] a reading unit, configured to read register information from a register corresponding to the heap block control function when detecting that the heap block control function is currently in a pre-execution stage and / or a post-execution stage, wherein the register is used to store the heap block information corresponding to the heap block control function in the pre-execution stage and / or the post-execution stage;
[0154] A generating unit is used to generate the stack block control information according to the register information.
[0155] The program attack risk detection device provided by the embodiment of the present application, when it is necessary to test whether the target program has a program with a hidden attack risk of a thread cache allocator, detects the heap control information generated by the target program after inputting the target input information that allows the target program to crash, and the heap control information can indicate the control behavior of the target program on the heap. After that, when the heap control information is used to indicate that the target program has a heap vulnerability, the heap attack constraint and the pointer attack constraint are generated for the target program, and the target attack information that satisfies the target path constraint, the heap attack constraint and the pointer attack constraint is generated. Since the target path constraint can describe the constraint conditions at the path branch in the target program, the attack information that satisfies the heap attack constraint can control the heap in the input program, and the attack information that satisfies the pointer attack constraint can control the pointer in the input program. Therefore, the target attack information is input into the target program to efficiently test whether the target attack information can control the heap in the target program and whether it can control the pointer in the target program, thereby determining whether the target program has a hidden attack risk of a thread cache allocator, and solving the problem of low detection efficiency of program attack risks in the related art. Thus, the technical effect of improving the detection efficiency of program attack risks is achieved.
[0156] The program attack risk detection device includes a processor and a memory. The above units are stored in the memory as program units, and the processor executes the above program units stored in the memory to realize corresponding functions.
[0157] The processor contains a kernel, which calls the corresponding program unit from the memory. One or more kernels can be set, and the detection efficiency of program attack risks can be improved by adjusting kernel parameters.
[0158] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0159] An embodiment of the present invention provides a computer-readable storage medium on which a program is stored. When the program is executed by a processor, the program implements the method for detecting program attack risks.
[0160] An embodiment of the present invention provides a processor, which is used to run a program, wherein the method for detecting program attack risks is executed when the program is running.
[0161] Figure 5 is a schematic diagram of an electronic device according to an embodiment of the present application. Figure 5 As shown, an embodiment of the present invention provides an electronic device, the device includes a processor, a memory, and a program stored in the memory and executable on the processor, and the processor implements the following steps when executing the program:
[0162] Detecting heap control information generated by a target program after inputting target input information, wherein the target program is a program to be tested for a risk of hidden attack on a thread cache allocator, the target input information is input information that allows the target program to crash, and the heap control information is used to indicate the control behavior of the target program on the heap;
[0163] In a case where the heap control information is used to indicate that the target program has a heap vulnerability, generating a heap attack constraint and a pointer attack constraint for the target program;
[0164] Generate target attack information that satisfies the target path constraint, the heap block attack constraint, and the pointer attack constraint at the same time, wherein the target path constraint is used to describe the constraint condition at the path branch in the target program, the attack information that satisfies the heap block attack constraint is used to control the heap block in the input program, and the attack information that satisfies the pointer attack constraint is used to control the pointer in the input program;
[0165] The target attack information is used to test whether the target program has a thread cache allocator hidden attack risk.
[0166] Optionally, the processor may further implement the following steps when executing the program:
[0167] Detecting whether the target program has a heap block that meets a target heap block control condition, wherein the heap block that meets the target heap block control condition is allowed to be controlled by the thread cache allocator hidden attack;
[0168] In the case where it is detected that the target program has a target heap block that satisfies the target heap block control condition, constructing the heap block attack constraint according to the target heap block, wherein the attack information that satisfies the heap block attack constraint is used to control the target heap block in the target program;
[0169] Detecting whether a target pointer corresponding to the target heap block is a pointer that satisfies a pointer control condition, wherein the target pointer is a pointer in the target heap block that points to a next heap block, and a pointer that satisfies the pointer control condition allows being controlled by information input from outside the target program;
[0170] When it is detected that the target pointer is a pointer that satisfies the pointer control condition, the pointer attack constraint is constructed according to the target pointer, wherein the attack information that satisfies the pointer attack constraint is used to control the target pointer in the target program.
[0171] Optionally, the processor may further implement the following steps when executing the program:
[0172] Detecting whether the target program has a heap block that satisfies a first heap block control condition, a second heap block control condition, and a third heap block control condition at the same time, wherein the heap block that satisfies the first heap block control condition is a heap block that has been released in the target program, the heap block that satisfies the second heap block control condition is a heap block that has been stored in an allocator linked list of a thread cache allocator in the target program, the allocator linked list is a linked list maintained by the thread cache allocator and is used to store heap blocks that the thread cache allocator allows to control, and the heap block that satisfies the third heap block control condition is a heap block that has a successor heap block in the target program;
[0173] When it is detected that the target program has a heap that satisfies the first heap control condition, the second heap control condition, and the third heap control condition at the same time, it is determined that the target program has a heap that satisfies the target heap control condition.
[0174] Optionally, the processor may further implement the following steps when executing the program:
[0175] Acquire a tainted area in the target program that is affected by the symbolic seed file, wherein the tainted area is obtained by symbolically executing the target program using target input information as the symbolic seed file, and the target input information is input information that allows the target program to crash;
[0176] In a case where the stain area includes the target pointer, the target pointer is determined to be a pointer that satisfies the pointer control condition.
[0177] Optionally, the processor may further implement the following steps when executing the program:
[0178] Before generating the heap attack constraint and the pointer attack constraint for the target program, detecting whether the target program has a first heap block vulnerability according to the heap block control information, wherein the first heap block vulnerability is used to indicate that the target program has a risk of overflowing written data from the heap block;
[0179] Detecting whether the target program has a second heap block vulnerability according to the heap block control information, wherein the second heap block vulnerability is used to indicate that the target program has a risk that a released heap block continues to be used;
[0180] Detecting whether the target program has a third heap block vulnerability according to the heap block control information, wherein the third heap block vulnerability is used to indicate that the target program has a risk of heap blocks being repeatedly released;
[0181] When it is detected that the target program has the first heap block vulnerability, and / or the second heap block vulnerability, and / or the third heap block vulnerability, it is determined that the heap block control information is used to indicate that the target program has the heap block vulnerability.
[0182] Optionally, the processor may further implement the following steps when executing the program, wherein the detecting whether the target program has a first heap block vulnerability according to the heap block control information includes: detecting whether a heap block boundary of a heap block in the target program is exceeded by the written data according to the heap block control information; and determining that the target program has a first heap block vulnerability when it is detected that the heap block boundary of the heap block in the target program is exceeded by the written data;
[0183] The detecting whether the target program has a second heap block vulnerability according to the heap block control information includes: detecting whether there is a dereference operation on a dangling pointer in the target program according to the heap block control information, wherein the dangling pointer is a pointer pointing to a released heap block or an uninitialized heap block, and the dereference operation is used to access the heap block position of the corresponding dangling pointer; when it is detected that the dereference operation on the dangling pointer exists in the target program, determining that the target program has a second heap block vulnerability;
[0184] The detecting whether the target program has a third heap block vulnerability according to the heap block control information includes: obtaining a reference pointer of the heap block to be released according to the heap block control information, and detecting whether there is a history pointer identical to the reference pointer in a history pointer set, wherein the history pointers in the history pointer set are pointers corresponding to the heap blocks that have been currently released; when it is detected that there is a history pointer identical to the reference pointer in the history pointer set, it is determined that the target program has a third heap block vulnerability.
[0185] Optionally, the processor may further implement the following steps when executing the program:
[0186] Extracting a heap block control function capable of controlling the heap block from the control function of the target program;
[0187] Detecting the current execution phase of the heap block control function;
[0188] In the case of detecting that the heap block control function is currently in a pre-execution stage and / or a post-execution stage, reading register information from a register corresponding to the heap block control function, wherein the register is used to store the heap block information corresponding to the heap block control function in the pre-execution stage and / or the post-execution stage;
[0189] The stack block control information is generated according to the register information.
[0190] The devices in this article can be servers, PCs, PADs, mobile phones, etc.
[0191] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program for initializing the following method steps:
[0192] Detecting heap control information generated by a target program after inputting target input information, wherein the target program is a program to be tested for a risk of hidden attack on a thread cache allocator, the target input information is input information that allows the target program to crash, and the heap control information is used to indicate the control behavior of the target program on the heap;
[0193] In a case where the heap control information is used to indicate that the target program has a heap vulnerability, generating a heap attack constraint and a pointer attack constraint for the target program;
[0194] Generate target attack information that satisfies the target path constraint, the heap block attack constraint, and the pointer attack constraint at the same time, wherein the target path constraint is used to describe the constraint condition at the path branch in the target program, the attack information that satisfies the heap block attack constraint is used to control the heap block in the input program, and the attack information that satisfies the pointer attack constraint is used to control the pointer in the input program;
[0195] The target attack information is used to test whether the target program has a thread cache allocator hidden attack risk.
[0196] Optionally, the above computer program product, when executed on a data processing device, is suitable for executing a program for initializing the following method steps:
[0197] Detecting whether the target program has a heap block that meets a target heap block control condition, wherein the heap block that meets the target heap block control condition is allowed to be controlled by the thread cache allocator hidden attack;
[0198] In the case where it is detected that the target program has a target heap block that satisfies the target heap block control condition, constructing the heap block attack constraint according to the target heap block, wherein the attack information that satisfies the heap block attack constraint is used to control the target heap block in the target program;
[0199] Detecting whether a target pointer corresponding to the target heap block is a pointer that satisfies a pointer control condition, wherein the target pointer is a pointer in the target heap block that points to a next heap block, and a pointer that satisfies the pointer control condition allows being controlled by information input from outside the target program;
[0200] When it is detected that the target pointer is a pointer that satisfies the pointer control condition, the pointer attack constraint is constructed according to the target pointer, wherein the attack information that satisfies the pointer attack constraint is used to control the target pointer in the target program.
[0201] Optionally, the above computer program product, when executed on a data processing device, is suitable for executing a program for initializing the following method steps:
[0202] Detecting whether the target program has a heap block that satisfies a first heap block control condition, a second heap block control condition, and a third heap block control condition at the same time, wherein the heap block that satisfies the first heap block control condition is a heap block that has been released in the target program, the heap block that satisfies the second heap block control condition is a heap block that has been stored in an allocator linked list of a thread cache allocator in the target program, the allocator linked list is a linked list maintained by the thread cache allocator and is used to store heap blocks that the thread cache allocator allows to control, and the heap block that satisfies the third heap block control condition is a heap block that has a successor heap block in the target program;
[0203] When it is detected that the target program has a heap that satisfies the first heap control condition, the second heap control condition, and the third heap control condition at the same time, it is determined that the target program has a heap that satisfies the target heap control condition.
[0204] Optionally, the above computer program product, when executed on a data processing device, is suitable for executing a program for initializing the following method steps:
[0205] Acquire a tainted area in the target program that is affected by the symbolic seed file, wherein the tainted area is obtained by symbolically executing the target program using target input information as the symbolic seed file, and the target input information is input information that allows the target program to crash;
[0206] In a case where the stain area includes the target pointer, the target pointer is determined to be a pointer that satisfies the pointer control condition.
[0207] Optionally, the above computer program product, when executed on a data processing device, is suitable for executing a program for initializing the following method steps:
[0208] Before generating the heap attack constraint and the pointer attack constraint for the target program, detecting whether the target program has a first heap block vulnerability according to the heap block control information, wherein the first heap block vulnerability is used to indicate that the target program has a risk of overflowing written data from the heap block;
[0209] Detecting whether the target program has a second heap block vulnerability according to the heap block control information, wherein the second heap block vulnerability is used to indicate that the target program has a risk that a released heap block continues to be used;
[0210] Detecting whether the target program has a third heap block vulnerability according to the heap block control information, wherein the third heap block vulnerability is used to indicate that the target program has a risk of heap blocks being repeatedly released;
[0211] When it is detected that the target program has the first heap block vulnerability, and / or the second heap block vulnerability, and / or the third heap block vulnerability, it is determined that the heap block control information is used to indicate that the target program has the heap block vulnerability.
[0212] Optionally, the computer program product, when executed on a data processing device, is suitable for executing a program that is initialized to have the following method steps, wherein the detecting whether the target program has a first heap block vulnerability according to the heap block control information comprises: detecting whether a heap block boundary of a heap block in the target program is exceeded by the written data according to the heap block control information; and determining that the target program has a first heap block vulnerability when it is detected that the heap block boundary of the heap block in the target program is exceeded by the written data;
[0213] The detecting whether the target program has a second heap block vulnerability according to the heap block control information includes: detecting whether there is a dereference operation on a dangling pointer in the target program according to the heap block control information, wherein the dangling pointer is a pointer pointing to a released heap block or an uninitialized heap block, and the dereference operation is used to access the heap block position of the corresponding dangling pointer; when it is detected that the dereference operation on the dangling pointer exists in the target program, determining that the target program has a second heap block vulnerability;
[0214] The detecting whether the target program has a third heap block vulnerability according to the heap block control information includes: obtaining a reference pointer of the heap block to be released according to the heap block control information, and detecting whether there is a history pointer identical to the reference pointer in a history pointer set, wherein the history pointers in the history pointer set are pointers corresponding to the heap blocks that have been currently released; when it is detected that there is a history pointer identical to the reference pointer in the history pointer set, it is determined that the target program has a third heap block vulnerability.
[0215] Optionally, the above computer program product, when executed on a data processing device, is suitable for executing a program for initializing the following method steps:
[0216] Extracting a heap block control function capable of controlling the heap block from the control function of the target program;
[0217] Detecting the current execution phase of the heap block control function;
[0218] In the case of detecting that the heap block control function is currently in a pre-execution stage and / or a post-execution stage, reading register information from a register corresponding to the heap block control function, wherein the register is used to store the heap block information corresponding to the heap block control function in the pre-execution stage and / or the post-execution stage;
[0219] The stack block control information is generated according to the register information.
[0220] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0221] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0222] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0223] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0224] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0225] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0226] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0227] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0228] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0229] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. A method for detecting program attack risks, characterized in that: include: Detecting heap control information generated by a target program after inputting target input information, wherein the target program is a program to be tested for a risk of hidden attack on a thread cache allocator, the target input information is input information that allows the target program to crash, and the heap control information is used to indicate the control behavior of the target program on the heap; In a case where the heap control information is used to indicate that the target program has a heap vulnerability, generating a heap attack constraint and a pointer attack constraint for the target program; Generate target attack information that satisfies the target path constraint, the heap block attack constraint, and the pointer attack constraint at the same time, wherein the target path constraint is used to describe the constraint condition at the path branch in the target program, the attack information that satisfies the heap block attack constraint is used to control the heap block in the input program, and the attack information that satisfies the pointer attack constraint is used to control the pointer in the input program; The target attack information is used to test whether the target program has a thread cache allocator hidden attack risk.
2. The method according to claim 1, characterized in that: The generating of the heap attack constraint and the pointer attack constraint for the target program includes: Detecting whether the target program has a heap block that meets a target heap block control condition, wherein the heap block that meets the target heap block control condition is allowed to be controlled by the thread cache allocator hidden attack; In the case where it is detected that the target program has a target heap block that satisfies the target heap block control condition, constructing the heap block attack constraint according to the target heap block, wherein the attack information that satisfies the heap block attack constraint is used to control the target heap block in the target program; Detecting whether a target pointer corresponding to the target heap block is a pointer that satisfies a pointer control condition, wherein the target pointer is a pointer in the target heap block that points to a next heap block, and a pointer that satisfies the pointer control condition allows being controlled by information input from outside the target program; When it is detected that the target pointer is a pointer that satisfies the pointer control condition, the pointer attack constraint is constructed according to the target pointer, wherein the attack information that satisfies the pointer attack constraint is used to control the target pointer in the target program.
3. The method according to claim 2, characterized in that The detecting whether the target program has a heap block that meets the target heap block control condition includes: Detecting whether the target program has a heap block that satisfies a first heap block control condition, a second heap block control condition, and a third heap block control condition at the same time, wherein the heap block that satisfies the first heap block control condition is a heap block that has been released in the target program, the heap block that satisfies the second heap block control condition is a heap block that has been stored in an allocator linked list of a thread cache allocator in the target program, the allocator linked list is a linked list maintained by the thread cache allocator and is used to store heap blocks that the thread cache allocator allows to control, and the heap block that satisfies the third heap block control condition is a heap block that has a successor heap block in the target program; When it is detected that the target program has a heap that satisfies the first heap control condition, the second heap control condition, and the third heap control condition at the same time, it is determined that the target program has a heap that satisfies the target heap control condition.
4. The method according to claim 2, characterized in that: The detecting whether the target pointer corresponding to the target heap block is a pointer that satisfies the pointer control condition includes: Acquire a tainted area in the target program that is affected by the symbolic seed file, wherein the tainted area is obtained by symbolically executing the target program using target input information as the symbolic seed file, and the target input information is input information that allows the target program to crash; In a case where the stain area includes the target pointer, the target pointer is determined to be a pointer that satisfies the pointer control condition.
5. The method according to claim 1, characterized in that Before generating the heap attack constraint and the pointer attack constraint for the target program, the method further includes: Detecting whether the target program has a first heap block vulnerability according to the heap block control information, wherein the first heap block vulnerability is used to indicate that the target program has a risk of overflowing written data from the heap block; Detecting whether the target program has a second heap block vulnerability according to the heap block control information, wherein the second heap block vulnerability is used to indicate that the target program has a risk that a released heap block continues to be used; Detecting whether the target program has a third heap block vulnerability according to the heap block control information, wherein the third heap block vulnerability is used to indicate that the target program has a risk of repeated heap block release; When it is detected that the target program has the first heap block vulnerability, and / or the second heap block vulnerability, and / or the third heap block vulnerability, it is determined that the heap block control information is used to indicate that the target program has the heap block vulnerability.
6. The method according to claim 5, characterized in that The detecting whether the target program has a first heap block vulnerability according to the heap block control information includes: detecting whether a heap block boundary of a heap block in the target program is exceeded by the written data according to the heap block control information; if it is detected that the heap block boundary of the heap block in the target program is exceeded by the written data, determining that the target program has a first heap block vulnerability; The detecting whether the target program has a second heap block vulnerability according to the heap block control information includes: detecting whether there is a dereference operation on a dangling pointer in the target program according to the heap block control information, wherein the dangling pointer is a pointer pointing to a released heap block or an uninitialized heap block, and the dereference operation is used to access the heap block position of the corresponding dangling pointer; when it is detected that the dereference operation on the dangling pointer exists in the target program, determining that the target program has a second heap block vulnerability; The detecting whether the target program has a third heap block vulnerability according to the heap block control information includes: obtaining a reference pointer of the heap block to be released according to the heap block control information, and detecting whether there is a history pointer identical to the reference pointer in a history pointer set, wherein the history pointers in the history pointer set are pointers corresponding to the heap blocks that have been currently released; when it is detected that there is a history pointer identical to the reference pointer in the history pointer set, it is determined that the target program has a third heap block vulnerability.
7. The method according to claim 1, characterized in that The detection target program generates the heap block control information after inputting the target input information, including: Extracting a heap block control function capable of controlling the heap block from the control function of the target program; Detecting the current execution phase of the heap block control function; In the case of detecting that the heap block control function is currently in a pre-execution stage and / or a post-execution stage, reading register information from a register corresponding to the heap block control function, wherein the register is used to store the heap block information corresponding to the heap block control function in the pre-execution stage and / or the post-execution stage; The stack block control information is generated according to the register information.
8. A device for detecting program attack risks, characterized in that: include: A first detection module is used to detect heap block control information generated by a target program after inputting target input information, wherein the target program is a program to be tested for a risk of hidden attack on a thread cache allocator, the target input information is input information that allows the target program to crash, and the heap block control information is used to indicate the control behavior of the target program on the heap block; A first generating module, configured to generate a heap attack constraint and a pointer attack constraint for the target program when the heap control information indicates that the target program has a heap vulnerability; A second generation module is used to generate target attack information that satisfies a target path constraint, the heap block attack constraint, and the pointer attack constraint at the same time, wherein the target path constraint is used to describe the constraint condition at the path branch in the target program, the attack information that satisfies the heap block attack constraint is used to control the heap block in the input program, and the attack information that satisfies the pointer attack constraint is used to control the pointer in the input program; A testing module is used to use the target attack information to test whether the target program has a thread cache allocator hidden attack risk.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method according to any one of claims 1 to 7 when executed.
10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 7 through the computer program.
