Firmware testing method and device

By clustering and mutating the seed file message fragments of the IoT device firmware, a targeted test case set is generated, which solves the problem of the lack of pertinence of traditional test cases for firmware vulnerabilities and significantly improves testing efficiency.

CN118132453BActive Publication Date: 2024-08-27CHINA MOBILEHANGZHOUINFORMATION TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410573845.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-10
Publication Date
2024-08-27
Estimated Expiration
2044-05-10

AI Technical Summary

Technical Problem

The test cases generated by traditional fuzz testing methods lack specificity for potential vulnerabilities in IoT device firmware, resulting in low testing efficiency.

Method used

By clustering message fragments in multiple seed files, target clusters corresponding to the potential vulnerability types of the firmware to be tested are generated, and the optimal mutation strategy is used to mutate the message fragments in these clusters. Generate a targeted set of test cases to test the firmware under test.

Benefits of technology

It improves the pertinence of test cases to the firmware under test, reduces the number of untargeted test cases, and significantly improves testing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118132453B
    Figure CN118132453B
Patent Text Reader

Abstract

The present application relates to the field of computer technology, and provides a firmware testing method and device. The method comprises: clustering message fragments in multiple seed files to generate multiple target clustering clusters; the multiple target clustering clusters correspond one-to-one to multiple potential vulnerability types of the firmware to be tested; mutating the message fragments in the multiple target clustering clusters according to the optimal mutation strategy to generate multiple test case sets; the multiple test case sets correspond one-to-one to the multiple target clustering clusters; and using the multiple test case sets to test the firmware to be tested. The firmware testing method and device provided in the present application can effectively improve the pertinence of the test cases to the potential vulnerabilities of the firmware to be tested, reduce the number of non-targeted test cases, and greatly improve the test efficiency when using these test cases to test the firmware to be tested.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a firmware testing method and device. Background Art

[0002] With the development of 5G technology, IoT devices are widely used in various fields of daily life. At the same time, IoT devices also bring many security issues. Due to their poor performance and diverse architectures, traditional security analysis techniques cannot be applied to the security analysis of IoT device firmware programs, which makes the vulnerability mining efficiency of IoT devices generally low.

[0003] The traditional firmware security vulnerability mining process is mainly implemented through two methods: manual reverse analysis and automated fuzz testing. In the fuzz testing method, test cases need to be generated first, and the firmware is tested using the test cases. However, the traditional fuzz testing method usually generates test cases by random generation or template generation. These methods can generate a large number of test cases, but these test cases are less targeted at the potential vulnerabilities of the firmware to be tested. Using a large number of non-targeted test cases to test the firmware to be tested will lead to low test efficiency. Summary of the invention

[0004] The embodiments of the present application provide a firmware testing method and device to solve the technical problem that the test cases generated by the traditional fuzz testing method are poorly targeted at the potential vulnerabilities of the firmware to be tested, and that the use of a large number of non-targeted test cases to test the firmware to be tested will lead to low testing efficiency.

[0005] In a first aspect, an embodiment of the present application provides a firmware testing method, including:

[0006] Clustering message fragments in a plurality of seed files to generate a plurality of target clusters; the plurality of target clusters correspond one to one to a plurality of potential vulnerability types of the firmware to be tested;

[0007] Mutating the message fragments in the multiple target clusters according to the optimal mutation strategy to generate multiple test case sets; the multiple test case sets correspond to the multiple target clusters one by one;

[0008] The firmware to be tested is tested using the multiple test case sets.

[0009] In one embodiment, clustering the message fragments in the plurality of seed files to generate a plurality of target clusters includes:

[0010] Inserting a message segment in any seed file into the message segment of the firmware to be tested to generate a target message segment;

[0011] Mutating the target message segment byte by byte to generate multiple mutated message segments;

[0012] Testing the firmware to be tested using the multiple variant message segments to obtain multiple test responses of the firmware to be tested;

[0013] Parsing the multiple test responses into multiple features, and using features with higher occurrence frequencies among the multiple features to form a feature vector of a message fragment in any one of the seed files;

[0014] Clustering the message fragments in the multiple seed files according to the edit distances between the feature vectors of the message fragments in the multiple seed files to generate multiple clusters;

[0015] The plurality of target clusters are generated according to the plurality of clusters.

[0016] In one embodiment, generating the plurality of target clusters according to the plurality of cluster clusters includes:

[0017] generating a plurality of new message segments according to any one of the plurality of clusters;

