Efficient fuzzy testing method based on score matrix

Through the efficient fuzz testing method based on the score matrix, the performance problem of the directional fuzz testing method in exploring irrelevant code is solved, efficient vulnerability detection of the software under test is achieved, and the efficiency of vulnerability mining and the performance of the fuzz testing tool are improved.

CN118733445AActive Publication Date: 2024-10-01ZHEJIANG LAB +1
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202410773432.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-17
Publication Date
2024-10-01
Estimated Expiration
2044-06-17

AI Technical Summary

Technical Problem

Existing directional fuzz testing methods such as AFLGO tend to waste resources on irrelevant code when exploring potential vulnerabilities in software applications, resulting in limited performance and cannot be applied to large-scale security detection of software systems.

Method used

An efficient fuzz testing method based on a score matrix is ​​adopted to divide the software under test into blocks to obtain the distance and score of each basic block. Only basic blocks with a block score greater than 0 are instrumented, a basic block calibration map is constructed, and test cases are randomly generated. And score, select the high-scoring path for mutation until the vulnerability is triggered or the target basic block is reached.

Benefits of technology

It improves the efficiency of vulnerability mining, avoids the exploration of irrelevant code, optimizes the performance of fuzz testing tools, ensures that test cases take high-scoring paths as much as possible to reach the target basic block, and enhances the vulnerability detection capability of the software under test.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733445A_ABST
    Figure CN118733445A_ABST
Patent Text Reader

Abstract

According to the efficient fuzzy testing method based on the score matrix, instrumentation operation is only carried out on the common basic blocks with the block scores larger than 0, equivalently, branches with the arrival probability being 0 are deleted in a pruning mode, and therefore it can be prevented that new irrelevant test case input is generated through fuzzy testing; therefore, through the optimization mode, the fuzzy test tool is prevented from exploring towards a path of irrelevant codes; meanwhile, the test cases in the seed pool can trigger a new path capable of reaching the target basic block or trigger vulnerabilities in the to-be-tested code, so that one test case is selected for variation according to the final score and variation probability corresponding to each test case in the seed pool; and according to the varied test case, the vulnerability test is continuously performed on the to-be-tested code, so that the test case can reach the target basic block through a high-score path as far as possible, and the vulnerability mining efficiency of the to-be-tested software system is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of network security, and in particular relates to an efficient fuzzy testing method based on a scoring matrix. Background Art

[0002] Existing directed fuzz testing methods (such as AFLGO) are an automated testing method for discovering potential vulnerabilities and important security issues in software applications. In the early stage of fuzzing, because the explored paths are limited, the distance to the target point may still be far away. At this time, the focus is on exploration, that is, to expand the coverage as much as possible. When the coverage reaches a certain level, the seeds with a closer distance are used for mutation to quickly cover the target point that the user expects to reach.

[0003] When AFLGO performs directed fuzz testing, it first compiles the source code to obtain the control flow graph (CFG) and function call graph (CG) of the program to be fuzzed. This step is completed by LLVMPass in AFL.

[0004] Secondly, through CFG and CG, as well as the given target, the distance from all basic blocks (BasicBlock, BB) to the basic block where the target is located is calculated. This step is completed by the python script.

[0005] Then, compile the source code again and instrument the program. In addition to AFL's original instrumentation logic, add instructions to increase the distance of each basic block to the specified address. That is, specify a shared memory address as a variable to record distance, instrument the basic block, and insert the following instruction: distance + = current_BB_distance, which increases the distance of the current basic block to the distance variable.

[0006] Finally, the logic of the fuzzing part. Based on the information fed back by the instrumentation, AFLGO can obtain the distance corresponding to each test case when it is used as input to the program for execution. That is, the distance between the test case execution path and the target point. Then, the test case is scored based on the distance. The scoring algorithm is the simulated annealing algorithm. The closer the distance, the higher the score, and the more chances the test case has to mutate.

