An Anonymous Network Traffic Classification Method Based on Small-Sample Machine Learning
By calculating the category center in the feature space and assigning pseudo-labels, the performance degradation of the anonymous network traffic classification algorithm when the data set changes is solved, and the efficient adaptability and accuracy of the model are improved.
Patent Information
- Application Number
- CN202211592847.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-13
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2042-12-13
AI Technical Summary
In the prior art, the performance of anonymous network traffic classification algorithms deteriorates when the data set changes, especially the data scarcity problem caused by the update of the Tor browser version, resulting in insufficient model performance.
Anonymous network traffic classification method based on clustering analysis, by mapping the original collected traffic data with a small amount of newly collected annotated data to the feature space, calculating the category center and assigning pseudo-labels, optimizing the classification loss function to complete knowledge migration, and reducing the impact of data timeliness on the model.
It effectively improves the performance of anonymous network traffic classification, solves the performance degradation caused by the differences in the distribution of training data and test data, and improves the adaptability and accuracy of the model.
Smart Images

Figure CN115913992B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to network security technology, and in particular to an anonymous network traffic classification method based on small sample machine learning. Background Art
[0002] With the development of the internet, a variety of anonymous communication systems have been designed and developed, and corresponding attack methods have also emerged. Website fingerprinting (WF) attacks can effectively undermine the anonymity of the Tor anonymous network. During website loading, traffic sequences between clients and servers exhibit different patterns due to different websites' add-ons and other content, facilitating attackers' ability to undermine anonymity. Deep learning-based anonymous network traffic classification methods significantly outperform non-deep anonymous network traffic classification methods. Deep anonymous network traffic classification requires a large amount of labeled data as a training set. Changes in the dataset, such as the generation of different Tor traffic data from Tor browser updates, can lead to performance degradation in anonymous network traffic classification algorithms.
[0003] Currently, there are two methods to solve the problem of degraded anonymous network traffic classification performance due to the scarcity of labeled traffic data: TF (Triplet Fingerprinting) [1] and TLFA (Transfer Learning Fingerprinting Attack) [2]. However, the TF method has the problem of large computational complexity, and the TLFA method only uses a small amount of newly collected labeled traffic to fine-tune the pre-trained classification model, resulting in insufficient improvement in model classification performance.
[0004] Therefore, in anonymous network traffic classification, the scarcity of labeled data caused by changes in the dataset poses a great challenge to the actual performance and deployment application of the algorithm. Summary of the Invention
[0005] Purpose of the invention: The purpose of the present invention is to solve the deficiencies in the prior art and provide an anonymous network traffic classification method based on small sample machine learning.
[0006] In anonymous network traffic classification, dataset timeliness issues caused by dataset changes pose a significant challenge to the practical deployment and application of algorithms. To address this challenge, this paper proposes an anonymous network traffic classification algorithm based on cluster analysis, based on the clustering assumption that samples belonging to the same cluster belong to the same category. The algorithm maps the original collected traffic data, a small amount of newly collected annotated data, and the data to be classified into a feature space using a deep neural network. The category centers of the newly collected annotated data are calculated in the feature space, and clustering is performed using the category centers as the cluster centers of the target traffic data to be classified. The target traffic data is assigned pseudo-labels, and by optimizing the classification loss function of the original annotated traffic data and the target pseudo-annotated data, the knowledge transfer of the original annotated data is completed, reducing the impact of data timeliness on the model.
[0007] Technical solution: The present invention provides an anonymous network traffic classification method based on small sample machine learning, comprising the following steps:
[0008] Step (1), collect network traffic and obtain the original traffic sequence X s , a small amount of newly collected labeled traffic X′ s And the traffic sequence to be classified X t ;
[0009] Among them, the original traffic sequence X s The data are annotated: n refers to the number of original traffic sequence data, and They represent the records of traffic sequences and their corresponding annotations respectively; a small amount of newly collected annotated traffic is represented as: The traffic sequence to be classified is expressed as: N and m are the number of newly collected labeled samples and the number of data samples to be classified respectively;
[0010] Step (2): Build a classification model
[0011] The feature extractor G and the task classifier C are combined to form a classification model, where the feature extractor G uses a deep convolutional network and the task classifier C includes a two-layer fully connected neural network;
[0012] Step (3), pre-training classification model
[0013] The original traffic sequence X with annotations s The data is input into the above-mentioned deep model (classification model), and the classification loss function is calculated based on the obtained original traffic data category prediction probability and the true label to pre-train the deep classification model constructed in the previous step;
[0014] Step (4): Training the classification model
[0015] Step (4.1) converts the labeled original traffic sequence X s and a small amount of newly collected annotated traffic X′ s Mapping to the feature space through a neural network, calculating the center points of each category of a small number of newly collected annotated traffic sequence features;
[0016] In step (4.2), the obtained category center point is used as the cluster center point of the newly collected traffic sequence features to be classified, and the distance between each traffic sequence feature to be classified and each cluster center point is calculated. The category label of the closest category center is assigned to the traffic sequence feature to be classified, and the category label is used as the pseudo label of the traffic sequence to be classified.
[0017] Step (4.3) maps the features of the feature space through the classifier to obtain the category prediction probability, and calculates the clustering loss function through the pseudo-label and the prediction probability; based on the obtained cluster adaptation loss, the network weights of the feature extractor G and the task classifier C are updated;
[0018] Repeat steps (4.1) to (4.3) multiple times to complete model training; finally, the feature center of the newly collected traffic sequence in the feature space is aligned with the feature center of the original traffic sequence, so that features of the same category are mapped to the same area by the classifier, effectively solving the performance degradation of the deep anonymous network traffic classification algorithm caused by the aging of training data.
[0019] Furthermore, the structures of the feature extractor G and the task classifier C in step (2) are as follows:
[0020] The feature extractor G has three convolution modules, the first convolution module contains two convolution layers, and the last two convolution modules each contain three convolution layers. Each convolution module is followed by a maximum pooling (MaxPooling) and a Dropout layer. The ELU activation function is used in the convolution module. This activation function helps to shorten the training time and improve the accuracy in the neural network. The task classifier C uses a two-layer fully connected neural network, and adds a dropout layer after each layer of the network to help avoid overfitting problems.
[0021] Furthermore, in step (3), when the classification model is used to pre-train the labeled original traffic sequence data, the classification loss function is calculated as follows, which is the same as the conventional supervised deep model training:
[0022]
[0023] where y′ s is the predicted probability output of the classifier for the original traffic data belonging to each category, y s is the true label of the traffic (in one-hot encoding form), represents the cross entropy loss function, which is calculated as follows:
[0024]
[0025] Where p(x) represents the predicted probability that sample x belongs to each category, and q(x) represents the one-hot encoding of the true label of sample x.
[0026] Furthermore, the specific calculation method of the cluster center in step (4.1) is:
[0027] Given a small amount of newly collected traffic sequence data input Assuming that the original traffic sequence data has K categories, there are cluster centers C k for:
[0028]
[0029] Among them, f′ i =G(x′ i ), when y′ i =k, I i =1, otherwise I i =0.n k Represents the number of samples of the original traffic sequence data with label k, k∈{1,2,3,…,K}.
[0030] Furthermore, the calculation method of the pseudo label of the traffic sequence to be classified in step (4.2) is:
[0031] After the newly collected traffic sequence passes through the neural network that maps the original traffic sequence, cosine similarity is used in the feature space to measure the distance between the new traffic sequence features and the cluster center. The distance is calculated as follows:
[0032]
[0033] in
[0034] For each newly collected sample, the distance between it and all cluster centers is calculated. Then, the newly collected traffic sequence is assigned the category of the nearest cluster center. A pseudo-label is assigned to the new traffic sequence within each cluster. The pseudo-label is obtained as follows:
[0035]
[0036] Furthermore, the step (4.3) calculates the cluster adaptation loss and updates the network weights. The specific process is:
[0037] The clustering loss function is calculated as follows:
[0038]
[0039] in For the classifier to collect new traffic sequence The predicted probability output belonging to each category, is the pseudo label obtained by the above formula (5) (one-hot encoding form);
[0040] The overall optimization objective function of the final anonymous network traffic classification algorithm of the present invention is as follows:
[0041] min G,C L=L clu (x s ,y s )+λL clu (x t ) (7)
[0042] Among them, λ is a hyperparameter that balances the classification loss and clustering loss in training.
[0043] Beneficial effects: The present invention maps the originally collected traffic data, small sample labeled data and data to be classified to the feature space through a deep neural network, calculates the category center of the small sample labeled data in the feature space, clusters the target traffic data to be classified using the category center, assigns pseudo labels to the target traffic data, and uses the originally collected labeled traffic data for deep model pre-training. By optimizing the classification loss function of the original labeled traffic data and the target pseudo-labeled data, the knowledge transfer of the original labeled data is completed, and the impact of data failure on the model is reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 It is a schematic diagram of the overall process of the present invention;
[0045] Figure 2 Schematic diagram of the feature extractor in the present invention;
[0046] Figure 3 Schematic diagram of the task classifier in the present invention. DETAILED DESCRIPTION
[0047] The technical solution of the present invention is described in detail below, but the protection scope of the present invention is not limited to the embodiments.
[0048] To address the above challenges, the present invention is based on the clustering assumption: samples belonging to the same cluster in the cluster belong to the same category, and proposes an anonymous network traffic classification method based on small sample machine learning. The algorithm maps the original and newly collected annotated traffic data and the data to be classified to the feature space through a deep neural network, calculates the category center of the newly collected annotated data in the feature space, clusters the target traffic data to be classified with the category center as the cluster center, assigns pseudo-labels to the target traffic data, and completes the knowledge transfer of the original annotated data by optimizing the classification loss function of the original annotated traffic data and the target pseudo-annotated data, thereby reducing the impact of the data on the model performance due to timeliness issues.
[0049] The present invention achieves effective anonymous network traffic classification through the following technical features, solving the problem of performance degradation of anonymous network traffic classification due to differences in the distribution of training data and test data:
[0050] 1. Based on the clustering hypothesis: Samples belonging to the same cluster in the cluster belong to the same category. In the feature space, the cluster center of the target traffic sequence is aligned with the category center of the original labeled data, thereby eliminating the distribution difference problem caused by data timeliness.
[0051] 2. Use a deep network to extract traffic sequence features, align the original labeled data class center and the cluster center of the traffic sequence to be classified in the feature space, and optimize the model in an end-to-end manner
[0052] like Figure 1 As shown, the anonymous network traffic classification method based on small sample machine learning of this embodiment includes the following steps:
[0053] Step (1), collect network traffic and obtain the original traffic sequence X s , a small amount of newly collected labeled traffic X′ and the traffic sequence to be classified X t ;
[0054] Among them, the original traffic sequence X s The data are annotated: n refers to the number of original traffic sequence data, and They represent the records of traffic sequences and their corresponding annotations respectively; a small amount of newly collected annotated traffic is represented as: The traffic sequence to be classified is expressed as: N and m are the number of newly collected labeled samples and the number of samples of data to be classified;
[0055] Use packet capture tools to collect a small amount of new access traffic, convert the captured traffic into a usable format, and label each traffic with the corresponding website;
[0056] Step (2): Build a classification model
[0057] The feature extractor G and the task classifier C are combined to form a classification model, where the feature extractor G uses a deep convolutional network and the task classifier C includes a two-layer fully connected neural network;
[0058] Step (3), pre-training classification model
[0059] The original traffic sequence X with annotations s The data is input into the above classification model, and the classification loss function is calculated based on the obtained original traffic data category prediction probability and the true label to pre-train the deep classification model built in the previous step;
[0060] Step (4): Training the classification model
[0061] Step (4.1) converts the labeled original traffic sequence X s and a small amount of newly collected annotated traffic X′ s Mapping to feature space through a neural network, calculating the category center points of each category of the newly collected annotated sample features;
[0062] In step (4.2), the obtained category center point is used as the cluster center point of the traffic sequence feature to be classified to calculate the distance between each traffic sequence feature to be classified and each cluster center point, and the category label of the closest category center is assigned to the sequence feature to be classified. This label is the pseudo label of the sequence feature to be classified;
[0063] Step (4.3) maps the features of the feature space through the classifier to obtain the category prediction probability, and calculates the clustering loss function through the pseudo-label and the prediction probability; based on the obtained cluster adaptation loss, the network weights of the feature extractor G and the task classifier C are updated;
[0064] Repeat steps (4.1) to (4.3) multiple times to complete model training.
[0065] The above embodiment uses the collected test set to perform performance evaluation on the classification algorithm.
[0066] The detailed process of the algorithm is:
[0067]
[0068] Example:
[0069] This embodiment uses the anonymous communication system Tor as an environment for acquiring traffic. Tor is based on onion routing technology and transmits data packets of anonymous network users through multiple proxy nodes. The source IP, destination IP and information in the data packets are encrypted, so the true source and destination of the data packets cannot be traced, thereby effectively protecting the user's privacy information. In actual application scenarios, due to problems such as the Tor browser version (Tor-browser-bundle, TBB), the settings of the Tor browser, and the timeliness between the newly collected data and the original collected data, there are distribution differences between the original data and the newly collected data. This difference causes the performance of the anonymous network traffic classification model on the original collected traffic sequence data to degrade, making it difficult to meet the needs of actual applications. Re-collecting the labeled data for training the deep anonymous network traffic classification model is time-consuming and labor-intensive. This embodiment solves this problem through the following steps.
[0070] Step (1): Collect network traffic
[0071] Download the source code of the Tor proxy service from Tor's official website https: / / www.torproject.org / download / tor / , upload it to a cloud server and install it. Use a packet capture tool to collect access traffic, simulate the browsing habits of Tor users, and then visit the website. Capture the traffic between the user and the first hop node of the Tor network, convert the captured traffic into a usable format, and label each flow with the corresponding website. We divide the collected traffic data set into a training set and a test set. For the convenience of subsequent experimental description, the original collected traffic sequence data is annotated and represented as A small amount of labeled traffic is divided into the test set and expressed as The remaining traffic in the test set is regarded as the traffic sequence to be classified, which is expressed as
[0072] When collecting traffic data, we categorize visited websites into two types, following industry-wide standards: monitored websites and non-monitored websites. Monitored websites are websites of interest to attackers, while non-monitored websites are websites that users have not visited or are not of interest to attackers. The dataset composition is shown in Table 1.
[0073] Table 1: Tor network traffic dataset
[0074]
[0075] Step (2): Build a classification model
[0076] The feature extractor G and the task classifier C are combined to form a classification model. The model structure of the extractor G is as follows: Figure 2 As shown, the task classifier model structure is as follows Figure 3As shown in the figure, the feature extractor G is composed of a convolutional neural network, and the task classifier C is composed of a two-layer fully connected neural network.
[0077] Step (3), pre-training classification model
[0078] The original traffic sequence data with annotations Input into the above deep model, calculate the classification loss function based on the obtained original traffic data category prediction probability and the true label, and minimize the classification loss function based on the stochastic gradient descent algorithm for the deep classification model constructed in the previous step to complete the model pre-training. The loss value calculation is shown in formula (1):
[0079]
[0080] in represents the cross entropy loss function, which is calculated as follows:
[0081]
[0082] Where p(x) represents the predicted probability that sample x belongs to each category, and q(x) represents the one-hot encoding of the true label of sample x.
[0083] Step (4): Training the classification model
[0084] There will be a new traffic sequence marked By mapping the pre-trained neural network in the previous step to the feature space, the center points of each category of the newly collected traffic sequence features are calculated as shown in the following formula (3):
[0085]
[0086] where f′ i =G(x′ i ), when y′ i =k, I i =1, otherwise I i =0.n k Represents the number of samples of the original traffic sequence data with label k, k∈{1,2,3,…,K}.
[0087] The obtained category center point is used as the cluster center point of the traffic sequence feature to be collected, and the distance from each traffic sequence feature to be classified to each cluster center point is calculated.
[0088]
[0089] For each newly collected sample, the distance between it and all cluster centers is calculated. Then, the newly collected traffic sequence is assigned the category of the nearest cluster center. A pseudo-label is assigned to the new traffic sequence within each cluster. The pseudo-label is obtained as follows:
[0090]
[0091] The features of the feature space are mapped by the classifier to obtain the category prediction probability. The cluster adaptation loss function is calculated by the pseudo label and the prediction probability as shown in the following formula (6):
[0092]
[0093] in For the classifier to collect new traffic sequence The predicted probability output belonging to each category, is the pseudo label obtained by the above formula (5) (one-hot encoding form);
[0094] The overall optimization objective function of the final anonymous network traffic classification algorithm is shown in the following formula (7):
[0095] min G,C L=L clu (x s ,y s )+λL clu (x t ) (7)
[0096] Here, λ is a hyperparameter that balances the classification loss and clustering loss during training. The network weights of the feature extractor G and the task classifier C are updated using the stochastic gradient descent algorithm. This process is repeated multiple times to complete model training.
[0097] Based on the training, validation, and test data sets set in Step 1, we used five-fold cross-validation and grid search to optimize the classifier's hyperparameters and determine the optimal hyperparameters for this classification process. We used the test data to evaluate the classification model's performance and calculated the classification accuracy. The results are shown in Table 2.
[0098] Table 2: Classification results of different models (N-shot represents N newly collected labeled samples, and the evaluation index in the table is classification accuracy (%))
[0099]
[0100] In Table 2, TF[1] refers to "More practical and portable website fingerprinting with n-shot learning" by P. Sirinam et al., and TLFA[2] refers to "Few-shot website fingerprinting attack" by M. Chen et al.
[0101] The above examples show that deep anonymous network traffic classification requires a large amount of labeled training data. Version updates of anonymous network systems such as the Tor browser will reduce the effectiveness of labeled data, thereby causing the performance of current deep anonymous network traffic classification algorithms to decline. The present invention proposes an anonymous network traffic classification algorithm based on cluster analysis. The algorithm is based on the clustering assumption: samples belonging to the same cluster in the cluster belong to the same category. In the feature space, the cluster center of the target traffic sequence is aligned with the category center of the original labeled data, thereby eliminating the distribution difference problem caused by data timeliness and effectively improving the performance of anonymous network traffic classification.
Claims
1. An anonymous network traffic classification method based on small sample machine learning, characterized by: The following steps are involved: Step (1), collect network traffic and obtain the original traffic sequence X s , a small amount of newly collected labeled traffic X′ s And the traffic sequence to be classified X t ; Among them, the original traffic sequence X s The data are annotated: n refers to the number of original traffic sequence data, and They represent the records of traffic sequences and their corresponding annotations respectively; a small amount of newly collected annotated traffic is represented as: The traffic sequence to be classified is expressed as: N is the data of a small number of newly collected labeled samples, and m is the number of data samples to be classified; Step (2): Build a classification model The feature extractor G and the task classifier C are combined to form a classification model, where the feature extractor G uses a deep convolutional network and the task classifier C includes a two-layer fully connected neural network; Step (3), pre-training classification model The original traffic sequence X with annotations s The data is input into the classification model, and the classification loss function is calculated based on the obtained raw traffic data category prediction probability and the true label to pre-train the deep classification model built in the previous step; Step (4): Training the classification model Step (4.1) converts the labeled original traffic sequence X s and a small amount of newly collected annotated traffic X′ s Mapping to the feature space through a neural network, calculating the center points of each category of a small number of newly collected annotated traffic sequence features; In step (4.2), the obtained category center point is used as the cluster center point of the newly collected traffic sequence features to be classified, and the distance between each traffic sequence feature to be classified and each cluster center point is calculated. The category label of the closest category center is assigned to the traffic sequence feature to be classified, and the category label is used as the pseudo label of the traffic sequence to be classified. Step (4.3) maps the features of the feature space through the classifier to obtain the category prediction probability, and calculates the clustering loss function through the pseudo-label and the prediction probability; based on the obtained cluster adaptation loss, the network weights of the feature extractor G and the task classifier C are updated; Repeat steps (4.1) to (4.3) multiple times to complete model training.
2. The anonymous network traffic classification method based on small sample machine learning according to claim 1 is characterized by: The structures of the feature extractor G and the task classifier C in step (2) are as follows: The feature extractor G has three convolution modules, the first convolution module contains two convolution layers, and the last two convolution modules each contain three convolution layers. Each convolution module is followed by a maximum pooling layer and a Dropout layer, and the ELU activation function is used in the convolution module; the task classifier C adopts a two-layer fully connected neural network, and a dropout layer is added after each layer of the network.
3. The anonymous network traffic classification method based on small sample machine learning according to claim 1 is characterized by: When the classification model is used in step (3) to pre-train the labeled original traffic sequence data, the classification loss function is calculated as follows: where y s ′ is the predicted probability of each category of the original traffic data by the classifier, y s is the one-hot encoding of the true label of the traffic, represents the cross entropy loss function, which is calculated as follows: Where p(x) represents the predicted probability that sample x belongs to each category, and q(x) represents the one-hot encoding of the true label of sample x.
4. The anonymous network traffic classification method based on small sample machine learning according to claim 1 is characterized by: The specific calculation method of the cluster center in step (4.1) is: Given a small amount of newly collected traffic sequence data input Assuming that the original traffic sequence data has K categories, there are cluster centers C k for: Among them, f i ′=G(x i ′); when y i When ′=k, I i =1, otherwise I i =0;n k Represents the number of samples of traffic sequence data with label k in the X′ dataset, k∈{1,2,3,…,K}.
5. The anonymous network traffic classification method based on small sample machine learning according to claim 1 is characterized by: The calculation method of the pseudo label of the traffic sequence to be classified in step (4.2) is: In the feature space, cosine similarity is used to measure the distance between the new traffic sequence features and the cluster center. The distance is calculated as follows: in Represents the i-th sample in the data set to be classified; For each newly collected sample, the distance between it and all cluster centers is calculated. Then, the newly collected traffic sequence is assigned the category of the nearest cluster center. A pseudo-label is assigned to the new traffic sequence within each cluster. The pseudo-label is obtained as follows:
6. The anonymous network traffic classification method based on small sample machine learning according to claim 1 is characterized by: The step (4.3) calculates the cluster adaptation loss and updates the network weights. The specific process is: The clustering loss function is calculated as follows: in For the classifier to collect new traffic sequence The category prediction output of is a pseudo label; The final overall optimization objective function is as follows: min G,C L=L clu (x s ,y s )+λL clu (x t ) Among them, λ is the hyperparameter for balancing the classification loss and clustering loss in training, L clu (x t ) represents the clustering loss function of the data to be classified.