[0018] Aggregating the multiple new message fragments into a new cluster of any cluster;

[0019] The plurality of clustering clusters and newly generated clustering clusters of the plurality of clustering clusters are determined as the plurality of target clustering clusters.

[0020] In one embodiment, the optimal mutation strategy is determined based on the following method:

[0021] Generate a value function of any seed file based on the firmware running state and mutation action corresponding to any seed file;

[0022] Generate a value function matrix according to the value functions of the plurality of seed files;

[0023] Iterating the value function matrix, and if the value function matrix converges, determining the value function matrix at this time as the optimal mutation strategy;

[0024] The firmware running state is the running state of the firmware to be tested when the firmware to be tested is tested using any one of the seed files as a test case, and the mutation action is a mutation operation performed on any one of the seed files.

[0025] In one embodiment, iterating the value function matrix includes:

[0026] Selecting a current mutation action according to the current firmware running states corresponding to the multiple seed files;

[0027] Executing corresponding current mutation actions on the plurality of seed files to generate a plurality of mutated seed files of the plurality of seed files;

[0028] Determine the firmware running states corresponding to the multiple variant seed files as new current firmware running states corresponding to the multiple seed files;

[0029] After selecting a new current mutation action according to the new current firmware running state, and updating the value function matrix according to the new current firmware running state and the new current mutation action, return to the step of executing the corresponding current mutation action on the multiple seed files to generate multiple mutation seed files of the multiple seed files.

[0030] In one embodiment, after the firmware to be tested is tested using the multiple test case sets, the following steps are included:

[0031] Obtaining execution information of any test case in the plurality of test case sets in the firmware to be tested;

[0032] Acquire the path triggering condition of any test case according to the execution information;

[0033] If any of the test cases triggers a new path, then the test case is added as a seed file to the seed file pool;

[0034] If any of the test cases does not trigger a new path, use the test case as a seed file, generate a value function for the test case based on the firmware running state and mutation action corresponding to the test case, and add the value function for the test case to the value function matrix.

[0035] In one embodiment, after obtaining the execution information of any test case in the plurality of test case sets in the firmware to be tested, the method includes:

[0036] Calculate the path coverage of any test case according to the execution information;

[0037] If the path coverage is higher than the coverage threshold, any test case is determined as a high-quality test case.

[0038] In a second aspect, an embodiment of the present application provides a firmware testing device, including:

[0039] A clustering module, used to: cluster message fragments in a plurality of seed files to generate a plurality of target clusters; the plurality of target clusters correspond one to one with a plurality of potential vulnerability types of the firmware to be tested;

[0040] A mutation module, used to: mutate the message fragments in the multiple target clusters according to the optimal mutation strategy to generate multiple test case sets; the multiple test case sets correspond to the multiple target clusters one by one;

[0041] The testing module is used to test the firmware to be tested using the multiple test case sets.

[0042] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory storing a computer program, wherein the processor implements the steps of the firmware testing method described in the first aspect when executing the program.

[0043] In a fourth aspect, an embodiment of the present application provides a computer program product, including a computer program, which implements the steps of the firmware testing method described in the first aspect when executed by a processor.

[0044] In a fifth aspect, an embodiment of the present application provides a non-transitory computer-readable storage medium, including a computer program, which, when executed by a processor, implements the steps of the firmware testing method described in the first aspect.

[0045] The firmware testing method and device provided by the present application clusters the message fragments in multiple seed files to generate multiple target clustering clusters, mutates the message fragments in the multiple target clustering clusters according to the optimal mutation strategy, generates multiple test case sets, and uses the multiple test case sets to test the firmware to be tested. The present application clusters the message fragments in the seed files into clustering clusters corresponding one-to-one to the potential vulnerability types of the firmware to be tested, and then mutates the message fragments in each clustering cluster using the optimal mutation strategy to generate a test case set corresponding one-to-one to the clustering cluster. Then, a test case set corresponding one-to-one to the potential vulnerability types of the firmware to be tested can be obtained, which effectively improves the pertinence of the test cases to the potential vulnerabilities of the firmware to be tested, reduces the number of non-targeted test cases, and greatly improves the test efficiency when these test cases are used to test the firmware to be tested. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the technical solutions in the present application or the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. 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.

[0047] Figure 1 This is one of the flowcharts of the firmware testing method provided in the embodiment of the present application;

[0048] Figure 2This is the second flowchart of the firmware testing method provided in the embodiment of the present application;

[0049] Figure 3 This is the third flowchart of the firmware testing method provided in the embodiment of the present application;

