A malicious traffic detection method and device based on LSTM

By using a two-stage LSTM network and PCA dimensionality reduction processing, combined with the Adam algorithm to train the model, the problems of insufficient real-time performance and punishment mechanism in existing technologies for malicious traffic detection are solved, and efficient and flexible detection and management of network traffic are achieved.

CN117014182BActive Publication Date: 2026-11-24ROCKET FORCE UNIV OF ENG
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310774662.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-28
Publication Date
2026-11-24
Estimated Expiration
2043-06-28

AI Technical Summary

Technical Problem

Existing LSTM-based malicious traffic detection methods are difficult to effectively extract malicious traffic features and lack flexible user punishment mechanisms. They cannot adapt to dynamically changing network traffic data scenarios, traditional deep learning algorithms cannot meet real-time requirements, and circuit breaker mechanisms have poor universality.

Method used

A two-stage LSTM network is adopted, and network traffic data is processed by PCA dimensionality reduction. The features of data packets and network flows are extracted by LSTM-1 and LSTM-2 layers. The model is trained by combining the Adam algorithm and a circuit breaker and recovery mechanism is introduced to punish malicious users.

Benefits of technology

It enables real-time detection and classification of network traffic, reduces computational complexity, adapts to dynamic traffic changes, flexibly manages user access permissions, and improves detection efficiency and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117014182B_ABST
    Figure CN117014182B_ABST
Patent Text Reader

Abstract

A malicious traffic detection method and device based on LSTM, belonging to the field of abnormal traffic detection technology, is characterized by: dimensionality reduction of network data through an improved PCA detection index analysis method, reducing computational complexity while retaining key information of the traffic data, thereby improving detection efficiency; simultaneously, by using multiple bytes to form data packets, and multiple data packets to form network flows, the LSTM neural network is used to extract and analyze the traffic data in stages; each data packet is processed in real time at the LSTM-1 layer to obtain a data packet vector, which is then stored in the backend for the next stage; and an attack mitigation technique of "circuit breaking and then recovery" is used to restore normal hosts' access to network critical node resources, and to extend the penalty time for hosts that launch multiple attacks, while restricting access to server resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of abnormal traffic detection technology, and in particular relates to a malicious traffic detection method and device based on LSTM. Background Technology

[0002] Network traffic, as a crucial carrier of information, allows for a concrete and intuitive understanding of the behavior and activities of communicating parties. Collecting and aggregating traffic from key network nodes enables overall system awareness, anomaly alerts, and dynamic, real-time visual detection. Focusing on analyzing abnormal login behavior, abnormal data packet transmissions, and abnormal user IP addresses is a crucial consideration in constructing anomaly traffic detection algorithms. Intrusion Detection Systems (IDS) are commonly used techniques for network traffic analysis, and numerous algorithms for traffic detection have emerged, such as deep learning and entropy calculation. However, abnormal network traffic exhibits correlations in both time and space, making traditional deep learning algorithms insufficient for real-time requirements and unsuitable for real-world network environments.

[0003] Currently, feature-based methods are widely used in the field of abnormal traffic detection. These methods analyze known traffic data, extract strings as feature fields, and establish a feature field library for matching and checking the traffic data. While this method can effectively detect attacks from known viruses, it is less effective at detecting attack variants. Furthermore, the establishment, maintenance, and updating of the feature field library are difficult and require additional storage.

[0004] Some experts have also combined convolutional neural networks (CNNs) with long short-term convolutional neural networks (LSTMs) to detect abnormal traffic. Existing LSTM-based CNN-based abnormal traffic detection methods fully explore the structural characteristics of attack traffic by extracting spatial features of individual data packets from CNNs, and use LSTMs to extract temporal features of the data stream. A high-dimensional data packet vector is output to the LSTM part, which processes the high-dimensional data packet vector into a classification probability vector. Finally, the vector is input to the softmax layer to obtain the final classification result, which has a high detection accuracy and a very low false alarm rate. However, this technology still has the following defects: (1) It uses complete traffic data to participate in the operation of the neural network, which fails to effectively and accurately extract malicious traffic features; (2) It does not propose a flexible penalty mechanism for frequent attacks by malicious users. It only proposes how to detect network traffic, but does not explain how to mark the malicious user after detection or when to restore their access rights. At the same time, the circuit breaker mechanism in the existing technology has poor universality, and the network traffic data it studies is static and not suitable for dynamically changing traffic data scenarios. Summary of the Invention

[0005] The present invention aims to solve the above problems and provides a malicious traffic detection method and device based on LSTM.

