Fuzzy testing method for stateful network protocol
By constructing an initial test case corpus and using a customized exponential weighting algorithm to select important states, combined with a genetic algorithm to evaluate test case fitness, the problems of low efficiency and high false alarm rate in traditional fuzz testing methods are solved, and a more efficient network protocol is achieved. Fuzz testing and vulnerability mining.
Patent Information
- Application Number
- CN202410981966.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-07-22
AI Technical Summary
Traditional stateful network protocol fuzz testing methods have problems such as low efficiency and high false positive rate in the process of state selection, test case selection and retention, making it difficult to effectively evaluate the state value and select high-quality test cases.
By building an initial test case corpus, using a customized exponential weight algorithm (exp3) to select important states, and combining genetic algorithms to evaluate test case fitness, comprehensively considering state coverage, code coverage and the number of state transitions, new test cases are generated. Conduct fuzz testing and adjust the testing process based on feedback.
It improves the efficiency of network protocol fuzz testing and vulnerability mining capabilities, optimizes state selection and test case selection, reduces meaningless state testing, and improves testing efficiency and accuracy.
Smart Images

Figure CN118740482A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of network protocol security vulnerability detection, and in particular to a fuzzy testing method for stateful network protocols. Background Art
[0002] Network protocols are the foundation of the modern Internet. They describe the specifications for two communicating entities to pass data to each other. However, due to the complexity and diversity of network protocols, it is often challenging to implement network protocols correctly, which may lead to the introduction of vulnerabilities in the implementation process. For example, the Heartbleed vulnerability in OpenSSL, one of the famous implementations of the Transport Layer Security (TLS) protocol, can be used by malicious attackers to leak confidential data in the memory of remote devices. Therefore, vulnerabilities in network protocol implementations are a major threat to the entire cyberspace, and it is crucial to discover these target vulnerabilities. Fuzz testing is one of the most effective techniques for software security analysis. Its advantages are high test efficiency, ease of use, and low false positive rate. These advantages make it widely used in various scenarios, including network protocols, operating system kernels, and smart contracts. Since most network protocols have complex state spaces, traditional stateless fuzz testing methods cannot fully represent the internal state of network protocol servers, so the test efficiency is low. At present, fuzz testing methods for stateful network protocols can be mainly divided into two categories: stateful black-box fuzz testing and coverage-based gray-box fuzz testing. Stateful black-box fuzz testing methods randomly generate a large number of test cases and use state machine models to guide the fuzz testing process. However, this method often contains many invalid and redundant test cases. In order to improve the efficiency of fuzz testing, coverage-based gray-box fuzz testing has gradually attracted the attention of industry personnel. This method guides the testing process by collecting feedback information at runtime, which can reduce the blindness of the fuzz testing process and thus improve the efficiency of fuzz testing.
[0003] The existing coverage-based gray-box fuzz testing method mainly uses code coverage to guide the fuzz testing process. The method first selects the state to be tested according to the state selection strategy, then selects test cases from the test case queue corresponding to the state to be tested, and finally uses the test cases to fuzz test the network protocol server. However, due to the complex state space of stateful network protocols, traditional fuzz testing methods guided by code coverage are difficult to effectively test stateful network protocols. The main problems are as follows: (1) The information for evaluating the state is too single and cannot accurately evaluate the value of the state; (2) The lack of an effective state selection algorithm causes the fuzzer to spend a lot of time testing meaningless states, thereby reducing test efficiency; (3) The selection and retention process of test cases relies too much on code coverage and ignores other feedback information. Summary of the invention
[0004] The purpose of the present invention is to provide a fuzz testing method for stateful network protocols, which can solve the problems existing in traditional network protocol fuzz testing in terms of state selection, test case selection, test case retention, etc., and improve the efficiency of network protocol fuzz testing and vulnerability mining capabilities.
[0005] The objective of the present invention is achieved through the following technical solutions:
[0006] A fuzz testing method for a stateful network protocol, the method comprising:
[0007] Step 1: Build the initial test case corpus and perform compilation and instrumentation operations;
[0008] Step 2: Initialize the state array and select the target state for each round of fuzz testing through the state selection algorithm;
[0009] Step 3: Select a test case queue corresponding to the target state obtained in step 2 from the test case set, then select a test case from the test case queue to perform a mutation operation to generate a new test case, and then send the new test case to the network protocol server for fuzz testing;
[0010] Step 4: After the network protocol server completes a round of fuzz testing, feedback information of the network protocol server is collected, including code coverage, state coverage, and state transfer, and subsequent fuzz testing processes are guided based on the feedback information.
[0011] It can be seen from the technical solution provided by the present invention that the above method can solve the problems existing in traditional network protocol fuzz testing in terms of state selection, test case selection, test case retention, etc., and improve the efficiency of network protocol fuzz testing and vulnerability mining capabilities. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0013] Figure 1 A schematic flow chart of a fuzzy testing method for a stateful network protocol provided by an embodiment of the present invention;
[0014] Figure 2 A flowchart of a state selection process according to an embodiment of the present invention;
[0015] Figure 3 The figure is a schematic diagram of an implementation scenario of the example of the present invention. DETAILED DESCRIPTION
[0016] The following is a clear and complete description of the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments, which does not constitute a limitation of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0017] like Figure 1 The figure is a flow chart of a fuzzy testing method for a stateful network protocol provided by an embodiment of the present invention, the method comprising:
[0018] Step 1: Build the initial test case corpus and perform compilation and instrumentation operations;
[0019] In this step, firstly, the client and the network protocol server are started and communicated; all the data packets of the corresponding port of the network protocol server are obtained and these data packets are collected and retained; finally, the data packet analysis tool WireShark is used to parse the collected data packets, and all the request data packets are extracted as the initial test case queue set TestCaseSet, that is, TestCaseSet = {T, ..., T i , ..., T n}, T i Refers to the i-th test case queue in TestCaseSet, i = 1, ..., n, where n is the total number of test case queues;
[0020] Test case queue T i It consists of test cases, namely T i ={t i,1 ,...t i,j , ..., t i,m}, t i,j represents the jth test case in the i-th test case queue, j = 1, ..., m, where m is T i Total number of test cases in;
[0021] Compilation is the process of converting source code into an executable program. Instrumentation is the process of adding additional code to the target program at compile time or runtime. Instrumentation can obtain relevant feedback information when the program is running. Specifically, the compilation and instrumentation tool LLVM is used to compile and instrument the target protocol server program to generate corresponding target code for collecting feedback information when the program is running, including code coverage and status information.
[0022] Step 2: Initialize the state array and select the target state for each round of fuzz testing through the state selection algorithm;
[0023] In this step, when fuzz testing a stateful network protocol, the state to be tested must be selected first. However, not all states are equally important, so an effective state selection algorithm is needed to prioritize important states. These important states can usually increase code coverage and help discover new states or new state transitions.
[0024] The state array is represented as States = {S1, ..., S k , ..., S u},S k represents the kth state, k = 1, ..., u, u is the total number of states; the state selection process can be regarded as a process of fully "utilizing" known important states and actively "exploring" unknown important states, which can be described by the multi-armed bandit problem in reinforcement learning. The customized exponential weight algorithm exp3 is used to guide the state selection process, so that each round of testing can select important states as much as possible, such as Figure 2 FIG. 1 is a flow chart of a state selection process according to an embodiment of the present invention, which specifically includes:
[0025] First, an initial weight w is assigned to each state k=1,...,u k (0), the initial weight is defined as:
[0026]
[0027] Each state k is associated with a reward value reword, which is used to represent the trade-off between rewarding states and rarely tested states, defined as:
[0028]
[0029] Among them, states_discovered indicates the new state discovered when the state is selected as the state to be tested; paths_discovered indicates the new code path discovered when the state is selected as the state to be tested; state_trans indicates the number of state transitions when the state is selected as the state to be tested; fuzzs indicates the number of times the state is triggered during the fuzz test; state_selects indicates the number of times the state is selected;
[0030] Then, in the rth round of fuzzy testing, the cumulative loss value Lk(r) of each state k is calculated. The calculation of the cumulative loss value Lk(r) is as follows:
[0031]
[0032]
[0033] Among them, loss k (r) refers to the loss value of selecting the kth state in the rth round; reword k (r) refers to the reward value of selecting the kth state in the rth round; MaxReword(r) refers to the maximum reward value among all states in the rth round; loss k (τ) refers to the loss value of selecting the kth state in the τth round; the cumulative loss value L k (r) is used to update the weight of the state, thereby affecting the probability of the state being selected;
[0034] Based on the cumulative loss value L k (r) Calculate the weight w of each state k in round r k (r), and according to the weight w k (r) Calculate the probability distribution p of each state k being selected in round r k (r); finally, according to the probability distribution p k (r) Randomly select a state for fuzz testing and observe and record the loss value loss k (r);
[0035] The weight w k (r) and probability distribution p k (r) is defined as follows:
[0036]
[0037]
[0038] η is the learning rate, which is used to control the degree of exploration of the algorithm.
[0039] The above process comprehensively evaluates the value of the selected target state from multiple aspects such as state coverage, code coverage, and the number of times the state is tested, and introduces a customized exp3 algorithm to guide the state selection process in stateful network protocol fuzz testing, which can give priority to important states for testing, thereby improving the efficiency of fuzz testing and vulnerability mining capabilities.
[0040] Step 3: Select a test case queue corresponding to the target state obtained in step 2 from the test case set, then select a test case from the test case queue to perform a mutation operation to generate a new test case, and then send the new test case to the network protocol server for fuzz testing;
[0041] In this step, how to select test cases with high testing efficiency and strong vulnerability discovery capabilities is a difficulty in network protocol fuzz testing. Traditional methods over-rely on the code coverage indicator when selecting test cases, but ignore other important state information in the test process, such as the number of state transitions. This makes it difficult to select high-quality test cases, which in turn affects the effectiveness and efficiency of the test.
[0042] This application evaluates each test case by introducing the concept of fitness in the genetic algorithm. Each test case has a fitness value Fitness, which is used to quantify the performance of the test case during the test process, specifically expressed as:
[0043] Fitness=α·F scov +β·F ccov +γ·F Strans
[0044] where F Scov is the fitness based on state coverage; F Ccov is the fitness based on code coverage; F strans is the fitness based on the number of state transitions; α, β, Y are dynamic parameters and α+β+γ=1;
[0045] For a test case c, its fitness value is Fitness c , then the probability of being selected is:
[0046]
[0047] Where N is the total number of test cases in the test case queue;
[0048] The present invention comprehensively evaluates test cases from three dimensions: state coverage, code coverage, and number of state transitions. It can overcome the limitation of traditional methods that over-rely on a single code coverage metric, and can more deeply and effectively explore the state space of stateful network protocols, thereby improving the efficiency of fuzz testing and vulnerability mining capabilities.
[0049] After the test cases are selected, the test cases are mutated to generate new test cases, and sent to the network protocol server for fuzz testing. The mutation strategies include bit-level mutation, block-level mutation, and byte-level mutation. The mutation strategies are shown in Table 1:
[0050] Table 1 Test case mutation module mutation strategy
[0051]
[0052]
[0053] These strategies combined together provide more possibilities for test case changes. The mutation process is divided into two stages. The first stage: flip some bits according to the size of the test case, which is divided into bit-level flipping and byte-level flipping, and then insert and delete operations on the test case at the bit level, block level and byte level; the second stage: this stage is a random combination of various mutation strategies. Specifically, various mutation strategies have a certain probability of being selected. Once selected, the strategy will be applied to the mutation process of the test case to achieve diversified mutation effects;
[0054] After the network protocol server completes a round of fuzz testing, the fitness value Fitness of the corresponding test case is modified according to the feedback information of the network protocol server, and the test cases in the test case queue are adjusted. Specifically, remove_rate(x) is used to represent the proportion of test cases removed in the xth round, which is defined as:
[0055] remove_rate(x)=remove_rate(0)×e -λ·x
[0056] Where, remove_rate(0) represents the initial removal rate; λ is a decay exponent; based on experience, the initial value of λ is set to 0.9, and then dynamically adjusted based on test results;
[0057] In each round, test cases with low fitness in the queue are removed according to remove_rate(x).
[0058] The advantage of the above method is that it allows low-quality test cases to be quickly removed in the early stage, and the removal speed gradually decreases over time, thereby retaining the diversity of test cases in the later stage of testing and avoiding the problem of low fuzz testing efficiency caused by premature convergence.
[0059] Step 4: After the network protocol server completes a round of fuzz testing, feedback information of the network protocol server is collected, including code coverage, state coverage, and state transfer, and subsequent fuzz testing processes are guided based on the feedback information.
[0060] In this step, feedback information from the network protocol server is collected. If a new state is generated new _ s t a t e , then add the new state new_state to the state array states;
[0061] Update the reward value reword of each state in the state array states and the fitness value Fitness of the corresponding test case according to the feedback information collected from the network protocol server;
[0062] Finally, a new round of fuzz testing is performed.
[0063] It is worth noting that the contents not described in detail in the embodiments of the present invention belong to the prior art known to professional and technical personnel in the field.
[0064] For example, if Figure 3 The figure shows a schematic diagram of the implementation scenario of the example of the present invention, which includes an intelligent network tester and multiple servers equipped with different network protocols, such as DTLS, FTP, DNS and other protocol servers. The intelligent network tester is mainly used to send a large number of abnormal, unexpected or randomly generated test cases to the above-mentioned network protocol servers and collect the corresponding feedback information of the servers, and generate a detailed test report based on the feedback information, so as to provide data support and decision-making basis for the optimization and improvement of network protocols.
[0065] Through the method described in the embodiment of the present invention, compared with other network protocol fuzz testing methods, the present invention takes into account the importance of state selection for the fuzz testing process, models the state selection process as an "exploration" and "utilization" problem, and introduces the exp3 algorithm variant in the multi-armed bandit problem to help the fuzzifier select a more potential state as the target state of the fuzz test, thereby solving the problem of traditional network protocol fuzz testing in state selection.
[0066] At the same time, the present invention evaluates states and test cases by comprehensively considering multiple dimensions such as code coverage, state coverage, and the number of state transitions, and no longer relies too much on code coverage, thereby solving the problems of redundant test cases and insufficient testing in traditional methods.
[0067] In addition, a person skilled in the art can understand that all or part of the steps in the above-mentioned embodiment method can be implemented by instructing related hardware through a program, and the corresponding program can be stored in a computer-readable storage medium. The above-mentioned storage medium can be a read-only memory, a disk or an optical disk, etc.
[0068] The above is only a preferred specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by any technician familiar with the technical field within the technical scope disclosed in the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims. The information disclosed in the background technology section of this article is only intended to deepen the understanding of the overall background technology of the present invention, and should not be regarded as an admission or in any form that the information constitutes prior art known to those skilled in the art.
Claims
1. A fuzz testing method for stateful network protocols, It is characterized in that The method comprises: Step 1: Build the initial test case corpus and perform compilation and instrumentation operations; Step 2: Initialize the state array and select the target state for each round of fuzz testing through the state selection algorithm; Step 3: Select a test case queue corresponding to the target state obtained in step 2 from the test case set, then select a test case from the test case queue to perform a mutation operation to generate a new test case, and then send the new test case to the network protocol server for fuzz testing; Step 4: After the network protocol server completes a round of fuzz testing, feedback information of the network protocol server is collected, including code coverage, state coverage, and state transfer, and subsequent fuzz testing processes are guided based on the feedback information.
2. According to the fuzz testing method for stateful network protocols according to claim 1, It is characterized in that In step 1, firstly, the client and the network protocol server are started and communicated; all data packets of the corresponding port of the network protocol server are obtained, and these data packets are collected and retained; finally, the data packet analysis tool WireShark is used to parse the collected data packets, and all request data packets are extracted as the initial test case queue set TestCaseSet, that is, TestCaseSet = {T, ..., T i , ..., T n }, T i Refers to the i-th test case queue in TestCaseSet, i = 1, ..., n, where n is the total number of test case queues; Test case queue T i It consists of test cases, namely T i ={t i,1 ,...t i,j , ..., t i,m }, t i,j represents the jth test case in the i-th test case queue, j = 1, ..., m, where m is T i Total number of test cases in; Then, the compilation and instrumentation tool LLVM is used to perform compilation and instrumentation operations on the target protocol server program to generate corresponding target code for collecting feedback information during program runtime, including code coverage and status information.
3. According to the fuzz testing method for stateful network protocols described in claim 1, It is characterized in that The process of step 2 is specifically as follows: The state array is represented as States = {S 1 , ..., S k , ..., S u },S k represents the kth state, k = 1, ..., u, and u is the total number of states. The customized exponential weight algorithm exp3 is used to guide the state selection process, so that each round of testing can select as many important states as possible. Specifically: First, an initial weight Wk(0) is assigned to each state k=1,...,u. The initial weight is defined as: Each state k is associated with a reward value reword, which is used to represent the trade-off between rewarding states and rarely tested states, defined as: Among them, states_discovered indicates the new state discovered when the state is selected as the tested state; paths_discovered indicates the new code paths discovered when this state is selected as the state to be tested; state_trans indicates the number of state transitions when this state is selected as the state to be tested; fuzzs indicates the number of times this state is triggered during the fuzz test; state_selects indicates the number of times this state is selected; Then, in the rth round of fuzz testing, the cumulative loss value L for each state k is calculated k (r), cumulative loss value L k (r) is calculated as follows: Among them, loss k (r) refers to the loss value of selecting the kth state in the rth round; reword k (r) refers to the reward value of selecting the kth state in the rth round; MaxReword(r) refers to the maximum reward value among all states in the rth round; loss k (τ) refers to the loss value of selecting the kth state in the τth round; the cumulative loss value L k (r) is used to update the weight of the state, thereby affecting the probability of the state being selected; Based on the cumulative loss value L k (r) Calculate the weight w of each state k in round r k (r), and according to the weight w k (r) Calculate the probability distribution p of each state k being selected in round r k (r); finally, according to the probability distribution p k (r) Randomly select a state for fuzz testing and observe and record the loss value loss k (r); The weight w k (r) and probability distribution p k (r) is defined as follows: η is the learning rate, which is used to control the degree of exploration of the algorithm.
4. According to the fuzz testing method for stateful network protocols according to claim 1, It is characterized in that In step 3, each test case is evaluated by introducing the concept of fitness in the genetic algorithm. Each test case has a fitness value Fitness, which is used to quantify the performance of the test case during the test process. Specifically, it is expressed as: Fitness=α·F Scov +β·F Ccov +γ·F Strans Among them, F Scov is the fitness based on state coverage; F Ccov is the fitness based on code coverage; F Strans is the fitness based on the number of state transitions; α, β, γ are dynamic parameters and α+β+γ=1; For a test case c, its fitness value is Fitness c , then the probability of being selected is: Where N is the total number of test cases in the test case queue; After the test cases are selected, the test cases are mutated to generate new test cases, which are then sent to the network protocol server for fuzz testing. The mutation strategies include bit-level mutation, block-level mutation, and byte-level mutation. The mutation process is divided into two stages. The first stage: according to the size of the test case, some bits are flipped, which is divided into bit-level flipping and byte-level flipping, and then the test case is inserted and deleted at the bit level, block level and byte level; the second stage: various mutation strategies have a certain probability of being selected. Once selected, the strategy will be applied to the mutation process of the test case to achieve diversified mutation effects; After the network protocol server completes a round of fuzz testing, the fitness value Fitness of the corresponding test case is modified according to the feedback information of the network protocol server, and the test cases in the test case queue are adjusted. Specifically, remove_rate(x) is used to represent the proportion of test cases removed in the xth round, which is defined as: remove_rate(x)=remove_rate(0)×e -λ·x Wherein, remove_rate(0) represents the initial removal rate; λ is a decay exponent, the initial value of λ is set to 0.9, and then dynamically adjusted according to the test results; In each round, test cases with low fitness in the queue are removed according to remove_rate(x).
5. According to the fuzz testing method for stateful network protocols according to claim 1, It is characterized in that In step 4, if a new state new_state is generated, the new state new_state is added to the state array states; Update the reward value reword of each state in the state array states and the fitness value Fitness of the corresponding test case according to the feedback information collected from the network protocol server; Finally, a new round of fuzz testing is performed.
Citation Information
Patent Citations
Deep reinforcement learning software test method based on coverage guide fuzzy test
CN114356778A
Model-based network protocol fuzzy test system and test method
CN115617683A
Stateful network protocol vulnerability test method and system based on state selection optimization
CN116827835A
Modbus TCP (Transmission Control Protocol) fuzzy test method based on multi-arm Huger machine algorithm
CN117478367A
System and method for fuzzing test orchestration using reinforcement learning
US20210240601A1
Cited By
Network protocol fuzz testing method and device, storage medium and electronic equipment
CN119743417A
Network protocol fuzzy test method and system based on protocol process state machine
CN119854186A
Fuzzy test method and fuzzy test device for AFDX network protocol
CN119892700A
Network protocol fuzz testing method based on branch information enhancement
CN120416120A
Fuzzy testing method for kernel network stack and related equipment
CN121217625A
