Encrypted traffic detection method and device based on contrastive learning pre-training

Through comparative learning pre-training technology, network traffic characteristics are extracted and model parameters are optimized, which solves the limitations of traditional encrypted traffic detection methods in recognition accuracy and generalization capabilities, achieves more efficient malicious traffic detection, and improves encrypted traffic detection. accuracy and robustness.

CN118555155BActive Publication Date: 2024-10-01BEIJING CHAITIN TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411045115.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-01
Publication Date
2024-10-01
Estimated Expiration
2044-08-01

AI Technical Summary

Technical Problem

Traditional encrypted traffic detection methods are difficult to effectively identify and prevent malicious behaviors, especially in encrypted traffic. Deep packet inspection and machine learning-based methods have limitations in identification accuracy and generalization capabilities, and are difficult to cope with complex and diverse networks. attack.

Method used

Adopting a pre-training method based on contrastive learning, by extracting the packet-level load characteristics and flow-level packet length sequence characteristics of network traffic, combined with the multi-head attention encoder and projection layer, positive and negative sample pairs are used for comparative learning, optimizing model parameters, and enhancing The model's ability to identify malicious traffic and improve its adaptability in actual network environments through model fine-tuning.

Benefits of technology

It improves the accuracy and robustness of encrypted traffic detection, enhances the understanding and representation of complex traffic characteristics, improves the effectiveness of the model in practical applications, can more effectively distinguish malicious and normal traffic, and improves the detection efficiency. Accuracy and generalization ability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118555155B_ABST
    Figure CN118555155B_ABST
Patent Text Reader

Abstract

The present invention discloses an encrypted traffic detection method and device based on contrastive learning pre-training, which relates to the field of network security protection technology. The method includes: extracting the packet-level load characteristics and flow-level packet length sequence characteristics of the network traffic to be detected; splicing the packet-level load characteristics and flow-level packet length sequence characteristics; sampling and pre-training the high-dimensional vectors with positive and negative samples; fine-tuning the initial classification model with the original training data set; and obtaining the probability that the network traffic to be detected belongs to each category. The present invention not only improves the accuracy of encrypted traffic detection and improves the generalization ability, but also provides a new solution for the field of network security.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of network security protection, and in particular to an encrypted traffic detection method and device based on contrastive learning pre-training. Background Art

[0002] With the development of the digital age, encryption technologies such as SSL / TLS have been widely adopted in network applications and services, significantly improving user privacy and data security. These technologies effectively protect user information from unauthorized access by encrypting data transmission. However, just as any technology has its double-edged sword characteristics, encryption technology is no exception. While it provides solid protection for user privacy, it also provides malicious actors with a means to hide their activities. In particular, attackers can use encrypted traffic to conceal their malicious behavior, making it difficult for traditional network security detection systems, such as intrusion detection systems (IDS) and intrusion prevention systems (IPS), to effectively identify and block these threats. Therefore, the detection of encrypted traffic has become a major challenge in the field of network security.

[0003] Traditional methods, such as deep packet inspection (DPI), have proven inadequate for detecting malicious encrypted traffic. As cyberattacks continue to evolve and change, these traditional methods face increasing limitations. For example, attackers may send stolen sensitive data through encrypted channels or conduct illegal transactions on the dark web, and these activities are often difficult to detect with traditional methods. To address these challenges, researchers have begun to turn to more advanced technologies, such as machine learning and deep learning, to seek more effective solutions. These machine learning-based methods attempt to extract features from plaintext messages during the SSL / TLS handshake process or use traffic-level statistical features to detect encrypted traffic. However, these methods face many challenges in practical applications. For example, SSL / TLS handshake information may be incomplete or missing, which can seriously affect the accuracy of identification. In addition, the extraction of statistical features usually relies on complex expert knowledge and requires manual operations, which not only increases the difficulty of implementation, but also often reduces the generalization ability of the model due to the reliance on empirical methods.