[0006] In a first aspect, the present invention provides a malicious traffic detection method based on LSTM, comprising the following steps: Step 1: Obtain raw network traffic; Step 2: Based on the actual network conditions and attack patterns, select the number of data packets, the number of bytes, the stream duration, and the average number of requests per second as detection indicators; Step 3: Use PCA to perform linear transformation on the aforementioned detection indicators, solve for the eigenvalues ​​and eigenvectors of the detection indicators, calculate the variance contribution rate of each detection indicator, and select the top m detection indicators with a cumulative contribution rate greater than the set value to enter the detection model. Step 4: Input the historical traffic data and the top m detection indicators extracted after PCA processing, along with the corresponding network status, into the LSTM network; the LSTM network includes an input layer, an LSTM-1 layer, an LSTM-2 layer, a fully connected layer, a softmax classification layer, and an output layer; The Adam algorithm is used to train the LSTM network, including: Step 4.1: Dynamically adjust the first-moment and second-moment estimates of the gradient of each parameter based on the loss function to obtain the learning rate of each parameter; this can accelerate model convergence and reduce oscillations. Step 4.2: Vectorize the time series data, divide the network stream into packets, and retain the time step information of each packet; Step 4.3: Input the traffic bytes in each data packet into the LSTM-1 layer network in chronological order to generate a data packet vector for each data packet. Arrange these vectors according to the interaction order of the two communicating parties in the network flow to form a data packet vector sequence; therefore, each data packet is processed in real time at this stage. Step 4.4: Place the packet vectors obtained in Step 4.3 into the LSTM-2 layer to learn network flow features, that is, learn the sequence relationship between each packet vector to form a network flow vector; this network flow vector contains the structured information of network traffic. The LSTM-2 layer does not require real-time processing of the packet vectors. When the number of packet vectors reaches the specified requirement, discrimination and classification can be performed. Step 4.5: Fuse and connect the multi-level feature vectors obtained from the LSTM-1 and LSTM-2 layers, and input them into a fully connected neural network for learning; wherein, the TimeDistributed wrapper is used to wrap the neural network layer of the data packet vector generated by the LSTM-1 layer into a time series processing layer, so as to transform the multiple data packet vector sequences generated by the LSTM-1 layer into the sequence data required by the LSTM-2 layer. Step 4.6: Perform dimensionality transformation on the vector output by the fully connected layer in Step 4.5, and then perform softmax classification; Step 4.7: Predict the network status based on historical data. If the output result is normal, return to step 4; if the output result is abnormal, put this traffic information into the abnormal traffic database and execute step 5. Step 5: Perform circuit breaking on abnormal traffic data; the controller detects whether there is characteristic information of attack flow in the network traffic; if so, it suspends its access to the target server; if not, it verifies the traffic data again. If the verification result is normal traffic, it returns to step 4; if the verification result is abnormal traffic, it puts this traffic information into the abnormal traffic database and sends the information of the circuit-breaking network flow as the flow table of the SDN switch to perform circuit breaking.

[0007] Furthermore, the malicious traffic detection method based on LSTM described in this invention uses a two-stage LSTM network consisting of LSTM-1 and LSTM-2 layers to comprehensively extract network traffic data features by learning features at both the packet and network flow levels. It learns parameters to forget unimportant information from previous time points and selects to remember important information. Its structure includes a dedicated memory unit consisting of three multiplication gates: a forget gate, an input gate, and an output gate. The forget gate is used to learn how long information has been stored in the memory unit and to determine whether it is necessary to forget certain information from previous points in time. The information is retrieved using the sigmoid function, where 0 indicates complete discarding and 1 indicates complete retention. The specific expression is as follows: in, This represents the update forget gate in LSTM networks. Forget gate activation function, Here is the forget gate weight matrix. This is the output gate for the upper layer. For source network flow, It is the bias vector; The input gate determines the information to be learned, the sigmoid layer updates the input value, and the tanh layer creates a new candidate value vector and adds it to the state. in, The input gate weight matrix, For bias vectors, For the input gate activation function, and These represent the tanh function weights and the system bias vector, respectively. Candidate state; From the above formula, we can obtain: in This is status information.

[0008] The output gate determines the final output value; first, the output state is determined by the sigmoid function, and then the output information is mapped by the tanh function; the output gate as follows: in, This is the output gate weight matrix. For bias vectors, For the output gate activation function, This is the activation function for the tanh layer.

