Abnormal traffic detection network training method and abnormal traffic detection method

Synthetic abnormal samples are generated through the feature extraction module and the bidirectional flow module, and the triplet loss function is used to train the classifier, which solves the problems of difficult sample generation and low detection performance in abnormal traffic detection in the existing technology, and achieves efficient semi-supervised Anomaly detection.

CN118784343APending Publication Date: 2024-10-15XIDIAN UNIV
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411042772.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-10-15

AI Technical Summary

Technical Problem

Existing technologies have problems in abnormal traffic detection, such as difficulty in generating abnormal samples, information loss and reconstruction, and detection performance being affected by model complexity and noise, especially in the context of the explosive growth and diversity of Internet data.

Method used

The abnormal traffic detection network training method using feature extraction module, bidirectional flow module and classifier module is used to generate synthetic abnormal samples by feature extraction and normalization processing of normal traffic data packets, and the triplet loss function is used to classify the classifier The module performs iterative training to achieve anomaly detection through semi-supervised learning.

Benefits of technology

Without the need to label a large amount of abnormal traffic data, pseudo-abnormal samples are generated, which improves the efficiency and effect of abnormal data detection, solves the problems of difficult sample collection and low reconstruction efficiency, and enhances the ability to identify abnormal traffic patterns.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118784343A_ABST
    Figure CN118784343A_ABST
Patent Text Reader

Abstract

The invention provides an abnormal traffic detection network training method and an abnormal traffic detection method, and the method comprises the steps: carrying out the processing of an obtained training sample through a feature extraction module, obtaining a first hidden vector and a second hidden vector corresponding to the training sample, and transmitting the first hidden vector to a classifier module; respectively transmitting the second hidden vector to a bidirectional flow module and a classifier module; the second hidden vector is processed by a plurality of reversible and differentiable functions along a normalization direction through a bidirectional flow module to obtain a normalization result, noise is added to the normalization result, then the normalization result is processed by a plurality of reversible and differentiable functions along a generation direction to obtain a synthesis abnormal sample, and the synthesis abnormal sample is output to a classifier module; and performing iterative training on a classifier module according to the first hidden vector, the second hidden vector, the synthetic abnormal sample and a preset triple loss function, and generating a pseudo-abnormal sample by a network obtained by training without abnormal priori knowledge to realize abnormal detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data security detection, and in particular to a training method for an abnormal flow detection network and an abnormal flow detection method. Background Art

[0002] The rapid development of the Internet has brought about an explosive growth in network traffic, which has led to various types of abnormal traffic threatening network security. In order to manage network resources and maintain the security of network infrastructure, supervised methods are used to detect abnormal traffic. However, supervised anomaly detection has difficulties in collecting abnormal traffic data and obtaining labels. To solve these problems, semi-supervised methods are applied in the field of anomaly detection, and only normal traffic is trained to detect anomalies. Akcay et al. proposed a semi-supervised anomaly detection method GANomaly based on adversarial training: a new encoder-decoder-encoder architecture model was introduced to achieve anomaly detection through an adversarial training framework. During the training process, minimizing the distance between these images and the latent vector helps to learn the data distribution of normal samples, and the larger distance metric obtained from the learning data distribution represents the outliers of the distribution.

[0003] However, the network traffic generated by GANomaly requires a large amount of data, and existing technologies can only generate network traffic similar to the distribution of collected data, which makes it challenging to simulate abnormal traffic with different distributions. In particular, GANomaly still has problems in the following aspects. First, in terms of simulating abnormal samples, the types of abnormal samples are not exhaustive and difficult to obtain. The number, types, scale and complexity of data samples in today's Internet are exploding, and the cost of obtaining a large amount of data is high. Secondly, in terms of reconstructing input samples, there are some common problems when reconstructing input samples. During the reconstruction process, there may be information loss between the reconstructed samples and the original samples; if the reconstruction model is too complex or the training data is too little, the model may remember the noise and specific details in the training set instead of the real structure of the learning data. This will lead to poor generalization ability on new data. Finally, in terms of defining the anomaly score, GANomaly uses a reconstruction error-based method to detect anomalies. That is, the model learns to reconstruct the input data into output data, and then determines the anomaly score by comparing the difference between the input data and the output data. This method is limited by the complexity of the model, requires appropriate hyperparameter selection, is difficult to handle new abnormal patterns, and has strong assumptions about data distribution. When the abnormal data is significantly different from the normal data or there is noise, the detection performance will be affected. Summary of the invention

