A malicious traffic detection method and system based on few-shot learning

By modeling network flow as an interactive reproducible graph and using graph convolutional neural networks to extract features, the problem of dependence on large amounts of labeled data and neglect of packet correlation in existing technologies is solved, and efficient detection of malicious traffic in small samples is achieved.

CN117896129BActive Publication Date: 2026-11-17ZHEJIANG UNIV OF TECH
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202410015441.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-05
Publication Date
2026-11-17
Estimated Expiration
2044-01-05

AI Technical Summary

Technical Problem

Existing malicious traffic detection methods rely on training with large amounts of labeled data, making them difficult to deal with new attack methods and ignoring the rich correlations between data packets.

Method used

The network flow is modeled as a directed graph structure of interactive recurrence graphs. Graph convolutional neural networks are used to extract the correlation features between data packets, and a Siamese network model is constructed for few-shot learning and detection.

Benefits of technology

It achieves high-precision malicious traffic detection with a very small number of labeled samples, reduces labeling costs, and can quickly respond to new attack methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117896129B_ABST
    Figure CN117896129B_ABST
Patent Text Reader

Abstract

A method and system for detecting malicious traffic in small samples based on graph convolutional neural networks (GCNNs) are disclosed. The method includes: S1: segmenting the collected network flow according to quintuples; S2: removing retransmitted packets, selecting the first N packets as a representation of a network flow, performing padding, alignment, and anonymization on the selected packets, and extracting IP address pairs; S3: constructing the network flow as graph structure data of an interactive replay graph; S4: constructing a Siamese network model based on a GCNN and training the model; S5: using the model to detect malicious traffic in the network traffic. The invention also includes a system comprising a network traffic acquisition module, a network traffic processing module, a model training module, and a malicious traffic detection module. This invention models network traffic as graph structure data of an interactive replay graph and uses a GCNN to capture its rich structural characteristics, achieving high-precision detection results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of malicious traffic detection, and in particular to a malicious traffic detection method and system based on few-shot learning. Background Technology

[0002] With the rapid development of the internet, the era of big data has begun, leading to a surge in network traffic. Simultaneously, malicious traffic and malicious behavior are constantly occurring. To quickly detect malicious activity and minimize its losses, many cybersecurity analysts have begun developing malicious traffic detection systems, analyzing patterns and characteristics in large amounts of network traffic data to identify attack behaviors.

[0003] Traditional traffic classification methods can be broadly categorized into three types: port-based methods, payload-based methods, and machine learning and deep learning-based methods. Port-based methods are hampered by the use of port spoofing, making them inaccurate in detecting malicious behavior; payload-based methods, due to the use of SSL and TLS encryption, struggle to accurately identify features that distinguish normal from abnormal traffic; and machine learning-based methods rely on expert-selected features. To eliminate the reliance on manual analysis in anomaly detection models and enable them to learn to differentiate between normal and abnormal traffic from large datasets, deep learning methods have recently become the mainstream approach in malicious traffic detection. Compared to machine learning, deep learning methods do not rely on expert features; instead, they automatically extract features from the data using a constructed deep learning model for classification.

[0004] However, the prerequisite for deep learning models to achieve good detection results is the need for a large amount of labeled traffic data for training the model. In real-world environments, the amount of normal traffic far exceeds the amount of malicious traffic, making it costly to select and label malicious traffic. Malicious traffic detection methods based on few-shot learning may be a unique path to solving this problem, because few-shot learning only requires a small number of labeled samples to detect malicious traffic. Meanwhile, network attack methods are constantly evolving with technological advancements. When new attack methods emerge, it is often difficult to defend against them using existing methods. These new attacks often have very few samples available, making it difficult to train a neural network model to detect them. In such cases, a support set can be constructed from a very small number of samples using few-shot learning, quickly building protection against these types of attacks.

[0005] A search revealed the following: CN201910858882.8, "A Network Intrusion Detection Method Based on Meta-Learning in a Few-Sample Scenarios," which extracts the final representation of a network flow using an F-Net constructed from a convolutional neural network. Then, a C-Net is used to sequentially evaluate the difference between the query sample and samples of each category in the sampling set, and the mean value for each class is calculated. The class represented by the minimum value is selected as the label of the query sample. CN202310253979.2, "A Method and System for Detecting Abnormal Traffic in Few Samples," converts data packets into grayscale images and uses a sliding window to sequentially combine three adjacent grayscale images into an RGB color image, completing the graphical processing of session traffic. A Siamese network model is constructed based on a convolutional neural network for subsequent detection tasks. CN202310783624.4, "A Few-Sample Learning Intrusion Detection Method Based on Drop-MAML," evaluates the similarity between the meta-task and the target task in few-sample learning using a certain strategy, and discards meta-tasks with low similarity with a certain probability, thereby improving the model's adaptability to new attacks and solving the overfitting problem.

[0006] Most of the existing methods mentioned above, when modeling network traffic data, only consider the sequential relationship between data packets, model them as image data, and obtain sample embeddings through convolutional neural networks. This ignores the richer relationships between data packets. Summary of the Invention

[0007] The present invention aims to overcome the above-mentioned shortcomings of the prior art and provide a malicious traffic detection method and system based on few-sample learning.

[0008] Thanks to the rapid development of graph neural network technology, this invention models network flow as directed graph structure data of interactive recurrence graphs, and constructs a feature extraction model based on graph convolutional neural networks to capture the rich correlation features between data packets contained in the interactive recurrence graphs, which are then used for subsequent few-shot learning and malicious traffic detection tasks.

[0009] This invention extracts IP address pairs from a network flow and uses them to model the network flow data into a directed graph structure called an interactive reproducibility graph. It then performs deduplication, padding, alignment, and anonymization on the data packets in the network flow to construct node features on the graph. A graph convolutional neural network is used to build a feature extraction model to capture the rich correlation features between data packets in a network flow. Finally, a similarity evaluation model is used to obtain the final prediction result.

