A method, device and readable storage medium for encrypted traffic analysis

By generating query stream embeddings through a packet byte evidence gating encoder, calculating similarity, and determining target nearest neighbor training streams, the adaptability problem of encrypted traffic analysis in low-label network environments is solved, improving the effectiveness and auditability of the analysis.

CN123138952APending Publication Date: 2026-11-20PENG CHENG LAB
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611292141.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-25
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

Existing encrypted traffic analysis methods are poorly adapted to low-label real-world network environments, making it difficult to effectively extract valid features from encrypted traffic, and the analysis results are difficult to verify.

Method used

The query stream embedding is generated by the packet byte evidence gating encoder, the similarity is calculated and the target nearest neighbor training stream is determined, and the encoded representation and stream embedding of the local window are extracted by the evidence gating unit and the context coding unit to generate the evidence items of the classification result.

Benefits of technology

It improves the effectiveness of encrypted traffic analysis and the auditability of analysis results, reduces the reliance on large-scale tag data, and enhances the discriminative value of local byte information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123138952A_ABST
    Figure CN123138952A_ABST
Patent Text Reader

Abstract

The application discloses an encrypted traffic analysis method and device, equipment and readable storage medium, and is applied to the technical field of computers, and comprises the following steps: generating query stream embedding through a pre-trained data packet byte evidence gate encoder according to a query stream formed by data packets in two directions of a same communication session; calculating the similarity between the query stream embedding and flow embedding in a neighbor index, and determining a target neighbor training flow; determining a classification result according to the label of the target neighbor training flow, and determining a target byte window from the query stream and the target neighbor training flow as an evidence item output according to a gate score; and the data packet byte evidence gate encoder generates a data packet abstract vector through local window gate aggregation, and generates flow embedding through context encoding. The application can reduce the interference of weak information bytes on traffic representation, and make the classification result associated with historical neighbors and local byte evidence, thereby improving analysis effectiveness and auditability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to an encrypted traffic analysis method, apparatus, device, and readable storage medium. Background Technology

[0002] With the widespread adoption of encryption protocols such as TLS (Transport Layer Security) and QUIC (Quick UDP Internet Connections), application payloads in network traffic often cannot be directly parsed. Existing encrypted traffic analysis methods primarily train classification models based on packet byte counts, packet lengths, timing, or flow statistics. These methods typically rely heavily on labeled traffic, but obtaining reliable labels in real-world operational networks is costly, and changes in application versions and encryption stacks can reduce model adaptability. Furthermore, discriminative information in encrypted traffic is often concentrated in a small number of local byte regions; excessive encryption, padding, or redundant content can dilute effective information, making it difficult for models to consistently extract effective features. In addition, existing models typically only output categories and confidence levels, making it difficult for analysts to determine which traffic content the model bases its conclusions on, and also to verify anomalies. These issues collectively limit the application of encrypted traffic analysis in low-label real-world network environments.

[0003] Therefore, improving the applicability of encrypted traffic analysis in low-label real-world network environments is a pressing technical problem that needs to be solved. Summary of the Invention

[0004] In view of this, the purpose of the present invention is to provide an encrypted traffic analysis method, apparatus, device and readable storage medium, which solves the problem of poor adaptability of encrypted traffic analysis in low-label real network environments in the prior art.

[0005] To address the aforementioned technical problems, this invention provides an encrypted traffic analysis method, comprising: Based on the acquired query stream, a query stream embedding is generated using a pre-trained data packet byte evidence gating encoder; wherein the query stream consists of data packets from two directions within the same communication session; Calculate the similarity between the query stream embedding and the stream embedding in the nearest neighbor index, and determine the target nearest neighbor training stream from the training stream corresponding to the nearest neighbor index based on the similarity; wherein, the nearest neighbor index is constructed from the stream embedding obtained by encoding the labeled training stream through the data packet byte evidence gating encoder; The classification result of the query stream is determined based on the label of the target nearest neighbor training stream, and the target byte window is determined from the query stream and the target nearest neighbor training stream respectively based on the gating score. The target byte window is output as evidence item of the classification result. The data packet byte evidence gating encoder includes an evidence gating unit and a context encoding unit. The evidence gating unit is used to divide the byte sequence of each data packet in the data stream into local windows, extract the encoded representation of each byte window and determine the corresponding gating score, and perform weighted aggregation of the encoded representation of each byte window according to the gating score to generate a digest vector of each data packet. The context encoding unit is used to perform context encoding on the digest vector of each data packet to generate the stream embedding of the data stream.

[0006] Optionally, the evidence gating unit is used to divide the byte sequence of each data packet in the data stream into local windows, extract the encoded representation of each byte window and determine the corresponding gating score, and perform weighted aggregation of the encoded representation of each byte window according to the gating score to generate a digest vector for each data packet, including: Divide the byte sequence of each data packet into multiple non-overlapping byte windows; Each byte window is convolutionally encoded, and the convolutional encoding results are pooled and projected to obtain the encoded representation of each byte window. The corresponding gating score is determined based on the encoded representation of each byte window; Based on the gating scores, the encoded representations of each byte window in the same data packet are normalized and weighted, and a digest vector of the data packet is generated.

[0007] Optionally, the context encoding unit is used to perform context encoding on the digest vector of each data packet to generate the stream embedding of the data stream, including: The digest vector of each data packet is projected, and the projected digest vector is combined with the corresponding data packet position embedding to obtain the data packet representation sequence; The context representation sequence of the data packet is context-encoded by a self-attention coding network with key-filled mask to obtain the context representation corresponding to the valid data packet; The context representation corresponding to the valid data packet is pooled and projected, and the projection result is normalized to obtain the stream embedding of the data stream.

[0008] Optionally, before generating the query stream embedding using a pre-trained packet byte evidence gating encoder based on the acquired query stream, the method further includes: Obtain multiple labeled training streams and construct training batches based on the labels of each training stream; Each training stream in the training batch is input into the data packet byte evidence gating encoder to be trained to generate the stream embedding corresponding to each training stream; For each anchor training stream in the training batch, positive sample training streams with the same label as the anchor training stream and negative sample training streams with different labels are determined according to the labels. The retrieval loss is determined based on the similarity between the flow embedding of the anchor training stream and the flow embeddings of the positive sample training stream and the negative sample training stream, respectively. The parameters of the packet byte evidence gating encoder to be trained are adjusted according to the retrieval loss to obtain the pre-trained packet byte evidence gating encoder.

[0009] Optionally, before adjusting the parameters of the packet byte evidence gating encoder to be trained according to the retrieval loss to obtain the pre-trained packet byte evidence gating encoder, the method further includes: The evidence weight corresponding to each data packet is determined based on the gating score of each data packet in each training stream. Based on the evidence weight and summary vector corresponding to each data packet, generate the evidence summary vector corresponding to each training stream; Determine the representation difference between the evidence summary vector of each training stream and the corresponding stream embedding, and determine the consistency loss based on the representation difference; Accordingly, adjusting the parameters of the data packet byte evidence gating encoder to be trained based on the retrieval loss to obtain the pre-trained data packet byte evidence gating encoder includes: The parameters of the packet byte evidence gating encoder to be trained are adjusted according to the retrieval loss and the consistency loss to obtain the pre-trained packet byte evidence gating encoder.

