A flow correlation attack method based on patching and contrast learning

By employing time-based patching and contrastive learning methods, Tor and Exit flows are segmented into patches of equal length. Feature embedding networks and cosine similarity are used to evaluate flow correlation, solving the problems of high computational complexity and inconsistent feature extraction in existing technologies, and achieving efficient and accurate flow correlation attacks.

CN118842641BActive Publication Date: 2026-05-01UNIV OF ELECTRONICS SCI & TECH OF CHINA
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
UNIV OF ELECTRONICS SCI & TECH OF CHINA
Filing Date
2024-08-02
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

Existing deep learning-based flow association attack methods face challenges in terms of inconsistent computational cost and feature extraction time. In particular, DeepCorr and DeepCoFFEA methods require pairwise analysis during flow association, resulting in high computational costs and false positive rates.

Method used

We employ time-based patching to segment Tor and Exit streams into patches of equal duration. We train the feature embedding network using a patch-based feature embedding network and contrastive learning, and evaluate stream relevance using cosine similarity, which simplifies computational complexity and improves accuracy.

Benefits of technology

By combining patching and contrastive learning, the computational complexity of flow association attacks is reduced, the accuracy and robustness of flow association attacks are improved, the problem of inconsistent flow embedding time is solved, and efficient flow association attacks are achieved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118842641B_ABST
    Figure CN118842641B_ABST
Patent Text Reader

Abstract

The application relates to the field of traffic analysis, and provides a flow correlation attack method based on patching and contrast learning. The main technical problem to be solved is that the flow embedding time is inconsistent, the calculation cost is high, and the accuracy is low in the existing flow correlation attack method. The main technical scheme comprises the following steps: using time-based patching to divide Tor flows and exit flows into patches with the same time length, wherein the Tor flows and the exit flows represent the traffic entering and exiting the Tor network respectively; using a patch-based feature embedding network to obtain flow embedding; using contrast learning to train the feature embedding network, so that the model can effectively learn flow embedding; and using cosine similarity as an index to evaluate flow correlation and perform flow correlation attack. The application is used in the field of traffic analysis, especially in traffic correlation analysis in anonymous communication systems such as the Tor network, and can improve the accuracy and efficiency of the attack and reduce the calculation cost.
Need to check novelty before this filing date? Find Prior Art

Description

A Stream Association Attack Method Based on Patching and Contrastive Learning Technical Field

[0001] This invention belongs to the field of traffic analysis, specifically relating to a flow association attack method based on patching and contrastive learning. Background Technology

[0002] Flow correlation is a traffic analysis technique that allows attackers to match incoming (Tor flow) and outgoing (exit flow) traffic in the Tor network by monitoring and comparing the traffic characteristics between different nodes in the Tor network, potentially leading to the deanonymization of IP addresses of communication endpoints. Previous flow correlation attacks primarily utilized standard statistical correlation metrics, including mutual information, Pearson correlation, cosine similarity, and Spearman rank correlation, to correlate characteristics between flows.

[0003] With the advancement of deep learning, researchers have begun exploring flow association attacks based on deep learning. Nasr et al. proposed DeepCorr, a flow association attack based on deep neural networks (DNNs). DeepCorr utilizes convolutional neural networks (CNNs) to implement flow association functions specific to Tor networks, achieving an accuracy of 96% for short-length flows. However, since DeepCorr requires pairwise analysis of flows to determine their correlations during flow association attacks, this approach necessitates evaluating n... 2 For individual stream pairs, computational costs are high. Oh et al. proposed an improved stream association attack, DeepCoFFEA, which uses deep learning to train a feature embedding network to map Tor and Exit streams into a low-dimensional space for comparison, thereby reducing computational costs. Furthermore, this method reduces false positives to some extent by segmenting the flow into multiple time windows and employing a voting mechanism. However, the voting mechanism does not fundamentally solve the problem of inconsistent feature extraction time when using CNNs to process streams. Summary of the Invention