[0010] Specifically, the technical solution adopted by the present invention to achieve the above-mentioned objectives is as follows:

[0011] The first aspect of this invention relates to a malicious traffic detection method based on few-shot learning, comprising the following steps:

[0012] S1: Segment the collected network traffic according to the five-tuple (source IP address, destination IP address, source port number, destination port number, and transport layer protocol number);

[0013] S2: Further process the segmented network flow, remove retransmitted packets, select the first N data packets as a representation of a network flow, perform padding, alignment and anonymization processing on the selected data packets, and extract IP address pair information;

[0014] S3: Construct the processed network traffic into a graph structure data called the interactive reproducibility graph, and extract the node relationship matrix and node feature matrix;

[0015] S4: Malicious traffic detection is performed by constructing a twin network model based on graph convolutional neural networks, and the model is trained using node relationship matrix and node feature matrix;

[0016] S5: Use a trained model to detect malicious traffic in network traffic.

[0017] Preferably, in step S1:

[0018] S1.1: The collected network traffic is segmented into a five-tuple (source IP address, destination IP address, source port number, destination port number, and transport layer protocol number). The distinction between source IP address and destination IP address, and source port number and destination port number is based on the corresponding information of the first data packet in each network flow. When the collected network flow does not contain a transport layer part, the transport layer protocol number, source port number, and destination port number are all set to 0.

[0019] Preferably, in step S2:

[0020] S2.1: Further process the network stream segmented based on the 5-tuple information to remove retransmitted packets caused by network transmission errors;

[0021] S2.2: Select the first N data packets in a network flow as the representation of this network flow;

[0022] S2.3: Extract the IP address pair information of each data packet in the network flow to facilitate the subsequent construction of the interaction reproduction diagram;

[0023] S2.4: Anonymize network flows. First, remove the MAC address layer from each data packet. Then, anonymize the source IP address and destination IP address in the IP header by replacing them with 0.0.0.0.

[0024] S2.5: Padding and aligning data packets in the network flow. First, padding and aligning the IP header in the data packet according to the maximum length of 60 bytes of the IP header. When the IP header of the data packet is less than 60 bytes, it is padded with 0s to reach a length of 60 bytes, forming the characteristic representation of the IP layer.

[0025] Then, the transport layer portion of the IP packet is padded. The padded operation specifically includes: First, determining whether it has transport layer content. If it does, the padded operation is performed according to the transport layer protocol number. When the transport layer protocol number is 6, that is, the transport layer uses TCP, the TCP header of the packet is first padded to its maximum length of 60 bytes, and then followed by a 0 value with a length of 8 bytes, which is the maximum length of the UDP header. A total of 68 bytes of transport layer feature representation will be generated. If the transport layer protocol number is 17, that is, UDP is used, a 60-byte 0 value will be padded first, and then the 8 bytes of data of its UDP header will be concatenated to form a 68-byte transport layer feature representation. If the packet does not have a transport layer portion, a 68-byte 0 value will be padded as its transport layer feature representation.

[0026] Finally, the first M bytes of the Payload portion are extracted as an extended feature representation, and the above-mentioned parts are concatenated to obtain a feature vector of length 60+68+M bytes to represent a data packet in the network stream.

[0027] Preferably, in step S3:

[0028] S3.1: The interactive reproduction graph contains two types of nodes: host nodes and data packet nodes, and two types of edges: passing and iteration.

[0029] S3.2: The specific process of constructing the interaction reproduction diagram based on the IP address pairs extracted in S2 is as follows:

[0030] First, when a node is added to the interaction reproduction graph for the first time, a source host node (Src0), a packet node (Packet0), and a destination host node (Dst0) are added to it, and transitive edges are added between the source host node (Src0) and the packet node (Packet0), and between the packet node (Packet0) and the destination host node (Dst0).

[0031] Next, source host nodes / destination host nodes and packet nodes will be added to the interaction replay graph based on the changes in IP address pair information. Specifically: when the IP address pair information changes, that is, compared with the previous packet, the IP address pair in the current packet has been swapped, which means that the data transmission direction has changed. Assuming that the current packet is sent from the destination host to the source host, a new source host node (Src1) and packet node (Packet1) will be added to the interaction replay graph. The transmission relationship between the destination host node (Dst0) and packet node (Packet1), the transmission relationship between packet node (Packet1) and the new source host node (Src1), and the transmission relationship between the previously added source host node (Src0) and the newly added source host node (Src1) will be established. When the current packet is sent from the source host to the destination host, the process is similar to the above, except that a new destination host node needs to be added instead of a new source host node.

[0032] Finally, repeat the process of adding host nodes and data packet nodes based on IP addresses until the preset value of N is reached. Extract the in-degree of each node to construct a node relationship matrix, and construct a node feature matrix according to the order in which the nodes are added. The feature of the host node is a feature vector of all zeros with a length of 60+68+M bytes, and the feature of the data packet node is the feature vector of the data packet processed in step S2.

[0033] Preferably, in step S4:

[0034] S4.1: The malicious traffic detection model based on few-shot learning consists of two parts: a feature extraction model built on graph convolutional neural networks and a similarity evaluation model.

[0035] S4.2: The specific feature extraction model based on graph convolutional neural networks consists of two layers of graph convolutional neural networks and one layer of global max pooling;

[0036] The two-layer graph convolutional neural network takes a node relationship matrix and a node feature matrix as input, and is used to aggregate node features in the interaction reconstruction graph. The interaction reconstruction graph is a directed graph, and the node relationship matrix is ​​composed of the in-degree relationships of each node. When the graph convolutional neural network aggregates node features, it aggregates the features of all nodes with in-degree relationships to a given node. The propagation method between layers of the graph convolutional neural network is as follows:

[0037]

[0038] in A is the node relationship matrix; It is the identity matrix; H is the degree matrix;(l) Let W be the hidden layer of the graph convolutional neural network, where l represents the number of hidden layers; (l) Here are the learning parameters for the l-th layer; σ represents the nonlinear activation function.

[0039] A global max pooling layer is used to extract the graph-level representation after node aggregation, representing the graph data as a feature vector of a certain length for subsequent similarity evaluation;

[0040] S4.3: Similarity evaluation model. First, all samples in the support set are fed into the feature extraction model according to their categories to obtain graph-level feature representation vectors. Then, a mean vector is calculated for all graph-level feature representation vectors of each category as the category prototype.

[0041] Next, the sample to be tested is fed into the feature extraction model to obtain the graph-level feature representation vector of the sample to be tested, and the Euclidean distance between it and all class prototypes obtained in the previous step is calculated. The class represented by the class prototype closest to it is selected as its prediction result.

[0042] S4.4: Few-shot learning requires constructing data into tasks for model training. The number of tasks is determined by N-way and K-shot, where N-way represents N categories in each task, and K-shot represents K samples in the support set for each category. The number of samples for each category in the query set is not fixed. Therefore, the training process for the malicious traffic detection model based on few-shot learning is as follows:

[0043] First, randomly select N categories from all categories in the training set. Here, the value of N should be less than or equal to the number of categories in the training set.

[0044] Then, from the samples of each of the selected N categories, K+Q samples are randomly selected, where K samples constitute the support set S. k The Q samples constitute the query set Q. k ;

[0045] All samples in the support set are fed into the feature extraction model, and the class prototype of each class is obtained.

[0046] All samples in the query set are fed into the feature extraction model, and the Euclidean distance to each class prototype is calculated. Then the model loss is calculated, the model parameters are optimized and updated, and the above steps are repeated until the model converges.

[0047] Since the model is for a classification task, all loss functions are cross-entropy loss functions. Before calculating the model's loss, the Euclidean distance needs to be converted into the probability that a sample in the query set is classified into each category using the Softmax function. The specific calculation formula is as follows:

[0048]

[0049] Where f(x) is the feature extraction model that transforms the input x into a graph-level feature representation vector, c k To support the prototype of the sample of category k, This represents the Euclidean distance (norm 2) between the graph-level feature vectors of two samples X1 and X2. A negative sign is added before it because the smaller the Euclidean distance, the closer the two samples are, and the higher the probability of them being classified into the corresponding category. Therefore, a negative sign is added to convert the calculated Euclidean distance.

[0050] Loss is calculated using the following formula:

[0051]

[0052] Where C = N × Q represents the total number of samples in the query set, y c,n To query the value of the nth element of the label ont-hot vector of sample c, p c,n The value of the nth element obtained by formula (2) for querying sample c.

[0053] Preferably, in step S5:

[0054] S5.1: For each category that needs to be detected, select a certain amount of manually labeled data to construct a support set;

[0055] S5.2: Use the malicious traffic detection model trained in step S4 to obtain the category prototype for each category in the support set;

[0056] S5.3: Input the sample to be tested into the malicious traffic detection model to obtain the graph-level feature representation vector, calculate its Euclidean distance to each category prototype, and then use the Softmax function to obtain the probability of it being classified into each category, and select the category label with the highest probability as the detection result.

[0057] The second aspect of the present invention relates to a malicious traffic detection system based on few-shot learning, comprising: a network traffic acquisition module, a network traffic processing module, a model training module, and a malicious traffic detection module;

[0058] The network traffic acquisition module collects network traffic data from the network environment and segments the collected network traffic data.

[0059] The network traffic processing module removes retransmitted data packets, performs padding, alignment, and anonymization on the data, and generates a node relationship matrix and a node feature matrix.

[0060] The model training module: constructs a Task based on the training data, trains the model until the loss converges;

[0061] The malicious traffic detection module works as follows: for each category of malicious traffic to be detected, a certain amount of manually labeled data is selected to construct a support set. The trained malicious traffic detection model is used to obtain the category prototype of each category in the support set. Finally, the sample to be tested is input into the malicious traffic detection model to obtain a graph-level feature representation vector, and its Euclidean distance to each category prototype is calculated. Then, the probability of it being classified into each category is obtained through the Softmax function, and the category label with the highest probability is selected as the detection result.

[0062] A third aspect of the present invention relates to a malicious traffic detection device based on few-shot learning, comprising a memory and one or more processors, wherein the memory stores executable code, and the one or more processors execute the executable code to implement the malicious traffic detection method based on few-shot learning of the present invention.

[0063] A fourth aspect of the present invention relates to a computer-readable storage medium having a program stored thereon that, when executed by a processor, implements the malicious traffic detection method based on few-shot learning of the present invention.

[0064] This invention constructs a twin network model based on graph convolutional neural networks to achieve rapid detection of malicious traffic in network traffic. In the detection stage, only a very small number of labeled samples are needed to construct a support sample set to achieve high-precision detection. This greatly reduces the cost of labeling traffic and also allows for the rapid construction of a detection system when new attack methods emerge.

[0065] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0066] (1) This invention extracts IP address pair information from network flow data and uses it to construct an interactive reproduction graph, models the network flow as graph structure data, and uses graph convolutional neural networks to capture the rich interactive information between data packets contained therein, instead of simply relying on the order of data packets to model them as images or time series data, and only capturing the correlation information between data packets before and after.

[0067] (2) This invention performs padding, alignment and anonymization on each data packet in the network flow so that each feature has the same meaning and eliminates sensitive information such as IP address, which allows the model to learn more accurate classification criteria.