[0007] Current directed fuzz testing methods (such as AFLGO) are an automated testing method for discovering potential vulnerabilities and security-critical issues in software applications. They use code coverage feedback to generate inputs to guide the directed fuzzer to explore most irrelevant code. By accessing these codes, the directed fuzzer makes almost no progress in reaching its goals or triggering specified vulnerabilities. Moreover, this path exploration strategy causes the fuzz testing tool to waste a lot of energy exploring irrelevant code, which severely limits the performance of the directed fuzzer and causes the fuzzer to require a large amount of computing resources including CPU time and memory, which makes them unable to be applied on a large scale to the security testing of the software system under test. Summary of the invention

[0008] To solve the above problems, the present invention provides an efficient fuzz testing method based on a scoring matrix, which can accurately identify the relevant codes that the directional fuzzer should explore for the software under test.

[0009] An efficient fuzz testing method based on a scoring matrix comprises the following steps:

[0010] S1: Divide the program code of the service software to be tested into blocks to obtain multiple basic blocks, and select the target basic block from each basic block, and the rest are used as common basic blocks;

[0011] S2: Get the block distance corresponding to each basic block;

[0012] S3: Obtaining a block score of each common basic block relative to each target basic block according to the block distance corresponding to each common basic block;

[0013] S4: For each common basic block, the average of the block scores corresponding to all target basic blocks is used as the final corresponding block score of the common basic block;

[0014] S5: Select a common basic block with a block score greater than 0 to perform a plugging operation, and obtain the program code of the service software to be tested after plugging;

[0015] S6: constructing a basic block calibration map including block scores of each common basic block and position information of the common basic blocks being instrumented according to the program code of the service software to be tested after instrumentation;

[0016] S7: inserting a set code snippet into a key position in the program code of the service software to be tested after the stub is inserted to obtain the code to be tested; the key position must satisfy any vulnerability feature in the vulnerability feature library;

[0017] S8: randomly generate a test case, then input the test case into the code to be tested, and identify the instrumented common basic blocks involved in the test case during the execution of the code to be tested according to the basic block calibration map;

[0018] S9: Score the current test case according to the block score corresponding to the identified instrumented common basic block to obtain a score A; at the same time, score the current test case according to whether the current test case causes changes in key variables of the code to be tested to obtain a score B; weighted sum of the score A and the score B to obtain a final score of the current test case;

[0019] S10: Determine whether the current time has reached the set cycle time, if not, proceed to step S11, if yes, end the cycle;

[0020] S11: Determine whether the current test case triggers a new path from any common basic block to any target basic block or triggers a vulnerability in the code to be tested. If yes, store the current test case in the seed pool and set a mutation probability for the current test case, and proceed to step S12; if no, discard the current test case and proceed to step S12;

[0021] S12: Determine whether the seed pool is empty. If so, randomly generate a new test case and re-execute S8~S11; if not, select a test case for mutation based on the final score and mutation probability corresponding to each test case in the seed pool, and re-execute steps S8~S11 on the mutated test case until the set cycle time is reached.

[0022] Furthermore, in step S3, the method for obtaining the block score of each common basic block relative to each target basic block is as follows:

[0023] Take each common basic block as the current common basic block and each target basic block as the current common basic block and perform the following steps in turn:

[0024] S31: Obtain all possible paths from the current common basic block to the current target basic block, and divide all possible paths into branch paths and non-branch paths according to whether the common basic blocks included in each possible path have branch statements; wherein, for branch paths, each branch path performs a block score acquisition operation, and for non-branch paths, select the non-branch path with the shortest distance to perform a block score acquisition operation; wherein, the block score acquisition operation is:

[0025] Get the current path, located at the current common basic block b j The subsequent basic blocks between the target basic block and the target basic block, and the number of subsequent basic blocks is recorded as n;

[0026] Substitute the block distances corresponding to each subsequent basic block into the following formula to obtain the current common basic block b j Score of blocks on the current path:

[0027]

[0028] Among them, t(b j ) is the current common basic block b j The block score on the current path, D(i) is the current common basic block b j The block distance corresponding to the i-th subsequent basic block, f i (b j ) is the current common basic block b j The probability of reaching its i-th subsequent basic block, ε is the set penalty term;

[0029] S32: After averaging the block scores of the current common basic block on all branch paths, the average is then averaged with the block score on the non-branch path with the shortest distance, and the final average is used as the block score of the current common basic block relative to the current target basic block.

[0030] Furthermore, the method for obtaining the block distance corresponding to each basic block in step S2 is:

[0031] Let each basic block be the current basic block and perform the following operations: obtain the arrival probability of the current basic block reaching each target basic block, and take the average of the reciprocals of each arrival probability as the block distance corresponding to the current basic block; wherein, if the current basic block is the target basic block, the probability of the current basic block reaching the target basic block to which it belongs is 1.

[0032] Furthermore, during the process of looping steps S8 to S12, if the code to be tested crashes after any test case is input into the code to be tested, it indicates that the current test case triggers a vulnerability in the code to be tested; at the same time, after the code to be tested crashes, the code to be tested is automatically restarted to continue looping steps S8 to S10.

[0033] Furthermore, the method for constructing the vulnerability feature library in step S7 is:

[0034] Collect vulnerability characteristics related to the tested service software in public data;

[0035] Read the source code of the tested service software and manually extract vulnerability features;

[0036] The collected vulnerability features and manually extracted vulnerability features are constructed into a vulnerability feature library.

[0037] Furthermore, the set code snippet inserted in step S7 is a code that can detect whether the key variables at the key position undergo expected changes; wherein the key variables are variables related to the vulnerability and can trigger the vulnerability, and the key position is the basic block where the key variables are located.

[0038] Further, the weight of score A in step S9 is higher than the weight of score B.

[0039] Beneficial effects:

[0040] 1. The present invention provides an efficient fuzz testing method based on a score matrix, which only performs plugging operations on ordinary basic blocks with block scores greater than 0, which is equivalent to deleting branches with a probability of reaching 0 by pruning, which can prevent the fuzz test of the present invention from generating new irrelevant test case inputs; it can be seen that the present invention avoids the fuzz testing tool of the present invention from exploring paths of irrelevant codes through this optimization method; at the same time, the test cases in the seed pool of the present invention can trigger new paths that can reach the target basic block or trigger vulnerabilities in the code to be tested, then the present invention selects a test case for mutation according to the final score and mutation probability corresponding to each test case in the seed pool, and continues to perform vulnerability testing on the code to be tested according to the mutated test case, which can make the test case take a high-scoring path as much as possible to reach the target basic block quickly, thereby improving the efficiency of vulnerability mining for the software to be tested.

[0041] 2. The present invention provides an efficient fuzzy testing method based on a score matrix. For non-branch paths, the non-branch path with the shortest distance is selected to perform a block score acquisition operation, which can better reflect the progress of reaching the target basic block and obtain the basic block arrival probability matrix.

[0042] 3. The present invention provides an efficient fuzz testing method based on a scoring matrix. It is believed that the possibility of discovering vulnerabilities on basic blocks with higher block scores is higher. Therefore, the scoring operation designed by the present invention is insensitive to large numbers. A heavier penalty item is set for a subsequent basic block that cannot reach the target basic block, which can effectively guide the present invention to discover more basic blocks that match the target basic block, rather than a basic block with a higher probability of a subsequent basic block, thereby making it easier to discover vulnerabilities on the target basic block. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 A flowchart of an efficient fuzzy testing method based on a scoring matrix provided by the present invention;

[0044] Figure 2 The architecture diagram of the scoring matrix fuzzy tester provided by the present invention;

[0045] Figure 3 This is an example diagram of the distance calculation code provided by the present invention. DETAILED DESCRIPTION

[0046] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.

[0047] like Figure 1As shown, an efficient fuzz testing method based on a score matrix includes the following steps:

[0048] S1: Divide the program code of the service software to be tested into blocks to obtain multiple basic blocks, and select the target basic block from each basic block, and the rest are used as common basic blocks;

[0049] It should be noted that the block division method of the program code and the screening criteria of the target basic block can refer to the existing directed fuzzy testing method, which will not be elaborated in the present invention.

[0050] S2: Obtain the block distance corresponding to each basic block, specifically including the following steps:

[0051] Let each basic block be the current basic block and perform the following operations: obtain the arrival probability of the current basic block reaching each target basic block, and take the average of the reciprocals of each arrival probability as the block distance corresponding to the current basic block; if the current basic block is the target basic block, the probability of the current basic block reaching the target basic block to which it belongs is 1;