[0004] In order to solve the above problems existing in the prior art, the present invention provides a training method for an abnormal traffic detection network and an abnormal traffic detection method. Specifically, the method includes:

[0005] In a first aspect, the present invention provides a training method for an abnormal traffic detection network, which is applied to an abnormal traffic detection network, the network comprising:

[0006] Feature extraction module, bidirectional flow module and classifier module;

[0007] The method includes:

[0008] The acquired training samples are processed by the feature extraction module to obtain a first hidden vector and a second hidden vector corresponding to the training samples, and the first hidden vector is transmitted to the classifier module, and the second hidden vector is transmitted to the bidirectional flow module and the classifier module respectively, wherein the training samples are determined according to normal traffic data packets conforming to the normal distribution;

[0009] The second hidden vector is processed by a bidirectional flow module along a normalization direction by a plurality of reversible and differentiable functions to obtain a normalized result, and noise is added to the normalized result and processed along a generation direction by a plurality of reversible and differentiable functions to obtain a synthetic abnormal sample, and the synthetic abnormal sample is output to the classifier module;

[0010] The classifier module is iteratively trained according to the first hidden vector, the second hidden vector, the synthetic abnormal sample, and the preset triplet loss function.

[0011] In a second aspect, the present invention further provides an abnormal traffic detection method, comprising:

[0012] The acquired traffic data packet to be detected is input into an abnormal traffic detection network trained according to any method provided in the first aspect to obtain a detection result.

[0013] In a third aspect, the present invention further provides an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;

[0014] Memory, used to store computer programs;

[0015] The processor is used to implement any method provided in the first aspect or the second aspect when executing the program stored in the memory.

[0016] In a fourth aspect, the present invention provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, any method provided in the first aspect or the second aspect is implemented.

[0017] Beneficial effects of the present invention:

[0018] The training method of the abnormal flow detection network and the abnormal flow detection method provided by the present invention include processing the acquired training samples through a feature extraction module to obtain a first hidden vector and a second hidden vector corresponding to the training samples, transmitting the first hidden vector to a classifier module, and transmitting the second hidden vector to a bidirectional flow module and a classifier module respectively, wherein the training samples are determined according to normal flow data packets conforming to a normal distribution; processing the second hidden vector through a bidirectional flow module along a normalization direction through a plurality of reversible and differentiable functions to obtain a normalized result, adding noise to the normalized result and processing the result along a generation direction through a plurality of reversible and differentiable functions to obtain a synthetic abnormal sample, and outputting the synthetic abnormal sample to the classifier module; according to the first hidden vector, the second hidden vector and the synthetic abnormal sample, and a preset triplet loss The function iteratively trains the classifier module. The abnormal traffic detection network trained by this method can generate pseudo-abnormal samples without prior knowledge of abnormalities, thereby realizing the detection of abnormal data. In addition, compared with the anomaly detection method using fully supervised learning, this method achieves effective anomaly detection by utilizing normal data that is easy to collect without the need to mark abnormal traffic. This method uses semi-supervised learning and does not require a large amount of labeled normal traffic and abnormal traffic data, thereby solving the problem of difficulty in collecting abnormal samples. The model trained by this method designs a feature extractor and a bidirectional flow module for traffic data. The corresponding modules can convert data packets into standard normal distribution space, and change the properties of traffic data packets through vector operations to simulate abnormal traffic, thereby solving the problems of low efficiency and poor effect of input sample reconstruction.

[0019] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 A schematic diagram of the structure of an abnormal flow detection network provided by the present invention;

[0021] Figure 2 A flow chart of a training method for an abnormal traffic detection network provided by the present invention;

[0022] Figure 3 A schematic diagram of a GANomaly structure provided by the present invention. DETAILED DESCRIPTION

[0023] The present invention is further described in detail below with reference to specific embodiments, but the embodiments of the present invention are not limited thereto.

[0024] In order to solve the problems in the prior art, the present invention provides an abnormal flow detection network, see Figure 1 , the network includes:

[0025] Feature extraction module 11, bidirectional flow module 12 and classifier module 13.

[0026] Figure 1 In the figure, Feature Extractor represents the feature extraction module, Bidirectional Flow Module represents the bidirectional flow module, Classifier represents the classifier module, Anchor represents the anchor point, Positive represents the positive sample, Negative represents the negative sample, Anomaly represents the abnormality, and Normal represents the normality.