[0004] The advantage of deep learning is that it can automatically learn data features and reduce reliance on expert knowledge. However, in the field of encrypted traffic detection, although deep learning methods have made some progress, they mainly rely on specific feature engineering and preset model architectures and still have limitations. When dealing with diverse and complex encrypted traffic, these methods are often limited in recognition accuracy and generalization ability. Therefore, how to effectively improve the accuracy and generalization ability of encrypted traffic detection has become an urgent problem to be solved in the field of network security. Summary of the invention

[0005] In view of the above defects or deficiencies in the prior art, the present invention provides an encrypted traffic detection method and device based on contrastive learning pre-training, which aims to use the advantages of contrastive learning to improve the model's ability to identify malicious behaviors in encrypted traffic, and at the same time enhance the generalization ability of the model through pre-training technology. The present invention not only improves the accuracy of encrypted traffic detection and improves the generalization ability, but also provides a new solution for the field of network security.

[0006] One aspect of the present invention provides an encrypted traffic detection method based on contrastive learning pre-training, comprising:

[0007] Traffic feature extraction step: extracting the packet-level load features and flow-level packet length sequence features of the network traffic to be detected;

[0008] Feature splicing step: splicing the packet-level load features and the flow-level packet length sequence features, and converting the discrete input sequence obtained after splicing into a high-dimensional vector;

[0009] A comparative pre-training step: sampling positive and negative sample pairs of the high-dimensional vector to form pre-training triplets, extracting hidden layer features of the pre-training triplets through a multi-head attention encoder and a projection layer, and optimizing the distance between positive samples and the distance between negative samples through a comparative loss function to achieve parameter optimization of the multi-head attention encoder;

[0010] Model fine-tuning step: Add a fully connected layer suitable for the classification task on the basis of the multi-head attention encoder to form an initial classification model, and fine-tune the initial classification model using the original training dataset;

[0011] Traffic classification step: Input the feature vector of the fully connected layer into the Softmax function for calculation to obtain the probability that the network traffic to be detected belongs to each category.

[0012] Another aspect of the present invention further provides an encrypted traffic detection device based on contrastive learning pre-training, comprising:

[0013] Traffic feature extraction module, used to extract packet-level load features and flow-level packet length sequence features of the network traffic to be detected;

[0014] A feature concatenation module is used to concatenate the packet-level load features and the flow-level packet length sequence features, and convert the concatenated discrete input sequence into a high-dimensional vector;

[0015] A contrast pre-training module is used to sample positive and negative sample pairs of the high-dimensional vector to form pre-training triplets, extract hidden layer features of the pre-training triplets through a multi-head attention encoder and a projection layer, and optimize the distance between positive samples and the distance between negative samples through a contrast loss function to achieve parameter optimization of the multi-head attention encoder;

[0016] A model fine-tuning module is used to add a fully connected layer suitable for the classification task on the basis of the multi-head attention encoder to form an initial classification model, and fine-tune the initial classification model using the original training data set;

[0017] The traffic classification module is used to input the feature vector of the fully connected layer into the Softmax function for calculation to obtain the probability that the network traffic to be detected belongs to each category.

[0018] The invention provides an encrypted traffic detection method and device based on contrastive learning pre-training, which has the following beneficial effects:

[0019] 1. Effectively use positive and negative sample pairs to enhance the model's ability to identify malicious traffic features. By optimizing the model through comparative loss functions, it can more accurately distinguish different types of traffic and improve the accuracy and robustness of detection.

[0020] 2. The combination of multi-head attention encoder and projection layer enhances the model's understanding and representation of complex traffic features, enabling the model to capture subtle feature differences and thus more effectively distinguish malicious traffic from normal traffic.

[0021] 3. By fine-tuning the initial classification model, the adaptability and accuracy of the model in a specific network environment are ensured. The fine-tuning process uses actual traffic data to make the model more in line with the needs of actual application scenarios and improves the effectiveness of the model in the actual network environment.

[0022] 4. Through the application of feature splicing modules and position coding, a comprehensive and information-rich traffic feature representation is constructed, which not only improves the accuracy of traffic classification, but also enhances the model's ability to handle the diversity of traffic patterns. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:

[0024] Figure 1 It is a flowchart of an encrypted traffic detection method based on contrastive learning pre-training provided by an embodiment of the present application;

[0025] Figure 2It is a schematic diagram of a framework of an encrypted traffic detection method based on contrastive learning pre-training provided by an embodiment of the present application;

[0026] Figure 3 It is a structural schematic diagram of an encrypted traffic detection device based on contrastive learning pre-training provided by an embodiment of the present application;

[0027] Figure 4 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0028] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0029] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.

[0030] It should be understood that although the terms first, second, third, etc. may be used to describe the acquisition modules in the embodiments of the present invention, the acquisition modules should not be limited to these terms. These terms are only used to distinguish the acquisition modules from each other.

[0031] The word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.

[0032] It should be noted that the directional words such as "upper", "lower", "left", and "right" described in the embodiments of the present invention are described at the angles shown in the drawings and should not be understood as limiting the embodiments of the present invention. In addition, in the context, it should also be understood that when it is mentioned that an element is formed "on" or "under" another element, it can not only be formed directly "on" or "under" another element, but also be formed "on" or "under" another element indirectly through an intermediate element.

[0033] Embodiment 1

[0034] like Figure 1 , 2 As shown, an encrypted traffic detection method based on contrastive learning pre-training provided by an embodiment of the present invention includes the following steps:

[0035] Step S101, obtaining the network traffic to be detected, and extracting the packet-level load characteristics and flow-level packet length sequence characteristics of the network traffic to be detected.

[0036] First, the captured network traffic is classified and reassembled according to the five-tuple (source address, source port, destination address, destination port, protocol). After the traffic is reassembled, the transmission direction of each data packet is marked, and the first N = 32 data packets are intercepted from each flow, and the first M = 128 bytes of the original payload are further extracted.

[0037] Then, the content of each data packet is processed to remove bias information such as IP addresses and port numbers, and the original payload is split into two-byte blocks, such as from {1a, 2b, 03, 45, 62, aa, ...} to {1a2b, 0345, 62aa,...}, and these blocks are encoded using a 1-gram dictionary, such as {1a2b:0, 0345:1, 62aa:2...}, forming the original payload features. , which is the packet-level load characteristic.

[0038] Finally, the length of each data packet is extracted according to the TCP header information bit tcp_len (for example, in bytes), and the positive and negative signs are used to indicate the transmission direction of the data packet. For example, a flow can be represented as {+328, -1074, -180, +328...}. The data packet length is encoded by 1-gram dictionary, for example, {1a2b:0, 0345:1, 62aa:2, +328:3, -1074:4, -180:5...}, and the packet length sequence feature is constructed. , which is the flow-level packet length sequence feature.

[0039] Step S102, concatenating the packet-level load features and the flow-level packet length sequence features, and converting the concatenated discrete input sequence into a high-dimensional vector.

[0040] Specifically, introduce markers into the encoding dictionary and concatenate structured packet-level payload features. and flow-level packet length sequence characteristics , using the parameter matrix Convert the concatenated discrete input sequence embedding into a high-dimensional vector ,include:

[0041] First, add four special markers to the dictionary, namely , , , , which represent the start flag, separator flag, fill flag and unregistered word flag of the input respectively, and concatenate the features to form an input sequence , expressed by the following formula:

[0042]

[0043] Then, using the parameter matrix ( is the matrix size, is the matrix dimension) for the concatenated input sequence Perform word embedding processing and convert it into a vector After that, the position coding information is added and expressed by the following formula:

[0044]

[0045] in, Indicates the position of the packet in the flow, represents the dimension index in the positional encoding vector, Iterating over a collection , D represents the maximum number of positions , Indicates the position of an element in a sequence. Indicates the number of dimensions of each position encoding vector.

[0046] It should be pointed out that the main purpose of position encoding in this step is to retain the position information of each element in the sequence when processing sequence data. In network traffic analysis, the position of the data packet in the flow may carry important information, which is very important for the model to accurately capture the characteristics of the flow.