[0052] For example, assuming that the program code of the service software to be tested is divided into 10 basic blocks, assuming that numbers 1 to 7 are ordinary basic blocks, and numbers 8 to 10 are target basic blocks, then the block distance corresponding to basic block No. 1 is the average of the reciprocals of the three arrival probabilities of basic block No. 1 reaching target basic block No. 8, target basic block No. 9, and target basic block No. 10; at the same time, basic block No. 8 itself belongs to the target basic block, then the arrival probability of basic block No. 8 reaching target basic block No. 8 is 1, and the block distance corresponding to basic block No. 8 is the average of the reciprocals of the three arrival probabilities of basic block No. 8 reaching target basic block No. 8, target basic block No. 9, and target basic block No. 10.

[0053] That is to say, the present invention starts from the control flow chart of the target service software to be tested, and according to the position of the target basic block selected in advance by the traditional method, extracts the probability of each basic block of the target service software to be tested reaching the target basic block. The present invention marks each basic block, and the marking principle is based on whether the arrival probability of the basic block has been calculated, and the marks are initial, calculate, and finish. For the selected basic block b, the present invention calculates the "probability" Pb of the basic block b reaching the target basic block, where the probability Pb ​​is used to estimate the probability of reaching the target basic block T from the basic block b. Then, the present invention calculates the inverse of the probability of the basic block b reaching the target basic block as the block distance Db(b,T) corresponding to the basic block. At the same time, if the basic block b is located at the target basic block, the present invention considers that its arrival probability is set to 100%. Otherwise, it recursively calculates the arrival probability of the successor block. Specifically, the arrival probability of the basic block b is the average of the arrival probabilities of all its successor blocks.

[0054] S3: Obtaining the block scores of each common basic block relative to each target basic block according to the block distances corresponding to each common basic block, specifically including the following steps:

[0055] Take each common basic block as the current common basic block and each target basic block as the current common basic block and perform the following steps in turn:

[0056] S31: Obtain all possible paths from the current common basic block to the current target basic block, and divide all possible paths into branch paths and non-branch paths according to whether the common basic blocks included in each possible path have branch statements; wherein, for branch paths, each branch path performs a block score acquisition operation, and for non-branch paths, select the non-branch path with the shortest distance to perform a block score acquisition operation; wherein, the block score acquisition operation is:

[0057] Get the current path, located at the current common basic block b j The subsequent basic blocks between the target basic block and the target basic block, and the number of subsequent basic blocks is recorded as n;

[0058] Substitute the block distances corresponding to each subsequent basic block into the following formula to obtain the current common basic block b j Score of blocks on the current path:

[0059]

[0060] Among them, t(b j ) is the current common basic block b j The block score on the current path, D(i) is the current common basic block b j The block distance corresponding to the i-th subsequent basic block, f i (b j ) is the current common basic block b j The probability of reaching its i-th subsequent basic block, ε is the set penalty term;

[0061] It should be noted that the present invention believes that the possibility of discovering vulnerabilities on basic blocks with higher block scores is higher. Therefore, the scoring operation designed by the present invention is insensitive to large numbers, and the penalty for a subsequent basic block failing to reach the target basic block is heavier, which can effectively guide the present invention to discover more basic blocks that match the target basic block, rather than a basic block with a higher probability of a subsequent basic block, thereby making it easier to discover vulnerabilities on the target basic block.

[0062] S32: After averaging the block scores of the current common basic block on all branch paths, the average is then averaged with the block score on the non-branch path with the shortest distance, and the final average is used as the block score of the current common basic block relative to the current target basic block.

[0063] It can be seen that the present invention needs to perform special processing for conditional statements and loop statements. For each if statement that is itself a basic block, the present invention assumes that the execution probability of each branch is equal. For example, if an if statement has 3 branches, and each branch is used as a basic block, the execution probability of each branch is 1 / 3. As for loops and recursive statements that are usually included in the program, since the present invention cannot accurately infer the specific number of running iterations of loops and recursive statements in static distance analysis, the present invention only executes the loop body and recursive function once, that is, assuming that a loop statement is actually run 10 times, but the present invention only counts the statement as running once when calculating the probability, so as to reduce the complexity of the model.