[0009] Furthermore, in the LSTM-based malicious traffic detection method of this invention, step 4.1, which involves dynamically adjusting the first-moment and second-moment estimates of the gradient of each parameter according to the loss function to obtain the learning rate of each parameter, includes calculating and storing the average value of an exponentially decaying historical squared gradient. Save an exponentially decaying mean of a historical gradient. ; in and Let these represent the first and second moments of the gradient, respectively. and When both tend to 0, the bias is offset by calculating the first and second moments of the bias correction. Based on this, the model parameters can be obtained. The update rules are as follows: The value is 0.9. The value is 0.999, and K is the step size, which ranges from 250 to 500. Values .

[0010] Furthermore, in the LSTM-based malicious traffic detection method of the present invention, when performing circuit breaker processing in step 5, the initial penalty time is set to... After the penalty period, the system automatically deletes the penalized flow from the table and restores the host's access to server resources. However, the attack flow's information already exists in the controller's attack source table. If the host continues to send attack requests, and the system determines it to be attack traffic after detection, not only will the host be blocked again, but an additional penalty period will also be added. ; ; Where m represents the number of malicious attack requests.

[0011] Furthermore, in the LSTM-based malicious traffic detection method of the present invention, when performing circuit breaking, if a network flow repeatedly exhibits the characteristics of attack traffic, its circuit breaking time T is... r The message will grow longer and longer. If it exceeds the specified limit, the host IP will be blocked, and its permanent access to server resources will be revoked.

[0012] Furthermore, in the LSTM-based malicious traffic detection method of the present invention, when performing circuit breaker processing, the LRU algorithm is used to reduce the storage capacity of the controller.

[0013] Secondly, the present invention provides a malicious traffic detection system based on LSTM, including a traffic collection module, a traffic data processing module, an abnormal traffic detection module, and an abnormal traffic processing module. The traffic collection module is used to acquire raw network traffic; collect and aggregate the traffic of key network nodes, process it, and then send it to other traffic analysis components. The traffic data processing module is used to extract features from the collected network traffic data according to the actual network situation and attack mode, select detection indicators, and perform normalization processing to reduce the weight difference between different data attribute components. It uses PCA to perform linear transformation on the aforementioned detection indicators, solves the eigenvalues ​​and eigenvectors of the detection indicators, calculates the variance contribution rate of each detection indicator, selects the top m detection indicators with a cumulative contribution rate greater than a set value to enter the detection model, and finally puts them into the storage system. The abnormal traffic detection module is used to divide traffic data into normal traffic and abnormal traffic according to the abnormal traffic detection model, and to dynamically update the existing abnormal traffic detection model using new traffic data. The abnormal traffic processing module is used to perform circuit breaking on abnormal traffic based on model detection results and abnormal traffic information, and set corresponding penalty time to restrict its access to server resources.

[0014] Furthermore, in the LSTM-based malicious traffic detection system of the present invention, the abnormal traffic detection module, when processing traffic data, puts historical traffic data and the top m detection indicators extracted after PCA processing, along with the corresponding network status, into an LSTM network. The LSTM network includes an input layer, an LSTM-1 layer, an LSTM-2 layer, a fully connected layer, a softmax classification layer, and an output layer. The Adam algorithm is used to train the LSTM network. The model is trained by learning features at both the packet and network flow levels through a two-stage multi-feature fusion LSTM network. Each packet is processed to obtain a packet vector, which is then input into the second-stage network flow layer for further processing.

[0015] Thirdly, the present invention provides an electronic device for detecting malicious traffic based on LSTM, comprising a processor and a memory electrically connected to each other; the memory is used to store a computer program; when the processor executes the aforementioned computer program, it can implement the malicious traffic detection method based on LSTM described in the first aspect.

[0016] Fourthly, the present invention provides a computer-readable storage medium storing a computer program thereon; when the computer program is executed, it can implement the LSTM-based malicious traffic detection method described in the first aspect above.

[0017] The malicious traffic detection method and apparatus based on LSTM described in this invention have the following beneficial effects: (1) The improved PCA detection index analysis method can effectively reduce the dimensionality of network data, reduce computational complexity, retain key information of traffic data, and improve detection efficiency; (2) Suitable for the structural form of network traffic data; multiple bytes together form a data packet, and multiple data packets together form a network flow. Using LSTM neural network to extract and analyze traffic data in stages can fully learn its structural information; (3) It is conducive to real-time processing. In the LSTM-1 layer, each data packet is processed in real time to obtain a data packet vector, which is then stored in the back end to enter the next stage. Therefore, if the entire network flow is detected and classified instead of being processed in stages, the workload within the interval will be very large when the network flow length is large, which is not conducive to real-time processing. (4) Use the circuit breaker and recovery attack mitigation technology to restore normal hosts’ access to network critical node resources, and extend the penalty time for hosts that launch multiple attacks and restrict access to server resources. Attached Figure Description

