A software analysis interaction method based on pile mask

Through the pile mask method, dynamically divide pile point types and update strategies, the shortcomings in execution rate and flexibility of existing software testing tools are solved, and efficient software testing and vulnerability mining performance are achieved.

CN114238984BActive Publication Date: 2024-11-12SOUTHEAST UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111527064.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-14
Publication Date
2024-11-12
Estimated Expiration
2041-12-14

AI Technical Summary

Technical Problem

Existing software testing tools are difficult to balance vulnerability mining capabilities, execution rate and execution overhead, and are not flexible and interactive, making it difficult to achieve an efficient software testing mechanism.

Method used

The pile masking method dynamically divides shielded pile points and non-shielded pile points to avoid the execution overhead of invalid and repeated paths, and adopts the pile mask update strategy to provide flexible information interaction methods to improve test rate and vulnerability mining performance.

Benefits of technology

It effectively reduces execution overhead, improves test rate and vulnerability mining performance, provides a more flexible information interaction mechanism, and adapts to the needs of different test goals.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114238984B_ABST
    Figure CN114238984B_ABST
Patent Text Reader

Abstract

The present invention discloses a software analysis interaction method based on a pile mask, in which each basic block of a program to be tested is uniquely identified and a pile code call instruction is inserted, and a pile mask is introduced to determine whether to execute the pile code. At the same time, the pile mask can be automatically or manually modified according to an update strategy, so as to achieve the purpose of shielding some pile points. The method can optimize the pile point layout and improve the execution rate under the premise of ensuring the software analysis performance, and is a software analysis interaction method with flexibility, extensibility and practicality.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of software testing, and in particular relates to a software analysis interaction method based on pile masks. Background Art

[0002] With the development of information technology, the software industry has expanded from professional fields such as national defense technology and industrial production to people's daily life and work applications. However, due to improper development, software vulnerabilities are increasing and are more hidden. As an effective vulnerability mining technology, software testing has received extensive attention and research with a high degree of automation and good usability. However, the bottleneck of this technology lies in the mutual restraint between vulnerability mining capability, execution rate, and execution overhead. In addition, the current popular testing tools are difficult to realize the conversion of artificial experience knowledge into data content, and the interactivity is not strong. Therefore, how to provide a more flexible information interaction method under the premise of ensuring vulnerability mining capability and execution rate, and to realize an efficient software testing mechanism still faces many challenges.

[0003] The patent "An Improved Source Code Insertion Method for Dynamic Analysis" with the publication (announcement) number CN111736846A provides a source code insertion method for multiple types of files by constructing a compilation database, overcoming the difficulties of conventional insertion methods in dealing with multi-file projects and complex syntax structures, and realizing dynamic analysis of the program execution process. However, this invention fails to avoid the execution and statistics of invalid and repeated paths during the dynamic analysis process. Although its vulnerability mining performance has been improved, it has defects in execution rate and execution overhead, and the method is not flexible and interactive.

[0004] The patent "A software analysis method and system based on dynamic instrumentation" with the publication (announcement) number CN112559322A uses dynamic instrumentation to count the execution paths of each test sample using the execution path tree, discarding repeated and invalid execution paths, thereby exploring deep code branches and improving vulnerability mining performance. However, the dynamic instrumentation method in this invention requires repeated execution of instrumentation and de-insertion operations, and the program to be tested needs to be updated multiple times during the complete test process. The execution overhead is large, the versatility is not strong, and the practicality in medium and large programs is limited.

[0005] The software analysis method based on the pile insertion refers to monitoring the abnormal state of the program operation during the execution of the target program by the test sample data by determining at least one pile point in the execution program of the target software and injecting a specific pile insertion code, so as to realize the monitoring and analysis of the dynamic execution process of the program, find out the potential vulnerability risk, and then realize the security analysis of the target program. The present invention dynamically defines the pile points as shielded pile points and non-shielded pile points through the pile mask method, taking into account the vulnerability detection capability and execution rate required for software testing, avoiding the execution overhead and statistical overhead of invalid and repeated paths, improving the test rate and vulnerability mining performance, and providing a more flexible information interaction mode through the pile mask update strategy, and providing a universal pile insertion interface for different test targets. Summary of the invention