[0064] That is to say, assuming that a path from a basic block to a target basic block contains a loop basic block, and the code on the loop basic block contains a loop statement, then in the path, the loop basic block is only calculated once; for example, the path is ordinary basic block No. 1, ordinary basic block No. 2, ordinary basic block No. 3, and target basic block No. 8. If ordinary basic block No. 3 is a loop basic block with 3 loops, then the subsequent basic blocks of ordinary basic block No. 1 on the path are ordinary basic block No. 2 and ordinary basic block No. 3, rather than ordinary basic block No. 2, ordinary basic block No. 3, ordinary basic block No. 3, and ordinary basic block No. 3.

[0065] Furthermore, in the process of mining the service software to be tested, the present invention uses the code position for guidance. Assuming that there are n subsequent basic blocks from the selected basic block b to the target basic block, given the subsequent basic block set involving the target basic block The probability score matrix is ​​constructed by calculating the probability of reaching the target basic block in the subsequent basic block. Let b represent the basic block and C(b) represent the arrival probability in basic block b. Then:

[0066]

[0067] Among them, F i (b) represents the arrival probability of the i-th subsequent basic block of basic block b.

[0068] Table 1 Arrival probability matrix of subsequent basic blocks

[0069]

[0070] At the same time, when calculating the distance of each subsequent basic block (i.e., D(i)), the distance metric of the present invention is the shortest block distance of all basic blocks covered during operation, rather than the method commonly used by other fuzz testers to calculate the average block distance of the covered basic blocks as the input distance. The reason behind this design choice of the present invention is that the shortest distance can better reflect the progress of reaching the target code and obtain the basic block arrival probability matrix. Let Distance(i) be used to represent the shortest distance from the subsequent basic block i contained in the basic block to the target basic block. The example target basic block shortest distance matrix D(j) is shown in Table 2.

[0071] Table 2 Target basic block shortest distance matrix

[0072]

[0073]

[0074] S4: For each common basic block, the average of the block scores corresponding to all target basic blocks is used as the final corresponding block score of the common basic block;

[0075] S5: Select a common basic block with a block score greater than 0 to perform a plugging operation, and obtain the program code of the service software to be tested after plugging;

[0076] It should be noted that the traditional method is to perform the plugging operation on all common basic blocks, while the present invention only performs the plugging operation on the common basic blocks with block scores greater than 0, which is equivalent to deleting branches with an arrival probability of 0 by pruning, which can prevent the fuzz test of the present invention from generating new irrelevant inputs; it can be seen that the present invention avoids the fuzz test tool of the present invention from exploring the path of irrelevant code through this optimization method.

[0077] The plugging operation is a useful technical means in this field, and the present invention will not elaborate on it.

[0078] S6: constructing a basic block calibration map including block scores of each common basic block and position information of the common basic blocks being instrumented according to the program code of the service software to be tested after instrumentation;

[0079] It can be seen that for steps S1 to S6, the present invention calculates the probability of each basic block reaching the target basic block, further obtains a block distance matrix, and finally obtains a basic block score matrix by taking the inverse operation of the obtained block distance matrix, and inserts the basic block according to the score result to obtain a basic block calibration map focusing on the target code for guiding the mining process of vulnerability mining.

[0080] The purpose of constructing the basic block calibration map is to provide the target basic block to the directional mining process and guide the focus of the mining. At the same time, through the guidance based on the target basic block, the present invention can evaluate the score of the basic block from the code structure of the service software to be tested, and insert the plug-in code to focus on the target basic block for mining. By generating the target test case for the service software to be tested input and the scoring matrix with higher directional score, more efficient targeted mining of the target code of the system to be tested can be achieved.

[0081] S7: inserting a set code snippet into a key position in the program code of the service software to be tested after the stub is inserted to obtain the code to be tested; the key position must satisfy any vulnerability feature in the vulnerability feature library;

[0082] Furthermore, the vulnerability feature library is constructed by:

[0083] Collect vulnerability features related to the service software under test from public data;

[0084] Read the source code of the service software under test and manually extract vulnerability features;

[0085] The collected vulnerability features and manually extracted vulnerability features are constructed into a vulnerability feature library;

[0086] At the same time, the set code snippet inserted in step S7 is a code that can detect whether the key variables at the key position undergo expected changes; wherein the key variables are variables related to the vulnerability and can trigger the vulnerability, and the key position is the basic block where the key variables are located.