[0018] Figure 1This is a schematic diagram of the malicious traffic detection method based on LSTM as described in an embodiment of the present invention; Figure 2 This is a schematic diagram of the hierarchical structure of the abnormal traffic detection algorithm described in an embodiment of the present invention; Figure 3 This is a schematic diagram of the LSTM network structure described in an embodiment of the present invention; Figure 4 This is a schematic diagram of the malicious traffic detection system based on LSTM as described in an embodiment of the present invention. Detailed Implementation

[0019] The LSTM-based malicious traffic detection method and apparatus described in the invention will be described in detail below with reference to the accompanying drawings and embodiments. Example 1

[0020] This embodiment discloses a malicious traffic detection method based on LSTM, such as... Figure 1 The specific steps shown are as follows: Step 1: Obtain raw network traffic; Step 2: Select flow rate detection metrics; Since DDoS attacks and similar attacks do not cause drastic changes in overall network traffic, but only minor changes in traffic volume at some critical network nodes, appropriate traffic detection metrics need to be selected based on network conditions and attack patterns before network detection. This embodiment focuses on the characteristic distribution, flow direction changes, and traffic volume of network traffic, selecting the following four metrics as characteristic parameters: number of data packets, number of bytes, flow duration, and average requests per second. A comprehensive analysis of the distribution changes of these four traffic characteristic parameters is used to effectively detect the entire network traffic.

[0021] Step 3: Use PCA to perform linear transformation on the four detection indicators, solve for the eigenvalues ​​and eigenvectors of these four indicators, calculate the variance contribution rate of each principal component detection indicator, and select the top m detection indicators with a cumulative contribution rate greater than a certain set value to enter the detection model.

[0022] PCA uses a linear transformation to convert a set of correlated vectors into a set of uncorrelated vectors, and arranges these new vectors in order of decreasing variance, while ensuring that the total variance of the variables before and after the transformation remains unchanged. The variable with the largest variance is called the first detection index, and so on.

[0023] In this embodiment of the disclosure, a 4-dimensional random vector is used. These represent the number of data packets, the number of bytes, the stream duration, and the average number of requests per second, respectively. The sample size is [number missing]. The algorithm uses an abnormal traffic detection algorithm as the target layer, and uses the number of data packets, the number of bytes, the stream duration, and the average number of requests per second as the criteria layers, such as... Figure 2 The diagram shows the hierarchical structure of the algorithm, and pairwise comparisons are performed on the four types of influencing factors to construct a sample set. , The sample matrix is ​​then: To ensure equal processing of each traffic feature attribute and eliminate detection bias caused by differences in units or attributes, it is necessary to standardize each feature value. A standardization matrix is ​​required. for: in, .

[0024] According to the standardization matrix The correlation coefficient matrix is ​​solved as follows: Solve the characteristic equation for the correlation coefficient matrix We can obtain four non-negative eigenvalues ​​and their corresponding eigenvectors.

[0025] Using consistency indicators right Conduct the inspection: Because when At that time, the random consistency index According to: It can be found The consistency ratio, when hour, The degree of inconsistency is within acceptable limits, and it passes the consistency test; therefore, it is usable. The feature vectors are used as weight vectors.

[0026] Finally, the order of detection indicators is determined based on the magnitude of the eigenvalues, and the variance contribution rate of each indicator can be calculated. The first m generated detection indicators are selected, and their cumulative contribution rate is set to a certain value. This algorithm selects the first m detection indicators to enter the LSTM traffic detection model to complete the subsequent detection work.

[0027] Step 4: Input the historical traffic data and the top m detection indicators extracted after PCA detection indicator analysis, as well as the network state at that time, into the LSTM network. By inputting multiple sets of data, the training effect of the network is enhanced.

[0028] Step 4.1: Train the LSTM network using the Adam gradient descent algorithm. This is an adaptive learning rate algorithm that dynamically adjusts the learning rate of each parameter based on the first and second moment estimates of the gradient of each parameter using the loss function. This accelerates model convergence and reduces oscillations. It not only calculates and stores the average of an exponentially decaying historical squared gradient, but also... It also preserves the exponentially decaying mean of a historical gradient. The details are as follows: in and Let these represent the first and second moments of the gradient, respectively. and When both tend to 0, the bias is offset by calculating the first and second moments of the bias correction. Based on this, the model parameters can be obtained. The update rules are as follows: Under normal circumstances The value is 0.9. The value is 0.999. Values .

