A few-shot malicious traffic data enhancement method based on spectral attention generative adversarial network

By using spectral attention generative adversarial networks, the problems of unstable generated samples and insufficient class consistency in few-sample malicious traffic scenarios are solved, generating high-quality synthetic samples and improving the model's detection performance and robustness for a few attack categories.

CN122268670APending Publication Date: 2026-06-23GUILIN UNIV OF ELECTRONIC TECH +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
GUILIN UNIV OF ELECTRONIC TECH
Filing Date
2026-05-13
Publication Date
2026-06-23

AI Technical Summary

Technical Problem

Existing methods for augmenting malicious traffic with few samples suffer from discriminator overfitting, gradient oscillation, and pattern collapse in long-tailed distribution scenarios. They also lack semantic consistency of generated samples, class consistency, and quality control, resulting in insufficient recall and reduced recognition capabilities for a few attack categories.

Method used

A spectral attention generative adversarial network is adopted, which generates high-quality synthetic samples by means of spectral normalization constraints, class-conditional cross attention, hybrid adversarial loss, hierarchical truncation sampling and teacher filtering mechanism, ensuring class consistency and training stability.

Benefits of technology

It improves the detection performance of a few attack categories, enhances the accuracy and robustness of downstream detection models, reduces interference from low-quality or cross-class mixed samples, and improves the model's minority class recognition ability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122268670A_ABST
    Figure CN122268670A_ABST
Patent Text Reader

Abstract

The present application relates to the field of network security and small sample data enhancement, and proposes a small sample malicious traffic data enhancement method based on spectral attention generative adversarial network. The method divides PCAP traffic according to the session and converts it into a fixed size grayscale image, and constructs an adversarial network composed of a conditional generator and a class conditional cross attention discriminator with spectral normalization constraint; in the training stage, the training stability and synthesis quality are improved by using the strategies such as Wasserstein adversarial target, gradient penalty, coverage and diversity regularization; in the sampling stage, the number of small class filling is determined according to the category size, the hierarchical truncation intensity is set, and the synthesized samples are screened according to the confidence by using the teacher classifier, and the real samples are fused to form an enhanced training set. The present application can supplement the rare attack class training signal without additional labeling cost, and improve the accuracy of small sample malicious traffic detection and the recognition ability of small class.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of network security, malicious traffic detection, few-shot learning, and generative data augmentation, specifically a few-shot malicious traffic data augmentation method based on spectral attention generative adversarial networks. Background Technology

[0002] As cyberattack toolchains continue to evolve, real-world network traffic is increasingly exhibiting a long-tail distribution. A relatively abundant number of samples exist for a few high-frequency attacks or normal traffic, while some high-risk, novel, or low-frequency attacks only appear briefly in localized scenarios, resulting in a limited number of labeled samples available for training. If such imbalanced data is directly used to train detection models, the models are prone to bias towards the majority class, leading to insufficient recall for a few attack categories, blurred category boundaries, and a decreased ability to identify unknown variants.

[0003] Existing methods for augmenting malicious traffic with few samples typically employ random oversampling, simple perturbations, interpolation sampling, or conventional generative adversarial networks (GANs) to supplement minority class samples. While these methods can alleviate class imbalance in terms of sample quantity, they still have the following shortcomings in malicious traffic grayscale image scenarios: First, adversarial training under few-sample conditions is prone to discriminator overfitting, gradient oscillations, and pattern collapse; second, when the generator relies solely on realistic feedback, it is difficult to guarantee the semantic consistency between the synthesized samples and the target attack class; third, there is a lack of sampling control and quality filtering mechanisms for long-tail class size differences, and low-quality or cross-class mixed samples may interfere with the decision boundaries of downstream detectors. Therefore, there is an urgent need for a data augmentation method for few-sample malicious traffic scenarios that can explicitly enhance class consistency, training stability, and sample availability while maintaining the realism of synthesized samples, so that the augmentation results can truly improve the detection performance of minority attack classes. Summary of the Invention