[0047] Step S103: Sampling positive and negative sample pairs of the high-dimensional vector to form pre-trained triplets, extracting hidden features of the pre-trained triplets through a multi-head attention encoder and a projection layer, and optimizing the distance between positive samples and the distance between negative samples through a contrast loss function to achieve parameter optimization of the multi-head attention encoder.

[0048] Specifically, the technical terms used in this step are explained below:

[0049] Sample vector : is the vector obtained from the input sequence after word embedding and position encoding. The positive sample is the vector obtained from the original sample. Therefore, the positive sample is the same as the original vector are the same, which tells the model that these samples are similar;

[0050] Negative samples : is a sample vector obtained by selecting from other different samples, not The same sample is selected from other different samples in the dataset to tell the model that these samples are not similar;

[0051] Positive sample pair: For each sample vector , copy one copy as a positive sample. For example, suppose _1 is the original sample, then The positive sample pair of _1 is also _1.

[0052] Negative sample pair: Select negative samples from other samples. For example, assuming x_2 is another different sample, then the negative sample of x_1 can be x_2, that is, the negative sample pair is (x_1, x_2).

[0053] The specific process of this step is described below:

[0054] (1) Sampling of positive and negative sample pairs

[0055] For the sample vector Perform positive and negative sample pair sampling by copying the sample vector As a positive sample, by selecting the sample vector across samples As negative samples, form pre-training triplets . Specifically include: sample vector is copied once as a positive sample, and the copied positive sample After the subsequent multi-head attention encoder and projection layer, the original sample Different representations are considered as positive examples of each other.

[0056] Negative samples Select in one of two ways:

[0057] Strong negative samples: when samples and another sample When having different category labels, Considered as This kind of negative sample selection focuses on the essential difference between the two in the classification task, ensuring that they have a significant distance in the high-dimensional feature space.

[0058] Weak negative samples: and have the same category tag, but their communication information is different, for example, different TLS certificates or destination IP address and port combinations, then Considered as In this case, although the two belong to the same category, the subtle difference in the communication pattern means that they should keep a certain distance in the high-dimensional feature space.

[0059] (2) Comparison with pre-training

[0060] By stacking Layer multi-head attention encoder and Layer projection layer to process pre-trained triplets , thereby obtaining the corresponding hidden layer feature triplet The multi-head attention encoder includes a self-attention layer and a feedforward neural network. The self-attention layer is responsible for encoding the contextual information of the input features to capture the complex relationship between samples. The feedforward neural network provides the necessary nonlinear transformation to enhance the model's understanding and processing capabilities of features. The projection layer includes a fully connected layer with ReLU activation to reduce the sample And its positive sample While ensuring that key features are not lost during the pre-training process.

[0061] (3) Contrastive loss function optimization

[0062] Use contrastive loss function to optimize the model. The goal of the loss function is to reduce the distance between positive examples.

[0063] At the same time, the distance between negative examples can be increased, which can be achieved through the following formula:

[0064] in, Represents the target of the contrastive loss function; Indicates that for positive samples The contrast loss of represents the input sample; represents a positive sample; Represents a weak negative sample; Indicates a strong negative sample; Indicates samples; Represents the first samples; represents the temperature parameter; Indicates the weight of strong / weak negative samples; Representation sample similarity; Representation sample The similarity.

[0065] Step S104: Add a fully connected layer suitable for the classification task on the basis of the multi-head attention encoder to form an initial classification model, and fine-tune the initial classification model using the original training data set.

[0066] First, build an initial classification model , its core is a multi-head attention encoder whose parameters are initialized by the previous pre-training stage, and a fully connected layer specially designed for classification tasks is added to the encoder to convert the features extracted by the encoder into classification decisions.

[0067] Then, use the original training data set to train the initial classification model Fine-tuning is performed to adjust and optimize its parameters to suit a specific classification task by learning the feature distribution and category relationships in the original dataset.