[0010] Optionally, before adjusting the parameters of the packet byte evidence gating encoder to be trained according to the retrieval loss to obtain the pre-trained packet byte evidence gating encoder, the method further includes: The gated sparsity loss is determined based on the gate score of each byte window corresponding to the valid data packets in each training stream; the valid data packets are the actual data packets that exist in the original network traffic. The gate smoothing loss is determined based on the difference between the gate scores corresponding to adjacent byte windows in the same valid data packet. Accordingly, adjusting the parameters of the data packet byte evidence gating encoder to be trained based on the retrieval loss to obtain the pre-trained data packet byte evidence gating encoder includes: The parameters of the data packet byte evidence gating encoder to be trained are adjusted according to the retrieval loss, the gating sparsity loss and the gating smoothness loss to obtain the pre-trained data packet byte evidence gating encoder.

[0011] Optionally, based on the acquired query stream, a query stream embedding is generated using a pre-trained packet byte evidence gating encoder, including: The original network traffic is categorized according to the communication quintuple, and the data packets in the two directions of the same communication session are merged and arranged in chronological order to form the query stream; Each data packet in the query stream is truncated or padded to ensure that each data packet has the same byte length, and a data packet byte tensor is constructed based on the processed data packets. A valid data packet mask is generated based on the position of the actual data packet in the query stream within the data packet byte tensor. The byte values ​​in the data packet byte tensor are mapped to byte embedding representations using a byte embedding table; The byte embedding representation and the effective data packet mask are input into the data packet byte evidence gating encoder to obtain the query stream embedding; wherein, the effective data packet mask is used to set the gating score corresponding to the padding data packet to zero in the evidence gating unit, and as a key padding mask in the context encoding unit so that the padding data packet does not participate in attention calculation.

[0012] The present invention also provides an encrypted traffic analysis device, comprising: An encoding module is used to generate a query stream embedding based on the acquired query stream using a pre-trained data packet byte evidence gating encoder; wherein the query stream consists of data packets from two directions within the same communication session; The retrieval module is used to calculate the similarity between the query stream embedding and the stream embedding in the nearest neighbor index, and determine the target nearest neighbor training stream from the training stream corresponding to the nearest neighbor index based on the similarity; wherein, the nearest neighbor index is constructed from the stream embedding obtained by encoding the labeled training stream through the data packet byte evidence gating encoder; The output module is used to determine the classification result of the query stream based on the label of the target nearest neighbor training stream, and to determine the target byte window from the query stream and the target nearest neighbor training stream respectively based on the gating score, and output the target byte window as evidence item of the classification result; The data packet byte evidence gating encoder includes an evidence gating unit and a context encoding unit. The evidence gating unit is used to divide the byte sequence of each data packet in the data stream into local windows, extract the encoded representation of each byte window and determine the corresponding gating score, and perform weighted aggregation of the encoded representation of each byte window according to the gating score to generate a digest vector of each data packet. The context encoding unit is used to perform context encoding on the digest vector of each data packet to generate the stream embedding of the data stream.

[0013] The present invention also provides an encrypted traffic analysis device, comprising: Memory, used to store computer programs; A processor is used to implement the encrypted traffic analysis method described above when executing the computer program.

[0014] The present invention also provides a computer-readable storage medium storing computer-executable instructions, which, when loaded and executed by a processor, implement the encrypted traffic analysis method described above.

[0015] The present invention also provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the above-described encrypted traffic analysis method.

[0016] As can be seen from the above technical solution, the present invention generates a query stream embedding by using a pre-trained data packet byte evidence gating encoder based on the acquired query stream. The query stream consists of data packets from two directions within the same communication session. The similarity between the query stream embedding and the stream embedding in the nearest neighbor index is calculated, and a target nearest neighbor training stream is determined from the training stream corresponding to the nearest neighbor index based on the similarity. The nearest neighbor index is constructed from the stream embedding obtained by encoding the labeled training stream using the data packet byte evidence gating encoder. The classification result of the query stream is determined based on the label of the target nearest neighbor training stream, and a target byte window is determined from both the query stream and the target nearest neighbor training stream based on the gating score. The target byte window is output as evidence item of the classification result. The data packet byte evidence gating encoder includes an evidence gating unit and a context encoding unit. The evidence gating unit is used to divide the byte sequence of each data packet in the data stream into local windows, extract the encoded representation of each byte window, determine the corresponding gating score, and perform weighted aggregation of the encoded representation of each byte window based on the gating score to generate a summary vector for each data packet. The context encoding unit is used to perform context encoding on the summary vector of each data packet to generate the stream embedding of the data stream.

[0017] The beneficial effects of this invention are as follows: This invention constructs a query stream from data packets in two directions within the same communication session, and performs local windowing on the byte sequence of each data packet. It then uses a gating score to weighted aggregate the encoded representation of each byte window, ensuring that local byte information with high discriminative value contributes significantly to the data packet digest, thereby reducing the interference of encryption, padding, and redundant bytes on the traffic representation. Simultaneously, it generates stream embeddings based on the digest vectors of each data packet, retrieves labeled target nearest neighbor training streams using stream embedding similarity, and determines the classification results. This allows existing labeled training streams to serve as reusable historical nearest neighbor evidence, rather than merely fitting classification boundaries, reducing reliance on large-scale labeled data. Furthermore, it determines the target byte windows in the query stream and target nearest neighbor training stream based on the gating scores involved in data packet digest formation and outputs them as evidence items. This enables the classification results to simultaneously correlate historical nearest neighbor and local byte evidence, improving the effectiveness of encrypted traffic analysis and the auditability of the analysis results.

[0018] In addition, the present invention also provides an encrypted traffic analysis device, equipment, and readable storage medium, which also have the above-mentioned beneficial effects. Attached Figure Description

[0019] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0020] Figure 1 A flowchart of an encrypted traffic analysis method provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of the overall system architecture of an encrypted traffic analysis method provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of an encrypted traffic analysis device provided in an embodiment of the present invention; Figure 4 This is a schematic diagram of the structure of an encrypted traffic analysis device provided in an embodiment of the present invention. Detailed Implementation

[0021] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0022] Please refer to Figure 1 , Figure 1 A flowchart illustrating an encrypted traffic analysis method provided in an embodiment of the present invention. The method may include: S101: Based on the acquired query stream, generate a query stream embedding using a pre-trained data packet byte evidence gating encoder; wherein the query stream consists of data packets from both directions of the same communication session.

[0023] The execution subject of this method can be an encrypted traffic analysis device with encrypted traffic processing and model inference capabilities, such as a server, network security device, or other electronic device; for ease of description, the encrypted traffic analysis device is used as the execution subject in the following description. In this embodiment, the query stream refers to the data stream to be analyzed in encrypted traffic. The data stream can refer to either the query stream or the training stream. The query stream adopts a bidirectional stream form, that is, data packets from two directions in the same communication session are merged into a single logical stream unit. The discrimination information of the encrypted session may exist simultaneously in data packets from both directions, for example, one direction carries request-side or client-side features, and the other direction carries response-side or server-side features; therefore, using a bidirectional stream as the basic input for subsequent gating encoding and nearest neighbor retrieval helps to avoid the separation of session request and response information caused by unidirectional processing. It should be noted that, based on the query stream, a query stream embedding is generated by a pre-trained data packet byte evidence gating encoder to represent the processing relationship between the query stream and the query stream embedding, and it is not limited to directly inputting the unprocessed original query stream into the data packet byte evidence gating encoder. In one implementation, input preprocessing can be performed on the query stream first, and then the resulting byte embedding representation and corresponding mask information can be sent to the data packet byte evidence gating encoder. This input preprocessing is used to form the encoder input and is not part of the window convolution, gating scoring, and aggregation processing within the evidence gating unit.