[0027] Accordingly, the present invention also provides a training method for an abnormal flow detection network, which is applied to an abnormal flow detection network, see Figure 2 , the method comprising:

[0028] S201. Process the acquired training samples through the feature extraction module to obtain the first hidden vector and the second hidden vector corresponding to the training samples, and transmit the first hidden vector to the classifier module, and transmit the second hidden vector to the bidirectional flow module and the classifier module respectively.

[0029] The training samples are normal traffic data packets that conform to the normal distribution.

[0030] Exemplarily, the training samples are one-dimensional traffic data packets.

[0031] In a possible implementation, the acquired training sample is processed by the feature extraction module to obtain a first hidden vector and a second hidden vector corresponding to the training sample, and the second hidden vector is transmitted to the bidirectional flow module and the classifier module respectively, and the first hidden vector is transmitted to the classifier module, including:

[0032] The feature extraction module is iteratively trained according to the preset training loss function and the acquired training samples, and the first hidden vector output from each round of training is transmitted to the classifier module, and the second hidden vector output from each round of training is transmitted to the bidirectional flow module and the classifier module respectively.

[0033] Optionally, the expression of the training loss function is:

[0034] L adv =E x~px ||f(x)-E x~px f(G(x))||2,

[0035] L con =E x~px ||xG(x)||1,

[0036] L enc =E x~px ||GE (x)-E(G(x))||2,

[0037] L=ω adv L adv +ω con L con +ω enc L enc ,

[0038] Among them, L adv represents the adversarial loss, f(x) represents encoding x through the encoder of the generator, G(x) represents the output of x reconstructed by the autoencoder, x represents the input training sample, px represents the distribution of x, and L con represents the context loss, L env represents the encoder loss of the generator, G E (x) represents the feature vector extracted after passing x through the encoder of the generator, L represents the total loss, ω adv Represents the weight coefficient of adversarial loss, ω con Represents the weight coefficient of context loss, ω env represents the weight coefficient of the encoder loss of the generator, and ||·||2 represents the Euclidean distance between the previous and next data.

[0039] Optionally, the feature extraction module uses the main structure of GANomaly to learn the deep representation of normal samples based on the reconstruction method to extract the features of the data packet. GANomaly is a method that can be trained only on normal data but can identify abnormal images. It proposes a general anomaly detection model composed of an adversarial training framework. An adversarial autoencoder is used in the encoder-decoder-encoder architecture to obtain the distribution of training data in images and implicit vectors. Figure 3 A schematic diagram of a GANomaly structure provided by the present invention is shown in FIG. Figure 3 As shown in the figure, GANormaly mainly consists of three parts, a generator, an autoencoder and a discriminator. In the first part, the generator consists of a generator encoder and a generator decoder. The generator learns the representation of the input data and reconstructs the input data through the generator encoder and the generator decoder. The output of the generator encoder is also called the bottleneck feature of the generator, and it is considered to represent the minimum dimension that contains the best representation of the input data. In the second part, the autoencoder compresses the output of the generator into a low dimension. The autoencoder and the generator encoder have the same structure, but different parameters, so the dimension of the output data of the two is the same. The third part is the discriminator composed of the generator encoder, whose goal is to determine whether the original input and the output of the generator are consistent.

[0040] Figure 3In the figure, Input / Output represents input / output, Conv represents convolution function, LeakyReLU represents activation function, BatchNorm represents batch normalization algorithm, ConvTranspose represents deconvolution function, ReLU represents activation function, Tanh represents activation function, Softmax represents activation function, and Real / Fake represents true / false.

[0041] Based on GANormaly, in a possible implementation, the feature extraction module includes:

[0042] The encoder G of the generator E , the decoder G of the generator D and autoencoder E.

[0043] Accordingly, the acquired training samples are processed by the feature extraction module to obtain the first hidden vector and the second hidden vector corresponding to the training samples, including the following steps A1-A3:

[0044] A1, through the encoder G of the generator E The training sample x is compressed into the first hidden vector z corresponding to the training sample, and the first hidden vector z is transmitted to the decoder G of the generator respectively. D and classifier module E.

[0045] Exemplarily, the training sample x is a one-dimensional traffic data packet.

[0046] A2. Through the decoder G of the generator D Reconstruct the first hidden vector z back to the data packet corresponding to the training sample x to obtain the reconstructed data And will reconstruct the data Output to the autoencoder E.