[0004] The purpose of this invention is to provide a few-shot malicious traffic data augmentation method based on spectral attention generative adversarial networks, aiming to solve the problems of unstable training, insufficient class semantic constraints, uncontrollable sampling quality, and low-quality synthetic samples easily interfering with downstream detection in few-shot long-tail traffic scenarios of existing generative augmentation methods. This invention generates high-quality synthetic samples that are more helpful for the detection of a few attack categories through the synergistic effect of spectral normalization constraints, class-conditional cross-attention, hybrid adversarial loss, hierarchical truncation sampling, and teacher filtering mechanism.

[0005] This invention is achieved through the following technical solution:

[0006] Step 1: Perform session segmentation and grayscale image construction on the original PCAP network traffic. Aggregate data packets based on the five-tuple consisting of source IP, destination IP, source port, destination port, and protocol, and determine session boundaries based on connection idle time; extract data packet bytes within the same session in chronological order and concatenate them into a session byte stream; truncate or pad the session byte stream to a fixed length and rearrange it into single-channel grayscale image samples to form a real training dataset with category labels.

[0007] Step 2: Construct a spectral attention generative adversarial network. This network includes a condition generator and an attention discriminator. The condition generator receives noise variables and class conditions to generate synthetic grayscale image samples of the target attack class; the attention discriminator introduces spectral normalization constraints in key convolutional layers and linear layers, and outputs a conditional discrimination score that fuses realism and class consistency through a class-conditional cross-attention module.

[0008] Step 3: Stabilize the adversarial training of the spectral attention generative adversarial network. The discriminator adopts the Wasserstein adversarial objective and gradient penalty constraint to stabilize the metric between the real distribution and the generated distribution; the generator introduces coverage regularization and diversity regularization in addition to the adversarial loss, and controls the weight of the regularization term at different training stages through Sigmoid course scheduling; differentiable data augmentation and exponential moving average of generator parameters are introduced during training to alleviate overfitting with few samples and sampling fluctuations.

[0009] Step 4: Determine the minority class set, target imputation quantity, and tiered cutoff thresholds based on the sample size of each class in the real training set. For classes with scarce samples, set a stricter latent variable cutoff range to prioritize ensuring synthesis quality; for classes with relatively abundant samples, set a more lenient cutoff range to preserve latent space exploration capabilities and intra-class diversity.

[0010] Step 5: Fix the generator exponential moving average parameters after training, generate a candidate synthetic sample pool according to the category conditions and the graded cutoff threshold; use the teacher classifier, which is pre-trained only with real samples and kept frozen during the filtering stage, to score the target category confidence of the candidate synthetic samples, and retain high confidence samples by category.

[0011] Step 6: Inject the selected synthetic samples into the real training dataset according to the target number of paddings to form an enhanced training set. This enhanced training set is then used to train the downstream malicious traffic detection model. The validation and test sets remain as real samples and are not involved in the sample generation process to ensure the objectivity of the evaluation results.

[0012] The beneficial effects of this invention are as follows: First, by limiting the hierarchical gain and local gradient morphology of the discriminator through spectral normalization and gradient penalty, the scale drift and gradient oscillation in few-shot adversarial training are reduced. Second, by enabling class-conditional cross-attention to actively retrieve spatial regions related to the target class through class embedding, the class consistency of generated samples is enhanced. Third, by guiding the generator to cover more real class regions and suppressing pattern collapse through coverage regularization and diversity regularization, the balance between quality and diversity is adjusted according to the differences in class sample size through hierarchical truncation sampling. Fifth, by performing quality gating on candidate synthetic samples through a teacher filter, the probability of low-quality or cross-class mixed samples entering the training set is reduced. Sixth, without increasing the cost of manual annotation, the sufficiency of training signals for minority attack classes is improved, enhancing the accuracy, robustness, and minority class recognition ability of downstream detection models. Attached Figure Description

[0013] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the following description of the embodiments are briefly described. Obviously, the drawings described below are only some embodiments of the present invention, and those skilled in the art can obtain other drawings based on these drawings without creative effort.

[0014] Figure 1 This is a schematic diagram of the process of the few-sample malicious traffic data augmentation method based on spectral attention generative adversarial network provided in the embodiments of the present invention;

[0015] Figure 2 This is a schematic diagram of the overall structure of the spectral attention generative adversarial network provided in an embodiment of the present invention;