[0024] Furthermore, the above-mentioned query stream embedding, generated by a pre-trained packet byte evidence gating encoder based on the acquired query stream, may specifically include: classifying the original network traffic according to communication quintuples; merging and arranging data packets from two directions in the same communication session in chronological order to form a query stream; truncating or padding each data packet in the query stream to ensure that each data packet has the same byte length, and constructing a packet byte tensor based on the processed data packets; generating an effective packet mask based on the position of the actual data packets in the query stream within the packet byte tensor; mapping the byte values ​​in the packet byte tensor to a byte embedding representation using a byte embedding table; and inputting the byte embedding representation and the effective packet mask into the packet byte evidence gating encoder to obtain the query stream embedding; wherein, the effective packet mask is used to set the gating score corresponding to the padded data packets to zero in the evidence gating unit, and as a key padding mask in the context encoding unit to prevent the padded data packets from participating in attention calculation.

[0025] Specifically, the raw network traffic (which is encrypted traffic) can be categorized into communication quintuples. Data packets from both directions within the same communication session can be merged and arranged in chronological order to form query streams. Each query stream can retain up to P data packets, and each data packet can be truncated or padded to B bytes, thereby constructing a data packet byte tensor X. b ∈Z P × B Where P represents the maximum number of data packets retained in each data stream, B represents the unified byte length of each data packet, Z represents the set of integers, and X... b This represents a packet byte tensor composed of the raw byte values ​​of each packet. For query streams with fewer than P real packets, packet-level padding can be performed in positions not occupied by real packets. Simultaneously, a valid packet mask m∈{0,1} can be generated. P The p-th element m in the valid packet mask p Used to indicate whether the p-th packet position in the packet byte tensor corresponds to an actual packet in the original network traffic; m is the actual packet position. p It can be set to 1, and m can be used to fill the data packet position. p It can be 0. The effective packet mask can be derived from preprocessed metadata; its purpose is to mask padding locations, not to be used as an independent traffic feature view input model. Subsequently, X is processed through a byte embedding table. b The raw byte values ​​in the data are mapped to byte embedding representations. For a data packet, its B bytes are embedded to form the intra-packet byte embedding sequence corresponding to the data packet, which serves as the input for subsequent local window encoding.

[0026] In this embodiment, the data packet byte evidence gating encoder includes an evidence gating unit and a context encoding unit. The evidence gating unit scores and selects local byte evidence before data packet aggregation. It divides the byte sequence of each data packet in the data stream into local windows, extracts the encoded representation of each byte window, determines the corresponding gating score, and performs weighted aggregation of the encoded representations of each byte window based on the gating score to generate a summary vector for each data packet. The context encoding unit models the contextual relationships between data packets based on the summary vectors of each data packet, generating a stream embedding of the data stream. In this embodiment, the stream embedding uniformly refers to the normalized stream-level vector representation used for nearest neighbor retrieval. The data packet byte evidence gating encoder can be represented as a learnable encoder f. θ It maps the packet byte tensor and the effective packet mask to a stream embedding z: Where z represents the stream embedding, i.e., the normalized embedding vector used for nearest neighbor retrieval; f θX represents a data packet byte evidence gated encoder, where θ represents the learnable parameters of the encoder; b Let represent the packet byte tensor; m represent the effective packet mask; the L2 norm of the stream embedding z is denoted as ||z||2, and constraining it to 1 ensures that the stream embedding lies on the unit hypersphere, facilitating subsequent retrieval based on vector similarity. In this embodiment, the byte window can be divided in a fixed and non-overlapping manner; alternatively, a sliding window can be used to divide the byte window to capture local byte patterns across fixed window boundaries, without specific limitations.

[0027] Furthermore, the aforementioned evidence gating unit is used to divide the byte sequence of each data packet in the data stream into local windows, extract the encoded representation of each byte window and determine the corresponding gating score, and perform weighted aggregation of the encoded representation of each byte window based on the gating score to generate a digest vector for each data packet. Specifically, this may include: dividing the byte sequence of each data packet into multiple non-overlapping byte windows; performing convolutional encoding on each byte window respectively, and performing pooling and projection processing on the convolutional encoding results to obtain the encoded representation of each byte window; determining the corresponding gating score based on the encoded representation of each byte window; and performing normalized weighted aggregation of the encoded representation of each byte window in the same data packet based on each gating score to generate a digest vector for the data packet.

[0028] Specifically, the evidence gating unit can divide the byte sequence of each data packet into multiple non-overlapping byte windows. Let the uniform byte length of each data packet be B and the window size be S. Then each data packet can form W = B / S non-overlapping byte windows, where W represents the total number of windows and S represents the number of bytes contained in a single byte window. In other implementations, as long as byte windows for local evidence scoring can be formed, the specific window size is not limited. For each byte window, a lightweight two-layer one-dimensional convolutional network (CNN) can be used for convolutional encoding, and the convolutional encoding result can be processed by max pooling and projection to obtain the encoded representation h of the byte window. p , j Where p represents the packet index, j represents the window index within that packet, and h... p , j This represents the encoded representation of the j-th byte window in data packet p. Since this processing occurs before stream-level context aggregation, it avoids prematurely mixing handshake-type bytes, cryptographic payload bytes, and padding or redundant regions before the model has determined which local regions are highly informative. Cryptographic payload bytes typically have high entropy values, with many bytes exhibiting near-random or weakly informative characteristics, while discriminative patterns reflecting protocol implementation, handshake structure, encapsulation behavior, or application characteristics are often concentrated in only a few local regions. Therefore, the corresponding gating score can be calculated based on the encoded representation of each byte window: .

[0029] Among them, g p , j The gating score represents the window size of the j-th byte in data packet p; m p This represents the p-th element in the valid packet mask m; σ represents the Sigmoid activation function. g Represents a learnable gating scoring function; h p , j This represents the encoded representation of the corresponding byte window; Tg represents the gating temperature parameter, used to control the sharpness of the gating distribution. For padding data packets, since m p A gating score of 0 corresponds to a zero gating score for the byte window, preventing the padding data packet from participating in subsequent evidence aggregation. The gating score is not a post-classification attention result but directly participates in the formation of the data packet digest vector. Based on each gating score, the normalized weighted aggregation of the byte window encoding representations within the same data packet can be performed to obtain the data packet digest vector. .

[0030] Among them, u p Represents the digest vector of data packet p; W represents the total number of bytes in the window contained in the data packet; g p , j and h p , j Let represent the gating score and encoded representation of the j-th byte window, respectively; ε represents a small positive value used to prevent the denominator from being zero. Using normalized gating weighted aggregation ensures that the digest vectors of different data packets do not suffer from unnecessary amplitude bias due to varying numbers of active windows, and allows local discriminative information with higher gating scores to contribute more to the data packet digest, thereby reducing interference from encryption, padding, randomization, or redundant bytes on subsequent traffic representation.

[0031] Furthermore, the aforementioned context encoding unit is used to perform context encoding on the digest vector of each data packet to generate the stream embedding of the data stream. Specifically, it may include: projecting the digest vector of each data packet and combining the projected digest vector with the corresponding data packet position embedding to obtain a data packet representation sequence; performing context encoding on the data packet representation sequence through a self-attention encoding network with key-filled mask to obtain the context representation corresponding to the valid data packet; pooling and projecting the context representation corresponding to the valid data packet, and normalizing the projection result to obtain the stream embedding of the data stream.