[0004] To address the aforementioned problems, the present invention aims to provide a flow association attack method based on patching and contrastive learning. This method uses time-based patching to segment the flow into patches of equal time length, uses a patch-based feature embedding network to obtain flow embeddings, trains the feature embedding network through contrastive learning to enable the model to effectively learn flow embeddings, and uses cosine similarity as an indicator to evaluate flow relevance for flow association attacks. This improves the accuracy of flow association attacks and reveals the effectiveness of the patching mechanism for flow embedding extraction.

[0005] To achieve the above objectives, the present invention adopts the following technical solution:

[0006] Specifically, this invention provides a flow association attack method based on patching and contrastive learning, the method comprising:

[0007] Use time-based patching to split the Tor stream and the exit stream into patches of the same length;

[0008] Use a patch-based feature embedding network to obtain stream embeddings;

[0009] Contrastive learning is used to train the feature embedding network, enabling the model to effectively learn stream embeddings;

[0010] Using cosine similarity as an indicator to evaluate flow correlation, flow association attacks are performed.

[0011] The specific implementation steps of time-based patching in the above technical solution are as follows:

[0012] Using packet arrival interval delay and packet size as feature vectors, treating them as two variables, and representing them with a two-dimensional array p. i =[I i S i The data is represented as a bivariate time series, with patches padded to ensure each patch has a fixed length P, where P is the maximum number of packets in all patches. The characteristics of a patch are represented as...

[0013] In the above technical solution, the two-dimensional array p i =[I i S i ], vector I i Composed of the arrival interval delay of uplink and downlink data packets, vector S i This includes the size of both uplink and downlink data packets.

[0014] In the above technical solution, Tor flow and exit flow represent traffic entering and leaving the Tor network, respectively.

[0015] In the above technical solution, the patch-based feature embedding network consists of a patch embedding layer and a DF neural network, specifically including:

[0016] The patch embedding layer consists of two linear layers, which are used to compute I separately. i and S i The embeddings are summed to obtain the patch embedding. Where D represents the dimension of the patch embedding, and for each stream, a sequence of patch embeddings is obtained. Where N is the number of patches in the stream, the patch embedding sequence is used as the input of the DF neural network, and the DF network outputs the stream embedding.

[0017] In the above technical solution, the specific formula for calculating patch embedding is as follows:

[0018]

[0019] W1 and W2 represent the weight matrices, and b1 and b2 represent the biases.

[0020] In the above technical solution, the DF neural network model specifically includes:

[0021] One-dimensional convolutional layers are used to capture local patterns in the input sequence, thereby recognizing local features in one-dimensional data;

[0022] Batch normalization layers normalize the data and help speed up convergence and prevent overfitting.

[0023] Activation functions delinearize linear data relationships, enriching the expressive power of neural networks and enabling them to learn more complex patterns and relationships.

[0024] Max pooling layers are used to compress features, alleviate the positional sensitivity of convolutional layers, and reduce computational cost.

[0025] Dropout layers are used to reduce dependencies between neurons, increase the network's generalization ability, and reduce the risk of overfitting to some extent.

[0026] The Flatten layer is used to flatten the input multidimensional feature data into one-dimensional data that is suitable for the input linear layer.

[0027] Linear layers are used to perform linear transformations on the input based on the learned parameters, and the output stream is embedded.

[0028] In the above technical solution, the specific structure of the DF neural network model is as follows:

[0029] The DF neural network consists of four basic blocks, each of which comprises two one-dimensional convolutional layers with batch normalization and activation functions, a max pooling layer, and a dropout layer, followed by a Flatten layer and a linear layer.

[0030] In the above technical solution, a feature embedding network is trained using contrastive learning. Based on the SimCLR framework, targeted adjustments and optimizations are made to its four key stages, specifically including:

[0031] Data Augmentation uses a pair of related Tor and Exit streams as naturally formed positive sample pairs, eliminating the need for artificial construction using data augmentation techniques.

[0032] Base Encoder employs a dual encoder design, with two independently parameterized patch-based feature embedding networks used for feature extraction from Tor and Exit streams, respectively.

[0033] Projection Head directly uses streaming embeddings generated by a patch-based feature embedding network to compute contrastive loss, simplifying the model architecture and allowing the feature embedding network to focus on learning representations that are highly relevant to specific tasks.

[0034] Contrastive Loss, using the NT-Xent loss function as the optimization objective, treats relevant Tor and Exit flows as positive sample pairs. It randomly samples n relevant Tor-Exit flow pairs as a mini-batch, extracting flow embeddings through temporal patching and patch-based feature embedding networks. The Tor flow is represented as z. 2k-1 The exit stream is represented as z 2k For each positive sample pair (i, j), the other 2(n-1) streams in the mini-batch are treated as negative samples, and the NT-Xent loss of the positive sample pair is calculated.

[0035] In the above technical solution, the NT-Xent loss calculation formula is as follows:

[0036]

[0037] in The meaning is the indicator function, which equals 1 only when k≠i; τ represents the temperature parameter; sim(z) i , z j The meaning of ) is z i and z j Cosine similarity between them.