[0047] The generator in the GANormaly architecture consists of a generator encoder and a generator decoder. The generator is used to learn the representation of input data and reconstruct the input data through its generator encoder and generator decoder. The output of the encoder of the generator in the generator is considered to be the bottleneck feature of the generator and is considered to represent the minimum dimension that contains the best representation of the input data.

[0048] For example, in the encoder G of the generator E , the decoder G of the generator D In the generator, the encoder G of the generator E The input x is compressed into a hidden vector z, and the decoder G of the generator D Output Responsible for reconstructing the hidden vector z back to the input packet.

[0049] It is generally believed that if the model is reconstructed is very close to the input x, then the hidden vector z can effectively represent the characteristics of the network packet. Based on this, optionally, see Figure 1 The feature extraction module also includes: a discriminator D, which is used to identify the decoder G of the generator D Output reconstructed data The encoder G with the input generator E Are the training samples x consistent?

[0050] A3, through the autoencoder E, reconstruct The data is compressed into a second hidden vector And the second hidden vector Transmitted to the bidirectional flow module and the classifier module respectively.

[0051] The autoencoder E transforms the decoder G of the generator D The output reconstruction data Compressed into a low-dimensional second hidden vector The autoencoder E and the generator encoder G E have the same structure but different parameters, so z and The dimensions are the same. Previous methods minimized the hidden vector through the bottleneck feature z. GANomaly adds an encoding network to explicitly learn to minimize the feature distance.

[0052] S202. The second hidden vector is processed by a bidirectional flow module along a normalization direction through a plurality of reversible and differentiable functions to obtain a normalized result, and noise is added to the normalized result. The result is processed along a generation direction through a plurality of reversible and differentiable functions to obtain a synthetic abnormal sample, and the synthetic abnormal sample is output to the classifier module.

[0053] Optionally, noise is randomly sampled from a Gaussian distribution.

[0054] In other words, the bidirectional flow module uses the normalization flow method to normalize the data output by the feature extraction module into a standard normal distribution, then adds noise to the normalized representation, and then simulates abnormal samples through the generation direction of the bidirectional flow module. For details, see Figure 1 , the second hidden vector output by the feature extraction module The simulated abnormal feature vector is obtained by normalizing the flow through the bidirectional flow That is, synthetic anomaly samples similar to real anomaly traffic patterns are generated.

[0055] The bidirectional flow includes normalization and generation direction. The generation flow model corresponding to the generation direction uses a series of reversible and differentiable operations to transform simple and easy-to-handle distributions into complex distributions. It can generally be described by the following formula:

[0056] c~P θ (c)

[0057] z=g θ (c)

[0058] Where c is a random vector that follows a distribution P θ , usually P θ is a simple distribution, such as the standard normal distribution. z is an extracted vector that follows the unknown true data distribution P*(z). The function g θ It is a reversible and differentiable function that can use samples from a simple distribution to generate real samples from a complex distribution. This direction is usually called the generation direction; function f θ Yes θ The inverse function of , normalizes the actual samples from the complex distribution to the simple distribution space. This direction is usually called the normalization direction.

[0059] According to the change of variables, the probability density of vector z can be written as follows:

[0060] log p θ (z) = log p θ (c)+log|det(dc / dz)|,

[0061] Wherein, log|det(dc / dz)| represents the logarithm of the absolute value of the determinant of the Jacobian matrix (dc / dz), which can be easily calculated by matrix transformation (such as triangular matrix transformation).

[0062] In practice, it is difficult to construct a strong, reversible, differentiable, and easy-to-compute Jacobian function. Therefore, in normalized flows, a series of reversible and differentiable functions are usually combined together to achieve the desired transformation. This is why this approach is called a "flow". Therefore, the transformation between c and z can be written as:

[0063]

[0064] Specifically, the bidirectional flow module takes the features extracted by the feature extractor as input and trains the module through the normalization direction. After training, the bidirectional flow module can map the features of normal samples to the standard normal distribution space. For normal samples, the bidirectional flow module maps its features to the standard normal distribution space. However, for abnormal samples, the situation is different. In the feature extraction stage, the feature extraction module is only trained on normal samples. Therefore, the features extracted by the feature extraction module from abnormal samples are likely to deviate from the distribution of normal features. Since the bidirectional flow module is also trained on normal samples, abnormal features that deviate from the distribution of normal samples may fall outside the standard normal distribution of the standard normal distribution space. In order to simulate the distribution of abnormal samples, the present invention introduces noise into normal samples in the standard normal distribution space. Specifically, the present invention chooses to randomly sample from a Gaussian distribution to generate noise, and uses a reparameterization technique to represent the noise:

[0065] η=μ+σ⊙ε,

[0066] Where μ is the mean vector, σ is the standard deviation vector, and ε is the random noise sampled from the standard normal distribution. By adjusting μ and σ, noise samples can be generated from different Gaussian distributions.

[0067] Then, the simulated abnormal samples in the standard normal distribution space are transformed using the generation direction of the bidirectional flow module to obtain vectors in the latent space. The representation vectors of normal samples and abnormal samples in the latent space can be obtained through the above method.

[0068] In the field of computer vision, synthetic abnormal samples are obtained by performing image applications such as flipping and transformation on normal samples. However, when it comes to traffic packets, it is challenging to obtain abnormal samples that are very similar to the real network environment through image processing technology. This is because traffic packets lack spatial semantic information. Therefore, it is necessary to use a bidirectional flow module to map the feature vector to the standard normal distribution space to construct abnormal samples. In the standard normal distribution space, the properties of the vector can be manipulated to make it closer to the real abnormal samples in the latent space. This method can generate synthetic abnormal samples that are similar to the real abnormal traffic patterns.

[0069] S203, iteratively training the classifier module according to the first hidden vector, the second hidden vector, the synthetic abnormal sample, and a preset triplet loss function.

[0070] Optionally, the classifier module is a triplet loss model.

[0071] The feature extraction module and the bidirectional flow module in the abnormal traffic detection network generate three feature vectors of the same size based on the data of the input model, namely the first latent vector, the second latent vector and the synthetic abnormal sample. These three vectors can be used as the input of the triplet loss function to calculate the embedded anomaly score for anomaly detection.

[0072] Accordingly, in a possible implementation method, the classifier module is iteratively trained according to the first hidden vector, the second hidden vector and the synthetic abnormal sample, and the preset triplet loss function, including: taking the first hidden vector as an anchor point, the second hidden vector as a positive sample, and the synthetic abnormal sample as a negative sample, and iteratively training the classifier module based on the preset triplet loss function.

[0073] The present invention introduces the triplet loss function into deep learning to create an embedding that minimizes the distance between similar samples while maximizing the distance between samples of different categories. The triplet loss function depends on anchors, positive and negative samples. Positive samples belong to the same class as the anchor, while negative samples belong to different classes. During training, the goal is to minimize the distance between the anchor and the positive sample and maximize the distance between the anchor and the negative sample, which is achieved by minimizing the triplet loss function.

[0074] Optionally, the triplet loss function is expressed as:

[0075] L Triplet =max(d(a,p)+margin-d(a,n),0),

[0076] Among them, L Triplet represents the triplet loss, a represents the feature vector extracted from the input normal sample, p represents the feature vector extracted from the reconstructed sample, n represents the constructed abnormal sample vector, d(a,p) represents the distance measure between a and p, margin represents the preset margin, and d(a,n) represents the distance measure between a and n.

[0077] In other words, a is the anchor point corresponding to the triplet loss function, p is the positive sample, and n is the negative sample.

[0078] By minimizing the triplet loss function, the distance between a and p (i.e., d(a,p)) is forced to be zero, while the distance between a and n (i.e., d(a,n)) is forced to be greater than d(a,p)+margin.

[0079] The triplet loss model is trained by the above method so that the distance between a and p is minimized, and the distance between a and n is greater than the preset margin, and a trained classifier model is obtained. The trained classifier model maps the embedding of the real data to the corresponding embedding that is closer to the normal data and away from the embedding of the abnormal sample based on the triplet loss function. The first hidden vector, the second hidden vector and the synthetic abnormal sample are created as corresponding embeddings, and the triple embedding of the abnormal data and the normal data is obtained by inputting these embeddings into the classifier model, and the obtained embedding difference is used as the abnormal score, so as to perform anomaly detection. Among them, vector embedding is a method of representing data, which refers to converting data into numbers that capture its meaning and relationship, and representing different data as points in a multi-dimensional space, where similar data points are closer. In the context of vector embedding, vectors and embeddings have the same meaning, both are digital representations of data, and can be used interchangeably in the context, but vectors refer only to digital arrays, and embeddings emphasize the representation of data in a meaningful and structured way, while vectors refer to the numbers themselves. The "vector" mentioned in this application emphasizes the extracted feature vector data, and the "embedding" mentioned emphasizes the underlying logic and properties between the data, which specifically refers to the same object.

