An unsupervised anomaly detection method for network traffic based on improved Transformer reconstruction model

Through the improved Transformer reconstruction model, using technologies such as frequency enhancement block and series decomposition block, the low accuracy and robustness problems of existing network anomaly detection methods are solved, and efficient unsupervised anomaly detection, recall rate and The accuracy rate is significantly improved.

CN117768207BActive Publication Date: 2024-10-18CHINESE PEOPLES LIBERATION ARMY UNIT 61660

Patent Information

Application Number
CN202311791348.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-24
Publication Date
2024-10-18
Estimated Expiration
2043-12-24

AI Technical Summary

Technical Problem

Existing network anomaly detection methods have low detection accuracy and poor robustness, and methods based on supervised machine learning require a large amount of annotated data and are time-consuming, making it difficult to effectively detect network attacks.

Method used

Using the improved Transformer reconstruction model, the input data is converted into time domain data by adding position coding information, and reconstructed encoding and decoding are performed in the transformed Transformer architecture, combining the frequency enhancement block, the series decomposition block and the feed-forward network , using the window right-shifting stepwise output mechanism and Fourier transform, and finally selecting the threshold through the POT algorithm to identify abnormal data.

Benefits of technology

On the KDD 99 network security data set, the recall rate, accuracy rate and F1 score have been significantly improved. The recall rate has reached more than 90%, the accuracy rate and F1 score have reached more than 85%, and the detection performance is higher and the robustness is stronger.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117768207B_ABST
    Figure CN117768207B_ABST
Patent Text Reader

Abstract

This invention relates to an unsupervised anomaly detection method for network traffic based on an improved Transformer reconstruction model, belonging to the fields of network security and artificial intelligence. This invention employs unsupervised learning to train the detection model. The improved Transformer reconstruction model is trained using normal network traffic samples to capture the spatiotemporal distribution characteristics of normal samples in the time and frequency domains. Finally, a reconstruction error threshold is used to distinguish between normal and abnormal network traffic. Compared to supervised anomaly detection models, this invention offers higher detection performance and stronger robustness.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the fields of network security and artificial intelligence, and specifically relates to an unsupervised anomaly detection method for network traffic based on an improved Transformer reconstruction model. Background Technology

[0002] Network anomalies refer to situations where, during normal operation, attackers employ various attack methods, causing a disruption in the provision of normal network services. Network anomaly detection aims to identify attack activities through real-time network traffic, with the goal of ensuring the stability and normal operation of network services.

[0003] Traditional network anomaly detection methods often employ expert systems, analyzing normal and abnormal network behavior to establish blacklists, whitelists, and network access rules. However, with the proliferation of network attack methods, the accuracy of these expert system-based anomaly detection methods is often low, and the models exhibit poor robustness. With the rapid development of machine learning, supervised machine learning-based temporal network anomaly detection methods have emerged. While these methods outperform traditional methods, training the model requires a large amount of labeled data, and the detection process is time-consuming. Therefore, there is an urgent need for a highly accurate, efficient, and robust network traffic anomaly detection method. Summary of the Invention

[0004] (a) Technical problems to be solved

[0005] The technical problem to be solved by this invention is how to provide an unsupervised anomaly detection method for network traffic based on an improved Transformer reconstruction model, so as to solve the problems of existing traditional anomaly detection methods and supervised machine learning-based detection methods.

[0006] (II) Technical Solution

[0007] To address the aforementioned technical problems, this invention proposes an unsupervised network traffic anomaly detection method based on an improved Transformer reconstruction model. This method includes:

[0008] The reconstruction model based on the Transformer architecture is adopted. First, the position encoding information is added to the input data and converted into time domain data. Then, the time domain data is input into the modified Transformer reconstruction model.

[0009] The modified Transformer architecture includes: a refactored encoder and a refactored decoder;

[0010] The reconstruction encoder has N layers, each of which includes: a Frequency Enhanced Block (FEB), a Series Decomposition Block (SDB), and a Feed Forward Network (FFD).