[0038] In the above technical solution, the flow association attack utilizes trained feature embedding networks G and H to calculate the flow embeddings z of Tor flow t and exit flow x, respectively. t and z x Directly calculate the cosine similarity cos(z) t , z x The correlation score of the flow is used as the correlation score. If the score exceeds the threshold θ, then the flow is considered to be correlated with the flow x.

[0039] Compared with existing technologies, the advantages of this invention are as follows:

[0040] I. By using time-based patching technology to segment Tor streams and exit streams into patches of equal duration, the problem of inconsistent stream embedding time in existing technical solutions is solved, the effectiveness of the patching mechanism is revealed, and the accuracy of stream association attacks is improved.

[0041] Second, by designing a patch-based feature embedding network, including a patch embedding layer and a DF neural network, the data scale processed by the model is simplified, and the local patterns and global structure of traffic can be effectively captured to achieve effective flow embedding extraction, thereby reducing computational complexity and improving the accuracy and robustness of flow association attacks.

[0042] Third, by training the feature embedding network through comparative learning, based on the SimCLR framework, targeted adjustments and optimizations were made. The relevant Tor and Exit streams were regarded as positive sample pairs, and two independently parameterized feature embedding networks were used to extract features from the Tor and Exit streams respectively. The generated stream embeddings were directly used to calculate the NT-Xent loss as the optimization objective, which improved the model's learning ability and the accuracy of stream embedding extraction.

[0043] Fourth, by using the cosine similarity between flow embeddings as an indicator to evaluate flow correlation, if the cosine similarity of the flow embeddings generated by the feature embedding network for a Tor flow and an Exit flow exceeds a threshold, they are considered to be correlated. For n flow pairs, only 2n deep neural network model evaluations and n... 2 The cosine similarity calculation solves the problem of high computational overhead for flow pair correlation calculation in existing technologies, reduces the computational complexity of flow association attacks, and enables efficient flow association attacks. Attached Figure Description

[0044] Figure 1 is a diagram of the overall architecture of the present invention.

[0045] Figure 2 is a schematic diagram of an embodiment of the present invention. Detailed Implementation

[0046] The present invention will now be further described in conjunction with the accompanying drawings and specific embodiments.

[0047] The stream association attack method based on patching and contrastive learning provided by this invention includes the following modules:

[0048] The patch segmentation module uses packet arrival interval delay and packet size as feature vectors, treats them as bivariate time series, and fills the patches so that each patch has a fixed length.

[0049] Feature Embedding Network Module: The patch-based feature embedding network consists of a patch embedding layer and a DF neural network. The patch embedding layer includes two linear layers, which respectively calculate I... i and S i The embeddings are summed to obtain the patch embeddings. For each stream, the sequence of patch embeddings is used as input to the DF neural network, and the DF network outputs the stream embeddings.