[0087] For example, the position pointed to by the pointer to the cache array exceeds 50% of the length of the cache array; the number of NS reference acquisitions is greater than 30% of the "maximum recursive query" threshold; it should be noted that the change of key variables in this example does not necessarily cause vulnerabilities such as crashes in the software under test, but based on the analysis of the vulnerability feature library, it is believed that test cases that cause expected changes in key variables have a greater probability of detecting vulnerabilities in the service software under test, and these test cases are given a higher mutation probability and execution count.

[0088] S8: randomly generate a test case, then input the test case into the code to be tested, and identify the instrumented common basic blocks involved in the test case during the execution of the code to be tested according to the basic block calibration map;

[0089] S9: Score the current test case according to the block score corresponding to the identified instrumented common basic block to obtain a score A; at the same time, score the current test case according to whether the current test case causes a change in the key variables of the code to be tested to obtain a score B; weighted sum of the score A and the score B to obtain a final score of the current test case; wherein the weight of the score A is higher than the weight of the score B;

[0090] S10: Determine whether the current time has reached the set cycle time, if not, proceed to step S11, if yes, end the cycle;

[0091] For example, assuming that it takes 10 hours to perform vulnerability mining on the program code of the service software under test, the cycle time is set to 10 hours.

[0092] S11: Determine whether the current test case triggers a new path from any common basic block to any target basic block or triggers a vulnerability in the code to be tested. If yes, store the current test case in the seed pool and set a mutation probability for the current test case, and proceed to step S12; if no, discard the current test case and proceed to step S12;

[0093] S12: Determine whether the seed pool is empty. If so, randomly generate a new test case and re-execute S8~S11; if not, select a test case for mutation according to the final score and mutation probability corresponding to each test case in the seed pool, and re-execute steps S8~S11 on the mutated test case until the set cycle time is reached; wherein, the higher the final score corresponding to the test case, the greater the mutation probability, and the greater the chance of being selected for mutation.

[0094] It should be noted that, during the process of looping execution of steps S8 to S12, if the code to be tested crashes after any test case is input into the code to be tested, it indicates that the current test case triggers a vulnerability in the code to be tested; at the same time, after the code to be tested crashes, the code to be tested is automatically restarted to continue looping execution of steps S8 to S10.

[0095] It can be seen that after determining the common basic blocks that can better reach the target basic block, the next problem to be solved by the present invention is how the selected basic blocks will reach the target basic block, so as to prompt the accuracy and efficiency of vulnerability mining.

[0096] The present invention first identifies the target code and the code related to control or data as related code. In other words, the code that can determine the control flow or data flow conditions that trigger the vulnerability is the related code. The present invention defines two types of related code: path code and data code. The path code is located in the last intersection block of the reachable path and the unreachable path. The data code affects the values ​​of key variables used in the target; these variables can be assigned the values ​​of some constants or variables (direct dependency), which can be further derived from other variables in other code blocks (indirect dependency). At the same time, the code in the target basic block is included as related code and is regarded as data code.

[0097] The path code provides important feedback, so that the fuzz tester of the present invention can distinguish the inputs that are moving toward the target through the feedback. Specifically, by passing through the reachable path when reaching the path code, the fuzz tester of the present invention can generate new inputs from better test case inputs and continuously approach the target basic block. However, it may also generate irrelevant inputs, and its execution only finds irrelevant code. However, because the code is not detected and neither coverage nor distance feedback is provided. Therefore, the present invention deletes branches with a probability of arrival of 0 by pruning, which can prevent the fuzz test of the present invention from generating new irrelevant inputs. The present invention avoids the fuzz test tool of the present invention from exploring the path of irrelevant code through this optimization method.

[0098] In addition, the present invention does not detect irrelevant code that may indirectly affect the control flow at the path divergence code. The present invention detects such code by weighing it against other code to obtain a smaller exploration space. The present invention notes that the reachability of the target is mainly affected by the path divergence code rather than other code. Specifically, the program will continue to execute on the reachable path (after reaching a path divergence block) until the next path divergence block is reached. When the fuzzer attempts to reach the code block of the path divergence, the indirect control related code blocks on the reachable path (i.e., those that affect conditional variables) will be visited regardless of whether the present invention detects them. Detecting other code on the reachable path does not provide additional useful feedback, but increases runtime overhead.