[0050] Figure 4 This is the fourth flowchart of the firmware testing method provided in the embodiment of the present application;

[0051] Figure 5 is a schematic diagram of the structure of a firmware testing device provided in an embodiment of the present application;

[0052] Figure 6 It is a schematic diagram of the test flow in the firmware testing device provided in an embodiment of the present application;

[0053] Figure 7 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0054] 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 the embodiments of 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.

[0055] Figure 1 This is one of the flowcharts of the firmware testing method provided in the embodiment of the present application. Figure 1 , an embodiment of the present application provides a firmware testing method, which may include:

[0056] 101. Clustering message fragments in multiple seed files to generate multiple target clusters;

[0057] Multiple target clusters correspond one-to-one to multiple potential vulnerability types of the firmware to be tested;

[0058] 102. Mutate message fragments in multiple target clusters according to the optimal mutation strategy to generate multiple test case sets;

[0059] Multiple test case sets correspond one-to-one to multiple target clusters;

[0060] 103. Use multiple test case sets to test the firmware under test.

[0061] In step 101, the plurality of seed files are original samples randomly selected from a seed file pool and conform to the input format of the firmware to be tested, and the message fragments are program code fragments of the seed files.

[0062] In step 102, mutation refers to making a small-scale controlled modification to the message fragment to improve the path coverage of the test case and the probability of triggering the security vulnerability of the firmware to be tested.

[0063] The firmware testing method provided in this embodiment clusters the message fragments in multiple seed files to generate multiple target clustering clusters, mutates the message fragments in the multiple target clustering clusters according to the optimal mutation strategy, generates multiple test case sets, and uses the multiple test case sets to test the firmware to be tested. This embodiment clusters the message fragments in the seed files into clusters corresponding to the potential vulnerability types of the firmware to be tested, and then mutates the message fragments in each cluster using the optimal mutation strategy to generate a test case set corresponding to the cluster cluster. Then, a test case set corresponding to the potential vulnerability type of the firmware to be tested can be obtained, which effectively improves the pertinence of the test case to the potential vulnerabilities of the firmware to be tested, reduces the number of non-targeted test cases, and greatly improves the test efficiency when these test cases are used to test the firmware to be tested.

[0064] Figure 2 This is the second flow chart of the firmware testing method provided in the embodiment of the present application. Figure 2 In one embodiment, clustering message fragments in multiple seed files to generate multiple target clusters may include:

[0065] 201. Insert a message segment in any seed file into a message segment of the firmware to be tested to generate a target message segment;

[0066] 202. Mutate the target message segment byte by byte to generate multiple mutated message segments;

[0067] 203. Testing the firmware to be tested using multiple variant message fragments to obtain multiple test responses of the firmware to be tested;

[0068] 204. Parse the multiple test responses into multiple features, and use the features with higher occurrence frequencies among the multiple features to form a feature vector of the message fragment in the seed file;

[0069] 205. Clustering the message fragments in the multiple seed files according to the edit distances between the feature vectors of the message fragments in the multiple seed files to generate multiple clusters;

[0070] 206. Generate multiple target clusters based on the multiple cluster clusters.

[0071] In step 202, a mutated message segment is generated each time a byte is mutated, and after all bytes are mutated, multiple mutated message segments are generated. It should be noted that when a certain byte is mutated, the other bytes keep their initial states in the target message segment unchanged.

[0072] In addition, it is necessary to first ensure that the target message segment meets the grammatical requirements before starting the byte-by-byte mutation.

[0073] In step 203 to step 206, since each mutation only targets one byte in the target message segment, if two generated mutated message segments obtain the same test response during the test of the firmware to be tested, it means that the two mutated bytes in the two mutated message segments are highly likely to be related to the code segments that implement the same function in the firmware to be tested. Therefore, features related to the functional points in the firmware to be tested can be extracted based on a variety of test responses. Since different functional points can trigger different firmware vulnerability types, the extracted features can be associated with the firmware vulnerability types, thereby associating the feature vectors of the message segments in the seed file with the firmware vulnerability types, and finally, through clustering, the target clustering clusters are matched one-to-one with the potential vulnerability types of the firmware to be tested.

[0074] Specifically:

[0075] In step 204, the feature can be a field or an attribute. Each test response can be parsed into multiple fields or multiple attributes according to the data structure and grammatical rules of the firmware to be tested. Taking the field as an example, a test response can be parsed into multiple fields, the frequency of occurrence of multiple fields is counted, and the frequency of occurrence is sorted from large to small. Several fields with the highest order are selected to form a feature vector of the message fragment in the corresponding seed file.

