Industrial protocol fuzzy test method and system based on Transform and particle swarm optimization
By combining Transformer and Particle Swarm Optimization methods, the problem of insufficient protocol modeling capabilities and mutation strategies in industrial control protocol security testing is solved, achieving efficient and intelligent protocol vulnerability detection, generating high-quality test cases, and improving the automation and effectiveness of protocol security testing.
Patent Information
- Application Number
- CN202511424459.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-30
- Publication Date
- 2025-11-18
AI Technical Summary
Existing industrial control protocol security testing suffers from limited protocol sequence modeling capabilities, a lack of adaptive feedback adjustment in mutation strategies, and insufficient diversity and adaptability of test samples, which limits the improvement of vulnerability detection capabilities and efficiency.
We employ a method based on Transformer and Particle Swarm Optimization (PSO). By integrating the attention mechanism into the Transformer model, we gain a deep understanding of the protocol's syntax structure and semantic specifications. We then combine the PSO algorithm with adaptive mutation to generate high-quality test cases and optimize the mutation strategy based on feedback.
It significantly improves the ability to discover unknown and critical vulnerabilities, enhances the diversity of test cases and protocol compliance, and enables smarter and faster protocol anomaly exploration.
Smart Images

Figure CN120979992A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of security testing technology for industrial control protocols, and relates to a fuzzy testing method and system for industrial protocols based on Transformer and particle swarm optimization. Background Technology
[0002] With the advent of Industry 4.0, Industrial Control Systems (ICS) have become the core of modern industrial automation and intelligent manufacturing, and are widely used in critical infrastructure fields. Industrial Control Protocols (ICPs), as the foundation of inter-device communication in ICS, play a crucial role in information exchange and process control. However, due to limitations in historical architecture and security design concepts, many industrial control protocols did not adequately consider cybersecurity measures in their initial design, making them highly vulnerable to cyber threats. Once attacked, they could lead to production system paralysis, significant economic losses, and social security risks. Therefore, improving the security detection capabilities of industrial control protocols has become an important research direction in the field of industrial information security. Existing industrial protocol fuzzing techniques mainly use rule-based random mutation or predefined syntax templates to generate test cases, relying on manual configuration of protocol formats, resulting in low automation levels and insufficient adaptability to complex or long-sequence protocols. In recent years, the development of deep learning technology has led to the introduction of sequence models such as RNNs and LSTMs, as well as methods such as Generative Adversarial Networks (GANs) and Transformers into the protocol test case generation process. Related research attempts to improve the diversity and protocol compliance of test samples through data-driven methods, and to improve anomaly detection efficiency by combining mechanisms such as coverage guidance and feedback optimization, but significant shortcomings still exist in practical applications. The core problem currently facing the field of industrial protocol fuzz testing is that existing deep learning modeling methods can only capture limited temporal features and struggle to effectively integrate content dependencies and long-distance relationships, resulting in limited performance in terms of protocol adaptability and coverage of generated test cases. Traditional mutation strategies are mostly statically set and lack dynamic adaptive capabilities based on test feedback, making it difficult to cope with the ever-changing security threats in industrial protocol environments. Data-driven methods struggle to balance sample diversity and practical acceptability, with some models exhibiting issues such as homogeneous generated samples and difficulty in triggering diverse anomalies. The fundamental reason is that industrial protocols have complex structures and strong data dependencies, making it difficult for existing technologies to fully characterize the inherent semantics and anomaly space of protocols. In addition, the limited feedback observation and imperfect mutation strategies and feedback adjustment mechanisms in actual industrial control environments severely restrict the improvement of protocol vulnerability detection capabilities and efficiency, thereby affecting the intelligence, automation, and effectiveness of industrial control protocol security testing. New methods are urgently needed to achieve breakthroughs and optimizations. Summary of the Invention
[0003] The purpose of this invention is to solve the technical problems existing in the security testing of industrial control protocols, such as limited protocol sequence modeling capabilities, lack of adaptive feedback adjustment in mutation strategies, and insufficient diversity of test samples and protocol adaptability. This invention provides an industrial protocol fuzzy testing method and system based on Transformer and particle swarm optimization.
[0004] To achieve the above objectives, the present invention employs the following technical solution: The first aspect of this invention provides an industrial protocol fuzz testing method based on Transformer and Particle Swarm Optimization, comprising the following steps: Acquire industrial protocol data; preprocess the industrial protocol data; The pre-processed industrial protocol data is input into the trained Transformer model with fusion attention mechanism, and the test case set is output. The particle swarm optimization algorithm is used to mutate the test case set to generate a new test case set. The generated new test case set is input into the industrial equipment for testing, the industrial equipment response is monitored and analyzed, and the mutation is optimized based on the industrial equipment response.
[0005] Furthermore, the preprocessing of the industrial protocol data specifically includes: The industrial protocol data is parsed and split to generate several data sequences; Add start and end symbols before and after each data sequence.
[0006] Furthermore, the Transformer model of the fusion attention mechanism includes a relative position attention module, a spectrum hybrid attention module, and a weighted fusion module; the data sequence is processed by the relative position attention module and the spectrum hybrid attention module respectively; the output of the relative position attention module and the output of the spectrum hybrid attention module are weighted and fused before being output.
[0007] Furthermore, the step of using particle swarm optimization to mutate the test case set and generate a new test case set specifically involves: Based on the current mutation operator probability distribution, a mutation operator is selected to mutate the test cases, generating mutated samples; The mutated samples are input into industrial equipment for testing, and corresponding scalar rewards are obtained. Based on the scalar reward, the mutation operator probability distribution of the test cases is optimized using the particle swarm optimization algorithm; Iterate through the above process to obtain a new set of test cases.
[0008] Furthermore, the mutation operators include function code replacement, data segment length expansion, check destruction, boundary value injection, field rearrangement, and semantic preservation fine-tuning.
[0009] Furthermore, the velocity update formula for the particle swarm optimization algorithm is:
[0010] in, Inertial weight; For individual learning coefficients, For social learning coefficient, Represents a locally optimal vector; This represents the globally optimal vector.
[0011] Furthermore, the optimization of variation based on the industrial equipment response specifically includes: Scalar rewards are awarded based on the industrial equipment's response. Based on the scalar reward, the mutation operator probability distribution of the test cases is optimized using the particle swarm optimization algorithm.
[0012] A second aspect of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the industrial protocol fuzz testing method based on Transformer and particle swarm optimization.
[0013] A third aspect of the present invention provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the optimized configuration method for the shared energy storage power station.
[0014] A fourth aspect of this invention provides an industrial protocol fuzz testing system based on Transformer and Particle Swarm Optimization, comprising: The data acquisition module acquires industrial protocol data and preprocesses the industrial protocol data. The test case generation module inputs preprocessed industrial protocol data into a trained Transformer model with a fusion attention mechanism and outputs a set of test cases. The mutation module mutates the test case set to generate a new test case set. The feedback optimization module inputs the generated new test case set into the industrial equipment for testing, monitors and analyzes the industrial equipment response, and optimizes the mutation based on the industrial equipment response.
[0015] Compared with the prior art, the present invention has the following beneficial effects: This invention discloses a fuzz testing method for industrial protocols based on Transformer and Particle Swarm Optimization. By integrating a Transformer model with a dual attention mechanism, it can deeply understand the syntactic structure and semantic specifications of industrial protocols, generating high-quality initial test cases that combine compliance and anomaly potential. This provides excellent seeds for subsequent mutations, effectively overcoming the shortcomings of traditional random mutations, such as high blindness and numerous invalid test cases. Employing an adaptive mutation strategy based on Particle Swarm Optimization, it can dynamically learn and adjust the selection probability of mutation operators based on test feedback, concentrating test resources on efficient mutation operations. This allows for more intelligent and faster exploration of the protocol's anomaly handling boundaries and deep state space, significantly improving the ability to discover unknown and critical vulnerabilities. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a diagram of the Transformer architecture based on the fusion attention mechanism; Figure 2 A flowchart of an industrial protocol fuzzy testing method based on Transformer and particle swarm optimization; Figure 3 This is a comparison chart of test case acceptance rates; Figure 4 This is a comparison chart showing the diversity of test cases. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0019] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0020] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0021] The present invention will now be described in further detail with reference to the accompanying drawings: See Figure 1 This invention discloses an industrial protocol fuzz testing method (i.e., SPTFuzz method) based on Transformer and Particle Swarm Optimization, comprising the following steps: S1. Raw data acquisition and preprocessing for industrial control protocols.
[0022] S101. In an industrial control network environment, use software tools (such as Wireshark) to collect communication data packets of the target industrial protocol (such as Modbus protocol) in real time to obtain the raw protocol data.
[0023] S102. Format the acquired raw data, including parsing, splitting, and protocol semantic annotation of data packets, and add specific start characters (such as "" to the beginning and end of each protocol data sequence). <s>) and terminator (such as " <eos>This step, known as "data input consistency and standardization," ensures the correct identification and training of data for subsequent deep learning models, providing a standardized data input foundation for model processing.
[0024] S2. Transformer model training and test case generation based on fusion attention mechanism S201. Using the protocol byte sequence obtained in step S1, construct an autoregressive decoder-type Transformer (hereinafter referred to as "fusion Transformer") that integrates relative position attention and spectral hybrid attention. The input is a sequence processed by the embedding layer. After passing through the parallel "positional relationship branch" and "spectral hybrid branch", the output is fused in an additive weighted manner. Then, after layer normalization and feedforward network, the conditional probability distribution for the next byte is obtained.
[0025] To avoid ambiguity, the following unified conventions are now adopted for the symbols and dimensions involved: Indicates the length of the current segment; For the number of attention heads; Hidden dimensions for the model; single-head dimension For the first Layers, sections For any attention head, the extended hidden state of the previous layer is denoted as . Sequence number The embedding vector of each token is .symbol Indicates transpose. This indicates element-wise multiplication. FFT and IFFT refer to the Fast Fourier Transform and Inverse Fourier Transform along the sequence dimension, respectively.
[0026] Specifically, relative position attention (positional relationship branch) is as follows: Regarding the first Layers, sections Each attention head dimension In this case, define an unnormalized relative position scoring matrix. , its first The elements are given by the following formula:
[0027] in, These are linear transformation matrices for query, key, and relative position, respectively; To relative offset Corresponding learnable position embedding; This is a trainable global bias vector used to supplement the content and position terms. Divide this expression row by row. Then input softmax to obtain the weight distribution, and then combine it with the value matrix. Multiply them to obtain the position-aware relational context.
[0028] Spectral Hybrid Attention (Spectral Hybrid Branch) extends the hidden state of the previous layer. Right multiplication by projection matrix Then, an FFT is performed along the sequence dimension, content-based complex gating is applied in the frequency domain, and then an IFFT is performed to return to the time domain and output the projection. Alignment dimension. Its calculation expression is:
[0029] in, Let be a complex gated vector, with its real part... With the imaginary part Summarized from the mean of the query vector (The mean value of the query along the sequence of the current layer) is input to the small perceptron to generate an adaptive filter that "amplifies / suppresses" each frequency band. Multiply by frequency point for each channel; Used to align the spectral branch output with the residual path.
[0030] The additive weighted fusion of the positional relationship branch and the spectral mixing branch is as follows: To introduce a frequency domain bias while preserving the probabilistic semantics of attention, an additive fusion strategy is adopted:
[0031] in, They represent the first Layers, sections The query matrix, key matrix, and value matrix (per attention head). These are learnable scaling factors used to adjust the relative contribution of the spectral branch to the fusion result: when Smaller, output is more biased towards The modeling of relative positional relationships; when When the output is large, the output is more emphasized. The frequency domain patterns provided are mixed with the global patterns.
[0032] S202. The fusion Transformer model is used to perform autoregressive training on the protocol byte sequence; wherein: the Adam optimizer is used to update the trainable parameters, the learning rate is scheduled in cosine annealing and a short warm-up phase is set; the batch size and sequence / segment length are set according to hardware resources, the segment length in the training phase is preferably 16-64, more preferably 32, the drop length in the evaluation / generation phase is 1, and the memory window mem_len can be 64-512; Dropout is applied to the residual and attention branches to suppress overfitting, and the gradient is dynamically clipped according to the norm (e.g., a threshold of 0.25-1.0) to prevent gradient explosion; memory management is performed to ensure efficiency, including intra-batch sharding, segment-level memory discarding and periodic cleaning, and mixed precision and multi-card parallelism are enabled when necessary; during training, the model is switched to evaluation mode at preset step intervals, and protocol test samples are generated under positional constraints and statistical priors for immediate diagnosis and continuous optimization; training logs are recorded and checkpoints are saved at intervals, and the training ends when the maximum number of steps is reached or the convergence condition is met.
[0033] S203. After training is complete, the target protocol's data frames are automatically generated based on the trained protocol sequence generation model. This step includes at least: S203.1, Start and Decoding Mechanism: Based on Start Mark As input, an autoregressive decoding method is used to progressively predict the score vector of the next byte (i.e., the byte value of 0–255 and the end marker). (from the candidate set), until an end marker is generated or the preset maximum length is reached.
[0034] S203.2, Conditional Probability Modeling and Output Usage: The generative model is a decoder-type Transformer with fused attention. The output layer generates log scores (loqits) for the sum of all candidate bytes at each decoding step, and obtains the conditional probability distribution for the next label through "fusion and scaling-linear-Softmax". In a preferred embodiment, the position constraint mask is first added to the score along with (optional) statistical priors, and then the score is calculated based on temperature. After scaling, the Softmax probability is calculated and used to drive subsequent sampling and decoding.
[0035] S203.3, Position Constraint Mask: Apply position-related protocol constraints to the candidate set for each decoding step, and set the scores of candidates that do not meet the constraints to infinitesimal to eliminate them probabilistically. Position constraints include, but are not limited to: the protocol identifier field being fixed at 0, the length field meeting a lower limit (e.g., the lower byte of length ≥ 6), the function code being limited to the legal set specified by the protocol, and the value range of fields such as start / transaction ID and unit ID being limited.
[0036] S203.4, Temperature Scaling and Dynamic Top- Sampling: The constrained scores are based on temperature parameters. Scaling and Softmax normalization are performed; then dynamic Top-Scaling is executed. Sampling to balance diversity and compliance: Decoding initially adopted a larger sampling method. To expand the exploration space and decode the later stages Shrinking to promote convergence and facilitate the generation of a valid termination (e.g., in the first few steps) =100, subsequent steps =10). When Top- is not enabled. At that time, sampling is performed from the complete constrained distribution.
[0037] S203.5, Termination Conditions and Result Formation: When sampling reaches... Alternatively, the generation process may terminate once the maximum length is reached, filtering out intermediate markers and retaining only the sequence of numerical bytes as candidate test cases.
[0038] S203.6, Legality Verification and Filtering (Optional): Perform protocol consistency checks on candidate test cases, including at least: a) Length check: The number of bytes in the sequence meets the minimum frame length requirement; b) Structure verification: The protocol identifier field is 0, and the length field matches the payload length; c) Function code verification: The function code must be within the valid set; only those that meet the above conditions can be used as the final output protocol test cases, and if necessary, they can be exported in decimal or hexadecimal format for actual testing.
[0039] S3. Adaptive data mutation based on particle swarm optimization.
[0040] S301, mutate the test cases generated in S2: from the seed queue Schedule a seed and submit it to the data mutation module. The scheduling strategy is as follows: when Polling from queue position mod Select; when Weighted by proximity from Sampling is used, with recently added seeds receiving greater weight. Specifically: enter: Seed queue (Formed from compliance test cases generated by S2). Set deterministic warm-up duration. . Mutation operator set (Such as function code replacement, data segment length expansion, check corruption, boundary value injection, field rearrangement, semantic preservation fine-tuning, etc.). Initial mutation operator selection probability distribution Particle swarm and PSO parameters Experimental budget Maximum time / round limit .
[0041] Output: The seed for the current scheduling .
[0042] S302, Adaptive Operator Selection and Feedback Evaluation (Single Trial).
[0043] S302.1, Mutation Operator Sampling and Mutation Execution For the particle swarm mutation probability vector The mutation operator index is obtained by performing class sampling. and the corresponding mutation operator Apply to seeds Obtaining variant samples , and then Send to the target under test for execution.
[0044] S302.2, feedback to scalar rewards.
[0045] Map execution feedback to scalar rewards ,in, Indicates whether new coverage has been obtained. Indicates whether to trigger a crash. These are the weighting coefficients.
[0046] S302.3, Local / Global Best Record Update.
[0047] Update the local optimum for the selected operator: And update the global optimum based on the local records of each group: .
[0048] S302.4, Queue Maintenance.
[0049] If the result results in a new overwrite or a crash, then... Add to queue , used for subsequent iterations.
[0050] This step outputs: the variant samples from a single trial. and corresponding rewards , and update and .
[0051] S303, Group Efficiency Assessment.
[0052] S303.1, Exploration phase.
[0053] Assign to each particle swarm Each trial was conducted, and the number of trials that resulted in new coverage or crashes was recorded. ,by Estimate group efficiency. S303.2, Optimal Group Exploitation.
[0054] Select the most efficient group Add to it A global update will be performed after the first test.
[0055] S304, PSO update and normalization of probability distribution.
[0056] S304.1, Speed Update: For each particle swarm Calculation speed:
[0057] in For inertial weights, These are the individual / social learning coefficients, respectively. and These represent the local optimal vector and the global optimal vector, respectively.
[0058] S304.2, Probability Update and Normalization.
[0059] according to
[0060] The operator selection distribution for the next round is obtained. Normalization guarantees... Each component is non-negative and sums to 1, thus ensuring the feasibility of subsequent category sampling. S305, in Repeat the above process within the loop; when the time or number of rounds limit is met, output: Updated operator selection distribution set ; The cumulative set of variant test cases; Statistical information (coverage increment, crash count, swarm efficiency, etc.). S4. Test case sending and response processing.
[0061] S401: Send the protocol test cases modified by S3 to the target industrial control equipment (such as programmable logic controllers (PLCs), remote terminal units (RTUs), etc.) through automated testing tools.
[0062] S402. During the test, monitor the response behavior of the system under test in real time, including information such as device operating status, abnormal output, system crashes, and performance degradation. Record test feedback in detail through log collection, device status monitoring, and other means.
[0063] S403. Analyze and detect anomalies in the collected response data. If a device malfunction or crash is detected, the relevant anomaly information is automatically recorded; if the system performs normally, continue to capture subsequent responses and loop through the aforementioned mutation and testing process. Based on the anomaly feedback results, return to step S3 to further adjust the mutation probability, achieving adaptive continuous optimization.
[0064] The industrial protocol fuzzy testing method based on Transformer and particle swarm optimization proposed in this invention has a solid theoretical basis for feasibility and demonstrates significant technical advantages in actual industrial control protocol (such as Modbus protocol) testing scenarios.
[0065] First, the Transformer model with an integrated attention mechanism effectively addresses the challenges of modeling long-distance dependencies and multi-dimensional relationships in industrial protocol data sequences. Industrial protocols typically possess strict syntactic structures and complex data dependencies. Traditional recurrent neural networks (such as RNNs and LSTMs) are susceptible to gradient vanishing or information forgetting issues when modeling long-sequence protocols, making it difficult to capture long-distance content and structural dependencies within the protocol. The integrated attention mechanism employed in this invention combines relative positional attention (capturing relative dependencies between positions in the sequence) with spectral attention (obtaining global features of the protocol sequence through frequency domain transformation). This not only enhances the model's ability to grasp the temporal characteristics of the protocol but also strengthens its comprehensive modeling capabilities for complex protocol semantics and anomalous distributions. This deep integration strategy provides theoretical support for the diversity of test cases and protocol compliance, and significantly expands the coverage space of generated samples.
[0066] Secondly, PSO, as a globally optimal search algorithm, can adaptively adjust the probability distribution of mutation operators through information exchange between particles, achieving dynamic mutation optimization for target systems of different industrial protocols. In the implementation of this invention, the PSO mechanism collects test feedback in real time and adjusts the mutation strategy according to anomaly triggering conditions, effectively avoiding local optima traps in the mutation space and continuously expanding the exploration depth of protocol anomalies. This method combines global search capabilities with individual optimal memory, theoretically superior to purely random or static mutation methods, and helps improve vulnerability discovery rates and test case diversity. Taking the Modbus protocol as a specific example, this invention collects real industrial protocol traffic and simulation data, preprocesses it, and inputs it into a fusion attention Transformer model to complete protocol feature learning and automatic test case generation. Combined with the PSO-driven mutation module, the generated protocol test cases are intelligently mutated, and the test cases are sent to multiple industrial control devices (such as PLCs, RTUs, etc.) through an automated testing platform for real-time monitoring.
[0067] See Figure 3 To verify the effectiveness of the method of this invention, we designed several experiments and compared them with several existing mainstream fuzzing methods. The experiments mainly used the Modbus protocol as the target protocol to evaluate the performance of different methods in terms of test case recognition rate (TCRR) and diversity of generated data (DGD). In the experiments, we used the SPTFuzz method of this invention, TXL-Fuzz, BLSTM-DCNNFuzz, and GANFuzz as comparison schemes, and analyzed the performance of each method through different training steps (10 steps, 20 steps, 30 steps, etc.).
[0068] Experimental results show that the SPTFuzz method of this invention significantly outperforms other existing methods in the two key metrics of TCRR and DGD. Firstly, as the number of training steps increases, SPTFuzz continuously improves its test case recognition rate. At 80 training steps, SPTFuzz's recognition rate approaches 95%, far exceeding TXL-Fuzz and other methods, whose improvement rate is relatively slow and still fails to reach the performance of SPTFuzz at 100 training steps. This indicates that the method of this invention has a significant advantage in generating high-quality protocol test cases.
[0069] Secondly, in the comparison with DGD, SPTFuzz demonstrated stronger capabilities, especially during the training phase from 50 to 70 steps, maintaining a data diversity score above 12. Furthermore, the data diversity gradually increased with the number of training steps. In contrast, other comparative methods such as TXL-Fuzz and BLSTM-DCNNFuzz showed relatively low diversity fluctuations during training. Figure 4 As shown, the diversity of GANFuzz decreased significantly in the later stages of training, failing to maintain a high level of diversity in the generated data, indicating that the method has certain limitations in terms of coverage and breadth of test data.
[0070] These experimental results fully demonstrate the superiority of the method of this invention, especially in automatically generating test cases that conform to protocol specifications, enhancing the diversity of test data, and improving anomaly detection capabilities, where SPTFuzz exhibits significant technical advantages. Furthermore, by introducing the PSO mutation strategy, this invention not only improves the quality of generated test cases but also effectively avoids the local optima problem in traditional methods, enabling broader exploration of protocol anomalies. Therefore, this invention provides an efficient, intelligent, and highly adaptable solution for the security testing of industrial control protocols.
[0071] The embodiments of this invention utilize the method described herein to perform fuzz testing on different types of industrial protocols, verifying its broad adaptability and effectiveness. Taking the Modbus protocol as an example, this embodiment uses the Pymodbus tool to capture raw data packets and preprocesses the data to generate input data that meets the protocol requirements. The Transformer model employed, by fusing relative position attention and spectral attention mechanisms, can perform deep modeling of the temporal and frequency domain features in the Modbus protocol, thereby effectively improving the protocol compliance and diversity of the generated test cases. During training, the hyperparameter configuration includes a batch size of 32, a learning rate of 0.001, a sequence length of 32, a training step count of 100, and an embedding dimension of 256. Based on the trained model, 30,000 test cases were generated. Each test case underwent reasonable variations in function codes, data fields, and register addresses, conforming to the basic requirements of the Modbus protocol.
[0072] Furthermore, this invention introduces an adaptive mutation strategy based on the PSO algorithm. During the mutation process, the probability distribution of the mutation operators is adaptively adjusted, allowing the execution probability of each mutation operation to be dynamically adjusted based on anomalies reported during testing. For example, the probability of function code replacement is 0.2, the probability of data field expansion is 0.3, and the probability of checksum corruption is 0.15. When the mutated test cases are sent to the target device, testing is performed using PLC and RTU devices, and the device's response is captured in real time. During testing, this invention effectively detects various device crashes and protocol anomalies, verifying its reliability and efficiency in practical industrial protocol security testing.
[0073] As demonstrated by the above embodiments, the method of the present invention exhibits strong adaptability and superiority in fuzz testing of various industrial protocols. It can effectively generate high-quality test cases and improve the accuracy and coverage of vulnerability detection through an adaptive mutation strategy. These embodiments verify the feasibility of the present invention in practical applications and provide efficient support for complex protocol environments.
[0074] One embodiment of the present invention provides an industrial protocol fuzz testing system based on Transformer and Particle Swarm Optimization, comprising: The data acquisition module acquires industrial protocol data and preprocesses the industrial protocol data. The test case generation module inputs preprocessed industrial protocol data into a trained Transformer model with a fusion attention mechanism and outputs a set of test cases. The mutation module mutates the test case set to generate a new test case set. The feedback optimization module inputs the generated new test case set into the industrial equipment for testing, monitors and analyzes the industrial equipment response, and optimizes the mutation based on the industrial equipment response.
[0075] One embodiment of the present invention provides a terminal device, which includes a processor and a memory. The memory stores a computer program, which includes program instructions. The processor executes the program instructions stored in the computer storage medium. The processor may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing and control core of the terminal, and is suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions to achieve a corresponding method flow or corresponding function. The processor described in this embodiment of the present invention can be used for the operation of an industrial protocol fuzzy testing method based on Transformer and particle swarm optimization.
[0076] One embodiment of the present invention also provides a storage medium, specifically a computer-readable storage medium (Memory), which is a memory device in a terminal device for storing programs and data. It is understood that the computer-readable storage medium here can include both the built-in storage medium in the terminal device and extended storage media supported by the terminal device; it can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. The computer-readable storage medium provides storage space that stores the terminal's operating system. Furthermore, the storage space also stores one or more instructions suitable for loading and execution by a processor, which can be one or more computer programs (including program code). It should be noted that more specific examples (a non-exhaustive list) of the computer-readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof.
[0077] Computer-readable storage media also include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable storage medium can also be any readable medium other than a readable storage medium that can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the readable storage medium can be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.
[0078] Program code for performing the operations of this invention can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java and C++, and conventional procedural programming languages such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0079] One or more instructions stored in a computer-readable storage medium can be loaded and executed by a processor to implement the corresponding steps of the industrial protocol fuzz testing method based on Transformer and particle swarm optimization in the above embodiments.
[0080] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.< / eos> < / s>
Claims
1. A method for fuzzy testing of industrial protocols based on Transformer and Particle Swarm Optimization, characterized in that, Includes the following steps: Acquire industrial protocol data; The industrial protocol data is preprocessed; The pre-processed industrial protocol data is input into the trained Transformer model with fusion attention mechanism, and the test case set is output. The particle swarm optimization algorithm is used to mutate the test case set to generate a new test case set. The generated new test case set is input into the industrial equipment for testing, the industrial equipment response is monitored and analyzed, and the mutation is optimized based on the industrial equipment response.
2. The industrial protocol fuzzy testing method based on Transformer and particle swarm optimization according to claim 1, characterized in that, The preprocessing of the industrial protocol data specifically involves: The industrial protocol data is parsed and split to generate several data sequences; Add start and end symbols before and after each data sequence.
3. The industrial protocol fuzzy testing method based on Transformer and particle swarm optimization according to claim 2, characterized in that, The Transformer model of the fusion attention mechanism includes a relative position attention module, a spectrum hybrid attention module, and a weighted fusion module; the data sequence is processed by the relative position attention module and the spectrum hybrid attention module, respectively; The outputs of the relative position attention module and the spectrum hybrid attention module are weighted and fused before being output.
4. The industrial protocol fuzzy testing method based on Transformer and particle swarm optimization according to claim 1, characterized in that, The process of using particle swarm optimization to mutate the test case set and generate a new test case set is as follows: Based on the current mutation operator probability distribution, a mutation operator is selected to mutate the test cases, generating mutated samples; The mutated samples are input into industrial equipment for testing, and corresponding scalar rewards are obtained. Based on the scalar reward, the mutation operator probability distribution of the test cases is optimized using the particle swarm optimization algorithm; Iterate through the above process to obtain a new set of test cases.
5. The industrial protocol fuzzy testing method based on Transformer and particle swarm optimization according to claim 4, characterized in that, The mutation operators include function code replacement, data segment length expansion, check destruction, boundary value injection, field rearrangement, and semantic preservation fine-tuning.
6. The industrial protocol fuzzy testing method based on Transformer and particle swarm optimization according to claim 4, characterized in that, The velocity update formula for the particle swarm optimization algorithm is: in, Inertial weights; For individual learning coefficients, The social learning coefficient, Represents a locally optimal vector; This represents the globally optimal vector.
7. The industrial protocol fuzzy testing method based on Transformer and particle swarm optimization according to claim 1, characterized in that, The optimization of variations based on the response of industrial equipment specifically includes: Scalar rewards are awarded based on the industrial equipment's response. Based on the scalar reward, the mutation operator probability distribution of the test cases is optimized using the particle swarm optimization algorithm.
8. An electronic device, characterized in that, The method includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the industrial protocol fuzz testing method based on Transformer and particle swarm optimization as described in any one of claims 1-7.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the shared energy storage power station optimization configuration method according to any one of claims 1-7.
10. An industrial protocol fuzzy testing system based on Transformer and Particle Swarm Optimization, characterized in that, include: The data acquisition module acquires industrial protocol data; The industrial protocol data is preprocessed; The test case generation module inputs preprocessed industrial protocol data into a trained Transformer model with a fusion attention mechanism and outputs a set of test cases. The mutation module mutates the test case set to generate a new test case set. The feedback optimization module inputs the generated new test case set into the industrial equipment for testing, monitors and analyzes the industrial equipment response, and optimizes the mutation based on the industrial equipment response.