[0016] Figure 3 This is a schematic diagram of the spectral normalization and class-conditional cross-attention discrimination structure provided in an embodiment of the present invention;

[0017] Figure 4 This is a schematic diagram of the hierarchical truncation sampling and teacher filtering enhancement process provided in an embodiment of the present invention;

[0018] Figure 5 This is a comparison chart of the accuracy, F1 score, and attack class F1 score of different methods on the UNSW-NB15 dataset in the embodiments of the present invention.

[0019] Figure 6 This is a graph showing the experimental results of spectral attention generative adversarial network ablation on the UNSW-NB15 dataset, according to an embodiment of the present invention. Detailed Implementation

[0020] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. The described embodiments are only a part of the embodiments of the present invention, not all of them, and do not constitute a limitation on the scope of protection of the present invention. Other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are all within the scope of protection of the present invention.

[0021] like Figure 1 , Figure 2 , Figure 3 , Figure 4 As shown in this embodiment, the method for augmenting few-shot malicious traffic data based on spectral attention generative adversarial networks includes the following steps:

[0022] Step 1: To construct training samples for few-sample malicious traffic with class consistency constraints, this invention first performs session segmentation and grayscale image construction on the original PCAP network traffic, converting heterogeneous network traffic data into a standardized input format suitable for convolutional generative adversarial learning, laying the data foundation for subsequent spectral attention generative adversarial network modeling and teacher filtering. This module covers steps such as quintuple aggregation, session boundary determination, byte stream extraction, fixed-length truncation, and grayscale image rearrangement.

[0023] In this step, the raw network traffic is input using a PCAP file. The system constructs a five-tuple based on source IP, destination IP, source port, destination port, and protocol, aggregating packets belonging to the same connection into the same candidate session. For connections with long durations or prolonged idle periods, session boundaries are determined based on whether the connection idle time exceeds a preset threshold, and the same connection is split into multiple session fragments. This process avoids mixing behavioral differences from different time periods within a long connection into the same sample, which helps maintain semantic consistency within the sample. For each session fragment, the system extracts the packet payload bytes in chronological order and concatenates them into a session byte stream. Assume a fixed input length of... The grayscale image size is Then the following condition is met:

[0024]

[0025] When the session byte stream length is greater than L, the first L bytes are truncated; when the session byte stream length is less than L, it is padded with 0 values ​​at the end. Then, the one-dimensional byte vector of length L is rearranged into a two-dimensional matrix in row-major order, and the byte values ​​from 0 to 255 are directly mapped to grayscale intensities to obtain single-channel grayscale image samples. This method preserves the local spatial structure of the session byte sequence, enabling the convolutional network to learn local patterns of attack categories from the grayscale image texture. Let the real training dataset be:

[0026]

[0027] in, Indicates the first A sample grayscale image of a conversation. This indicates its corresponding category label. This represents the total number of real training samples. This dataset serves as the basis for training the spectral attention generative adversarial network, the teacher classifier, and subsequent boosting injections.

[0028] Step 2: To construct a generative adversarial model with stable training capabilities for scenarios with few samples, this invention constructs a spectral attention generative adversarial network in this step. It employs a network architecture that coordinates a conditional generator and an attention discriminator. Under strict control of the discriminator's capacity, it completes sample generation and discrimination learning under class conditions. Simultaneously, spectral normalization and class-conditional cross-attention enhance the discriminator's focus on the target class spatial region, laying a structural foundation for subsequent stable adversarial training and targeted augmentation. This module encompasses steps such as conditional generator construction, attention discriminator construction, spectral normalization constraints, and class-conditional cross-attention.

[0029] In this step, such as Figure 2 As shown, the spectral attention generative adversarial network consists of a condition generator. and attention discriminator Composition: The generator is used to generate synthetic samples of the target attack category under given category conditions, and the discriminator is used to determine whether the input sample is close to the true distribution and further determine whether the sample is consistent with the given category conditions.

[0030] On the generator side, potential noise variables Sampling from a standard normal distribution, category labels Mapped to class vectors through the embedding layer The noise variable is then concatenated with the class vector to obtain the conditional input:

[0031]