[0076] In step 205, the edit distance refers to the minimum number of edit operations required to convert one string into another. Permitted edit operations include replacing one character with another, inserting a character, and deleting a character. The smaller the edit distance, the more similar the two strings are. The string distance can be calculated according to the following formula: Before Characters and strings Before The edit distance between characters :

[0077] ; (2-1)

[0078] in, is an indicator function, Is a string No. characters, Is a string No. When the two are different, the indicator function value is 1, and when the two are the same, the indicator function value is 0.

[0079] Assume the string There are 5 characters in total, string There are 3 characters in total, calculate the string With string The edit distance between the two is the calculated string The first 5 characters and string The edit distance between the first three characters can be calculated using the formula (2-1).

[0080] By applying the above method to the calculation of the edit distance between two feature vectors, feature vectors with close edit distances can be aggregated into a cluster, thereby realizing the clustering of message fragments in multiple seed files.

[0081] This embodiment generates a mutated message segment by mutating the target message segment byte by byte, and obtains the test response of the firmware to be tested to the mutated message segment, thereby extracting features that are highly correlated with the firmware vulnerability type, thereby associating the feature vectors of the message segment in the seed file with the firmware vulnerability type, clustering the feature vectors with high similarity through edit distance clustering, and realizing clustering of the message segments in the corresponding seed file, ultimately making the target clustering clusters and the potential vulnerability types of the firmware to be tested accurately correspond one by one.

[0082] In one embodiment, generating multiple target clusters according to multiple cluster clusters may include:

[0083] A plurality of new message segments are generated according to any cluster among the plurality of clusters, the plurality of new message segments are aggregated into a new cluster of the cluster, and the plurality of clusters and the new cluster of the plurality of clusters are determined as a plurality of target clusters.

[0084] This embodiment generates multiple new message fragments through the message fragments in each cluster. Since the message fragments in the cluster are highly similar, they can learn from each other in the process of generating new message fragments, further improving the similarity between the new message fragments, thereby further improving the targeting of potential firmware vulnerabilities. These new message fragments are used as new clusters and used together with the original clusters as target clusters, which can improve the overall targeting of the target cluster for potential firmware vulnerabilities, help to generate targeted test cases later, and improve testing efficiency.

[0085] Figure 3 This is the third flow chart of the firmware testing method provided in the embodiment of the present application. Figure 3 In one embodiment, the optimal mutation strategy can be determined based on the following method:

[0086] 301. Generate a value function of any seed file based on the firmware running state and mutation action corresponding to the seed file;

[0087] 302. Generate a value function matrix according to the value functions of the plurality of seed files;

[0088] 303. Iterate the value function matrix. If the value function matrix converges, the value function matrix at this time is determined as the optimal mutation strategy.

[0089] The firmware running state is the running state of the firmware to be tested when the seed file is used as a test case to test the firmware to be tested, and the mutation action is the mutation operation performed on the seed file.

[0090] In step 301, the firmware running status corresponding to any seed file can be Indicates that the mutation action can be used Represented as, then the value function of the seed file can be expressed as .

[0091] It should be noted that the mutation operation performed on the seed file may include replacing a portion of code in the seed file, inserting new code into the seed file, and deleting a portion of code in the seed file.

[0092] In step 303, the process of iterating the value function matrix is ​​as follows:

[0093] 303a, selecting a current mutation action according to the current firmware running states corresponding to the multiple seed files;

[0094] 303b, executing the corresponding current mutation action on the multiple seed files to generate multiple mutation seed files of the multiple seed files;

[0095] 303c, determining the firmware running states corresponding to the multiple variant seed files as new current firmware running states corresponding to the multiple seed files;

[0096] 303d. Select a new current mutation action according to the new current firmware running state, and update the value function matrix according to the new current firmware running state and the new current mutation action, and then return to step 303b.

[0097] For any seed file, the above iterative process can be expressed by the following formula:

[0098] ; (3-1)

[0099] in, is the learning factor, and its value range is , is the current firmware running status of the seed file. is the current mutation action of the seed file, is the new current firmware running status of the seed file, is the new current mutation action of the seed file, Yes Execution The subsequent reward value, if executed After that, a mutation seed file is generated. When the mutation seed file is used as a test case to test the firmware under test, if the test case can be executed correctly and triggers a vulnerability or error, Set to a positive number. If the variant seed file is used as a test case to test the firmware under test, and the test case cannot be executed correctly or cannot trigger a vulnerability or error, Set to a negative number, is the discount factor, and its value range is , the larger the value, the more attention is paid to future rewards, and the smaller the value, the more attention is paid to immediate rewards. , and Can be adjusted according to actual situation.