[0032] Specifically, the gated packet digest is projected into the stream latent space, combined with learnable packet position embeddings, and input into a self-attention encoding network with a key-padded mask. The key-padded mask can be formed from the aforementioned valid packet mask, preventing padded packets from participating in the self-attention computation. The self-attention encoding network can, for example, employ a Transformer encoder to further model the contextual dependencies between different packets after local byte gating. Pooling and projecting the context representations corresponding to valid packets, followed by L2 normalization of the projection results, yields the stream embedding z. In one implementation, pooling can be average pooling. Since cross-packet context modeling occurs after local window gating, the self-attention encoding network can refine cross-packet relationships around the already filtered local information without directly assigning approximately uniform attention to all original bytes.

[0033] Furthermore, before generating the query stream embedding using a pre-trained data packet byte evidence gating encoder based on the acquired query stream, the process may further include: acquiring multiple labeled training streams and constructing training batches based on the labels of each training stream; inputting each training stream in the training batch into the data packet byte evidence gating encoder to be trained to generate the stream embedding corresponding to each training stream; for each anchor training stream in the training batch, determining positive sample training streams with the same labels as the anchor training streams and negative sample training streams with different labels based on the labels; determining the retrieval loss based on the similarity between the stream embedding of the anchor training stream and the stream embeddings of the positive and negative sample training streams, respectively; and adjusting the parameters of the data packet byte evidence gating encoder to be trained based on the retrieval loss to obtain the pre-trained data packet byte evidence gating encoder.

[0034] It should be noted that before performing query stream inference, the packet byte evidence gating encoder can undergo retrieval-oriented supervised contrastive training. This training does not use a fixed classification head as the primary prediction interface, but rather adjusts the geometry of the embedding space to ensure that training streams with the same label are close to each other, while training streams with different labels are far apart, allowing the retrieval itself to serve as the basis for subsequent classification decisions. Specifically, multiple labeled training streams can be obtained, and a class-balanced training batch can be constructed based on the labels of each training stream. For each anchor training stream in the training batch, positive sample training streams with the same label as the anchor training stream and negative sample training streams with different labels are determined based on the label. Class-balanced mini-batch sampling ensures that each anchor has multiple positive samples and sufficient negative samples in the training batch, reducing the risk of insufficient samples of the same type to form a stable neighborhood. After processing each training stream by the packet byte evidence gating encoder to be trained, the corresponding stream embedding is obtained, and the retrieval loss is determined based on the similarity between the anchor stream embedding and the positive and negative sample stream embeddings. The retrieval loss can be expressed as: .

[0035] Among them, L ret Indicates retrieval loss; The current training batch is represented by i, which represents the anchor sample index in the training batch; p represents the positive sample index with the same label as anchor i; P(i) represents the set of positive samples with the same label as anchor i; a represents the other sample indices involved in the denominator calculation; s ip s represents the temperature-scaled similarity between anchor point i and positive sample p. ia This represents the temperature-scaled similarity between anchor point i and sample a. We can let s ip =z i T z p / τ、s ia =z i T z a / τ, where z i z p and z a Let represent the stream embeddings corresponding to the anchor sample, positive sample, and sample a, respectively, and τ represent the contrast temperature parameter. By adjusting the parameters of the packet byte evidence gating encoder to be trained based on the retrieval loss, the labeled training stream can not only be used to determine class relationships during the training phase, but also be retained and reused as historical evidence in the nearest neighbor index during the inference phase.

[0036] Furthermore, before adjusting the parameters of the packet byte evidence gating encoder to be trained based on the retrieval loss to obtain the pre-trained packet byte evidence gating encoder, the process may further include: determining the evidence weight corresponding to each packet based on the gating score of each packet in each training stream; generating the evidence summary vector corresponding to each training stream based on the evidence weight and summary vector corresponding to each packet; determining the representation difference between the evidence summary vector of each training stream and the corresponding stream embedding, and determining the consistency loss based on the representation difference; correspondingly, adjusting the parameters of the packet byte evidence gating encoder to be trained based on the retrieval loss to obtain the pre-trained packet byte evidence gating encoder includes: adjusting the parameters of the packet byte evidence gating encoder to be trained based on the retrieval loss and the consistency loss to obtain the pre-trained packet byte evidence gating encoder.

[0037] Specifically, to ensure that the target byte window of the subsequent output remains relevant to the stream embedding used for nearest neighbor retrieval, evidence alignment constraints can be introduced during the training phase. First, packet-level evidence weights can be determined based on the gating scores of all byte windows in each packet: .

[0038] Where, αp The normalized evidence weight of packet p is represented by p; P represents the total number of packet positions in a data stream; W represents the total number of byte windows for each packet; p′ represents the packet index used when summing all packet positions; g p , j ε represents the gated fraction of the corresponding byte window; ε represents a small positive quantity used to prevent the denominator from being zero.

[0039] Without introducing packet location embedding and without using context coding units, evidence digest vectors can be constructed solely from gated evidence: .

[0040] Among them, z evi This represents an evidence summary vector formed solely from gated evidence; 2 represents the L2 normalization operation; α p The normalized evidence weight of data packet p; r p The gated window average projection representation of data packet p can be derived from the data packet digest vector u. p The projection is obtained and is located before adding the packet location embedding and entering the self-attention encoding network.

[0041] Then, the complete stream embedding z and the evidence summary vector z can be used as a basis. evi The difference in representation between them determines the consistency loss of the stream-packet data: .

[0042] Where Lcons represents the stream-packet consistency loss; cos(z,z) evi ) represents the stream embedding z and the evidence summary vector z evi The cosine similarity between them. By reducing this consistency loss, the local window selected by the gating score can be constrained to retain the information used to form the nearest neighbor retrieval representation, so that the gating selection not only acts as a sparse mask, but also corresponds to the retrieval decision criteria. Stream-data packet consistency loss can be applied to the stream embedding z and the evidence summary vector z. evi Simultaneous optimization can be performed; or z or z can be optimized. evi One side of the process uses gradient stopping to avoid simultaneous adjustments at both ends of the consistency constraint, which could cause training instability.

[0043] Further, before adjusting the parameters of the to-be-trained packet byte evidence gated encoder according to the retrieval loss to obtain the pre-trained packet byte evidence gated encoder, the method may specifically further include: determining a gated sparsity loss according to the gated score of each byte window corresponding to the valid packet in each training flow, where the valid packet is a packet that actually exists in the original network traffic; determining a gated smoothness loss according to the difference between the gated scores corresponding to adjacent byte windows in the same valid packet. Correspondingly, adjusting the parameters of the to-be-trained packet byte evidence gated encoder according to the retrieval loss to obtain the pre-trained packet byte evidence gated encoder may include: adjusting the parameters of the to-be-trained packet byte evidence gated encoder according to the retrieval loss, the gated sparsity loss and the gated smoothness loss to obtain the pre-trained packet byte evidence gated encoder.

[0044] Specifically, a sparsity constraint and a smoothness constraint may also be set for the gated distribution. Let Ω={(p,j):m p =1,1≤j≤W} represent the set of all valid packet byte window positions, and ΩΔ={(p,j):m p =1,1≤j<W} represent the position set corresponding to adjacent byte window pairs in the same valid packet, then the gated sparsity loss and the gated smoothness loss can be expressed as: .