[0068] Step S105: Input the feature vector of the fully connected layer into the Softmax function for calculation to obtain the probability that the network traffic to be detected belongs to each category.

[0069] First, the output feature vector of the fully connected layer is input into the Softmax function. The Softmax function is responsible for converting these feature vectors into a set of probability values, each of which corresponds to the possibility that the network traffic to be detected belongs to a certain category.

[0070] Then, based on the probability output by Softmax, the difference between the predicted probability distribution and the actual label distribution is measured by calculating the cross entropy loss function. The back propagation algorithm is used to update the network parameters and optimize the classification performance. Specifically, the following formula is used to predict a given sample Belongs to category The probability is:

[0071]

[0072] Among them, the weight matrix between the Softmax layer and the last fully connected layer is To express, is the bias vector, Represents the category label predicted by the model; Represents a transpose operation; Indicates the index of the category; Represents the feature representation vector obtained after the input sample is processed by the network layer.

[0073] Through the above steps, the conditional probability that the traffic sample belongs to each category can be accurately estimated, and the network can be optimized to minimize the overall cross entropy loss to improve the overall performance of malicious traffic detection.

[0074] See also Figure 3Another embodiment of the present invention further provides an encrypted traffic detection device 200 based on contrastive learning pre-training, comprising a traffic feature extraction module 201, a feature splicing module 202, a contrast pre-training module 203, a model fine-tuning module 204, and a traffic classification module 205. The encrypted traffic detection device 200 can execute the data communication method in the method embodiment.

[0075] Specifically, the device 200 includes:

[0076] Traffic feature extraction module 201, used to extract packet-level load features and flow-level packet length sequence features of the network traffic to be detected;

[0077] A feature concatenation module 202 is used to concatenate the packet-level load feature and the flow-level packet length sequence feature, and convert the concatenated discrete input sequence into a high-dimensional vector;

[0078] A comparison pre-training module 203 is used to sample positive and negative sample pairs of the high-dimensional vector to form pre-training triplets, extract hidden layer features of the pre-training triplets through a multi-head attention encoder and a projection layer, and optimize the distance between positive samples and the distance between negative samples through a comparison loss function to achieve parameter optimization of the multi-head attention encoder;

[0079] A model fine-tuning module 204 is used to add a fully connected layer suitable for the classification task on the basis of the multi-head attention encoder to form an initial classification model, and fine-tune the initial classification model using the original training data set;

[0080] The traffic classification module 205 is used to input the feature vector of the fully connected layer into the Softmax function for calculation to obtain the probability that the network traffic to be detected belongs to each category.

[0081] The traffic feature extraction module 201 is further used to: classify and reorganize the network traffic to be detected according to the TCP quintuple, mark the transmission direction of each data packet in the reorganized network traffic, and intercept the first N data packets from each flow, and extract the first M bytes of the original payload of each data packet; after removing the bias information in the original payload, divide the original payload into two-byte blocks, encode the two-byte blocks using a 1-gram dictionary to form a packet-level payload feature; measure and record the length of each data packet, encode the length of the data packet using a 1-gram dictionary to form a stream-level packet length sequence feature.

[0082] The feature concatenation module 202 is further used to concatenate the packet-level load feature and the flow-level packet length sequence feature to form a discrete input sequence, which is expressed by the following formula:

[0083]

[0084] in, represents a discrete input sequence, Indicates the start of input. Indicates the separator mark, Indicates packet-level load characteristics. Stream-level packet length sequence characteristics;

[0085] Using the parameter matrix For discrete input sequences Perform word embedding processing. is the matrix size, is the matrix dimension, and we get a high-dimensional vector , adding position encoding information to the high-dimensional vector, expressed as:

[0086]

[0087] in, Indicates the position of the packet in the flow, represents the dimension index in the positional encoding vector, Iterating over a collection , D represents the maximum number of positions , Indicates the position of an element in a sequence. Indicates the number of dimensions of each position encoding vector.