[0068] (3) The present invention constructs a twin neural network model based on graph convolutional neural network, and achieves effective detection of malicious traffic through feature extraction model and similarity evaluation model. In the detection stage, only a small number of labeled samples are needed to construct a support sample set to achieve high-precision detection effect. Attached Figure Description

[0069] To more clearly illustrate the content of the present invention, the present invention will be further described below with reference to specific embodiments and accompanying drawings.

[0070] Figure 1 This is a flowchart of the method of the present invention.

[0071] Figure 2 This is a flowchart of the network traffic processing of the present invention.

[0072] Figure 3 This is a spliced ​​diagram of the components after the data packet of the present invention has been filled and aligned.

[0073] Figure 4 This is a sample diagram of a transport layer using TCP after padding alignment and anonymization processing according to the present invention.

[0074] Figure 5 This is a sample diagram of a transport layer using UDP after padding alignment and anonymization processing for this invention.

[0075] Figure 6 This is a diagram illustrating the construction process of the interactive reproduction diagram of the present invention.

[0076] Figure 7 This is a framework diagram of the model proposed in this invention.

[0077] Figure 8 This is a schematic diagram of the system structure of the present invention. Detailed Implementation

[0078] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0079] It should be noted that, unless otherwise specified, the features in the following embodiments and implementation methods can be combined with each other.

[0080] Example 1

[0081] Reference, Figures 1-7This invention extracts IP address pair information from a network flow and uses it to model the network flow data into a directed graph structure called an interactive reproducibility graph. It also performs deduplication, padding, alignment, and anonymization on the data packets in the network flow to construct node features on the graph. A graph convolutional neural network is used to build a feature extraction model to capture the rich correlation features between data packets in a network flow. Finally, a similarity evaluation model is used to obtain the final prediction result.

[0082] Specifically, the technical solution adopted by the present invention to achieve the above-mentioned objectives is as follows:

[0083] A malicious traffic detection method based on few-shot learning, characterized by the following steps:

[0084] S1: Segment the collected network traffic according to the five-tuple (source IP address, destination IP address, source port number, destination port number, and transport layer protocol number);

[0085] S2: Further process the segmented network stream, remove retransmitted packets, select the first N data packets as a representation of a network stream, and perform padding and alignment processing on the selected data packets;

[0086] S3: Construct the processed network stream into a graph structure data called the interactive replay graph, and extract the node relationship matrix and node feature matrix;

[0087] S4: Malicious traffic detection is performed by constructing a twin network model based on graph convolutional neural networks, and the model is trained using node relationship matrix and node feature matrix;

[0088] S5: Use a trained model to detect malicious traffic in network traffic.

[0089] In step S1:

[0090] S1.1: The collected network traffic is segmented into a five-tuple (source IP address, destination IP address, source port number, destination port number, and transport layer protocol number). The distinction between source IP address and destination IP address, and source port number and destination port number is based on the corresponding information of the first data packet in each network flow. When the collected network flow does not contain a transport layer part, the transport layer protocol number, source port number, and destination port number are all set to 0.

[0091] In step S2:

[0092] S2.1: Further process the network stream segmented based on the 5-tuple information to remove retransmitted packets caused by network transmission errors;

[0093] S2.2: Select the first 15 packets in a network flow as a representation of the network flow;

[0094] S2.3: Extract the IP address pair information of each data packet in the network flow to facilitate the subsequent construction of the interaction reproduction diagram;

[0095] S2.4: Anonymize network flows. First, remove the MAC address layer from each data packet. Then, anonymize the source IP address and destination IP address in the IP header by replacing them with 0.0.0.0.

[0096] S2.5: Perform padding and alignment operations on data packets in the network flow. First, padding and alignment operations are performed on the IP header in the data packet according to the maximum length of 60 bytes of the IP header. When the IP header of the data packet is less than 60 bytes, it is padded to a length of 60 bytes by padding with 0 values ​​to form the characteristic representation of the IP layer.

[0097] Then, the transport layer portion of the IP packet is padded. The padded operation specifically includes: First, determining whether it has transport layer content. If it does, the padded operation is performed according to the transport layer protocol number. When the transport layer protocol number is 6, that is, the transport layer uses TCP, the TCP header of the packet is first padded to its maximum length of 60 bytes, and then followed by a 0 value with a length of 8 bytes, which is the maximum length of the UDP header. A total of 68 bytes of transport layer feature representation will be generated. If the transport layer protocol number is 17, that is, UDP is used, a 60-byte 0 value will be padded first, and then the 8 bytes of data of its UDP header will be concatenated to form a 68-byte transport layer feature representation. If the packet does not have a transport layer portion, a 68-byte 0 value will be padded as its transport layer feature representation.

[0098] Finally, the first 128 bytes of the payload are extracted as an extended feature representation, and the various parts mentioned above are concatenated to obtain a feature vector of length 60 + 68 + 128 = 256 bytes to represent a data packet in the network flow. After processing, the components of a data packet are as follows: Figure 3 As shown;

[0099] Figure 4 This is a sample of a data packet taken from a TCP network stream, after padding, alignment, and anonymization. For ease of display, we normalized each byte of the packet to the range of 0 to 255 and converted it into a 16*16 grayscale image.

[0100] Figure 5 This is an example of a data packet sampled from a UDP network stream, padded and anonymized.

[0101] In step S3:

[0102] S3.1: The interactive reproduction graph contains two types of nodes: host nodes and data packet nodes, and two types of edges: passing and iteration.

[0103] S3.2: The specific process of constructing the interaction reproduction diagram based on the IP address pairs extracted in S2 is as follows:

[0104] First, when a node is added to the interaction reproduction graph for the first time, a source host node (Src0), a packet node (Packet0), and a destination host node (Dst0) are added to it, and transitive edges are added between the source host node (Src0) and the packet node (Packet0), and between the packet node (Packet0) and the destination host node (Dst0).