[0029] Step 4.2: Vectorize the time series data by dividing the network stream into packets and preserving the time step information of each packet; Step 4.3: Input the traffic bytes in each data packet into the LSTM-1 network in chronological order to generate a data packet vector for each data packet. These vectors are arranged according to the interaction order of the two communicating parties in the network flow to form a data packet vector sequence. Therefore, each data packet is processed in real time at this stage. Step 4.4: Place the packet vectors obtained in Step 4.2 into the LSTM-2 layer, which is responsible for learning network flow features, that is, the sequence relationship between each packet vector, to form a network flow vector. This network flow vector contains the structured information of network traffic. The LSTM-2 layer does not require real-time processing of the packet vectors. When the number of packet vectors reaches the specified requirement, discrimination and classification can be performed. Step 4.5: Fuse and connect the multi-level feature vectors obtained from the LSTM-1 and LSTM-2 layers, and input them into a fully connected neural network for learning; Specifically, the TimeDistributed wrapper is used to wrap the neural network layer of the data packet vector generated by the LSTM-1 layer into a time series processing layer, so as to transform the multiple data packet vector sequences generated by the LSTM-1 layer into the sequence data required by an LSTM-2 layer.

[0030] Step 4.6: Perform dimensionality transformation on the vector output by the fully connected layer in Step 4.5, and then perform softmax classification; Step 4.7: Predict the network status based on historical data. If the output is 0, it means the network is normal. Return to step 4. If the network output is 1, it means the network is abnormal. Add this traffic information to the abnormal traffic database and proceed to step 5.

[0031] Step 5: Circuit breaking for abnormal traffic data. Generally, attackers control infected botnets to damage critical nodes in the network. However, these hosts still need to access node resources after recovering. Therefore, it's impractical to classify a single attack as malicious and block access to node resources. Furthermore, when many users simultaneously access a node resource using the same proxy server, the excessive traffic will also flag them as "malicious users" by the traffic detection system, adding their IP address to the blocked list. Removing the block requires manual changes by the administrator, which inconveniences legitimate users. Therefore, dynamic management of host access requests is necessary. This system introduces a circuit breaker and recovery attack mitigation technique, which can promptly block malicious requests from botnets and restore their normal access to the target server after recovery, improving the flexibility of the detection system.

[0032] In this embodiment of the disclosure, step 5 includes: Step 5.1: The controller sets up corresponding access control lists to distinguish between normal and malicious users, blocking attacks from attack sources to the target server. During the actual detection process, the controller checks the network traffic for attack flow characteristics. For bot hosts identified as engaging in attack behavior, the controller temporarily suspends their access to the target server—a process known as "circuit breaker." If no attack is detected, it indicates an algorithm malfunction, requiring manual intervention to re-verify the traffic data. If it is indeed normal traffic, the process returns to step 4; if it is indeed abnormal traffic, the traffic information is added to the abnormal traffic database, and step 5.2 is executed. Step 5.2: Distribute the information of the circuit-breaking network flow as a flow table of the SDN switch; Step 5.3: Set the initial penalty time to After the penalty period, the system automatically deletes the penalized flow from the table and restores the host's access to server resources. However, the attack flow's information already exists in the controller's attack source table. If the host continues to send attack requests, and the system determines it to be attack traffic after detection, not only will the host be blocked again, but an additional penalty period will also be added. ; ; Where m represents the number of malicious attack requests.

[0033] When a network flow repeatedly exhibits characteristics of attack traffic, its circuit breaker time T r The message will grow longer and longer. If it exceeds the specified limit, the host IP will be blocked, and its permanent access to server resources will be revoked.

[0034] Step 5.4: For the controller, if the network node is frequently subjected to various malicious attacks from different hosts, the data in its attack source table will increase, which will seriously affect the controller's storage capacity. To solve this problem, the LRU algorithm can be used. When an entry is hit, it is moved to the head of the source table. When the source table reaches a set length, the entry at the tail of the table is deleted.

[0035] In this embodiment of the disclosure, the method for obtaining the raw network traffic in step 1 is as follows: a NetFlow collector is installed on the server to collect network traffic data. NetFlow is a network detection function that can collect IP packet information and network services entering and leaving the network.

[0036] In this embodiment of the disclosure, the set value in step 3, “cumulative contribution rate is greater than a certain set value”, is 85%. The number of detection indicators that meet the condition of “cumulative contribution rate is greater than a certain set value for the top m detection indicators” is 4. That is, the feature parameters that need to be input into the model are: number of data packets, number of bytes, stream duration and average number of requests per second.