[0045] where Lsp represents the gated sparsity loss, Lsm represents the gated smoothness loss; |Ω| and |ΩΔ| represent the number of elements in the set Ω and the set ΩΔ respectively; g p , j and g p , j+1 represent the gated scores of adjacent byte windows in the same valid packet. The gated sparsity loss is used to suppress a large number of byte windows from having high gated scores at the same time, so as to promote the evidence to be concentrated in fewer local regions; the gated smoothness loss is used to suppress excessive jump of the gated scores between adjacent windows, so as to reduce fragmented evidence patterns.

[0046] When the retrieval loss, the flow-packet consistency loss, the gated sparsity loss and the gated smoothness loss are adopted at the same time, the total loss can be expressed as: .

[0047] where L represents the total loss; L ret represents the retrieval loss; L cons represents the flow-packet consistency loss; L sp represents the gated sparsity loss; L sm represents the gated smoothness loss; λ cons , λ sp and λ smThese represent the weight coefficients of the stream-data packet consistency loss term, the gated sparsity loss term, and the gated smoothness loss term, respectively. Adjusting the parameters of the data packet byte evidence gated encoder to be trained based on the overall loss can balance the formation of the retrieval embedding space, the consistency between gated evidence and the retrieval representation, and the compactness and local continuity of the evidence. A pre-trained data packet byte evidence gated encoder can be obtained when a preset training termination condition is met. The preset training termination condition may include, for example, reaching a preset number of training rounds, the retrieval macro F1 not improving for several consecutive rounds on the validation set, or the retrieval loss and the evidence alignment-related loss reaching at least one of the preset convergence conditions. The above training termination conditions are merely examples and do not limit the specific stopping criteria.

[0048] S102: Calculate the similarity between the query stream embedding and the stream embedding in the nearest neighbor index, and determine the target nearest neighbor training stream from the training stream corresponding to the nearest neighbor index based on the similarity; wherein, the nearest neighbor index is constructed from the stream embedding obtained by encoding the labeled training stream through the data packet byte evidence gating encoder.

[0049] Specifically, after the data packet byte evidence gating encoder is trained, the labeled training stream can be used to generate corresponding stream embeddings z. i After associating the training stream identifier, label, and stream embedding, a nearest neighbor index (vector library) is constructed. For the query stream q to be analyzed, the query stream embedding z is obtained through a byte-evidence gated encoder of the same data packet. q This ensures that the query stream embedding and the training stream embedding in the nearest neighbor index are in the same embedding space. In one implementation, since the stream embeddings have already undergone L2 normalization, cosine similarity can be used to calculate the similarity between the query stream and the training stream in the index. .

[0050] Where sim(q,i) represents the similarity between the query stream q and the i-th training stream in the nearest neighbor index; z q Indicates the stream embedding of query stream q; z i Let sim(q,i) represent the embedding of the i-th training stream; the superscript T denotes the vector transpose. The training streams can be sorted from highest to lowest according to sim(q,i), and one or more of the top-ranked training streams can be identified as the target nearest neighbor training streams. Thus, the classification decision of the query stream can be mapped to a specific historical training stream, rather than simply forming an isolated category output. Precise cosine similarity can be used for nearest neighbor retrieval; while maintaining the query stream and training stream in the same embedding space, dot product similarity, Euclidean distance corresponding to the cosine relationship under the same norm condition, or an approximate nearest neighbor retrieval ANN can also be used to reduce inference latency when the nearest neighbor index size is large.

[0051] S103: Determine the classification result of the query stream based on the label of the target nearest neighbor training stream, and determine the target byte window from the query stream and the target nearest neighbor training stream respectively based on the gating score, and output the target byte window as evidence item of the classification result.

[0052] In one implementation, the label of the target nearest neighbor training stream with the highest similarity can be used as the classification result of the query stream. When multiple target nearest neighbor training streams are returned, the classification result can also be determined based on the labels of multiple target nearest neighbor training streams, and a class consistency score can be calculated. The class consistency score can be the proportion of the number of training streams belonging to the majority label in the returned target nearest neighbor training streams to the total number of target nearest neighbor training streams, used to represent the degree of support of the neighboring region for the current classification result. For the query stream and the retrieved target nearest neighbor training streams, the gating score g of the byte window in each valid data packet can be used. p,j The data is sorted, and one or more byte windows with higher scores are identified as target byte windows and output as evidence items. Each evidence item may include a packet index, byte range, gating score, and corresponding byte window content. Since the gating score directly participates in the formation of the packet digest vector and further affects the stream embedding, the local byte window output based on the gating score can be associated with the local information forming the retrieval representation. Therefore, this embodiment can simultaneously output the classification result of the query stream, the target nearest neighbor training stream as a historical reference, and the localized target byte window evidence when analyzing the query stream. This allows analysts to not only know the category to which the query stream belongs, but also to view historical cases similar to the query stream and local byte regions with high discriminative contributions in the query stream and historical nearest neighbors, thereby improving the effectiveness, checkability, and verifiability of the encrypted traffic analysis results.

[0053] The encrypted traffic analysis method provided by this invention comprises the following steps: S101: Based on the acquired query flow, a query flow embedding is generated using a pre-trained data packet byte evidence gating encoder; wherein the query flow consists of data packets from two directions within the same communication session; S102: The similarity between the query flow embedding and the flow embedding in the nearest neighbor index is calculated, and a target nearest neighbor training flow is determined from the training flow corresponding to the nearest neighbor index based on the similarity; wherein the nearest neighbor index is constructed from the flow embedding obtained by encoding the labeled training flow using a data packet byte evidence gating encoder; S103: The classification result of the query flow is determined based on the label of the target nearest neighbor training flow, and a target byte window is determined from both the query flow and the target nearest neighbor training flow based on the gating score, and the target byte window is output as evidence item of the classification result. This invention constructs a query stream from data packets in both directions of the same communication session and divides the byte sequence of each data packet into local windows. A weighted aggregation of the encoded representations of each byte window is performed using gating scores, ensuring that local byte information with high discriminative value contributes significantly to the data packet digest, thereby reducing interference from encryption, padding, and redundant bytes on the traffic representation. Simultaneously, a stream embedding is generated based on the digest vector of each data packet. Labeled target nearest neighbor training streams are retrieved using stream embedding similarity to determine the classification result. This allows existing labeled training streams to serve as reusable historical nearest neighbor evidence, rather than merely fitting classification boundaries, reducing reliance on large-scale labeled data. Furthermore, the target byte windows in the query stream and target nearest neighbor training stream are determined based on the gating scores involved in data packet digest formation and output as evidence items. This enables the classification result to simultaneously correlate historical nearest neighbor and local byte evidence, improving the effectiveness of encrypted traffic analysis and the auditability of the analysis results.

