A method for classifying encrypted traffic based on adaptive fusion of packet-level protocol semantics and behavioral sequences
By constructing a hierarchical classification framework and combining packet-level protocol semantic learning with adaptive fusion of behavior sequences, the problem of traffic classification under strong encryption conditions is solved, achieving efficient classification under limited observable information and adapting to the needs of different traffic samples and tasks.
Patent Information
- Application Number
- CN202611447008.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-17
- Publication Date
- 2026-11-17
AI Technical Summary
Under strong encryption protocols, existing technologies struggle to learn stable traffic representations with discriminative capabilities from limited observable information. Furthermore, they are unable to coordinate the contributions of protocol semantic information and behavioral sequence information while preserving packet-level information correspondence and inter-packet communication order, resulting in insufficient effectiveness and adaptability of encrypted traffic classification.
A hierarchical classification framework based on the adaptive fusion of packet-level protocol semantics and behavioral sequences is constructed. Through packet-level protocol semantic learning, packet-level semantic-behavioral feature adaptive fusion, and flow-level sequence modeling, self-supervised pre-training is performed using unlabeled network traffic to generate and fuse protocol semantic representations and behavioral feature representations, adapting to the needs of different traffic samples and classification tasks.
It improves the accuracy and generalization ability of encrypted traffic classification, reduces the dependence on labeled data, and enhances the model's adaptability and classification performance in different downstream tasks.
Smart Images