[0011] The reconstruction decoder adopts an M-layer structure, each layer including: a Frequency Enhanced Block (FEB), a Series Decomposition Block (SDB), and a Feed Forward (FFD) network, as well as a Frequency Enhanced Attention (FEA) module for connecting the encoder and decoder.

[0012] The input of the reconstruction model adopts a window-shifting stepwise output mechanism. Before obtaining the complete reconstruction output, the output result is converted into a time domain representation with added position encoding information and input into the decoder of the reconstruction model. Before inputting into the decoder, Fourier transform is used to convert the time domain representation of the reconstruction output into a frequency domain representation and input it into the reconstruction decoder together to complete the reconstruction of the next time window.

[0013] Finally, the final reconstruction output and reconstruction error of the reconstruction model are used as the objective function of the overall model. The threshold selected based on the POT algorithm and the reconstruction error are used to identify abnormal data, thereby optimizing the reconstruction model.

[0014] (III) Beneficial Effects

[0015] This invention proposes an unsupervised anomaly detection method for network traffic based on an improved Transformer reconstruction model. The key objective of this invention is to quickly and accurately detect network anomalies caused by network attacks. Therefore, an unsupervised network anomaly detection method based on an improved Transformer reconstruction model is designed. Compared to existing traditional anomaly detection methods and supervised machine learning-based detection methods, this method is expected to effectively improve recall, accuracy, and F1 score. Specifically, tested on the KDD 99 network security dataset, the recall rate of this invention is improved to over 90%, the accuracy to over 85%, and the F1 score to over 90%. Attached Figure Description

[0016] Figure 1 This is a diagram of the refactoring model architecture based on the improved Transformer of this invention;

[0017] Figure 2This is a flowchart illustrating the implementation of the reconstruction model based on the improved Transformer of this invention. Detailed Implementation

[0018] To make the objectives, contents, and advantages of the present invention clearer, the specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples.

[0019] When facing network anomalies caused by cyberattacks, existing anomaly detection methods mostly employ supervised learning to train the anomaly detection model. Due to the difficulty in dataset labeling, supervised anomaly detection methods generally have low detection performance and struggle to detect network anomalies caused by zero-day attacks. This invention proposes a network traffic anomaly detection model based on an improved Transformer reconstruction model, which uses unsupervised learning to train the detection model. The improved Transformer reconstruction model is trained using normal network traffic samples to capture the spatiotemporal distribution characteristics of normal samples in the time and frequency domains. Finally, a reconstruction error threshold is used to distinguish between normal and abnormal network traffic. Compared to supervised anomaly detection models, this invention offers higher detection performance and stronger robustness.

[0020] like Figure 1As shown, the unsupervised anomaly detection method for network traffic based on an improved Transformer reconstruction model proposed in this invention employs a Transformer-based reconstruction model. First, location encoding information is added to the input data, transforming it into temporal data. Then, the temporal data is input into the modified Transformer reconstruction model. The modified Transformer architecture consists of a reconstruction encoder and a reconstruction decoder. The reconstruction encoder has N layers, each including a Frequency Enhanced Block (FEB), a Series Decomposition Block (SDB), and a Feed Forward (FFD) network. The reconstruction decoder uses an M-layer structure, each including a Frequency Enhanced Block (FEB), a Series Decomposition Block (SDB), and a Feed Forward (FFD) network, as well as a Frequency Enhanced Attention (FEA) for connecting the encoder and decoder. Furthermore, the input to the reconstruction model uses a window-shifting, step-by-step output mechanism. Before obtaining the complete reconstructed output, the output result is converted into a time-domain representation with added positional encoding information and input into the decoder of the reconstruction model. Before being input into the decoder, a Fourier transform is used to convert the time-domain representation of the reconstructed output into a frequency-domain representation, which is then input into the reconstruction decoder to complete the reconstruction of the next time window. Finally, the final reconstruction output and reconstruction error of the reconstruction model are used as the objective function of the overall model. A threshold selected based on the POT algorithm and the reconstruction error are used to identify abnormal data, thereby optimizing the reconstruction model.