[0105] Next, source host nodes / destination host nodes and packet nodes will be added to the interaction replay graph based on the changes in IP address pair information. Specifically: when the IP address pair information changes, that is, compared with the previous packet, the IP address pair in the current packet has been swapped, which means that the data transmission direction has changed. Assuming that the current packet is sent from the destination host to the source host, a new source host node (Src1) and packet node (Packet1) will be added to the interaction replay graph. The transmission relationship between the destination host node (Dst0) and packet node (Packet1), the transmission relationship between packet node (Packet1) and the new source host node (Src1), and the transmission relationship between the previously added source host node (Src0) and the newly added source host node (Src1) will be established. When the current packet is sent from the source host to the destination host, the process is similar to the above, except that a new destination host node needs to be added instead of a new source host node.

[0106] Figure 6 This demonstrates the specific process of constructing the interaction reproduction graph:

[0107] When a node is added to the graph for the first time, the transmission direction of data packet P0 is S→D. At this time, a source host node S0, a data packet node P0, and a destination host node D0 will be added to the graph, and two edges with transmission relationships will be added, namely S0→P0 and P0→D0.

[0108] When adding nodes to the graph for the second time, the transmission direction of data packet P1 changes to D→S. At this time, two new nodes need to be added to the graph: the P1 data packet node and the S1 source host node. Three edges need to be added to the graph: the D0→P1 transmission relationship edge, the P1→S1 transmission relationship edge, and the S0→S1 iteration relationship edge. The more complex iteration relationship is added here because it is relatively easy to collect network traffic data when collecting data, but it is extremely difficult to collect the host's state data when sending data packets. The purpose of building the iteration relationship here is to distinguish the host's state when sending or receiving data packets in more detail.

[0109] When adding a node to the graph for the third time, the transmission direction of data packet P2 changes to S→D. At this time, two new nodes need to be added to the graph, namely the P2 data packet node and the D1 source host node. Three edges need to be added to the graph: the S1→P2 transmission relationship edge, the P2→D1 transmission relationship edge, and the D0→D1 iteration relationship edge.

[0110] As can be seen from the three additions above, only the first addition adds three nodes and two edges. Subsequent operations add two nodes and three edges to the graph according to the direction of data packet transmission. Therefore, when adding nodes to the graph for the Nth time, nodes and edges are added according to the direction of data packets, eventually resulting in a directed graph with 2N+1 nodes and 3N-1 edges.

[0111] Finally, the in-degree of each node is extracted to construct a node relationship matrix, and a node feature matrix is ​​constructed according to the order in which nodes are added. The feature of the host node is a feature vector of all zeros with a length of 60+68+128=256 bytes, while the feature of the data packet node is the feature vector of the data packet processed in step S2.

[0112] In step S4:

[0113] S4.1: The malicious traffic detection model based on few-shot learning consists of two parts: a feature extraction model built on graph convolutional neural networks and a similarity evaluation model.

[0114] Figure 7 This is a diagram of the malicious traffic detection model based on few-shot learning proposed in this invention.

[0115] S4.2: The specific feature extraction model based on graph convolutional neural networks consists of two layers of graph convolutional neural networks and one layer of global max pooling;

[0116] The two-layer graph convolutional neural network takes a node relationship matrix and a node feature matrix as input, and is used to aggregate node features in the interaction reconstruction graph. The interaction reconstruction graph is a directed graph, and the node relationship matrix is ​​composed of the in-degree relationships of each node. When the graph convolutional neural network aggregates node features, it aggregates the features of all nodes with in-degree relationships to a given node. The propagation method between layers of the graph convolutional neural network is as follows:

[0117]

[0118] in A is the node relationship matrix; It is the identity matrix; H is the degree matrix; (l) Let W be the hidden layer of the graph convolutional neural network, where l represents the number of hidden layers; (l) Here are the learning parameters for the l-th layer; σ represents the nonlinear activation function.

[0119] A global max pooling layer is used to extract the graph-level representation after node aggregation, representing the graph data as a feature vector of a certain length for subsequent similarity evaluation;

[0120] S4.3: Similarity evaluation model. First, all samples in the support set are fed into the feature extraction model according to their categories to obtain graph-level feature representation vectors. Then, a mean vector is calculated for all graph-level feature representation vectors of each category as the category prototype.

[0121] Next, the sample to be tested is fed into the feature extraction model to obtain the graph-level feature representation vector of the sample to be tested, and the Euclidean distance between it and all class prototypes obtained in the previous step is calculated. The class represented by the class prototype closest to it is selected as its prediction result.

[0122] S4.4: Few-shot learning requires constructing data into tasks for model training. The number of tasks is determined by N-way and K-shot, where N-way represents N categories in each task, and K-shot represents K samples in the support set for each category. The number of samples for each category in the query set is not fixed. Therefore, the training process for the malicious traffic detection model based on few-shot learning is as follows:

[0123] First, randomly select N categories from all categories in the training set. Here, the value of N should be less than or equal to the number of categories in the training set.

[0124] Then, from the samples of each of the selected N categories, K+Q samples are randomly selected, where K samples constitute the support set S. k The Q samples constitute the query set Q. k ;

[0125] All samples in the support set are fed into the feature extraction model, and the class prototype of each class is obtained.

[0126] All samples in the query set are fed into the feature extraction model, and the Euclidean distance to each class prototype is calculated. Then the model loss is calculated, the model parameters are optimized and updated, and the above steps are repeated until the model converges.

[0127] Since the model is for a classification task, all loss functions are cross-entropy loss functions. Before calculating the model's loss, the Euclidean distance needs to be converted into the probability that a sample in the query set is classified into each category using the Softmax function. The specific calculation formula is as follows:

[0128]

[0129] Where f(x) is the feature extraction model that transforms the input x into a graph-level feature representation vector, c k To support the prototype of the sample of category k, This represents the Euclidean distance (norm 2) between the graph-level feature vectors of two samples X1 and X2. A negative sign is added before it because the smaller the Euclidean distance, the closer the two samples are, and the higher the probability of them being classified into the corresponding category. Therefore, a negative sign is added to convert the calculated Euclidean distance.

[0130] Loss is calculated using the following formula:

[0131]

[0132] Where C = N × Q represents the total number of samples in the query set, y c,n To query the value of the nth element of the label ont-hot vector of sample c, p c,n The value of the nth element obtained by formula (2) for querying sample c.

[0133] In step S5:

[0134] S5.1: For each category that needs to be detected, select a certain amount of manually labeled data to construct a support set;

[0135] S5.2: Use the malicious traffic detection model trained in step S4 to obtain the category prototype for each category in the support set;

[0136] S5.3: Input the sample to be tested into the malicious traffic detection model to obtain the graph-level feature representation vector, calculate its Euclidean distance to each category prototype, and then use the Softmax function to obtain the probability of it being classified into each category, and select the category label with the highest probability as the detection result.

[0137] To better demonstrate the performance of the proposed method, the effectiveness of the proposed method was evaluated using the CIC-IDS-2017 and CIC-IDS-2018 datasets, specifically conducting experiments in two main categories:

[0138] The first type of experiment is a binary classification experiment, in which normal traffic includes two types: TCP traffic and UDP traffic; malicious traffic includes four types: DoS, DDoS, FTP-Patator, and SSH-Patator; the number of TCP traffic is 4000, the number of UDP traffic is 4000, and the number of each type of attack traffic is 2000. In this experiment, 6000 attack traffic from the three types and 6000 normal traffic consisting of 3000 normal TCP traffic and 3000 normal UDP traffic are selected each time to form a positive and negative sample pair set for training the model. The remaining attack traffic and normal traffic are used to construct the support set and test set for evaluating the model, and each type of attack is used as the test set in turn. Finally, the average of all experimental results is taken as the performance index of the model. The performance evaluation index of the method is accuracy and detection rate. The comparison method is the FC-Net method proposed in patent CN201910858882.8, "A Network Intrusion Detection Method Based on Meta-Learning in a Small Sample Scenario". The comparison results are shown in Table 1.

[0139] The second type of experiment was a multi-class classification experiment. The CIC-IDS-2017 dataset was constructed as a training dataset containing 11 classes, and the CIC-IDS-2018 dataset was constructed as a test dataset containing 12 classes. When training the model, five classes of data were randomly selected from the training dataset each time. When testing the model, five classes of data were randomly selected from the test dataset each time to test the model's performance. Accuracy was used as the evaluation metric for model performance. Five-way, five-shot, and five-way, ten-shot experiments were conducted respectively. The model performance is shown in Table 2. The result is the average of the accuracy of 1000 random test tasks.

[0140] Table 1. Performance of binary classification and comparison with other methods

[0141] method Number of samples per class in the support set accuracy Detection rate This invention 5 97.45% 99.88% This invention 10 97.91% 99.91% FC-Net 5 93.90% 98.25% FC-Net 10 95.08% 97.78%

[0142] Table 2 Results of the multi-classification experiment

[0143] experiment accuracy 5-way, 5-shot 90.45% 5-way, 10-shot 93.61%

[0144] Example 2

[0145] Reference Figure 8This embodiment relates to a malicious traffic detection system based on few-shot learning, including: a network traffic acquisition module, a network traffic processing module, a model training module, and a malicious traffic detection module;

[0146] The network traffic acquisition module collects network traffic data from the network environment and segments the collected network traffic data.

[0147] S1.1: The collected network traffic is segmented into a five-tuple (source IP address, destination IP address, source port number, destination port number, and transport layer protocol number). The distinction between source IP address and destination IP address, and source port number and destination port number is based on the corresponding information of the first data packet in each network flow. When the collected network flow does not contain a transport layer part, the transport layer protocol number, source port number, and destination port number are all set to 0.

[0148] The network traffic processing module removes retransmitted data packets, performs padding, alignment, and anonymization on the data, and generates a node relationship matrix and a node feature matrix.

[0149] S2.1: Further process the network stream segmented based on the 5-tuple information to remove retransmitted packets caused by network transmission errors;

[0150] S2.2: Select the first 15 packets in a network flow as a representation of the network flow;

[0151] S2.3: Extract the IP address pair information of each data packet in the network flow to facilitate the subsequent construction of the interaction reproduction diagram;

[0152] S2.4: Anonymize network flows. First, remove the MAC address layer from each data packet. Then, anonymize the source IP address and destination IP address in the IP header by replacing them with 0.0.0.0.

[0153] S2.5: Padding and alignment operation for data packets in a network flow;

[0154] S2.6: Construct an interactive reproduction graph and extract the node relationship matrix and node feature matrix.

[0155] The model training module: constructs a Task based on the training data, trains the model until the loss converges;

[0156] S3.1: Randomly select N categories from all categories in the training set. Here, the value of N should be less than or equal to the number of categories in the training set.

[0157] S3.2: From the samples of each of the selected N categories, randomly select K+Q samples, where K samples constitute the support set S. k The Q samples constitute the query set Q. k

[0158] S3.3: Feed all samples from the support set into the feature extraction model and obtain the class prototype for each class;

[0159] S3.4: Feed all samples in the query set into the feature extraction model and calculate their Euclidean distance to the prototype of each class. Then calculate the model cross-entropy loss function, optimize and update the model parameters, and return to the previous steps to repeat until the model converges.

