Message generation method and device, computer device, storage medium and program product
By selecting effective targets from the set of valid messages of the tested object, constructing an initial target matrix, and optimizing it using various mutation functions and genetic algorithms, efficient mutated messages are generated. This solves the problem of blind and inefficient generation of mutated messages in existing technologies, and improves the efficiency of fuzz testing and vulnerability discovery capabilities.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ELECTRIC POWER RES INST CHINA SOUTHERN POWER GRID CO LTD
- Filing Date
- 2026-06-09
- Publication Date
- 2026-07-10
Smart Images

Figure CN122364102A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of fuzz testing technology, and in particular to a message generation method, apparatus, computer equipment, storage medium, and program product. Background Technology
[0002] Fuzzing is an automated testing technique that discovers potential vulnerabilities by inputting unexpected, abnormal, or random test samples into the object under test and observing its operational state, such as crashes, abnormal exits, or functional malfunctions. Mutant messages are the core test samples in fuzzing, and the quality of the generated mutant messages directly determines the efficiency and vulnerability discovery capability of fuzzing.
[0003] In existing technologies, the generation of mutated messages mainly uses random mutation. Random mutation is blind, which makes most of the generated messages invalid and difficult to hit the key vulnerability targets of the tested object, thus resulting in low testing efficiency of fuzz testing. Summary of the Invention
[0004] Therefore, it is necessary to provide a message generation method, apparatus, computer equipment, storage medium, and program product to address the aforementioned technical problems and improve the testing efficiency of fuzz testing.
[0005] Firstly, this application provides a message generation method, including:
[0006] Select at least two valid target points from the initial target points corresponding to the valid message set of the tested object;
[0007] An initial target matrix is constructed based on the feature parameters of the at least two effective target points; a row or column in the initial target matrix corresponds to the feature parameters of different dimensions of the same effective target point.
[0008] The initial target matrix is mutated according to each mutation function to obtain a new target matrix; different mutation functions are used to mutate the feature parameters of different dimensions of the effective targets in the initial target matrix;
[0009] Based on the initial target matrix and the new target matrix, construct the initial population;
[0010] The initial population is iterated to obtain the target population;
[0011] Based on the target population, determine the mutation message for the tested object.
[0012] In one embodiment, the step of mutating the initial target matrix according to each mutation function to obtain a new target matrix includes:
[0013] For each effective target in the initial target matrix, the trigger probability and transformation parameters of each mutation function are determined based on the mutation factor corresponding to the effective target.
[0014] For each mutation function, if the trigger probability corresponding to the mutation function satisfies the mutation condition, the mutation function is used to mutate the feature parameters corresponding to the mutation function in different dimensions of the effective target to obtain new feature parameters.
[0015] The initial target matrix is updated by using the new feature parameters of each initial target to obtain a new target matrix.
[0016] In one embodiment, the initial population is iterated to obtain a target population, including:
[0017] For each iteration round, a first preset number of parent individuals are selected from the initial population corresponding to the iteration round;
[0018] Perform a crossover operation on the first preset number of parent individuals to obtain the first preset number of child individuals;
[0019] The offspring individuals are mutated according to different mutation functions to obtain new offspring individuals, and a new initial population is constructed based on the new offspring individuals;
[0020] If the iteration stopping condition is met, the new initial population is taken as the target population;
[0021] If the iteration stopping condition is not met, the new initial population is used as the initial population for the next iteration round.
[0022] In one embodiment, selecting a first preset number of parent individuals from the initial population corresponding to the iteration round includes:
[0023] From the initial population corresponding to the iteration round, individuals are selected for a total selection round. In each selection round, a second preset number of candidate individuals are selected from the initial population corresponding to the iteration round, and the candidate individual with the highest fitness among the candidate individuals is taken as the parent individual corresponding to the selection round.
[0024] The fitness is determined based on the vulnerability trigger probability, target coverage, and message validity of the candidate individual. The vulnerability trigger probability is determined based on the vulnerability trigger probability of each target included in the candidate individual. The target coverage is determined based on the ratio of the number of valid targets included in the candidate individual to the initial number of targets. The message validity is determined based on the number of messages that conform to the message format corresponding to the candidate individual to the total number of messages. The total number of selection rounds is the first preset number.
[0025] In one embodiment, selecting at least two valid target points from the initial target points corresponding to the valid message set of the tested object includes:
[0026] Based on at least one of the vulnerability correlation and information gain of each initial target point corresponding to the valid message set of the tested object, select at least two valid targets from each initial target point.
[0027] The vulnerability correlation is used to measure the strength of the causal relationship between the mutation of the initial target and the vulnerability triggering of the tested object, and the information gain is used to measure the amount of information provided by the initial target for the vulnerability triggering of the tested object.
[0028] In one embodiment, determining the mutation message for the tested object based on the target population includes:
[0029] Based on the message generation format and the individual with the highest fitness in the target population, a mutated message for the tested object is generated.
[0030] Secondly, this application also provides a message generation apparatus, comprising:
[0031] The selection module is used to select at least two valid target points from each initial target point corresponding to the valid message set of the tested object.
[0032] The first construction module is used to construct an initial target matrix based on the feature parameters of the at least two effective target points; a row or column in the initial target matrix corresponds to the feature parameters of different dimensions of the same effective target point.
[0033] The mutation module is used to mutate the initial target matrix according to various mutation functions to obtain a new target matrix; different mutation functions are used to mutate the feature parameters of different dimensions of the effective targets in the initial target matrix.
[0034] The second construction module is used to construct an initial population based on the initial target matrix and the new target matrix;
[0035] An optimization module is used to iterate the initial population to obtain the target population;
[0036] The determination module is used to determine the mutation message for the tested object based on the target population.
[0037] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0038] Select at least two valid target points from the initial target points corresponding to the valid message set of the tested object;
[0039] An initial target matrix is constructed based on the feature parameters of the at least two effective target points; a row or column in the initial target matrix corresponds to the feature parameters of different dimensions of the same effective target point.
[0040] The initial target matrix is mutated according to each mutation function to obtain a new target matrix; different mutation functions are used to mutate the feature parameters of different dimensions of the effective targets in the initial target matrix;
[0041] Based on the initial target matrix and the new target matrix, construct the initial population;
[0042] The initial population is iterated to obtain the target population;
[0043] Based on the target population, determine the mutation message for the tested object.
[0044] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0045] Select at least two valid target points from the initial target points corresponding to the valid message set of the tested object;
[0046] An initial target matrix is constructed based on the feature parameters of the at least two effective target points; a row or column in the initial target matrix corresponds to the feature parameters of different dimensions of the same effective target point.
[0047] The initial target matrix is mutated according to each mutation function to obtain a new target matrix; different mutation functions are used to mutate the feature parameters of different dimensions of the effective targets in the initial target matrix;
[0048] Based on the initial target matrix and the new target matrix, construct the initial population;
[0049] The initial population is iterated to obtain the target population;
[0050] Based on the target population, determine the mutation message for the tested object.
[0051] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0052] Select at least two valid target points from the initial target points corresponding to the valid message set of the tested object;
[0053] An initial target matrix is constructed based on the feature parameters of the at least two effective target points; a row or column in the initial target matrix corresponds to the feature parameters of different dimensions of the same effective target point.
[0054] The initial target matrix is mutated according to each mutation function to obtain a new target matrix; different mutation functions are used to mutate the feature parameters of different dimensions of the effective targets in the initial target matrix;
[0055] Based on the initial target matrix and the new target matrix, construct the initial population;
[0056] The initial population is iterated to obtain the target population;
[0057] Based on the target population, determine the mutation message for the tested object.
[0058] The aforementioned message generation method, apparatus, computer equipment, storage medium, and program products enable mutation operations to be specifically adjusted based on the stability and vulnerability triggering potential of the target; and during the mutation process, only mutation functions that meet the triggering conditions are executed, avoiding unnecessary mutation operations; at the same time, different mutation functions mutate different dimensional feature parameters of the effective target, which can comprehensively cover various feature changes of the target, improve the efficiency and effectiveness of mutation operations, generate more new target matrixes with high vulnerability triggering potential, and further enhance the vulnerability discovery capability of fuzz testing. Attached Figure Description
[0059] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0060] Figure 1 This is a flowchart illustrating a message generation method in one embodiment;
[0061] Figure 2 This is a schematic diagram of the process for obtaining a new target matrix in one embodiment;
[0062] Figure 3 This is a schematic diagram of the process for obtaining the target population in one embodiment;
[0063] Figure 4 This is a structural block diagram of a message generation device in one embodiment;
[0064] Figure 5 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0065] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0066] The message generation method provided in this application can be applied to fuzz testing scenarios involving the tested object. This method can be executed by a server or a terminal. The terminal can be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart in-vehicle devices, projection devices, etc. Portable wearable devices can include smartwatches, smart bracelets, head-mounted displays, etc. Head-mounted displays can be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.
[0067] In one exemplary embodiment, such as Figure 1 The diagram illustrates a message generation method, using a server as an example. The method includes the following steps:
[0068] S101, select at least two valid target points from the initial target points corresponding to the valid message set of the object under test.
[0069] The object under test is the target entity for fuzz testing, vulnerability discovery, and security verification. It is a hardware or software unit that receives mutated message input, runs, and generates status responses. For example, it can be a network protocol entity, such as the Modbus Remote Terminal Unit (Modbus RTU) protocol, or an embedded system or device, such as an industrial controller, remote terminal unit (RTU), programmable logic controller (PLC), smart terminal, IoT device, gateway, etc. It can also be a software program or service, such as message parsing software, communication services, data processing programs, network applications, etc.
[0070] A valid message set refers to the set of messages that can be normally parsed, executed, or responded to by the object under test, including normal communication messages of the object under test and abnormal messages that have triggered vulnerabilities in the past.
[0071] Initial target points refer to message components parsed from valid messages that may affect the operating status of the object under test, including message header fields, data segment length, protocol type identifier, checksum, data format identifier, etc.
[0072] Valid targets refer to the initial targets that have been retained after validity screening and are highly correlated with the triggering of vulnerabilities in the tested object, and can reflect the core characteristics of the message.
[0073] For example, a valid packet set of the target object can be obtained through network packet capture tools, log analysis systems, or manual construction. The valid packet set includes normal packets and historical vulnerability trigger packets to achieve comprehensive target extraction.
[0074] Then, using message parsing tools in conjunction with the protocol specifications or software interface documents of the object under test, each message is parsed field by field to extract all possible initial target points. For example, for Modbus RTU protocol messages, initial target points such as slave address, function code, data address, data length, data field, and Cyclic Redundancy Check (CRC) checksum can be extracted. Based on the correlation between each initial target point and vulnerability triggering, at least two valid target points are selected from the initial target points corresponding to the valid message set of the object under test.
[0075] In some optional implementations, when selecting effective targets from the initial targets corresponding to the effective message set of the tested object, at least two effective targets can be selected from each initial target based on at least one of vulnerability correlation and information gain. Vulnerability correlation is used to measure the strength of the causal relationship between the mutation of the initial target and the vulnerability triggering of the tested object, and information gain is used to measure the amount of information provided by the initial target for the vulnerability triggering of the tested object.
[0076] For example, a target importance assessment model can be used to screen the effectiveness of all initial targets. The vulnerability correlation and information gain of each target are calculated, and targets with a vulnerability correlation greater than a preset threshold and an information gain above average are selected as valid targets. The preset threshold can be set according to actual needs, for example, to 0.6. The vulnerability correlation can be calculated by statistically analyzing the frequency of vulnerability triggering after the target mutates in historical test data, and the information gain can be determined by calculating the degree of uncertainty reduction in the target's impact on vulnerability triggering. In this way, invalid and redundant targets can be eliminated, retaining only truly relevant and effective targets.
[0077] For example, vulnerability correlation can be determined using the following formula:
[0078]
[0079] in, Let m be the vulnerability correlation degree of the i-th target, and m be the total number of vulnerability severity levels. Let be the weight coefficient for the j-th level vulnerability, which is positively correlated with its severity. This represents the total number of times the mutation of the i-th target point triggered a level j vulnerability in historical tests. This represents the total number of times the i-th target has been mutated in historical tests.
[0080] For example, information gain can be determined in the following ways:
[0081]
[0082]
[0083]
[0084] in, Let be the information gain of the i-th target, and D be the historical test dataset. The overall entropy of the dataset, Let i be the conditional entropy of the i-th target point. Let n be the set of all possible values for the i-th target point, and n be the number of distinct values for target point i. For a subset of messages in the dataset where target point i has the k-th value, For subset Size, The size of the entire dataset, For subset Entropy; This represents the percentage of packets that trigger the vulnerability in the dataset. This represents the percentage of packets in the dataset that did not trigger the vulnerability.
[0085] In this way, by calculating the vulnerability correlation and information gain of the initial target, effective targets can be screened, which can comprehensively evaluate the importance of the target from two different perspectives: causality and information theory. Furthermore, the vulnerability correlation reflects the possibility that the target mutation will directly trigger the vulnerability, and the information gain reflects the role of the target in distinguishing between vulnerability-triggered messages and non-vulnerability-triggered messages. Combining these two indicators for screening can ensure that the selected effective targets have high vulnerability triggering potential and distinguishability, thereby improving the accuracy and effectiveness of target screening and further enhancing the efficiency of fuzz testing and vulnerability discovery capabilities.
[0086] S102, construct an initial target matrix based on the feature parameters of at least two effective target points.
[0087] The initial target matrix is a two-dimensional matrix constructed with effective target points as rows or columns, and different dimensional feature parameters of each effective target point as columns or rows. It is used to uniformly represent the feature information of multiple effective targets. In the initial target matrix, one row or one column corresponds to different dimensional feature parameters of the same effective target point.
[0088] For example, an initial target matrix can be constructed based on the selected set of valid targets. For instance, rows of the matrix correspond to different valid targets, and columns correspond to the feature parameters of each valid target. These feature parameters include the target's value range, data type, constraints, etc.
[0089] For example, based on the slave address, function code, data address, data length, and CRC checksum of the five valid target points in the Modbus RTU protocol, a 5×3 initial target point matrix can be constructed, where each row represents a valid target point, and each column corresponds to the value range, data type, and constraints of that target point.
[0090] Then, the feature parameters of each target point are quantized and encoded, transforming them into a numerical form that can be used for genetic algorithm calculations. For discrete targets, such as function codes, a binary encoding method is used, mapping each possible value to a corresponding binary string; for continuous targets, such as data length, a real number encoding method is used, directly using its numerical representation. Through quantization and encoding, the initial target point matrix is initialized, allowing each element in the matrix to participate in subsequent genetic operations.
[0091] S103, the initial target matrix is mutated according to each mutation function to obtain a new target matrix.
[0092] A mutation function is a mathematical function used to transform the feature parameters in the initial target matrix. Different mutation functions are used to mutate the feature parameters of the effective targets in the initial target matrix in different dimensions.
[0093] The new target matrix refers to the matrix containing new target feature parameters obtained after transformation by the variogram function.
[0094] For example, various mutation functions with different dimensions can be designed, including but not limited to matrix translation transformation functions, matrix scaling transformation functions, matrix rotation transformation functions, and matrix random perturbation functions. Specifically, the matrix translation transformation function is used to adjust the overall value offset of target feature parameters, simulating small fluctuations in target features; the matrix scaling transformation function is used to adjust the value range of target feature parameters, simulating amplitude changes in target features; the matrix rotation transformation function is used to adjust the correlation between different targets, simulating cooperative changes between targets; and the matrix random perturbation function is used to randomly modify target feature parameters with a small probability, maintaining population diversity.
[0095] A corresponding mutation function can be applied to the initial target matrix to generate a new target matrix. During the transformation process, the validity of the new target matrix can be verified in real time, and invalid matrices that do not conform to the message format constraints or exceed the target value range can be eliminated to ensure that the transformed matrix corresponds to valid message features.
[0096] S104. Construct the initial population based on the initial target matrix and the new target matrix.
[0097] The initial population refers to the set of individuals at the start of the genetic algorithm iteration, consisting of the initial target matrix and the new target matrix.
[0098] The initial target matrix can be used as the parent individuals in the genetic algorithm, and the new target matrix obtained after mutation function transformation can be used as the offspring individuals, together forming the initial population of the genetic algorithm. The population size can be set according to the complexity of the object being tested and the testing requirements, for example, it can be set to 50-200 individuals. For example, for fuzz testing of the Modbus RTU protocol, the population size can be set to 100, which includes 1 initial target matrix (parent) and 99 new target matrices (offspring). The initial population constructed in this way contains both the good features of the original message and introduces sufficient mutation diversity, providing a good foundation for subsequent genetic iterative optimization.
[0099] S105, iterate through the initial population to obtain the target population.
[0100] The target population refers to the population obtained after multiple iterations of optimization using a genetic algorithm.
[0101] The genetic algorithm can be iteratively applied to the initial population, including three operations: selection, crossover, and mutation. The selection operation involves choosing 'a' individuals from the population as parents, who then participate in the crossover operation. 'a' can be the number of individuals in the initial population or half of that number. The crossover operation can employ a multi-point crossover method, for example, pairing parents together and exchanging some rows of the two parent matrices within a pair, representing the feature parameters of different effective target points, to generate a offspring matrix. Finally, a corresponding mutation function can be used to randomly mutate the offspring matrix generated by the crossover.
[0102] Repeat the above iterative process until the termination conditions are met. The termination conditions include, but are not limited to, the number of iterations reaching a preset maximum number of iterations, the fitness value of the best individual in the population remaining unchanged for a preset number of consecutive iterations, and the number of generated mutation messages meeting the testing requirements. After the iteration terminates, the resulting population is the target population.
[0103] S106, Based on the target population, determine the mutation message for the tested object.
[0104] Mutation messages refer to anomalous messages generated based on individuals in the target population for fuzz testing.
[0105] Multiple individuals with the highest fitness values can be selected from the target population, forming multiple multidimensional mutation matrices. Each multidimensional mutation matrix is then inversely quantized and encoded to convert it into corresponding message target feature parameters. These target feature parameters are then combined with the message format specifications of the tested object to form a complete mutated message. Finally, the generated mutated messages are validated, and invalid messages with format errors or those that cannot be parsed by the tested object are removed, resulting in the final fuzz test sample set for subsequent fuzz testing.
[0106] In some optional implementations, messages can be generated based on the message generation format and the individual with the highest fitness in the target population to obtain a mutated message for the tested object.
[0107] Among them, the message generation format refers to the message structure specification followed by the object under test, including the components of the message, the order of each component, the length, the encoding method, etc.
[0108] For example, one could first select several individuals with the highest fitness values from the target population, such as those ranking in the top 10%-20%. Then, each selected individual would undergo inverse quantization encoding, converting the numerical feature parameters of the individual into actual target message feature parameters. For binary-encoded targets, the binary string would be converted into the corresponding decimal or hexadecimal value; for real-number-encoded targets, the numerical value would be directly used as the target feature parameter.
[0109] Then, based on the message generation format of the tested object, the characteristic parameters of each target point are combined into a complete variant message according to a specified order and length. For example, for the Modbus RTU protocol, the message generation format is slave address (1 byte) + function code (1 byte) + data address (2 bytes) + data length (1 byte) + data field (n bytes) + CRC checksum (2 bytes). The characteristic parameters such as slave address, function code, data address, data length, and CRC checksum obtained by inverse quantization encoding are combined according to this format, and the corresponding data field content is filled according to the data length to generate a complete Modbus RTU variant message.
[0110] Finally, all generated variant messages are validated to check if the message format conforms to the specifications, if the values of each field are within the legal range, and if the checksum is correct. Invalid messages with incorrect formats or that cannot be parsed by the tested object are removed to obtain the final fuzz test sample set.
[0111] The mutated messages generated in this way retain the desirable characteristics of highly fit individuals in the target population, while also conforming to the message format specifications of the tested object, thus possessing high vulnerability triggering potential and effectiveness.
[0112] Taking the Modbus RTU protocol in industrial control networks as an example, firstly, 1000 valid Modbus RTU protocol messages are captured using a packet capture tool, including 900 normal messages and 100 historical vulnerability-triggered messages. These messages are parsed to extract six initial target points: slave address, function code, data address, data length, data field, and CRC checksum. The vulnerability correlation and information gain of each target point are calculated, and five valid target points (slave address, function code, data address, data length, and CRC checksum) with a vulnerability correlation greater than or equal to 0.6 and an information gain greater than or equal to 0.5 are selected.
[0113] A 5×3 initial target matrix is then constructed, with rows corresponding to 5 valid target points and columns corresponding to value ranges, data types, and constraints. The feature parameters of each target point are binary encoded; for example, slave addresses 1-247 correspond to 00000001-11110111, and function code 01H corresponds to 00000001. Four mutation functions are designed, and the trigger probability of each mutation function is determined based on a mutation factor of 0.05. For example, the trigger probability for translation transformation is determined to be 30%, for scaling transformation 25%, for rotation transformation 25%, and for random perturbation 20%.
[0114] A mutation function was used to mutate the initial target matrix, generating 99 new target matrices, which, together with the initial target matrix, constituted an initial population of size 100. An iterative process of a genetic algorithm was performed on the initial population, including selection, crossover, and mutation operations. After the iteration terminated, the target population was obtained. The 20 individuals with the highest fitness values in the target population were selected and inversely quantized to generate 20 Modbus RTU mutation messages. After validity verification, 18 valid test samples were obtained for vulnerability mining testing of the Modbus RTU protocol.
[0115] In the above embodiments, on the one hand, effective targets related to vulnerability triggering are screened from the effective message set, and a multi-dimensional initial target matrix is constructed to uniformly represent the feature information of multiple targets, breaking through the limitations of traditional single target mutation and being able to simultaneously cover the multi-dimensional features of messages; on the other hand, multiple mutation functions of different dimensions are used to transform the matrix, and combined with the iterative optimization process of the genetic algorithm, global optimization of mutated messages is achieved, avoiding the blindness of random mutation and the defects of traditional genetic algorithms that are prone to getting trapped in local optima, improving the efficiency of fuzz testing and vulnerability discovery capabilities, reducing testing time costs, and increasing the success rate of vulnerability discovery.
[0116] In some alternative implementations, see [link to relevant documentation]. Figure 2 , Figure 2 A flowchart for obtaining a new target matrix is provided, including the following steps:
[0117] S201, for each effective target in the initial target matrix, determine the trigger probability of each mutation function based on the mutation factor corresponding to the effective target.
[0118] The mutation factor is a coefficient used to control the trigger probability of the mutation function. It is negatively correlated with the stability of the target. The lower the stability of the target, the larger the mutation factor.
[0119] Trigger probability refers to the probability that a certain mutation function will be executed in a single mutation operation.
[0120] For example, a corresponding mutation factor can be assigned to each valid target. The initial value of the mutation factor is obtained through training with historical test data, and it can be dynamically adjusted according to changes in population fitness during the genetic algorithm iteration process. The mutation factor is negatively correlated with the stability of the target; the lower the stability of the target, the higher the probability of triggering a vulnerability after mutation, and therefore the larger the mutation factor. For example, CRC checksums have lower stability, so their mutation factors are usually set to be larger; while slave addresses have higher stability, so their mutation factors are usually set to be smaller.
[0121] Then, based on the mutation factor of each effective target point, the trigger probability of each mutation function is determined. Generally, the larger the mutation factor, the higher the trigger probability of the random perturbation function, and the lower the trigger probability of the translation, scaling, and rotation transformation functions. For example, when the mutation factor is 0.05, the trigger probability of the random perturbation function can be set to 20%, the trigger probability of the translation transformation function to 30%, the trigger probability of the scaling transformation function to 25%, and the trigger probability of the rotation transformation function to 25%. Simultaneously, the transformation parameters of each mutation function are adaptively determined based on the characteristic parameter range of the target point. The transformation parameters refer to the specific parameters used when the mutation function is executed, such as the offset of the translation transformation and the scaling ratio of the scaling transformation. For example, for a data address target point, whose value range is 0000H-FFFFH, the offset of the translation transformation can be set to a random value between 0001H-0010H; for a data length target point, whose value range is 1-256 bytes, the scaling ratio of the scaling transformation can be set to a random value between 0.5 and 2. In this way, it can be ensured that the transformation parameters of the mutation function can cover more potential vulnerability triggering scenarios without generating too many invalid matrices.
[0122] S202, for each mutation function, if the trigger probability corresponding to the mutation function satisfies the mutation condition, the mutation function is used to mutate the feature parameters of different dimensions of the effective target that correspond to the mutation function, so as to obtain new feature parameters.
[0123] The mutation condition refers to the condition for determining whether to execute a certain mutation function. It can generate a random number between 0 and 1. If the random number is less than or equal to the trigger probability of the mutation function, then the mutation condition is satisfied.
[0124] For each mutation function, a random number between 0 and 1 is generated and compared with the trigger probability of the mutation function. If the random number is less than or equal to the trigger probability, the mutation condition is met, and the mutation function is executed; otherwise, the mutation function is not executed.
[0125] When the mutation conditions are met, the transformation parameters corresponding to the mutation function are used to mutate the corresponding feature parameters of the effective target. For example, for a data address target, if the trigger probability of the translation transformation function is 30% and the generated random number is 0.2 (less than 0.3), the mutation conditions are met. The offset 0005H is used to perform a translation transformation on the value range feature parameter of the data address, shifting the original value range 0000H-FFFFH to 0005H-1004H, resulting in a new value range feature parameter. For function code and data length targets, if the trigger probability of the rotation transformation function is 25% and the generated random number is 0.2 (less than 0.25), the mutation conditions are met. The association between the function code and the data length is adjusted, modifying the regular data length 1-10 bytes corresponding to the read-hold register function code (03H) to 1-20 bytes, resulting in new constraint feature parameters. In this way, targeted mutations can be performed on the feature parameters of different dimensions of the effective target to generate new target points with different characteristics.
[0126] S203, using the new feature parameters of each initial target point, updates the initial target point matrix to obtain a new target point matrix.
[0127] For each valid target, the new feature parameters obtained through mutation replace the corresponding original feature parameters in the initial target matrix. If a feature parameter of a valid target is not mutated by any mutation function, its original value is retained. After the update, a new target matrix is obtained.
[0128] The new target matrix is then validated to ensure that the characteristic parameters of each target meet its constraints, such as whether the slave address is within the range of 1-247, whether the function code is a valid value, and whether the data length is within the range of 1-256 bytes. If any characteristic parameters in the new target matrix do not meet the constraints, the matrix is marked as invalid and discarded. In this way, it can be ensured that the generated new target matrices are valid and correspond to legitimate message characteristics.
[0129] Taking the function code target point of the Modbus RTU protocol as an example, assume the mutation factor of the function code is 0.05. Based on this mutation factor, the trigger probabilities of each mutation function are determined as follows: translation transformation trigger probability is 30%, scaling transformation trigger probability is 25%, rotation transformation trigger probability is 25%, and random perturbation trigger probability is 20%. The characteristic parameters of the function code include the value range (01H-06H), data type (discrete), and constraints (related to data length).
[0130] First, four random numbers between 0 and 1 are generated, corresponding to four mutation functions: 0.2 (translation), 0.3 (scaling), 0.2 (rotation), and 0.8 (random perturbation). Comparing the random numbers with the trigger probabilities, translation and rotation transformations satisfy the mutation conditions, while scaling and random perturbation do not. A translation transformation is performed, shifting the function code's value range from 01H-06H to 02H-07H; a rotation transformation is performed, adjusting the association between the function code and data length, changing the data length constraint corresponding to the read-hold register function code (03H) from 1-10 bytes to 1-20 bytes.
[0131] Then, the original feature parameters corresponding to the function code targets in the initial target matrix are replaced with the new value range and constraints to obtain a new target matrix. The new matrix is then validated to check whether the value range of the function code (02H-07H) is valid and whether the data length constraint (1-20 bytes) is within the range of 1-256 bytes. After confirming that there are no errors, the new target matrix is valid.
[0132] In the above embodiments, a mutation factor is determined individually for each effective target, and the trigger probability of each mutation function is dynamically adjusted according to the mutation factor. This allows the mutation operation to be adjusted specifically according to the stability and vulnerability triggering potential of the target. Furthermore, during the mutation process, only mutation functions that meet the triggering conditions are executed, avoiding unnecessary mutation operations. At the same time, different mutation functions mutate different dimensional feature parameters of the effective target, which can comprehensively cover various feature changes of the target, improving the efficiency and effectiveness of the mutation operation, generating more new target matrixes with high vulnerability triggering potential, and further enhancing the vulnerability discovery capability of fuzz testing.
[0133] In some alternative implementations, see [link to relevant documentation]. Figure 3 , Figure 3 A flowchart for obtaining the target population is provided, including the following steps:
[0134] S301, for each iteration round, select a first preset number of parent individuals from the initial population corresponding to the iteration round.
[0135] In this context, "iteration round" refers to one complete selection, crossover, and mutation operation in a genetic algorithm. "Parent individual" refers to the individual selected during the selection operation to generate offspring individuals.
[0136] At the start of each iteration, the initial population corresponding to the current iteration is first obtained. Then, a first preset number of parent individuals are selected from the initial population according to a selection mechanism. The first preset number is set based on the population size and the requirements of crossover operations; it can be set to the population size or half of the population size. The selection mechanism should prioritize retaining individuals with high fitness values while maintaining a certain level of population diversity. Selection mechanisms include, but are not limited to, tournament selection, roulette wheel selection, or sorting selection.
[0137] S302, perform a crossover operation on a first preset number of parent individuals to obtain a first preset number of child individuals.
[0138] Offspring individuals refer to new individuals generated through crossover operations on parent individuals.
[0139] The selected first preset number of parent individuals are randomly paired to form parent-child pairs. Then, a crossover operation is performed on each parent-child pair to generate two child individuals. The crossover operation uses a multi-point crossover method, that is, multiple crossover points are randomly selected in the target matrix corresponding to the parent individuals, and rows between the crossover points in the two parent matrices are swapped, representing the feature parameters of different effective targets. For example, for a 5-row target matrix, rows 2 and 4 can be randomly selected as crossover points, swapping all rows between rows 2 and 4 in the two parent matrices to generate two new child matrices. The probability of the crossover operation is determined by the crossover factor, which is negatively correlated with the feature similarity between the two effective targets; the lower the feature similarity of the targets, the higher the crossover probability. For example, the crossover probability is set between 0.6 and 0.9. Through the crossover operation, the superior features of different parent individuals can be combined to generate better child individuals, expanding the search range of the solution space.
[0140] S303, mutate each offspring individual according to different mutation functions to obtain new offspring individuals, and construct a new initial population based on the new offspring individuals.
[0141] The new initial population refers to the population obtained after mutation operations and used for the next iteration.
[0142] For all offspring individuals generated by the crossover operation, for each valid target in the target matrix corresponding to each offspring individual, the trigger probability of each mutation function is determined based on its mutation factor. The feature parameters that meet the mutation conditions are mutated to obtain new feature parameters, the target matrix is updated, and new offspring individuals are generated. Then, all new offspring individuals are combined with the individuals with the highest fitness values from the previous generation to construct a new initial population. By retaining the individuals with the highest fitness values, superior genes can be prevented from being lost during the inheritance process, accelerating the convergence speed of the algorithm. For example, for a population of size 100, the 5 individuals with the highest fitness values can be retained and combined with 95 new offspring individuals to form a new initial population.
[0143] S304: If the iteration stopping condition is met, the new initial population is used as the target population.
[0144] The stopping condition refers to the condition for terminating the iteration process of the genetic algorithm, including the number of iterations reaching the preset maximum value, the optimal fitness value of the population remaining unchanged, and the number of generated mutation messages meeting the requirements.
[0145] S305: If the iteration stopping condition is not met, the new initial population is used as the initial population for the next iteration round.
[0146] After each iteration, it is determined whether the iteration stopping condition is met. If any iteration stopping condition is met, the genetic algorithm terminates its iteration process, and the current new initial population is used as the target population. If the iteration stopping condition is not met, the current initial population is used as the initial population for the next iteration, and the next round of selection, crossover, and mutation operations continues. Through this iterative optimization process, the fitness values of individuals in the population can be continuously improved, ultimately resulting in a target population containing individuals with high vulnerability triggering potential.
[0147] In the above embodiments, by combining the superior features of different parent individuals through crossover operations, the search range of the understanding space is expanded, which can generate better offspring individuals. At the same time, the diversity of the population is maintained through mutation operations, avoiding premature convergence of the algorithm, improving the optimization efficiency and effect of the genetic algorithm, and further improving the efficiency of fuzz testing and the vulnerability discovery capability.
[0148] In some optional implementations, a first preset number of parent individuals can be selected from the initial population corresponding to the iteration round. Alternatively, individuals can be selected from the initial population corresponding to the iteration round for a total selection round. In each selection round, a second preset number of candidate individuals can be selected from the initial population corresponding to the iteration round, and the candidate individual with the highest fitness among the candidate individuals can be used as the parent individual corresponding to the selection round.
[0149] Among them, fitness refers to the indicator used to measure the vulnerability triggering potential of the message corresponding to an individual. Fitness is determined based on the vulnerability triggering probability, target coverage, and message validity of the candidate individual. The vulnerability triggering probability is determined based on the vulnerability triggering probability of each target contained in the candidate individual. The target coverage is determined based on the ratio of the number of valid targets contained in the candidate individual to the initial number of targets. The message validity is determined based on the number of messages corresponding to the candidate individual that conform to the message format to the total number of messages. The total number of selection rounds is the first preset number.
[0150] For example, in the selection phase of each iteration round, the total number of selection rounds is first determined. The total number of selection rounds is equal to the number of parent individuals to be selected, i.e., the first preset number. For example, if 50 parent individuals need to be selected, 50 selections are performed. In each selection round, a second preset number of candidate individuals is randomly selected from the initial population corresponding to the current iteration round. The second preset number can be set according to actual needs, for example, 3-10. Then, the fitness value of each candidate individual is calculated. The fitness value is calculated as: Fitness Value = α × Vulnerability Trigger Probability + β × Target Coverage + γ × Packet Validity, where α, β, and γ are weighting coefficients, and α + β + γ = 1. The weighting coefficients can be adjusted according to the type of the object being tested and the testing requirements. For scenarios with high vulnerability triggering priority, the value of α can be increased; for scenarios with high target coverage priority, the value of β can be increased; for scenarios with high packet validity requirements, the value of γ can be increased. The fitness values of the second preset number of candidate individuals are compared, and the candidate individual with the largest fitness value is selected as the parent individual corresponding to this selection round. This process is repeated until all total selection rounds are completed, yielding the first predetermined number of parent individuals. This selection mechanism prioritizes individuals with high fitness while maintaining population diversity.
[0151] In the above embodiments, on the one hand, selecting parent individuals based on fitness can both prioritize the retention of high-fitness, superior individuals and prevent super-individuals from monopolizing the population, thus maintaining population diversity. On the other hand, the fitness value comprehensively considers three dimensions: vulnerability triggering probability, target coverage, and message effectiveness. This can comprehensively and accurately measure the vulnerability triggering potential of an individual, ensuring that the selected parent individuals not only have a high vulnerability triggering probability but also cover more effective targets, and that the generated messages have high effectiveness. This improves the quality and effectiveness of the selection operation, provides superior parent individuals for subsequent crossover and mutation operations, and further enhances the optimization effect of the genetic algorithm and the vulnerability discovery capability of fuzz testing.
[0152] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0153] Based on the same inventive concept, this application also provides a message generation apparatus for implementing the message generation method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more message generation apparatus embodiments provided below can be found in the limitations of the message generation method described above, and will not be repeated here.
[0154] In one exemplary embodiment, such as Figure 4 As shown, a structural block diagram of a message generation device is provided, including:
[0155] Selection module 10 is used to select at least two valid target points from each initial target point corresponding to the valid message set of the object under test;
[0156] The first construction module 20 is used to construct an initial target matrix based on the feature parameters of at least two effective target points; a row or column in the initial target matrix corresponds to the feature parameters of different dimensions of the same effective target point.
[0157] The mutation module 30 is used to mutate the initial target matrix according to each mutation function to obtain a new target matrix; different mutation functions are used to mutate the feature parameters of different dimensions of the effective targets in the initial target matrix.
[0158] The second construction module 40 is used to construct the initial population based on the initial target matrix and the new target matrix;
[0159] Optimization module 50 is used to iterate the initial population to obtain the target population;
[0160] The determination module 60 is used to determine the mutation message for the tested object based on the target population.
[0161] In the above embodiments, a mutation factor is determined individually for each effective target, and the trigger probability of each mutation function is dynamically adjusted according to the mutation factor. This allows the mutation operation to be adjusted specifically according to the stability and vulnerability triggering potential of the target. Furthermore, during the mutation process, only mutation functions that meet the triggering conditions are executed, avoiding unnecessary mutation operations. At the same time, different mutation functions mutate different dimensional feature parameters of the effective target, which can comprehensively cover various feature changes of the target, improving the efficiency and effectiveness of the mutation operation, generating more new target matrixes with high vulnerability triggering potential, and further enhancing the vulnerability discovery capability of fuzz testing.
[0162] In one embodiment, the mutation module 30 is specifically used for:
[0163] For each effective target in the initial target matrix, the trigger probability and transformation parameters of each mutation function are determined based on the mutation factor corresponding to the effective target. For each mutation function, if the trigger probability corresponding to the mutation function satisfies the mutation condition, the mutation function is used to mutate the feature parameters of different dimensions of the effective target that correspond to the mutation function, so as to obtain new feature parameters. The initial target matrix is updated using the new feature parameters of each initial target to obtain a new target matrix.
[0164] In one embodiment, the optimization module 50 is specifically used for:
[0165] For each iteration, a first preset number of parent individuals are selected from the initial population corresponding to the iteration; a crossover operation is performed on the first preset number of parent individuals to obtain a first preset number of child individuals; each child individual is mutated according to a different mutation function to obtain new child individuals, and a new initial population is constructed based on the new child individuals; if the iteration stopping condition is met, the new initial population is used as the target population; if the iteration stopping condition is not met, the new initial population is used as the initial population corresponding to the next iteration.
[0166] In one embodiment, the optimization module 50 is specifically used for:
[0167] From the initial population corresponding to each iteration round, individuals are selected for the total selection round. In each selection round, a second preset number of candidate individuals are selected from the initial population corresponding to the iteration round, and the candidate individual with the highest fitness is used as the parent individual for the selection round. Fitness is determined based on the vulnerability trigger probability, target coverage, and message validity of the candidate individual. The vulnerability trigger probability is determined based on the vulnerability trigger probability of each target contained in the candidate individual. The target coverage is determined based on the ratio of the number of valid targets contained in the candidate individual to the initial number of targets. The message validity is determined based on the number of messages corresponding to the candidate individual that conform to the message format and the total number of messages. The total selection round is the first preset number.
[0168] In one embodiment, the selection module 10 is specifically used for:
[0169] Based on at least one of the vulnerability correlation and information gain of each initial target corresponding to the valid message set of the tested object, at least two valid targets are selected from each initial target. The vulnerability correlation is used to measure the strength of the causal relationship between the mutation of the initial target and the vulnerability triggering of the tested object, and the information gain is used to measure the amount of information provided by the initial target for the vulnerability triggering of the tested object.
[0170] In one embodiment, the determining module 60 is specifically used for:
[0171] Based on the message generation format and the individual with the highest fitness in the target population, a mutated message is generated for the tested object.
[0172] Each module in the aforementioned message generation device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0173] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 5As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and databases. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media to run. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a message generation method.
[0174] Those skilled in the art will understand that Figure 5 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0175] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the message generation method described in any of the above embodiments.
[0176] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the message generation method described in any of the above embodiments.
[0177] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of the message generation method described in any of the above embodiments.
[0178] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0179] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0180] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0181] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A message generation method, characterized in that, The method includes: Select at least two valid target points from the initial target points corresponding to the valid message set of the tested object; An initial target matrix is constructed based on the feature parameters of the at least two effective target points; a row or column in the initial target matrix corresponds to the feature parameters of different dimensions of the same effective target point. The initial target matrix is mutated according to each mutation function to obtain a new target matrix; different mutation functions are used to mutate the feature parameters of different dimensions of the effective targets in the initial target matrix; Based on the initial target matrix and the new target matrix, construct the initial population; The initial population is iterated to obtain the target population; Based on the target population, determine the mutation message for the tested object.
2. The method according to claim 1, characterized in that, The step of mutating the initial target matrix according to each mutation function to obtain a new target matrix includes: For each effective target in the initial target matrix, the trigger probability of each mutation function is determined based on the mutation factor corresponding to the effective target. For each mutation function, if the trigger probability corresponding to the mutation function satisfies the mutation condition, the mutation function is used to mutate the feature parameters corresponding to the mutation function in different dimensions of the effective target to obtain new feature parameters. The initial target matrix is updated by using the new feature parameters of each initial target to obtain a new target matrix.
3. The method according to claim 1, characterized in that, Iterating through the initial population to obtain the target population includes: For each iteration round, a first preset number of parent individuals are selected from the initial population corresponding to the iteration round; Perform a crossover operation on the first preset number of parent individuals to obtain the first preset number of child individuals; The offspring individuals are mutated according to different mutation functions to obtain new offspring individuals, and a new initial population is constructed based on the new offspring individuals; If the iteration stopping condition is met, the new initial population is taken as the target population; If the iteration stopping condition is not met, the new initial population is used as the initial population for the next iteration round.
4. The method according to claim 3, characterized in that, The step of selecting a first preset number of parent individuals from the initial population corresponding to the iteration round includes: From the initial population corresponding to the iteration round, individuals are selected for a total selection round. In each selection round, a second preset number of candidate individuals are selected from the initial population corresponding to the iteration round, and the candidate individual with the highest fitness among the candidate individuals is taken as the parent individual corresponding to the selection round. The fitness is determined based on the vulnerability trigger probability, target coverage, and message validity of the candidate individual. The vulnerability trigger probability is determined based on the vulnerability trigger probability of each target included in the candidate individual. The target coverage is determined based on the ratio of the number of valid targets included in the candidate individual to the initial number of targets. The message validity is determined based on the number of messages that conform to the message format corresponding to the candidate individual to the total number of messages. The total number of selection rounds is the first preset number.
5. The method according to any one of claims 1-4, characterized in that, The step of selecting at least two valid target points from each initial target point corresponding to the valid message set of the tested object includes: Based on at least one of the vulnerability correlation and information gain of each initial target point corresponding to the valid message set of the tested object, select at least two valid targets from each initial target point. The vulnerability correlation is used to measure the strength of the causal relationship between the mutation of the initial target and the vulnerability triggering of the tested object, and the information gain is used to measure the amount of information provided by the initial target for the vulnerability triggering of the tested object.
6. The method according to any one of claims 1-4, characterized in that, The step of determining the mutation message for the tested object based on the target population includes: Based on the message generation format and the individual with the highest fitness in the target population, a mutated message for the tested object is generated.
7. A message generation apparatus, characterized in that, The device includes: The selection module is used to select at least two valid target points from each initial target point corresponding to the valid message set of the tested object. The first construction module is used to construct an initial target matrix based on the feature parameters of the at least two effective target points; a row or column in the initial target matrix corresponds to the feature parameters of different dimensions of the same effective target point. The mutation module is used to mutate the initial target matrix according to various mutation functions to obtain a new target matrix; different mutation functions are used to mutate the feature parameters of different dimensions of the effective targets in the initial target matrix. The second construction module is used to construct an initial population based on the initial target matrix and the new target matrix; An optimization module is used to iterate the initial population to obtain the target population; The determination module is used to determine the mutation message for the tested object based on the target population.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.