[0021] 1. Position Embedding

[0022] Because the model does not include recurrence and convolution, it cannot capture sequence information. However, sequence information is extremely important in time-series data, representing global structural information. Therefore, the Position Embedding method must be used to utilize the relative or absolute position information of the tokens in the sequence. The calculation method of Position Embedding is shown in Equation 1, where pos represents the position index of the token, i represents the dimension index of each token, and d... model Dimensions for each token.

[0023]

[0024]

[0025] Then, the original input data is added to the position code output by Formula 1 and used as the temporal input of the encoder and decoder in the reconstruction model.

[0026] 2. Reconstruct the encoder

[0027] The input data is represented in the time domain, and the reconstruction model first uses a reconstruction encoder for encoding. The reconstruction encoder has N layers, each consisting of a Frequency Enhanced Block (FEB), a Series Decomposition Block (SDB), and a Feed Forward (FFD) network. The encoder is computed as follows: Where l∈{1,…,N} is the l-th layer of the encoder. This is the output of the l-th layer. This is the input for the l-th layer. The specific process of Encoder(·) is shown in Formula 2. Wherein, This represents the periodic representation of the output of the i-th level decomposition block in the l-th layer of the encoder.

[0028]

[0029]

[0030]

[0031] The specific components of the reconstruction encoder are as follows:

[0032] (1) Frequency Enhanced Block (FEB)

[0033] The frequency enhancement block (FEB) uses the Discrete Fourier Transform (DFT), where F is defined as the Fourier transform. -1 This is the inverse Fourier transform.

[0034] The input of the Frequency Enhanced Block with Fourier Transform (FEB-f) is... Using w∈R D×D A linear projection is performed on x, calculated as q = x·w. The output q is the time-domain representation. Then, a Fourier transform is used to convert the time-domain representation q to the frequency domain, where the frequency-domain representation is... Then, Q is randomly sampled, and M rows are randomly selected from Q as a subset of Q. Where M< <N。 The calculation process is shown in Formula 3.

[0035]

[0036] exist Based on this, the calculation process of FEB-f is shown in Formula 4, where

[0037]

[0038] To learn complex time models, this invention employs a decomposition approach, separating the series into trend and periodic components. Let the input of the SDB be... Then R,T = SDB(χ). Where R is the period and T is the trend. The specific calculation process of SDB(·) is shown in Formula 5.

[0039] T = AvgPool(Padding(χ))

[0040] R = χ - T (5)

[0041] A Feed Forward (FFD) network is a fully connected network. Let X be the input to the FFD, and Equation 6 illustrates the calculation process. Here, Y is the output of the FFD, W and b represent the weights and biases of the fully connected layer, and f(·) is the ReLU activation function.

[0042] Y = f(WX + b) (6)

[0043] 3. Reconstructing the decoder

[0044] The reconstruction decoder employs an M-layer structure, with each layer including: a Frequency Enhanced Block (FEB), a Series Decomposition Block (SDB), a Feed Forward Network (FFD), and a Frequency Enhanced Attention (FEA) for connecting the encoder and decoder. The FEB, SDB, and FFD of the decoder are computed in the same way as those of the encoder. The initial reconstruction output is transformed into an initial temporal representation after adding positional encoding information. Then, Fourier transform was used to... Transformation to the initialized frequency domain representation The process is as follows and It serves as the initial input to the decoder and participates in the decoder reconstruction process. Afterwards, the decoder is computed as follows: Where l∈{1,…,M} is the l-th layer of the decoder. The specific process of Decoder(·) is shown in Equation 7. ω represents the periodic and trend representations of the output of the i-th series decomposition block in the l-th layer of the decoder. t,i ,i∈{1,2,3} represents the weights used in the calculation when extracting the i-th trend.

[0045]

[0046]

[0047]

[0048]

[0049]

[0050] Finally, the final reconstruction output of the model is Z, and Equation 8 shows the specific calculation process. Where ω s This represents the weight matrix used in calculating the reconstructed output.