[0080] The present invention proposes to apply the triplet loss function to the anomaly detection metric to better quantify the difference between the detected features and the true features. This new metric optimizes the problems of other anomaly detection methods in the detection score in a principled way, thereby better identifying abnormal traffic. Based on the network model provided by the present invention, the middle layer embedding of the feature extractor is used as the input of the proposed triplet loss function, thereby reducing the embedding distance between the detected features and the actual features, and increasing the embedding distance between the true prediction and the unpaired prediction (i.e., the prediction from the unknown).

[0081] The anomaly score is an indicator that measures the difference between data and normal data. The method provided by the present invention has made improvements in defining the anomaly score. It adopts a powerful metric learning loss function, namely the triplet loss function. The difference between the embedding of normal data and the embedding of detection data is calculated by using the triplet loss function, and the relationship between the calculated difference and the preset threshold is further compared. The data exceeding the threshold is determined as abnormal data. This method can learn more discriminative features, avoid the collapse of inter-class distance, and can be applied to various scenarios, with high practical value.

[0082] It should be noted that the number of iterations of the feature extraction module and the number of iterations of the classifier module can be the same or different. When the number of iterations of the feature extraction module is less than the number of iterations of the classifier module, that is, after the training of the feature extraction module is completed, the training of the classifier module is not completed. Therefore, during the entire training process, some of the data transmitted to the bidirectional flow module and the classifier module are output by the untrained feature extraction module, and some are output by the trained feature extraction module.

[0083] Optionally, before the acquired training samples are processed by the feature extraction module, the method further includes the following steps B1-B3:

[0084] B1. Obtain the original data set. The target data set includes normal traffic data packets and abnormal traffic data packets. The normal traffic data packets include unencrypted traffic data packets and benign traffic data packets, and the abnormal traffic data packets include encrypted traffic data packets and malicious traffic data packets.

[0085] Exemplarily, the original data sets include the "UNB-CIC Tor and non-Tor" data set collected and captured by Arash et al. using Wireshark and Tcp-dump, the "ISCX VPN and non-VPN" data set collected and captured by Gerard et al. using Wireshark and Tcp-dump, and the "DataCon2020" data set derived from malicious and benign software collected from February to June 2020.

[0086] Among them, Arash et al. collected the captured "UNB-CIC Tor and non-Tor" dataset using Wireshark and Tcp-dump. This dataset includes regular traffic and Tor traffic captured from workstations and gateways, including 14 types of traffic, such as chat, streaming, email, etc.

[0087] Gerard et al. collected and captured the "ISCX VPN and non-VPN" data set using Wireshark and Tcp-dump. During the packet capture process, only the packets of the destination IP were captured. The data set includes 14 categories of regular and VPN traffic, including file transfers, etc.

[0088] The dataset is derived from the "DataCon2020" dataset of malicious and benign software collected from February to June 2020. The traffic is collected by Qi'anxin. The dataset defines malicious traffic as encrypted traffic generated by malware and benign traffic as encrypted traffic generated by benign software.

[0089] B2. Randomly select a preset number of normal traffic data packets that conform to the normal distribution from the original data set, clean the acquired data, remove invalid data to obtain the target data packet, the invalid data includes data packets related to the DNS protocol, data packets related to the TCP protocol, data packets related to the ARP protocol, data packets with empty content, and data packets with zero payload.

[0090] Cleaning the acquired data means removing data packets that may cause confusion to anomaly detection in the data set. The DNS protocol is used for mapping between domain names and IP addresses. Normal traffic and abnormal traffic obtain the corresponding IP addresses through the DNS protocol before performing activities. Such traffic packets are not directly associated with normal and abnormal features and cannot be used for anomaly detection. The TCP protocol has a series of connection-related stages, including connection establishment, connection termination, and connection confirmation. Such data packets usually do not contain any actual payload and are only associated with the connection. They are not directly associated with specific activities, so such data packets are deleted. The ARP protocol is responsible for mapping IP addresses and MAC addresses, but is usually not directly associated with the activities of upper-level users, so data packets related to the ARP protocol are deleted. For some data packets that are empty or have a payload of all zeros, filtering is performed, and the payload part of the valid data packet is directly extracted as data input.

[0091] B3. Perform traffic encoding on the target data packet based on byte encoding to obtain training samples.

[0092] Optionally, traffic encode the payload in the target packet using byte encoding.

[0093] It is understandable that the traffic data packet is still a traffic data packet after being encoded.

