A method and system for detecting malicious encrypted traffic based on data packet representation learning
Through a method based on packet representation learning, combined with LSTM and multi-head attention mechanism, the packet characteristics of encrypted traffic are extracted, which solves the problems of high resource consumption and unsatisfactory detection results of existing detection methods, and achieves efficient identification of malicious encrypted traffic. .
Patent Information
- Application Number
- CN202410757865.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-13
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-06-13
AI Technical Summary
Existing malicious encrypted traffic detection methods rely on payload decryption or manually designed statistical features, resulting in high resource consumption, data privacy concerns and unsatisfactory detection results, and lack of in-depth exploration of encrypted traffic.
A method based on packet representation learning is used to divide encrypted traffic by enriching bidirectional flow sessions, select packet parameters as detection features, input them into the deep learning network, and combine LSTM and multi-head attention mechanisms to extract packet features to identify malicious encrypted traffic.
It improves the accuracy and efficiency of malicious encrypted traffic detection, reduces resource consumption, enhances the ability to deeply mine encrypted traffic, and improves the detection rate.
Smart Images

Figure CN118337533B
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of malicious encrypted traffic detection, and in particular relates to a malicious encrypted traffic detection method and system based on data packet characterization learning. Background Art
[0002] With the widespread use of encrypted traffic in the network, attackers cannot display this feature through the content of encrypted traffic, and send encrypted traffic with malicious behavior to bypass the detection equipment to achieve the attacker's purpose. Among the current traditional detection methods, the main one is the payload-based deep packet inspection technology. This method uses the method of decrypting encrypted traffic, but it consumes a lot of resources and causes users to worry about data privacy. In order to avoid the use of payload decryption, a method based on statistical features is proposed. By extracting the statistical features of encrypted traffic and designing an algorithm for traffic identification, this type of method relies on expert experience to manually design features to extract features. This type of feature is not accurate enough for the characterization of attack behaviors and lacks in-depth mining of encrypted traffic. Therefore, the detection effect of current detection methods is not ideal. . Summary of the invention
[0003] In order to solve the above technical problems, the present invention proposes a technical solution of a malicious encrypted traffic detection method based on data packet representation learning to solve the above technical problems.
[0004] The first aspect of the present invention discloses a malicious encrypted traffic detection method based on data packet characterization learning, the method comprising:
[0005] Step S1, using rich bidirectional flow sessions as the basic unit of division, dividing each encrypted traffic Pcap file to obtain a number of sessions;
[0006] Step S2, selecting a preset number of packets in the session to represent global traffic; selecting several parameters of each packet as detection features;
[0007] Step S3: input the detection features into a deep learning network to obtain malicious encrypted traffic identification results.
[0008] According to the method of the first aspect of the present invention, in step S2, the preset value is equal to 30.
[0009] According to the method of the first aspect of the present invention, in step S2, the parameters of each data packet include:
[0010] Size: packet payload size; time: time interval with the previous packet; dir: packet transmission direction; ack: the first flag bit of the TCP layer of the packet; psh: the second flag bit of the TCP layer of the packet.
[0011] According to the method of the first aspect of the present invention, in step S3, the method of inputting the detection feature into a deep learning network to obtain a malicious encrypted traffic identification result includes:
[0012] Input the detection feature into the LSTM network to obtain an LSTM output; use the LSTM output as the query, key and value of the multi-head attention mechanism; use different weight matrices to perform multiple linear transformations on the multi-head attention pair query, key and value in parallel to obtain vector attention of different data packets; merge the vector attention of all data packets and output a global feature;
[0013] After the global features are processed by the fully connected layer, a data packet feature vector is obtained; the data packet feature vector is input into the Softmax classifier to obtain a malicious encrypted traffic identification result.
[0014] A second aspect of the present invention discloses a malicious encrypted traffic detection system based on data packet representation learning, the system comprising:
[0015] The first processing module is configured to divide each encrypted traffic Pcap file by using a rich bidirectional flow session as a basic unit of division to obtain a plurality of sessions;
[0016] The second processing module is configured to select a preset number of packets in the session to represent global traffic; and select several parameters of each packet as detection features;
[0017] The third processing module is configured to input the detection features into a deep learning network to obtain malicious encrypted traffic identification results.
[0018] According to the system of the second aspect of the present invention, the preset value is equal to 30.
[0019] According to the system of the second aspect of the present invention, the several parameters of each data packet include:
[0020] Size: packet payload size; time: time interval with the previous packet; dir: packet transmission direction; ack: the first flag bit of the TCP layer of the packet; psh: the second flag bit of the TCP layer of the packet.
[0021] According to the system of the second aspect of the present invention, inputting the detection feature into a deep learning network to obtain a malicious encrypted traffic identification result includes:
[0022] Input the detection feature into the LSTM network to obtain an LSTM output; use the LSTM output as the query, key and value of the multi-head attention mechanism; use different weight matrices to perform multiple linear transformations on the multi-head attention pair query, key and value in parallel to obtain vector attention of different data packets; merge the vector attention of all data packets and output a global feature;
[0023] After the global features are processed by the fully connected layer, a data packet feature vector is obtained; the data packet feature vector is input into the Softmax classifier to obtain a malicious encrypted traffic identification result.
[0024] The third aspect of the present invention discloses an electronic device. The electronic device includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the steps in any one of the malicious encrypted traffic detection methods based on data packet characterization learning in the first aspect of the present disclosure are implemented.
[0025] The fourth aspect of the present invention discloses a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any one of the malicious encrypted traffic detection methods based on data packet characterization learning in the first aspect of the present disclosure are implemented.
[0026] In summary, the scheme proposed in the present invention can deeply mine the features at the TLS protocol packet level, use the LSTM algorithm to extract the sequence information of the features, and add a self-attention mechanism to reduce the propagation information loss of the LSTM algorithm and extract key information from the sequence information for detection, thereby improving the detection rate of encrypted malicious traffic. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0028] Figure 1 A flowchart of a malicious encrypted traffic detection method based on data packet characterization learning according to an embodiment of the present invention;
[0029] Figure 2 A structural diagram of a malicious encrypted traffic detection system based on data packet characterization learning according to an embodiment of the present invention;
[0030] Figure 3 The figure is a structural diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0031] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0032] A first aspect of the present invention discloses a malicious encrypted traffic detection method based on data packet representation learning. Figure 1 FIG. 1 is a flow chart of a method for detecting malicious encrypted traffic based on data packet characterization learning according to an embodiment of the present invention. Figure 1 As shown, the method includes:
[0033] Step S1, using rich bidirectional flow sessions as the basic unit of division, dividing each encrypted traffic Pcap file to obtain a number of sessions;
[0034] Step S2, selecting a preset number of packets in the session to represent global traffic; selecting several parameters of each packet as detection features;
[0035] Step S3: input the detection features into a deep learning network to obtain malicious encrypted traffic identification results.
[0036] In step S1, each encrypted traffic Pcap file is divided using a rich bidirectional stream session as a basic unit of division to obtain a number of sessions.
[0037] Specifically, the five-tuple (source IP, destination IP, source port, destination port, and transport layer protocol) is used as the basis for traffic division, and rich two-way flow sessions are used as the basic unit of division. Each encrypted traffic Pcap file is divided to obtain several sessions.
[0038] In step S2, a preset number of data packets in the session are selected to represent the global traffic; and several parameters of each data packet are selected as detection features.
[0039] In some embodiments, in step S2, the preset value is equal to 30.
[0040] The parameters of each data packet include:
[0041] Size: packet payload size; time: time interval with the previous packet; dir: packet transmission direction; ack: the first flag bit of the TCP layer of the packet; psh: the second flag bit of the TCP layer of the packet.
[0042] Specifically, since the distribution of malicious traffic and normal traffic at the packet level is quite different, modeling based on packet characteristics can effectively distinguish malicious traffic from normal encrypted traffic. According to statistics, the number of sample packets in most sessions is less than 30. Even if the number exceeds 30, the basic important information is stored in the first 30 packets. Therefore, the first 30 packets in the session are selected to represent the global traffic. The characterization of the session at the packet granularity is as follows:
[0043]
[0044]
[0045] in, session behavior Represents a session; p t Indicates the tth data packet; Size: data packet payload size; time: time interval with the previous data packet; dir: data packet transmission direction; ack: the first flag bit of the TCP layer of the data packet; psh: the second flag bit of the TCP layer of the data packet.
[0046] In step S3, the detection features are input into a deep learning network to obtain malicious encrypted traffic identification results.
[0047] In some embodiments, in step S3, the method of inputting the detection feature into a deep learning network to obtain a malicious encrypted traffic identification result includes:
[0048] Input the detection feature into the LSTM network to obtain an LSTM output; use the LSTM output as the query, key and value of the multi-head attention mechanism; use different weight matrices to perform multiple linear transformations on the multi-head attention pair query, key and value in parallel to obtain vector attention of different data packets; merge the vector attention of all data packets and output a global feature;
[0049] After the global features are processed by the fully connected layer, a data packet feature vector is obtained; the data packet feature vector is input into the Softmax classifier to obtain a malicious encrypted traffic identification result.
[0050] Specifically, the LSTM algorithm is used to learn features and mine the intrinsic temporal relationships between data packets. This algorithm is derived from a recurrent neural network and solves the problem of long-term dependency of recurrent neural networks by constructing input gates, forget gates, and output gates. It can handle data with temporal relationships well and better mine the relationships between data. The specific formula of the algorithm is as follows:
[0051]
[0052]
[0053]
[0054]
[0055]
[0056]
[0057]
[0058] Where W and U are the parameter matrices of the gate, representing the input The linear change and hidden state The linear change of , b is the bias, and the subscript corresponds to the corresponding gate, such as The weight bias corresponding to the input gate.
[0059] Through the input gate and the forget gate , control the current t time packet and the memory unit at time t-1 Which features are used for , through the output gate Get hidden nodes . Every moment , through calculation, we get the corresponding hidden node , thus obtaining a basic representation based on the data packet. However, LSTM loses a lot of information in long-distance transmission and is insensitive to feature importance. Therefore, a multi-head self-attention mechanism is used here to improve the extraction process of data packet features.
[0060] The core idea of the multi-head attention mechanism is to assign different weights to input signals at different positions when processing sequence data, so that the model pays more attention to important inputs. The specific operation is: first calculate the attention matrix, split the input tensor into multiple sub-tensors, each of which is the attention information learned in a different way. Then, for each sub-tensor, perform a self-attention calculation to obtain an output tensor. Finally, splice multiple output tensors together to obtain the final output tensor.
[0061] Use the LSTM output as the query, key and value of the multi-head attention mechanism; use different weight matrices , and Perform multiple linear transformations on the multi-head attention pairs (Q), keys (K), and values (V) in parallel to obtain vector attention for different data packets. ; Merge the vector attention of all data packets and output the global features; The key information in different representation subspaces can be learned efficiently. The specific calculation is shown in the following formula:
[0062]
[0063]
[0064]
[0065] in: is the dimension of the K matrix; the Softmax function converts the normalized result of the dot product operation of Q and K into a probability distribution, and multiplies it with the matrix V to obtain the sum of the attention weights.
[0066] After the global features are processed by the fully connected layer, a data packet feature vector is obtained; the data packet feature vector is input into the Softmax classifier to obtain a malicious encrypted traffic identification result. Result , and get the predicted label = argmax( Result ).
[0067] If the predicted label is equal to the actual label, calculate ,in, a The value penalizes and rewards the number of samples of the two categories. y The value rewards samples that are difficult to train and updates the model parameters.
[0068] Experimental test, the specific contents of the experiment are as follows:
[0069] Dataset setting: Daily encrypted business traffic from the existing network environment is collected as white traffic, while the sources of black traffic are three parts. The first is public data sets, such as the CICAndMal2017 data set, the CTU data set, and malicious encrypted traffic pcap packages collected from public websites such as the Weibu Intelligence Platform. The second is the malicious encrypted traffic generated by building a target range and using attack tools to simulate attacks. The third is the real encrypted attack traffic collected from the existing network. In this experiment, there are 1 million white traffic sessions and 500,000 black traffic sessions.
[0070] The test indicators used in the experimental evaluation. In this embodiment, malicious encrypted traffic is classified as positive (labeled as 1) and normal traffic is classified as negative (labeled as 0). First, the following four basic concepts are introduced:
[0071] TP (True Positive): The number of positive samples predicted as positive samples.
[0072] FN (False Negative): The number of positive samples predicted as negative samples.
[0073] FP (False Positive): The number of negative samples predicted as positive samples.
[0074] TN (True Negative): The number of negative samples predicted as negative samples.
[0075] Based on the above basic concepts, the evaluation indicators are established:
[0076] (1) Precision: How many samples predicted as positive are actually positive samples.
[0077]
[0078] The precision reflects the model's ability to correctly predict the accuracy of positive samples. The larger the value, the better the performance.
[0079] (2) Recall: How many samples that are actually positive are predicted to be positive samples.
[0080]
[0081] The recall rate reflects the model's ability to correctly predict the full range of positive samples. The larger the value, the better the model performance.
[0082] (3) Accuracy: The proportion of correctly predicted samples (including positive and negative samples) among all classes of samples.
[0083]
[0084] (4) F1 Score: The harmonic mean of precision and recall.
[0085]
[0086] The purpose of the F1 score is to balance precision and recall. In the F1 score, precision and recall have the same influence weight. The larger the F1 score, the stronger the comprehensive decision-making ability of the model.
[0087] Comparison of experimental results
[0088] In order to verify the effectiveness of this solution, two other mature malicious encrypted traffic detection solutions are used to compare with this solution. Solution 1 uses a model based on traditional machine learning algorithms to extract the flow features of encrypted traffic for detection. Solution 2 uses a convolutional neural network algorithm to convert pcap packets into images and perform detection. The experimental evaluation indicators in the previous section are used for evaluation, and the results are shown in Table 1:
[0089] Table 1
[0090]
[0091] It can be seen from the experimental results that the effect of this embodiment is better than the solutions currently known in the industry, so it can be used as a solution to malicious traffic identification.
[0092] A second aspect of the present invention discloses a malicious encrypted traffic detection system based on data packet representation learning. Figure 2 FIG. 4 is a structural diagram of a malicious encrypted traffic detection system based on data packet characterization learning according to an embodiment of the present invention; Figure 2 As shown, the system 100 includes:
[0093] The first processing module 101 is configured to divide each encrypted traffic Pcap file by using a rich bidirectional flow session as a basic unit of division to obtain a plurality of sessions;
[0094] The second processing module 102 is configured to select a preset number of packets in the session to represent global traffic; and select several parameters of each packet as detection features;
[0095] The third processing module 103 is configured to input the detection features into a deep learning network to obtain a malicious encrypted traffic identification result.
[0096] According to the system of the second aspect of the present invention, the first processing module 101 is specifically configured to use the quintuple (source IP, destination IP, source port, destination port, transport layer protocol) as the basis for traffic division, and use rich bidirectional stream sessions as the basic unit of division, to divide each encrypted traffic Pcap file into several sessions.
[0097] According to the system of the second aspect of the present invention, the second processing module 102 is specifically configured such that the preset value is equal to 30.
[0098] The parameters of each data packet include:
[0099] Size: packet payload size; time: time interval with the previous packet; dir: packet transmission direction; ack: the first flag bit of the TCP layer of the packet; psh: the second flag bit of the TCP layer of the packet.
[0100] Specifically, since the distribution of malicious traffic and normal traffic at the packet level is quite different, modeling based on packet characteristics can effectively distinguish malicious traffic from normal encrypted traffic. According to statistics, the number of sample packets in most sessions is less than 30. Even if the number exceeds 30, the basic important information is stored in the first 30 packets. Therefore, the first 30 packets in the session are selected to represent the global traffic. The characterization of the session at the packet granularity is as follows:
[0101]
[0102]
[0103] in, session behavior Represents a session; p t Indicates the tth data packet; Size: data packet payload size; time: time interval with the previous data packet; dir: data packet transmission direction; ack: the first flag bit of the TCP layer of the data packet; psh: the second flag bit of the TCP layer of the data packet.
[0104] According to the system of the second aspect of the present invention, the third processing module 103 is specifically configured to input the detection feature into the deep learning network to obtain the malicious encrypted traffic identification result including:
[0105] Input the detection feature into the LSTM network to obtain an LSTM output; use the LSTM output as the query, key and value of the multi-head attention mechanism; use different weight matrices to perform multiple linear transformations on the multi-head attention pair query, key and value in parallel to obtain vector attention of different data packets; merge the vector attention of all data packets and output a global feature;
[0106] After the global features are processed by the fully connected layer, a data packet feature vector is obtained; the data packet feature vector is input into the Softmax classifier to obtain a malicious encrypted traffic identification result.
[0107] Specifically, the LSTM algorithm is used to learn features and mine the intrinsic temporal relationships between data packets. This algorithm is derived from a recurrent neural network and solves the problem of long-term dependency of recurrent neural networks by constructing input gates, forget gates, and output gates. It can handle data with temporal relationships well and better mine the relationships between data. The specific formula of the algorithm is as follows:
[0108]
[0109]
[0110]
[0111]
[0112]
[0113]
[0114]
[0115] Where W and U are the parameter matrices of the gate, representing the input The linear change and hidden state The linear change of , b is the bias, and the subscript corresponds to the corresponding gate, such as The weight bias corresponding to the input gate.
[0116] Through the input gate and the forget gate , control the current t time packet and the memory unit at time t-1 Which features are used for , through the output gate Get hidden nodes . Every moment , through calculation, we get the corresponding hidden node , thus obtaining a basic representation based on the data packet. However, LSTM loses a lot of information in long-distance transmission and is insensitive to feature importance. Therefore, a multi-head self-attention mechanism is used here to improve the extraction process of data packet features.
[0117] The core idea of the multi-head attention mechanism is to assign different weights to input signals at different positions when processing sequence data, so that the model pays more attention to important inputs. The specific operation is: first calculate the attention matrix, split the input tensor into multiple sub-tensors, each of which is the attention information learned in a different way. Then, for each sub-tensor, perform a self-attention calculation to obtain an output tensor. Finally, splice multiple output tensors together to obtain the final output tensor.
[0118] Use the LSTM output as the query, key and value of the multi-head attention mechanism; use different weight matrices , and Perform multiple linear transformations on the multi-head attention pairs (Q), keys (K), and values (V) in parallel to obtain vector attention for different data packets. ; Merge the vector attention of all data packets and output the global features; The key information in different representation subspaces can be learned efficiently. The specific calculation is shown in the following formula:
[0119]
[0120]
[0121]
[0122] in: is the dimension of the K matrix; the Softmax function converts the normalized result of the dot product operation of Q and K into a probability distribution, and multiplies it with the matrix V to obtain the sum of the attention weights.
[0123] After the global features are processed by the fully connected layer, a data packet feature vector is obtained; the data packet feature vector is input into the Softmax classifier to obtain the malicious encrypted traffic identification result Result , and get the predicted label = argmax( Result ).
[0124] If the predicted label is equal to the actual label, calculate ,in, a The value penalizes and rewards the number of samples of the two categories. y The value rewards samples that are difficult to train and updates the model parameters.
[0125] The third aspect of the present invention discloses an electronic device. The electronic device includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the steps of any one of the malicious encrypted traffic detection methods based on data packet representation learning disclosed in the first aspect of the present invention are implemented.
[0126] Figure 3 is a structural diagram of an electronic device according to an embodiment of the present invention, such as Figure 3As shown, the electronic device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the electronic device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, an operator network, near field communication (NFC) or other technologies. The display screen of the electronic device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the electronic device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the housing of the electronic device, or an external keyboard, touchpad or mouse, etc.
[0127] Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a structural diagram of the part related to the technical solution of the present disclosure, and does not constitute a limitation on the electronic device to which the technical solution of the present application is applied. The specific electronic device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0128] The fourth aspect of the present invention discloses a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the method for detecting malicious encrypted traffic based on data packet characterization learning in any one of the first aspects of the present invention are implemented.
[0129] Please note that the technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification. The above embodiments only express several implementation methods of the present application, and their descriptions are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that for ordinary technicians in this field, without departing from the concept of the present application, several variations and improvements can be made, which all belong to the scope of protection of the present application. Therefore, the scope of protection of the patent in this application shall be based on the attached claims.
Claims
1. A method for detecting malicious encrypted traffic based on packet representation learning, It is characterized in that The method comprises: Step S1, using rich bidirectional flow sessions as the basic unit of division, dividing each encrypted traffic Pcap file to obtain a number of sessions; Step S2, selecting a preset number of packets in the session to represent global traffic; selecting several parameters of each packet as detection features; Step S3: input the detection feature into a deep learning network to obtain a malicious encrypted traffic identification result; In step S2, the preset value is equal to 30; In step S2, the parameters of each data packet include: Size: the payload size of the data packet; time: the time interval between the last data packet; dir: the transmission direction of the data packet; ack: the first flag bit of the TCP layer of the data packet; psh: the second flag bit of the TCP layer of the data packet; In step S3, the method of inputting the detection feature into a deep learning network to obtain a malicious encrypted traffic identification result includes: Input the detection feature into the LSTM network to obtain an LSTM output; use the LSTM output as the query, key and value of the multi-head attention mechanism; use different weight matrices to perform multiple linear transformations on the multi-head attention pair query, key and value in parallel to obtain vector attention of different data packets; merge the vector attention of all data packets and output a global feature; After the global features are processed by the fully connected layer, a data packet feature vector is obtained; the data packet feature vector is input into the Softmax classifier to obtain a malicious encrypted traffic identification result; In step S2, specifically, since the distribution of malicious traffic and normal traffic at the packet level is quite different, modeling is performed based on the detection features of the data packets, which can effectively distinguish malicious traffic from normal encrypted traffic; the first 30 data packets in the session are selected to represent the global traffic, and the characterization of the session at the packet granularity is as follows: in, session behavior Represents a session; p t Indicates the tth data packet; Size: the payload size of the data packet; time: the time interval between the last data packet; dir: the transmission direction of the data packet; ack: the first flag bit of the TCP layer of the data packet; psh: the second flag bit of the TCP layer of the data packet; In step S3, specifically, the LSTM algorithm is used to learn the features and mine the intrinsic temporal relationship between data packets; the problem of long-term dependence of the recurrent neural network is solved by constructing the input gate, the forget gate and the output gate, and the data with temporal relationship is well processed, and the relationship between the data is better mined. The specific formula is as follows: Where W and U are the parameter matrices of the gate, representing the input The linear change and hidden state The linear change of , b is the bias, and the subscript corresponds to the corresponding gate, such as The weight bias corresponding to the input gate; Through the input gate and the forget gate , control the current t time packet and the memory unit at time t-1 Which features are used for , through the output gate Get hidden nodes ; every moment , through calculation, we get the corresponding hidden node , thereby obtaining a basic representation based on the data packet; a multi-head self-attention mechanism is used to improve the feature extraction of the data packet; When processing sequence data, the multi-head attention mechanism assigns different weights to input signals at different positions, making the model pay more attention to important inputs. The specific operations are as follows: First, the attention matrix is calculated to split the input tensor into multiple sub-tensors, each of which is the attention information learned in a different way; Then, for each sub-tensor, a self-attention calculation is performed to obtain an output tensor; Finally, multiple output tensors are concatenated together to obtain the final output tensor; Use the LSTM output as the query, key and value of the multi-head attention mechanism; use different weight matrices , and Perform multiple linear transformations on the multi-head attention pairs (Q), keys (K), and values (V) in parallel to obtain vector attention for different data packets. ; Merge the vector attention of all data packets and output the global features; The key information in different representation subspaces can be learned efficiently. The specific calculation is shown in the following formula: in: is the dimension of the K matrix; the Softmax function converts the dot product of Q and K and the normalized result into a probability distribution, and multiplies it with the matrix V to obtain the sum of the attention weights; After the global features are processed by the fully connected layer, a data packet feature vector is obtained; the data packet feature vector is input into the Softmax classifier to obtain a malicious encrypted traffic identification result. Result , and get the predicted label = argmax( Result ); If the predicted label is equal to the actual label, calculate ,in, a The value penalizes and rewards the number of samples of the two categories. y The value rewards samples that are difficult to train and updates the model parameters.
2. A malicious encrypted traffic detection system based on data packet characterization learning, the system adopts the method of claim 1, It is characterized in that The system comprises: The first processing module is configured to divide each encrypted traffic Pcap file by using a rich bidirectional flow session as a basic unit of division to obtain a plurality of sessions; The second processing module is configured to select a preset number of packets in the session to represent global traffic; and select several parameters of each packet as detection features; A third processing module is configured to input the detection feature into a deep learning network to obtain a malicious encrypted traffic identification result; The preset value is 30; The parameters of each data packet include: Size: the payload size of the data packet; time: the time interval between the last data packet; dir: the transmission direction of the data packet; ack: the first flag bit of the TCP layer of the data packet; psh: the second flag bit of the TCP layer of the data packet; Inputting the detection features into the deep learning network to obtain malicious encrypted traffic identification results includes: Input the detection feature into the LSTM network to obtain an LSTM output; use the LSTM output as the query, key and value of the multi-head attention mechanism; use different weight matrices to perform multiple linear transformations on the multi-head attention pair query, key and value in parallel to obtain vector attention of different data packets; merge the vector attention of all data packets and output a global feature; After the global features are processed by the fully connected layer, a data packet feature vector is obtained; the data packet feature vector is input into the Softmax classifier to obtain a malicious encrypted traffic identification result.
3. An electronic device, It is characterized in that The electronic device includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the steps in the malicious encrypted traffic detection method based on data packet characterization learning described in claim 1 are implemented.
4. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, the steps in the malicious encrypted traffic detection method based on data packet characterization learning described in claim 1 are implemented.