[0050] Contrastive learning training module: The feature embedding network is trained using contrastive learning. Based on the SimCLR framework, the four key stages of its implementation—Data Augmentation, Base Encoder, Projection Head, and Contrastive Loss—are adjusted and optimized to give the trained feature embedding network excellent performance.

[0051] The correlation calculation module uses two trained feature embedding networks to calculate the flow embeddings of the Tor flow and the exit flow respectively. Then, the cosine similarity of the flow embeddings is calculated as the relevance score of the flow. If the score exceeds the threshold, the flow pair is considered to be related.

[0052] The specific implementation steps of the patch segmentation module in the above technical solution are as follows:

[0053] S1: Using packet arrival interval delay and packet size as feature vectors, treating them as two variables, and representing them with a two-dimensional array p. i =[I i S i This is represented as a bivariate time series;

[0054] S2: Pad the patch to ensure that each patch has a fixed length P, where P is the maximum number of packets in all patches. The characteristics of the patch are represented as follows: Two-dimensional array p i =[I i S i ], vector I i Composed of the arrival interval delay of uplink and downlink data packets, vector S i This includes the size of both uplink and downlink data packets.

[0055] The specific implementation steps of the feature embedding network module in the above technical solution are as follows:

[0056] S1: The patch-based feature embedding network consists of a patch embedding layer and a DF neural network. The patch embedding layer includes two linear layers, which are used to calculate I respectively. iand S i The embeddings are summed to obtain the patch embedding. Where D represents the dimension of patch embedding;

[0057] S2: For each stream, obtain the patch embedding sequence. Where N is the number of patches in the stream, and the patch embedding sequence is used as the input to the DF neural network.

[0058] S3: The DF neural network model consists of a one-dimensional convolutional layer, a batch normalization layer, an activation function, a max pooling layer, a dropout layer, a flatten layer, and a linear layer. Its structure consists of four basic blocks, each of which consists of two one-dimensional convolutional layers with batch normalization layers and activation functions, a max pooling layer, and a dropout layer. Then, a flatten layer and a linear layer are input, and the patch embedding sequence is embedded via the DF network output stream.

[0059] The specific implementation steps of the comparative learning training module in the above technical solution are as follows:

[0060] S1: Use contrastive learning to train the feature embedding network, based on the SimCLR framework, and make targeted adjustments and optimizations to its four key stages;

[0061] S2: In the Data Augmentation phase, a pair of related Tor streams and exit streams are used as naturally formed positive sample pairs, without the need for artificial construction using data augmentation techniques;

[0062] S3: The Base Encoder stage employs a dual encoder design, with two independent parameterized patch-based feature embedding networks used for feature extraction from the Tor stream and the Exit stream, respectively.

[0063] S4: In the Projection Head stage, the contrastive loss is directly calculated using the streaming embeddings generated by the patch-based feature embedding network, which simplifies the model architecture and allows the feature embedding network to focus on learning representations that are highly relevant to the specific task.

[0064] S5: In the Contrastive Loss stage, the NT-Xent loss function is selected as the optimization objective. Related Tor and Exit streams are treated as positive sample pairs. n related Tor-Exit stream pairs are randomly sampled as a mini-batch. Stream embeddings are extracted using temporal patching and patch-based feature embedding networks, and the Tor stream is represented as z. 2k-1 The exit stream is represented as z 2kFor each positive sample pair (i, j), the other 2(n-1) streams in the mini-batch are treated as negative samples, and the NT-Xent loss of the positive sample pair is calculated.

[0065] The specific implementation steps of the correlation calculation module in the above technical solution are as follows:

[0066] S1: Stream association attack utilizes trained feature embedding networks G and H to compute the stream embeddings z of Tor stream t and exit stream x, respectively. t and z x ;

[0067] S2: Directly calculate the cosine similarity cos(z) t , z x As a correlation score of the flow, if the score exceeds the threshold θ, then flow t and flow x are considered to be correlated, thereby realizing correlation calculation and flow correlation attack.

[0068] This invention discloses a flow correlation attack method based on patching and contrastive learning, relating to the field of traffic analysis. This method solves the problems in existing technologies through the following technical means and achieves significant results:

[0069] 1. Time-based Patching Technique: This invention employs a time-based patching technique to segment Tor and Exit streams into patches of equal duration. This technique resolves the issue of inconsistent stream embedding times, improving the accuracy of stream correlation attacks. By segmenting the streams into patches of equal length, it ensures that each stream is analyzed on the same time scale, thereby eliminating false positives and false negatives caused by inconsistent stream lengths.

[0070] 2. By designing a patch-based feature embedding network: This invention effectively extracts flow features by designing a patch-based feature embedding network. This network includes a patch embedding layer and a Deep Feature (DF) neural network. The patch embedding layer uses linear layers to compute feature vectors, while the DF neural network includes one-dimensional convolutional layers, batch normalization layers, activation functions, max pooling layers, dropout layers, and linear layers to learn complex flow features. This feature embedding network can effectively capture the local patterns and global structure of traffic, thereby improving the accuracy and robustness of flow association attacks.

[0071] 3. Training the Feature Embedding Network through Contrastive Learning: This invention employs contrastive learning to train the feature embedding network, based on the SimCLR framework with targeted adjustments and optimizations. Contrastive learning treats related Tor and Exit flows as positive sample pairs, randomly sampling n related Tor-Exit flow pairs as mini-batches. Flow embeddings are extracted through temporal patching and patch-based feature embedding networks, representing the Tor flow as z. 2k-1 The exit stream is represented as z 2k For each positive sample pair (i, j), the other 2(n-1) flows in the mini-batch are treated as negative samples, and the NT-Xent loss of the positive sample pair is calculated. This training method can effectively improve the generalization ability and robustness of the feature embedding network, thereby reducing the computational complexity of flow association attacks.

[0072] 4. Flow Association Attack Using Cosine Similarity: This invention uses cosine similarity as an indicator to evaluate flow correlation and perform flow association attacks. This technique directly calculates the cosine similarity between the flow embeddings of the Tor flow and the Exit flow. If the similarity exceeds a threshold, the flows are considered correlated, thus achieving an efficient flow association attack. Cosine similarity is a commonly used similarity measurement method that can effectively measure the degree of similarity between two vectors in a direction, and is therefore suitable for evaluating the correlation between flow embeddings.

[0073] Compared with the prior art, the main advantages of the present invention include:

[0074] Improved accuracy of flow association attacks: By employing time-based patching and feature embedding networks, this invention effectively improves the accuracy of flow association attacks. This advantage can be verified through comparative experiments, such as evaluating the performance of the proposed method against other flow association attack methods on publicly available datasets.

[0075] Reduced computational complexity: Contrastive learning training methods simplify model architecture and reduce computational complexity. This advantage can be quantified by calculating the time required for model training and inference.

[0076] This invention demonstrates the effectiveness of the patching mechanism in flow embedding extraction, providing a new perspective and method for the field of traffic analysis. This advantage can be visually demonstrated through analysis of the flow embeddings before and after patching.

Claims

1. A flow association attack method based on patching and contrastive learning, characterized in that, The method includes: segmenting Tor and Exit streams into patches of equal duration using time-based patching, where Tor and Exit streams represent traffic entering and exiting the Tor network, respectively; obtaining stream embeddings using a patch-based feature embedding network; training the feature embedding network using contrastive learning to enable the model to effectively learn stream embeddings; performing stream association attacks using cosine similarity as an indicator to evaluate stream relevance; training the feature embedding network using contrastive learning, based on the SimCLR framework, and specifically adjusting and optimizing its four key stages, including: data augmentation, using a pair of related Tor and Exit streams as naturally formed positive sample pairs; a base encoder, employing a dual encoder design, with two independently parameterized patch-based feature embedding networks used for feature extraction from Tor and Exit streams respectively; a projection head, using the stream embeddings generated by the patch-based feature embedding network to calculate the contrastive loss, simplifying the model architecture and allowing the feature embedding network to focus on learning representations highly relevant to the specific task; and contrastive loss, selecting the NT-Xent loss function as the optimization objective, treating related Tor and Exit streams as positive sample pairs, and randomly sampling... Each associated Tor-exit stream pair is used as a mini-batch. Stream embeddings are extracted through temporal patching and patch-based feature embedding networks, representing the Tor stream as... Represent the exit stream as For each positive sample pair Other items in the small batch Each stream is treated as a negative sample, and the NT-Xent loss for positive sample pairs is calculated.

2. The flow association attack method based on patching and contrastive learning according to claim 1, characterized in that, Time-based patching specifically includes using packet arrival interval delay and packet size as feature vectors, treating them as two variables, and representing them using a two-dimensional array. It is represented as a bivariate time series, and the patches are padded to ensure that each patch has a fixed length. ,in It is the maximum number of packets in all patches, and the characteristics of a patch are represented as follows: , where the two-dimensional array ,vector Composed of the arrival interval delay of uplink and downlink data packets, vector This includes the size of both uplink and downlink data packets.

3. The flow association attack method based on patching and contrastive learning according to claim 1, characterized in that, The patch-based feature embedding network consists of a patch embedding layer and a DF neural network. Specifically, the patch embedding layer includes two linear layers, which are used to compute the feature embedding network. and The embeddings are summed to obtain the patch embedding. Where D represents the dimension of the patch embedding, and for each stream, a sequence of patch embeddings is obtained. , where N is the number of patches in the stream, the patch embedding sequence is used as the input of the DF neural network, and the DF network outputs the stream embedding.

4. The flow association attack method based on patching and contrastive learning according to claim 3, characterized in that, The formula for calculating patch embedding is as follows: in and The meaning is the weight matrix. and The meaning is deviation.

5. The stream association attack method based on patching and contrastive learning according to claim 3, characterized in that, The DF neural network model specifically includes: a one-dimensional convolutional layer, used to capture local patterns in the input sequence and identify local features in one-dimensional data; a batch normalization layer, used to normalize the data to accelerate convergence and prevent overfitting; an activation function, used to delinearize linear data relationships, enriching the expressive power of the neural network and enabling it to learn more complex patterns and relationships; a max pooling layer, used to compress features, alleviating the positional sensitivity of the convolutional layer and reducing computational cost; a dropout layer, used to reduce dependencies between neurons, increase the network's generalization ability, and reduce the risk of overfitting; a flattening layer, used to flatten the multi-dimensional feature data of the input into one-dimensional data suitable for the input linear layer; and a linear layer, used to perform a linear transformation on the input based on the learned parameters, with the output stream embedded. 。 6. The stream association attack method based on patching and contrastive learning according to claim 5, characterized in that, The specific structure of the DF neural network model is as follows: The DF neural network consists of four basic blocks, each of which includes two one-dimensional convolutional layers with batch normalization layers and activation functions, a max pooling layer and a dropout layer, followed by input to a Flatten layer and a linear layer.

7. The stream association attack method based on patching and contrastive learning according to claim 1, characterized in that, The formula for calculating NT-Xent loss is as follows: in The meaning is an indicator function, only when Time equals 1, This represents the sample index, ranging from 1 to 2n, where n is the batch size. The meaning is temperature parameter. The meaning is and Cosine similarity between them.

8. The stream association attack method based on patching and contrastive learning according to claim 7, characterized in that, The flow association attack utilizes trained feature embedding networks G and H to compute the flow embeddings of Tor flow t and exit flow x, respectively. and Directly calculate cosine similarity As a relevance score for the flow, if the score exceeds a threshold... If so, then flow t and flow x are considered to be related.

Citation Information

Patent Citations

  • Network intrusion detection method, system and equipment based on comparative learning, and medium

    CN117914618A