[0037] In this embodiment of the disclosure, the input method of traffic data in step 3 is as follows: the traffic is input in batches. For example, in 1-second units, all sample data of the first batch are input and then processed to obtain the feature vector of the current batch of data. A buffer is set to store the traffic data to be processed. Each time the next batch of traffic data is input, the feature values ​​of the previous batch of traffic data are dynamically updated. Then, in 10-second units, the dimensionality-reduced data is put into the LSTM traffic detection model. This improvement can minimize the feature vector error at different time intervals. When the convergence tends to stabilize, the next detection operation is performed.

[0038] In this embodiment of the disclosure, step 5 stipulates that if a single instruction requests more than 2500 requests within 10 seconds, a circuit breaker will be triggered. The initial penalty time is 3 hours, the additional penalty time is 6 hours, and if the specified circuit breaker time limit of 7 days is exceeded, the host will be deprived of permanent access to server resources.

[0039] The malicious traffic detection method and apparatus based on LSTM described in this embodiment utilizes an improved PCA analysis method for dimensionality reduction, reducing computational load while retaining key traffic data information and improving detection efficiency. A two-stage multi-feature fusion LSTM network is established to learn features at both the packet and network flow levels for model training. Each packet is processed to obtain a packet vector, which is then input into the second-stage network flow layer for further processing. This effectively avoids the high latency and high computational load issues caused by the entire network flow participating in the computation. Finally, a circuit breaker and recovery mechanism is introduced. For repeated attacks, the penalty time is extended. If the penalty time exceeds a specified upper limit, the host IP is blocked, revoking its permanent access to server resources. This achieves a progressively layered circuit breaker approach, effectively blocking malicious attacks. Example 2

[0040] This embodiment discloses a malicious traffic detection system based on LSTM, such as... Figure 4 As shown, it includes a traffic collection module, a traffic data processing module, an abnormal traffic detection module, and an abnormal traffic processing module; The traffic collection module is used to acquire raw network traffic; collect and aggregate the traffic of key network nodes, process it, and then send it to other traffic analysis components. The traffic data processing module is used to extract features from the collected network traffic data according to the actual network situation and attack mode, select detection indicators, and perform normalization processing to reduce the weight difference between different data attribute components. It uses PCA to perform linear transformation on the aforementioned detection indicators, solves the eigenvalues ​​and eigenvectors of the detection indicators, calculates the variance contribution rate of each detection indicator, selects the top m detection indicators with a cumulative contribution rate greater than a set value to enter the detection model, and finally puts them into the storage system. The abnormal traffic detection module is used to divide traffic data into normal traffic and abnormal traffic according to the abnormal traffic detection model, and to dynamically update the existing abnormal traffic detection model using new traffic data. The abnormal traffic processing module is used to perform circuit breaking on abnormal traffic based on model detection results and abnormal traffic information, and set corresponding penalty time to restrict its access to server resources.

[0041] In this embodiment of the disclosure, when processing traffic data, the abnormal traffic detection module puts historical traffic data, the first m detection indicators extracted after PCA processing, and the corresponding network status into the LSTM network; for example... Figure 3 As shown, the LSTM network includes an input layer, an LSTM-1 layer, an LSTM-2 layer, a fully connected layer, a softmax classification layer, and an output layer. The Adam algorithm is used to train the LSTM network. The model is trained by learning features at both the data packet and network flow levels through a two-stage multi-feature fusion LSTM network. Each data packet is processed to obtain a data packet vector, which is then input into the second-stage network flow layer for further processing.

[0042] In practical applications, the overall performance of the traffic detection system can be visualized and managed as needed, and self-service data collection, self-service analysis, report export, rapid emergency response, proactive early warning, and rapid backup can be achieved in standardized business scenarios. Example 3

[0043] This embodiment discloses an electronic device for detecting malicious traffic based on LSTM, including a processor and a memory electrically connected to each other; the memory is used to store a computer program; when the processor executes the aforementioned computer program, it can implement the malicious traffic detection method based on LSTM as described in Embodiment 1. The specific detection method steps are the same as those in Embodiment 1, and will not be repeated here.

[0044] Example 4 This embodiment discloses a computer-readable storage medium storing a computer program. When the computer program is executed, it can implement the LSTM-based malicious traffic detection method as described in Embodiment 1. The specific detection method steps are the same as those in Embodiment 1, and will not be repeated here.

[0045] The computer described in this application embodiment can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. The computer-readable storage medium can be any usable medium that a computer can read, or a data storage device such as a server or data center that integrates one or more usable media. The usable medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital versatile optical disc (DVD)), or a semiconductor medium (e.g., solid-state drive (SSD)). The software formed by the computer's stored code can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other storage media that are mature in the art.