[0051]

[0052] For the output Z of the reconstructed model, the reconstruction error is calculated and used as the objective function for optimizing the model. The calculation process is shown in Equation 9, where G is the input of the entire model.

[0053]

[0054] The Frequency Enhanced Attention (FEA) module in the Transformer uses Scaled Dot-Product Attention as its attention algorithm. Assuming the input query q has dimension D, the key k has dimension D, and the value v has dimension D, the dot product of the query and each key is calculated and divided by... Then the Softmax function is applied to calculate the weights, as shown in Formula 10.

[0055]

[0056] In FEA, the query q, key k, and value v are transformed from the time domain to the frequency domain using the Fourier transform. After the Fourier transform, q, k, and v are represented as Then, random sampling is performed on Q, K, and V, and M rows are randomly selected from Q, K, and V as subsets of Q, K, and V where M << N. The calculation process of is shown in Equation 11.

[0057]

[0058]

[0059]

[0060] In Based on this, the calculation process of FEA is shown in Equation 12, where σ is the activation function.

[0061]

[0062] 4. Automatic threshold selection

[0063] The present invention uses the POT method to automatically select the anomaly threshold. Equation 13 is a detailed explanation of the POT method. Here, th is the initial threshold for anomaly scoring. For the part below the threshold th, it is denoted as th - S, where s is a preset low quantile and follows the Generalized Pareto Distribution (GPD) with parameters γ and β. S is any one of the network traffic anomaly scoring sequences {S1, S2,..., S N'}, and N' is the total number of observed scoring times.

[0064]

[0065] After obtaining the estimated values and the final threshold th F can be calculated by Equation 14. Here, N' th is the number of S i S i ∈ {S1, S2,..., S N'}, S i < th. p is the preset expected probability of observing S < th.

[0066]

[0067] During the inference process, for the input sample X, the anomaly score Err(X) is calculated. Here, L RThe output value is used as the result of Err(X). The rule for determining inference anomalies is that when Err(X) > th... F When the test sample in the sequence is in the "abnormal" state, it can be predicted as "abnormal" otherwise.

[0068] like Figure 2 As shown, an unsupervised network anomaly detection method based on an improved Transformer reconstruction model is characterized by the following steps:

[0069] S1: Process and analyze network packet data to complete data normalization and embed location coding information;

[0070] S2: Use a reconstruction model to perform reconstruction analysis on the data, and calculate the corresponding reconstruction error based on the reconstruction results output by the model;

[0071] S3: Use the threshold selected based on the POT algorithm and the reconstruction error to identify abnormal data.

[0072] 1. The preprocessing of network packet data in step S1 specifically includes the following steps:

[0073] S1.1: Normalize the collected network packet features and normalize each feature to [0,1];

[0074] S1.2: Add positional encoding information to the normalized feature data to be input to the encoder and decoder, and convert it into frequency domain data;

[0075] S1.3: The frequency domain data to be input into the decoder is transformed into time domain data using Fourier transform.

[0076] 2. The model reconstruction in step S2 specifically includes the following:

[0077] S2.1: The reconstruction model first uses a reconstruction encoder for encoding. The reconstruction encoder has N layers, each layer including: a Frequency Enhanced Block (FEB), a Series Decomposition Block (SDB), and a Feed Forward (FFD) network;

[0078] S2.2: The reconstruction decoder adopts an M-layer structure, each layer including: Frequency Enhanced Block (FEB), Series Decomposition Block (SDB), and Feed Forward (FFD), as well as Frequency Enhanced Attention (FEA) for connecting the encoder and decoder;

[0079] S2.3 Calculates the reconstruction error for the reconstruction results based on the improved Transformer reconstruction model.

[0080] 3. The anomaly classification in step S3 specifically involves: using the threshold selected by the POT algorithm to classify the reconstruction error and achieve real-time anomaly detection.