[0160] The malicious traffic detection module:

[0161] S4.1: For each category of malicious traffic that needs to be detected, select a certain amount of manually labeled data to build a support set, and use the trained malicious traffic detection model to obtain the category prototype of each category in the support set;

[0162] S4.2: Input the sample to be tested into the malicious traffic detection model to obtain the graph-level feature representation vector, calculate its Euclidean distance to each category prototype, and then use the Softmax function to obtain the probability of it being classified into each category, and select the category label with the highest probability as the detection result.

[0163] Example 3

[0164] This embodiment relates to a malicious traffic detection device based on few-shot learning, including a memory and one or more processors. The memory stores executable code, and when the one or more processors execute the executable code, they are used to implement the malicious traffic detection method based on few-shot learning in Embodiment 1.

[0165] Example 4

[0166] This embodiment relates to a computer-readable storage medium storing a program that, when executed by a processor, implements the malicious traffic detection method based on few-shot learning in Embodiment 1.

[0167] The embodiments described above are only for the purpose of providing a more detailed description of the present invention and are not intended to limit the scope of the present invention. Various modifications and improvements made by those skilled in the art to the technical solutions of the present invention without departing from the spirit of the present invention should fall within the protection scope defined by the claims of the present invention.

Claims

1. A malicious traffic detection method based on few-shot learning, characterized in that, Includes the following steps: S1: The collected network traffic is segmented into five-tuples, which are source IP address, destination IP address, source port number, destination port number, and transport layer protocol number. S2: Further process the segmented network flow, remove retransmitted packets, select the first N data packets as a representation of a network flow, perform padding, alignment and anonymization processing on the selected data packets, and extract IP address pair information; S3: Construct the processed network traffic into a graph structure data called the Interactive Reproduction Graph, and extract the node relationship matrix and node feature matrix; specifically including: S3.1: The interactive reproduction graph contains two types of nodes: host nodes and data packet nodes, and two types of edges: passing and iteration. S3.2: The specific process of constructing the interaction reproduction diagram based on the IP address pairs extracted in S2 is as follows: First, when a node is added to the interaction reproduction graph for the first time, a source host node Src0, a packet node Packet0, and a destination host node Dst0 are added to it, and transitive edges are added between the source host node Src0 and the packet node Packet0, and between the packet node Packet0 and the destination host node Dst0. Subsequently, source host nodes / destination host nodes and packet nodes are added to the interaction replay graph based on changes in IP address pair information. Specifically: when IP address pair information changes, meaning the IP address pairs in the current packet have been swapped compared to the previous packet, it indicates a change in data transmission direction. Assuming the current packet is sent from the destination host to the source host, a new source host node Src1 and packet node Packet1 are added to the interaction replay graph. The transmission relationships between the destination host node Dst0 and packet node Packet1, between packet node Packet1 and the new source host node Src1, and between the previously added source host node Src0 and the newly added source host node Src1 are also established. When the current packet is sent from the source host to the destination host, a new destination host node Dst1 and packet node Packet1 are added to the interaction replay graph. The transmission relationships between the source host node Src0 and packet node Packet1, between packet node Packet1 and the new destination host node Dst1, and between the previously added destination host node Dst0 and the newly added destination host node Dst1 are also established. Finally, repeat the process of adding host nodes and packet nodes based on IP addresses until the preset value of N is reached. Extract the in-degree of each node to construct a node relationship matrix, and then construct a node feature matrix according to the order in which the nodes were added. The host node's feature is one... A zero-based feature vector of length byte, while the data packet node feature is the feature vector of the data packet processed in step S2. S4: Malicious traffic detection is performed by constructing a twin network model based on graph convolutional neural networks, and the model is trained using node relationship matrix and node feature matrix; S5: Use a trained model to detect malicious traffic in network traffic.

2. The malicious traffic detection method based on few-shot learning according to claim 1, characterized in that, Step S1 specifically includes: The collected network traffic is segmented into 5-tuples. The distinction between source IP address and destination IP address, source port number and destination port number is based on the corresponding information of the first data packet in each network flow. When the collected network flow does not contain a transport layer part, the transport layer protocol number, source port number and destination port number are all set to 0.

3. The malicious traffic detection method based on few-shot learning according to claim 1, characterized in that, Step S2 specifically includes: S2.1: Further process the network stream segmented based on the 5-tuple information to remove retransmitted packets caused by network transmission errors; S2.2: Select the first N data packets in a network flow as the representation of this network flow; S2.3: Extract the IP address pair information of each data packet in the network flow to facilitate the subsequent construction of the interaction reproduction diagram; S2.4: Anonymize network flows. First, remove the MAC address layer from each data packet. Then, anonymize the source IP address and destination IP address in the IP header by replacing them with 0.0.0.

0. S2.5: Perform padding and alignment operations on data packets in the network flow. First, padding and alignment operations are performed on the IP header in the data packet according to the maximum length of 60 bytes of the IP header. When the IP header of the data packet is less than 60 bytes, it is padded with 0s to reach a length of 60 bytes, forming the characteristic representation of the IP layer. Then, the transport layer portion of the IP packet is padded. The padded operation specifically includes: First, determining whether it has transport layer content. If it does, the padded operation is performed according to the transport layer protocol number. When the transport layer protocol number is 6, that is, the transport layer uses TCP, the TCP header of the packet is first padded to its maximum length of 60 bytes, and then followed by a 0 value with a length of 8 bytes, which is the maximum length of the UDP header. A total of 68 bytes of transport layer feature representation will be generated. If the transport layer protocol number is 17, that is, UDP is used, a 60-byte 0 value will be padded first, and then the 8 bytes of data of its UDP header will be concatenated to form a 68-byte transport layer feature representation. If the packet does not have a transport layer portion, a 68-byte 0 value will be padded as its transport layer feature representation. Finally, the M-byte payload portion is extracted as an extended feature representation, and the aforementioned portions are concatenated to obtain a... A feature vector of length 1 byte is used to represent a data packet in a network stream.