[0054] This invention addresses the problem that existing encrypted traffic classifiers, due to their reliance on large amounts of labeled data, neglect of sparse evidence, and lack of auditability, are difficult to deploy effectively in real-world low-label operation scenarios. It proposes an evidence-based retrieval framework. For example... Figure 2 As shown, Figure 2 This invention provides a schematic diagram of the overall system architecture of an encrypted traffic analysis method, which may specifically include: a data packet byte evidence gating encoder (i.e., Figure 2 The system includes a packet gating encoder, a supervised contrastive learning module (which includes contrastive learning and evidence alignment and regularization), a retrieval-based inference module, and a retrieval-based evidence interpretation module. The raw network traffic consists of individual packets (…). The input data packet byte evidence gating encoder first divides the byte sequence of each data packet into local windows, extracts the encoded representation of each byte window, and calculates the gating score. Based on the gating score, the window representations are weighted and aggregated to output the summary vector of each data packet. Subsequently, the context encoding unit of the data packet byte evidence gating encoder applies position embedding to the summary vector of each data packet, and then passes it through a self-attention encoding network (i.e., ... Figure 2 The packet self-attention mechanism models the contextual dependencies between packets and performs pooling and normalization on the encoding results corresponding to valid packets, ultimately outputting a normalized stream embedding of the data stream (i.e., ...). Figure 2 (flow representation in the code). During the training phase, the encoder's optimization is constrained by multiple loss functions: retrieval loss (i.e., ... Figure 2 The contrastive loss is used to bring similar sample embeddings closer together and push dissimilar sample embeddings further apart, shaping an embedding space geometry suitable for nearest neighbor retrieval. The stream-data packet consistency loss is used to constrain the evidence summary vector, which consists only of gated evidence windows, to align with the complete stream embedding in cosine space, ensuring that the information relied upon by the retrieval decision is consistent with the ultimately exposed evidence. The gated sparsity loss and gated smoothness loss are used to limit the number of gated activation windows and penalize drastic changes in the gate scores of adjacent windows, respectively. After training, all labeled training streams are encoded by the data packet byte evidence gate encoder to construct an embedding index (i.e., the nearest neighbor index). During inference, the query stream passes through the same data packet byte evidence gate encoder to obtain the query embedding. By calculating and sorting the similarity with each embedding in the index, the target nearest neighbor training stream and its label are returned as the classification result, and the byte window with the highest gate score is output as the evidence item. Therefore, the overall concept of this invention is to transform encrypted traffic analysis from a single closed-set classification prediction to an evidence-based encrypted traffic analysis retrieval paradigm: It shapes an embedding space through supervised contrastive learning, allowing labeled flows to serve as reusable nearest-neighbor evidence, rather than merely fitting classification boundaries, thus overcoming the dependence of traditional classifiers on large-scale labeled data; it introduces a packet byte window gating mechanism, explicitly selecting a local discriminative byte window before packet aggregation to suppress the influence of encryption, padding, or redundant regions, solving the problem of useful signal dilution caused by implicit processing of sparse evidence in existing technologies; and through evidence alignment regularization, it associates the output evidence with the retrieval embedding, ultimately returning historical nearest-neighbor flows, neighborhood consistency, and localized packet byte evidence during inference, simultaneously addressing the technical challenges of label dependence, evidence sparsity, and unauditable decisions. The technical solution of this invention is based on a core invariant: the representation used for retrieval must be formed from the same packet byte regions subsequently exposed as evidence.

[0055] The encrypted traffic analysis device provided in the embodiments of the present invention will be described below. The encrypted traffic analysis device described below can be referred to in correspondence with the encrypted traffic analysis method described above.

[0056] Please refer to the details. Figure 3 , Figure 3 A schematic diagram of an encrypted traffic analysis device provided in an embodiment of the present invention may include: The encoding module 100 is used to generate a query stream embedding based on the acquired query stream using a pre-trained data packet byte evidence gating encoder; wherein the query stream consists of data packets from two directions within the same communication session; The retrieval module 200 is used to calculate the similarity between the query stream embedding and the stream embedding in the nearest neighbor index, and determine the target nearest neighbor training stream from the training stream corresponding to the nearest neighbor index based on the similarity; wherein, the nearest neighbor index is constructed from the stream embedding obtained by encoding the labeled training stream through the data packet byte evidence gating encoder; The output module 300 is used to determine the classification result of the query stream based on the label of the target nearest neighbor training stream, and to determine the target byte window from the query stream and the target nearest neighbor training stream respectively based on the gating score, and output the target byte window as evidence item of the classification result; The data packet byte evidence gating encoder includes an evidence gating unit and a context encoding unit. The evidence gating unit is used to divide the byte sequence of each data packet in the data stream into local windows, extract the encoded representation of each byte window and determine the corresponding gating score, and perform weighted aggregation of the encoded representation of each byte window according to the gating score to generate a digest vector of each data packet. The context encoding unit is used to perform context encoding on the digest vector of each data packet to generate the stream embedding of the data stream.

[0057] Based on any of the above embodiments, the encoding module 100 may include: A partitioning unit is used to divide the byte sequence of each data packet into multiple non-overlapping byte windows; The first encoding unit is used to perform convolutional encoding on each of the byte windows respectively, and to perform pooling and projection processing on the convolutional encoding results to obtain the encoded representation of each of the byte windows; The gate score determination unit is used to determine the corresponding gate score based on the encoded representation of each byte window; An aggregation unit is used to perform normalized weighted aggregation of the encoded representations of each byte window in the same data packet based on the gating scores, and generate a digest vector of the data packet.

[0058] Based on any of the above embodiments, the encoding module 100 may include: The projection unit is used to project the digest vector of each data packet, and combine the projected digest vector with the corresponding data packet position embedding to obtain the data packet representation sequence; The second encoding unit is used to perform context encoding on the data packet representation sequence through a self-attention encoding network with a key-filled mask to obtain the context representation corresponding to the valid data packet; The normalization unit is used to pool and project the context representation corresponding to the valid data packet, and normalize the projection result to obtain the stream embedding of the data stream.

[0059] Based on any of the above embodiments, the encrypted traffic analysis device may further include: The training data acquisition module is used to acquire multiple labeled training streams and construct training batches based on the labels of each training stream. The training data input module is used to input each training stream in the training batch into the data packet byte evidence gating encoder to be trained, and generate the stream embedding corresponding to each training stream. The positive and negative sample determination module is used to determine, based on the labels, positive sample training streams that have the same labels as the anchor training streams and negative sample training streams that have different labels from the anchor training streams for each anchor training stream in the training batch. The retrieval loss calculation module is used to determine the retrieval loss based on the similarity between the flow embedding of the anchor training stream and the flow embedding of the positive sample training stream and the negative sample training stream, respectively. The parameter tuning module is used to adjust the parameters of the data packet byte evidence gating encoder to be trained according to the retrieval loss, so as to obtain the pre-trained data packet byte evidence gating encoder.

[0060] Based on any of the above embodiments, the encrypted traffic analysis device may further include: The weight determination module is used to determine the evidence weight corresponding to each data packet based on the gating score of each data packet in each training stream. The evidence summary vector generation module is used to generate evidence summary vectors corresponding to each training stream based on the evidence weights and summary vectors corresponding to each data packet. A consistency loss determination module is used to determine the representation difference between the evidence summary vector of each training stream and the corresponding stream embedding, and to determine the consistency loss based on the representation difference; Correspondingly, the parameter tuning module may include: The first parameter tuning unit is used to adjust the parameters of the data packet byte evidence gating encoder to be trained according to the retrieval loss and the consistency loss, so as to obtain the pre-trained data packet byte evidence gating encoder.

[0061] Based on any of the above embodiments, the encrypted traffic analysis device may further include: The gated sparsity loss determination module is used to determine the gated sparsity loss based on the gate score of each byte window corresponding to the valid data packets in each training stream; the valid data packets are the data packets that actually exist in the original network traffic; The gating smoothing loss determination module is used to determine the gating smoothing loss based on the difference between the gating scores corresponding to adjacent byte windows in the same valid data packet. Correspondingly, the parameter tuning module may include: The second parameter tuning unit is used to adjust the parameters of the data packet byte evidence gating encoder to be trained according to the retrieval loss, the gating sparsity loss and the gating smoothness loss, so as to obtain the pre-trained data packet byte evidence gating encoder.

[0062] Based on the above embodiments, the encoding module 100 may include: The first processing unit is used to classify the original network traffic according to the communication quintuple, and to merge and arrange the data packets in two directions in the same communication session in chronological order to form the query stream; The second processing unit is used to truncate or pad each data packet in the query stream so that each data packet has the same byte length, and to construct a data packet byte tensor based on the processed data packets. The third processing unit is used to generate a valid data packet mask based on the position of the real data packet in the query stream within the data packet byte tensor. The fourth processing unit is used to map the byte values ​​in the data packet byte tensor to byte embedding representations through a byte embedding table; An input unit is used to input the byte embedding representation and the effective data packet mask into the data packet byte evidence gating encoder to obtain the query stream embedding; wherein, the effective data packet mask is used to set the gating score corresponding to the padding data packet to zero in the evidence gating unit, and as a key padding mask in the context encoding unit so that the padding data packet does not participate in attention calculation.

[0063] It should be noted that the order of the modules and units in the above-mentioned encrypted traffic analysis device can be changed without affecting the logic.

[0064] An encrypted traffic analysis device provided in this embodiment of the invention includes an encoding module 100, which generates a query stream embedding based on an acquired query stream using a pre-trained data packet byte evidence gating encoder; wherein the query stream consists of data packets from two directions within the same communication session; a retrieval module 200, which calculates the similarity between the query stream embedding and the stream embedding in the nearest neighbor index, and determines a target nearest neighbor training stream from the training stream corresponding to the nearest neighbor index based on the similarity; wherein the nearest neighbor index is constructed from the stream embedding obtained by encoding the labeled training stream using the data packet byte evidence gating encoder; and an output module 300, which determines the query stream embedding based on the label of the target nearest neighbor training stream. The classification results of the query stream are used to determine target byte windows from the query stream and the target nearest neighbor training stream based on the gating scores. The target byte windows are then output as evidence items of the classification results. The data packet byte evidence gating encoder includes an evidence gating unit and a context encoding unit. The evidence gating unit is used to divide the byte sequence of each data packet in the data stream into local windows, extract the encoded representation of each byte window, determine the corresponding gating score, and perform weighted aggregation of the encoded representation of each byte window based on the gating score to generate a summary vector for each data packet. The context encoding unit is used to perform context encoding on the summary vector of each data packet to generate the stream embedding of the data stream. This invention constructs a query stream from data packets in both directions of the same communication session and divides the byte sequence of each data packet into local windows. A weighted aggregation of the encoded representations of each byte window is performed using gating scores, ensuring that local byte information with high discriminative value contributes significantly to the data packet digest, thereby reducing interference from encryption, padding, and redundant bytes on the traffic representation. Simultaneously, a stream embedding is generated based on the digest vector of each data packet. Labeled target nearest neighbor training streams are retrieved using stream embedding similarity to determine the classification result. This allows existing labeled training streams to serve as reusable historical nearest neighbor evidence, rather than merely fitting classification boundaries, reducing reliance on large-scale labeled data. Furthermore, the target byte windows in the query stream and target nearest neighbor training stream are determined based on the gating scores involved in data packet digest formation and output as evidence items. This enables the classification result to simultaneously correlate historical nearest neighbor and local byte evidence, improving the effectiveness of encrypted traffic analysis and the auditability of the analysis results.

[0065] The encrypted traffic analysis device provided in the embodiments of the present invention will be described below. The encrypted traffic analysis device described below can be referred to in correspondence with the encrypted traffic analysis method described above.

[0066] Please refer to Figure 4 , Figure 4 A schematic diagram of an encrypted traffic analysis device provided in an embodiment of the present invention may include: Memory 10 is used to store computer programs; Processor 20 is used to execute computer programs to implement the encrypted traffic analysis method described above.

[0067] The memory 10, processor 20, and communication interface 31 all communicate with each other through the communication bus 32.

[0068] In this embodiment of the invention, the memory 10 is used to store one or more programs. The programs may include program code, which includes computer operation instructions. In this embodiment of the invention, the memory 10 may store programs for implementing the following functions: Based on the acquired query stream, a query stream embedding is generated using a pre-trained data packet byte evidence gating encoder; wherein the query stream consists of data packets from both directions of the same communication session; Calculate the similarity between the query stream embedding and the stream embedding in the nearest neighbor index, and determine the target nearest neighbor training stream from the training stream corresponding to the nearest neighbor index based on the similarity; wherein, the nearest neighbor index is constructed from the stream embedding obtained by encoding the labeled training stream through a data packet byte evidence gating encoder; The classification result of the query stream is determined based on the label of the target nearest neighbor training stream, and the target byte window is determined from the query stream and the target nearest neighbor training stream respectively based on the gating score. The target byte window is output as evidence item of the classification result. The data packet byte evidence gating encoder includes an evidence gating unit and a context encoding unit. The evidence gating unit is used to divide the byte sequence of each data packet in the data stream into local windows, extract the encoded representation of each byte window and determine the corresponding gating score, and perform weighted aggregation of the encoded representation of each byte window according to the gating score to generate the digest vector of each data packet. The context encoding unit is used to perform context encoding on the digest vector of each data packet to generate the stream embedding of the data stream.

[0069] In one possible implementation, the memory 10 may include a program storage area and a data storage area, wherein the program storage area may store the operating system and applications required for at least one function; and the data storage area may store data created during use.

[0070] Furthermore, memory 10 may include read-only memory and random access memory, providing instructions and data to the processor. A portion of the memory may also include NVRAM. The memory stores operating systems and operating instructions, executable modules, or data structures, or subsets thereof, or extended sets thereof, wherein the operating instructions may include various operating instructions for implementing various operations. The operating system may include various system programs for implementing various basic tasks and handling hardware-based tasks.

[0071] Processor 20 can be a central processing unit (CPU), an application-specific integrated circuit, a digital signal processor, a field-programmable gate array, or other programmable logic device. Processor 20 can be a microprocessor or any conventional processor. Processor 20 can call programs stored in memory 10.

[0072] Communication interface 31 can be an interface for the communication module, used to connect with other devices or systems.

[0073] Of course, it should be noted that, Figure 4 The structure shown does not constitute a limitation on the encrypted traffic analysis device in the embodiments of the present invention. In practical applications, the encrypted traffic analysis device may include devices that are more complex than those described above. Figure 4 More or fewer components as shown, or combinations of certain components.

[0074] It is understood that if the encrypted traffic analysis method in the above embodiments is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the current technology, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and executes all or part of the steps of the methods in the various embodiments of the present invention. The aforementioned storage medium includes: USB flash drive, mobile hard drive, read-only memory (ROM), random access memory (RAM), electrically erasable programmable ROM, register, hard disk, removable disk, CD-ROM, magnetic disk, or optical disk, and other media capable of storing program code.

[0075] Based on this, embodiments of the present invention also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the encrypted traffic analysis method described above.

[0076] The following describes a computer program product provided by an embodiment of this application. The computer program product described below can be referred to in conjunction with other embodiments described herein.

[0077] A computer program product includes a computer program / instructions that, when executed by a processor, implement the steps of the aforementioned disclosed encrypted traffic analysis method.

[0078] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0079] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0080] Finally, it should be noted that in this document, relationships such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0081] The encrypted traffic analysis method, apparatus, device, and readable storage medium provided by the present invention have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A method for analyzing encrypted traffic, characterized in that, include: Based on the acquired query stream, a query stream embedding is generated using a pre-trained data packet byte evidence gating encoder; wherein the query stream consists of data packets from two directions within the same communication session; Calculate the similarity between the query stream embedding and the stream embedding in the nearest neighbor index, and determine the target nearest neighbor training stream from the training stream corresponding to the nearest neighbor index based on the similarity; wherein, the nearest neighbor index is constructed from the stream embedding obtained by encoding the labeled training stream through the data packet byte evidence gating encoder; The classification result of the query stream is determined based on the label of the target nearest neighbor training stream, and the target byte window is determined from the query stream and the target nearest neighbor training stream respectively based on the gating score. The target byte window is output as evidence item of the classification result. The data packet byte evidence gating encoder includes an evidence gating unit and a context encoding unit. The evidence gating unit is used to divide the byte sequence of each data packet in the data stream into local windows, extract the encoded representation of each byte window and determine the corresponding gating score, and perform weighted aggregation of the encoded representation of each byte window according to the gating score to generate a digest vector of each data packet. The context encoding unit is used to perform context encoding on the digest vector of each data packet to generate the stream embedding of the data stream.