[0081] The primary objective of this invention is to rapidly and accurately detect network anomalies caused by cyberattacks. Therefore, an unsupervised network anomaly detection method based on an improved Transformer reconstruction model is designed. Compared to existing traditional anomaly detection methods and supervised machine learning-based detection methods, this method is expected to significantly improve recall, accuracy, and F1 score. Specifically, tests on the KDD 99 network security dataset show that the recall rate of this invention is improved to over 90%, the accuracy to over 85%, and the F1 score to over 90%.

[0082] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A network traffic unsupervised anomaly detection method based on an improved Transformer reconstruction model, characterized in that: The method includes: Using a reconstruction model based on the Transformer architecture, we first add positional encoding information to the input data to convert it into time domain data, and then input the time domain data into the modified Transformer reconstruction model; The modified Transformer architecture includes: reconstruction encoder and reconstruction decoder; The reconstruction encoder has N layers, each of which includes: Frequency Enhanced Block (FEB), Series Decomposition Block (SDB) and Feed Forward (FFD); The reconstruction decoder adopts an M-layer structure, each layer includes: Frequency Enhanced Block (FEB), Series Decomposition Block (SDB) and Feed Forward (FFD), as well as the Frequency Enhanced Attention (FEA) module for connecting the encoder and decoder; The input of the reconstruction model adopts a window right-shift step-by-step output mechanism. Before the complete reconstruction output is obtained, the output result will add position coding information and convert it into a time domain representation and input it into the decoder of the reconstruction model. Before inputting the decoder, the time domain representation of the reconstructed output is converted into a frequency domain representation using Fourier transform and inputted into the reconstruction decoder together to complete the reconstruction of the next time window. Finally, the final reconstruction output and reconstruction error of the reconstruction model are used as the objective function of the overall model, and the threshold and reconstruction error selected based on the POT algorithm are used to distinguish abnormal data, thereby optimizing the reconstruction model.

2. The network traffic unsupervised anomaly detection method based on the improved Transformer reconstruction model as claimed in claim 1 is characterized in that: The position encoding process specifically includes: The Position Embedding method is used to utilize the relative or absolute position information of the token in the sequence. The calculation method of Position Embedding is shown in Formula 1, where pos represents the position index of the token, i represents the dimension index in each token, and d model The dimension for each token; Then the original input data is added to the position code output by formula 1 as the time domain input of the encoder and decoder in the reconstruction model.

3. The network traffic unsupervised anomaly detection method based on the improved Transformer reconstruction model as claimed in claim 2 is characterized in that: The reconstruction encoder is calculated as where l∈{1,…,N} is the lth layer of the encoder, is the output of layer l, is the input of the lth layer; the specific process of Encoder(·) is shown in Formula 2; where, It represents the periodic representation of the output of the i-th series decomposition block in the l-th layer of the encoder:

4. The network traffic unsupervised anomaly detection method based on the improved Transformer reconstruction model as claimed in claim 3 is characterized in that: The frequency enhancement block (FEB) uses discrete Fourier transform (DFT), defining F as the Fourier transform, F -1 is the inverse Fourier transform; the input of the Frequency Enhanced Block with Fourier Transform (FEB-f) is Take w∈R D×D Perform a linear projection on x, and the calculation method is q = x w; where the output q is the time domain representation, and then Fourier transform is used to convert the time domain representation q to the frequency domain, and the frequency domain representation is Then Q is randomly sampled, and M rows are randomly selected from Q as a subset of Q Among them, M< <N; The calculation process is shown in Formula 3: exist The calculation process of FEB-f based on is shown in Formula 4, where 5. The unsupervised anomaly detection method for network traffic based on the improved Transformer reconstruction model as claimed in claim 3, characterized in that: The Series Decomposition Block (SDB) uses the decomposition idea to decompose the series into two parts: trend and season. Suppose the input of SDB is Then R,T=SDB(χ), where R is the period and T is the trend. The specific calculation process of SDB(·) is shown in Formula 5: T = AvgPool(Padding(X)) R=XT (5).