4. The malicious traffic detection method based on few-shot learning according to claim 1, characterized in that, Step S4 specifically includes: S4.1: The malicious traffic detection model based on few-shot learning consists of two parts: a feature extraction model built on graph convolutional neural networks and a similarity evaluation model. S4.2: The specific feature extraction model based on graph convolutional neural networks consists of two layers of graph convolutional neural networks and one layer of global max pooling; The two-layer graph convolutional neural network takes a node relationship matrix and a node feature matrix as input, and is used to aggregate node features in the interaction reconstruction graph. The interaction reconstruction graph is a directed graph, and the node relationship matrix is ​​composed of the in-degree relationships of each node. When the graph convolutional neural network aggregates node features, it aggregates the features of all nodes with in-degree relationships to a given node. The propagation method between layers of the graph convolutional neural network is as follows: in , This is a node relationship matrix; It is the identity matrix; It is a degree matrix; For the hidden layers of a graph convolutional neural network, Indicates the number of hidden layers; For the first Layer learning parameters; Represents a non-linear activation function; A global max pooling layer is used to extract the graph-level representation after node aggregation, representing the graph data as a feature vector of a certain length for subsequent similarity evaluation; S4.3: Similarity evaluation model. First, all samples in the support set are fed into the feature extraction model according to their categories to obtain graph-level feature representation vectors. Then, a mean vector is calculated for all graph-level feature representation vectors of each category as the category prototype. Next, the sample to be tested is fed into the feature extraction model to obtain the graph-level feature representation vector of the sample to be tested, and the Euclidean distance between it and all class prototypes obtained in the previous step is calculated. The class represented by the class prototype closest to it is selected as its prediction result. S4.4: Few-shot learning requires constructing data into tasks for model training. A task is determined by N-way and K-shot, where N-way represents N categories in each task, and K-shot represents K samples in the support set for each category. The number of samples for each category in the query set is not fixed. Therefore, the training process for the malicious traffic detection model based on few-shot learning is as follows: First, randomly select N categories from all categories in the training set. Here, the value of N should be less than or equal to the number of categories in the training set. Then, from the samples of each of the selected N categories, K+Q samples are randomly selected, where K samples constitute the support set. The Q samples constitute the query set. ; All samples in the support set are fed into the feature extraction model, and the class prototype of each class is obtained. All samples in the query set are fed into the feature extraction model, and the Euclidean distance to each class prototype is calculated. Then the model loss is calculated, the model parameters are optimized and updated, and the above steps are repeated until the model converges. Since the model is for a classification task, all loss functions are cross-entropy loss functions. Before calculating the model's loss, the Euclidean distance needs to be converted into the probability that a sample in the query set is classified into each category using the Softmax function. The specific calculation formula is as follows: in The feature extraction model transforms the input x into a graph-level feature representation vector. To support the prototype of the sample of category k, , indicating two samples and The graph-level representation of the Euclidean distance of the feature vectors is shown here. The negative sign is added in front of it because the smaller the Euclidean distance, the closer the two samples are to each other, and the greater the probability of them being classified into the corresponding category. Therefore, a negative sign is needed to transform the calculated Euclidean distance. Loss is calculated using the following formula: in This represents the total number of samples in the query set. To query the value of the nth element of the label ont-hot vector of sample c, The value of the nth element obtained by formula (2) for querying sample c.

5. The malicious traffic detection method based on few-shot learning according to claim 1, characterized in that, Step S5 specifically includes: S5.1: For each category that needs to be detected, select a certain amount of manually labeled data to construct a support set; S5.2: Use the malicious traffic detection model trained in step S4 to obtain the category prototype for each category in the support set; S5.3: Input the sample to be tested into the malicious traffic detection model to obtain the graph-level feature representation vector, calculate its Euclidean distance to each category prototype, and then use the Softmax function to obtain the probability of it being classified into each category, and select the category label with the highest probability as the detection result.

6. A malicious traffic detection system based on few-shot learning, implementing the method described in claim 1, characterized in that: It includes a network traffic acquisition module, a network traffic processing module, a model training module, and a malicious traffic detection module; The network traffic acquisition module collects network traffic data from the network environment and segments the collected network traffic data. The network traffic processing module removes retransmitted data packets, performs padding, alignment, and anonymization on the data, and generates a node relationship matrix and a node feature matrix. The model training module: constructs a Task based on the training data, trains the model until the loss converges; The malicious traffic detection module works as follows: for each category of malicious traffic that needs to be detected, a certain amount of manually labeled data is selected to construct a support set. The trained malicious traffic detection model is used to obtain the category prototype of each category in the support set. Finally, the sample to be tested is input into the malicious traffic detection model to obtain a graph-level feature representation vector, and its Euclidean distance to each category prototype is calculated. Then, the probability of it being classified into each category is obtained through the Softmax function, and the category label with the highest probability is selected as the detection result.

7. A malicious traffic detection device based on few-shot learning, characterized in that, The device includes a memory and one or more processors, wherein the memory stores executable code, and the one or more processors execute the executable code to implement the malicious traffic detection method based on few-shot learning as described in any one of claims 1-5.

8. A computer-readable storage medium, characterized in that, It stores a program that, when executed by a processor, implements the malicious traffic detection method based on few-shot learning as described in any one of claims 1-5.

Citation Information

Patent Citations

  • Meta-learning-based network intrusion detection method in small sample scene

    CN110808945A

  • Small sample abnormal flow detection method and system

    CN116366313A

  • Small sample learning intrusion detection method based on Drop-MAML

    CN116821907A