A method and system for encrypted traffic classification based on structure-aware latent space representation

By reshaping and transposing the flow-level view and the packet header view, combined with a robust latent space encoder and self-supervised pre-training, the problem of model sensitivity to perturbations and distribution drift in encrypted traffic classification is solved, achieving highly accurate and robust encrypted traffic classification.

CN123185151APending Publication Date: 2026-11-27GUANGZHOU UNIVERSITY +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611070663.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-18
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing technologies struggle to effectively identify the application or behavior categories of encrypted traffic without decryption, and the models are sensitive to packet loss, out-of-order delivery, local disturbances, and protocol drift. Furthermore, the reconstruction loss model has difficulty learning the evolutionary patterns of protocol fields.

Method used

By reshaping and transposing the flow-level view and the message header view, and combining the minimum gated cyclic unit to extract long-range context and cross-message structure features, a robust latent space encoder is used to predict conditional Gaussian distribution and sample standard normal noise to form a random neighborhood. Self-supervised pre-training and message header structure loss are used to optimize classification.

Benefits of technology

It improves the accuracy and robustness of encrypted traffic classification, reduces the impact of encrypted payload noise, enhances the model's adaptability to local changes and protocol drift, and maintains good generalization ability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure FT_1
    Figure FT_1
  • Figure FT_2
    Figure FT_2
Patent Text Reader

Abstract

The application discloses a kind of encrypted traffic classification method and system based on structure perception latent space representation, belong to network security and traffic identification technical field.The method is according to five-element group reorganization network traffic and carries out fixed length and block embedding;Global context and cross-message header evolution features are extracted in flow level view and message header view obtained by transposition respectively using minimum gate cycle unit;Mean and logarithmic variance parameterized input adaptive Gaussian latent space is obtained by reparameterization sampling;In mask auto-encoding pre-training, reconstructive loss and message header structure loss including correlation, variance and mean constraint are jointly optimized, and latent space KL divergence regularization term weight is set to zero;After fine-tuning with labeled data, the encrypted traffic category is output.The application can improve the robustness and migration ability of the model to message disturbance, protocol drift and unknown data distribution.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of network security, network traffic analysis and machine learning, and in particular to an encrypted traffic classification method and system based on structure-aware latent space representation.

[0002] This invention is applicable to the identification of virtual private network traffic, anonymous network traffic, Internet of Things (IoT) traffic, industrial IoT traffic, and encrypted communication traffic containing network attack behaviors. Background Technology

[0003] With the widespread adoption of transport layer security protocols, virtual private networks (VPNs), and anonymous communication technologies, network payloads exhibit high entropy and unreadable characteristics, making classification methods relying on port numbers, plaintext keywords, or fixed payload patterns difficult to operate stably. Encrypted traffic classification requires identifying application or behavior categories from packet length, direction, header fields, and their cross-packet variations without decrypting the payload.

[0004] Existing deep learning-based solutions typically flatten a traffic stream into a single byte sequence or rearrange the bytes into a two-dimensional image. The former ignores the evolutionary relationship of the same protocol fields between consecutive messages, while the latter easily introduces spatial adjacency biases unrelated to the network protocol. Although some methods can extract global sequence features, they do not explicitly distinguish between the message header and the cryptographic payload, causing the model to easily memorize payload noise specific to the dataset.

[0005] Furthermore, conventional sequence encoders map each traffic item to a deterministic point in the latent space. When messages are lost, out of order, locally disturbed, or the protocol implementation drifts, the deterministic point representation is prone to significant shifts. Standard variational autoencoders improve local smoothness through Gaussian sampling, but their KL divergence regularization term pushes the class conditional mean toward the common prior center, weakening the inter-class geometric separation required for encrypted traffic classification.

[0006] Existing masked autoencoder pre-training methods often use mean squared error as a general reconstruction objective. This objective processes the input byte-by-byte with equal weights, which cannot adequately constrain the correlation direction, relative dispersion, and mean variation of the header fields in consecutive packets. Therefore, a cryptographic traffic classification scheme is needed that simultaneously models the flow-level context, the evolution of the header structure, and the adaptive latent space neighborhood of the input. Summary of the Invention

[0007] The purpose of this invention is to solve the problems of existing technologies that flatten traffic while ignoring cross-header structure, deterministic latent space representation being sensitive to disturbances and distribution drift, and the difficulty of learning the evolution law of protocol fields in general reconstruction loss.

[0008] To achieve the above objectives, the present invention provides a method for classifying encrypted traffic based on structure-aware latent space representation, comprising the following steps.