[0088] The comparative pre-training module 203 is further used to: copy the high-dimensional vector once as a positive sample, and the positive sample is represented differently from the original positive sample after passing through the multi-head attention encoder and the projection layer, and the two are regarded as positive examples of each other; when the positive sample and the other sample have different category labels, the other sample is regarded as a strong negative sample of the positive sample; when the positive sample and the other sample have the same category label and there is a difference in the communication information between the two, the other sample is regarded as a weak negative sample of the positive sample;

[0089] The pre-trained triples are processed by stacking multiple layers of multi-head attention encoders and multiple layers of projection layers to obtain corresponding hidden layer feature triples; wherein the multi-head attention encoder includes a self-attention layer and a feedforward neural network, and the projection layer includes a fully connected layer activated by ReLU; the distance between positive samples and the distance between negative samples of the model are optimized by the following contrast loss function:

[0090]

[0091] in, Represents the target of the contrastive loss function; Indicates that for positive samples The contrast loss of represents the input sample; represents a positive sample; Represents a weak negative sample; Indicates a strong negative sample; Indicates samples; Represents the first samples; represents the temperature parameter; Indicates the weight of strong / weak negative samples; Representation sample similarity; Representation sample similarity;

[0092] The traffic classification module 205 is further used to: input the output feature vector of the fully connected layer into the Softmax function, and use the Softmax function to predict the given sample Belongs to category The probability is:

[0093]

[0094] Among them, the weight matrix between the Softmax layer and the last fully connected layer is To express, is the bias vector, Represents the category label predicted by the model; Represents a transpose operation; Indicates the index of the category; Represents the feature representation vector obtained after the input sample is processed by the network layer.

[0095] It should be noted that the encrypted traffic detection device 200 based on contrastive learning pre-training provided in this embodiment corresponds to a technical solution that can be used to execute various method embodiments. Its implementation principle and technical effects are similar to the method and will not be repeated here.

[0096] Figure 4 A schematic diagram of the structure of an electronic device 300 provided in another embodiment of the present invention, the electronic device is used to implement the encrypted traffic detection method based on contrastive learning pre-training in the method embodiment. The electronic device 300 in the embodiment of the present invention may include but is not limited to mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle terminals (such as vehicle navigation terminals), wearable electronic devices, etc., and fixed terminals such as digital TVs, desktop computers, laptops, etc. Figure 4 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0097] like Figure 4 As shown, the electronic device 300 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 302 or a program loaded from a storage device 308 to a random access memory (RAM) 303 to implement the method of the embodiment of the present invention. In the RAM 303, various programs and data required for the operation of the electronic device 300 are also stored. The processing device 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.

[0098] Typically, the following devices may be connected to the I / O interface 305: an input device 306 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 308 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 309. The communication device 309 may allow the electronic device 300 to communicate with other devices wirelessly or by wire to exchange data. Figure 4 The electronic device 300 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0099] The above description is only a preferred embodiment of the present invention. Those skilled in the art should understand that the scope of disclosure involved in the present invention is not limited to the technical solution formed by a specific combination of the above technical features, but also should cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present invention (but not limited to) to form a technical solution.

Claims

1. An encrypted traffic detection method based on contrastive learning pre-training, characterized in that: include: Traffic feature extraction step: extracting the packet-level load features and flow-level packet length sequence features of the network traffic to be detected; Feature splicing step: splicing the packet-level load features and the flow-level packet length sequence features, and converting the discrete input sequence obtained after splicing into a high-dimensional vector, specifically including: The packet-level load characteristics and the flow-level packet length sequence characteristics are concatenated to form a discrete input sequence, which is expressed by the following formula: in, represents a discrete input sequence, Indicates the start of input. Indicates the separator mark, Indicates packet-level load characteristics. Stream-level packet length sequence characteristics; Using the parameter matrix For discrete input sequences Perform word embedding processing. is the matrix size, is the matrix dimension, and we get a high-dimensional vector , adding position encoding information to the high-dimensional vector, expressed as: in, Indicates the position of the packet in the flow, represents the dimension index in the positional encoding vector, Iterating over a collection , D represents the maximum number of positions , Indicates the position of an element in a sequence. Indicates the number of dimensions of each position encoding vector; A comparative pre-training step: sampling positive and negative sample pairs of the high-dimensional vector to form pre-training triplets, extracting hidden layer features of the pre-training triplets through a multi-head attention encoder and a projection layer, and optimizing the distance between positive samples and the distance between negative samples through a comparative loss function to achieve parameter optimization of the multi-head attention encoder; Model fine-tuning step: Add a fully connected layer suitable for the classification task on the basis of the multi-head attention encoder to form an initial classification model, and fine-tune the initial classification model using the original training dataset; Traffic classification step: Input the feature vector of the fully connected layer into the Softmax function for calculation to obtain the probability that the network traffic to be detected belongs to each category.