[0032] The generator takes the conditional input. The data is mapped to a low-resolution spatial feature tensor, and then restored to a fixed-size single-channel grayscale image sample through progressive upsampling and convolution transformation.

[0033]

[0034] On the discriminator side, the input sample First, a spatial feature map is obtained through convolutional feature extraction. The discriminator output consists of a ground truth branch and a class attention branch. The ground truth branch characterizes whether the sample closely approximates the real traffic distribution, while the class attention branch characterizes whether the sample is consistent with the target class conditions. Through this dual-branch structure, the discriminator not only constrains the authenticity of the samples but also the semantic consistency of the classes, thus enabling the generator to obtain clearer class condition feedback during backpropagation.

[0035] like Figure 3 As shown, to suppress discriminator scale drift during few-shot adversarial training, this embodiment introduces spectral normalization constraints in the key convolutional and linear layers of the discriminator. For linear layers, the weights are themselves two-dimensional matrices; for convolutional layers, the weights are typically four-dimensional tensors, which need to be expanded into two-dimensional matrices along the output channel dimension.

[0036]

[0037] in, Number of output channels Input the number of channels. and These represent the height and width of the convolution kernel, respectively. For the weight matrix... The system maintains left and right singular vectors. and The maximum singular value is approximated by exponential iteration:

[0038]

[0039] The weights are then normalized:

[0040]

[0041] in, This is a numerically stable term. By limiting the maximum gain of each mapping layer, the discriminator's scoring scale is less prone to drastic drift during training, and the gradient signal received by the generator is more stable. This mechanism is particularly suitable for few-shot adversarial training because a small number of real samples can easily cause the discriminator to overfit quickly, while spectral normalization can constrain the discriminator's capacity and scale variation at the structural level.

[0042] Conventional conditional generative adversarial networks (GANs) typically use class conditions as input to the generator or as additional input to the discriminator. However, this approach may not be sufficient to ensure that the discriminator truly focuses on spatial regions related to the target class. To address this issue, this embodiment incorporates a class-conditional cross-attention module in the discriminator, enabling the class embedding to actively retrieve locations in the spatial feature map related to the target class in the form of a query vector.

[0043] Suppose that the discriminator backbone network outputs a spatial feature map before global pooling. , of which The spatial location features are Category tags The corresponding category embedding is Using category embeddings as query vectors, similarity is calculated for spatial locations and normalized using softmax to obtain attention weights:

[0044]

[0045] in, Temperature is a parameter used to control the sharpness of the attention distribution. Spatial features are weighted and aggregated according to attention weights to obtain category-aware contextual features:

[0046]

[0047] Let the global pooling feature be The weight of the authenticity branch is The category attention branch weight is Then the discriminator output is:

[0048]

[0049] The aforementioned structure allows the discriminator to simultaneously impose both realism and class consistency constraints. The realism branch requires the samples to closely approximate the real traffic distribution, while the class attention branch requires the samples to be consistent across spatial regions related to the target class. For few-shot attack classes, this design reduces the risk of generated samples being realistic but class-biased, making synthetic samples more suitable for training downstream detection models.

[0050] Step 3: To alleviate common problems in few-shot adversarial training such as discriminator overfitting, gradient oscillation, and pattern collapse, this invention performs stable adversarial training on the spectral attention generative adversarial network. The discriminator employs a Wasserstein adversarial objective and gradient penalty constraints to stabilize the metric between the real and generated distributions. In addition to the adversarial loss, the generator introduces coverage regularization and diversity regularization, and controls the weights of the regularization terms at different training stages through Sigmoid course scheduling. Simultaneously, differentiable data augmentation and exponential moving average of generator parameters are introduced to alleviate few-shot overfitting and sampling fluctuations, improving the realism and diversity of the synthesized samples.

[0051] In this step, this embodiment employs a hybrid adversarial loss model centered on the Wasserstein distance. Let the real sample be... The potential noise is The generated sample is The discriminator conditional output is The basic adversarial terms on the discriminator side are:

[0052]

[0053] To constrain the local gradient shape of the discriminator, interpolated samples are constructed between real samples and generated samples with the same label:

[0054]

[0055] The gradient penalty term is defined as:

[0056]

[0057] Therefore, the overall loss of the discriminator is:

[0058]

[0059] in, The gradient penalty weights are used. This loss can alleviate the problem of the discriminator being overly sharp under conditions of few samples, allowing the generator to obtain a more continuous optimization signal.

[0060] The generator aims to improve the conditional scoring of synthesized samples on the discriminator, while introducing coverage regularization and diversity regularization. Let the discriminator's intermediate feature extraction function be... The characteristics of the real sample are The characteristics of the synthesized samples are Coverage regularization measures whether a real sample region is covered by generated samples; when a real sample feature is too far from the nearest synthetic sample feature, the generator needs to expand into that region. Diversity regularization suppresses excessive clustering of synthetic samples in the feature space, reducing pattern collapse.

[0061] The overall loss of the generator is defined as:

[0062]

[0063] in, and These are weights that change as training progresses. In the early stages of training, the adversarial relationships are not yet stable, and overly strong regularization terms may interfere with the alignment of the base distribution. Therefore, during the warm-up phase, the regularization weights are reset to zero. After the warm-up, Sigmoid course scheduling is used to gradually increase the regularization weights.

[0064]

[0065] in, For the current training round, As a dispatch center, Controlling the transition slope. Through course scheduling, the model can first learn the basic true distribution and then gradually enhance coverage and diversity, thereby improving the usability of synthetic samples in downstream detection tasks.

[0066] In scenarios with few samples, the discriminator tends to memorize the local textures of a limited number of real samples, making the generator gradient highly sensitive to input perturbations. To alleviate this problem, this embodiment applies a consistent, insignificant perturbation to both real and generated samples during the training phase before inputting them into the discriminator. Let the differentiable enhancement operator be... The discriminator training input can then be represented as:

[0067]

[0068] Differentiable enhancements are applied only during the training phase; no additional perturbation is applied during the sampling phase, thus avoiding unnecessary transformations on the final generated samples. This mechanism can expand the equivalent input neighborhood of the discriminator and reduce its overfitting to the local textures of a small number of real samples.

[0069] Simultaneously, this embodiment maintains the exponential moving average of the generator parameters. Let the... The generator parameters after the next update are: The moving average parameter is The update method is as follows:

[0070]

[0071] in, This is the smoothing coefficient. It is used consistently when constructing augmented datasets through sampling. The corresponding generator generates samples. Compared to directly using the current iteration parameters, exponential moving average can reduce the impact of short-term training oscillations on sampling quality, making the generated samples more stable in terms of texture structure and category semantics.

[0072] Step 4: To control the trade-off between quality and diversity of synthesized samples based on the differences in sample size among different categories in the real training set, this invention determines the minority class set, the target imputation quantity, and the hierarchical truncation threshold based on the sample size of each category in the real training set. For categories with scarce samples, a stricter latent variable truncation range is set to prioritize ensuring the consistency between the synthesized quality and the target category; for categories with relatively abundant samples, a more lenient truncation range is set to preserve the latent space exploration capability and intra-class diversity. This module covers steps such as category statistics, size classification, hierarchical truncation of latent variables, and calculation of targeted imputation quotas.

[0073] In this step, such as Figure 4As shown, after the spectral attention generative adversarial network is trained, it enters a generative enhancement process consisting of category statistics, size classification, EMA conditional sampling, teacher confidence scoring, top-k retention by class, and construction of enhanced training sets. This process separates the generation stage from the training stage: the training stage focuses on learning a stable category conditional distribution, while the generation stage performs quality control and targeted completion on candidate synthetic samples based on the category sample size and teacher filtering results, thereby preventing low-quality samples from directly entering the downstream detection training set.

[0074] Once the spectral attention generative adversarial network (GAN) is trained, the process enters the generative augmentation phase. During training, truncated sampling is not introduced to avoid sampling bias affecting adversarial convergence; during the sampling phase, a truncation threshold is set based on the sample size for each category. Let the categories be... The cutoff threshold is For latent variables Perform component-level truncation:

[0075]

[0076] Then, conditional sampling is performed using an exponential moving average generator:

[0077]