[0006] To solve the above problems, the present invention discloses a software analysis interaction method based on pile masks. The method can dynamically realize the division of shielded pile points and non-shielded pile points through pile masks during the test process according to the security analysis requirements of the target software, so as to realize the filtering of the effectiveness of the execution path, reduce the overhead and improve the execution rate on the basis of ensuring the accurate statistics of the coverage information, and provide a more flexible information interaction mechanism on the basis of ensuring the vulnerability mining performance.

[0007] To achieve the above object, the present invention provides a software analysis interaction method based on stub mask, including shielding execution of stub code by stub mask, and the specific steps are as follows:

[0008] (1) Preparation: Obtain the program to be tested and test sample data, and formulate the security analysis requirements and test objectives of the program to be tested;

[0009] (2) Insertion: statically analyze the program to be tested, obtain the program structure, insert a unique identifier and a call instruction of the insertion code at the granularity of basic blocks, and design and insert a section of the insertion code at the granularity of the entire program to be tested;

[0010] (3) Setting: constructing a pile mask array that can be indexed by the basic block unique identifier, setting whether to execute the pile code for each pile point, realizing pile point classification, and initializing the pile mask update strategy;

[0011] (4) Execution: using the test sample data as the input of the program to be tested, executing the program to be tested, determining whether to execute the stub code according to the setting of the stub mask, obtaining the entry status of each stub point as the execution path information, and recording the crash information;

[0012] (5) Statistics: Based on the execution path information and crash information, statistics are collected on test indicators such as code coverage and crash samples. At the same time, the pile mask is automatically updated or manually updated according to the update strategy to achieve dynamic update of the category to which each pile point belongs, so as to enter the next execution;

[0013] (6) Analysis: Performing security analysis on the program to be tested based on test indicators such as code coverage and crash samples;

[0014] As a further improvement of the present invention, the classification of the pile point categories includes: dividing the pile points into two types through pile masks, namely shielded pile points and non-shielded pile points. When the sample data to be tested triggers the non-shielded pile point, the entire content of the pile insertion code is entered and executed; when the sample data to be tested triggers the shielded pile point, after entering the pile point, only necessary records are made without executing the pile insertion code. By dividing the pile point types, the pile insertion code is selectively executed, which solves the problem of invalid overhead caused by fixed pile points, repeated paths, etc. in existing popular test tools, and improves the test rate;

[0015] As a further improvement of the present invention, the dynamic update of the pile point category through the pile mask update strategy includes: in the initial case, according to the software security analysis requirements and the pile point type classification standard defined in the test target, by setting the pile mask, the category of each pile point is initialized. For example: the pile mask value is set to 1 to indicate that the pile point is a non-shielded pile point, and the pile mask value is set to 0 to indicate that the pile point is a shielded pile point; during the test process, the pile mask value can be updated according to the coverage and execution of the pile point, and the category attributes of each pile point can be reset. For example: after the non-shielded pile point with the pile mask value set to 1 completes the execution of the program in the test sample data once, according to the software security analysis requirements and the pile point type classification standard defined in the test target, it is allowed to be set as a shielded pile point, then according to the pile mask update strategy, its pile mask value is set to 0 and redefined as a shielded pile point; the pile mask update strategy is used to realize the dynamic update of the pile point attributes, realize timely feedback during the test process, and improve the software testing performance.

[0016] As a further improvement of the present invention, the software analysis interactive method includes: formulating different pile mask setting strategies and update strategies according to different software to be tested and its security analysis objectives. In the actual application process, artificial experience knowledge, feedback results of existing tests and other contents can be converted into pile mask setting strategies and update strategies to realize interactive automated testing and achieve effective intervention in the testing process;

[0017] As a further improvement of the present invention, the stub step includes: constructing a control flow graph of the target program through static analysis to obtain structural information of each basic block. Inserting a unique identifier and a call instruction of the stub code within the scope of each basic block. At the same time, inserting a stub code within the scope of the entire target program to count coverage information, crash information, etc. during the execution process;