[0046] In the various embodiments of this application, the functional modules can be integrated into one processing unit or module, or each module can exist physically separately, or two or more modules can be integrated into one unit or module. In the above embodiments, they can be implemented entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, they can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated.

[0047] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for detecting malicious traffic based on LSTM, characterized in that Includes the following steps: Step 1: Obtain raw network traffic; Step 2: Based on the actual network conditions and attack patterns, select the number of data packets, the number of bytes, the stream duration, and the average number of requests per second as detection indicators; Step 3: Using Principal Component Analysis (PCA), perform linear transformation on the aforementioned detection indicators, solve for the eigenvalues ​​and eigenvectors of the detection indicators, calculate the variance contribution rate of each detection indicator, and select the top m detection indicators with a cumulative contribution rate greater than a set value to enter the detection model. Step 4: Put the historical traffic data and the top m detection indicators extracted after PCA processing, along with the corresponding network states, into a Long Short-Term Memory (LSTM) network; the LSTM network includes an input layer, an LSTM-1 layer, an LSTM-2 layer, a fully connected layer, a softmax classification layer, and an output layer; The Adam algorithm is used to train the LSTM network, including: Step 4.1: Dynamically adjust the first-moment and second-moment estimates of the gradient of each parameter based on the loss function to obtain the learning rate of each parameter; Step 4.2: Vectorize the time series data, divide the network stream into packets, and retain the time step information of each packet; Step 4.3: Input the traffic bytes in each data packet into the LSTM-1 layer network in chronological order to generate a data packet vector for each data packet. Arrange these vectors according to the interaction order of the two communicating parties in the network flow to form a data packet vector sequence. Step 4.4: Put the packet vector obtained in Step 4.3 into the LSTM-2 layer to learn network flow features, that is, learn the sequence relationship between each packet vector to form a network flow vector; Step 4.5: Fuse and connect the multi-level feature vectors obtained from the LSTM-1 and LSTM-2 layers, and input them into a fully connected neural network for learning; Step 4.6: Perform dimensionality transformation on the vector output by the fully connected layer in Step 4.5, and then perform softmax classification; Step 4.7: Predict the network status based on historical data. If the output result is normal, return to step 4; if the output result is abnormal, put this traffic information into the abnormal traffic database and execute step 5. Step 5: Perform circuit breaking on abnormal traffic data; the controller detects whether there is any characteristic information of the attack flow in the network traffic; if so, it suspends the access to the target server; if not, it verifies the traffic data again. If the verification result is normal traffic, it returns to step 4; if the verification result is abnormal traffic, it puts the traffic information into the abnormal traffic database and sends the information of the circuit-breaking network flow as the flow table of the software-defined network (SDN) switch to perform circuit breaking.

2. The LSTM-based malicious traffic detection method of claim 1, wherein: The two-stage LSTM network with LSTM-1 and LSTM-2 layers includes a dedicated memory unit consisting of three multiplication gates: a forget gate, an input gate, and an output gate. The forget gate is used to learn how long information has been stored in the memory unit and to determine whether it is necessary to forget certain information from previous points in time. The information is retrieved using the sigmoid function, where 0 indicates complete discarding and 1 indicates complete retention. The specific expression is as follows: wherein, represents an update forget gate of the LSTM network, is a forget gate activation function, is a forget gate weight matrix, is an output gate of the previous layer, is a source network flow, is a bias vector, is a current time, is an output vector of the forget gate; The input gate determines the information to be learned, the sigmoid layer updates the input value, and the tanh layer creates a new candidate value vector and adds it to the state. wherein, is an input gate weight matrix, is a bias vector, is an input gate activation function, and represent the tanh function weight and system bias vector, respectively, is a candidate state, is the current time instant; From the above formula, we can obtain: wherein is state information, is the current time; The output gate determines the value of the final output; first determine the output state through sigmoid, and then map the output information through tanh function; output gate As follows: wherein, is an output gate weight matrix, is a bias vector, is an output gate activation function, is a tanh layer activation function, is a current time.

3. The malicious traffic detection method based on LSTM according to claim 1, characterized in that: The first order moment estimation and the second order moment estimation of the gradient of each parameter according to the loss function are dynamically adjusted according to step 4.1, to obtain the learning rate of each parameter; including calculating and saving an exponentially decaying average value of a history square gradient , saving an exponentially decaying average value of a history gradient ; where and denote the first and second moment estimations of the gradient, respectively, is the current time instant the computed gradient vector, is the current time instant; when and both tend to 0, the bias-corrected first and second moment estimations are computed to counteract the bias: Accordingly, the model parameters can be obtained The update rule of the is as follows: takes the value 0.9, takes the value 0.999, K takes the value 250-500, takes the value .