2. The encrypted traffic analysis method according to claim 1, characterized in that, The evidence gating unit is used to divide the byte sequence of each data packet in the data stream into local windows, extract the encoded representation of each byte window and determine the corresponding gating score, and perform weighted aggregation of the encoded representation of each byte window according to the gating score to generate a digest vector for each data packet, including: Divide the byte sequence of each data packet into multiple non-overlapping byte windows; Each byte window is convolutionally encoded, and the convolutional encoding results are pooled and projected to obtain the encoded representation of each byte window. The corresponding gating score is determined based on the encoded representation of each byte window; Based on the gating scores, the encoded representations of each byte window in the same data packet are normalized and weighted, and a digest vector of the data packet is generated.

3. The encrypted traffic analysis method according to claim 1, characterized in that, The context encoding unit is used to perform context encoding on the digest vector of each data packet to generate the stream embedding of the data stream, including: The digest vector of each data packet is projected, and the projected digest vector is combined with the corresponding data packet position embedding to obtain the data packet representation sequence; The context representation sequence of the data packet is context-encoded by a self-attention coding network with key-filled mask to obtain the context representation corresponding to the valid data packet; The context representation corresponding to the valid data packet is pooled and projected, and the projection result is normalized to obtain the stream embedding of the data stream.

4. The encrypted traffic analysis method according to any one of claims 1 to 3, characterized in that, Before generating the query stream embedding using a pre-trained packet byte evidence gating encoder based on the acquired query stream, the process also includes: Obtain multiple labeled training streams and construct training batches based on the labels of each training stream; Each training stream in the training batch is input into the data packet byte evidence gating encoder to be trained to generate the stream embedding corresponding to each training stream; For each anchor training stream in the training batch, positive sample training streams with the same label as the anchor training stream and negative sample training streams with different labels are determined according to the labels. The retrieval loss is determined based on the similarity between the flow embedding of the anchor training stream and the flow embeddings of the positive sample training stream and the negative sample training stream, respectively. The parameters of the data packet byte evidence gating encoder to be trained are adjusted according to the retrieval loss to obtain the pre-trained data packet byte evidence gating encoder.