[0078] A smaller cutoff threshold concentrates latent variables in high-probability regions, resulting in more stable and clearer generated samples, but at the cost of decreased diversity. Conversely, a larger cutoff threshold allows for a wider exploration of the latent space and greater diversity, but may reduce the quality of generated samples and class consistency. This embodiment divides samples into different levels based on their size: those with relatively abundant samples and larger class configurations... To preserve intra-class diversity; smaller configurations for classes with scarce samples. Prioritize ensuring the quality of generated samples and consistency with the target category.

[0079] To avoid forcibly flattening all categories, this embodiment employs a targeted completion strategy. Let the set of non-empty categories be... , No. The number of real samples is The maximum number of samples in the largest category is:

[0080]

[0081] Definition of the first The class imbalance ratio is:

[0082]

[0083] When the imbalance ratio reaches the preset threshold In this case, the category is included in the minority category set:

[0084]

[0085] If no category meets the threshold, then a predetermined proportion of the tail categories are selected as the minority class set in ascending order of the number of samples in each category. For each minority class... According to the median of the number of samples in the non-minority class and minimum target lower bound Determine the target size and calculate the number of samples to be synthesized:

[0086]

[0087] This strategy does not change the real validation and test sets, nor does it unnecessarily amplify the head categories. Instead, it prioritizes allocating enhancement quotas to attack categories that have scarce samples and have a significant impact on detection performance.

[0088] Step 5: To avoid low-quality or cross-class mixed samples interfering with the discrimination boundary of the downstream detection model, this invention introduces a teacher filtering mechanism. The generator's exponential moving average parameters are fixed after training, and a candidate synthetic sample pool is generated according to class conditions and hierarchical cutoff thresholds. A teacher classifier, pre-trained only with real samples and frozen during the filtering phase, is used to score the target class confidence of the candidate synthetic samples, and high-confidence samples are retained by class. This module covers steps such as candidate sample generation, teacher confidence scoring, and Top-k retention by class.

[0089] In this step, to prevent low-quality or inconsistent samples from entering the augmented training set, this embodiment sets up a teacher filter. The teacher filter is a classifier pre-trained only on real training samples, and its parameters remain frozen during the filtering stage, unaffected by the generated samples. For candidate synthetic samples... The teacher classifier outputs that it belongs to the target category. Confidence score:

[0090]

[0091] in, This represents the output probability of the teacher classifier. For each target category, the system sorts the candidate synthetic samples in descending order according to their confidence scores and retains the top-scoring samples. There are 10 samples. The retainer set can be represented as:

[0092]

[0093] The final synthesized sample set is as follows:

[0094]

[0095] The augmented training set is as follows:

[0096]

[0097] Step 6: To target the enhancement resources to a few attack categories while ensuring the objectivity of the evaluation results, this invention injects the selected synthetic samples into the real training dataset according to the target number of samples to form an enhanced training set, and uses the enhanced training set for training the downstream malicious traffic detection model; the validation set and test set remain unchanged as real samples and do not participate in the injection of generated samples, thereby completing the data enhancement closed loop for malicious traffic detection with few samples.

[0098] In this step, the augmented training set is used to train the downstream malicious traffic detection model. Since the teacher filter is trained only on real samples and the parameters are frozen during the filtering phase, it provides a relatively stable class consistency screening criterion for generated samples. After low-confidence samples are excluded, the synthetic samples entering the minority class from the augmented training set are more likely to have clear target class features, thereby reducing interference with the boundary learning of the downstream classifier.

[0099] In specific experimental implementations, publicly available malicious traffic datasets such as UNSW-NB15, CICIDS2017, and Bot-IoT can be used for validation. The downstream classifier can be fixed as a single-channel input ResNet-18, and the effects of different augmentation methods can be compared under the same training configuration. In the experimental procedure, all methods use the same data preprocessing, the same downstream classifier, and the same evaluation protocol. The validation set and test set remain unchanged with real samples to ensure that the comparison between augmentation methods mainly reflects the differences in the quality of synthetic samples.