Figure CN123123487A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of network security, network traffic analysis, and deep learning, specifically to an encrypted traffic classification method based on the adaptive fusion of packet-level protocol semantics and behavioral sequences. Background Technology
[0002] With the continuous growth of internet communication and the increasing demand for network security and privacy protection, transport layer security protocols and encrypted transmission mechanisms have been widely used in network communication. In traditional TLS communication, passive observation devices can still obtain server names, cipher suites, certificates, and other handshake information; TLS 1.3 further encrypts some handshake messages and server authentication information; the Encrypted Client Hello (ECH) mechanism further hides the server name and other sensitive client parameters; QUIC further combines transmission control functions with encryption mechanisms to protect most frame content, packet numbers, and some header information.
[0003] These changes not only render plaintext content at the application layer inaccessible, but also render some handshake metadata and protocol control information, which could previously be used for service identification, invisible or only observable to a limited extent. In such strongly encrypted communication scenarios, some fields at the network and transport layers, the outer encapsulation information of the encryption protocol, and behavioral information such as packet length, transmission direction, and packet order can still be passively obtained. At the same time, the observability and discriminative value of different types of information will vary depending on the protocol type, protection configuration, communication stage, and downstream classification task.
[0004] To reduce reliance on plaintext communication, existing methods primarily extract traffic features from information such as flow-level statistical characteristics, raw bytes, and packet behavior sequences. Statistical feature-based methods typically rely on expert knowledge and manual feature design; end-to-end deep learning methods can automatically learn representations from raw traffic data, but usually require a large number of labeled samples. Pre-training methods, on the other hand, learn general representations on large-scale unlabeled traffic data and fine-tune them for downstream classification tasks, thereby reducing the model's dependence on labeled data.
[0005] However, under strong encryption, observable upper-layer bytes are gradually replaced by ciphertext bytes, weakening the correspondence between the original byte pattern and application semantics. If protocol fields, ciphertext content, and other data are treated as uniform byte sequences, the model struggles to learn a semantic representation with stable discriminative capabilities from a large number of ciphertext bytes. Although behavioral information such as packet length, transmission direction, and observable sequence are still observable after payload encryption and can describe the data exchange process between the communicating parties, relying solely on behavioral sequences is insufficient to fully reflect the semantics within the data packets. Furthermore, features such as time intervals are easily affected by network paths, queuing delays, and changes in the acquisition environment.
[0006] To improve traffic representation capabilities, existing technologies have extracted observable information from various perspectives, such as protocol structure, traffic statistics, and packet behavior, and improved classification performance through joint representation learning. However, under different protocols, protection configurations, and classification tasks, the observability and discriminative role of various types of information are inconsistent. Predetermined or coarse-grained feature combinations are difficult to fully coordinate the contributions of various types of information according to specific traffic samples and classification tasks, reducing the effectiveness and adaptability of the model to different traffic classification tasks.
[0007] Furthermore, when protocol semantic information and behavioral information have been aggregated into stream-level representations before fusion, the correspondence between protocol semantics and behavioral information such as packet length and transmission direction on the same data packet may be weakened, and the differences in the roles of various types of information in different data packets may not be fully preserved, thus affecting the joint modeling of packet-level information and inter-packet order relationships.
[0008] Therefore, under the condition that application layer content and some service identifier metadata are encrypted or hidden, how to learn a traffic representation with stable discriminative ability from limited observable information, and on the basis of preserving the correspondence of packet-level information and the communication order between packets, adaptively coordinate the contribution of protocol semantic information and behavioral sequence information according to different traffic samples and classification tasks, so as to form a traffic representation with strong discriminative ability and task adaptability, is an important problem that encrypted traffic classification needs to solve. Summary of the Invention
[0009] To address the problems of application layer content and service identification handshake metadata being unobservable due to strong encryption protocols, the difficulty in forming a stable semantic representation of raw ciphertext bytes, the varying degrees of dependence of different traffic samples and classification tasks on protocol semantic information and behavioral sequence information, and the difficulty of maintaining the correspondence between protocol semantic information and behavioral information in the same data packet using existing flow-level post-fusion methods, this invention provides an encrypted traffic classification method based on packet-level protocol semantics and behavioral sequence adaptive fusion.
[0010] This method aims to construct a hierarchical classification framework consisting of packet-level protocol semantic learning, adaptive fusion of packet-level semantic and behavioral features, and flow-level sequence modeling. First, the parsable protocol fields in data packets are structured, and reusable packet-level protocol semantic representations are learned through unlabeled network traffic. Then, behavioral feature representations are constructed based on the length and transmission direction of each data packet, and the protocol semantic representation and behavioral feature representation corresponding to the same data packet are adaptively fused. Finally, the fused packet-level representations are used for flow-level modeling according to the data packet order, obtaining flow-level representations suitable for classification tasks based on specific downstream tasks, thereby improving classification accuracy and generalization ability.
[0011] To achieve the above objectives, the technical solution of the present invention includes:
[0012] A method for classifying encrypted traffic based on adaptive fusion of packet-level protocol semantics and behavioral sequences includes the following steps:
[0013] Step S1: Obtain raw network traffic data. Based on the five-tuple information of source IP address, destination IP address, source port number, destination port number, and protocol type, divide the traffic data belonging to the same bidirectional communication process into network flows and arrange them according to the observation order of the data packets in the network flow.
[0014] Step S2: For each data packet in the network flow, perform protocol parsing, organize the parsed data content into structured protocol units according to protocol fields, and segment the data content that cannot be parsed into protocol fields; construct the field structured input sequence corresponding to each data packet according to the position order of each structured protocol unit and segmented data content in the data packet;
[0015] Step S3: Based on the field structured input sequence constructed in S2, perform self-supervised pre-training on the packet-level protocol semantic encoder, so that the packet-level protocol semantic encoder learns the contextual relationships between protocol fields within the same data packet and between protocol fields and other data content;
[0016] Step S4: For the network traffic data of the downstream task, the pre-trained packet-level protocol semantic encoder is used to obtain the packet-level protocol semantic representation corresponding to each data packet in the network flow; according to the data packet length and transmission direction of each data packet in the network flow, the behavioral feature representation corresponding to each data packet is generated, and a behavioral feature representation sequence is formed according to the order of the data packets in the network flow; according to the order of the data packets in the network flow, the packet-level protocol semantic representation of each data packet is aligned with the behavioral feature representation corresponding to the same data packet; the two types of representations of the same data packet are adaptively fused through the semantic-behavior adaptive fusion module to obtain the packet-level fused representation; according to the order of the data packets in the network flow, the packet-level fused representation is used to construct the semantic-behavior joint representation sequence.
[0017] Step S5: Input the constructed semantic-behavior joint representation sequence into the stream-level sequence encoder to model and learn the dependencies between multiple packet-level fusion representations, obtain the stream-level representation and prediction results corresponding to the network flow, and train the semantic-behavior adaptive fusion module, the stream-level sequence encoder and the classification module based on the prediction results and the corresponding real category labels to obtain the trained traffic classification model.
[0018] Step S6: Input the network flow to be classified into the trained model, and select the candidate category with the highest probability output by the classification module as the corresponding traffic category.
[0019] A computing device includes: at least one processor and a memory storing program instructions; when the program instructions are read and executed by the processor, the computing device performs the encrypted traffic classification method based on the adaptive fusion of packet-level protocol semantics and behavioral sequences.
[0020] The beneficial effects of this invention are as follows:
[0021] (1) Compared with the prior art, the present invention uses a hierarchical classification framework that connects packet-level protocol semantic learning, packet-level semantic-behavior adaptive fusion and stream-level sequence modeling. Under the condition that application layer content and some service identification metadata are encrypted or hidden, the present invention jointly utilizes the still parsable protocol structure information and continuously observable data packet behavior information.
[0022] (2) The present invention organizes the content information of each data packet according to the protocol fields and uses unlabeled network traffic for packet-level self-supervised pre-training, so that the packet-level protocol semantic encoder can learn the protocol fields and their contextual relationships, reducing the information loss caused by treating fields with protocol structure semantics and ciphertext-dominated payload content as indiscriminate byte sequences.
[0023] (3) The present invention generates packet-level protocol semantic representations of each data packet in the network flow and aligns and merges them with the behavioral feature representations corresponding to the same data packet, which can preserve the correspondence between protocol semantic information and behavioral information such as data packet length and transmission direction at the data packet granularity.
[0024] (4) The present invention generates fusion weights based on the protocol semantic representation and behavioral feature representation corresponding to each data packet, so that different data packets and different representation dimensions can adaptively adjust the contribution of protocol semantic information and behavioral information, thereby adapting to the differences in discrimination information relied upon by different traffic samples and classification tasks.
[0025] (5) This invention utilizes unlabeled network traffic to learn reusable packet-level protocol semantic representations, and trains semantic-behavior adaptive fusion modules and flow-level sequence encoders according to specific downstream tasks. This helps reduce the dependence of traffic classification on large-scale labeled data and improves the model's adaptability to different downstream classification tasks.
[0026] (6) The present invention can form an adaptive fusion traffic representation that takes into account the intra-packet protocol structure, packet-level information correspondence and inter-packet communication order from limited observable information in a strongly encrypted communication scenario, thereby improving the effectiveness and adaptability of this type of network traffic classification task. Attached Figure Description
[0027] Figure 1 This is a schematic diagram of the encrypted traffic classification method based on the adaptive fusion of packet-level protocol semantics and behavior sequences provided by the present invention.
[0028] Figure 2 This is a schematic diagram of the encrypted traffic classification method framework based on the adaptive fusion of packet-level protocol semantics and behavior sequences provided by the present invention.
[0029] Figure 3 This is a schematic diagram comparing the semantic-sequence information fusion preferences of the model provided by this invention under different datasets. Detailed Implementation
[0030] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
[0031] Figure 1 This is a schematic diagram of the encrypted traffic classification method based on the adaptive fusion of packet-level protocol semantics and behavior sequences provided by the present invention. Figure 2 This is a schematic diagram of the framework of the encrypted traffic classification method based on adaptive fusion of packet-level protocol semantics and behavioral sequences provided by this invention. (Refer to...) Figure 2 The method of this invention mainly includes four logical modules: packet-level protocol semantic learning, semantic-behavioral feature extraction and fusion, flow-level fine-tuning, and traffic classification using the trained model.
[0032] The packet-level protocol semantic learning stage parses unlabeled network traffic packets into a structured sequence of protocol fields. The packet-level protocol semantic encoder learns the protocol structure and contextual relationships between fields through mask reconstruction. The semantic-behavioral feature extraction and adaptive fusion stage generates protocol semantic representation and behavioral feature representation for each packet, achieving fusion at the same packet granularity and constructing a flow-level fused feature sequence. The flow-level fine-tuning stage models the sequence dependencies between multiple packet-level fused representations and uses labeled data from downstream tasks to train the sequence encoding module, adaptive fusion module, flow-level sequence encoding module, and classification module. In the network traffic classification stage, packets from the network flow to be classified are input into the pre-trained packet-level semantic encoder to obtain protocol semantic representation. Then, the length and direction of the packets are extracted and input into the sequence encoding module to obtain behavioral sequence representation. Finally, the trained adaptive fusion module performs feature fusion on the flow to be classified and inputs it into the trained flow-level sequence encoder and classification module to obtain the classification result.
[0033] like Figure 1 As shown, the method includes the following steps:
[0034] Step S1: Network traffic preprocessing. Obtain raw network traffic data. Based on the five-tuple information of source IP address, destination IP address, source port number, destination port number, and protocol type, divide the traffic data belonging to the same bidirectional communication process into network flows and arrange them according to the observation order of the data packets in the network flow.
[0035] Specifically, network traffic preprocessing includes the following sub-steps:
[0036] The system acquires raw network traffic data stored in PCAP file format and segments the raw traffic data into bidirectional streams based on the five-tuple of source IP address, destination IP address, source port number, destination port number, and protocol type. Each bidirectional stream contains a continuous sequence of data packets.
[0037] ,in This represents a sequence of data packets selected from a bidirectional stream. In a bidirectional flow, the first... Data packets, Indicates the number of data packets selected.
[0038] Step S2: Constructing the structured input sequence of fields. For each data packet in the network flow, perform protocol parsing, organize the parsed data content into structured protocol units according to protocol fields, and segment data content that cannot be parsed into protocol fields. Construct the structured input sequence of fields corresponding to each data packet according to the position order of each structured protocol unit and segmented data content within the data packet.
[0039] Furthermore, step S2 specifically includes the following steps:
[0040] Each data packet is parsed according to the protocol, and each field is extracted and segmented. Data that cannot be parsed is divided according to a preset length.
[0041] Excluding network addresses, network ports, and data that can directly identify the network service from the parsed fields, the remaining data packet traffic is organized into a structured sequence of fields.
[0042] More specifically, step S2 includes:
[0043] Step S21, send the data packet Convert the sequence to hexadecimal representation, retaining its first few digits. Each byte is used for field parsing and lexical construction, by default. The byte range can cover the network layer header, transport layer header, parsable protocol information near the beginning of the data packet, and part of the encrypted payload content.
[0044] Step S22: The Scapy protocol parsing tool is used to identify the network layer, transport layer, and parsable upper-layer protocol fields in the data packet. Parsable protocol fields are extracted according to the protocol encapsulation layer and the original position of each field in the data packet. Each protocol field is treated as an independent structured semantic unit to preserve field boundaries and the structural and contextual relationships between protocol fields.
[0045] Step S23: To avoid the classification model relying on shortcuts formed by communication endpoints or service identities, relevant fields, including IP addresses, transport layer port numbers, and server names, are excluded from packet-level protocol semantics. Packet-level protocol semantics refers to the semantic representation of data packets formed by protocol fields obtained through protocol parsing, their values and structural relationships, and information extracted from unparsed content.
[0046] Step S24: For data content within the reserved byte range that can be parsed into protocol fields, structured protocol units are formed according to the protocol field boundaries; for data content that cannot be parsed into protocol fields, including encrypted payload bytes, it is divided into two-byte units. When the number of remaining bytes is not divisible by the unit length, the last byte can be discarded. Here, the unit length refers to the number of consecutive bytes contained in each data unit when dividing unparsable data content; in this step, the unit length is 2 bytes.
[0047] Step S25: Arrange the structured protocol units and unparsed byte units according to their original positions in the data packet to obtain the data packet. The corresponding field structured input sequence.
[0048] ,in, Representing the The structured input sequence of fields corresponding to each data packet This represents the parsed protocol field. Represents an unparsed byte unit. This represents the number of protocol fields parsed from the structured input sequence. This represents the length of the parsed structured sequence of fields.
[0049] Step S3: Packet-level protocol semantic encoder pre-training. Based on the field-structured input sequence constructed in S2, the packet-level protocol semantic encoder is pre-trained under self-supervised supervision, enabling the encoder to learn the contextual relationships between protocol fields within the same data packet and between protocol fields and other data content.
[0050] Step S3 specifically includes:
[0051] Different strategies are used to mask the field-structured input sequences of a large number of unlabeled network traffic packets to construct pre-trained task samples.
[0052] By predicting the content of masked positions in the structured input sequence of fields, it helps the packet-level protocol semantic encoder learn protocol field boundaries, protocol field order, and contextual dependencies between different protocol fields.
[0053] Specifically, the packet-level protocol semantic encoder pre-training shown includes the following sub-steps:
[0054] Step S31: For unlabeled network traffic, extract the field structured input sequence of the data packets according to step S2. A training corpus is constructed. Then, a byte-pair encoding method is used to learn frequently occurring patterns in the sequence, which does not cross the boundaries between different protocol fields, nor the boundaries between protocol fields and unparsed data areas, thus obtaining a set of ordinary lexical units for the vocabulary.
[0055] Four special lexical units are added to the vocabulary: classification lexical unit [CLS], padding lexical unit [PAD], masking lexical unit [MASK], and unknown lexical unit [UNK]. [CLS] serves as the semantic representation of data packets and is set at the beginning of each data packet lexical sequence; [PAD] is used to pad data packet lexical series of different lengths to a uniform length; [MASK] is used to replace selected ordinary lexical units during the training of the packet-level protocol semantic encoder, enabling the encoder to predict the masked original lexical units based on the remaining protocol fields and data content in the same data packet; and [UNK] represents content units that cannot be mapped by the current vocabulary.
[0056] Add [CLS] at the beginning of the lexical sequence of each data packet. The corresponding structured lexical sequence is represented as follows:
[0057] ,in This indicates the length of the predefined word sequence excluding the category word [CLS]. Indicates the packet index. Indicates the first The structured word sequence of the fields corresponding to each data packet Indicates the first The first to the second field in the structured word sequence corresponding to each data packet Each word element.
[0058] Step S32, for any field structured lexical sequence A predetermined proportion of word positions are randomly selected as prediction positions. In this invention, the prediction positions account for 15% of the effective word positions.
[0059] For the selected prediction position, a masking process is performed according to preset probabilities: the original word is replaced with the mask word [MASK] with a first predetermined probability, such as 80%; the original word is replaced with a random word from the vocabulary with a second predetermined probability, such as 10%; and the original word remains unchanged with a third predetermined probability, such as 10%.
[0060] Step S33: Input the processed field structured lexical sequence into the packet-level protocol semantic encoder, and predict the original lexical at each prediction position based on the context composed of other protocol fields and byte units in the same data packet.
[0061] For field structured word sequence Let the set of predicted locations be... The word sequence after masking is The packet-level protocol semantic pre-training loss is:
[0062] ,in This indicates that the packet-level protocol semantic encoder predicts the original lexical units. The probability, Indicates the first The set of masked and predicted word positions in the structured word sequence corresponding to each data packet. Indicates the packet index. Indicates the first The field corresponding to each data packet contains the word position index in the structured word sequence. This represents the mask field prediction loss for packet-level protocol semantic pre-training.
[0063] The parameters of the packet-level protocol semantic encoder are updated by minimizing the packet-level protocol semantic pre-training loss, enabling it to learn the contextual relationships between protocol fields and between protocol fields and unparsed data content.
[0064] After pre-training, the parameters of the packet-level protocol semantic encoder are saved. The packet-level protocol semantic encoder uses a BERT-based encoding network, representing the protocol semantics of the entire data packet through the final hidden state corresponding to the classification unit [CLS]. For the first... The final hidden state of the categorized word positions in each data packet. As a semantic representation of the packet-level protocol.
[0065] Step S4: Semantic-Behavioral Feature Representation Construction. For the network traffic data of the downstream task, the pre-trained packet-level protocol semantic encoder is used to obtain the packet-level protocol semantic representation corresponding to each data packet in the network flow. Based on the data packet length and transmission direction of each data packet in the network flow, the behavioral feature representation corresponding to each data packet is generated, and a behavioral representation sequence is formed according to the order of the data packets in the network flow. According to the order of the data packets in the network flow, the packet-level protocol semantic representation of each data packet is aligned with the behavioral feature representation corresponding to the same data packet. The two types of representations of the same data packet are adaptively fused through the semantic-behavioral adaptive fusion module to obtain the packet-level fused representation. According to the order of the packet-level fused representations in the network flow, a semantic-behavioral joint representation sequence is constructed.
[0066] Specifically, the semantic-behavioral feature extraction and fusion includes the following sub-steps:
[0067] Step S41: For the labeled dataset of a specific classification task, process it according to step S2. For the data packets... The packet-level protocol semantic encoder, after training, is used to encode the data to obtain the packet-level protocol semantic representation. .
[0068] For containing The network flow of data packets, arranged according to the order of observation of each data packet in the bidirectional network flow, yields the following packet-level protocol semantic representation:
[0069] ,in The packet-level protocol semantic representation matrix representing network flows is composed of... The packet-level protocol semantic representation of each data packet is obtained by arranging them in the order of observation. The dimension representing the semantic representation of the packet-level protocol;
[0070] Step S42, for data packets Get the data packet length and transmission direction identifier .
[0071] Among them, when data packets The transmission direction identifier is sent from the initiating end to the responding end. Set as When data packets The communication response end sends the transmission direction identifier to the communication initiator. Set as ,Right now:
[0072] In client-server communication mode, the communication initiator is the client, and the communication responder is the server. Accordingly, the transmission direction from client to server is encoded as follows: Encode the transmission direction from server to client as .
[0073] According to the data packet Given the packet length and transmission direction identifier, construct a packet length value with direction:
[0074] ,thus The absolute value of the number indicates the length of the data packet, and the positive or negative sign indicates the direction of transmission of the data packet relative to the network flow.
[0075] Step S43: The directional packet length value is converted into a behavioral feature representation with the same dimension as the packet-level protocol semantic representation through a trainable linear mapping.
[0076] ,in and These are the weights and bias parameters of the mapping layer, respectively. This represents the behavioral feature representation obtained after mapping, and .
[0077] Arrange the behavioral feature representations of each data packet according to their observation order in the bidirectional network flow to obtain the behavioral representation sequence:
[0078] .
[0079] Step S44: Align the packet-level protocol semantic representation and behavioral feature representation according to the packet index, and adaptively fuse the two types of representations for the same packet, i.e., the... Protocol semantic representation of data packets Behavioral feature representation corresponding to the same data packet The packets are fused to obtain packet-level fused representations. The packet-level fused representations are then arranged in the order of observation of the corresponding data packets to construct a semantic-behavior joint representation sequence.
[0080] S44-1, the first The protocol semantic representation and behavioral feature representation of each data packet are concatenated and input into the gating mapping module to generate a feature dimension gating vector:
[0081] ,in, This represents the Sigmoid activation function. and For trainable parameters, It is the generated feature dimension gated vector, and .
[0082] S44-2, perform element-wise weighting of the two representations based on the feature dimension gating vector to obtain the packet-level fused representation of the i-th data packet:
[0083] ,in, This represents element-wise multiplication. This represents the obtained packet-level fusion representation.
[0084] The gating vector is jointly determined by the protocol semantic representation and behavioral feature representation of the current data packet. Therefore, different data packets can form different gating vectors; different feature dimensions in the same data packet can also adopt different fusion ratios.
[0085] S44-3, arrange all packet-level fused representations in the same network flow according to the observation order of the corresponding data packets to construct a semantic-behavior joint representation sequence:
[0086] , This represents the constructed semantic-behavioral joint representation sequence.
[0087] The semantic-behavior joint representation sequence contains both protocol semantic information and behavioral information at each data packet granularity, and preserves the sequence relationship between each data packet.
[0088] Step S5: Flow-level fine-tuning. Input the constructed semantic-behavior joint representation sequence into the flow-level sequence encoder to model and learn the dependencies between multiple packet-level fusion representations, obtain the flow-level representation and prediction results corresponding to the network flow, and train the semantic-behavior adaptive fusion module, the flow-level sequence encoder, and the classification module based on the prediction results and the corresponding true class labels to obtain the trained traffic classification model.
[0089] Specifically, the flow level fine-tuning includes the following sub-steps:
[0090] Step S51: Add a trainable stream-level classification vector at the beginning of the semantic-behavior joint representation sequence. :
[0091] ,in, Represents the stream-level classification vector. This represents the obtained input sequence.
[0092] Step S52, input sequence The input stream-level sequence encoder is used to learn the sequence dependencies between multiple packet-level fused representations in the network stream.
[0093] The stream-level sequence encoder uses a BERT-based bidirectional coding network. Its network structure has the same basic coding structure as the packet-level protocol semantic encoder, but the two are initialized and trained separately.
[0094] Step S53, retrieve the stream-level classification vector The final hidden state corresponding to the current location is represented as a network flow level:
[0095] ;
[0096] Step S54: Input the network flow level representation into the classification module to predict the probability that the network flow belongs to each candidate category:
[0097] ;
[0098] in, This represents the probability corresponding to the candidate category. This represents the normalization function used to map the output of the classification module to the probability distribution of each candidate class. and These represent the weight matrices of the first and second fully connected layers, respectively. and These represent the bias vectors of the first fully connected layer and the second fully connected layer, respectively. This represents the Gaussian error linear unit activation function.
[0099] Step S55: Calculate the classification loss based on the true class labels and predicted probabilities of the network stream.
[0100] ,in, For the number of candidate categories, For the first in the real category label The tag value corresponding to the class, To predict which belongs to the first The probability of a class It is the calculated classification loss.
[0101] During downstream classification training, the parameters of the packet-level protocol semantic encoder are fixed, and the reusable protocol semantic representation learned from unlabeled network traffic is utilized to jointly update the parameters of the behavior feature mapping module, the gating fusion module, the stream-level sequence encoder, and the classification module.
[0102] No additional unsupervised training is performed on the stream-level sequence encoder. Instead, it is initialized independently in each downstream task and trained and tested using the labeled traffic data of the corresponding task.
[0103] Step S6: Input the network flow to be classified into the trained model, and select the candidate category with the highest probability output by the classification module as the corresponding traffic category.
[0104] To verify the effectiveness of the proposed method, this example uses datasets for different traffic classification tasks, including service and application classification tasks based on the ISCX-VPN dataset, IoT attack traffic classification based on the UNSW-TON-IoT dataset, malware classification based on the USTC-TFC dataset, and IoT status classification based on the CIC-IoT-2022 dataset. Furthermore, the CipherSpectrum, CSTNE-TLS 1.3, and VisQUIC datasets are used to verify the model's classification capabilities under strong encryption conditions.
[0105] The statistical results of the categories and sample sizes in each dataset in this example are shown in Table 1. The network streams were segmented according to the data processing steps in step S1, and then... The dataset is divided into training, testing, and validation sets according to a specific ratio. The maximum number of training epochs is set to [value missing]. The batch size is The initial learning rate is set to During training, an early stop mechanism should be used in conjunction with the training process. If consecutive early stops occur... If the classification accuracy of the model does not improve after one epoch, training is stopped.
[0106] Table 1. Statistics of downstream task dataset categories
[0107]
[0108] For ease of description, the network traffic classification method proposed in this invention will be referred to as FLARE (Field-aware Learning and Adaptive Representation Fusion for Encrypted Traffic Classification). In this example, the FLARE method of this invention will be compared with three main categories of methods: machine learning methods based on statistical features such as AppScanner and BIND; deep learning methods based on raw byte and behavioral sequence features such as DeepPacket, LexNet, FS-Net, and DF; and pre-trained methods such as ET-BERT, YaTC, BERT-p, and TrafficFormer.
[0109] This example uses classification accuracy (Acc) and macro-F1 score (F1) to evaluate the performance of different methods.
[0110] According to the method proposed in this invention, the experiment mainly includes two tasks: the first task is to verify the effectiveness and adaptability of the model under different types of downstream tasks, and the second task is to verify the classification ability of the model under strong encryption conditions.
[0111] The experimental results for Task 1 are shown in Tables 2 and 3: FLARE achieved the highest F1 score across all datasets, demonstrating excellent classification performance on tasks such as VPN traffic classification, website fingerprinting, malicious traffic detection, and IoT traffic classification.
[0112] Table 2 Comparison of experimental results of different methods on the ISCX-VPN dataset
[0113]
[0114] Table 3. Comparison of experimental results of different methods on the UNSW-TON-IoT, USTC-TFC, and CIC-IoT-2022 datasets.
[0115]
[0116] To evaluate FLARE's classification capabilities under strong encryption, three website fingerprint classification datasets with increasing encryption strength were selected for experiments. The CipherSpectrum dataset uses the AEAD cipher suite, mandated by TLS 1.3, to encrypt traffic. Since its ClientHello packets carry plaintext SNI, the SNI field needs to be removed to prevent shortcut learning. The CSTNET-TLS 1.3 dataset also uses TLS 1.3 encryption and discards the ClientHello packet and all packets preceding it in each stream, further reducing the available handshake context beyond SNI removal. The VisQUIC dataset consists of QUIC traffic, with its TLS 1.3 handshake encapsulated in encrypted CRYPTO frames. The packet number is hidden by header protection mechanisms, and transport layer information previously exposed in the TCP header is also included in the encrypted payload, making it the dataset with the fewest plaintext fields that can be parsed.
[0117] The experimental results for Task 2 are shown in Table 4: FLARE achieves state-of-the-art classification performance on all three strongly encrypted datasets. Compared to the strongest pre-trained baselines on each dataset, FLARE achieves average accuracies of 3.11%, 5.11%, and 10.92% higher on CipherSpectrum, CSTNET-TLS 1.3, and VisQUIC, respectively; and compared to the strongest deep learning baselines, it achieves accuracies of 11.77%, 8.57%, and 3.92% higher, respectively.
[0118] Table 4. Comparison of experimental results of different methods on strongly encrypted datasets
[0119]
[0120] Furthermore, to further analyze FLARE's feature representation fusion preference for different downstream task datasets, the dataset-level protocol semantic fusion preference score is defined as the average protocol semantic gating weight at all non-padded grouping positions:
[0121] ,in, Represents a set of streams in the dataset. Represents the dataset Protocol semantic fusion preference score, Represents the dataset Network flow in It is a flow The number of non-filled positions in Represents network flow Index of non-padding positions The dimension of the gate vector is represented. The dimension index of the gated vector. Indicates the gating vector at the th The first non-filled position Each component, and the corresponding behavioral feature fusion preference score, is defined as follows:
[0122] .
[0123] Preference calculations were performed on six different datasets, combining protocol semantic representation and behavioral feature representation. Figure 3 As shown, FLARE can employ different representation fusion ratios for different datasets to achieve effective traffic classification. The fusion preference for protocol semantic representations ranges from 6.0% to 37.5%, while the fusion preference for behavioral feature representations ranges from 62.5% to 94.0%, demonstrating that the gated network can adaptively adjust accordingly. In comparison, for the VPN dataset, the model relies more on protocol semantic representations, while on the CipherSpectrum dataset, due to the strong encryption of traffic data using the TLS 1.3 protocol, less field information is available, causing the model to rely more on behavioral feature representations for classification in the final process.
[0124] In summary, the experimental results of the method of this invention verify that the FLARE model can effectively capture and adaptively adjust the dependencies between the protocol semantic features and behavioral features of traffic in different scenarios, and still has excellent classification ability under the condition of limited observation information.
[0125] The present invention also provides a computing device, comprising: at least one processor and a memory storing program instructions; when the program instructions are read and executed by the processor, the computing device performs the encrypted traffic classification method based on packet-level protocol semantics and behavioral sequence adaptive fusion.
[0126] Although the invention has been described with respect to a limited number of embodiments, those skilled in the art will understand from the foregoing description that other embodiments are conceivable within the scope of the invention described herein. Furthermore, it should be noted that the language used in this specification has been chosen primarily for readability and instructional purposes, and not for the purpose of explaining or limiting the subject matter of the invention.
Claims
1. A method for classifying encrypted traffic based on adaptive fusion of packet-level protocol semantics and behavioral sequences, characterized in that, Includes the following steps: Step S1: Obtain raw network traffic data. Based on the five-tuple information of source IP address, destination IP address, source port number, destination port number, and protocol type, divide the traffic data belonging to the same bidirectional communication process into network flows and arrange them according to the observation order of the data packets in the network flow. Step S2: For each data packet in the network flow, perform protocol parsing, organize the parsed data content into structured protocol units according to protocol fields, and segment the data content that cannot be parsed into protocol fields. Construct a structured input sequence of fields corresponding to each data packet according to the position and order of each structured protocol unit and segmented data content in the data packet; Step S3: Based on the field structured input sequence constructed in S2, perform self-supervised pre-training on the packet-level protocol semantic encoder, so that the packet-level protocol semantic encoder learns the contextual relationships between protocol fields within the same data packet and between protocol fields and other data content; Step S4: For the network traffic data of the downstream task, the pre-trained packet-level protocol semantic encoder is used to obtain the packet-level protocol semantic representation corresponding to each data packet in the network flow; according to the data packet length and transmission direction of each data packet in the network flow, the behavioral feature representation corresponding to each data packet is generated, and a behavioral feature representation sequence is formed according to the order of the data packets in the network flow; according to the order of the data packets in the network flow, the packet-level protocol semantic representation of each data packet is aligned with the behavioral feature representation corresponding to the same data packet; the two types of representations of the same data packet are adaptively fused through the semantic-behavior adaptive fusion module to obtain the packet-level fused representation; according to the order of the data packets in the network flow, the packet-level fused representation is used to construct the semantic-behavior joint representation sequence. Step S5: Input the constructed semantic-behavior joint representation sequence into the stream-level sequence encoder to model and learn the dependencies between multiple packet-level fusion representations, obtain the stream-level representation and prediction results corresponding to the network flow, and train the semantic-behavior adaptive fusion module, the stream-level sequence encoder and the classification module based on the prediction results and the corresponding real category labels to obtain the trained traffic classification model. Step S6: Input the network flow to be classified into the trained model, and select the candidate category with the highest probability output by the classification module as the corresponding traffic category.
2. The encrypted traffic classification method based on adaptive fusion of packet-level protocol semantics and behavioral sequences according to claim 1, characterized in that, Step S2 specifically includes the following steps: Each data packet is parsed according to the protocol, and each field is extracted and segmented. Data that cannot be parsed is divided according to a preset length. Excluding network addresses, network ports, and data that can directly identify the network service from the parsed fields, the remaining data packet traffic is organized into a structured sequence of fields.
3. The encrypted traffic classification method based on adaptive fusion of packet-level protocol semantics and behavioral sequences according to claim 1, characterized in that, Step S2 includes: Step S21, send the data packet Convert the sequence to hexadecimal representation, retain the first few bytes for field parsing and word construction; Step S22: Use the Scapy protocol parsing tool to identify the network layer, transport layer and parsable upper-layer protocol fields in the data packet, and extract the parsable protocol fields according to the protocol encapsulation layer and the original position of each field in the data packet. Step S23: Exclude relevant fields from the packet-level protocol semantics, including IP address, transport layer port number and server name; Step S24: For data content that can be parsed into protocol fields within the reserved byte range, structured protocol units are formed according to the protocol field boundaries; for data content that cannot be parsed into protocol fields, it is divided into two-byte units. Step S25: Arrange the structured protocol units and unparsed byte units according to their original positions in the data packet to obtain the data packet. The corresponding field structured input sequence.
4. The encrypted traffic classification method based on adaptive fusion of packet-level protocol semantics and behavioral sequences according to claim 3, characterized in that, Step S3 specifically includes: Step S31: For unlabeled network traffic, extract the field structured input sequence of the data packets according to step S2. A training corpus is constructed; byte-pair encoding is used to learn frequently occurring patterns in the sequence, without crossing the boundaries between different protocol fields or the boundaries between protocol fields and unparsed data areas, to obtain a set of ordinary lexical units for the vocabulary; Add a classification term [CLS] at the beginning of the term sequence of each data packet to obtain the corresponding field structured term sequence. [CLS] serves as the semantic representation of the data packet aggregation and is set at the beginning of the term sequence of each data packet. Step S32: For any field structured word sequence, randomly select a preset proportion of word positions as prediction positions; for the selected prediction positions, perform masking processing according to preset probabilities: replace the original word with masked word with a first predetermined probability; replace the original word with random word in the vocabulary with a second predetermined probability; and keep the original word unchanged with a third predetermined probability. Step S33: Input the processed field structured lexical sequence into the packet-level protocol semantic encoder, and predict the original lexical at each prediction position based on the context composed of other protocol fields and byte units in the same data packet.
5. The encrypted traffic classification method based on adaptive fusion of packet-level protocol semantics and behavior sequences according to claim 4, characterized in that, For field structured word sequence Let the set of predicted locations be... The trained word sequence is The pre-training loss of the packet-level protocol semantic encoder is: ,in This indicates that the packet-level protocol semantic encoder predicts the original lexical units. The probability, Indicates the first The set of masked and predicted word positions in the structured word sequence corresponding to each data packet. Indicates the packet index. Indicates the first The field corresponding to each data packet contains the word position index in the structured word sequence. This represents the mask field prediction loss for packet-level protocol semantic pre-training.
6. The encrypted traffic classification method based on adaptive fusion of packet-level protocol semantics and behavior sequences according to claim 4, characterized in that, The packet-level protocol semantic encoder uses a BERT-based encoding network to represent the packet-level protocol semantics of the entire data packet through the final hidden state corresponding to the classification term [CLS].
7. The encrypted traffic classification method based on adaptive fusion of packet-level protocol semantics and behavioral sequences according to claim 6, characterized in that, Step S4 includes: Step S41: For the labeled dataset of a specific classification task, process it according to step S2; for the data packet... The packet-level protocol semantic encoder, after training, is used to encode the data to obtain the packet-level protocol semantic representation. ; For containing The network flow of data packets is arranged according to the order of observation of each data packet in the bidirectional network flow, and the packet-level protocol semantic representation is arranged accordingly. Step S42, for data packets Get the data packet length and transmission direction identifier According to the data packet Given the packet length and transmission direction identifier, construct a packet length value with direction: Step S43: The directional packet length value is converted into a behavioral feature representation with the same dimension as the packet-level protocol semantic representation through a trainable linear mapping; The behavioral feature representations of each data packet are arranged in the order of their observation in the bidirectional network flow to obtain the behavioral representation sequence; Step S44: Align the packet-level protocol semantic representation and behavioral feature representation according to the packet index, adaptively fuse the two types of representations for the same packet to obtain the packet-level fused representation, arrange the packet-level fused representations according to the observation order of the corresponding packets, and construct the semantic-behavioral joint representation sequence.
8. The encrypted traffic classification method based on adaptive fusion of packet-level protocol semantics and behavioral sequences according to claim 7, characterized in that, Step S44 includes: S44-1, the first The protocol semantic representation and behavioral feature representation of each data packet are concatenated and input into the gating mapping module to generate a feature dimension gating vector; S44-2, weight the two representations element-wise according to the feature dimension gate vector to obtain the first... Packet-level fused representation of individual data packets; S44-3 arranges all packet-level fused representations in the same network flow according to the observation order of the corresponding data packets to construct a semantic-behavior joint representation sequence.
9. The encrypted traffic classification method based on adaptive fusion of packet-level protocol semantics and behavioral sequences according to claim 8, characterized in that, Step S5 includes: Step S51: Add a trainable stream-level classification vector to the starting position of the semantic-behavior joint representation sequence to obtain the input sequence; Step S52: Input the input sequence into the stream-level sequence encoder, and learn the sequence dependencies between multiple packet-level fused representations in the network stream through the stream-level sequence encoder; Step S53: Take the final hidden state corresponding to the position of the flow-level classification vector as the network flow-level representation; Step S54: Input the network flow level representation into the classification module to predict the probability that the network flow belongs to each candidate category; Step S55: Calculate the classification loss based on the true class labels and predicted probabilities of the network stream. ,in, The number of candidate categories, For the first in the real category label The tag value corresponding to the class, To predict which belongs to the first The probability of a class It is the calculated classification loss.
10. A computing device, characterized in that, include: At least one processor and a memory storing program instructions; When the program instructions are read and executed by the processor, the computing device performs the encrypted traffic classification method based on the adaptive fusion of packet-level protocol semantics and behavior sequences as described in any one of claims 1-9.
