Method and apparatus for generating fuzzy test case
By preprocessing and model training of industrial protocol data packets, and combining genetic variation algorithms to generate fuzzy test cases, the problems of insufficient data volume and poor adaptability in industrial protocol fuzz testing are solved, and the feature learning and testing capabilities of industrial protocols are improved. Adapt to multiple protocol structures.
Patent Information
- Application Number
- PCT/CN2023/118551
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-05-10
- Filing Date
- 2023-09-13
- Publication Date
- 2024-11-14
AI Technical Summary
The amount of effective data for fuzz testing in existing industrial protocols is limited, and the machine learning model is not applicable, requiring a large amount of data for training, and it is unable to adapt to multiple protocols, making it difficult to quickly identify and deal with potential problems with security risks in industrial control systems. .
By collecting industrial protocol data packets, preprocessing and generating protocol entries, building a task set and model training, generating the best initialization parameters, building a hierarchical clustering model, combining genetic variation algorithms to generate fuzzy test cases, and improving the characteristics of industrial protocols Learning ability and adaptability.
When the number of industrial protocols learned and trained is small, the threshold for testers to use fuzz testing tools is lowered, the targetedness of industrial protocols is improved, the ability to adapt to unknown industrial protocol structure types is enhanced, and the fuzz testing of industrial protocols is enhanced. ability.
Smart Images