[0099] Data-dependent code may not help reach the target code, but can improve the efficiency of the present invention when using the fuzz testing tool. Since some vulnerabilities may only be triggered when key variables in the target are at specific values, exploring data-dependent code can help the use stage of the fuzz tester of the present invention.

[0100] For example, for a vulnerability in a service software to be tested, the vulnerability is caused by a function overflow during query. That is, check_dns_listeners enters the receive_query function. After dnsmasq receives the second PTR request from the client, it will first call the answer_request function and then respond to the client through the forward_query function. At this time, the query crashes when entering the answer_request function. When the crash occurs, the present invention can know that the value of anscount is 0x51, that is, after looping 81 times, calling cache_find_by_addr again causes an illegal memory reference to crash. Specifically, the data packet generated by the cache referenced by this function will be expanded after processing and recorded in a loop. Therefore, when the cache_find_by_addr function accesses the address of the crec structure, the cache data packet has a stack overflow due to 81 loop records, causing the crec address to overflow by the Z character, which ultimately results in an illegal address reference. Therefore, when we explore related codes, the code segments where the address of the crec structure changes are regarded as data-related codes in the present invention. By closely monitoring the changes of key data in the related codes, we can know whether this mining will discover vulnerabilities.

[0101] In summary, traditional directional fuzz testing schemes such as AFLGO calculate the score of seeds according to the annealing algorithm combined with time and the shortest distance during fuzz testing, and allocate the time for seed mutation according to the score. The distance score matrix of the present invention is based on the consideration of the shortest distance, and the score operation is designed to be insensitive to large numbers. It imposes a heavier penalty on a subsequent basic block that cannot reach the target basic block, narrows the range of reachable basic blocks, and avoids the fuzz test program wasting computing power on invalid basic blocks.

[0102] Secondly, for all reachable basic blocks, the present invention deletes branches with a reach probability of 0 through path selection technology, and further refines the fuzzy test range of the seed through pruning operations.

[0103] Finally, compared to the traditional directional fuzz testing solution that only considers the path, the present invention believes that triggering a vulnerability requires not only the seed to execute to the target basic block, but also the key value to trigger the vulnerability. The present invention further designs the data code and further refines the seed by selecting more seeds with some key data. In other words, compared with the traditional directional fuzz testing technology, the present invention improves the cost-effectiveness of vulnerability mining in the system to be tested.

[0104] Of course, the present invention may have many other embodiments. Without departing from the spirit and essence of the present invention, those skilled in the art may certainly make various corresponding changes and modifications based on the present invention, but these corresponding changes and modifications should all fall within the scope of protection of the claims attached to the present invention.

Claims

1. An efficient fuzzy testing method based on a scoring matrix, characterized in that: The following steps are involved: S1: Divide the program code of the service software to be tested into blocks to obtain multiple basic blocks, and select the target basic block from each basic block, and the rest are used as common basic blocks; S2: Get the block distance corresponding to each basic block; S3: Obtaining a block score of each common basic block relative to each target basic block according to the block distance corresponding to each common basic block; S4: For each common basic block, the average of the block scores corresponding to all target basic blocks is used as the final corresponding block score of the common basic block; S5: Select a common basic block with a block score greater than 0 to perform a plugging operation, and obtain the program code of the service software to be tested after plugging; S6: constructing a basic block calibration map including block scores of each common basic block and position information of the common basic blocks being instrumented according to the program code of the service software to be tested after instrumentation; S7: inserting a set code snippet into a key position in the program code of the service software to be tested after the stub is inserted to obtain the code to be tested; the key position must satisfy any vulnerability feature in the vulnerability feature library; S8: randomly generate a test case, then input the test case into the code to be tested, and identify the instrumented common basic blocks involved in the test case during the execution of the code to be tested according to the basic block calibration map; S9: Score the current test case according to the block score corresponding to the identified instrumented common basic block to obtain a score A; at the same time, score the current test case according to whether the current test case causes changes in key variables of the code to be tested to obtain a score B; weighted sum of the score A and the score B to obtain a final score of the current test case; S10: Determine whether the current time has reached the set cycle time, if not, proceed to step S11, if yes, end the cycle; S11: Determine whether the current test case triggers a new path from any common basic block to any target basic block or triggers a vulnerability in the code to be tested. If yes, store the current test case in the seed pool and set a mutation probability for the current test case, and proceed to step S12; if no, discard the current test case and proceed to step S12; S12: Determine whether the seed pool is empty. If so, randomly generate a new test case and re-execute S8~S11; if not, select a test case for mutation based on the final score and mutation probability corresponding to each test case in the seed pool, and re-execute steps S8~S11 on the mutated test case until the set cycle time is reached.