[0009] Step S101: Obtain the raw network traffic, extract and reassemble the independent traffic based on the five-tuple consisting of the source Internet Protocol address, destination Internet Protocol address, source port, destination port and transport layer protocol; truncate or pad each traffic item with zeros, and form a fixed-length byte sequence according to the preset number of bytes in the header and payload.

[0010] Step S102: Use stride embedding to divide the fixed-length byte sequence into non-overlapping continuous byte blocks, map each byte block to an embedding vector, and superimpose learnable position embeddings to obtain a flow token sequence that maintains the sequence order.

[0011] Step S103: Input the traffic token sequence into the hierarchical encoder; in the shallow layer, take the entire traffic as the flow-level view and use the minimum gated loop unit to extract the long-range context; reshape and transpose the shallow layer output according to the number of messages and the length of a single message, and segment the message header features; in the deep layer, take the sequence formed by the same message header byte offset position along the message order as the message header view, and then use the minimum gated loop unit to extract the cross-message structure features.

[0012] Step S104: Input the structure-aware features into the robust latent space encoder to predict the mean and log-variance of the conditional Gaussian distribution, sample the standard normal noise, and obtain the latent vector through reparameterization; the variance is predicted by the current input flow, thereby forming a random neighborhood that varies with the flow complexity.

[0013] Step S105: In the self-supervised pre-training stage, partially mask the traffic tokens with a high masking ratio, use the latent vector as the initial hidden state of the minimum gated recurrent unit decoder, and reconstruct the masked original content.

[0014] Step S106: Align and transpose the headers of consecutive messages according to byte offset positions to construct the header field evolution sequence; calculate the correlation loss, variance loss and mean loss for the real evolution sequence and the reconstructed evolution sequence respectively, and form the header structure loss through learnable weights.

[0015] Step S107: Use the weighted sum of reconstruction loss and message header structure loss as the total pre-training loss, and set the weight of the latent space KL divergence regularization term corresponding to the robust latent space encoder to zero, so as to retain the input adaptive random sampling and avoid the class conditional latent space mean being pushed towards the common prior center.

[0016] Step S108: Connect the lightweight multilayer perceptron classifier to the pre-trained hierarchical encoder and robust latent space encoder, perform end-to-end fine-tuning using target traffic with category labels, and determine the encrypted traffic category based on the classifier output.

[0017] In one alternative approach, the minimum gated loop unit calculates the forget gate at time t. Candidate hidden state and hidden state Specifically:

[0018]

[0019]

[0020]

[0021] in, For the current input, This represents the hidden state at the previous time step, where σ is the Sigmoid function and ⊙ represents element-wise multiplication. , , and These are trainable parameters.

[0022] In one alternative, the robust latent space encoder outputs the mean value. Sum of logarithmic variance The latent vector is obtained according to the following formula:

[0023]

[0024] Traffic with stable and identifiable protocol patterns corresponds to smaller variance, allowing the reconstruction target to be concentrated near reliable latent points; traffic with higher behavioral entropy or ambiguous patterns corresponds to larger variance, allowing the decoder to learn invariance in a wider latent space neighborhood.

[0025] In one alternative approach, the message header structure is lost. Loss due to correlation Variance loss and mean loss constitute:

[0026]

[0027] in, This is the average of the reduced values ​​of the Pearson correlation coefficients between the real evolutionary sequence and the reconstructed evolutionary sequence; This represents the average KL divergence between the relatively discrete distributions obtained after applying Softmax normalization to both. α represents the average absolute error between the means of the corresponding evolutionary sequences; α, β, and γ are learnable weights. The total pre-training loss is:

[0028]

[0029] in, The reconstruction loss of the masked content, λ is the latent space KL divergence regularization term between the conditional Gaussian distribution and the standard normal prior, and λ is the message header structure loss weight. The KL divergence used to compare the relatively discrete distribution of the message header and the latent space KL divergence regularization term with zero weight have different objects of action, and the former is retained.

[0030] The present invention also provides an encrypted traffic classification system, including a traffic preprocessing module 100, a hierarchical encoding module 200, a robust latent space encoding module 300, a mask decoding module 400, a packet header structure loss module 500, a classification module 600, and a classification output module 700, each module being used to execute the aforementioned method steps.

[0031] The present invention also provides an electronic device and a computer-readable storage medium, wherein when the processor of the electronic device executes a computer program in the memory, or when the computer program in the computer-readable storage medium is executed by the processor, the aforementioned encrypted traffic classification method is implemented.

[0032] Beneficial effects