Figure CN2023118551_14112024_PF_FP_ABST
Abstract
Description
A method and device for generating fuzzy test cases Technical Field
[0001] The present invention relates to the field of fuzzy testing technology, and in particular to a method and device for generating fuzzy test cases. Background Art
[0002] Fuzz testing is an automatic or semi-automatic testing technology that is often used to discover errors and security issues in software / operating system / network code. The data used to input random and illegal data is called "FUZZ".
[0003] Industrial control networks are unique to industrial control systems, and industrial communication protocols are the cornerstone of these networks. However, most communication protocols lack security regulations. Therefore, security fuzz testing of industrial communication protocols is essential to identify potential security risks. This allows for timely response measures, prevents further exploitation, and reduces the likelihood of exploitation of security risks within industrial control systems.
[0004] Current fuzz testing techniques primarily focus on use case generation. Fuzzers used for fuzz testing fall into two categories: mutation-based fuzzers, which create test cases by mutating existing data samples; and generation-based fuzzers, which model the protocols or file formats used by the system under test, generate inputs based on the models, and create test cases accordingly. The main drawbacks of existing fuzzing techniques using machine learning are that they require rebuilding the training model for each new scenario, or manually exhaustively enumerating scenarios before training the model. Fuzz testing of industrial protocols requires testers to have a comprehensive and in-depth understanding of the industrial protocols in the market. Furthermore, the amount of effective data available for fuzz testing of industrial protocols is limited, making it unsuitable for machine learning models that require large amounts of data for training. Furthermore, the models have high spatial and temporal overhead, making them difficult to quickly migrate to new protocol scenarios and insufficiently adaptable to multiple protocols.
[0005] Summary of the Invention
[0006] Therefore, the technical solution of the present invention mainly solves the defects that the amount of effective data for fuzz testing of existing industrial protocols is limited, machine learning models that require a large amount of data for training are not suitable, and the current models cannot adapt to multiple protocols, thereby providing a method and device for generating fuzzy test cases.
[0007] In a first aspect, an embodiment of the present invention provides a method for generating a fuzzy test case, comprising:
[0008] Collecting industrial protocol data packets, preprocessing the industrial protocol data packets, and generating protocol entries;
[0009] Constructing an industrial protocol task set based on the protocol terms; wherein the data in each task in the industrial protocol task set includes a training data set and a test data set;
[0010] Obtaining initialization model parameters, and performing inner loop training and updating on the initial model based on the initialization model parameters, the training data set, and the test data set;
[0011] After the inner loop training is updated, the outer loop training of the initial model is updated to generate the optimal initialization parameters;
[0012] Building a hierarchical clustering model based on the optimal initialization parameters, inputting the collected unknown industrial protocols into the hierarchical clustering model to generate industrial protocol features;
[0013] Genetic mutation is performed on the industrial protocol features to generate fuzzy test cases.
[0014] An embodiment of the present invention provides a method for generating fuzzy test cases, which trains an industrial protocol task set to generate optimal initialization parameters, then uses a hierarchical clustering model constructed with the optimal initialization parameters to generate industrial protocol features, and finally performs genetic mutation on the industrial protocol features to generate fuzzy test cases. When the number of industrial protocols to be learned and trained is small, the ability to learn industrial protocol features is guaranteed, the threshold for testers to use fuzzy testing tools to test industrial protocols is lowered, the method can adapt to unknown industrial protocol structure types, and the targetedness of fuzzy testing of industrial protocols is improved.
[0015] In conjunction with the first aspect, in one possible implementation, preprocessing the industrial protocol data packet to generate a protocol entry includes:
[0016] Unpack the industrial protocol data packet and generate the industrial protocol message;
[0017] Segment the industrial protocol message according to bytes to generate a list of entries;
[0018] Determining a weight of each entry in the entry list based on the entry list and the industrial protocol message;
[0019] The weight of each term in the term list is sorted from large to small, and the protocol term is selected based on the sorting result.
[0020] In combination with the first aspect, in another possible implementation, determining the weight of each entry in the entry list based on the entry list and the industrial protocol message includes:
[0021] Obtain the total number of industrial protocol messages, the total number of words in the industrial protocol messages, and the number of industrial protocol messages containing each term, and calculate the weight of each term in the term list based on the number of times each term in the term list appears in the industrial protocol message, the total number of industrial protocol messages, the total number of words in the industrial protocol message, and the number of industrial protocol messages containing each term.
[0022] In combination with the first aspect, in another possible implementation, performing inner loop training and updating on the initial model based on the initialization model parameters, the training dataset, and the test dataset includes:
[0023] Training step: obtaining initialization model parameters, using the training data set as the input of the initial model, performing forward propagation on the initialization model parameters, and calculating the current loss function based on the prediction results of the forward propagation and the training labels;
[0024] First update step: based on the current loss function, update the initialized model parameters using the gradient descent method;
[0025] Inner loop step: add 1 to the number of inner loop iterations to generate the current number of iterations, compare the current number of iterations with the maximum number of updates of the inner loop, and when the current number of iterations does not reach the maximum number of updates of the inner loop, use the updated initialized model parameters as the initial parameters, repeat the training step and the first update step, otherwise perform outer loop training and update.
[0026] In combination with the first aspect, in another possible implementation, updating the initialized model parameters using a gradient descent method based on the current loss function includes:
[0027] The current loss function is differentiated to generate parameter gradients, and the gradient parameters are used to update the initialized model parameters.
[0028] In combination with the first aspect, in another possible implementation, after the inner loop training is updated, the outer loop training of the initial model is updated to generate the optimal initialization parameters, including:
[0029] A second updating step: using the test dataset as input to the initial model, generating a loss function for the test dataset in each task, summing the loss functions for the test dataset in each task to generate an outer loop loss function, and updating the initialized model parameters using a gradient descent method based on the outer loop loss function;
[0030] Outer loop step: Use the updated initialization model parameters as the initialization model parameters for the next inner loop, repeat the training step, the first update step, the inner loop step and the second update step until the number of cycles reaches the maximum training period of the outer loop, and generate the optimal initialization parameters.
[0031] In conjunction with the first aspect, in another possible implementation, performing genetic mutation on the industrial protocol features to generate fuzzy test cases includes:
[0032] Using the industrial protocol feature as a variant bit of the unknown industrial protocol;
[0033] The variant bits of the unknown industrial protocol are used as basic bits, and the unknown industrial protocol is mutated using a genetic mutation algorithm to generate the fuzzy test case.
[0034] In a second aspect, an embodiment of the present invention further provides a device for generating a fuzzy test case, comprising:
[0035] An acquisition module, configured to acquire industrial protocol data packets, pre-process the industrial protocol data packets, and generate protocol entries;
[0036] A construction module, configured to construct an industrial protocol task set based on the above-mentioned protocol terms; wherein the data in each task in the above-mentioned industrial protocol task set includes a training data set and a test data set;
[0037] An inner loop module is used to obtain initialization model parameters and perform inner loop training and update on the initial model based on the initialization model parameters, the training data set, and the test data set;
[0038] An outer loop module is used to perform outer loop training and update on the initial model after the inner loop training and update to generate the optimal initialization parameters;
[0039] A generation module, configured to construct a hierarchical clustering model based on the optimal initialization parameters, input the collected unknown industrial protocols into the hierarchical clustering model, and generate industrial protocol features;
[0040] The genetic mutation module is used to perform genetic mutation on the industrial protocol features to generate fuzzy test cases.
[0041] In the third aspect, an embodiment of the present invention also discloses an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the steps of a method for generating a fuzzy test case as described in the first aspect or any optional embodiment of the first aspect.
[0042] In a fourth aspect, an embodiment of the present invention further discloses a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of a method for generating a fuzzy test case as described in the first aspect or any optional embodiment of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0044] FIG1 is a flow chart of a method for generating a fuzzy test case provided by an embodiment of the present invention;
[0045] FIG2 is a flow chart of S101 according to an embodiment of the present invention;
[0046] FIG3 is a flow chart of S103 provided in an embodiment of the present invention;
[0047] FIG4 is a flow chart of S104 provided in an embodiment of the present invention;
[0048] FIG5 is a flow chart of S106 provided in an embodiment of the present invention;
[0049] FIG6 is a block diagram of a device for generating fuzzy test cases according to an embodiment of the present invention;
[0050] FIG7 is a diagram showing a specific example of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0051] The technical solution of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0052] An embodiment of the present invention provides a method for generating a fuzzy test case, as shown in FIG1 , comprising:
[0053] S101 : Collect industrial protocol data packets, pre-process the industrial protocol data packets, and generate protocol entries.
[0054] Among them, industrial protocol data packets containing multiple industrial protocol messages are captured from on-site real-time transmission and downloaded from the Internet.
[0055] S102 . Construct an industrial protocol task set based on the protocol terms; wherein the data in each task in the industrial protocol task set includes a training data set and a test data set.
[0056] Among them, the training data set is used to train a recognition model specific to the classification task; the test data set is used to obtain the adaptability of the model to the classification task. If the classification loss value is small, it means that the model has good adaptability to this task. Otherwise, it means that the model has poor adaptability and cannot meet the recognition requirements of the data.
[0057] S103: Obtain initialization model parameters, and perform inner loop training and update on the initial model based on the initialization model parameters, the training data set, and the test data set.
[0058] Specifically, multiple tasks are arbitrarily selected from the industrial protocol task set, and the training data sets of the multiple tasks are input into the initial model to realize the learning and training process of the multiple tasks.
[0059] S104: After the inner loop training is updated, the outer loop training of the initial model is updated to generate the optimal initialization parameters.
[0060] Among them, the optimal initialization parameters include parameters such as the number of clusters, affinity algorithm, and link algorithm.
[0061] S105 : constructing a hierarchical clustering model based on the above optimal initialization parameters, inputting the collected unknown industrial protocols into the above hierarchical clustering model, and generating industrial protocol features.
[0062] Specifically, the similarity between the best initialization parameters is calculated, the two best initialization parameters with higher similarity are merged to establish a new class, and the above steps are repeated until the stopping condition is met to obtain hierarchical categories and generate a hierarchical clustering model.
[0063] S106. Perform genetic mutation on the above industrial protocol features to generate fuzzy test cases.
[0064] This embodiment proposes a method for generating fuzzy test cases, which generates optimal initialization parameters by training an industrial protocol task set, and then generates industrial protocol features using a hierarchical clustering model constructed with the optimal initialization parameters. Finally, the industrial protocol features are genetically mutated to generate fuzzy test cases. When the number of industrial protocols to be learned and trained is small, the ability to learn industrial protocol features is guaranteed, the threshold for testers to use fuzzy testing tools to test industrial protocols is lowered, the method can adapt to unknown industrial protocol structure types, and the targetedness of fuzzy testing of industrial protocols is improved.
[0065] As an optional embodiment of the present invention, as shown in FIG2 , the above-mentioned S101, i.e., pre-processing the above-mentioned industrial protocol data packet to generate protocol entries, includes:
[0066] S1011 . Unpack the industrial protocol data packet to generate an industrial protocol message.
[0067] Specifically, the captured protocol data packets are unpacked to extract the messages of the specific application layer protocol, namely, the industrial protocol messages.
[0068] S1012: Segment the industrial protocol message according to bytes to generate a list of entries.
[0069] S1013: Determine the weight of each entry in the entry list based on the entry list and the industrial protocol message.
[0070] Specifically, the total number of industrial protocol messages, the total number of words in the industrial protocol messages and the number of industrial protocol messages containing each term are obtained, and the weight of each term in the above term list is calculated based on the number of times each term in the above term list appears in the above industrial protocol message, the total number of the above industrial protocol messages, the total number of words in the above industrial protocol message and the number of industrial protocol messages containing each term.
[0071] Furthermore, the weight of each entry in the entry list = (number of times a certain entry appears in the industrial protocol message / total number of words in the industrial protocol message)*log (total number of industrial protocol messages / (number of industrial protocol messages containing each entry+1)).
[0072] S1014. Sort the weights of the terms in the term list from large to small, and select the protocol term based on the sorting result.
[0073] Specifically, a preset number of protocol terms are selected from the sorting results, the protocol features and data types of the protocol terms are known and can be used to classify and mark data.
[0074] As an optional embodiment of the present invention, as shown in FIG3 , the above S103, i.e., performing inner loop training and updating on the initial model based on the above initialization model parameters, the above training data set, and the above test data set, includes:
[0075] S1031, training step: obtain the initialization model parameters, use the above training data set as the input of the initial model, perform forward propagation on the above initialization model parameters, and calculate the current loss function based on the prediction results of the forward propagation and the training labels.
[0076] Specifically, any task is selected from the industrial protocol task set, and the training data set in the task is input into the initial model.
[0077] S1032, first update step: based on the current loss function, update the initialization model parameters using the gradient descent method.
[0078] Specifically, the current loss function is differentiated to generate parameter gradients, and the gradient parameters are used to update the initialization model parameters, that is, the parameter gradients are propagated back to each network layer in the initial model to obtain updated parameters specific to the current task, that is, the updated initialization model parameters.
[0079] S1033, inner loop step: add 1 to the number of inner loop iterations to generate the current number of iterations, compare the current number of iterations with the maximum number of updates of the inner loop, and when the current number of iterations does not reach the maximum number of updates of the inner loop, use the updated initialized model parameters as the initial parameters, repeat the above training steps and the above first update step, otherwise perform outer loop training and update.
[0080] As an optional embodiment of the present invention, as shown in FIG4 , the above S104, i.e., after the above inner loop training and updating, the outer loop training and updating of the above initial model to generate the above optimal initialization parameters, includes:
[0081] S1041. Second update step: use the above test data set as the input of the initial model, generate a loss function under the test data set in each task, sum the loss functions under the test data set in each task, generate an outer loop loss function, and based on the outer loop loss function, use the gradient descent method to update the above initialized model parameters.
[0082] Specifically, the above test dataset is used as the input of the initial model, and the loss function generated under the test dataset in each task is the same as the above training steps.
[0083] Furthermore, the gradient descent algorithm is used to update the initialized model parameters to minimize the overall loss value. This parameter update process takes into account the applicability of the model to each task, and the updated parameters can be considered as common model parameters for all tasks in the inner loop.
[0084] S1042, outer loop step: use the updated initialization model parameters as the initialization model parameters for the next inner loop, repeat the training step, the first update step, the inner loop step, and the second update step until the number of loops reaches the maximum training period of the outer loop, and generate the above-mentioned optimal initialization parameters.
[0085] As an optional embodiment of the present invention, as shown in FIG5 , the above-mentioned S106, i.e., performing genetic mutation on the above-mentioned industrial protocol features to generate fuzzy test cases, includes:
[0086] S1061. Use the above industrial protocol features as the variant bits of the above unknown industrial protocol.
[0087] Specifically, a general communication message includes multiple bits. For example, the Modbus protocol RTU data request message is 09 03 00 0000 01 85 42, where 09 represents the device address, 03 represents the function code, 00 00 is the starting address, 00 01 is the number of registers, and 85 42 represents the check bit. The message structure of other protocols is similar; the characteristics of industrial protocols determine which bits in various messages are the most representative bits, and then the determined bits are used as variant bits.
[0088] S1062. Using the mutation bits of the above unknown industrial protocol as basic bits, the above unknown industrial protocol is mutated using a genetic mutation algorithm to generate the above fuzzy test case.
[0089] Specifically, the mutation operation in the genetic algorithm refers to replacing the gene values at certain loci in the individual chromosome code string with other alleles at the loci, thereby forming a new individual; for example, the binary code: 101101001011001 may become the new code: 001101011011001 after gene mutation. The mutation operation of the genetic algorithm includes basic bit mutation, uniform mutation, boundary mutation, etc. Among them, the basic bit mutation is to perform a mutation operation on the values at a certain bit or several loci randomly specified with a mutation probability in the individual code string; by using the mutation bits determined by the embodiment of the present invention and using the mutation bits as the basic bits of the genetic algorithm, the mutation operation of the message samples in the best message sample set can be realized, and more targeted fuzzy test cases can be generated; compared with the existing technology that directly uses the genetic mutation algorithm to perform random mutation, the generation of redundant test cases is reduced.
[0090] Furthermore, a large number of data packets of unknown protocols are captured, and the data packets are parsed to obtain message samples. The captured message samples are studied to construct an initial seed pool of fuzzy test seeds. The initial seed pool is calculated using a set covering algorithm to obtain the optimal message sample set Si with the minimum cost, which is the initialization population of the test case; the fitness of the individuals in the optimal message sample set is calculated; the variant bits of the above-mentioned unknown industrial protocol are used as basic bits to generate new individuals in Si to obtain Si'; the individual fitness of Si' is calculated to determine whether it meets the preset indicators. If so, the fuzzy test case is output to obtain a test case set; if not, the fitness of the individuals in Si is repeatedly calculated until the preset indicators are met; the union of the fuzzy test case sets of each subset is obtained to obtain a fuzzy test case set for all unknown protocols.
[0091] In the above optional implementation, the obtained fuzzy test cases can adapt to unknown industrial protocol structure types, avoid the randomly generated test cases with too high repetitiveness and lack of targeted coverage, thereby avoiding the redundancy of test cases and improving the targetedness of fuzzy testing of industrial communication protocols.
[0092] The embodiment of the present invention further discloses a device for generating fuzzy test cases, as shown in FIG6 , comprising:
[0093] The collection module 61 is used to collect industrial protocol data packets, pre-process the industrial protocol data packets, and generate protocol entries.
[0094] Among them, industrial protocol data packets containing multiple industrial protocol messages are captured from on-site real-time transmission and downloaded from the Internet.
[0095] The construction module 62 is used to construct an industrial protocol task set based on the above-mentioned protocol terms; wherein the data in each task in the above-mentioned industrial protocol task set includes a training data set and a test data set.
[0096] Among them, the training data set is used to train a recognition model specific to the classification task; the test data set is used to obtain the adaptability of the model to the classification task. If the classification loss value is small, it means that the model has good adaptability to this task. Otherwise, it means that the model has poor adaptability and cannot meet the recognition requirements of the data.
[0097] The inner loop module 63 is used to obtain the initialization model parameters and perform inner loop training and updating on the initial model based on the initialization model parameters, the training data set and the test data set.
[0098] Specifically, multiple tasks are arbitrarily selected from the industrial protocol task set, and the training data sets of the multiple tasks are input into the initial model to realize the learning and training process of the multiple tasks.
[0099] The outer loop module 64 is used to perform outer loop training and update on the initial model after the inner loop training and update to generate the optimal initialization parameters.
[0100] Among them, the optimal initialization parameters include parameters such as the number of clusters, affinity algorithm, and link algorithm.
[0101] The generation module 65 is used to build a hierarchical clustering model based on the above-mentioned optimal initialization parameters, input the collected unknown industrial protocols into the above-mentioned hierarchical clustering model, and generate industrial protocol features.
[0102] Specifically, the similarity between the best initialization parameters is calculated, the two best initialization parameters with higher similarity are merged to establish a new class, and the above steps are repeated until the stopping condition is met to obtain hierarchical categories and generate a hierarchical clustering model.
[0103] The genetic mutation module 66 is used to perform genetic mutation on the above industrial protocol features to generate fuzzy test cases.
[0104] The present invention provides a device for generating fuzzy test cases. The device generates optimal initialization parameters by training an industrial protocol task set, and then generates industrial protocol features using a hierarchical clustering model constructed with the optimal initialization parameters. Finally, the industrial protocol features are genetically mutated to generate fuzzy test cases. When the number of industrial protocols to be learned and trained is small, the device ensures the ability to learn the industrial protocol features, lowers the threshold for testers to use fuzzy testing tools to test industrial protocols, can adapt to unknown industrial protocol structure types, and improves the pertinence of fuzzy testing on industrial protocols.
[0105] As an optional embodiment of the present invention, the acquisition module 61 includes:
[0106] The unpacking unit is used to unpack the industrial protocol data packet to generate an industrial protocol message.
[0107] Specifically, the captured protocol data packets are unpacked to extract the messages of the specific application layer protocol, namely, the industrial protocol messages.
[0108] The segmentation unit is used to segment the industrial protocol message according to bytes to generate an entry list.
[0109] The determination submodule is used to determine the weight of each entry in the entry list based on the entry list and the industrial protocol message.
[0110] Specifically, the total number of industrial protocol messages, the total number of words in the industrial protocol messages and the number of industrial protocol messages containing each term are obtained, and the weight of each term in the above term list is calculated based on the number of times each term in the above term list appears in the above industrial protocol message, the total number of the above industrial protocol messages, the total number of words in the above industrial protocol message and the number of industrial protocol messages containing each term.
[0111] Furthermore, the weight of each entry in the entry list = (number of times a certain entry appears in the industrial protocol message / total number of words in the industrial protocol message)*log (total number of industrial protocol messages / (number of industrial protocol messages containing each entry+1)).
[0112] The sorting unit is used to sort the weights of the entries in the entry list from large to small, and select the protocol entry based on the sorting result.
[0113] Specifically, a preset number of protocol terms are selected from the sorting results, the protocol features and data types of the protocol terms are known and can be used to classify and mark data.
[0114] As an optional embodiment of the present invention, the internal circulation module 63 includes:
[0115] The training unit is used to obtain the initialization model parameters, use the above training data set as the input of the initial model, perform forward propagation on the above initialization model parameters, and calculate the current loss function based on the prediction results of the forward propagation and the training labels.
[0116] Specifically, any task is selected from the industrial protocol task set, and the training data set in the task is input into the initial model.
[0117] The first updating unit is used to update the above-mentioned initialization model parameters using the gradient descent method based on the above-mentioned current loss function.
[0118] Specifically, the current loss function is differentiated to generate parameter gradients, which are then propagated back to each network layer in the initial model to obtain updated parameters specific to the current task, i.e., the updated initialization model parameters.
[0119] The inner loop unit is used to add 1 to the number of inner loop iterations to generate the current number of iterations, compare the current number of iterations with the maximum number of updates of the inner loop, and when the current number of iterations does not reach the maximum number of updates of the inner loop, use the updated initialized model parameters as the initial parameters and repeat the steps in the training unit and the first update unit. Otherwise, perform outer loop training and update.
[0120] As an optional embodiment of the present invention, the external circulation module 64 includes:
[0121] The second update unit is used to use the above test data set as the input of the initial model, generate a loss function under the test data set in each task, sum the loss functions under the test data set in each task, generate an outer loop loss function, and update the above initialized model parameters using the gradient descent method based on the above outer loop loss function.
[0122] Specifically, the above test dataset is used as the input of the initial model, and the steps for generating the loss function under the test dataset in each task are the same as those in the above training unit.
[0123] Furthermore, the gradient descent algorithm is used to update the initialized model parameters to minimize the overall loss value. This parameter update process takes into account the applicability of the model to each task, and the updated parameters can be considered as common model parameters for all tasks in the inner loop.
[0124] The outer loop unit is used to use the updated initialization model parameters as the initialization model parameters of the next inner loop, repeat the steps in the training unit, the first update unit, the inner loop unit and the second update unit until the number of cycles reaches the maximum training period of the outer loop, and generate the above-mentioned optimal initialization parameters.
[0125] As an optional embodiment of the present invention, the genetic variation module 66 includes:
[0126] The generating unit is configured to use the industrial protocol feature as a variation bit of the unknown industrial protocol.
[0127] The mutation unit is used to use the mutation bit of the above-mentioned unknown industrial protocol as the basic bit, use the genetic mutation algorithm to mutate the above-mentioned unknown industrial protocol, and generate the above-mentioned fuzzy test case.
[0128] In addition, an embodiment of the present invention further provides an electronic device, as shown in FIG7 , which may include a processor 110 and a memory 120 , wherein the processor 110 and the memory 120 may be connected via a bus or other means, with FIG7 using a bus connection as an example. Furthermore, the electronic device also includes at least one interface 130 , which may be a communication interface or other interface, and is not limited in this embodiment.
[0129] The processor 110 may be a central processing unit (CPU). The processor 110 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or a combination of the above chips.
[0130] Memory 120, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer executable programs, and modules, such as the program instructions / modules corresponding to the video synthesis method in the embodiments of the present invention. Processor 110 executes the non-transitory software programs, instructions, and modules stored in memory 120 to perform various processor functions and data processing, thereby implementing a method for generating fuzzy test cases in the above-mentioned method embodiment.
[0131] The memory 120 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and application programs required for at least one function; the data storage area may store data created by the processor 110, etc. In addition, the memory 120 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 120 may optionally include a memory remotely located relative to the processor 110, and these remote memories may be connected to the processor 110 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0132] In addition, at least one interface 130 is used for communication between the electronic device and external devices, such as communication with a server, etc. Optionally, at least one interface 130 can also be used to connect to external input and output devices, such as a keyboard, a display screen, etc.
[0133] The one or more modules are stored in the memory 120 , and when executed by the processor 110 , perform a method for generating a fuzzy test case in the embodiment shown in FIG1 .
[0134] The specific details of the above electronic device can be understood by referring to the corresponding descriptions and effects in the embodiment shown in FIG1 , and will not be repeated here.
[0135] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk drive (HDD), or a solid-state drive (SSD). The storage medium can also include a combination of the above-mentioned types of memory.
Claims
1. A method for generating fuzzy test cases, It is characterized in that include: Collecting industrial protocol data packets, preprocessing the industrial protocol data packets, and generating protocol entries; Constructing an industrial protocol task set based on the protocol terms; wherein the data in each task in the industrial protocol task set includes a training data set and a test data set; Obtaining initialization model parameters, and performing inner loop training and updating on the initial model based on the initialization model parameters, the training data set, and the test data set; After the inner loop training is updated, the initial model is trained and updated in an outer loop to generate the optimal initialization parameters; Building a hierarchical clustering model based on the optimal initialization parameters, inputting the collected unknown industrial protocols into the hierarchical clustering model, and generating industrial protocol features; Genetic mutation is performed on the industrial protocol features to generate fuzzy test cases.
2. A method for generating a fuzzy test case according to claim 1, It is characterized in that The preprocessing of the industrial protocol data packet to generate protocol entries includes: Unpack the industrial protocol data packet and generate the industrial protocol message; Segment the industrial protocol message according to bytes to generate a list of entries; Determining the weight of each entry in the entry list based on the entry list and the industrial protocol message; The weights of the terms in the term list are sorted from large to small, and the protocol term is selected based on the sorting result.
3. A method for generating a fuzzy test case according to claim 2, It is characterized in that The determining the weight of each entry in the entry list based on the entry list and the industrial protocol message includes: Obtain the total number of industrial protocol messages, the total number of words in the industrial protocol messages, and the number of industrial protocol messages containing each term, and calculate the weight of each term in the term list based on the number of times each term in the term list appears in the industrial protocol message, the total number of industrial protocol messages, the total number of words in the industrial protocol message, and the number of industrial protocol messages containing each term.
4. The method for generating a fuzzy test case according to claim 1, It is characterized in that The inner loop training and updating of the initial model based on the initialization model parameters, the training data set and the test data set includes: Training step: obtaining initialization model parameters, taking the training data set as the input of the initial model, performing forward propagation on the initialization model parameters, and calculating the current loss function based on the prediction results of the forward propagation and the training labels; First updating step: based on the current loss function, updating the initialization model parameters using the gradient descent method; Inner loop steps: add 1 to the number of inner loop iterations to generate the current number of iterations, and compare the current number of iterations with the maximum number of iterations in the inner loop. When the current iteration number does not reach the maximum update number of the inner loop, the updated initialization model parameters are used as the initial parameters, and the training step and the first update step are repeated, otherwise the outer loop training update is performed.
5. A method for generating a fuzzy test case according to claim 4, It is characterized in that The updating of the initialization model parameters by using a gradient descent method based on the current loss function includes: The current loss function is differentiated to generate parameter gradients, and the gradient parameters are used to update the initialized model parameters.
6. A method for generating a fuzzy test case according to claim 4, It is characterized in that After the inner loop training is updated, the initial model outer loop training is updated to generate the optimal initialization parameters, including: The second updating step: using the test data set as the input of the initial model, generating a loss function under the test data set in each task, summing the loss functions under the test data set in each task to generate an outer loop loss function, and updating the initialized model parameters using the gradient descent method based on the outer loop loss function; Outer loop step: use the updated initialization model parameters as the initialization model parameters for the next inner loop, repeat the training step, the first update step, the inner loop step and the second update step until the number of loops reaches the maximum training period of the outer loop, and generate the optimal initialization parameters.
7. A method for generating a fuzzy test case according to claim 1, It is characterized in that The step of performing genetic mutation on the industrial protocol features to generate fuzzy test cases includes: Using the industrial protocol feature as a variant bit of the unknown industrial protocol; The variant bits of the unknown industrial protocol are used as basic bits, and the unknown industrial protocol is mutated using a genetic mutation algorithm to generate the fuzzy test case.
8. A device for generating fuzzy test cases, It is characterized in that include: A collection module, used for collecting industrial protocol data packets, preprocessing the industrial protocol data packets, and generating protocol entries; A construction module, used to construct an industrial protocol task set based on the above-mentioned protocol terms; wherein the data in each task in the above-mentioned industrial protocol task set includes a training data set and a test data set; An inner loop module is used to obtain initialization model parameters, and perform inner loop training and updating on the initial model based on the initialization model parameters, the training data set and the test data set; An outer loop module, used for performing outer loop training and updating of the initial model after the inner loop training and updating, to generate the optimal initialization parameters; A generation module, used to construct a hierarchical clustering model based on the optimal initialization parameters, input the collected unknown industrial protocols into the hierarchical clustering model, and generate industrial protocol features; The genetic mutation module is used to perform genetic mutation on the industrial protocol features to generate fuzzy test cases.
Citation Information
Patent Citations
Small sample fault diagnosis method based on task sorting meta learning
CN113837000A
Ethernet / IP protocol fuzz testing method based on generative adversarial network
CN114064471A
Human face action unit detection method based on meta-learning
CN114708637A
Fuzzy test case generation method and device of industrial protocol and electronic equipment
CN115729825A
Fuzzy test case generation method and device, equipment and storage medium
CN116257455A
Cited By
Message generation method and device, computer equipment, storage medium and program product
CN122364102A