[0018] As a further improvement of the present invention, the setting step includes: constructing a pile mask array that can be indexed by the basic block unique identifier, and setting whether each pile point executes the plug-in code. Among them, the pile mask corresponding to the non-shielded pile point, that is, the pile point that needs to enter and execute the plug-in code is set to a non-shielded state; the shielded pile point, that is, the pile mask corresponding to the pile point that does not need to execute the plug-in code is set to a shielded state. In addition, the pile mask update strategy is formulated according to the security analysis requirements and test objectives of the program to be tested, which should include the definition of the pile mask value and its meaning, the pile point type classification standard, the pile point type conversion requirements and other contents.

[0019] As a further improvement of the present invention, the execution step includes: using the test sample data as the input of the program to be tested, and executing the program to be tested. The test sample data will trigger a stub each time a basic block is executed, and the corresponding stub mask is queried according to the unique identifier of the current basic block: if the stub mask state is a non-shielded state, it means that the stub is a non-shielded stub, and it is necessary to enter and execute the stub code content; if the stub mask state is a shielded state, it means that the stub is a shielded stub, and it is necessary to skip the stub code and continue to execute the original content of the program. In addition, it is necessary to obtain the entry status of each stub during the execution process as the execution path information, and record the crash information at the same time;

[0020] As a further improvement of the present invention, the statistical step includes: determining whether the execution path of the test sample data meets the target based on the software security analysis target and the execution path information of the test sample data. If it meets the target, and each pile point on the path meets the type conversion requirement, the pile mask information is automatically or manually updated according to the pile mask update strategy to enter the next test. If it does not meet the target, the corresponding test case can be discarded, and no changes are made to the pile points. In addition, test indicators such as code coverage and crash sample conditions are counted based on the execution path information and crash information of the test sample data;

[0021] The present invention provides a software analysis interaction method based on pile mask, which has the following beneficial effects:

[0022] (1) Customizable scope of stub insertion: Based on the software security analysis requirements and test objectives, you can customize the stub type conversion standard and the stub mask initialization setting strategy and update strategy. The stub mask divides the stub into shielded stubs and non-shielded stubs. While retaining the validity of each stub, the scope of the stub that enters and executes the stub code is limited to meet the different analysis requirements of different types of software.

[0023] (2) Reversible pile point state switching method: In the conventional dynamic pile insertion method, the effectiveness and failure of the pile point depend on the pile insertion operation and the pile withdrawal operation. The switching process is complicated and will generate additional overhead. The present invention realizes the dynamic switching of the pile point shielding state and the non-shielding state according to the pile mask. This method not only effectively avoids the additional overhead, but also each pile point always maintains its effectiveness. The switching process is reversible and convenient.

[0024] (3) Interactive automated testing method: In actual application, this method can convert artificial experience knowledge, existing test feedback results, etc. into pile mask initialization setting strategies and update strategies, intervene in the software testing process, and realize interactive automated testing.

[0025] (4) Improving software testing rate and vulnerability mining performance: This method effectively avoids the tracking and statistical overhead of repeated paths and invalid paths. By increasing the testing rate, it increases the chance of mutation of effective test sample data, increases the probability of reaching deep code or target code, and ultimately improves vulnerability mining performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 Interaction methods for pile mask-based software analysis;

[0027] Figure 2 A static analysis and instrumentation flow chart according to an embodiment of the present invention;

[0028] Figure 3 A state transition diagram of a stub trigger according to an embodiment of the present invention; DETAILED DESCRIPTION

[0029] The present invention is further explained below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the following specific embodiments are only used to illustrate the present invention and are not used to limit the scope of the present invention. It should be noted that the words "front", "rear", "left", "right", "upper" and "lower" used in the following description refer to directions in the accompanying drawings, and the words "inner" and "outer" refer to directions toward or away from the geometric center of a specific component, respectively.