[0033] First, by reshaping and transposing the flow-level view and the packet header view, the model simultaneously preserves the global context of the entire flow and explicitly learns the variation patterns of the same packet header fields across packets, reducing the loss of structural information caused by encryption payload noise and flattening processing.

[0034] Second, by forming a random latent space neighborhood through input conditional mean and variance, different perturbation radii are obtained for traffic of different complexities without using fixed amplitude noise, thereby improving robustness to local byte changes, packet loss, out-of-order delivery and protocol drift.

[0035] Third, by setting the weight of the latent space KL divergence regularization term to zero, we avoid the class mean being compressed by the common prior, while retaining the neighborhood smoothness brought by reparameterized sampling, so as to balance separability and generalization ability.

[0036] Fourth, the message header structure loss is formed by three complementary constraints: correlation, variance, and mean. This expands the reconstruction target from byte-by-byte error to the evolution law of protocol fields, and uses learnable weights to balance different structural indicators. Attached Figure Description

[0037] Figure 1 This is a flowchart illustrating the pre-training and fine-tuning process of the encrypted traffic classification method of this invention.

[0038] Figure 2 This is a schematic diagram of the structure of the hierarchical encoder and robust latent space encoder of the present invention.

[0041] In the diagram: 100, Traffic preprocessing module; 110, Traffic reconstruction unit; 120, Length normalization unit; 130, Stride embedding unit; 200, Hierarchical coding module; 210, Stream-level coding unit; 220, Reshaping and transposing unit; 230, Message header slicing unit; 240, Message header coding unit; 300, Robust latent space coding module; 310, Mean parameter unit; 320, Log-variance parameter unit; 330, Reparameterized sampling unit; 340, Latent vector; 400, Mask decoding module; 500, Message header structure loss module; 501, True message header evolution sequence; 502, Reconstructed message header evolution sequence; 510, Correlation loss unit; 520, Variance loss unit; 530, Mean loss unit; 540, Dynamic weighting unit; 600, Classification module; 700, Classification output module; 800, Encrypted traffic classification system. Detailed Implementation

[0042] The present invention will be further described below with reference to the accompanying drawings and embodiments. It should be understood that the embodiments are used to illustrate the present invention and not to limit the scope of protection; where there is no conflict, the technical features of the various embodiments can be combined with each other.

[0043] Example 1: Encrypted Traffic Classification Method

[0044] like Figure 1 As shown, the traffic preprocessing module 100 obtains packets from the original packet capture file or online mirror interface, and the traffic reassembly unit 110 aggregates bidirectional packets according to five-tuples and arranges them in chronological order. The length normalization unit 120 selects the first P packets of each traffic stream, retaining H header bytes and Q payload bytes for each packet; any insufficient packets are padded with zeros, and any excessive packets are truncated, thus forming the length normalization unit. Byte sequence.

[0045] In this embodiment, P=5, H=80, Q=240, therefore L=1600 bytes. This set of parameters illustrates a feasible configuration; P, H, and Q can be adjusted according to the protocol type, deployment computing power, and real-time requirements. For messages lacking sufficient payload, only the corresponding positions are padded; the original valid bytes are neither decrypted nor modified.

[0046] The stride embedding unit 130 treats a single-channel byte sequence of length L as a time signal and performs non-overlapping sliding window segmentation using a one-dimensional convolution with a kernel size and stride of S; each byte block is linearly projected to D dimensions, and then learnable position embeddings are superimposed. In this embodiment... ,get Traffic token.

[0047] like Figure 2As shown, the hierarchical coding module 200 first uses the stream-level coding unit 210 to input the flow token sequence as a continuous time series into multiple minimum-gated cyclic unit blocks to obtain features containing long-range context. The reshaping and transpose unit 220 then reshapes the transpose into a shape that is... Feature reshaping ,in The length of the token sequence. This represents the number of tokens corresponding to a single message. The message header slicing unit 230 separates the message header and payload according to the token range corresponding to H. The message header encoding unit 240 performs timing modeling after arranging the same byte offset positions along P messages.

[0048] Both stream-level coding and header coding employ minimum-gated cyclic units. This unit controls both the retention rate of old states and the writing rate of candidate states simultaneously through a single forget gate. The computational complexity of the sequence increases linearly with the input length, making it suitable for processing longer byte sequences.

[0049] The robust latent space coding module 300 takes the hidden features of the hierarchical coding module 200 as input. The mean parameter unit 310 outputs... Logarithmic variance parameter unit 320 output The reparameterized sampling unit 330 samples ε and calculates the latent vector 340. The latent vector 340 contains both semantic information of the current flow and local perturbations controlled by the input conditional variance.