[0100] For each value function in the value function matrix, iteration as shown in formula (3-1) is performed synchronously to implement iteration of the entire value function matrix, and finally the converged value function matrix is ​​determined as the optimal mutation strategy.

[0101] This embodiment iterates the value function matrix generated by the value functions of multiple seed files. It can adjust the mutation action according to the changes of various parameters during the iteration process, and then adjust the firmware running state according to the mutation action, so that the value function matrix gradually converges, and the value function matrix at the time of convergence is used as the optimal mutation strategy, that is, the mutation action that can obtain the maximum benefit for multiple seed files is obtained.

[0102] Figure 4 This is the fourth flow chart of the firmware testing method provided in the embodiment of the present application. Figure 4 In one embodiment, after the firmware to be tested is tested using multiple test case sets, the following may be included:

[0103] 401. Obtain execution information of any test case in a plurality of test case sets in the firmware to be tested;

[0104] 402. Obtain the path triggering status of the test case according to the execution information;

[0105] 403. If the test case triggers a new path, the test case is added to the seed file pool as a seed file;

[0106] 404. If the test case does not trigger a new path, the test case is used as a seed file, and a value function of the test case is generated based on the firmware running state and mutation action corresponding to the test case, and the value function of the test case is added to the value function matrix.

[0107] In step 401, execution information may be obtained through an instrumentation program.

[0108] It should be noted that, in actual applications, there is no strict timing relationship between step 403 and step 404; that is, they can be executed simultaneously, or any one of the steps can be executed first, depending on actual needs and is not limited here.

[0109] In this embodiment, the test cases are processed differently according to the path triggering conditions of the test cases. If the test case can trigger a new path, it means that the test case has a greater probability of discovering vulnerabilities on the new path, and the quality of the test case is good. Adding it to the seed file pool can improve the effectiveness of the seed file, which is helpful for a series of subsequent clustering and iterative operations, and ultimately generates more targeted test cases to improve test efficiency. If the test case cannot trigger a new path, it means that there is room for improvement in the effectiveness of the test case, and then its value function is generated and added to the value function matrix for iteration, and the mutation strategy is further optimized, so that after the subsequent mutation of the message fragments in the clustering cluster, more targeted test cases can be generated to improve test efficiency.

[0110] In one embodiment, after obtaining the execution information of any test case in the firmware to be tested in the plurality of test case sets, the following steps may be included:

[0111] The path coverage of the test case is calculated according to the execution information. If the path coverage is higher than the coverage threshold, the test case is determined as a high-quality test case.

[0112] This embodiment evaluates the quality of test cases by their path coverage, which helps to screen out high-quality test cases with high path coverage, increases the probability of discovering firmware security vulnerabilities, and promotes the generation of test data for high-quality test cases.

[0113] The firmware testing device provided in an embodiment of the present application is described below. The firmware testing device described below and the firmware testing method described above can refer to each other.

[0114] Figure 5 is a schematic diagram of the structure of a firmware testing device provided in an embodiment of the present application;

[0115] Figure 6It is a schematic diagram of the test flow in the firmware testing device provided in an embodiment of the present application.

[0116] Reference Figure 5 , an embodiment of the present application provides a firmware testing device, which may include:

[0117] The clustering module 501 is used to cluster the message fragments in the plurality of seed files to generate a plurality of target clusters; the plurality of target clusters correspond one to one with the plurality of potential vulnerability types of the firmware to be tested;

[0118] The mutation module 502 is used to: mutate the message segments in the multiple target clusters according to the optimal mutation strategy to generate multiple test case sets; the multiple test case sets correspond to the multiple target clusters one by one;

[0119] The testing module 503 is used to test the firmware to be tested using the multiple test case sets.

[0120] The firmware testing device provided in this embodiment clusters the message fragments in multiple seed files to generate multiple target clustering clusters, mutates the message fragments in the multiple target clustering clusters according to the optimal mutation strategy, generates multiple test case sets, and uses the multiple test case sets to test the firmware to be tested. This embodiment clusters the message fragments in the seed files into clustering clusters corresponding to the potential vulnerability types of the firmware to be tested, and then mutates the message fragments in each clustering cluster using the optimal mutation strategy to generate a test case set corresponding to the clustering cluster. Then, a test case set corresponding to the potential vulnerability type of the firmware to be tested can be obtained, which effectively improves the pertinence of the test case to the potential vulnerabilities of the firmware to be tested, reduces the number of non-targeted test cases, and greatly improves the test efficiency when these test cases are used to test the firmware to be tested.