[0094] Exemplarily, byte encoding is used to process the payload of the data packet, and the single bytes in the payload are converted into corresponding decimal numbers to obtain a one-dimensional array of data packets. In order to ensure consistency and facilitate model understanding, the optional fields of the IP and TCP protocols are filled. In addition, there are two protocols in the transport layer, TCP and UDP, and the header of the UDP protocol is also filled to match the header length of TCP to ensure consistency between the two protocols. The length of all data packets is unified. Considering our statistical analysis of the length of the data packet and the preprocessing requirements of the comparative experiment, the length of the one-dimensional data packet array can be set to 1600 bytes. Then, the data packets are normalized to the range of 0 to 1. Finally, the processed data packets are stored in the CSV file format to form training samples.

[0095] The training method of the abnormal flow detection network provided by the present invention comprises processing the acquired training samples through a feature extraction module to obtain a first hidden vector and a second hidden vector corresponding to the training samples, transmitting the first hidden vector to a classifier module, transmitting the second hidden vector to a bidirectional flow module and a classifier module respectively, wherein the training samples are determined according to normal flow data packets conforming to a normal distribution; processing the second hidden vector through a bidirectional flow module along a normalization direction through a plurality of reversible and differentiable functions to obtain a normalized result, adding noise to the normalized result and processing the second hidden vector along a generation direction through a plurality of reversible and differentiable functions to obtain a synthetic abnormal sample, and outputting the synthetic abnormal sample to the classifier module; and classifying the first hidden vector, the second hidden vector and the synthetic abnormal sample, and a preset triplet loss function to classify the first hidden vector, the second hidden vector and the synthetic abnormal sample. The classifier module is iteratively trained. The abnormal traffic detection network trained by this method can generate pseudo-abnormal samples without prior knowledge of abnormalities, thereby realizing the detection of abnormal data. In addition, compared with the anomaly detection method using fully supervised learning, this method achieves effective anomaly detection by utilizing normal data that is easy to collect without the need to mark abnormal traffic. This method uses semi-supervised learning and does not require a large amount of labeled normal traffic and abnormal traffic data, thereby solving the problem of difficulty in collecting abnormal samples. The model trained by this method designs a feature extractor and a bidirectional flow module for traffic data. Through the corresponding modules, the data packet can be converted into a standard normal distribution space, and the properties of the traffic data packet can be changed through vector operations to simulate abnormal traffic, thereby solving the problem of low efficiency and poor effect of input sample reconstruction.

[0096] The present invention also provides an abnormal traffic detection method, which comprises: inputting the acquired traffic data packet to be detected into the abnormal traffic detection network trained according to the method provided in the above embodiment to obtain a detection result.

[0097] The present invention also provides a structure of an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus.

[0098] Memory, used to store computer programs;

[0099] The processor is used to implement the steps provided in the above method embodiment when executing the program stored in the memory.

[0100] The communication interface is used for communication between the above electronic device and other devices.

[0101] The method provided in the embodiment of the present invention can be applied to electronic devices. Specifically, the electronic device can be: a desktop computer, a portable computer, an intelligent mobile terminal, a server, etc. This is not limited here, and any electronic device that can implement the present invention belongs to the protection scope of the present invention.

[0102] The present invention also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps provided in the above method embodiment are implemented.

[0103] As for the electronic device / storage medium embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the specific content and beneficial effects and other related matters can be referred to the partial description of the method embodiment.

[0104] The terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.

[0105] The above contents are further detailed descriptions of the present invention in combination with specific preferred embodiments, and it cannot be determined that the specific implementation of the present invention is limited to these descriptions. For ordinary technicians in the technical field to which the present invention belongs, several simple deductions or substitutions can be made without departing from the concept of the present invention, which should be regarded as falling within the protection scope of the present invention.

Claims

1. A training method for an abnormal traffic detection network, characterized in that: Applied to an abnormal traffic detection network, the network comprising: Feature extraction module, bidirectional flow module and classifier module; The method comprises: Processing the acquired training samples through the feature extraction module to obtain a first hidden vector and a second hidden vector corresponding to the training samples, and transmitting the first hidden vector to the classifier module, and transmitting the second hidden vector to the bidirectional flow module and the classifier module respectively, wherein the training samples are determined according to normal traffic data packets that conform to a normal distribution; The second hidden vector is processed by the bidirectional flow module along the normalization direction by a plurality of reversible and differentiable functions to obtain a normalized result, and noise is added to the normalized result and processed along the generation direction by a plurality of reversible and differentiable functions to obtain a synthetic abnormal sample, and the synthetic abnormal sample is output to the classifier module; The classifier module is iteratively trained according to the first hidden vector, the second hidden vector, the synthetic abnormal sample, and a preset triplet loss function.