[0050] During pre-training, 90% of the traffic tokens are randomly masked, and the mask decoding module 400 reconstructs the original tokens using latent vector 340 as the initial hidden state. The header structure loss module 500 inputs the real header evolution sequence 501 and the reconstructed header evolution sequence 502 into the correlation loss unit 510, variance loss unit 520, and mean loss unit 530, which are then combined by the dynamic weighting unit 540. .

[0051] In this embodiment, the hierarchical encoding module 200 includes four minimum gated recurrent unit blocks with a hidden dimension of 256, and the mask decoding module 400 includes two minimum gated recurrent unit blocks; the Adam optimizer is used, and the initial learning rate is... The batch size is 128, using cosine decay and 25 preheating cycles. The pre-training process involves 150,000 steps. All parameters can be adjusted while maintaining the method structure.

[0052] During supervised fine-tuning, the mask decoding module 400 is removed or stopped, and the classification module 600 is connected after the robust latent space encoding module 300. In this embodiment, the classification module 600 is a lightweight multilayer perceptron, with the training set, validation set, and test set divided in an 8:1:1 ratio, a batch size of 64, and 100 rounds of end-to-end training; the classification output module 700 outputs the probability of each category and the encrypted traffic category corresponding to the highest probability.

[0053] To verify the effectiveness of the technique, full fine-tuning was performed on five public datasets, and the results are shown in Table 1.

[0054] Table 1. Classification results of encrypted traffic using the method of the present invention

[0055] Dataset accuracy Macro average F1 ISCXVPN 2016 0.9960 0.9972 ISCXTor2016 0.9999 0.9999 CICIoT2022 0.9999 0.9999 Edge-IIoT 0.9986 0.9949 ToN-IoT 0.9889 0.9863

[0056] The results show that the method of this invention can achieve high classification accuracy and macro-average F1 in different encrypted communication and IoT scenarios, and still maintains good transfer ability on datasets that have not participated in pre-training. This effect is jointly achieved by hierarchical structure modeling, input adaptive random latent space encoding, and message header structure loss.

[0057] Example 2: Encrypted Traffic Classification System

[0058] The encrypted traffic classification system 800 includes a traffic preprocessing module 100, a hierarchical coding module 200, a robust latent space coding module 300, a mask decoding module 400, a packet header structure loss module 500, a classification module 600, and a classification output module 700. Each module can be implemented by software, hardware, or a combination of both.

[0059] In pre-training mode, the traffic preprocessing module 100, hierarchical coding module 200, robust latent space coding module 300, mask decoding module 400, and packet header structure loss module 500 work together. In fine-tuning or inference mode, the traffic preprocessing module 100, hierarchical coding module 200, robust latent space coding module 300, classification module 600, and classification output module 700 work together. The classification module 600 can be configured with different output dimensions according to the application identification, attack type identification, or device behavior identification task.

[0060] Example 3: Electronic devices and storage media

[0061] The electronic device includes a processor, memory, network interface, and bus. The memory stores model parameters and computer programs; the processor reads and executes the computer programs to perform traffic reconstruction, embedding, hierarchical coding, latent space sampling, pre-training, or classification inference. The network interface receives packet capture files, mirrored traffic, or reconstructed traffic and outputs classification results.

[0062] The computer-readable storage medium may be a disk, solid-state storage, read-only memory, random access memory, or other non-transitory medium capable of storing program code. When the stored program is executed by a processor, it implements the method steps described in this specification.

[0063] The specific values, number of network layers, and training parameters in the above embodiments are optional implementations and do not constitute a limitation on the scope of protection of this invention. Those skilled in the art can make equivalent substitutions for the number of messages, byte length, embedding dimension, classifier form, or optimization parameters without departing from the core concept of this invention, and all such substitutions can employ the structure-aware coding, input adaptive random latent space sampling, and message header structure constraints described in this invention.

Claims