2. According to claim 1, the encrypted traffic detection method based on contrastive learning pre-training is characterized in that ,The flow feature extraction step further includes: The network traffic to be detected is classified and reorganized according to the TCP quintuple, the transmission direction of each data packet in the reorganized network traffic is marked, and the first N data packets are intercepted from each flow, and the first M bytes of the original payload of each data packet are extracted; after removing the bias information in the original payload, the original payload is divided into two-byte blocks, and the two-byte blocks are encoded using a 1-gram dictionary to form a packet-level payload feature; the length of each data packet is measured and recorded, and the length of the data packet is encoded using a 1-gram dictionary to form a stream-level packet length sequence feature.

3. According to claim 1, the encrypted traffic detection method based on contrastive learning pre-training is characterized in that: The comparison pre-training step further includes: The high-dimensional vector is copied once as a positive sample. After the positive sample passes through the multi-head attention encoder and the projection layer, it obtains a different representation from the original positive sample, and the two are regarded as positive examples of each other; When the positive sample and the other sample have different category labels, the other sample is regarded as a strong negative sample of the positive sample; when the positive sample and the other sample have the same category label and there is a difference in the communication information between the two, the other sample is regarded as a weak negative sample of the positive sample.

4. According to claim 3, the encrypted traffic detection method based on contrastive learning pre-training is characterized in that: The comparison pre-training step further includes: Processing the pre-trained triples with a plurality of multi-head attention encoders and a plurality of projection layers stacked in sequence to obtain corresponding hidden layer feature triples; wherein the multi-head attention encoder comprises a self-attention layer and a feedforward neural network, and the projection layer comprises a fully connected layer activated by ReLU; The distance between the model's positive samples and the distance between the negative samples are optimized by the following contrast loss function: in, Represents the target of the contrastive loss function; Indicates that for positive samples The contrast loss of represents the input sample; represents a positive sample; Represents a weak negative sample; Indicates a strong negative sample; Indicates samples; Represents the first samples; represents the temperature parameter; Indicates the weight of strong / weak negative samples; Representation sample similarity; Representation sample The similarity.

5. According to claim 1, the encrypted traffic detection method based on contrastive learning pre-training is characterized in that: The traffic classification step further comprises: The output feature vector of the fully connected layer is input into the Softmax function, and the Softmax function is used to predict the given sample Belongs to category The probability is: Among them, the weight matrix between the Softmax layer and the last fully connected layer is To express, is the bias vector, Represents the category label predicted by the model; represents the transpose operation; Indicates the index of the category; Represents the feature representation vector obtained after the input sample is processed by the network layer.