4. The malicious traffic detection method based on LSTM according to claim 1, characterized in that: When the fusing processing is performed as described in step 5, the first penalty time is set as , and after the penalty time, the system automatically deletes the penalty flow table and restores the access right of the host to the server resources, but at this time, the attack source table of the controller already has the related information of the attack flow, and if the host continues to initiate an attack request, the system determines it as attack flow after detection, and not only the host will be fused again, but also an additional penalty time will be added. ; wherein, is the number of malicious attack requests.

5. The LSTM-based malicious traffic detection method of claim 4, wherein: When the circuit breaker process is implemented, if a network flow repeatedly exhibits characteristics of attack traffic, its circuit breaker time Tr will become longer and longer. If it exceeds the specified upper limit, the host IP will be blocked, and its permanent access to server resources will be revoked.

6. The LSTM-based malicious traffic detection method of claim 5, wherein: When performing circuit breaker processing, the Least Recently Used (LRU) algorithm is used to reduce the controller's storage capacity. 7.A LSTM-based malicious traffic detection system, characterized in that: It includes a traffic collection module, a traffic data processing module, an abnormal traffic detection module, and an abnormal traffic processing module; The traffic collection module is used to acquire raw network traffic; The system module collects and aggregates traffic from key network nodes, processes it, and then sends it to other traffic analysis components. The traffic data processing module is used to extract features from the collected network traffic data according to the actual network situation and attack mode, select detection indicators, perform normalization processing, use PCA to perform linear transformation on the aforementioned detection indicators, solve for the eigenvalues ​​and eigenvectors of the detection indicators, calculate the variance contribution rate of each detection indicator, select the top m detection indicators with a cumulative contribution rate greater than a set value to enter the detection model, and finally put them into the storage system. The abnormal traffic detection module is used to divide traffic data into normal traffic and abnormal traffic according to the abnormal traffic detection model, and to dynamically update the existing abnormal traffic detection model using new traffic data. When processing traffic data, the abnormal traffic detection module inputs historical traffic data and the top m detection indicators extracted after PCA processing, along with the corresponding network status, into an LSTM network. The LSTM network includes an input layer, an LSTM-1 layer, an LSTM-2 layer, a fully connected layer, a softmax classification layer, and an output layer. The Adam algorithm is used to train the LSTM network. The model is trained by learning features at both the packet and network flow levels through a two-stage multi-feature fusion LSTM network. Each packet is processed to obtain a packet vector, which is then input into the second-stage network flow layer for further processing. The abnormal traffic processing module is used to perform circuit breaking on abnormal traffic based on model detection results and abnormal traffic information, and set corresponding penalty time to restrict its access to server resources.

8. The LSTM-based malicious traffic detection system of claim 7, wherein: The training of the LSTM network using the Adam algorithm specifically includes: Step 4.1: Dynamically adjust the first-moment and second-moment estimates of the gradient of each parameter based on the loss function to obtain the learning rate of each parameter; Step 4.2: Vectorize the time series data, divide the network stream into packets, and retain the time step information of each packet; Step 4.3: Input the traffic bytes in each data packet into the LSTM-1 layer network in chronological order to generate a data packet vector for each data packet. Arrange these vectors according to the interaction order of the two communicating parties in the network flow to form a data packet vector sequence. Step 4.4: Put the packet vector obtained in Step 4.3 into the LSTM-2 layer to learn network flow features, that is, learn the sequence relationship between each packet vector to form a network flow vector; Step 4.5: Fuse and connect the multi-level feature vectors obtained from the LSTM-1 and LSTM-2 layers, and input them into a fully connected neural network for learning; Step 4.6: Perform dimensionality transformation on the vector output by the fully connected layer in Step 4.5, and then perform softmax classification; Step 4.7: Predict the network status based on historical data. If the output result is normal, return to the abnormal traffic detection module for processing; if the output result is abnormal, put this traffic information into the abnormal traffic database and process it through the abnormal traffic processing module. 9.An electronic device for LSTM-based malicious traffic detection, comprising a processor and a memory electrically connected to each other; the memory is configured to store a computer program; characterized in that: When the processor executes the aforementioned computer program, it can implement the LSTM-based malicious traffic detection method as described in any one of claims 1-6.

10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program; when the computer program is executed, it can implement the LSTM-based malicious traffic detection method as described in any one of claims 1-6.

Citation Information

Patent Citations

  • DDoS attack detection method based on LSTM (Long Short-Term Memory) prediction model

    CN108900542A

  • SDN controller-oriented real-time DDoS attack detection system and method

    CN109981691A