[0030] This embodiment provides a software analysis interaction method based on pile mask, and the process of each stage is as follows: Figure 1 As shown, the following steps are included:

[0031] 1. Preparation. Select the program to be tested and the test sample data according to the expected requirements and actual situation, and formulate the security analysis requirements and software testing goals of the program to be tested. In this embodiment, the security analysis requirements of the program to be tested are: to discover potential risk vulnerabilities in the target software; and the software testing goals are: ① to improve code coverage with basic blocks as the granularity; ② to give priority to exploring execution paths with low test sample data preference; ③ to improve software testing rate;

[0032] 2. Instrumentation. The static analysis and instrumentation process is as follows Figure 2 As shown. First, the LLVM compiler is used to perform static analysis on the source code of the software to be tested, a program control flow chart is constructed, and program structure information is obtained. Secondly, a soft interrupt INT3 instruction is inserted into each basic block as the stub of the basic block, and the instruction will also be used as a calling instruction for the stub code. The specific calling method will be described in point 4. In addition, the logical address of the stub is obtained, and the address is used as the unique identifier of the corresponding basic block. Since the present embodiment uses the INT3 soft interrupt instruction as the trigger signal of the stub, its stub code will be inserted into the program to be tested in the form of an interrupt signal handler.

[0033] 3. Setting. Construct a stub mask array that can be indexed by the basic block unique identifier, set whether to execute the stub code for each stub point, and initialize the stub mask update strategy according to the software security analysis requirements and test objectives.

[0034] 1) Construct a pile mask array and set the pile mask state value. The pile mask setting values ​​and their meanings are shown in Table 1. The pile mask value of the non-shielded pile point is set to 1, and the pile mask value of the shielded pile point is set to 0. Construct a pile mask array that can be indexed by the unique identifier of each basic block, that is, the pile point logical address. In the initial state, all pile points are set to non-shielded pile points, and the corresponding pile mask is set to 1.

[0035] Table 1 Pile mask setting values ​​and their meanings

[0036] Index value Stub Mask Value Pile mask meaning Basic block unique identifier 1 Unshielded pile point Basic block unique identifier 0 Shielding pile points

[0037] 2) Initialize the pile mask update strategy: ① When the test sample data triggers pile point A, and the current state of pile point A is non-shielded, it means that the basic block is the basic block that needs to be covered for the first time. In order to avoid the subsequent test sample data from repeatedly executing coverage statistics and other contents, the pile point can be changed from non-shielded state to shielded state after being triggered, that is, the pile mask value changes from 1 to 0; ② If the test sample data generates crash information during execution and the crash path needs to be reproduced, the pile point in the program that is in shielded state can be set to non-shielded state.

[0038] 3) Other settings. Since the INT3 interrupt instruction is used as the stub signal, in order to capture the interrupt signal and clarify the stub triggering time, Ptrace is attached to the program to be tested, and Ptrace is used to monitor the breakpoints in the program to be tested. Among them, Ptrace provides a tracking mechanism that can control the operation of the child process by the parent process. When the child process triggers a certain type of signal, the child process will be in a suspended state and notify the parent process of the generation of the signal. The parent process can then enter the memory space of the tracked process for reading and writing, and control the continued execution of the child process.

[0039] The specific setting method is as follows Figure 3 As shown: ① Create a process as the parent process in the Ptrace mechanism, and the parent process creates its child process through the fork() function; ② Set the child process as the traced process, and the parent process will monitor the SIGTRAP signal in the child process; ③ Use the test sample data as the input of the program to be tested, and the child process calls the execve() function to execute the program to be tested.

[0040] 4. Execute the program to be tested and collect relevant information. Figure 3 As shown in steps ④-⑦ in the above, during the program execution, Ptrace monitors the interrupt signal content. When the parent process receives the SIGTRAP interrupt signal sent by the program under test executed in the child process, the soft interrupt signal processing program, i.e., the stub code, is started.