1. A method for classifying encrypted traffic based on structure-aware latent space representation, characterized in that, include: The original network traffic is acquired and reassembled into a traffic sample according to the communication quintuple. The traffic sample is then subjected to fixed-length processing, block embedding and position encoding to obtain a traffic token sequence. The traffic token sequence is input into a hierarchical encoder. In the flow-level view, a first minimum-gated recurrent unit is used to extract global context features of the traffic. The resulting feature sequence is reshaped and transposed into a message header view along the message dimension, separating the message header features from the payload features. A second minimum-gated recurrent unit is used to perform cross-message temporal modeling of the message header features to obtain structure-aware features. These structure-aware features are then input into a robust latent space encoder to predict the mean and log-variance of a Gaussian distribution conditioned on the input traffic. Latent vectors are obtained through reparameterized sampling. During the self-supervised pre-training phase... The traffic token sequence is masked, and the latent vector is used as the initial hidden state of the decoder to reconstruct the masked content. A weighted sum optimization model of reconstruction loss and message header structure loss is used, wherein the weight of the latent space KL divergence regularization term corresponding to the Gaussian distribution is set to zero. The message header structure loss includes the correlation loss, variance loss, and mean loss of the message header evolution sequence. In the supervised fine-tuning stage, the classifier is connected to the pre-trained hierarchical encoder and robust latent space encoder, and end-to-end optimization is performed using traffic samples with class labels to output the encrypted traffic category.

2. The encrypted traffic classification method according to claim 1, characterized in that, The fixed-length processing includes: extracting bidirectional traffic according to a five-tuple consisting of source Internet Protocol address, destination Internet Protocol address, source port, destination port, and transport layer protocol; and selecting the first few bytes of each traffic stream. Each message is stored. One message header byte and Each payload byte truncates traffic exceeding a preset length and pads traffic less than the preset length with zeros at the end.

3. The encrypted traffic classification method according to claim 1, characterized in that, The block embedding includes: embedding blocks of length [number missing]. A single-channel byte sequence is input into a one-dimensional convolutional layer, and the kernel size and stride of the one-dimensional convolutional layer are both set to... to form A series of non-overlapping contiguous byte blocks are linearly mapped to each contiguous byte block as follows: The embedding vectors are multidimensional, and the learnable position embeddings are superimposed onto each embedding vector.

4. The encrypted traffic classification method according to claim 1, characterized in that, The hierarchical encoder will have a shape of The flow-level feature sequence is reshaped into a shape of The message-level feature tensor, in which For batch size, For the number of messages, For the length of a single message, The number of channels is specified; the message-level feature tensor is sliced ​​according to the message header length, and the message header features with the same byte offset position are arranged in the message order and then input into the second minimum gated loop unit.

5. The encrypted traffic classification method according to claim 1, characterized in that, The first minimum gated loop unit and the second minimum gated loop unit are in accordance with , and Update hidden state, where For the Gate of Oblivion For the current input, The state was hidden in the previous moment. This is the candidate hidden state.

6. The encrypted traffic classification method according to claim 1, characterized in that, The robust latent space encoder is based on structure-aware features Output the mean respectively and logarithmic variance and in accordance with Obtain latent vector ,in It follows a standard normal distribution, and the variance is... As the input traffic changes, traffic with stable protocol patterns corresponds to a smaller sampling neighborhood, while traffic with higher behavioral entropy corresponds to a larger sampling neighborhood.

7. The encrypted traffic classification method according to claim 1, characterized in that, The calculation of the message header structure loss includes: aligning and transposing the message headers of multiple consecutive messages by byte offset to construct an evolution sequence in which the fields of each message header change with the message order; using a sliding window to extract the state transition relationship of field values ​​between adjacent messages; and calculating the correlation loss, variance loss, and mean loss for the real evolution sequence and the reconstructed evolution sequence, respectively.

8. The encrypted traffic classification method according to claim 7, characterized in that, The correlation loss is the average of the reduced Pearson correlation coefficients between the real and reconstructed evolutionary sequences; the variance loss is the average of the KL divergences between the relatively discrete distributions obtained after applying Softmax normalization to both the real and reconstructed evolutionary sequences; and the mean loss is the average of the absolute errors between the means of the corresponding sequences, using learnable weights. , and form The total pre-training loss is .

9. The encrypted traffic classification method according to claim 1, characterized in that, In one training example Take 5. Take 80 bytes. Take 240 bytes. Take 1600 bytes. Take 4. The hierarchical encoder, with a hidden dimension of 256, contains four minimum gated cyclic unit blocks (MOUs), and the decoder contains two MOUs. The mask ratio is 0.9, and the message header structure loss weights are used. Take 0.

1.

10. A cryptographic traffic classification system based on structure-aware latent space representation, characterized in that, It includes a traffic preprocessing module, a hierarchical coding module, a robust latent space coding module, a mask decoding module, a packet header structure loss module, a classification module, and a classification output module; each module is configured to perform the encrypted traffic classification method according to any one of claims 1 to 9.

11. An electronic device, characterized in that, It includes a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the encrypted traffic classification method according to any one of claims 1 to 9.

12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the encrypted traffic classification method according to any one of claims 1 to 9.