6. The network traffic unsupervised anomaly detection method based on the improved Transformer reconstruction model as claimed in claim 3 is characterized in that: The feed forward network (FFD) is a fully connected network. Let the input of FFD be X. Formula 6 is the calculation process of FFD, where Y is the output of FFD, W and b represent the weights and bias terms of the fully connected layer, and f(·) is the ReLu activation function: Y=f(WX+b) (6).

7. The method for unsupervised anomaly detection of network traffic based on the improved Transformer reconstruction model according to any one of claims 1 to 6, characterized in that: The reconstruction decoder is specifically designed as follows: The initialized reconstructed output is transformed into the initialized time domain representation after adding the position encoding information Then, Fourier transform is used to Convert to the initialized frequency domain representation The process is and As the initialization input of the decoder, it participates in the decoder reconstruction process; after that, the decoder is calculated as follows Where l∈{1,…,M} is the lth layer of the decoder; the specific process of Decoder(·) is shown in Formula 7, where, represents the periodic representation and trend representation of the output of the i-th series decomposition block in the l-th layer of the decoder, ω t,i ,i∈{1,2,3} represents the weight involved in the calculation when extracting the i-th trend; Finally, the final reconstruction output of the reconstruction model is Z. Formula 8 is the specific calculation process, where ω s Represents the weight matrix involved in calculating the reconstructed output; For the output result Z of the reconstruction model, the reconstruction error is calculated as the objective function of the optimization model; the calculation process is shown in Formula 9, where G is the input of the entire model:

8. The network traffic unsupervised anomaly detection method based on the improved Transformer reconstruction model as claimed in claim 7, characterized in that: The attention algorithm used by the Frequency Enhanced Attention (FEA) module in Transformer is Scaled Dot-Product Attention. Assuming that the dimension of the input query q (query) is D, the dimension of the key k (key) is D, and the dimension of the value v (value) is D, the dot product operation between the query and each key is calculated and divided by Then the Softmax function is applied to calculate the weights. The calculation process is shown in Formula 10: In FEA, Fourier transform is used to convert query q(query), key k(key), and value v(value) from time domain to frequency domain. The Fourier transformed q, k, and v are expressed as Then randomly sample Q, K, V and randomly select M rows from Q, K, V as the subset of Q, K, V Among them, M< <N, The calculation process is shown in formula 11: exist The calculation process of FEA based on is shown in formula 12, where σ is the activation function:

9. The network traffic unsupervised anomaly detection method based on the improved Transformer reconstruction model as claimed in claim 7, characterized in that: The process of selecting a threshold value based on the POT algorithm is as follows: The POT method is used to automatically select the anomaly threshold. In formula 13, th is the initialization threshold of the anomaly score. For the part below the threshold th, it is recorded as th-S, s is a pre-set low quantile, following the generalized Pareto distribution GPD with parameters γ and β; S is the network traffic anomaly score sequence {S1, S2…, S N' }, N' is the total number of observed scores; After obtaining the estimated values and the final threshold th F is calculated by Equation 14. Where N' th is the number of S i S i ∈{S1, S2, …, S N'}, S i < th; p is the preset expected probability of observing S < th:

10. The network traffic unsupervised anomaly detection method based on the improved Transformer reconstruction model as claimed in claim 9, characterized in that: The method of distinguishing abnormal data specifically includes: in the inference process, for the input sample X, calculating the abnormal score Err(X), where L R The output value of is taken as the calculation result of Err(X), and the judgment rule of inference exception is when Err(X)>th F , the test sample in the sequence is predicted as "abnormal", otherwise it is "normal".

Citation Information

Patent Citations

  • Data flow anomaly detection method and system based on graph deep learning

    CN115080964A

  • Sensor gas concentration detection method based on deep learning transformer neural network

    CN116304912A

  • Network flow prediction system based on time sequence decomposition

    CN116992986A

  • Encrypted traffic identification method, and system, terminal and storage medium

    WO2022094926A1

Cited By

  • Network boundary security stack system

    CN119743291A

  • A network boundary security stack system

    CN119743291B