A method for improving the efficiency of network protocol fuzz testing based on shared memory
By using a shared memory region and synchronization mechanism between the fuzzing tool and the target program, the problem of low efficiency in traditional network protocol fuzzing is solved, and a more efficient testing process is achieved.
Patent Information
- Application Number
- CN202510254781.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-05
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2045-03-05
AI Technical Summary
Traditional network protocol fuzzing methods are inefficient, mainly due to the high data transmission overhead and frequent context switching caused by the IPC mechanism.
A shared memory mechanism is adopted to create a shared memory area between the fuzzing tool and the target program to store test cases and results. A communication mechanism is established through synchronization mechanisms such as semaphores and mutexes to reduce data transmission overhead and context switching.
It improves the efficiency of network protocol fuzz testing, reduces data transmission overhead and context switching frequency, enhances testing flexibility, and simplifies communication processes.
Abstract
Description
Technical Field
[0001] This invention belongs to the field of network security technology, specifically relating to a method for improving the efficiency of fuzz testing of network protocols based on shared memory. Background Technology
[0002] Fuzzing is an effective software vulnerability discovery technique. It involves inputting large amounts of unexpected data into a target program, triggering program anomalies, and thus uncovering potential security vulnerabilities. Network protocol fuzzing targets the implementation of network protocols, aiming to discover vulnerabilities within these implementations.
[0003] Traditional network protocol fuzzing methods typically employ inter-process communication (IPC) mechanisms, such as pipes and sockets, to transfer test cases from the fuzzing tool to the target program. However, this method is inefficient, primarily because:
[0004] High data transmission overhead: The IPC mechanism requires multiple data copies, increasing the overhead of data transmission.
[0005] Frequent context switching: The IPC mechanism requires frequent context switching, which reduces testing efficiency. Summary of the Invention
[0006] (a) Technical problems to be solved
[0007] The technical problem to be solved by this invention is to provide a method for improving the efficiency of fuzz testing of network protocols.
[0008] (II) Technical Solution
[0009] To address the aforementioned technical problems, this invention provides a method for improving the efficiency of fuzz testing of network protocols based on shared memory, comprising the following steps:
[0010] Step 1: Create a shared memory region: Create a shared memory region between the fuzzing tool and the target program to store test cases and test results;
[0011] Step 2: Initialize the shared memory region: The fuzzing tool and the target program initialize the shared memory region and establish a communication mechanism.
[0012] Step 3: Generate test cases: The fuzzing tool generates test cases and writes them to the shared memory area;
[0013] Step 4: Execute test cases: The target program reads test cases from the shared memory area and executes them, then writes the execution results back to the shared memory area;
[0014] Step 5: Monitor execution results: The fuzzing tool monitors the execution results in the shared memory area to determine whether the target program has encountered any abnormalities;
[0015] Repeat steps 3-5: Repeat steps 3-5 until the preset test stop condition is met.
[0016] Preferably, in step 1, a shared memory region is created using the shared memory API provided by the operating system. The size of the shared memory region is dynamically adjusted according to the size and number of test cases, and it can accommodate all test cases and test results. When creating the shared memory region, a dynamic sharding strategy is introduced, and memory blocks are automatically divided based on protocol field characteristics, with each field corresponding to an independent memory shard. At the same time, a Bloom filter is used to detect memory access hotspots and dynamically adjust the caching strategy of the preset high-frequency access shards. In addition, the protocol header and payload are stored separately, with the protocol header using fixed sharding and the payload using elastic sharding.
[0017] Preferably, in step 2, when initializing the shared memory region, the fuzzing tool and the target program respectively map the shared memory region to their respective address spaces and establish a communication mechanism. The communication mechanism includes synchronization mechanisms such as semaphores and mutexes to ensure that the fuzzing tool and the target program have mutually exclusive access to the shared memory region.
[0018] Preferably, the communication mechanism established in step 2 includes a lock-free synchronization mechanism based on atomic operations, which supports the transmission of batch test cases by introducing circular buffer read / write pointers.
[0019] Preferably, the method further includes a three-level state machine to control the test process, wherein state 0 represents test case ready; state 1 represents execution in progress; and state 2 represents result pending reading.
[0020] Preferably, in step 3, the fuzz testing tool uses multiple methods to generate test cases, including random generation, rule-based generation, and model-based generation. The generated test cases cover various boundary conditions and abnormal situations of the network protocol.
[0021] Preferably, in step 4, when the target program executes the test cases, instrumentation code is inserted into the target program, or symbolic execution technology is used to analyze the target program.
[0022] Preferably, the anomalies monitored by the fuzzing tool in step 5 include target program crashes, memory leaks, and abnormal outputs. In addition, after an anomaly is detected, the execution results of the anomaly are analyzed to locate the location and cause of the vulnerability.
[0023] Preferably, in step 1, a shared memory region is created using shmget and attached to the process address space using shmat; in step 2, when initializing the shared memory region, two semaphores are created using sem_open, one for synchronizing test cases and the other for passing results; in step 3, the fuzzing tool Fuzzer generates test cases and writes them to the shared memory, and the semaphore sem_test_case notifies the target program that the test cases are ready; in step 4, when the target program reads and executes the test cases from the shared memory region, string processing is used to simulate the execution of network protocols, the execution results are written to the shared memory region, and the semaphore sem_result is used to notify the fuzzing tool.
[0024] The present invention also provides a system for implementing the method.
[0025] (III) Beneficial Effects
[0026] The method for improving the efficiency of network protocol fuzz testing based on shared memory provided by this invention has the following beneficial effects:
[0027] Improved testing efficiency: By using a shared memory mechanism, data transfer overhead and the number of context switches are reduced, thus improving testing efficiency.
[0028] Enhanced testing flexibility: The size of the shared memory region can be dynamically adjusted according to testing needs, enhancing testing flexibility.
[0029] Simplified testing process: The shared memory mechanism simplifies the communication process between fuzzing tools and target programs, reducing the complexity of testing. Detailed Implementation
[0030] To make the objectives, contents, and advantages of the present invention clearer, the specific embodiments of the present invention will be described in further detail below with reference to examples.
[0031] The method for improving network protocol fuzz testing based on shared memory provided in this invention includes the following steps:
[0032] Step 1: Create a shared memory region: Create a shared memory region between the fuzzing tool and the target program to store test cases and test results.
[0033] Step 2: Initialize the shared memory region: The fuzzing tool and the target program initialize the shared memory region and establish a communication mechanism.
[0034] Step 3: Generate test cases: The fuzzing tool generates test cases and writes them to the shared memory area.
[0035] Step 4: Execute test cases: The target program reads test cases from the shared memory area and executes them, then writes the execution results back to the shared memory area.
[0036] Step 5: Monitor execution results: The fuzzing tool monitors the execution results in the shared memory area to determine whether the target program has encountered any abnormalities.
[0037] Repeat steps 3-5: Repeat steps 3-5 until the preset test stop condition is met.
[0038] Specifically as follows:
[0039] 1. Creation and initialization of shared memory regions
[0040] A shared memory region is a memory area shared between the fuzzing tool and the target program, used to store test cases and test results. The creation and initialization of the shared memory region is a key step in the method of this invention.
[0041] Create a shared memory region: Use the shared memory API provided by the operating system (e.g., the shmget and shmat functions in Linux) to create a shared memory region. The size of the shared memory region should be dynamically adjusted according to the size and number of test cases to ensure that it can accommodate all test cases and test results. A dynamic sharding strategy is introduced, automatically dividing memory blocks based on protocol field characteristics, with each field corresponding to an independent memory shard. A Bloom filter is also used to detect memory access hotspots and dynamically adjust the caching strategy for frequently accessed shards. Furthermore, the protocol header and payload are stored separately; the protocol header uses fixed sharding, while the payload uses flexible sharding.
[0042] Initializing the shared memory region: The fuzzing tool and the target program need to map the shared memory region to their respective address spaces and establish a communication mechanism. This communication mechanism includes synchronization mechanisms such as semaphores and mutexes to ensure mutual exclusion of access to the shared memory region by both the fuzzing tool and the target program. Specifically, this includes implementing a lock-free synchronization mechanism based on atomic operations, and supporting batch test case transfer by introducing circular buffer read / write pointers. A three-level state machine is set up to control the test flow, where state 0 represents test case ready; state 1 represents execution in progress; and state 2 represents results pending.
[0043] 2. Test Case Generation and Execution
[0044] The generation and execution of test cases are core steps in network protocol fuzz testing. This invention improves the transmission efficiency of test cases through a shared memory mechanism.
[0045] Generating test cases: Fuzzing tools can generate test cases using various methods, including random generation, rule-based generation, and model-based generation. The generated test cases should cover various boundary conditions and abnormal situations of the network protocol.
[0046] Executing test cases: The target program reads test cases from the shared memory area and executes them. To improve test coverage, instrumentation code is inserted into the target program when test cases are executed, or symbolic execution techniques are used to analyze the target program.
[0047] 3. Monitoring and analysis of execution results
[0048] Monitoring and analyzing execution results is a crucial step in discovering network protocol vulnerabilities. The method of this invention improves the transmission efficiency of execution results through a shared memory mechanism.
[0049] Monitoring execution results: Fuzzing tools need to monitor the execution results in the shared memory area to determine if the target program has encountered any anomalies. Monitored anomalies include target program crashes, memory leaks, and abnormal output. Furthermore, after detecting anomalies, the execution results are analyzed to pinpoint the location and cause of vulnerabilities.
[0050] In this embodiment, a shared memory region is created using `shmget` and attached to the process address space using `shmat`. During the initialization of the shared memory region, two semaphores are created using `sem_open`, one for synchronizing test cases and the other for passing results. Test cases are generated using the fuzzing tool `Fuzzer` and written to the shared memory. The semaphore `sem_test_case` notifies the target program that the test cases are ready. The target program then returns the execution result, and synchronization is achieved via the semaphore `sem_result`.
[0051] When executing test cases, the target program reads the test cases from shared memory and executes them (here, simple string manipulation is used to simulate the execution of network protocols). The execution results are written to shared memory and notified to the fuzzing tool via the semaphore sem_result.
[0052] During resource cleanup, use shmdt and shmctl to release shared memory; use sem_unlink to delete semaphores.
[0053] The following example, testing a simple network protocol, illustrates the specific implementation of this invention.
[0054] Create a shared memory region: Use the shared memory API provided by the operating system to create a shared memory region of 1MB in size.
[0055] Initialize the shared memory region: The fuzzing tool and the target program respectively map the shared memory region to their respective address spaces and use a semaphore mechanism to achieve synchronization.
[0056] Test case generation: The fuzzing tool uses a random generation method to generate 1000 test cases and writes them to a shared memory area.
[0057] Execute test cases: The target program reads test cases from the shared memory area and executes them, then writes the execution results back to the shared memory area.
[0058] Monitoring execution results: Fuzzing tools monitor the execution results in the shared memory area to determine whether the target program has crashed, leaked memory, or experienced other anomalies.
[0059] Repeat steps 3-5 until all test cases have been tested.
[0060] The program execution process includes four steps:
[0061] 1. The parent process (fuzzing tool) generates test cases and writes them to shared memory.
[0062] 2. The child process (target program) reads test cases from shared memory and executes them.
[0063] 3. The target program writes the execution result to shared memory.
[0064] 4. The fuzzing tool reads and outputs the execution results.
[0065] As can be seen, the method for improving network protocol fuzzing based on shared memory provided by this invention can effectively improve the efficiency of network protocol fuzzing through the shared memory mechanism, and has high practical value. In practical applications, the method of this invention can be optimized and improved according to specific testing needs and environments.
[0066] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for improving the efficiency of fuzz testing of network protocols based on shared memory, characterized in that, Includes the following steps: Step 1: Create a shared memory region: Create a shared memory region between the fuzzing tool and the target program to store test cases and test results; Step 2: Initialize the shared memory region: The fuzzing tool and the target program initialize the shared memory region and establish a communication mechanism. Step 3: Generate test cases: The fuzzing tool generates test cases and writes them to the shared memory area; Step 4: Execute test cases: The target program reads test cases from the shared memory area and executes them, then writes the execution results back to the shared memory area; Step 5: Monitor execution results: The fuzzing tool monitors the execution results in the shared memory area to determine whether the target program has encountered any abnormalities; Repeat steps 3-5: Repeat steps 3-5 until the preset test stop condition is reached; In step 1, a shared memory region is created using the shared memory API provided by the operating system. The size of the shared memory region is dynamically adjusted according to the size and number of test cases, and it can accommodate all test cases and test results. When creating a shared memory region, a dynamic sharding strategy is introduced, which automatically divides memory blocks based on protocol field characteristics, with each field corresponding to an independent memory shard; at the same time, a Bloom filter is used to detect memory access hotspots and dynamically adjust the caching strategy of preset high-frequency access shards. In addition, the protocol header and payload are stored separately, with the protocol header using fixed fragmentation and the payload using flexible fragmentation; The communication mechanism established in step 2 includes a lock-free synchronization mechanism based on atomic operations, which supports the transmission of batch test cases by introducing circular buffer read / write pointers.
2. The method as described in claim 1, characterized in that, In step 2, when initializing the shared memory region, the fuzzing tool and the target program respectively map the shared memory region to their respective address spaces and establish a communication mechanism. The communication mechanism includes synchronization mechanisms such as semaphores and mutexes to ensure that the fuzzing tool and the target program have mutually exclusive access to the shared memory region.
3. The method as described in claim 1, characterized in that, This method also sets up a three-level state machine to control the test process, where state 0 represents test case ready; state 1 represents execution in progress; and state 2 represents result pending reading.
4. The method as described in claim 1, characterized in that, In step 3, the fuzzing tool uses various methods to generate test cases, including random generation, rule-based generation, and model-based generation. The generated test cases cover various boundary conditions and abnormal situations of network protocols.
5. The method as described in claim 4, characterized in that, In step 4, when the target program executes the test cases, instrumentation code is inserted into the target program, or symbolic execution techniques are used to analyze the target program.
6. The method as described in claim 5, characterized in that, In step 5, the anomalies monitored by the fuzzing tool include target program crashes, memory leaks, and abnormal outputs. In addition, after detecting an anomaly, the execution results of the anomaly are analyzed to locate the location and cause of the vulnerability.
7. The method as described in claim 6, characterized in that, In step 1, a shared memory region is created using `shmget` and attached to the process address space using `shmat`. In step 2, during the initialization of the shared memory region, two semaphores are created using `sem_open`, one for synchronizing test cases and the other for passing results. In step 3, the fuzzing tool `Fuzzer` generates test cases and writes them to the shared memory. The semaphore `sem_test_case` is used to notify the target program `TargetProgram` that the test cases are ready. In step 4, when the target program `TargetProgram` reads and executes the test cases from the shared memory region, string manipulation is used to simulate network protocol execution. The execution results are written to the shared memory region, and the semaphore `sem_result` is used to notify the fuzzing tool.
Citation Information
Patent Citations
Automation software loophole verification system and method based on loophole library
CN107480531A
Processing method and device for testing embedded operating system, equipment and medium
CN118069531A