2. An efficient fuzzy testing method based on a scoring matrix as described in claim 1, characterized in that: The method for obtaining the block score of each common basic block relative to each target basic block in step S3 is as follows: Take each common basic block as the current common basic block and each target basic block as the current common basic block and perform the following steps in turn: S31: Obtain all possible paths from the current common basic block to the current target basic block, and divide all possible paths into branch paths and non-branch paths according to whether the common basic blocks included in each possible path have branch statements; wherein, for branch paths, each branch path performs a block score acquisition operation, and for non-branch paths, select the non-branch path with the shortest distance to perform a block score acquisition operation; wherein, the block score acquisition operation is: Get the current path, located at the current common basic block b j The subsequent basic blocks between the target basic block and the target basic block, and the number of subsequent basic blocks is recorded as n; Substitute the block distances corresponding to each subsequent basic block into the following formula to obtain the current common basic block b j Score of blocks on the current path: Among them, t(b j ) is the current common basic block b j The block score on the current path, D(i) is the current common basic block b j The block distance corresponding to the i-th subsequent basic block, f i (b j ) is the current common basic block b j The probability of reaching its i-th subsequent basic block, ε is the set penalty term; S32: After averaging the block scores of the current common basic block on all branch paths, the average is then averaged with the block score on the non-branch path with the shortest distance, and the final average is used as the block score of the current common basic block relative to the current target basic block.

3. The efficient fuzzy testing method based on a scoring matrix as claimed in claim 1, characterized in that: The method for obtaining the block distance corresponding to each basic block in step S2 is: Let each basic block be the current basic block and perform the following operations: obtain the arrival probability of the current basic block reaching each target basic block, and take the average of the reciprocals of each arrival probability as the block distance corresponding to the current basic block; wherein, if the current basic block is the target basic block, the probability of the current basic block reaching the target basic block to which it belongs is 1.

4. The efficient fuzzy testing method based on a scoring matrix as claimed in claim 1, characterized in that: During the process of looping steps S8 to S12, if the code to be tested crashes after any test case is input into the code to be tested, it indicates that the current test case triggers a vulnerability in the code to be tested; at the same time, after the code to be tested crashes, the code to be tested is automatically restarted to continue looping steps S8 to S10.

5. The efficient fuzzy testing method based on a scoring matrix as claimed in claim 1, characterized in that: The method for constructing the vulnerability feature library in step S7 is: Collect vulnerability characteristics related to the tested service software in public data; Read the source code of the tested service software and manually extract vulnerability features; The collected vulnerability features and manually extracted vulnerability features are constructed into a vulnerability feature library.

6. The efficient fuzzy testing method based on a scoring matrix as claimed in claim 1, characterized in that: The set code snippet inserted in step S7 is a code that can detect whether the key variable at the key position undergoes the expected change; wherein the key variable is a variable related to the vulnerability and can trigger the vulnerability, and the key position is the basic block where the key variable is located.

7. The efficient fuzzy testing method based on a scoring matrix as claimed in claim 1, characterized in that: The weight of score A in step S9 is higher than the weight of score B.

Citation Information

Patent Citations

  • Directional fuzzy test method based on target preposition area search

    CN115269412A

  • Global association directional fuzz testing method and system under code submission scene

    CN116383047A

  • Fuzzy testing method based on code vulnerability perception

    CN117332428A

  • Fuzzy testing method, device and storage medium based on code similarity

    JP7290784B1

  • Machine learning for constrained mutation-based FUZZ testing

    US20180365139A1