[0121] In one embodiment, the clustering module 501 is specifically configured to:

[0122] Inserting a message segment in any seed file into the message segment of the firmware to be tested to generate a target message segment;

[0123] Mutating the target message segment byte by byte to generate multiple mutated message segments;

[0124] Testing the firmware to be tested using the multiple variant message segments to obtain multiple test responses of the firmware to be tested;

[0125] Parsing the multiple test responses into multiple features, and using features with higher occurrence frequencies among the multiple features to form a feature vector of a message fragment in any one of the seed files;

[0126] Clustering the message fragments in the multiple seed files according to the edit distances between the feature vectors of the message fragments in the multiple seed files to generate multiple clusters;

[0127] The plurality of target clusters are generated according to the plurality of clusters.

[0128] In one embodiment, the clustering module 501 is specifically configured to:

[0129] generating a plurality of new message segments according to any one of the plurality of clusters;

[0130] Aggregating the multiple new message fragments into a new cluster of any cluster;

[0131] The plurality of clustering clusters and newly generated clustering clusters of the plurality of clustering clusters are determined as the plurality of target clustering clusters.

[0132] In one embodiment, it also includes an optimal mutation strategy generation module ( Figure 5 not shown) for:

[0133] Generate a value function of any seed file based on the firmware running state and mutation action corresponding to any seed file;

[0134] Generate a value function matrix according to the value functions of the plurality of seed files;

[0135] Iterating the value function matrix, and if the value function matrix converges, determining the value function matrix at this time as the optimal mutation strategy;

[0136] The firmware running state is the running state of the firmware to be tested when the firmware to be tested is tested using any one of the seed files as a test case, and the mutation action is a mutation operation performed on any one of the seed files.

[0137] In one embodiment, the optimal mutation strategy generation module is specifically used to:

[0138] Selecting a current mutation action according to the current firmware running states corresponding to the multiple seed files;

[0139] Executing corresponding current mutation actions on the plurality of seed files to generate a plurality of mutated seed files of the plurality of seed files;

[0140] Determine the firmware running states corresponding to the multiple variant seed files as new current firmware running states corresponding to the multiple seed files;

[0141] After selecting a new current mutation action according to the new current firmware running state, and updating the value function matrix according to the new current firmware running state and the new current mutation action, return to the step of executing the corresponding current mutation action on the multiple seed files to generate multiple mutation seed files of the multiple seed files.

[0142] In one embodiment, a test case processing module is also included ( Figure 5 not shown) for:

[0143] Obtaining execution information of any test case in the plurality of test case sets in the firmware to be tested;

[0144] Acquire the path triggering condition of any test case according to the execution information;

[0145] If any of the test cases triggers a new path, then the test case is added as a seed file to the seed file pool;

[0146] If any of the test cases does not trigger a new path, use the test case as a seed file, generate a value function for the test case based on the firmware running state and mutation action corresponding to the test case, and add the value function for the test case to the value function matrix.

[0147] In one embodiment, the test case processing module is specifically used to:

[0148] Calculate the path coverage of any test case according to the execution information;

[0149] If the path coverage is higher than the coverage threshold, any test case is determined as a high-quality test case.

[0150] Reference Figure 6 ,The firmware testing device also includes a seed selection module, which is used to randomly select multiple seed files from the seed file pool and synchronously send the multiple seed files to the clustering module and the optimal mutation strategy generation module. In addition, the seed selection module is also used to collect the firmware running status corresponding to the seed file and send the firmware running status to the optimal mutation strategy generation module;

[0151] The optimal mutation strategy generation module includes a state monitoring module, a learning module, a mutation strategy generation module and a mutation strategy execution module, wherein the state monitoring module is used to detect the current firmware running state corresponding to the seed file, the learning module is used to adjust the learning factor, the mutation strategy generation module is used to select the current mutation action, and the mutation strategy execution module is used to execute the current mutation action. The state detection module, the learning module, the mutation strategy generation module and the mutation strategy execution module run in a loop to finally generate the optimal mutation strategy, that is, the optimal mutation strategy generation module is used to generate the optimal mutation strategy and send the optimal mutation strategy to the mutation module;