5. The encrypted traffic analysis method according to claim 4, characterized in that, Before adjusting the parameters of the packet byte evidence gating encoder to be trained according to the retrieval loss to obtain the pre-trained packet byte evidence gating encoder, the method further includes: The evidence weight corresponding to each data packet is determined based on the gating score of each data packet in each training stream. Based on the evidence weight and summary vector corresponding to each data packet, generate the evidence summary vector corresponding to each training stream; Determine the representation difference between the evidence summary vector of each training stream and the corresponding stream embedding, and determine the consistency loss based on the representation difference; Accordingly, adjusting the parameters of the data packet byte evidence gating encoder to be trained based on the retrieval loss to obtain the pre-trained data packet byte evidence gating encoder includes: The parameters of the packet byte evidence gating encoder to be trained are adjusted according to the retrieval loss and the consistency loss to obtain the pre-trained packet byte evidence gating encoder.

6. The encrypted traffic analysis method according to claim 4, characterized in that, Before adjusting the parameters of the packet byte evidence gating encoder to be trained according to the retrieval loss to obtain the pre-trained packet byte evidence gating encoder, the method further includes: The gated sparsity loss is determined based on the gate score of each byte window corresponding to the valid data packets in each training stream; the valid data packets are the actual data packets that exist in the original network traffic. The gate smoothing loss is determined based on the difference between the gate scores corresponding to adjacent byte windows in the same valid data packet. Accordingly, adjusting the parameters of the data packet byte evidence gating encoder to be trained based on the retrieval loss to obtain the pre-trained data packet byte evidence gating encoder includes: The parameters of the data packet byte evidence gating encoder to be trained are adjusted according to the retrieval loss, the gating sparsity loss and the gating smoothness loss to obtain the pre-trained data packet byte evidence gating encoder.

7. The encrypted traffic analysis method according to claim 1, characterized in that, Based on the acquired query stream, a query stream embedding is generated using a pre-trained packet byte evidence gating encoder, including: The original network traffic is categorized according to the communication quintuple, and the data packets from two directions in the same communication session are merged and arranged in chronological order to form the query stream; Each data packet in the query stream is truncated or padded to ensure that each data packet has the same byte length, and a data packet byte tensor is constructed based on the processed data packets. A valid data packet mask is generated based on the position of the actual data packet in the query stream within the data packet byte tensor. The byte values ​​in the data packet byte tensor are mapped to byte embedding representations using a byte embedding table; The byte embedding representation and the effective data packet mask are input into the data packet byte evidence gating encoder to obtain the query stream embedding; wherein, the effective data packet mask is used to set the gating score corresponding to the padding data packet to zero in the evidence gating unit, and as a key padding mask in the context encoding unit so that the padding data packet does not participate in attention calculation.

8. An encrypted traffic analysis device, characterized in that, include: An encoding module is used to generate a query stream embedding based on the acquired query stream using a pre-trained data packet byte evidence gating encoder; wherein the query stream consists of data packets from two directions within the same communication session; The retrieval module is used to calculate the similarity between the query stream embedding and the stream embedding in the nearest neighbor index, and determine the target nearest neighbor training stream from the training stream corresponding to the nearest neighbor index based on the similarity; wherein, the nearest neighbor index is constructed from the stream embedding obtained by encoding the labeled training stream through the data packet byte evidence gating encoder; The output module is used to determine the classification result of the query stream based on the label of the target nearest neighbor training stream, and to determine the target byte window from the query stream and the target nearest neighbor training stream respectively based on the gating score, and output the target byte window as evidence item of the classification result; The data packet byte evidence gating encoder includes an evidence gating unit and a context encoding unit. The evidence gating unit is used to divide the byte sequence of each data packet in the data stream into local windows, extract the encoded representation of each byte window and determine the corresponding gating score, and perform weighted aggregation of the encoded representation of each byte window according to the gating score to generate a digest vector of each data packet. The context encoding unit is used to perform context encoding on the digest vector of each data packet to generate the stream embedding of the data stream.

9. An encrypted traffic analysis device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the encrypted traffic analysis method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when loaded and executed by a processor, implement the encrypted traffic analysis method as described in any one of claims 1 to 7.