Program reinforcement method and device, electronic equipment, storage medium and computer product
By introducing randomization coefficients into the software protection scheme, dynamically adjusting the compilation and reinforcement of active programs and binary rewriting of passive programs, the problem that the existing technology cannot dynamically adjust the protection strength according to the application scenarios is solved, and the optimal balance of security and performance is achieved.
Patent Information
- Application Number
- CN202411894473.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2025-04-11
AI Technical Summary
Existing software protection solutions cannot dynamically adjust the protection strength according to the specific application scenarios of the program, resulting in insufficient protection in high-security demand scenarios, and performance losses will be caused by excessive protection in high-performance demand scenarios.
By introducing a randomization coefficient, we can dynamically balance the security indicators and performance indicators of the target program in different application scenarios, and compile and reinforce the active program and binary rewrite and reinforce the passive program based on the randomization coefficient.
It realizes flexibly adjusting the program protection strength according to specific application scenarios, enhancing the protection strength in high-security demand scenarios, and reducing performance overhead in high-performance demand scenarios, effectively balancing the program's security and operating performance.
Smart Images

Figure CN119808033A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer program security, and in particular to a program reinforcement method, device, electronic device, storage medium and computer product. Background Art
[0002] With the rapid development of information technology, software systems have been widely used in various fields of social life. Software security issues are becoming increasingly prominent, and various attack methods targeting software vulnerabilities are emerging in an endless stream, such as stack overflow, return-oriented programming and other attack methods. These attacks may lead to the hijacking of program control flow, resulting in serious consequences such as information leakage and system crash. Therefore, how to effectively protect software systems from malicious attacks has become an important issue that needs to be solved urgently.
[0003] At present, common software protection solutions mainly adopt static reinforcement. For example, by inserting security check code in the compilation stage to defend against stack overflow attacks; or filling random instructions in binary programs to prevent return-oriented programming attacks. These solutions improve software security by implanting fixed protection measures in the program.
[0004] However, existing software protection solutions often adopt a unified reinforcement strategy and cannot dynamically adjust the protection strength according to the specific application scenarios of the program. This leads to insufficient protection in scenarios with high security requirements, and obvious performance loss due to excessive protection in scenarios with high performance requirements. Summary of the invention
[0005] The present application provides a program reinforcement method, device, electronic device, storage medium and computer product, which can enhance the protection strength by increasing the randomization coefficient in high security requirement scenarios, and reduce the performance overhead by reducing the randomization coefficient in high performance requirement scenarios, effectively solving the technical problem that the existing technology cannot balance program security and operating performance.
[0006] In a first aspect of the present application, a program reinforcement method is provided, comprising: Acquire a target program to be reinforced, wherein the target program includes an active program and / or a passive program; Obtaining a randomization coefficient of the target program, where the randomization coefficient is used to balance a safety index and a performance index when the target program is running in an application scenario; In the case where the target program includes an active program, compiling the active program based on a randomization coefficient corresponding to the active program to obtain a reinforced first target program; In the case where the target program includes a passive program, the passive program is binary rewritten based on a randomization coefficient corresponding to the passive program to obtain a reinforced second target program.
[0007] The present application also provides a program reinforcement device, comprising: A target program acquisition module, used to acquire a target program to be reinforced, wherein the target program includes an active program and / or a passive program; A randomization coefficient acquisition module, used to acquire a randomization coefficient of the target program, wherein the randomization coefficient is used to balance the safety index and the performance index of the target program when it is running in an application scenario; An active program reinforcement module, used for compiling the active program based on a randomization coefficient corresponding to the active program to obtain a reinforced first target program when the target program includes the active program; The passive program reinforcement module is used to perform binary rewriting on the passive program based on the randomization coefficient corresponding to the passive program when the target program includes the passive program, so as to obtain a reinforced second target program.
[0008] In a second aspect of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, any one of the program reinforcement methods described above is implemented.
[0009] In a third aspect of the present application, a non-transitory computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the program hardening method described in any one of the above is implemented.
[0010] In a fourth aspect of the present application, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the program hardening methods described above.
[0011] In summary, one or more technical solutions provided in this application have at least the following technical effects or advantages: By introducing a randomization coefficient to dynamically balance the security and performance indicators of the target program in different application scenarios, and based on the randomization coefficient, the active program is compiled and reinforced and the passive program is binary rewritten and reinforced, thereby achieving the purpose of flexibly adjusting the program protection strength according to the specific application scenario. Compared with the unified reinforcement strategy adopted in the prior art, this application can enhance the protection strength by increasing the randomization coefficient in high security demand scenarios, and reduce the performance overhead by reducing the randomization coefficient in high performance demand scenarios, effectively solving the technical problem that the prior art cannot balance program security and operating performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the technical solutions in the present application or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0013] Figure 1 It is a schematic diagram of an implementation environment of a solution provided in an embodiment of the present application; Figure 2 It is a flowchart of the program reinforcement method provided in the embodiment of the present application; Figure 3 This is a schematic diagram of the comparison of the spatial layout before and after source code reinforcement provided by an embodiment of the present application; Figure 4 It is a comparative schematic diagram before and after the invalid instruction filling without source code reinforcement provided by the embodiment of the present application; Figure 5 This is a schematic diagram of a non-source code reinforced return address and stack base address encryption comparison provided by an embodiment of the present application Figure 6 This is a comparison diagram before and after the rearrangement of the source code-free reinforcement function provided in an embodiment of the present application; Figure 7 It is a structural schematic diagram of a program reinforcement device provided in an embodiment of the present application; Figure 8 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0014] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in this application. Obviously, the described embodiments are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0015] In order to clearly describe the technical solutions of the embodiments of the present application, some terms and technologies involved in the embodiments of the present application are briefly introduced below: (1) Compiler instrumentation technology: refers to the technology of inserting additional monitoring or control code into the program by modifying or adding code during the program compilation process. In this application, it is mainly used to achieve security reinforcement during the compilation stage.
[0016] (2) Binary rewriting technology: refers to the technology of directly modifying and optimizing binary executable files without the need for source code. In this application, it is used to implement security reinforcement of programs without source code.
[0017] (3) LLVM (Low Level Virtual Machine): is an open source compiler infrastructure project that provides a set of reusable compiler and toolchain technologies. It is used as the basic platform for implementing compiler instrumentation in this application.
[0018] (3) Return-Oriented Programming (ROP): It is an advanced attack technique in which the attacker controls the return address of the program and connects multiple existing code fragments to achieve the attack purpose.
[0019] (4) Jump-Oriented Programming (JOP): It is an attack technique based on code reuse, which implements the attack by controlling the target address of indirect jump instructions.
[0020] (5) Use After Free (UAF): It is a memory vulnerability that refers to a security issue caused by a program continuing to access a memory area after releasing the memory.
[0021] (6) Stack Randomization: refers to a technique that increases the difficulty of attack by changing the memory layout of the program stack. It includes both static and dynamic implementations.
[0022] (7) Heap Randomization: refers to the technology of preventing heap-related attacks by randomizing the heap memory allocation location, which also includes static and dynamic implementation methods.
[0023] (8) No Operation (NOP): A CPU instruction that does not perform any operation and is used to implement instruction filling in this application.
[0024] (9) Address Space Layout Randomization (ASLR): It is a security technology that increases the difficulty of attack by randomizing the process address space.
[0025] (10) Memory Allocation (malloc): This is a function used in C / C++ programs to dynamically allocate memory. It serves as an important entry point for heap operations in this application.
[0026] (11) Base Pointer Register (RBP): A register used to indicate the base address of the current stack frame. It is an important object for implementing stack frame protection.
[0027] (12) Stack Pointer Register (RSP): A register used to indicate the current top position of the stack. It is an important operation object for implementing stack randomization.
[0028] (8) Code fragment (Gadget): A short code sequence used in ROP / JOP attacks, usually ending with a ret or jmp instruction.
[0029] (14) Complex Instruction Set Computing (CISC): The instruction set type used by the x86 architecture, characterized by a large number of instructions and a complex format.
[0030] (15) Reduced Instruction Set Computing (RISC): The instruction set type used by the ARM architecture, characterized by a small number of instructions and a unified format.
[0031] With the rapid development of information technology, software systems have been deeply integrated into all areas of social life, and software security issues have become increasingly prominent. Various attack methods targeting software vulnerabilities have emerged in an endless stream, such as stack overflow, return-oriented programming and other attack methods. These attacks may lead to the hijacking of program control flow, resulting in serious consequences such as information leakage and system crash.
[0032] Existing software protection solutions mainly use static reinforcement methods, such as inserting security check code at the compilation stage to defend against stack overflow attacks, or filling random instructions in binary programs to prevent return-oriented programming attacks. These protection measures mainly focus on source code level optimization and security checks, and improve software security by implanting fixed protection measures in the program.
[0033] However, since the source code of commercial software and third-party libraries is usually not available, it is difficult to effectively protect such software with source code-based security hardening methods. At the same time, although inserting a large amount of security detection code during compilation improves the security of the program, it also brings significant performance overhead, which is particularly obvious in resource-constrained environments.
[0034] More importantly, existing software protection solutions often adopt a unified reinforcement strategy and cannot dynamically adjust the protection strength according to the specific application scenarios of the program. This leads to insufficient protection in scenarios with high security requirements, and excessive protection in scenarios with high performance requirements will cause significant performance loss. In addition, these security reinforcement methods often only provide protection for specific types of vulnerabilities or attack methods, lack comprehensiveness and flexibility, and are difficult to cope with increasingly complex and diverse attack methods. Faced with the widespread predictability problems in the program's memory management and execution process, existing technologies cannot effectively prevent the risk of attackers hijacking the program control flow by precisely constructing malicious inputs and then performing illegal operations.
[0035] In response to the above technical problems, this application provides a technical solution for program reinforcement, which dynamically balances the security and performance indicators of the target program in different application scenarios by introducing a randomization coefficient, and performs compilation reinforcement on the active program and binary rewriting reinforcement on the passive program based on the randomization coefficient. This solution can not only implement compilation-level reinforcement for programs with source code, but also effectively protect programs without source code through binary rewriting technology, overcoming the limitation of existing technologies that rely on source code; At the same time, through the dynamic adjustment mechanism of the randomization coefficient, the protection strength can be flexibly adjusted according to the specific application scenarios of the program. In scenarios with high security requirements, the protection strength can be enhanced by increasing the randomization coefficient. In scenarios with high performance requirements, the performance overhead can be reduced by reducing the randomization coefficient, thereby effectively balancing the security and operating performance of the program. In addition, the solution can effectively prevent various attack methods including stack overflow and return-oriented programming through multi-level reinforcement measures, providing comprehensive security protection capabilities and solving the problem of insufficient coverage of existing technologies.
[0036] Please refer to Figure 1 , which shows a schematic diagram of a solution implementation environment provided by an embodiment of the present application. The solution implementation environment can be implemented as a program reinforcement system, which can include a program reinforcement device and an application terminal, and the application terminal can be directly or indirectly connected to the program reinforcement device through a wired or wireless network.
[0037] Program reinforcement equipment refers to a computing device that can perform security reinforcement processing on computer programs. In the embodiment of the present application, it can be understood as a general computing device including a processor and a memory, or it can be a dedicated program security reinforcement server. The program reinforcement equipment is used to receive the target program to be reinforced, compile and reinforce the target program or perform binary rewrite reinforcement based on the randomization coefficient, and generate a reinforced program.
[0038] Application terminals refer to various computing devices that can run computer programs that have been security-hardened. In the embodiments of this application, they can be understood as computing devices based on different processor architectures, including but not limited to: general-purpose computers and servers based on the x86 architecture, and embedded devices and IoT devices based on the ARM architecture. The application terminal is used to run programs that have been hardened by the program hardening device, and during the program running process, the security parameters of the program are dynamically adjusted based on the built-in randomization function.
[0039] Among them, application terminals based on the x86 architecture use a complex instruction set to process program instructions, have more general registers, and use a combination of page tables and segment tables to convert memory addresses, which are mainly suitable for general-purpose computers, servers, etc. Application terminals based on the ARM architecture use a reduced instruction set to process program instructions, have a dedicated stack pointer register and link register, and use page tables for virtual memory management, which are mainly suitable for embedded devices, IoT devices, and other scenarios.
[0040] When running the hardened program, application terminals with different architectures can implement instruction filling and adjustment to adapt to different instruction sets based on their own hardware characteristics, randomize the stack according to the characteristics of the register structure, and randomize the heap space for specific memory management mechanisms. This architecture-independent implementation method enables the hardened program to maintain the same security protection effect on different hardware platforms.
[0041] In an optional interaction mode, the application terminal obtains the reinforced program directly from the program reinforcement device through the network. The application terminal first sends a program reinforcement request to the program reinforcement device, which contains the target program to be reinforced. After receiving the request, the program reinforcement device reinforces the target program and returns the reinforced program to the application terminal. In this process, the program reinforcement device can also automatically select an adaptive reinforcement strategy based on the hardware architecture characteristics of the application terminal to ensure that the reinforced program can run normally on the application terminal.
[0042] In another optional interaction mode, the application terminal loads the hardened program from the local storage medium. In this case, the program hardening device will pre-harden the target program and save the hardened program and its configuration information in the local storage medium of the application terminal. The application terminal can directly load these programs locally without having to interact with the program hardening device every time. This method is suitable for scenarios where the network connection is unstable or the program startup performance requirements are high.
[0043] In another optional interaction mode, the application terminal uses the integrated program hardening function to directly harden the target program locally. In this mode, the program hardening device deploys the core functional modules required for hardening to the application terminal. The application terminal can independently complete the program hardening process and dynamically adjust the hardening parameters according to changes in the operating environment. This method not only ensures the independence of the hardening process, but also provides more flexible hardening strategy adjustment capabilities.
[0044] In addition, during the program running process, the application terminal can also feedback the program running status and security event information to the program reinforcement device. The program reinforcement device can optimize the reinforcement strategy based on this information and push the optimized parameters to the application terminal, thereby achieving continuous improvement of the reinforcement effect. This two-way interactive mechanism enables the security reinforcement solution of this application to continuously adapt to new security threats and maintain a strong protection capability.
[0045] exist Figure 1 Based on the system architecture, please refer to Figure 2 , Figure 2 This is a flowchart of a program reinforcement method provided by an embodiment of the present application. The method can be implemented by a computer program, can be implemented by a single-chip microcomputer, or can be run on a program reinforcement system based on the von Neumann system. The computer program can be integrated into an application or run as an independent tool application. Specifically, the method may include the following steps: S101. Obtain a target program to be reinforced, where the target program includes an active program and / or a passive program.
[0046] The target program refers to a computer program that needs to be security-hardened. In the embodiments of the present application, it can be understood as an executable program code containing an active program and / or a passive program. Among them, an active program refers to a program with complete source code, such as an independent application developed in C / C++ language; a passive program refers to a program that only has a binary file and cannot obtain the source code, such as commercial software or a third-party program library. The target program is used to perform specific functions on the application terminal, and obtains enhanced security protection capabilities through the processing of the program hardening device, so that it can resist various security attacks while maintaining its original functions.
[0047] Specifically, the program hardening device can obtain the target program in a variety of ways. For active programs, the source code file of the program can be directly obtained through the interface of the program development environment, or the source code package can be obtained through network transmission, storage medium copy, etc. For passive programs, it can be achieved by obtaining the binary files of the program, which may be executable files, dynamic link libraries or other forms of program files.
[0048] During the acquisition process, the program hardening device will conduct a preliminary analysis of the target program to identify whether it contains source code, and classify it as an active program or a passive program accordingly. If the target program contains both source code and non-source code parts (for example, a self-developed program that uses a third-party library), the program hardening device will mark it as a mixed type to prepare for the subsequent use of different hardening strategies; for example, a correlation analysis is performed on the active program in the mixed type to obtain a randomization coefficient, and a correlation analysis is performed on the passive program in the mixed type to obtain another different randomization coefficient.
[0049] The above-mentioned acquisition and classification method based on program type enables the subsequent reinforcement process to select the most suitable reinforcement strategy for different types of programs. For active programs, the instrumentation technology during compilation can be used to achieve deeper security reinforcement; for passive programs, the necessary security protection can be achieved through binary rewriting technology. The above-mentioned differentiated processing methods not only improve the flexibility of reinforcement, but also ensure the optimization of the reinforcement effect. At the same time, the above-mentioned method also lays the foundation for subsequent cross-platform compatibility processing, because the reinforcement strategies of different types of programs on different hardware architectures may require special adjustments.
[0050] S102: Obtain a randomization coefficient of the target program, where the randomization coefficient is used to balance the security index and performance index of the target program when it is running in an application scenario.
[0051] The randomization coefficient refers to a set of parameters used to quantify the strength of program security reinforcement. In the embodiment of the present application, it can be understood as a comprehensive indicator of security reinforcement parameters such as stack randomization strength, heap randomization frequency, instruction fill ratio, and function reordering degree. Each indicator has its value range and weight, which together determine the overall strength of program reinforcement. For example, for programs running in a server environment, a higher randomization coefficient can be used to provide stronger security protection; for programs running on resource-constrained embedded devices, a lower randomization coefficient is required to ensure the program's operating efficiency. The randomization coefficient is used to dynamically balance the security protection strength and execution efficiency when the program is running, ensuring that the program can obtain the optimal security performance ratio in different application scenarios.
[0052] Specifically, after obtaining the target program, it is necessary to determine the randomization coefficient that is suitable for the program. This is because the process of program security reinforcement is essentially to improve its security by increasing the uncertainty of the program, but excessive randomization may significantly affect the execution efficiency of the program. Therefore, it is necessary to find the best balance between security and performance, that is, the randomization coefficient, according to the specific application scenario of the target program.
[0053] Based on the above embodiment, as an optional embodiment, in S102: the step of obtaining the randomization coefficient of the target program may further include the following process: S201. Perform static analysis on the target program to obtain security indicators and performance indicators when the target program is running in an application scenario.
[0054] Static analysis refers to a technical means of systematically analyzing program code without executing the program. In the embodiments of the present application, it can be understood as a process of using code analysis tools to comprehensively check the structural features of the target program, which is used to identify potential security vulnerabilities and evaluate performance bottlenecks before the program runs, and provide a basis for determining the appropriate randomization coefficient.
[0055] Furthermore, security indicators and performance indicators refer to numerical parameters used to quantitatively evaluate the security protection capabilities and operating efficiency of a program. In the embodiments of the present application, they can be understood as a set of data indicators obtained through static analysis. For example, security indicators may include stack buffer overflow risk value, heap memory usage risk level, function pointer usage frequency, number of formatted string vulnerabilities and other security risk quantification values; performance indicators may include function call frequency statistics, memory access pattern characteristic values, loop structure complexity scores and other execution efficiency-related parameters, which are used to guide the program reinforcement equipment to determine the appropriate randomization coefficient to minimize the impact on performance while ensuring program security.
[0056] In an optional embodiment, when the target program is an active program, the program hardening device first needs to build a complete program analysis environment. In an embodiment of the present application, the static analysis environment can be built based on the LLVM compiler framework, which provides a wealth of program analysis tools and interfaces that can deeply analyze the structural characteristics and potential risks of the source code. Specifically, the program hardening device will use analysis tools such as Clang Static Analyzer to perform a multi-dimensional security risk assessment on the source code of the target program.
[0057] When performing stack layout analysis, the program hardening device will build a stack frame model for each function, recording in detail the allocation location, size, and life cycle of local variables. By analyzing the arrangement and access patterns of variables on the stack, risk points where stack overflows may occur can be identified. For example, when a function is detected to have a large number of local array variables, and the access operations of these variables do not have strict boundary checks, the function will be marked as a high-risk area and needs to be dealt with in the subsequent hardening process.
[0058] For the analysis of heap memory allocation patterns, the program hardening device mainly focuses on the application and release operations of dynamic memory. By tracking the calls of memory management functions such as malloc and free, the system can build a profile of the program's heap memory usage. This profile not only includes the size distribution characteristics of memory blocks, but also records the timing relationship of memory operations. For example, the system will pay special attention to those situations where memory is applied in conditional branches but may not be released in time on certain execution paths, or code segments with potential double release risks.
[0059] In terms of function call relationship analysis, the program hardening device will build a complete function call graph. This call graph not only shows the direct call relationship between functions, but also includes indirect calls implemented through function pointers. By analyzing the topological structure of the call graph, the key execution paths and potential attack chains in the program can be identified. In particular, for functions that are frequently called or at key nodes in the call chain, the system will conduct a stricter security review. For example, if a function contains sensitive operations and is at an important position in the call chain, then this function requires stronger security protection measures.
[0060] Based on the above analysis results, the program hardening device generates a complete security feature report for the target program. The report quantifies the security indicators of the program in different dimensions, including stack overflow risk value, heap operation hazard level, function call chain complexity and other security indicators. At the same time, the report also includes the performance indicators of the program, such as function call frequency statistics, memory access pattern characteristics, loop structure complexity and other performance indicators. These indicators together constitute the characteristic portrait of the target program in a specific application scenario, providing an objective basis for the subsequent determination of the randomization coefficient.
[0061] In addition, the results of static analysis are also used to optimize the configuration parameters of the compiler. The program hardening device will automatically adjust the enabling strategy and parameter settings of each security-related Pass in the LLVM compiler based on the security risk distribution obtained from the analysis. This adaptive configuration mechanism based on analysis results enables the program hardening process to achieve a better balance between security and performance. For example, for those code segments that have been confirmed to be safe, the system can appropriately reduce the protection strength to reduce performance overhead; and for code areas with multiple security risks, more comprehensive protection measures will be enabled.
[0062] In an optional embodiment, when the target program is a passive program, the program reinforcement device first needs to build a binary program analysis environment. In an embodiment of the present application, the static analysis environment can be built based on binary analysis tools such as IDA Pro, Ghidra or Radare2. These tools provide rich binary code analysis functions and interfaces, which can deeply analyze the structural characteristics and potential risks of the program. Specifically, the program reinforcement device will use binary analysis tools to perform multi-dimensional security risk assessments on the target program.
[0063] When performing static analysis, the program hardening device first builds a complete function call graph through decompilation and control flow analysis, and identifies key information such as function entry points, call instructions, and return addresses in the program. By analyzing this information, the system can build a call chain relationship between functions and identify the key execution paths in the program. When a function is detected to be frequently called by multiple execution paths and the function involves sensitive operations, the function will be marked as a key protection object, and more stringent protection measures will be required in the subsequent hardening process.
[0064] Subsequently, the program hardening device will analyze the section table and segment table of the program to determine the distribution of key memory areas such as the code segment, data segment, and BSS segment, and focus on analyzing the usage characteristics of the stack and heap. By analyzing the allocation method of the stack frame, the arrangement order of local variables, and the allocation and release mode of the heap memory, the system can identify code areas with continuous large blocks of memory allocation or functions with complex pointer operations. These locations are often potential targets of memory attacks.
[0065] After completing the basic structural analysis, the program hardening device uses heuristic rules to scan the binary code for vulnerabilities, detecting memory operation instructions with missing buffer bounds checks, large local variable allocations that may cause stack overflows, function calls with format string vulnerability risks, and potential null pointer dereference or use after free issues. The system assigns a risk level to each potential vulnerability found and records its specific location in the program and the triggering conditions.
[0066] Based on the above analysis results, the program hardening device will generate a comprehensive security assessment report to quantify the security indicators of the program in different dimensions, including function call complexity score, memory operation risk index, instruction sequence availability, execution path prediction difficulty and other security indicators. It also includes performance indicators, including key function call frequency statistics, memory access locality characteristics, instruction execution time distribution estimation, resource consumption bottleneck analysis, etc.
[0067] S202: Determine a randomization coefficient of the target program based on the security index and the performance index.
[0068] Specifically, after obtaining the security and performance indicators of the target program, the program hardening device needs to determine the appropriate randomization coefficient based on these indicators. This is because the security hardening of a program essentially increases its security by increasing the uncertainty of the program, but excessive randomization may significantly affect the execution efficiency of the program. Therefore, it is necessary to find the best balance between security and performance based on the specific application scenario of the target program.
[0069] Specifically, the program hardening device will first build a security requirement model based on security indicators. For program areas with high function call complexity and high memory operation risk index, the system will assign a higher randomization weight.
[0070] For example, when the call chain complexity score of a function exceeds a preset threshold and the function involves sensitive memory operations, the system will increase the stack randomization intensity and heap randomization frequency corresponding to the function. At the same time, for code segments with high instruction sequence exploitability, the system will increase the proportion of instruction padding to reduce the success rate of attackers constructing ROP / JOP attack chains.
[0071] Furthermore, the program hardening device will adjust the initially determined randomization weights based on performance indicators. By analyzing the call frequency statistics of key functions and the locality characteristics of memory access, the system can identify performance-sensitive areas of the program. For code segments with high execution frequency or obvious performance bottlenecks, the system will appropriately reduce their randomization strength to avoid excessive security measures affecting the program's operating efficiency.
[0072] Exemplarily, when it is detected that a certain function is located on the critical execution path of the program and the distribution of its instruction execution time shows that the function has a significant impact on the overall performance, the system will correspondingly reduce the function reordering degree of the function.
[0073] S103: When the target program includes an active program, compile the active program based on a randomization coefficient corresponding to the active program to obtain a reinforced first target program.
[0074] Specifically, for programs containing source code, the compiler's stub function can be used to achieve deeper security reinforcement during the compilation stage. In an embodiment of the present application, the program reinforcement device mainly implements program reinforcement based on the randomization coefficient by configuring the compilation parameters of the LLVM compiler and customizing the Pass. Specifically, the program reinforcement device first configures the security-related parameters of the LLVM compiler according to the previously determined randomization coefficient. These parameters determine the type and amount of security check code that needs to be inserted during the compilation process. For example, when the randomization coefficient indicates that a function has a higher risk of stack overflow, the compiler will insert more dynamic random filling code during the stack frame allocation process of the function.
[0075] During the compilation process, the program hardening device implements dynamic stack randomization and dynamic heap randomization through a custom compiler pass. Dynamic stack randomization inserts randomization logic at the function entry so that the position of the stack pointer changes each time the function is called, making the stack layout different each time it is run. This technology can effectively defend against stack overflow-based attacks, especially those that rely on a fixed stack layout, without recompiling the program. For the protection of heap memory, the program hardening device dynamically adjusts the location and size of heap memory allocation at runtime by modifying the behavior of memory allocation functions such as malloc, so that the location of each heap allocated memory block is random. This dynamic randomization process ensures that even if an attacker obtains part of the heap memory information, it is difficult to predict the overall memory layout, thereby increasing the difficulty of the attack.
[0076] While enabling these security reinforcement measures, the program reinforcement device will also dynamically adjust the protection strength according to the randomization coefficient. By analyzing the calling frequency and execution path characteristics of the function, the system can optimize the performance overhead while ensuring security. For example, for those functions that are frequently called but have relatively low security risks, the randomization strength can be appropriately reduced to reduce performance loss; while for those functions that contain sensitive operations or are at key positions in the attack chain, a higher protection strength is maintained.
[0077] Finally, the program hardening device marks the compiled program as the first target program after hardening. This hardened program not only retains the original functions, but also has the ability to defend against common attacks such as stack overflow and heap overflow. Through the combination of code instrumentation during compilation and dynamic randomization technology, the hardened program can continuously adjust its memory layout during runtime, significantly increasing the difficulty for attackers to predict and control program behavior. This compilation hardening method based on randomization coefficients achieves the optimal balance between security and performance, allowing the program to obtain effective security protection while maintaining high execution efficiency.
[0078] Based on the above embodiment, as an optional embodiment, in S103: when the target program includes an active program, the step of compiling the active program based on the randomization coefficient corresponding to the active program to obtain the reinforced first target program may further include the following steps: S301. Determine a compilation instruction based on a randomization coefficient corresponding to an active program, wherein the compilation instruction includes in the active program: a first offset for adjusting a position of a stack pointer corresponding to a function, and / or a second offset for adjusting an address of a heap memory corresponding to the function.
[0079] Specifically, before compiling and reinforcing the active program, the program reinforcement device needs to first determine the specific compilation instructions based on the randomization coefficient. Because the security reinforcement effect of the program depends largely on the randomization logic inserted during the compilation process, and the strength and distribution of these randomization logics need to be precisely controlled through compilation instructions. In an embodiment of the present application, the compilation instructions mainly include a first offset for adjusting the position of the function stack pointer and a second offset for adjusting the heap memory address. The above two offsets jointly determine the degree of randomization of the memory layout when the program is running.
[0080] Specifically, the program reinforcement device first calculates the first offset based on the randomization coefficient. By analyzing the security risk index of the function, the system determines a baseline random range for each function. For example, when the stack overflow risk value of a function is high, the corresponding first offset value range will be expanded accordingly, so that the stack frame of the function can obtain a larger randomization space each time it is called. In order to ensure the normal execution of the program, the calculation of the first offset also needs to consider the stack frame size and alignment requirements of the function to ensure that the randomized stack pointer position does not cause out-of-bounds access or alignment errors.
[0081] At the same time, the program hardening device will also calculate the second offset based on the randomization coefficient. The second offset is mainly used to adjust the address randomization range when allocating heap memory. Its calculation needs to comprehensively consider the program's heap memory usage pattern and performance requirements. For those code areas that frequently allocate heap memory, the system will dynamically adjust the range of the second offset according to its security risk level. For example, when a section of code is detected to have a potential heap overflow risk, the system will increase the range of the second offset corresponding to the area, making the address interval between adjacent heap blocks more randomized, thereby reducing the possibility of attackers predicting and exploiting the heap layout.
[0082] After determining these compilation instructions, the program hardening device converts them into parameter forms that can be recognized by the LLVM compiler. These parameters will guide the compiler to insert the corresponding randomization logic when generating the target code. For example, for the first offset, the compiler will insert code in the function prologue, use the random number generator to generate the actual offset value, and adjust the stack pointer accordingly; for the second offset, the compiler will modify the implementation of the memory allocation function and add address calculation logic based on the random offset.
[0083] The above method of dynamically determining compilation instructions based on randomization coefficients enables the program reinforcement process to adopt differentiated protection strategies according to the security requirements of different functions and memory areas. By precisely controlling the value range of the first offset and the second offset, the system can ensure that the critical code area has sufficient protection strength and avoid excessive randomization measures in the code area that is not sensitive to performance.
[0084] S302: Compile the active program based on the compilation instruction to obtain a reinforced first target program.
[0085] Specifically, the program hardening device first configures the security-related parameters of the LLVM compiler and creates a special compiler pass for randomizing the stack and heap spaces. For stack space processing, the compiler inserts randomization code into the prologue of the function based on the first offset.
[0086] For example, please refer to Figure 3 , Figure 3 A schematic diagram comparing the spatial layout before and after source code reinforcement provided by an embodiment of the present application is shown. The spatial layout of stack variables in the reinforced program has shown a significant increase. The above growth mainly comes from two aspects: on the one hand, random padding space is reserved in the stack frame so that the actual position of the stack variables can change each time a function is called; on the other hand, a protection area is added around key variables to prevent data overwriting caused by buffer overflow by increasing the spacing between variables. This change in the stack space layout significantly increases the difficulty for attackers to control the execution flow of the program through stack overflow attacks.
[0087] At the same time, the program hardening device also handles the randomization of the heap space. Based on the second offset, the compiler modifies the implementation logic of the memory allocation related functions, making the allocation location of the heap memory have a certain degree of randomness. Figure 3 As shown in the figure, although the spatial layout of heap variables grows relatively small, this moderate growth ensures that there are random intervals between heap blocks without over-consuming memory resources. This balanced design takes into account the frequency of heap memory allocation, ensuring security while avoiding excessive performance overhead.
[0088] S104: When the target program includes a passive program, binary rewrite the passive program based on a randomization coefficient corresponding to the passive program to obtain a reinforced second target program.
[0089] Specifically, the program hardening device first uses binary analysis tools (such as IDA Pro, Ghidra or Radare2) to conduct in-depth analysis of the target program to identify key locations in the program, such as function entry points, return instructions, and memory operation instructions. Based on the randomization coefficient, the system will determine the specific hardening strategies that need to be adopted for different code areas.
[0090] For example, for functions that contain sensitive operations or are located on critical execution paths, the system will apply stronger protection measures; while for some performance-sensitive but low-security risk areas, relatively lightweight protection measures are used.
[0091] When performing binary rewriting, the program hardening device mainly implements the following security hardening measures: randomizing instruction offsets by inserting NOP instructions or invalid functions in the program segment. This method can effectively disrupt the instruction sequence that ROP and JOP attacks rely on; encrypting the return address and stack base address RBP so that even if the attacker successfully overwrites the stack content, these addresses cannot be used to attack; implementing static stack randomization to change the stack layout by adding randomization code at the entry and exit of each function; and also including technologies such as static heap randomization and function reordering. These measures together build a multi-level protection system.
[0092] During the rewriting process, the program hardening equipment pays special attention to the characteristics of different processor architectures. For the x86 architecture, the system needs to handle the characteristics of complex instruction sets to ensure that the inserted instructions do not destroy the original instruction alignment and execution efficiency; for the ARM architecture, it is necessary to consider the requirements of the reduced instruction set and the use of dedicated stack pointer registers and link registers. This architecture-aware rewriting method ensures that the hardened program can run normally on different hardware platforms.
[0093] The resulting second target program retains its original functionality while achieving significantly enhanced security protection capabilities. Through multi-level randomization and encryption measures, the program's memory layout and execution flow become more unpredictable, significantly increasing the difficulty for attackers to successfully launch attacks. This binary rewriting-based reinforcement solution can provide effective protection, especially for attacks that rely on fixed memory layouts or instruction sequences.
[0094] Based on the above embodiment, as an optional embodiment, in S104: the step of performing binary rewriting on the passive program based on the randomization coefficient corresponding to the passive program to obtain the reinforced second target program may further include the following steps: S401. Determine a binary rewrite instruction based on a randomization coefficient corresponding to the passive program, wherein the binary rewrite instruction includes one or more of the number of filler instructions inserted into the function in the passive program, the encryption complexity of the function return address and the stack base address, the degree of function reordering, a third offset for adjusting the position of the stack pointer corresponding to the function, and a fourth offset for adjusting the address of the heap memory corresponding to the function.
[0095] Specifically, before binary rewriting the passive program, the program reinforcement device needs to first determine the specific binary rewrite instructions based on the randomization coefficient. This is because the security reinforcement effect of the passive program depends largely on the randomization and protection measures implemented during the binary rewriting process, and the strength and distribution of these measures need to be precisely controlled through binary rewriting instructions. In an embodiment of the present application, the binary rewrite instructions include parameters of multiple dimensions such as the number of padding instructions, encryption complexity, degree of function reordering, and memory offset, which together determine the security protection strength of the program at runtime.
[0096] The program hardening device first calculates the number of padding instructions based on the randomization coefficient. By analyzing the key execution paths and instruction sequence characteristics in the program, the system determines the appropriate padding instruction insertion strategy for different code segments. For example, when a code segment contains a key instruction sequence that may be used to construct a ROP chain, the system will insert more NOP instructions or invalid functions into the code segment to increase the difficulty for attackers to locate and exploit these instruction sequences. Please refer to Figure 4 , Figure 4 A comparison diagram of a non-source code reinforcement invalid instruction before and after filling provided by an embodiment of the present application is shown. The insertion of the filling instruction significantly changes the offset address of the original instruction, making it difficult for an attacker to accurately locate the location of a specific instruction. At the same time, the system will control the distribution density of the filling instruction to avoid excessive filling that causes the program volume to be too large or the execution efficiency to decrease.
[0097] Secondly, the program hardening device will determine the encryption complexity of the return address and stack base address based on the randomization coefficient. Figure 5 , Figure 5 A schematic diagram of a comparison of encryption of return address and stack base address reinforced by source code-free provided in an embodiment of the present application is shown. The system selects an appropriate encryption algorithm and key management strategy according to the security risk level of the function. For those functions with higher security risks, the system may choose a more complex encryption algorithm to protect its return address and stack base address; while for some functions that are performance-sensitive but have relatively low security risks, a simple XOR operation may be used to achieve basic address protection. Through this differentiated encryption strategy, the system ensures that key functions obtain sufficient protection strength while avoiding excessive performance overhead.
[0098] When determining the degree of function reordering, program hardening equipment needs to balance security and program execution efficiency. Figure 6 , Figure 6A schematic diagram of a comparison before and after source code-free hardened function reordering provided by an embodiment of the present application is shown. The system assigns reordering priorities to different functions by analyzing the function call relationship and execution frequency. For those functions that are frequently called and are on the performance-critical path, the system will limit their reordering range to avoid excessive performance loss; for some security-sensitive but less frequently called functions, a wider range of position adjustments can be made. This priority-based reordering strategy ensures that the program can maintain good execution efficiency while being fully protected.
[0099] Finally, the program hardening device also needs to determine the third offset and the fourth offset, which are used to adjust the randomization range of the stack space and the heap space respectively. For the stack space, the system will calculate the value range of the third offset based on the stack frame size and security requirements of the function to ensure that the randomized stack layout can provide sufficient security without causing stack overflow or out-of-bounds access. Similarly, the determination of the fourth offset also needs to consider the program's heap memory usage pattern, while providing sufficient randomization space to avoid excessive memory fragmentation and performance loss.
[0100] S402: Perform binary rewriting on the passive program based on the binary rewriting instruction to obtain a reinforced second target program.
[0101] Specifically, after determining the binary rewrite instructions, the program hardening device needs to perform binary rewrites on the passive program based on these instructions. Because the security hardening of the passive program must be implemented directly at the binary level, the protection effect is achieved by modifying the program's instruction sequence, memory layout, and control flow. In an embodiment of the present application, the program hardening device first uses a binary analysis tool (such as IDA Pro, Ghidra, or Radare2) to parse the target program.
[0102] It is important to note the characteristics of different processor architectures when implementing these rewrite operations. For the x86 architecture, the system must deal with the characteristics of complex instruction sets to ensure that the inserted code does not break instruction alignment; for the ARM architecture, it is necessary to consider the requirements of the reduced instruction set and the use of dedicated stack pointer registers (SP) and link registers (LR). The above architecture-aware rewrite method ensures that the hardened program can run normally on different hardware platforms.
[0103] The final generated second target program not only retains the original functional integrity, but also obtains multi-level security protection capabilities. The various protection measures implemented based on the binary rewrite instruction cooperate with each other to build a three-dimensional defense system: instruction padding interferes with the attacker's static analysis, return address encryption prevents control flow hijacking, function reordering increases spatial randomness, and memory layout randomization directly raises the threshold for memory attacks. This multi-dimensional protection strategy makes it difficult for an attacker to completely break through the entire defense system even if he successfully bypasses a layer of protection, thereby significantly improving the overall security of the program.
[0104] After completing the reinforcement process of the target program, the program reinforcement device needs to perform comprehensive functional and performance tests on the reinforced program. Because the security reinforcement process may affect the normal function and execution efficiency of the program, systematic testing can not only verify the effectiveness of the reinforcement measures, but also evaluate the degree of impact on program performance. In an embodiment of the present application, the test process will design and execute different test cases based on the characteristics of the first target program and the second target program. As an optional embodiment, the above process may specifically include the following steps: S501. Perform function test and performance test on the first target program and / or the second target program to obtain test results.
[0105] Specifically, the program hardening equipment will build a complete test environment, including test platforms of different hardware architectures. For the test environment based on the x86 architecture, the system needs to consider the execution characteristics of complex instruction sets and the impact of multi-level caches; for the test environment based on the ARM architecture, it is necessary to pay attention to the execution efficiency of the reduced instruction set and resource constraints. By testing on different architectures, it can be ensured that the hardened program can run stably on various hardware platforms.
[0106] In terms of functional testing, the program hardening device first performs basic functional verification, and ensures that the hardening measures do not destroy the normal logic of the program by executing the core functional modules of the program. In particular, for those functions that have been processed by stack randomization and heap randomization, the system will focus on testing whether their parameter passing and return value processing are correct. At the same time, it is also necessary to verify whether encryption protection and instruction padding will cause unexpected behavior changes under different execution paths. For example, when there is exception handling or multi-threaded operation in the program, it is necessary to ensure that the hardening measures will not interfere with the normal execution of these complex scenarios.
[0107] In terms of performance testing, the program hardening device will use standardized performance testing tools to collect performance indicators of the program under different workloads. These indicators include program startup time, memory usage, CPU occupancy, and response delays of key operations. By comparing the performance data before and after hardening, the system can accurately evaluate the performance overhead brought by randomization measures. For example, for code segments that have undergone function reordering, it is necessary to measure the change in instruction cache hit rate; for functions that have implemented dynamic stack randomization, it is necessary to pay attention to the increase in function call overhead.
[0108] In addition, the program hardening equipment will also perform stress testing to verify the stability of the hardened program by simulating extreme situations of high concurrent access or resource constraints. For example, when the system memory is tight, whether the heap randomization mechanism will lead to increased memory fragmentation; or under high load, whether return address encryption will become a performance bottleneck.
[0109] Finally, the program hardening device will generate complete test results, detailing all issues and performance data found during the test. The test results also provide an objective basis for evaluating the rationality of the current randomization coefficient, helping to find a better balance between security and performance.
[0110] S502: Adjust the randomization coefficient corresponding to the active program and / or the randomization coefficient corresponding to the passive program based on the test result.
[0111] Specifically, for the first target program, the program reinforcement device first analyzes the key indicators in the performance test data. When it is found that the performance overhead of certain functions has increased significantly after reinforcement, the system will focus on analyzing the randomization parameters of these functions. For example, if a frequently called function causes the execution time to be significantly prolonged due to dynamic stack randomization, the system will correspondingly reduce the first offset range corresponding to the function, while maintaining the basic protection effect and reducing performance loss. Similarly, for those code segments involving intensive heap memory operations, if the test shows that its memory allocation efficiency has decreased significantly, the system will appropriately adjust the value range of the second offset to optimize the randomization strategy of the heap space.
[0112] Correspondingly, for the second target program, the program hardening device needs to focus on the adjustment of binary rewrite instructions. By analyzing the anomalies found in the functional test, the system can identify possible over-protected areas. For example, if a code segment causes the instruction cache efficiency to decrease due to too many padding instructions, the system will reduce the number of padding instructions in that area accordingly. For those functions that implement return address encryption, if the test shows that it may cause stability problems in specific scenarios, the system will adjust its encryption complexity and select a more suitable encryption algorithm or parameter. At the same time, based on the results of the performance test, the system will also optimize the degree of function reordering and adjust the range of the third offset and the fourth offset to ensure that the performance impact is minimized while providing sufficient security protection.
[0113] It should be noted that when the program hardening device recognizes that the target program contains both a source code part and a non-source code part, the program hardening device analyzes the active program and the passive program respectively to obtain the randomization coefficients corresponding to the active program and the passive program respectively.
[0114] For example, when the target program includes an active program, the active program is analyzed to obtain the randomization coefficient of the active program; when the target program includes a passive program, the passive program is analyzed to obtain the randomization coefficient of the passive program. It should be noted that during the adjustment process, the program reinforcement device will adopt a progressive optimization strategy. First, the areas where the problems are most obvious are adjusted, and then the adjustment effect is confirmed through small-scale verification tests. If the adjusted results meet expectations, the system will gradually expand the adjustment range; if new problems are found, it will roll back in time and try other adjustment solutions. This iterative optimization process ensures that the adjustment of the randomization coefficient is safe and controllable.
[0115] Especially for programs running on different hardware architectures, the adjustment of randomization coefficients also needs to take into account architectural characteristics. On the x86 architecture, the system may need to pay more attention to the impact of instruction padding on the instruction cache; on the ARM architecture, it may need to be more cautious in handling randomization parameters related to stack pointers and link registers. Through this architecture-aware adjustment strategy, it is ensured that the optimized program can achieve good performance on different platforms.
[0116] After determining the optimal randomization coefficient, the program reinforcement device needs to generate a corresponding randomization function and write it into the target program. This is because static security reinforcement may not be able to cope with the various dynamic threats faced by the program when it is running. By implanting a randomization function in the program, the program can be equipped with the ability to dynamically adjust the security protection strategy. In an embodiment of the present application, the randomization function can not only dynamically adjust the randomization coefficient according to the running state of the program, but also trigger a re-reinforcement process when necessary, thereby providing more flexible and effective security protection. The above process may also specifically include the following steps: A randomization function is generated based on the randomization coefficient of the target program, and the randomization function is written into the target program. The randomization function is used to adjust the randomization coefficient of the target program according to the running state when the target program is running, and / or to re-reinforce the target function based on the randomization coefficient of the target program.
[0117] When the target program includes an active program, a randomization function of the active program is generated based on a randomization coefficient of the active program; when the target program includes a passive program, a randomization function of the passive program is generated based on a randomization coefficient of the passive program.
[0118] Specifically, the program hardening device first needs to build the basic framework of the randomization function. This function contains three core components: the state monitoring module, the decision analysis module, and the execution adjustment module. The state monitoring module is responsible for collecting key indicators during program runtime, such as memory usage, function call frequency, system load, etc. The decision analysis module evaluates the current security risk level based on these runtime data and calculates the randomization parameters that need to be adjusted; the execution adjustment module is responsible for implementing specific randomization operations, including updating memory layout, re-encrypting key data, etc.
[0119] Furthermore, the program hardening device will select different randomization strategies according to the type of target program. For the first target program, the randomization function mainly focuses on the parameter adjustment of dynamic stack randomization and heap randomization. For example, when it is detected that a function is frequently called and there is a potential stack overflow risk, the randomization function will dynamically increase the stack randomization strength of the function; when it is found that the heap memory usage pattern has changed significantly, the randomization strategy of heap block allocation will be adjusted. For the second target program, the randomization function focuses more on instruction-level protection measures, such as dynamically adjusting the density of instruction filling, updating the encryption parameters of the return address, etc.
[0120] In order to ensure the security of the randomization function itself, the program hardening device will use code obfuscation and self-protection technology. This includes encrypted storage of function code, integrity verification during runtime, and dynamic obfuscation of key parameters. At the same time, the execution process of the randomization function also adopts a decentralized triggering method to avoid significant performance fluctuations or the formation of characteristic patterns that can be identified by attackers due to centralized security operations.
[0121] It should be noted that when dealing with different hardware architectures, the randomization function needs to adapt to their respective characteristics. On the x86 architecture, the function will make more use of the characteristics of general registers and complex instruction sets to achieve flexible randomization operations; on the ARM architecture, special consideration needs to be given to the use of dedicated registers and the limitations of the reduced instruction set to ensure the efficiency and accuracy of the randomization operation.
[0122] Optionally, the randomization function also includes an adaptive learning mechanism that can record and analyze past security events and performance data. Through this historical data, the function can gradually optimize its decision model and improve the accuracy of randomized parameter adjustments. For example, if a certain parameter combination performs well in a specific scenario, the system will increase the weight of the combination in similar scenarios; conversely, if it is found that a certain adjustment may cause performance problems, similar adjustments will be avoided in subsequent decisions.
[0123] Ultimately, the target program implanted with the randomization function gains dynamic and adaptive security protection capabilities. The program can adjust its security strategy according to the real-time running status, enhance the protection strength when attacked, and maintain low performance overhead during normal operation. This dynamic balance mechanism not only improves the security of the program, but also ensures that the performance overhead is always within a controllable range. At the same time, the running data collected by the randomization function also provides an important reference for the program reinforcement device to optimize its reinforcement strategy, forming a continuously improving security protection closed loop.
[0124] Please refer to Figure 7 , Figure 7 A schematic diagram of the structure of a program reinforcement device provided in an embodiment of the present application includes: A target program acquisition module, used to acquire a target program to be reinforced, wherein the target program includes an active program and / or a passive program; A randomization coefficient acquisition module, used to acquire a randomization coefficient of the target program, wherein the randomization coefficient is used to balance the safety index and the performance index of the target program when it is running in an application scenario; An active program reinforcement module, used for compiling the active program based on a randomization coefficient corresponding to the active program to obtain a reinforced first target program when the target program includes the active program; The passive program reinforcement module is used to perform binary rewriting on the passive program based on the randomization coefficient corresponding to the passive program when the target program includes the passive program, so as to obtain a reinforced second target program.
[0125] Based on the above embodiment, as an optional embodiment, the randomization coefficient acquisition module is also used to perform static analysis on the target program to obtain the safety index and performance index of the target program when it runs in the application scenario; based on the safety index and the performance index, determine the randomization coefficient of the target program.
[0126] Based on the above embodiment, as an optional embodiment, the active program reinforcement module is also used to determine the compilation instruction based on the randomization coefficient corresponding to the active program; compile the active program based on the compilation instruction to obtain a reinforced first target program; wherein the compilation instruction includes a first offset of the position of the stack pointer corresponding to the adjustment function in the active program, and / or a second offset of the address of the heap memory corresponding to the adjustment function.
[0127] On the basis of the above embodiments, as an optional embodiment, the passive program reinforcement module is also used to determine a binary rewrite instruction based on a randomization coefficient corresponding to the passive program; the passive program is binary rewritten based on the binary rewrite instruction to obtain a reinforced second target program; wherein the binary rewrite instruction includes one or more of the number of fill instructions inserted into the function in the passive program, the encryption complexity of the function return address and the stack base address, the degree of function reordering, the third offset for adjusting the position of the stack pointer corresponding to the function, and the fourth offset for adjusting the address of the heap memory corresponding to the function.
[0128] Based on the above embodiments, as an optional embodiment, the program reinforcement device may also include a target program testing module, which is used to perform functional testing and performance testing on the first target program and / or the second target program to obtain test results; based on the test results, adjust the randomization coefficient corresponding to the active program and / or the randomization coefficient corresponding to the passive program.
[0129] Based on the above embodiment, as an optional embodiment, the program reinforcement device may also include a randomization function generation module, which is used to generate a randomization function based on the randomization coefficient of the target program, write the randomization function into the target program, and the randomization function is used to adjust the randomization coefficient according to the running state when the target program is running, and / or re-reinforce the target function based on the randomization coefficient.
[0130] Please refer to Figure 8 , Figure 8A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application is shown. Figure 8 As shown, the electronic device may include: a processor 810, a communication interface 820, a memory 830 and a communication bus 840, wherein the processor 810, the communication interface 820 and the memory 830 communicate with each other through the communication bus 840. The processor 810 may call the logic instructions in the memory 830 to execute the program reinforcement method.
[0131] In addition, the logic instructions in the above-mentioned memory 830 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0132] On the other hand, the present application also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the program hardening methods provided by the above methods.
[0133] On the other hand, the present application also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to execute the program hardening methods provided by the above methods.
[0134] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0135] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0136] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A program reinforcement method, characterized in that: include: Acquire a target program to be reinforced, wherein the target program includes an active program and / or a passive program; Obtaining a randomization coefficient of the target program, where the randomization coefficient is used to balance a safety index and a performance index when the target program is running in an application scenario; In the case where the target program includes an active program, compiling the active program based on a randomization coefficient corresponding to the active program to obtain a reinforced first target program; In the case where the target program includes a passive program, the passive program is binary rewritten based on a randomization coefficient corresponding to the passive program to obtain a reinforced second target program.
2. The program reinforcement method according to claim 1, characterized in that: The step of compiling the active program based on the randomization coefficient corresponding to the active program to obtain a reinforced first target program includes: Determining compilation instructions based on the randomization coefficient corresponding to the active program; Compiling the active program based on the compile instruction to obtain a reinforced first target program; The compile instruction includes a first offset for adjusting a position of a stack pointer corresponding to a function in the active program, and / or a second offset for adjusting an address of a heap memory corresponding to the function.
3. The program reinforcement method according to claim 1, characterized in that: The step of performing binary rewriting on the passive program based on the randomization coefficient corresponding to the passive program to obtain a reinforced second target program includes: Determining a binary rewrite instruction based on a randomization coefficient corresponding to the passive program; Perform binary rewriting on the passive program based on the binary rewriting instruction to obtain a reinforced second target program; Among them, the binary rewrite instruction includes one or more of the number of fill instructions inserted into the function in the passive program, the encryption complexity of the function return address and the stack base address, the degree of function reordering, the third offset for adjusting the position of the stack pointer corresponding to the function, and the fourth offset for adjusting the address of the heap memory corresponding to the function.
4. The program reinforcement method according to claim 1, characterized in that: The method further comprises: Performing a function test and a performance test on the first target program and / or the second target program to obtain a test result; The randomization coefficient corresponding to the active program and / or the randomization coefficient corresponding to the passive program are adjusted based on the test result.
5. The program reinforcement method according to any one of claims 1 to 4, characterized in that: The obtaining of the randomization coefficient of the target program includes: Performing static analysis on the target program to obtain security indicators and performance indicators of the target program when it is running in an application scenario; Based on the security indicator and the performance indicator, a randomization coefficient of the target program is determined.
6. The program reinforcement method according to claim 5, characterized in that: After obtaining the randomization coefficient of the target program, the method further includes: A randomization function is generated based on the randomization coefficient of the target program, and the randomization function is written into the target program. The randomization function is used to adjust the randomization coefficient of the target program according to the running state when the target program is running, and / or to re-reinforce the target function based on the randomization coefficient of the target program.
7. A program reinforcement device, characterized in that: include: A target program acquisition module, used to acquire a target program to be reinforced, wherein the target program includes an active program and / or a passive program; A randomization coefficient acquisition module, used to acquire a randomization coefficient of the target program, wherein the randomization coefficient is used to balance the safety index and the performance index of the target program when it is running in an application scenario; An active program reinforcement module, used for compiling the active program based on a randomization coefficient corresponding to the active program to obtain a reinforced first target program when the target program includes the active program; The passive program reinforcement module is used to perform binary rewriting on the passive program based on the randomization coefficient corresponding to the passive program when the target program includes the passive program, so as to obtain a reinforced second target program.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the program reinforcement method according to any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the program reinforcement method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the program reinforcement method according to any one of claims 1 to 6 is implemented.