6. An encrypted traffic detection device based on contrastive learning pre-training, characterized in that include: Traffic feature extraction module, used to extract packet-level load features and flow-level packet length sequence features of the network traffic to be detected; The feature concatenation module is used to concatenate the packet-level load features and the flow-level packet length sequence features, and convert the concatenated discrete input sequence into a high-dimensional vector, specifically including: The packet-level load characteristics and the flow-level packet length sequence characteristics are concatenated to form a discrete input sequence, which is expressed by the following formula: in, represents a discrete input sequence, Indicates the start of input. Indicates the separator mark, Indicates packet-level load characteristics. Stream-level packet length sequence characteristics; Using the parameter matrix For discrete input sequences Perform word embedding processing. is the matrix size, is the matrix dimension, and we get a high-dimensional vector , adding position encoding information to the high-dimensional vector, expressed as: in, Indicates the position of the packet in the flow, represents the dimension index in the positional encoding vector, Iterating over a collection , D represents the maximum number of positions , Indicates the position of an element in a sequence. Indicates the number of dimensions of each position encoding vector; A contrast pre-training module is used to sample positive and negative sample pairs of the high-dimensional vector to form pre-training triplets, extract hidden layer features of the pre-training triplets through a multi-head attention encoder and a projection layer, and optimize the distance between positive samples and the distance between negative samples through a contrast loss function to achieve parameter optimization of the multi-head attention encoder; A model fine-tuning module is used to add a fully connected layer suitable for the classification task on the basis of the multi-head attention encoder to form an initial classification model, and fine-tune the initial classification model using the original training data set; The traffic classification module is used to input the feature vector of the fully connected layer into the Softmax function for calculation to obtain the probability that the network traffic to be detected belongs to each category.

7. The encrypted traffic detection device based on contrastive learning pre-training according to claim 6 is characterized in that ,The flow feature extraction module is further used to: The network traffic to be detected is classified and reorganized according to the TCP quintuple, the transmission direction of each data packet in the reorganized network traffic is marked, and the first N data packets are intercepted from each flow, and the first M bytes of the original payload of each data packet are extracted; after removing the bias information in the original payload, the original payload is divided into two-byte blocks, and the two-byte blocks are encoded using a 1-gram dictionary to form a packet-level payload feature; the length of each data packet is measured and recorded, and the length of the data packet is encoded using a 1-gram dictionary to form a stream-level packet length sequence feature.

8. The encrypted traffic detection device based on contrastive learning pre-training according to claim 6 is characterized in that: The comparative pre-training module is further used to: copy the high-dimensional vector once as a positive sample, and the positive sample obtains a different representation from the original positive sample after passing through the multi-head attention encoder and the projection layer, and the two are regarded as positive examples of each other; when the positive sample and the other sample have different category labels, the other sample is regarded as a strong negative sample of the positive sample; when the positive sample and the other sample have the same category label and there is a difference in the communication information between the two, the other sample is regarded as a weak negative sample of the positive sample; use multiple layers of multi-head attention encoders and multiple layers of projection layers stacked in sequence to process the pre-training triples to obtain corresponding hidden layer feature triples; wherein the multi-head attention encoder includes a self-attention layer and a feedforward neural network, and the projection layer includes a fully connected layer activated by ReLU; optimize the distance between the positive sample and the distance between the negative sample of the model through the following comparative loss function: in, Represents the target of the contrastive loss function; Indicates that for positive samples The contrast loss of represents the input sample; represents a positive sample; Represents a weak negative sample; Indicates a strong negative sample; Indicates samples; Represents the first samples; represents the temperature parameter; Indicates the weight of strong / weak negative samples; Representation sample similarity; Representation sample similarity; The traffic classification module is further used to: input the output feature vector of the fully connected layer into the Softmax function, and use the Softmax function to predict the given sample Belongs to category The probability is: Among them, the weight matrix between the Softmax layer and the last fully connected layer is To express, is the bias vector, Represents the category label predicted by the model; represents the transpose operation; Indicates the index of the category; Represents the feature representation vector obtained after the input sample is processed by the network layer.

Citation Information

Patent Citations

  • Malicious encrypted traffic identification method and device, electronic equipment and storage medium

    CN116418558A

  • Encrypted malicious traffic small sample detection method and system based on comparative learning

    CN116827671A

  • Intrusion detection method fusing comparative learning and feature selection

    CN117081808A

  • Malicious traffic detection method based on mask automatic encoder pre-training

    CN118400195A

  • Header-based packet filtering and inferencing to identify malicious network traffic using neural networks

    US20220255897A1