A lightweight malicious encrypted traffic detection method based on knowledge distillation
Through a two-stage detection method based on knowledge distillation, combined with a lightweight convolutional neural network, it solves the problems of traditional malicious encrypted traffic detection model complexity and high computing resource usage, and achieves efficient and accurate malicious encrypted traffic detection, which is suitable for mobile device.
Patent Information
- Application Number
- CN202410796259.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-20
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2044-06-20
AI Technical Summary
Traditional malicious encrypted traffic detection models are too large and complex to be effectively deployed on mobile devices, and deep learning models require long training times and high computing resource usage due to complex structures and too many parameters, making them unable to meet the requirements of terminal devices.
Adopting a lightweight malicious encrypted traffic detection method based on knowledge distillation, through two-stage detection: the first stage uses original feature information for rapid filtering, and the second stage uses image feature information for in-depth analysis, combined with a lightweight convolutional neural network, to reduce the model The overall resource consumption of detection is reduced, and detection accuracy is improved through knowledge distillation training.
It greatly improves the efficiency and accuracy of malicious encrypted traffic detection, reduces the computing pressure of deep learning models, adapts to the computing resource limitations of mobile devices, and provides efficient and accurate network security threat analysis.
Smart Images

Figure CN118368150B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of network security situation awareness, and in particular to a lightweight malicious encrypted traffic detection method based on knowledge distillation. Background Art
[0002] With the widespread popularity of mobile device applications, the security issues that come with it have become a challenge that needs to be addressed urgently. Malicious traffic, as an important channel for network attacks and threats, poses a challenge to the cyberspace environment, prompting the need to take strong security monitoring and defense measures.
[0003] The memory and computing resources in many mobile devices are usually limited, making traditional malicious encrypted traffic detection models too large and complex, posing a challenge to their effective deployment on devices. Traditional deep packet inspection techniques have difficulty adapting to the surge in traffic, resulting in a sharp drop in accuracy. In contrast, machine learning-based inspection methods have demonstrated the ability to quickly classify encrypted traffic with minimal overhead. However, the reliance on handcrafted features in machine learning makes it unable to reveal complex relationships in data samples, thereby reducing accuracy. Deep learning has attracted attention for its powerful modeling and automatic learning capabilities. The models utilize convolutional neural networks or long short-term memory network features to effectively solve encryption challenges by only analyzing the size and direction of the initial data packet in a given flow. Despite their commendable performance, these models still have difficulty solving problems related to complex structures and too many parameters. This not only prolongs the model training process, but also fails to meet the stringent computing resource requirements of terminal devices. Therefore, lightweight detection methods are urgently needed to alleviate these challenges. Summary of the invention
[0004] In order to overcome the deficiencies of the above technologies, the present invention provides a lightweight malicious encrypted traffic detection method based on knowledge distillation, which greatly reduces the overall resource consumption of model detection.
[0005] The technical solution adopted by the present invention to overcome the technical problems is:
[0006] A lightweight malicious encrypted traffic detection method based on knowledge distillation includes the following steps:
[0007] (a) Capture the behavior traffic data of encrypted applications and label the behavior traffic data as malicious or benign;
[0008] (b) Split the behavior traffic data into sessions, forming the original dataset , , For the Sessions, ;
[0009] (c) Pursuant to Sessions Use the simple flow model to obtain the final simple flow label and complex flow label ;
[0010] (d) Based on the final simple flow label and complex flow label Get grayscale image ;
[0011] (e) Establish a teacher model to transform the grayscale image Input into the teacher model and output the probability distribution of the category ;
[0012] (f) Establish a student model to transform the grayscale image Input into the student model and output the probability distribution of the category , take the probability distribution The category corresponding to the index value of the maximum value is taken as the final prediction result;
[0013] (g) Through the formula Calculate the total loss , where is the cross entropy loss function, is the probability distribution With probability distribution The KL divergence loss function between , using the Adam optimizer to take advantage of the total loss Train the student model and obtain the optimized student model.
[0014] Further, step (a) comprises the following steps:
[0015] (a-1) Using sandbox technology to run malware operations, each malware operation lasts for more than or equal to M minutes;
[0016] (a-2) Use Wireshark software to synchronously capture packets of malware operations, obtain a file containing behavioral traffic data of the encrypted application in pcap format, and mark the behavioral traffic data as malicious;
[0017] (a-3) Use the Appium tool to simulate a user's benign App application behavior operations, and the operation duration is greater than or equal to M minutes;
[0018] (a-4) Use Wireshark software to synchronously capture packets of benign App application operations, obtain a file in pcap format that contains the behavior traffic data of the encrypted application, and mark the behavior traffic data as benign.
[0019] Preferably, in step (a-1), the value of M is 30.
[0020] Furthermore, in step (a-2), the behavioral traffic data is identified as a distributed denial of service attack or malicious advertising behavior.
[0021] Further, step (b) comprises the following steps:
[0022] (b-1) Use the rdpcap function of Python's Scapy toolkit to read a file in pcap format, read the behavior flow data of the encrypted application from the given pcap file path, and divide the behavior flow data of the encrypted application into Data packets;
[0023] (b-2) Packets Store in a list Among them For the Data packets, ;
[0024] (b-3) The packets with the same source IP address, destination IP address, source port and destination port in the packets constitute a session. ,get Sessions ,in For the Sessions, ;
[0025] (b-4) Sessions The data packets in the session are sorted in chronological order according to their timestamps to obtain the sorted session ;
[0026] (b-5) Use the wrpcap() function of the Python Scapy toolkit to sort the sessions Save as a pcap file and name the pcap file as the session The source IP address + destination IP address corresponding to each data packet in the session .
[0027] Further, step (c) comprises the following steps:
[0028] (c-1) The original data set Middle Sessions Input into CICFlowMeter tool to obtain The format of each stream feature is the raw feature data matrix of the CSV file , , For the The flow characteristics, ;
[0029] (c-2) Construct a simple stream model consisting of twenty decision tree models, and transform the original feature data matrix Input into each decision tree model of the simple stream model respectively, Decision tree model output labels ;
[0030] (c-3) If the labels output by the decision tree model are greater than or equal to 15 If the values of are the same, then the formula Calculate the final simple flow label and complex flow label , where To count the number of labels output by the decision tree model, if there are less than 15 labels output by the decision tree model, If the value of is the same, the final simple flow label and the complex flow label The value of is set to -1.
[0031] Further, step (d) comprises the following steps:
[0032] (d-1) The final simple flow label and the complex flow label The value of -1 corresponds to the session Add to new list middle;
[0033] (d-2) List Middle Sessions Extract the first 784 bytes. If the session length is less than 784 bytes, fill the space less than 784 bytes with 0 to obtain the payload data. ;
[0034] (d-3) Create a 28×28 two-dimensional array and store the payload data in a row-first manner. Fill into a two-dimensional array;
[0035] (d-4) Use the imshow() function of the Matplotlib library to convert the filled two-dimensional array into a grayscale image , ,in is the real number space and 1 is the number of channels.
[0036] Further, step (e) comprises the following steps:
[0037] (e-1) Use the np.array() function of the Python numpy library to convert the grayscale image Expanded to RGB three-channel image , ;
[0038] (e-2) establishing a teacher model consisting of a convolutional layer, a BN layer, a ReLU activation function, a maximum pooling layer, a first residual block, a second residual block, a third residual block, a fourth residual block, a fifth residual block, a sixth residual block, a seventh residual block, an eighth residual block, a ninth residual block, a tenth residual block, an eleventh residual block, a twelfth residual block, a thirteenth residual block, a fourteenth residual block, a fifteenth residual block, a sixteenth residual block, a seventeenth residual block, an eighteenth residual block, a nineteenth residual block, a twentieth residual block, a global pooling layer, and a fully connected layer, wherein all residual blocks are composed of a first layer, a second layer, and a third layer, and the first layer, the second layer, and the third layer are all composed of a convolutional layer, a BN layer, and a ReLU activation function;
[0039] (e-3) Image Input into the convolution layer of the teacher model and output the feature map , ;
[0040] (e-4) The feature map Input into the BN layer of the teacher model and output the feature map ;
[0041] (e-5) The feature map Input into the ReLU activation function of the teacher model and output the feature map ;
[0042] (e-6) The feature map Input to the maximum pooling layer of the teacher model and output the feature map , ;
[0043] (e-7) The feature map Input into the convolutional layer of the first layer of the first residual block of the teacher model, and output the feature map , the feature map Input into the BN layer of the first layer of the first residual block, and output the feature map , the feature map Input to the ReLU activation function of the first layer of the first residual block, and output the feature map ;
[0044] (e-8) The feature map Input to the convolutional layer of the second layer of the first residual block of the teacher model, and output the feature map , the feature map Input to the BN layer of the second layer of the first residual block, and output the feature map , the feature map Input to the ReLU activation function of the second layer of the first residual block, and output the feature map ;
[0045] (e-9) The feature map Input to the third convolutional layer of the first residual block of the teacher model, and output the feature map , the feature map Input to the BN layer of the third layer of the first residual block, and output the feature map , the feature map With feature map After the residual connection, it is input into the ReLU activation function of the third layer of the first residual block, and the feature map is output. , ;
[0046] (e-10) The feature map Replace the feature map in step (e-7) , repeat steps (e-7) to (e-9) to obtain the feature map output by the second residual block , ;
[0047] (e-11) Repeat step (e-9) 18 times to obtain the feature map output by the twentieth residual block , ;
[0048] (e-12) The feature map Input into the global pooling layer of the teacher model and output the feature map , ;
[0049] (e-13) The feature map After being input into the fully connected layer of the teacher model, it is input into the softmax function and the probability distribution of the category is obtained as the output. .
[0050] Further, step (f) comprises the following steps:
[0051] (f-1) Establish a student model consisting of the first convolutional layer, the first ReLU activation function, the first residual block, the second residual block, the third residual block, the fourth residual block, the fifth residual block, the sixth residual block, the seventh residual block, the eighth residual block, the ninth residual block, the second convolutional layer, the second ReLU activation function, the maximum pooling layer, the third convolutional layer, the third ReLU activation function, the fourth convolutional layer, the fourth ReLU activation function, the global pooling layer, and the fully connected layer. All residual blocks are composed of the first layer, the second layer, and the third layer. The first layer is composed of a convolutional layer, a BN layer, and a ReLU activation function, and the third layer is composed of a convolutional layer and a ReLU activation function;
[0052] (f-2) Image Input into the first convolutional layer of the student model and output the feature map , ;
[0053] (f-3) The feature map Input into the first ReLU activation function of the student model, and output the feature map ;
[0054] (f-4) The feature map Input into the first layer of the first residual block of the student model, and output the feature map ;
[0055] (f-5) The feature map Input to the convolutional layer of the second layer of the first residual block of the student model, and output the feature map , the feature map Input into the second layer of BN layer, and output the feature map , the feature map Input into the ReLU activation function of the second layer, and output the feature map ;
[0056] (f-6) The feature map Input to the third convolutional layer of the first residual block of the student model, and output the feature map , the feature map With feature map Perform addition operation to obtain feature map , the feature map Input into the ReLU activation function of the third layer, and output the feature map , ;
[0057] (f-7) The feature map Replace the feature map in step (f-4) , repeat steps (f-4) to (f-6) to obtain the feature map output by the second residual block , ;
[0058] (f-8) Repeat step (f-8) 7 times to obtain the feature map output by the ninth residual block ;
[0059] (f-9) The feature map Input into the second convolutional layer of the student model and output the feature map ;
[0060] (f-10) The feature map Input into the second ReLU activation function of the student model, and output the feature map , ;
[0061] (f-11) The feature map Input into the maximum pooling layer of the student model, output, get the feature map , ;
[0062] (f-12) The feature map Input into the third convolutional layer of the student model and output the feature map ;
[0063] (f-13) The feature map Input into the third ReLU activation function of the student model, and output the feature map , ;
[0064] (f-14) The feature map Input into the fourth convolutional layer of the student model and output the feature map ;
[0065] (f-15) The feature map Input to the fourth ReLU activation function of the student model, and output the feature map ;
[0066] (f-16) The feature map Input to the global pooling layer of the student model and output the feature map ;
[0067] (f-17) The feature map After being input into the fully connected layer of the student model, it is input into the softmax function, and the probability distribution of the category .
[0068] Furthermore, in step (e-1), the convolution kernel size of the convolution layer of the teacher model is 7×7, the step size is 2, and the padding is 3. The step size of the maximum pooling layer of the teacher model is 2 and the padding is 1. The convolution kernel size of the first layer of the convolution layer of all the residual blocks of the teacher model is 1×1, the step size is 1, and the number of channels is 64. The convolution kernel size of the second layer of the convolution layer of all the residual blocks of the teacher model is 3×3, the step size is 1, and the number of channels is 64. The convolution kernel size of the third layer of the convolution layer of all the residual blocks of the teacher model is 1×1, the step size is 1, and the number of channels is 256. In step (f-1), the convolution kernel size of the first layer of the convolution layer of all the residual blocks of the student model is 1×1, the step size is 1, and the number of channels is 32. The convolution kernel size of the second convolution layer of the block is 3×3, the stride is 1, and the number of channels is 32. The convolution kernel size of the third convolution layer of all residual blocks is 1×1, the stride is 1, and the number of channels is 16. In step (f-2), the convolution kernel size of the first convolution layer of the student model is 3×3, the stride is 2, and the padding is 2. In step (f-9), the convolution kernel size of the second convolution layer of the student model is 1×1, the stride is 1, and the padding is 1. In step (f-11), the convolution kernel size of the maximum pooling layer of the student model is 7×7, the stride is 1. In step (f-12), the convolution kernel size of the third convolution layer of the student model is 1×1, the stride is 1, and the convolution kernel size of the fourth convolution layer of the student model in step (f-3) is 1×1, the stride is 1.
[0069] The beneficial effects of the present invention are as follows: In the first stage, the original feature information of the traffic is used for rapid filtering, which reduces the computational pressure of the subsequent deep learning model. Subsequently, in the second stage, we further use the image feature information of the traffic and use a lightweight convolutional neural network (CNN) to more comprehensively analyze the content characteristics of the flow. The two-stage method greatly improves the detection efficiency of malicious encrypted traffic. Secondly, the training strategy of knowledge distillation is used to further improve the system's detection accuracy of malicious encrypted traffic. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] Figure 1 Flow chart of the method of the present invention
[0071] Figure 2 It is a structural schematic diagram of the malicious encrypted traffic detection mode of the present invention. DETAILED DESCRIPTION
[0072] The following is combined with Figure 1 , Attachment Figure 2 The present invention is further described.
[0073] A lightweight malicious encrypted traffic detection method based on knowledge distillation is proposed. Based on the different levels of difficulty in identifying encrypted traffic, a two-stage classification framework for malicious encrypted traffic detection is developed from the perspectives of traditional traffic features and image data features, which greatly reduces the overall resource consumption of model detection. The specific steps include the following:
[0074] (a) Capture the behavioral traffic data of encrypted applications and label the behavioral traffic data as malicious or benign.
[0075] (b) Split the behavior traffic data into sessions, forming the original dataset , , For the Sessions, .
[0076] (c) Pursuant to Sessions Use the simple flow model to obtain the final simple flow label and complex flow label .
[0077] (d) Based on the final simple flow label and complex flow label Get grayscale image .
[0078] (e) Establish a teacher model to transform the grayscale image Input into the teacher model and output the probability distribution of the category .
[0079] (f) Establish a student model to transform the grayscale image Input into the student model and output the probability distribution of the category , take the probability distribution The category corresponding to the index value of the maximum value is taken as the final prediction result.
[0080] (g) Through the formula Calculate the total loss , where is the cross entropy loss function, is the probability distribution With probability distribution The KL divergence loss function between , using the Adam optimizer to take advantage of the total loss Train the student model and obtain the student model after distillation training (optimization).
[0081] In the field of network security, it is crucial to efficiently and accurately identify and mitigate the potential threats of malicious encrypted traffic. With the development of deep learning, methods that rely on convolutional neural networks (CNNs) to convert traffic payloads into visual representations for analysis have become popular. Although this technology can effectively identify malicious encrypted traffic, it faces inherent limitations, such as deployment difficulties due to the wide network scale and high computing requirements, especially in edge computing environments. To address these challenges, this method analyzes various encrypted traffic data collected on the network, divides network flows into simple flows and complex flows based on the difficulty of identification, and establishes a lightweight two-stage malicious encrypted traffic detection model to detect malicious encrypted traffic in stages. At the same time, a training strategy based on knowledge distillation is adopted for the model, which reduces the computing resource usage and further improves the accuracy of model detection, effectively protecting the security of related network systems and users. Through deep learning technology, lightweight detection of malicious encrypted traffic is achieved, and the analysis efficiency and accuracy are further improved. The proposed system can solve the practical challenges brought by malicious encrypted traffic and provide security experts with a comprehensive and intuitive network security threat analysis tool.
[0082] In one embodiment of the present invention, step (a) comprises the following steps:
[0083] (a-1) Use sandbox technology to run malware operations (mainly focusing on exe file types, this sandbox environment can simulate the real computer environment), and each malware operation lasts for more than or equal to M minutes.
[0084] (a-2) Use Wireshark software to synchronously capture packets of malware operations, obtain a file in pcap format containing behavioral traffic data of an encrypted application, and mark the behavioral traffic data as malicious.
[0085] (a-3) Use the Appium tool to simulate a user performing benign App application behavior operations, with the operation duration being greater than or equal to M minutes.
[0086] (a-4) Use Wireshark software to synchronously capture packets of benign App application operations, obtain a file in pcap format that contains the behavior traffic data of the encrypted application, and mark the behavior traffic data as benign.
[0087] In this embodiment, the value of M in step (a-1) is 30.
[0088] In this embodiment, in step (a-2), the behavioral traffic data is identified as a distributed denial of service attack or malicious advertising behavior.
[0089] In one embodiment of the present invention, step (b) comprises the following steps:
[0090] (b-1) Use the rdpcap function of Python's Scapy toolkit to read a file in pcap format, read the behavior flow data of the encrypted application from the given pcap file path, and divide the behavior flow data of the encrypted application into The rdpcap function loads all packets in the PCAP file and stores them in a list L for subsequent processing.
[0091] (b-2) Packets Store in a list Among them For the Data packets, .
[0092] (b-3) The packets with the same source IP address, destination IP address, source port and destination port in the packets constitute a session. ,get Sessions ,in For the Sessions, .
[0093] (b-4) Sessions The data packets in the session are sorted in chronological order according to their timestamps to obtain the sorted session , ensuring that the packets are in chronological order.
[0094] (b-5) Use the wrpcap() function of the Python Scapy toolkit to sort the sessions Save as a pcap file and name the pcap file as the session The source IP address + destination IP address corresponding to each data packet in the session .
[0095] In one embodiment of the present invention, step (c) comprises the following steps:
[0096] (c-1) The original data set Middle Sessions Input into CICFlowMeter tool to obtain The format of each stream feature is the raw feature data matrix of the CSV file , , For the The flow characteristics, .
[0097] (c-2) Construct a simple stream model consisting of twenty decision tree models, and transform the original feature data matrix Input into each decision tree model of the simple stream model respectively, Decision tree model output labels .
[0098] (c-3) If the labels output by the decision tree model are greater than or equal to 15 The value of is the same, indicating that this flow can be correctly classified and filtered out in the first stage, then the formula Calculate the final simple flow label and complex flow label , where To count the number of labels output by the decision tree model, if there are less than 15 labels output by the decision tree model, The value of is the same, this flow is considered a complex flow, and the final simple flow label and the complex flow label are The value of is set to -1.
[0099] In one embodiment of the present invention, step (d) comprises the following steps:
[0100] (d-1) The final simple flow label and the complex flow label The value of -1 corresponds to the session Add to new list middle.
[0101] (d-2) List Middle Sessions Extract the first 784 bytes, that is, the payload length exceeds 784 bytes, we truncate the session, if the session length is less than 784 bytes, fill the position less than 784 bytes with 0 to get the payload data .
[0102] (d-3) Create a 28×28 two-dimensional array and store the payload data in a row-first manner. Fill into a 2D array.
[0103] (d-4) Use the imshow() function of the Matplotlib library to convert the filled two-dimensional array into a grayscale image , ,in is the real number space and 1 is the number of channels.
[0104] In one embodiment of the present invention, step (e) comprises the following steps:
[0105] (e-1) Use the np.array() function of the Python numpy library to convert the grayscale image Expanded to RGB three-channel image , .
[0106] (e-2) Establish a teacher model consisting of a convolutional layer, a BN layer, a ReLU activation function, a maximum pooling layer, a first residual block, a second residual block, a third residual block, a fourth residual block, a fifth residual block, a sixth residual block, a seventh residual block, an eighth residual block, a ninth residual block, a tenth residual block, an eleventh residual block, a twelfth residual block, a thirteenth residual block, a fourteenth residual block, a fifteenth residual block, a sixteenth residual block, a seventeenth residual block, an eighteenth residual block, a nineteenth residual block, a twentieth residual block, a global pooling layer, and a fully connected layer. All residual blocks are composed of the first layer, the second layer, and the third layer, and the first layer, the second layer, and the third layer are all composed of a convolutional layer, a BN layer, and a ReLU activation function.
[0107] (e-3) Image Input into the convolution layer of the teacher model and output the feature map , .
[0108] (e-4) The feature map Input into the BN layer of the teacher model and output the feature map .
[0109] (e-5) The feature map Input into the ReLU activation function of the teacher model and output the feature map .
[0110] (e-6) The feature map Input to the maximum pooling layer of the teacher model and output the feature map , .
[0111] (e-7) The feature map Input into the convolutional layer of the first layer of the first residual block of the teacher model, and output the feature map , the feature map Input into the BN layer of the first layer of the first residual block, and output the feature map , the feature map Input to the ReLU activation function of the first layer of the first residual block, and output the feature map .
[0112] (e-8) The feature map Input to the convolutional layer of the second layer of the first residual block of the teacher model, and output the feature map , the feature map Input to the BN layer of the second layer of the first residual block, and output the feature map , the feature map Input to the ReLU activation function of the second layer of the first residual block, and output the feature map .
[0113] (e-9) The feature map Input to the third convolutional layer of the first residual block of the teacher model, and output the feature map , the feature map Input to the BN layer of the third layer of the first residual block, and output the feature map , the feature map With feature map After the residual connection, it is input into the ReLU activation function of the third layer of the first residual block, and the feature map is output. , .
[0114] (e-10) The feature map Replace the feature map in step (e-7) , repeat steps (e-7) to (e-9) to obtain the feature map output by the second residual block , .
[0115] (e-11) Repeat step (e-9) 18 times to obtain the feature map output by the twentieth residual block , .
[0116] (e-12) The feature map Input into the global pooling layer of the teacher model and output the feature map , .
[0117] (e-13) The feature map The fully connected layer input to the teacher model maps the input size to two categories: malicious and benign. Then it is input to the softmax function and the output is the probability distribution of the category. .
[0118] In one embodiment of the present invention, step (f) comprises the following steps:
[0119] (f-1) Establish a student model consisting of the first convolutional layer, the first ReLU activation function, the first residual block, the second residual block, the third residual block, the fourth residual block, the fifth residual block, the sixth residual block, the seventh residual block, the eighth residual block, the ninth residual block, the second convolutional layer, the second ReLU activation function, the maximum pooling layer, the third convolutional layer, the third ReLU activation function, the fourth convolutional layer, the fourth ReLU activation function, the global pooling layer, and the fully connected layer. All residual blocks are composed of the first layer, the second layer, and the third layer. The first layer is composed of the convolutional layer, the second layer is composed of the convolutional layer, the BN layer, and the ReLU activation function, and the third layer is composed of the convolutional layer and the ReLU activation function.
[0120] (f-2) Image Input into the first convolutional layer of the student model and output the feature map , .
[0121] (f-3) The feature map Input into the first ReLU activation function of the student model, and output the feature map .
[0122] (f-4) The feature map Input into the first layer of the first residual block of the student model, and output the feature map .
[0123] (f-5) The feature map Input to the convolutional layer of the second layer of the first residual block of the student model, and output the feature map , the feature map Input into the second layer of BN layer, and output the feature map , the feature map Input into the ReLU activation function of the second layer, and output the feature map .
[0124] (f-6) The feature map Input to the third convolutional layer of the first residual block of the student model, and output the feature map , the feature map With feature map Perform addition operation to obtain feature map , the feature map Input into the ReLU activation function of the third layer, and output the feature map , .
[0125] (f-7) The feature map Replace the feature map in step (f-4) , repeat steps (f-4) to (f-6) to obtain the feature map output by the second residual block , .
[0126] (f-8) Repeat step (f-8) 7 times to obtain the feature map output by the ninth residual block .
[0127] (f-9) The feature map Input into the second convolutional layer of the student model and output the feature map .
[0128] (f-10) The feature map Input into the second ReLU activation function of the student model, and output the feature map , .
[0129] (f-11) The feature map Input into the maximum pooling layer of the student model, output, get the feature map , .
[0130] (f-12) The feature map Input into the third convolutional layer of the student model and output the feature map .
[0131] (f-13) The feature map Input into the third ReLU activation function of the student model, and output the feature map , .
[0132] (f-14) The feature map Input into the fourth convolutional layer of the student model and output the feature map .
[0133] (f-15) The feature map Input to the fourth ReLU activation function of the student model, and output the feature map .
[0134] (f-16) The feature map Input to the global pooling layer of the student model and output the feature map .
[0135] (f-17) The feature map The fully connected layer input to the student model maps the input size to two categories: malicious and benign, and then inputs it to the softmax function to obtain the probability distribution of the categories. .
[0136] Further preferably, in step (e-1), the convolution kernel size of the convolution layer of the teacher model is 7×7, the step size is 2, and the padding is 3; the step size of the maximum pooling layer of the teacher model is 2, and the padding is 1; the convolution kernel size of the first layer of the convolution layer of all residual blocks of the teacher model is 1×1, the step size is 1, and the number of channels is 64; the convolution kernel size of the second layer of the convolution layer of all residual blocks of the teacher model is 3×3, the step size is 1, and the number of channels is 64; the convolution kernel size of the third layer of the convolution layer of all residual blocks of the teacher model is 1×1, the step size is 1, and the number of channels is 256; in step (f-1), the convolution kernel size of the first layer of the convolution layer of all residual blocks of the student model is 1×1, the step size is 1, and the number of channels is 32; all The convolution kernel size of the second convolution layer of the residual block is 3×3, the stride is 1, and the number of channels is 32. The convolution kernel size of the third convolution layer of all residual blocks is 1×1, the stride is 1, and the number of channels is 16. In step (f-2), the convolution kernel size of the first convolution layer of the student model is 3×3, the stride is 2, and the padding is 2. In step (f-9), the convolution kernel size of the second convolution layer of the student model is 1×1, the stride is 1, and the padding is 1. In step (f-11), the convolution kernel size of the maximum pooling layer of the student model is 7×7, and the stride is 1. In step (f-12), the convolution kernel size of the third convolution layer of the student model is 1×1, the stride is 1, and the convolution kernel size of the fourth convolution layer of the student model in step (f-3) is 1×1, and the stride is 1.
[0137] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A lightweight malicious encrypted traffic detection method based on knowledge distillation, characterized in that: The steps include: (a) Capture the behavior traffic data of encrypted applications and label the behavior traffic data as malicious or benign; (b) Split the behavior traffic data into sessions, forming the original dataset , , For the Sessions, ; (c) Pursuant to Sessions Use the simple flow model to obtain the final simple flow label and complex flow label ; (d) Based on the final simple flow label and complex flow label Get grayscale image ; (e) Establish a teacher model to transform the grayscale image Input into the teacher model and output the probability distribution of the category ; (f) Establish a student model to transform the grayscale image Input into the student model and output the probability distribution of the category , take the probability distribution The category corresponding to the index value of the maximum value is taken as the final prediction result; (g) Through the formula Calculate the total loss , where is the cross entropy loss function, is the probability distribution With probability distribution The KL divergence loss function between , using the Adam optimizer to take advantage of the total loss Train the student model and obtain the optimized student model.
2. According to claim 1, the lightweight malicious encrypted traffic detection method based on knowledge distillation is characterized in that: Step (a) comprises the following steps: (a-1) Using sandbox technology to run malware operations, each malware operation lasts for more than or equal to M minutes; (a-2) Use Wireshark software to synchronously capture packets of malware operations, obtain a file containing behavioral traffic data of the encrypted application in pcap format, and mark the behavioral traffic data as malicious; (a-3) Use the Appium tool to simulate a user's benign App application behavior operations, and the operation duration is greater than or equal to M minutes; (a-4) Use Wireshark software to synchronously capture packets of benign App application operations, obtain a file in pcap format containing the behavior traffic data of the encrypted application, and mark the behavior traffic data as benign.
3. According to claim 2, the lightweight malicious encrypted traffic detection method based on knowledge distillation is characterized in that: In step (a-1), the value of M is 30.
4. According to claim 2, the lightweight malicious encrypted traffic detection method based on knowledge distillation is characterized in that: In step (a-2), the behavioral traffic data is identified as a distributed denial of service attack or malicious advertising behavior.
5. The lightweight malicious encrypted traffic detection method based on knowledge distillation according to claim 2 is characterized in that: Step (b) comprises the following steps: (b-1) Use the rdpcap function of Python's Scapy toolkit to read a file in pcap format, read the behavior traffic data of the encrypted application from the given pcap file path, and divide the behavior traffic data of the encrypted application into Data packets; (b-2) Packets Store in a list Among them For the Data packets, ; (b-3) The packets with the same source IP address, destination IP address, source port and destination port in the packets constitute a session. ,get Sessions ,in For the Sessions, ; (b-4) Sessions The data packets in the session are sorted in chronological order according to their timestamps to obtain the sorted session ; (b-5) Use the wrpcap() function of the Python Scapy toolkit to sort the sessions Save as a pcap file and name the pcap file as the session The source IP address + destination IP address corresponding to each data packet in the session .
6. The lightweight malicious encrypted traffic detection method based on knowledge distillation according to claim 1 is characterized in that: Step (c) comprises the following steps: (c-1) The original data set Middle Sessions Input into CICFlowMeter tool to obtain The format of each stream feature is the raw feature data matrix of the CSV file , , For the The flow characteristics, ; (c-2) Construct a simple stream model consisting of twenty decision tree models, and transform the original feature data matrix Input into each decision tree model of the simple stream model respectively, Decision tree model output labels ; (c-3) If the labels output by the decision tree model are greater than or equal to 15 If the values of are the same, then the formula Calculate the final simple flow label and complex flow label , where To count the number of labels output by the decision tree model, if there are less than 15 labels output by the decision tree model, If the value of is the same, the final simple flow label and the complex flow label The value of is set to -1.
7. The lightweight malicious encrypted traffic detection method based on knowledge distillation according to claim 1 is characterized in that: Step (d) comprises the following steps: (d-1) The final simple flow label and the complex flow label The value of -1 corresponds to the session Add to new list middle; (d-2) List Middle Sessions Extract the first 784 bytes. If the session length is less than 784 bytes, fill the space less than 784 bytes with 0 to obtain the payload data. ; (d-3) Create a 28×28 two-dimensional array and store the payload data in a row-first manner. Fill into a two-dimensional array; (d-4) Use the imshow() function of the Matplotlib library to convert the filled two-dimensional array into a grayscale image , ,in is the real number space and 1 is the number of channels.
8. The lightweight malicious encrypted traffic detection method based on knowledge distillation according to claim 1 is characterized in that: Step (e) comprises the following steps: (e-1) Use the np.array() function of the Python numpy library to convert the grayscale image Expanded to RGB three-channel image , ; (e-2) establishing a teacher model consisting of a convolutional layer, a BN layer, a ReLU activation function, a maximum pooling layer, a first residual block, a second residual block, a third residual block, a fourth residual block, a fifth residual block, a sixth residual block, a seventh residual block, an eighth residual block, a ninth residual block, a tenth residual block, an eleventh residual block, a twelfth residual block, a thirteenth residual block, a fourteenth residual block, a fifteenth residual block, a sixteenth residual block, a seventeenth residual block, an eighteenth residual block, a nineteenth residual block, a twentieth residual block, a global pooling layer, and a fully connected layer, wherein all residual blocks are composed of a first layer, a second layer, and a third layer, and the first layer, the second layer, and the third layer are all composed of a convolutional layer, a BN layer, and a ReLU activation function; (e-3) Image Input into the convolution layer of the teacher model and output the feature map , ; (e-4) The feature map Input into the BN layer of the teacher model and output the feature map ; (e-5) The feature map Input into the ReLU activation function of the teacher model and output the feature map ; (e-6) The feature map Input to the maximum pooling layer of the teacher model and output the feature map , ; (e-7) The feature map Input into the convolutional layer of the first layer of the first residual block of the teacher model, and output the feature map , the feature map Input into the BN layer of the first layer of the first residual block, and output the feature map , the feature map Input to the ReLU activation function of the first layer of the first residual block, and output the feature map ; (e-8) The feature map Input to the convolutional layer of the second layer of the first residual block of the teacher model, and output the feature map , the feature map Input to the BN layer of the second layer of the first residual block, and output the feature map , the feature map Input to the ReLU activation function of the second layer of the first residual block, and output the feature map ; (e-9) The feature map Input to the third convolutional layer of the first residual block of the teacher model, and output the feature map , the feature map Input to the BN layer of the third layer of the first residual block, and output the feature map , the feature map With feature map After the residual connection, it is input into the ReLU activation function of the third layer of the first residual block, and the feature map is output. , ; (e-10) The feature map Replace the feature map in step (e-7) , repeat steps (e-7) to (e-9) to obtain the feature map output by the second residual block , ; (e-11) Repeat step (e-9) 18 times to obtain the feature map output by the twentieth residual block , ; (e-12) The feature map Input into the global pooling layer of the teacher model and output the feature map , ; (e-13) The feature map After being input into the fully connected layer of the teacher model, it is input into the softmax function and the probability distribution of the category is obtained as the output. .
9. The lightweight malicious encrypted traffic detection method based on knowledge distillation according to claim 8 is characterized in that: Step (f) comprises the following steps: (f-1) Establish a student model consisting of the first convolutional layer, the first ReLU activation function, the first residual block, the second residual block, the third residual block, the fourth residual block, the fifth residual block, the sixth residual block, the seventh residual block, the eighth residual block, the ninth residual block, the second convolutional layer, the second ReLU activation function, the maximum pooling layer, the third convolutional layer, the third ReLU activation function, the fourth convolutional layer, the fourth ReLU activation function, the global pooling layer, and the fully connected layer. All residual blocks are composed of the first layer, the second layer, and the third layer. The first layer is composed of a convolutional layer, a BN layer, and a ReLU activation function, and the third layer is composed of a convolutional layer and a ReLU activation function; (f-2) Image Input into the first convolutional layer of the student model and output the feature map , ; (f-3) The feature map Input into the first ReLU activation function of the student model, and output the feature map ; (f-4) The feature map Input into the first layer of the first residual block of the student model, and output the feature map ; (f-5) The feature map Input to the convolutional layer of the second layer of the first residual block of the student model, and output the feature map , the feature map Input into the second layer of BN layer, and output the feature map , the feature map Input into the ReLU activation function of the second layer, and output the feature map ; (f-6) The feature map Input to the third convolutional layer of the first residual block of the student model, and output the feature map , the feature map With feature map Perform addition operation to obtain feature map , the feature map Input into the ReLU activation function of the third layer, and output the feature map , ; (f-7) The feature map Replace the feature map in step (f-4) , repeat steps (f-4) to (f-6) to obtain the feature map output by the second residual block , ; (f-8) Repeat step (f-8) 7 times to obtain the feature map output by the ninth residual block ; (f-9) The feature map Input into the second convolutional layer of the student model and output the feature map ; (f-10) The feature map Input into the second ReLU activation function of the student model, and output the feature map , ; (f-11) The feature map Input into the maximum pooling layer of the student model, output, get the feature map , ; (f-12) The feature map Input into the third convolutional layer of the student model and output the feature map ; (f-13) The feature map Input into the third ReLU activation function of the student model, and output the feature map , ; (f-14) The feature map Input into the fourth convolutional layer of the student model and output the feature map ; (f-15) The feature map Input to the fourth ReLU activation function of the student model, and output the feature map ; (f-16) The feature map Input to the global pooling layer of the student model and output the feature map ; (f-17) The feature map After being input into the fully connected layer of the student model, it is input into the softmax function, and the probability distribution of the category .
10. The lightweight malicious encrypted traffic detection method based on knowledge distillation according to claim 9 is characterized in that: In step (e-1), the convolution kernel size of the convolution layer of the teacher model is 7×7, the step size is 2, and the padding is 3. The step size of the maximum pooling layer of the teacher model is 2 and the padding is 1. The convolution kernel size of the first layer of the convolution layer of all residual blocks of the teacher model is 1×1, the step size is 1, and the number of channels is 64. The convolution kernel size of the second layer of the convolution layer of all residual blocks of the teacher model is 3×3, the step size is 1, and the number of channels is 64. The convolution kernel size of the third layer of the convolution layer of all residual blocks of the teacher model is 1×1, the step size is 1, and the number of channels is 256. In step (f-1), the convolution kernel size of the first layer of the convolution layer of all residual blocks of the student model is 1×1, the step size is 1, and the number of channels is 32. The convolution kernel size of the second convolution layer is 3×3, the stride is 1, and the number of channels is 32. The convolution kernel size of the third convolution layer of all residual blocks is 1×1, the stride is 1, and the number of channels is 16. In step (f-2), the convolution kernel size of the first convolution layer of the student model is 3×3, the stride is 2, and the padding is 2. In step (f-9), the convolution kernel size of the second convolution layer of the student model is 1×1, the stride is 1, and the padding is 1. In step (f-11), the convolution kernel size of the maximum pooling layer of the student model is 7×7, and the stride is 1. In step (f-12), the convolution kernel size of the third convolution layer of the student model is 1×1, the stride is 1, and the convolution kernel size of the fourth convolution layer of the student model in step (f-3) is 1×1, and the stride is 1.