[0152] The clustering module is used to cluster the message fragments in the multiple seed files, generate multiple target clusters corresponding to multiple potential vulnerability types of the firmware to be tested, and send the target clusters to the mutation module;

[0153] The mutation module is used to execute the optimal mutation strategy, mutate the message fragments in multiple target clusters, and generate multiple test case sets corresponding to the multiple target clusters, that is, corresponding to the multiple potential vulnerability types of the firmware to be tested;

[0154] These test case sets are used to test the firmware to be tested, and the execution information of the test cases is obtained using the stub program. Each test case is processed differently based on this information. If a test case triggers a new path, it is added to the seed file pool. If the test case does not trigger a new path, its value function is generated and added to the optimal mutation strategy generation module to participate in the iteration of the value function matrix.

[0155] Figure 7 An example of a structural diagram of an electronic device is shown in FIG. Figure 7 As shown, the electronic device may include: a processor 710, a communication interface 720, a memory 730 and a communication bus 740, wherein the processor 710, the communication interface 720 and the memory 730 communicate with each other through the communication bus 740. The processor 710 may call a computer program in the memory 730 to execute the steps of the firmware testing method, for example including:

[0156] Clustering message fragments in a plurality of seed files to generate a plurality of target clusters; the plurality of target clusters correspond one to one to a plurality of potential vulnerability types of the firmware to be tested;

[0157] Mutating the message fragments in the multiple target clusters according to the optimal mutation strategy to generate multiple test case sets; the multiple test case sets correspond to the multiple target clusters one by one;

[0158] The firmware to be tested is tested using the multiple test case sets.

[0159] In addition, the logic instructions in the above-mentioned memory 730 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.

[0160] On the other hand, an embodiment of the present application further provides a computer program product, the computer program product including a computer program, the computer program can be stored on a non-transitory computer-readable storage medium, and when the computer program is executed by a processor, the computer can perform the steps of the firmware testing method provided in the above embodiments, for example, including:

[0161] Clustering message fragments in a plurality of seed files to generate a plurality of target clusters; the plurality of target clusters correspond one to one to a plurality of potential vulnerability types of the firmware to be tested;

[0162] Mutating the message fragments in the multiple target clusters according to the optimal mutation strategy to generate multiple test case sets; the multiple test case sets correspond to the multiple target clusters one by one;

[0163] The firmware to be tested is tested using the multiple test case sets.

[0164] On the other hand, an embodiment of the present application further provides a processor-readable storage medium, wherein the processor-readable storage medium stores a computer program, wherein the computer program is used to enable the processor to execute the steps of the methods provided in the above embodiments, for example, including:

[0165] Clustering message fragments in a plurality of seed files to generate a plurality of target clusters; the plurality of target clusters correspond one to one to a plurality of potential vulnerability types of the firmware to be tested;

[0166] Mutating the message fragments in the multiple target clusters according to the optimal mutation strategy to generate multiple test case sets; the multiple test case sets correspond to the multiple target clusters one by one;

[0167] The firmware to be tested is tested using the multiple test case sets.

[0168] The processor-readable storage medium can be any available medium or data storage device that can be accessed by the processor, including but not limited to magnetic storage (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc.), optical storage (such as CD, DVD, BD, HVD, etc.), and semiconductor storage (such as ROM, EPROM, EEPROM, non-volatile memory (NANDFLASH), solid-state drive (SSD)), etc.

[0169] 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.

[0170] 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.

[0171] 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 firmware testing method, characterized in that: include: Clustering message fragments in multiple seed files to generate multiple target clusters; The multiple target clusters correspond one-to-one to multiple potential vulnerability types of the firmware to be tested; Mutating the message fragments in the multiple target clusters according to the optimal mutation strategy to generate multiple test case sets; the multiple test case sets correspond to the multiple target clusters one by one; Testing the firmware to be tested using the multiple test case sets; The message fragment is a program code fragment of the seed file; The clustering of message fragments in multiple seed files to generate multiple target clusters includes: Inserting a message segment in any seed file into the message segment of the firmware to be tested to generate a target message segment; Mutating the target message segment byte by byte to generate multiple mutated message segments; Testing the firmware to be tested using the multiple variant message segments to obtain multiple test responses of the firmware to be tested; Parsing the multiple test responses into multiple features, and using features with higher occurrence frequencies among the multiple features to form a feature vector of a message fragment in any one of the seed files; Clustering the message fragments in the multiple seed files according to the edit distances between the feature vectors of the message fragments in the multiple seed files to generate multiple clusters; generating the plurality of target clusters according to the plurality of cluster clusters; The optimal mutation strategy is determined based on the following method: Generate a value function of any seed file based on the firmware running state and mutation action corresponding to any seed file; Generate a value function matrix according to the value functions of the plurality of seed files; Iterating the value function matrix, and if the value function matrix converges, determining the value function matrix at this time as the optimal mutation strategy; The firmware running state is the running state of the firmware to be tested when the firmware to be tested is tested using any one of the seed files as a test case, and the mutation action is a mutation operation performed on any one of the seed files.