2. The method according to claim 1, characterized in that The feature extraction module comprises: A generator and an autoencoder, wherein the generator includes an encoder and a decoder; The step of processing the acquired training sample by the feature extraction module to obtain a first hidden vector and a second hidden vector corresponding to the training sample includes: Compressing the training sample into a first hidden vector corresponding to the training sample through the encoder of the generator, and transmitting the first hidden vector to the decoder of the generator and the classifier module respectively; Reconstructing the first hidden vector back into the data packet corresponding to the training sample through the decoder of the generator to obtain reconstructed data, and outputting the reconstructed data to the autoencoder; The reconstructed data is compressed into the second hidden vector by the autoencoder, and the second hidden vector is transmitted to the bidirectional flow module and the classifier module respectively.

3. The method according to claim 1, characterized in that The method of processing the acquired training sample by the feature extraction module to obtain a first hidden vector and a second hidden vector corresponding to the training sample, and transmitting the second hidden vector to the bidirectional flow module and the classifier module respectively, and transmitting the first hidden vector to the classifier module includes: The feature extraction module is iteratively trained according to a preset training loss function and the acquired training samples, and the first hidden vector output from each round of training is transmitted to the classifier module, and the second hidden vector output from each round of training is transmitted to the bidirectional flow module and the classifier module respectively.

4. The method according to claim 3, characterized in that The expression of the training loss function is: L adv =E x~px ||f(x)-E x~px f(G(x))||2, L con =E x~px ||x-G(x)||1, L enc =E x~px ||G E (x)-E(G(x))||2, L=ω adv L adv +oh con L con +oh enc L enc , Among them, L adv represents the adversarial loss, f(x) represents the output of x after passing through the encoder of the generator, G(x) represents the output of x after being reconstructed by the autoencoder, x represents the input training sample, px represents the distribution of x, and L con represents the context loss, L env represents the encoder loss of the generator, G E (x) represents the feature vector extracted after x passes through the encoder of the generator, L represents the total loss, ω adv Represents the weight coefficient of adversarial loss, ω con Represents the weight coefficient of context loss, ω env represents the weight coefficient of the encoder loss of the generator, and ||·||2 represents the Euclidean distance between the previous and next data.

5. The method according to any one of claims 1 to 4, characterized in that: The iterative training of the classifier module according to the first hidden vector, the second hidden vector, the synthetic abnormal sample, and a preset triplet loss function includes: The first hidden vector is used as an anchor point, the second hidden vector is used as a positive sample, and the synthetic abnormal sample is used as a negative sample. The classifier module is iteratively trained based on a preset triplet loss function.

6. The method according to claim 5, characterized in that The expression of the triple loss function is: L T riplet=max(d(a,p)+margin-d(a,n),0), Among them, L Triplet represents the triplet loss, a represents the feature vector extracted from the input normal sample, p represents the feature vector extracted from the reconstructed sample, n represents the constructed abnormal sample vector, d(a,p) represents the distance measure between a and p, margin represents the preset margin, and d(a,n) represents the distance measure between a and n.

7. The method according to any one of claims 1 to 4 or 6, characterized in that: Before the feature extraction module processes the acquired training samples, the method further includes: Acquire an original data set, wherein the original data set includes normal traffic data packets and abnormal traffic data packets, wherein the normal traffic data packets include unencrypted traffic data packets and benign traffic data packets, and the abnormal traffic data packets include encrypted traffic data packets and malicious traffic data packets; Randomly select a preset number of normal traffic data packets that conform to the normal distribution from the original data set, clean the acquired data, remove invalid data to obtain the target data packet, the invalid data includes data packets related to the DNS protocol, data packets related to the TCP protocol, data packets related to the ARP protocol, data packets with empty content, and data packets with zero payload; The target data packet is traffic encoded based on byte encoding to obtain the training sample.

8. A method for detecting abnormal traffic, characterized in that: include: The acquired traffic data packet to be detected is input into the abnormal traffic detection network trained according to any one of the methods described in claims 1-7 to obtain a detection result.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-8 when executing a program stored in a memory.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.

Citation Information

Cited By

  • Method and device for analyzing network traffic, electronic equipment and storage medium

    CN119788384A

  • Abnormal traffic detection method based on large model CLIP guidance

    CN120151050A