[0041] The stub code content is shown in Algorithm 1. Among them, child_pid represents the process ID of the child process, Mask[MAP_SIZE] represents the stub mask array, and Sigtrap_addr represents the logical address of the instruction that triggers the SIGTRAP interrupt signal. In addition, the algorithm involves the call of three functions: HitCount(Sigtrap_addr) counts the number of hits of each basic block based on the basic block unique identifier, and outputs the hit count array hit_count[MAP_SIZE], Coverage_Statistics(Sigtrap_addr) counts the code coverage information based on the basic block unique identifier, and Mask_Update(Sigtrap_addr) dynamically updates the stub mask of each stub point according to the stub mask update strategy.

[0042] First, the parent process enters the child process memory and reads the logical address of the soft interrupt instruction generated by it. This address is the basic block unique identifier set during the instrumentation.

[0043] Secondly, find the corresponding pile mask value in the pile mask array according to the basic block unique identifier as the index value:

[0044] 1) If the corresponding pile mask value is 0, it means that the current pile point is a shielded pile point, and the execution path of the test sample has previously covered the pile point. Therefore, the execution of the plugged code can be skipped for this pile point. In this embodiment, since the test sample data needs to be screened according to the path preference of the test case in the future, the pile point needs to retain the statistics of the basic block hit frequency and shield the statistics of the basic block coverage information.

[0045] 2) If the corresponding pile mask value is 1, it means that the current pile point is a non-shielded pile point and is the pile point covered for the first time. It is necessary to execute the entire content of the pile code, including the statistics of the basic block hit frequency and the statistics of the basic block coverage information. And, according to the pile mask update strategy, after the pile point is covered, its corresponding pile mask value can be updated to 0.

[0046] Finally, if Figure 3 As shown in steps ⑧-⑨ in , the parent process sends a signal instruction to the child process to continue execution, and the child process resumes the execution of the program under test from the breakpoint until the next interrupt signal is triggered, and the above steps are repeated.

[0047]

[0048] 5. Statistical path information and crash information. If the program to be tested generates a crash signal during the test process, the relevant content of the crash information is recorded, including: test sample information, execution path, crash signal, etc., for subsequent software security analysis. In addition, according to the software security analysis requirements and test objectives, it is required to improve the code coverage and give priority to exploring execution paths with lower test sample preferences. Therefore, the screening of the test sample data is shown in Algorithm 2: whether to include it in the test sample set is determined based on whether the test sample data covers new pile points; according to the basic block hit frequency, the test sample data that can hit the basic blocks with fewer hits (ie, lower hit_count values) is selected and given high priority. Finally, a test sample data set with priority is obtained as the test sample data for the next round of testing, so as to optimize the execution path during the test process.

[0049]

[0050]

[0051] 6. Software security analysis. Perform security analysis on the program under test based on test indicators such as the code coverage and crash sample conditions. To confirm whether there is a potential vulnerability risk in the execution path of the crash sample, the stub type can be reset through the stub mask if necessary, and the crash sample can be used as the input of the program under test to confirm its execution path and detailed crash information.

[0052] The technical means disclosed in the scheme of the present invention are not limited to the technical means disclosed in the above-mentioned implementation mode, but also include technical schemes composed of any combination of the above technical features.

Claims

1. A software analysis interaction method based on pile mask, characterized in that: Including the shielding execution of the stub code by the stub mask, the specific steps are as follows: (1) Preparation: Obtain the program to be tested and test sample data, and formulate the security analysis requirements and test objectives of the program to be tested; (2) Stub insertion: statically analyze the program to be tested, obtain the program structure, insert a unique identifier and a call instruction of the stub code at the granularity of basic blocks, and design and insert a stub code at the granularity of the entire program to be tested; (3) Setting: constructing a pile mask array indexed by the basic block unique identifier, setting whether to execute the pile code for each pile point, and initializing the pile mask update strategy; (4) Execution: using the test sample data as the input of the program to be tested, executing the program to be tested, determining whether to execute the stub code according to the setting of the stub mask, obtaining the entry status of each stub point as the execution path information, and recording the crash information at the same time; in the step (4), using the test sample data as the input of the program to be tested, executing the program to be tested; each time a basic block is executed by the test sample data, a stub point will be triggered, and the corresponding stub mask will be queried according to the unique identifier of the current basic block: if the stub mask state is a non-shielded state, it means that the stub point is a non-shielded stub point, and the stub code content needs to be entered and executed; If the stub mask status is shielded, it means that the stub point is a shielded stub point, and the stub code needs to be skipped to continue executing the original content of the program; (5) Statistics: According to the execution path information and crash information, the code coverage and crash sample test indicators are counted, and at the same time, the stub mask is automatically updated or manually updated according to the update strategy to enter the next execution; (6) Analysis: Perform security analysis on the program under test based on the code coverage and crash sample test indicators.