2. The firmware testing method according to claim 1, characterized in that: The generating the plurality of target clusters according to the plurality of cluster clusters comprises: generating a plurality of new message segments according to any one of the plurality of clusters; Aggregating the multiple new message fragments into a new cluster of any cluster; The plurality of clustering clusters and newly generated clustering clusters of the plurality of clustering clusters are determined as the plurality of target clustering clusters.

3. The firmware testing method according to claim 1, characterized in that: The iterating the value function matrix comprises: Selecting a current mutation action according to the current firmware running states corresponding to the multiple seed files; Executing corresponding current mutation actions on the plurality of seed files to generate a plurality of mutated seed files of the plurality of seed files; Determine the firmware running states corresponding to the multiple variant seed files as new current firmware running states corresponding to the multiple seed files; After selecting a new current mutation action according to the new current firmware running state, and updating the value function matrix according to the new current firmware running state and the new current mutation action, return to the step of executing the corresponding current mutation action on the multiple seed files to generate multiple mutation seed files of the multiple seed files.

4. The firmware testing method according to claim 1, characterized in that: After the firmware to be tested is tested by using the multiple test case sets, the method includes: Obtaining execution information of any test case in the plurality of test case sets in the firmware to be tested; Acquire the path triggering condition of any test case according to the execution information; If any of the test cases triggers a new path, then the test case is added as a seed file to the seed file pool; If any of the test cases does not trigger a new path, use the test case as a seed file, generate a value function for the test case based on the firmware running state and mutation action corresponding to the test case, and add the value function for the test case to the value function matrix.

5. The firmware testing method according to claim 4, characterized in that: After obtaining the execution information of any test case in the plurality of test case sets in the firmware to be tested, the method includes: Calculate the path coverage of any test case according to the execution information; If the path coverage is higher than the coverage threshold, any test case is determined as a high-quality test case.

6. A firmware testing device, characterized in that: include: A clustering module is used to: cluster message fragments in multiple seed files to generate multiple target clusters; The multiple target clusters correspond one-to-one to multiple potential vulnerability types of the firmware to be tested; A mutation module, used to: mutate the message fragments in the multiple target clusters according to the optimal mutation strategy to generate multiple test case sets; the multiple test case sets correspond to the multiple target clusters one by one; A testing module, used to: test the firmware to be tested using the multiple test case sets; The message fragment is a program code fragment of the seed file; The clustering of message fragments in multiple seed files to generate multiple target clusters includes: Inserting a message segment in any seed file into the message segment of the firmware to be tested to generate a target message segment; Mutating the target message segment byte by byte to generate multiple mutated message segments; Testing the firmware to be tested using the multiple variant message segments to obtain multiple test responses of the firmware to be tested; Parsing the multiple test responses into multiple features, and using features with higher occurrence frequencies among the multiple features to form a feature vector of a message fragment in any one of the seed files; Clustering the message fragments in the multiple seed files according to the edit distances between the feature vectors of the message fragments in the multiple seed files to generate multiple clusters; generating the plurality of target clusters according to the plurality of cluster clusters; The optimal mutation strategy is determined based on the following method: Generate a value function of any seed file based on the firmware running state and mutation action corresponding to any seed file; Generate a value function matrix according to the value functions of the plurality of seed files; Iterating the value function matrix, and if the value function matrix converges, determining the value function matrix at this time as the optimal mutation strategy; The firmware running state is the running state of the firmware to be tested when the firmware to be tested is tested using any one of the seed files as a test case, and the mutation action is a mutation operation performed on any one of the seed files.

7. An electronic device comprising a processor and a memory storing a computer program, characterized in that: When the processor executes the computer program, the steps of the firmware testing method according to any one of claims 1 to 5 are implemented.

8. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the firmware testing method according to any one of claims 1 to 5 are 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 steps of the firmware testing method according to any one of claims 1 to 5 are implemented.