[0100] like Figure 5 As shown, on the UNSW-NB15 dataset, this embodiment achieves improvements in accuracy, F1 score, and attack class F1 score compared to the baseline of real samples without synthetic data. This result demonstrates that the samples generated by the spectral attention generative adversarial network not only supplement the minority class training signal but also do not significantly disrupt the overall class boundaries. Compared to conventional GAN ​​enhancement methods, the advantages of this embodiment mainly stem from the constraints on class consistency imposed by class-conditional cross-attention and teacher filtering mechanisms, as well as the control over the generation quality of the minority class by hierarchical truncation sampling.

[0101] like Figure 6As shown, removing the teacher filter, hierarchical truncation strategy, coverage and diversity regularization, differentiable data augmentation, or exponential moving average of generator parameters all resulted in varying degrees of decline in downstream detection metrics. Among these, the F1 score for attack classes was more sensitive to the removal of each module, indicating that the main gains of this invention are concentrated in the ability to identify attack and minority classes. The teacher filter primarily filters out low-quality samples from the user side, the hierarchical truncation strategy primarily controls the quality of latent variables from the sampling side, diversity regularization and differentiable data augmentation primarily improve the coverage and discriminative stability of the generated distribution from the training side, and the exponential moving average improves sampling consistency from the perspective of parameter temporal smoothing. The synergistic effect of these modules enables this invention to maintain a relatively stable enhancement effect in datasets with varying degrees of long-tail length.

[0102] In summary, this invention forms a data augmentation closed loop for detecting malicious traffic with few samples by employing session-level grayscale image representation, spectral attention discriminative structure, stable adversarial training, hierarchical truncation sampling, teacher filtering, and targeted completion. This method retains the modeling capabilities of generative adversarial networks for complex data distributions while introducing class consistency, quality screening, and long-tail completion mechanisms specifically for malicious traffic with few samples. This effectively improves the learnability of a few attack categories and the robustness of downstream detection models.

[0103] The above description is merely a preferred embodiment of the present invention. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in this invention, based on the technical solutions and concepts of the present invention, should be included within the protection scope of this invention.

Claims

1. A method for augmenting few-shot malicious traffic data based on spectral attention generative adversarial networks, characterized in that, Includes the following steps: Step 1: Obtain raw network traffic data, segment the raw network traffic data into sessions according to connection relationships, and convert the session byte sequence into fixed-size single-channel grayscale image samples to form a real training dataset with category labels; Step 2: Construct a spectral attention generative adversarial network. The network includes a condition generator and an attention discriminator. The condition generator generates synthetic malicious traffic grayscale samples of the corresponding categories based on noise variables and category conditions. The attention discriminator introduces spectral normalization constraints in the convolutional and linear layers and outputs a discrimination score that fuses authenticity and category consistency through a class-conditional cross-attention module. Step 3: Perform adversarial training on the spectral attention generative adversarial network. On the discriminator side, Wasserstein adversarial objectives and gradient penalty constraints are adopted. On the generator side, coverage regularization, diversity regularization and course scheduling mechanisms are adopted. Differentiable data augmentation and exponential moving average of generator parameters are introduced during the training process. Step 4: Determine the minority class set and the target imputation quantity for each minority class based on the number of samples of each class in the real training dataset, and configure a graded truncation sampling threshold for each class according to the sample size of each class. Step 5: Fix the generator exponential moving average parameters after training, perform graded truncation conditional sampling according to category to generate candidate synthetic sample pools, and use the teacher classifier pre-trained on real samples to score the target category confidence of the candidate synthetic samples and filter them by category. Step 6: Inject the selected synthetic samples into the real training dataset according to the target number of paddings to obtain the enhanced training set, and use the enhanced training set for training the downstream malicious traffic detection model.

2. The method for augmenting few-shot malicious traffic data based on spectral attention generative adversarial networks according to claim 1, characterized in that, Step 1, the construction of the session grayscale image, includes: aggregating data packets based on a five-tuple consisting of source IP, destination IP, source port, destination port, and protocol, and determining session boundaries based on connection idle time; extracting data packet bytes within the same session in chronological order and concatenating them into a session byte stream; truncating or padding the session byte stream with zeros to a preset length L, where L = H × W; rearranging the byte vector of length L into a two-dimensional matrix of length H × W in row-major order, and mapping byte values ​​from 0 to 255 to grayscale intensity to obtain a single-channel grayscale image sample.