2. The software analysis interaction method based on pile mask according to claim 1, characterized in that: The pile points are divided into two types through pile masks, namely shielded pile points and non-shielded pile points. The shielded pile points are entered pile points but the inserted pile code is not executed, and the non-shielded pile points are entered pile points and all the contents of the inserted pile code are executed. The conversion between the shielded pile points and the non-shielded pile points is reversible.

3. The software analysis interaction method based on pile mask according to claim 2 is characterized in that: The method of distinguishing the shielded pile points from the non-shielded pile points is as follows: a) constructing a stub mask array indexed by the basic block unique identifier; b) Initially, the pile mask of each pile point is set according to the software security analysis requirements; c) During execution, when the execution path of the test sample data triggers a stub point, the corresponding stub mask state is queried according to the unique identifier of the basic block where the stub point is located, so as to determine whether to execute the stub code.

4. The software analysis interaction method based on pile mask according to claim 1 is characterized in that: The pile mask is dynamically updated according to the pile mask update strategy. When the execution path of the test sample data triggers the pile point and the corresponding pile content is executed, if the pile point meets the shielding / non-shielding requirements of the software analysis needs, the corresponding pile mask is set to the shielding / non-shielding state, thereby reducing / increasing the number of pile points that actually execute the pile code and updating the pile point range.

5. The software analysis interaction method based on pile mask according to claim 1 is characterized in that: The pile mask is set to different values ​​according to different pile mask update strategies and pile point tracking strategies, and artificial experience knowledge information is converted into a pile mask update strategy to achieve interactive automatic testing.

6. The software analysis interaction method based on pile mask according to claim 1 is characterized in that: The method further includes: screening a matching test sample data generation algorithm according to the input format requirement of the program to be tested, and determining the contribution of the test sample data to the software analysis target according to the execution status of the test sample data to decide whether to retain or discard the test sample data.

7. The software analysis interaction method based on pile mask according to claim 1 is characterized in that: In the step (2), a control flow graph of the target program is constructed through static analysis to obtain structural information of each basic block; a unique identifier and a call instruction of the stub code are inserted within the scope of each basic block; at the same time, a section of the stub code is inserted within the scope of the entire target program to count the coverage information and crash information content during the execution process.

8. The software analysis interaction method based on pile mask according to claim 2 is characterized in that: In the step (3), a pile mask array indexed by the basic block unique identifier is constructed to set whether each pile point executes the plug-in code; wherein, the pile mask corresponding to the non-shielded pile point, that is, the pile point that needs to enter and execute the plug-in code is set to a non-shielded state; the pile mask corresponding to the shielded pile point, that is, the pile point that does not need to execute the plug-in code is set to a shielded state; in addition, a pile mask update strategy is formulated according to the security analysis requirements and test objectives of the program to be tested, which should include the definition of the pile mask value and its meaning, the pile point type classification standard, and the pile point type conversion requirements.

9. The software analysis interaction method based on pile mask according to claim 1, characterized in that: In the step (4), according to the software security analysis target and the execution path information of the test sample data, it is determined whether the execution path of the test sample data meets the target; if it meets the target and each stub on the path meets the type conversion requirement, the stub mask information is automatically or manually updated according to the stub mask update strategy to enter the next test; If the goal is not met, the corresponding test case is discarded and no changes are made to the stubs. At the same time, the code coverage and crash sample situation test indicators are calculated based on the execution path information and crash information of the test sample data.