3. The method for augmenting few-shot malicious traffic data based on spectral attention generative adversarial networks according to claim 1, characterized in that, The spectral normalization constraint in step 2 includes: expanding the convolutional layer weight tensors in the discriminator into a two-dimensional weight matrix along the output channel dimension. The weights of the linear layers are directly expressed in matrix form; in each training iteration, the left and right singular vectors u and v are maintained, and the weights are estimated through power iteration. The spectral norm is calculated, and the weights are normalized according to the estimated spectral norm before participating in the forward propagation to limit the maximum gain of each layer of the discriminator mapping.

4. The method for augmenting few-shot malicious traffic data based on spectral attention generative adversarial networks according to claim 1, characterized in that, The class-conditional cross-attention module in step 2 includes: mapping the class label y to a class embedding vector e(y); using e(y) as the query vector; calculating similarity and performing softmax normalization on each spatial location in the spatial feature map F(x) output by the discriminator backbone network before global pooling; using the normalized attention weights to perform weighted aggregation of the spatial features to obtain class-aware context features; and fusing the class attention term corresponding to the class-aware context features with the ground truth term corresponding to the global pooling features to obtain the discriminator conditional output D(x,y).

5. The method for augmenting few-shot malicious traffic data based on spectral attention generative adversarial networks according to claim 1, characterized in that, The adversarial training in step 3 includes: the discriminator uses the expected difference in conditional scores between real samples and synthetic samples with the same label as the Wasserstein adversarial term, and constructs interpolated samples between real samples and synthetic samples to calculate gradient penalties; the generator aims to improve the conditional scores of synthetic samples on the discriminator, and simultaneously calculates coverage regularization and diversity regularization in the discriminator's intermediate feature space; the coverage regularization measures the insufficient coverage of the target class space based on the distance from the features of real samples to the features of the nearest synthetic sample, and the diversity regularization suppresses mode collapse based on the average pairwise distance between synthetic samples.

6. The method for augmenting few-shot malicious traffic data based on spectral attention generative adversarial networks according to claim 1, characterized in that, The training stabilization mechanism in step 3 includes: setting a warm-up phase in the early stages of training, where the weights of coverage regularization and diversity regularization are zero; gradually adjusting the regularization weights using Sigmoid curriculum scheduling after the warm-up phase; updating the generator sampling parameters using an exponential moving average after each generator parameter update; and applying a consistent, small-amplitude perturbation to the real and generated samples at the discriminator input to expand the discriminator's equivalent input neighborhood and reduce few-sample overfitting.

7. The method for augmenting few-shot malicious traffic data based on spectral attention generative adversarial networks according to claim 1, characterized in that, Determining the minority class set in step 4 includes: counting the number of samples in each class within the non-empty class set C+. Calculate the number of samples in the largest category. And based on the imbalance ratio Determine if the category is a minority class; when When the imbalance ratio is greater than or equal to a preset threshold, category c is included in the minority class set; when there is no category that meets the threshold, the tail category with a preset proportion is selected as the minority class set in ascending order of the number of category samples.

8. The method for augmenting few-shot malicious traffic data based on spectral attention generative adversarial networks according to claim 1, characterized in that, Step 5, hierarchical truncation sampling, includes: dividing the categories into multiple levels based on the sample size of each category, configuring a larger truncation threshold for categories with relatively abundant samples to preserve latent space diversity, and configuring a smaller truncation threshold for categories with scarce samples to improve generation quality; performing component-level truncation on the latent variable z, restricting it to... Within the range, input the generator corresponding to the generator exponential moving average parameter to obtain the target category synthetic sample.

9. The method for augmenting few-shot malicious traffic data based on spectral attention generative adversarial networks according to claim 1, characterized in that, The teacher filtering and targeted imputation in steps 5 and 6 include: inputting candidate synthetic samples into a teacher classifier that is trained only on real samples and remains frozen during the filtering phase, and obtaining the confidence scores of the candidate synthetic samples on the target category; sorting the candidate synthetic samples for each target category in descending order of the confidence scores, and retaining the top few synthetic samples that meet the target imputation number; performing imputation only on tail categories with a sample size lower than the target size, and keeping the validation set and test set as real samples and not participating in the generation injection.