Encrypted traffic type detection method, apparatus, program product, and electronic device
By using a spatiotemporal feature fusion detection method, the problem of low accuracy in encrypted traffic detection is solved. This method enables multi-dimensional feature capture in encrypted environments, improving detection accuracy and adaptability, and is suitable for complex network scenarios such as banking.
Patent Information
- Application Number
- CN202611397993.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-09
- Publication Date
- 2026-11-24
AI Technical Summary
Existing technologies have low accuracy in encrypted traffic detection, struggle to capture key features under strong encryption protocols, and have poor model adaptability, failing to meet the real-time protection needs of financial networks.
A spatiotemporal feature fusion detection method is adopted. By extracting spatial and temporal features from encrypted traffic, a grayscale image is generated and multi-scale convolution operation is performed. Combined with a multi-head attention module and a Transformer model, the global dependency relationship of byte sequence is captured to achieve classification of encrypted traffic types.
It improves the accuracy and robustness of encrypted traffic detection, overcomes the problems of missing content features and weak model generalization ability caused by traffic encryption, has strong adaptability, and can maintain good detection performance in complex network scenarios such as banks.
Smart Images

Figure CN123164028A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology or other related technical fields. Specifically, it relates to a method, apparatus, program product, and electronic device for detecting the type of encrypted traffic. Background Technology
[0002] Currently, deep learning technology has been widely used in financial institutions for traffic detection; however, it still has the following shortcomings in actual financial business scenarios:
[0003] (1) Since the traffic is encrypted, the effective content features that the deep learning model can extract are reduced. Under strong encryption protocols, it is difficult for intelligent models to capture key features related to risky behavior from the ciphertext, thus affecting the accuracy of identifying bank network attacks.
[0004] (2) The continuous updates and iterations of traffic encryption protocols have led to a decline in the adaptability of existing detection models. When new encryption protocols appear, the detection rate of the model decreases because it has not learned the corresponding features. It is often necessary to re-collect banking scenario data and retrain the model, which is difficult to meet the real-time protection requirements of financial networks.
[0005] (3) Most deep learning methods extract only a single feature of traffic, but the feature dimension is singular and not comprehensive, resulting in weak model practicality and generalization ability. In the complex network environment of banks with multiple businesses and multiple links, the detection effect is unstable.
[0006] There is currently no effective solution to the technical problem of low accuracy in detecting encrypted traffic based on existing technologies. Summary of the Invention
[0007] This application provides a method, apparatus, program product, and electronic device for detecting the type of encrypted traffic, in order to at least solve the technical problem of low accuracy in classifying encrypted traffic based on existing technologies.
[0008] According to one aspect of this application, a method for detecting the type of encrypted traffic is provided, comprising: preprocessing an encrypted traffic file to obtain a target session, wherein the target session carries application layer data; determining a target sequence based on the application layer data in the target session, wherein the target sequence includes T bytes, where T is a positive integer; generating a target grayscale image based on the target sequence, wherein each pixel in the target grayscale image represents one byte of the T bytes; performing feature extraction on the target sequence to obtain temporal features of the target session, and performing feature extraction on the target grayscale image to obtain spatial features of the target session; and determining the traffic type of the encrypted traffic in the target session based on the temporal features and spatial features.
[0009] Optionally, the encrypted traffic file is preprocessed to obtain the target session, including: segmenting the encrypted traffic file according to network sessions to obtain an initial session set, wherein the initial session set includes at least one initial session; if the k-th initial session in the initial session set carries application layer data and the total length of the bytes corresponding to the carried application layer data is greater than a preset length threshold, the k-th initial session is taken as the target session.
[0010] Optionally, determining the target sequence based on application layer data in the target session includes: detecting the number of original bytes included in the application layer data in the target session to obtain the original byte length; if the original byte length is less than T, padding the end of the application layer data with P zero bytes, and taking all the original bytes and P zero bytes in the application layer data as the target sequence, where P is the difference between T and the original byte length; if the original byte length is greater than or equal to T, taking the first T original bytes in the application layer data as the target sequence.
[0011] Optionally, feature extraction is performed on the target sequence to obtain the temporal features of the target session, including: performing vector transformation on T bytes in the target sequence to obtain an embedding vector sequence, wherein the embedding vector sequence includes T embedding vectors, each embedding vector having a dimension of d, where d is a positive integer; adding position encoding to each embedding vector in the embedding vector sequence to obtain a target vector sequence, wherein the position encoding is used to represent the position information of the corresponding embedding vector; extracting features from the target vector sequence through a multi-head attention module to obtain h sub-features, wherein h is a positive integer, the multi-head attention module includes h attention heads, and each sub-feature is the global dependency between target vectors extracted by an attention head; performing residual connection and layer normalization processing on the h sub-features to obtain the temporal features of the target session.
[0012] Optionally, feature extraction is performed on the target grayscale image to obtain the spatial features of the target session, including: performing convolution operations on the target grayscale image through Q convolutional paths to obtain Q convolutional features, where Q is a positive integer; performing channel weighting processing on each convolutional feature through the convolutional attention module corresponding to each convolutional path to obtain Q channel weighted features; and concatenating the Q channel weighted features to obtain the spatial features of the target session.
[0013] Optionally, the Q convolutional paths include a first convolutional path, a second convolutional path, a third convolutional path, and a fourth convolutional path. Convolutional operations are performed on the target grayscale image through these Q convolutional paths to obtain Q convolutional features, including: performing a 1×1 convolution operation on the target grayscale image through the first convolutional path to obtain the first convolutional feature; performing a 1×1 convolution operation followed by a 3×3 convolution operation on the target grayscale image through the second convolutional path to obtain the second convolutional feature; performing a 1×1 convolution operation followed by a 5×5 convolution operation on the target grayscale image through the third convolutional path to obtain the third convolutional feature; and performing a 3×3 convolution operation followed by a 1×5 convolution operation on the target grayscale image through the fourth convolutional path to obtain the fourth convolutional feature. The first, second, third, and fourth convolutional features are then used as the Q convolutional features.
[0014] Optionally, determining the traffic type of encrypted traffic in the target session based on temporal and spatial features includes: performing feature fusion on temporal and spatial features to obtain the spatiotemporal features of the target session; and determining the traffic type of encrypted traffic in the target session based on the spatiotemporal features of the target session using a target model, wherein the target model includes a multilayer perceptron and a preset classification module.
[0015] According to another aspect of this application, an encrypted traffic type detection device is also provided, comprising: a preprocessing unit for preprocessing an encrypted traffic file to obtain a target session, wherein the target session carries application layer data; a sequence determination unit for determining a target sequence based on the application layer data in the target session, wherein the target sequence includes T bytes, where T is a positive integer; a graph generation unit for generating a target grayscale image based on the target sequence, wherein each pixel in the target grayscale image represents one byte of the T bytes; a feature extraction unit for performing feature extraction on the target sequence to obtain temporal features of the target session, and performing feature extraction on the target grayscale image to obtain spatial features of the target session; and a type detection unit for determining the traffic type of the encrypted traffic in the target session based on the temporal features and spatial features.
[0016] According to another aspect of this application, a computer program product is also provided, which stores a computer program, wherein, when the computer program is running, it controls the computer program product to execute any of the above-mentioned encrypted traffic type detection methods.
[0017] According to another aspect of this application, an electronic device is also provided, wherein the electronic device includes one or more processors and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the encrypted traffic type detection method of any of the above.
[0018] As described above, this application employs a spatiotemporal feature fusion detection method. Through a dual architecture of spatial feature extraction and temporal feature extraction of encrypted traffic, it aims to classify session traffic in encrypted traffic files. Specifically, this application first extracts the application layer data of the target session from the encrypted traffic file and generates a fixed-length byte sequence. This sequence is then synchronously converted into a grayscale image representing the byte distribution characteristics. Subsequently, multi-scale spatial features are extracted from the grayscale image. At the same time, the byte sequence is embedded and self-attention mechanism is used to capture temporal features, thereby obtaining the global dependency relationship between any time steps in the byte sequence. Then, this application determines the traffic type of the encrypted traffic in the target session based on the temporal and spatial features.
[0019] Therefore, this application achieves the capture of multi-dimensional traffic features in an encrypted traffic environment through the above steps, thereby overcoming the technical defects of traditional methods such as the lack of content features, insufficient single feature dimensions, and weak model generalization ability caused by traffic encryption. It achieves the technical effect of improving the accuracy and robustness of encrypted malicious traffic detection, and solves the technical problem of low accuracy in classifying encrypted traffic based on existing technologies. Attached Figure Description
[0020] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0021] Figure 1 This is a hardware structure block diagram of an optional computer terminal (or mobile device) for implementing a type detection method for encrypted traffic, according to an embodiment of this application.
[0022] Figure 2 This is a flowchart of an optional encrypted traffic type detection method according to an embodiment of this application;
[0023] Figure 3 This is a structural diagram of an optional encrypted traffic type detection system according to an embodiment of this application;
[0024] Figure 4 This is a grayscale image of an optional different type of encrypted traffic according to an embodiment of this application;
[0025] Figure 5 This is a structural diagram of an optional spatial feature extraction module according to an embodiment of this application;
[0026] Figure 6 This is a schematic diagram of an optional encrypted traffic type detection device according to an embodiment of this application;
[0027] Figure 7 This is a structural block diagram of an electronic device according to an embodiment of this application. Detailed Implementation
[0028] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0029] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0030] It should also be noted that all information and data (including but not limited to information used for display and analysis) involved in this application are authorized by the user or fully authorized by all parties. For example, if there is an interface between this system and the relevant user or organization, before obtaining the relevant information, it is necessary to send a request to the aforementioned user or organization through the interface, and obtain the relevant information only after receiving consent from the aforementioned user or organization.
[0031] Furthermore, the collection, storage, use, processing, transmission, provision, disclosure, and application of relevant information and data involved in this application all comply with the relevant laws, regulations, and standards of the relevant regions, and necessary security measures have been taken. They do not violate public order and good morals. In addition, this application provides corresponding operation entry points for users to choose to agree to authorization or refuse authorization. If the user chooses to refuse authorization, the corresponding expert decision-making process will be initiated.
[0032] This application aims to propose a method for detecting the type of encrypted traffic based on a spatiotemporal feature fusion mechanism for banking scenarios. This method does not rely on manual, experience-based feature extraction and can overcome the limitations of traffic encryption. It can mine effective information from both temporal and spatial dimensions, ensuring that a stable feature source can still be obtained in the encrypted traffic environment. Since network spatiotemporal features have universality and stability and are not easily affected by encryption protocol updates, this method has stronger adaptability and generalization ability. It can maintain good detection performance in various business network scenarios of banks. By learning the differences between normal traffic and attack traffic in spatiotemporal features, it can accurately characterize traffic behavior and thus achieve efficient identification of encrypted attack traffic in banks.
[0033] The present application will now be described in detail with reference to various embodiments.
[0034] Example 1
[0035] According to an embodiment of this application, an embodiment of a method for detecting the type of encrypted traffic is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0036] The methods and embodiments provided in this application can be executed on mobile terminals, computer terminals, or similar computing devices. Figure 1 This is a hardware structure block diagram of an optional computer terminal (or mobile device) for implementing a method for detecting the type of encrypted traffic, according to an embodiment of this application. Figure 1 As shown, the computer terminal 10 (or mobile device) may include one or more processors 102 (shown as 102a, 102b, ..., 102n in the figure) 102 (processor 102 may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of a BUS bus), a network interface, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, computer terminal 10 may also include... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0037] It should be noted that the aforementioned one or more processors 102 and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer terminal 10 (or mobile device). As involved in the embodiments of this application, the data processing circuits serve as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).
[0038] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the encrypted traffic type detection method in this embodiment. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby implementing the aforementioned encrypted traffic type detection method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0039] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the computer terminal 10. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0040] The display can be configured as a touchscreen liquid crystal display (LCD) that allows the user to interact with the user interface of the computer terminal 10 (or mobile device).
[0041] Under the aforementioned operating environment, this application provides an encrypted traffic type detection system (hereinafter referred to as the detection system) for executing the encrypted traffic type detection method in this application. Figure 2 This is a flowchart of an optional encrypted traffic type detection method according to an embodiment of this application, such as... Figure 2 As shown, the method includes the following steps:
[0042] Step S201: Preprocess the encrypted traffic file to obtain the target session, wherein the target session carries application layer data.
[0043] Optionally, the detection system first uses SplitCap (a network session segmentation tool) to segment the PCAP (Packet Capture) file (i.e., encrypted traffic file) according to the session format to obtain multiple initial sessions. Then, the initial session set is cleaned to retain only the target session that carries data communication information (i.e., application layer data).
[0044] Optionally, since the sessions after the tool is segmented vary in length, some sessions may lack key information. Although these sessions are included in the encrypted traffic file, they do not carry valid data communication information. Therefore, the detection system cleans up these empty sessions, thereby reducing the size of the dataset to be analyzed and improving the efficiency and accuracy of subsequent traffic analysis results.
[0045] Step S202: Determine the target sequence based on the application layer data in the target session, wherein the target sequence includes T bytes, where T is a positive integer.
[0046] Optionally, in practical applications, T can be set to 784. The detection system detects the number of raw bytes included in the application layer data in the target session. In order to ensure that the data input to the intelligent model in the future must be of a fixed length, the sequence length is specified as 784 bytes. Session sequences with insufficient length are padded with zeros at the end, and those exceeding the range are truncated to the first 784 bytes.
[0047] Optionally, the detection system solves the problem of variable network traffic packet length by truncating a target sequence of fixed length, thus achieving standardization of input data. By truncating or padding with zeros, the detection system ensures that the subsequent intelligent model can receive traffic data of different lengths in a unified format. By truncating the first 784 bytes of the target session in the PCAP file, the system can retain key data communication information in the target session while reducing the amount of data to be analyzed.
[0048] Step S203: Generate a target grayscale image based on the target sequence, wherein each pixel in the target grayscale image represents one byte out of T bytes.
[0049] Optionally, the detection system maps the target sequence of length T into a two-dimensional pixel matrix. For example, if T is 784, the matrix size is 28×28. Each element in the matrix corresponds to a byte value in the target sequence, and the value is mapped to the pixel grayscale value (0 for black, 255 for white) in the grayscale image, thereby generating the target grayscale image.
[0050] Optionally, the detection system transforms one-dimensional byte sequences into two-dimensional image data, enabling the use of sophisticated convolutional neural networks (CNNs) to extract spatial features in subsequent steps. This visual representation preserves local spatial correlations between bytes (such as the fixed structure of protocol headers and repetition patterns of encrypted blocks), allowing intelligent models to capture the static structural features of traffic from a spatial dimension, thus compensating for the shortcomings of plain text sequences in spatial feature extraction.
[0051] Step S204: Extract features from the target sequence to obtain the temporal features of the target session, and extract features from the target grayscale image to obtain the spatial features of the target session.
[0052] Optionally, temporal features refer to the feature representations captured by the Transformer that reflect the temporal order dependencies and global context relationships in the sequence of traffic bytes; spatial features refer to the feature representations captured by the CNN that reflect the multi-scale structure, texture, and local details in the image of the distribution of traffic bytes.
[0053] Optionally, the detection system achieves multi-dimensional feature extraction by extracting features from the target sequence. The extraction of temporal features enables the detection system to capture the logical relationships between long-distance bytes in encrypted traffic (such as the relationship between the handshake phase and the application data phase), solving the problems of gradient vanishing or low parallelism in traditional technologies when processing long sequences. At the same time, the extraction of spatial features enables the detection system to adaptively focus on key regions and important channels in the image. The combination of the two achieves the feature characterization of encrypted traffic from both temporal and spatial dimensions.
[0054] Step S205: Determine the traffic type of encrypted traffic in the target session based on temporal and spatial characteristics.
[0055] Optionally, the detection system concatenates the extracted temporal and spatial features along the channel dimension to obtain the spatiotemporal features corresponding to the target session. Then, the target model determines the traffic type of the encrypted traffic in the target session based on the spatiotemporal features of the target session. The target model includes a multilayer perceptron (MLP) and a preset classification module.
[0056] Optionally, traffic type refers to the determination result of the category to which the target session belongs, which is usually divided into two categories: normal traffic and malicious attack traffic; spatiotemporal features refer to the comprehensive feature vector formed by the fusion of temporal features and spatial features, which contains both temporal and spatial information of the traffic.
[0057] Optionally, using temporal or spatial features alone may lead to misjudgment of traffic type due to incomplete information. By combining the two, the detection system can use spatiotemporal features to more comprehensively characterize the behavior of encrypted traffic. This allows the target model to accurately classify traffic based on stable spatiotemporal patterns even when faced with content feature loss due to strong encryption protocols, which helps improve the accuracy and generalization ability of detection.
[0058] As described above, this application employs a spatiotemporal feature fusion detection method. Through a dual architecture of spatial feature extraction and temporal feature extraction of encrypted traffic, it aims to classify session traffic in encrypted traffic files. Specifically, this application first extracts the application layer data of the target session from the encrypted traffic file and generates a fixed-length byte sequence. This sequence is then synchronously converted into a grayscale image representing the byte distribution characteristics. Subsequently, multi-scale spatial features are extracted from the grayscale image. At the same time, the byte sequence is embedded and self-attention mechanism is used to capture temporal features, thereby obtaining the global dependency relationship between any time steps in the byte sequence. Then, this application determines the traffic type of the encrypted traffic in the target session based on the temporal and spatial features.
[0059] Therefore, this application achieves the capture of multi-dimensional traffic features in an encrypted traffic environment through the above steps, thereby overcoming the technical defects of traditional methods such as the lack of content features, insufficient single feature dimensions, and weak model generalization ability caused by traffic encryption. It achieves the technical effect of improving the accuracy and robustness of encrypted malicious traffic detection, and solves the technical problem of low accuracy in classifying encrypted traffic based on existing technologies.
[0060] In this embodiment, the detection system first segments the encrypted traffic file according to network sessions to obtain an initial session set, wherein the initial session set includes at least one initial session. Then, if the k-th initial session in the initial session set carries application layer data and the total length of the bytes corresponding to the carried application layer data is greater than a preset length threshold, the detection system will take the k-th initial session as the target session.
[0061] Optionally, the detection system can segment the encrypted traffic file by network session to obtain an initial session set, which can solve the problem of mixed and complex original traffic data and achieve finer data granularity. On this basis, the detection system determines whether the k-th initial session carries application layer data and whether its total byte length is greater than a preset length threshold, and thus selects the k-th initial session as the target session. This filtering mechanism can eliminate "empty sessions" that only contain control information such as TCP handshake and disconnection or have no actual data payload, thus avoiding interference from invalid data to the subsequent traffic type detection of the target model.
[0062] In this embodiment, the detection system first detects the number of raw bytes included in the application layer data of the target session to obtain the raw byte length. Then, if the raw byte length is less than T, the detection system pads the end of the application layer data with P zero bytes and takes all the raw bytes and P zero bytes in the application layer data as the target sequence, where P is the difference between T and the raw byte length. In addition, if the raw byte length is greater than or equal to T, the first T raw bytes in the application layer data are taken as the target sequence.
[0063] Optionally, the detection system can solve the technical defect of inconsistent model input dimensions caused by the variable length of network traffic packets by detecting the original byte length of application layer data in the target session and performing padding or truncation operations according to the relationship between this length and the preset length T. Specifically, when the original byte length is less than T, the detection system pads the data to T by padding P zero bytes. When the original byte length is greater than or equal to T, the first T original bytes are truncated. The above processing mechanism ensures that all data input to the model are byte sequences of consistent length, which meets the requirement of deep learning models for fixed input dimensions. At the same time, the above processing mechanism can set T to 784, thereby suppressing the data size while retaining key traffic features (such as protocol header information, initial handshake features, etc.), thus avoiding computational redundancy caused by excessively long traffic sequences.
[0064] In this embodiment, the detection system first performs vector transformation on T bytes in the target sequence to obtain an embedded vector sequence, wherein the embedded vector sequence includes T embedded vectors, each embedded vector having a dimension of d, where d is a positive integer. Then, the detection system adds positional encoding to each embedded vector in the embedded vector sequence to obtain a target vector sequence, wherein the positional encoding is used to represent the positional information of the corresponding embedded vector. Then, the detection system extracts features from the target vector sequence through a multi-head attention module to obtain h sub-features, wherein h is a positive integer. The multi-head attention module includes h attention heads, and each sub-feature is the global dependency between target vectors extracted by an attention head. Subsequently, the detection system performs residual connection and layer normalization processing on the h sub-features to obtain the temporal features of the target session.
[0065] Optionally, the detection system performs vector transformation on T bytes in the target sequence to obtain an embedded vector sequence, and adds positional encoding to construct the target vector sequence. This addresses the technical shortcomings of traditional neural networks in handling variable-length sequences and lacking positional awareness, thus enabling the understanding of the ordered nature of the byte sequence. Subsequently, the detection system performs parallel computation on the target vector sequence using a multi-head attention module to extract h sub-features, thereby capturing the global dependency between any two bytes in the target session. This overcomes the computational bottleneck and insufficient long-distance dependency capture of recurrent neural networks when processing long sequences. Finally, the detection system performs residual connections and layer normalization on the h sub-features to obtain the temporal features of the target session that can stably propagate gradients. In other words, through the above steps, the detection system accurately characterizes the complex logical relationships between bytes in encrypted traffic from a temporal dimension, providing a temporal representation rich in global contextual information for subsequent spatiotemporal feature fusion, which helps improve the accuracy of traffic type detection.
[0066] In this embodiment, the detection system first performs convolution operations on the target grayscale image through Q convolution paths to obtain Q convolution features, where Q is a positive integer. Then, the detection system performs channel weighting processing on each convolution feature through the convolution attention module corresponding to each convolution path to obtain Q channel weighted features. Finally, the detection system concatenates the Q channel weighted features to obtain the spatial features of the target session.
[0067] Optionally, the detection system performs convolution operations on the target grayscale image through Q convolutional paths to obtain Q convolutional features. This allows the system to simultaneously capture fine details and macroscopic structures in the target grayscale image from multiple scale perspectives, solving the problem of insufficient feature representation caused by a single receptive field and enriching the dimensions of spatial features. Subsequently, the detection system performs channel-weighted processing on each convolutional feature through the convolutional attention module corresponding to each convolutional path, obtaining Q channel-weighted features. This adaptively enhances key feature channels and suppresses irrelevant noise, improving the purity and discriminative power of feature representation. Finally, the detection system concatenates the Q channel-weighted features to obtain the spatial features of the target session, which can integrate complementary information from multiple paths and scales. In other words, by combining parallel multi-scale convolution with attention mechanisms, the detection system ensures that discriminative spatial structural features can be extracted from the image representation of encrypted traffic, providing spatial input for subsequent fusion with temporal features and helping to improve the accuracy of traffic type detection.
[0068] In this embodiment, the Q convolutional paths include a first convolutional path, a second convolutional path, a third convolutional path, and a fourth convolutional path. During the convolutional operation on the target grayscale image, the detection system includes the following steps: performing a 1×1 convolution on the target grayscale image through the first convolutional path to obtain a first convolutional feature; performing a 1×1 convolution on the target grayscale image through the second convolutional path, followed by a 3×3 convolutional operation to obtain a second convolutional feature; performing a 1×1 convolution on the target grayscale image through the third convolutional path, followed by a 5×5 convolutional operation to obtain a third convolutional feature; performing a 3×3 convolution on the target grayscale image through the fourth convolutional path, followed by a 1×5 convolutional operation to obtain a fourth convolutional feature; and using the first, second, third, and fourth convolutional features as the Q convolutional features.
[0069] Optionally, the detection system sets up a first convolutional path, a second convolutional path, a third convolutional path, and a fourth convolutional path to perform 1×1 convolution, 1×1+3×3 convolution, 1×1+5×5 convolution, and 3×3 pooling+1×1 convolution operations on the target grayscale image, respectively. This allows the system to extract features from multiple different scales (i.e., receptive fields) simultaneously. The first convolutional path ensures flexible transformation of channel dimensions; the second convolutional path captures local details; the third convolutional path captures global structure; and the fourth convolutional path enhances robustness through pooling. This parallel multi-scale convolutional structure avoids the problem of limited receptive field of a single convolutional kernel, enabling the detection system to more comprehensively capture fine-grained textures and macroscopic morphologies in encrypted traffic images. This provides rich convolutional feature data for subsequent processing, helping to improve the expressive power and diversity of the final determined spatial feature extraction.
[0070] In this embodiment, the detection system first performs feature fusion on temporal and spatial features to obtain the spatiotemporal features of the target session. Then, the detection system determines the traffic type of encrypted traffic in the target session based on the spatiotemporal features of the target session using a target model. The target model includes a multilayer perceptron and a preset classification module.
[0071] Optionally, the detection system first fuses temporal and spatial features to obtain the spatiotemporal features of the target session. These spatiotemporal features characterize the logical dependencies of encrypted traffic in the time series and the distribution patterns in the spatial structure. Temporal features capture long-distance dependencies and macroscopic behavioral patterns between bytes, while spatial features capture the local texture and structural details of the traffic image. The fusion of the two achieves the complementarity of multi-dimensional information, which helps to overcome the detection blind spots under a single feature perspective. Subsequently, the detection system determines the traffic type of encrypted traffic in the target session based on the spatiotemporal features of the target session through the target model. That is, it performs nonlinear mapping and feature extraction on high-dimensional spatiotemporal features through a multilayer perceptron, and then outputs the probability that the encrypted traffic belongs to attack traffic through a preset classification module. This enables efficient binary classification of attack traffic. The detection system does not need to rely on manual empirical feature extraction, thus breaking through the limitation of traffic encryption shielding traffic content features. As a result, it can maintain high detection accuracy and generalization ability in complex network scenarios such as banks.
[0072] Figure 3 This is a structural diagram of an optional encrypted traffic type detection system according to an embodiment of this application, such as... Figure 3 As shown, the detection system includes a preprocessing module, a spatiotemporal feature extraction module, and an MLP classification module. The function of each module is as follows:
[0073] (1) Preprocessing module:
[0074] In the preprocessing module, the PCAP file is first segmented by session using the SplitCap tool. Next, data cleaning is performed to filter out valid sessions carrying application-layer data (i.e., target sessions). Then, the byte sequences of application-layer data from the valid sessions are extracted. Since the data input to the model needs to be of a fixed sequence length each time, in this embodiment, the fixed sequence length T is defined as 784 bytes. For valid sessions with insufficient length, zeros are padded to the end of the byte sequence; for valid sessions with excessive length, the first 784 bytes are truncated. Finally, the processed 784-byte sequence is converted into a 28×28 grayscale image (i.e., the target grayscale image), where each pixel in the grayscale image is represented by a grayscale value between 0 and 255, where 0 is black and 255 is white. Figure 4 This is an effect diagram of grayscale images corresponding to different types of encrypted traffic according to an embodiment of this application. Grayscale images numbered (a) and (b) are grayscale images corresponding to attack traffic with risks, and grayscale images numbered (a) and (b) are grayscale images corresponding to normal traffic without risks.
[0075] Here, the preprocessing module can reduce the amount of data that needs to be processed later by truncating the first 784 bytes of the byte sequence that is too long. This allows the key data communication information to be preserved.
[0076] (2) Spatiotemporal feature extraction module:
[0077] Optionally, the spatiotemporal feature extraction module includes a spatial feature extraction module and a temporal feature extraction module.
[0078] 1) Spatial Feature Extraction Module:
[0079] The spatial feature extraction module in this embodiment provides a spatial feature extraction method based on Inception (hybrid convolutional module) and CBAM (convolutional block attention module). Figure 5 This is a structural diagram of an optional spatial feature extraction module according to an embodiment of this application, such as... Figure 5 As shown, the spatial feature extraction module includes an Inception module and a CBAM module. The Inception module includes four parallel multi-scale convolutional kernels, and each convolutional kernel is connected to a corresponding CBAM module.
[0080] The Inception module processes input features in parallel using convolutional kernels of different scales, effectively capturing multi-scale information in images. This multi-scale processing method allows the network to focus on both local and global features simultaneously, thereby improving feature representation capabilities. When processing images of targets of different sizes, convolutional kernels of different scales can focus on the fine details of small targets and the overall shape of large targets, respectively.
[0081] In the actual feature extraction process, the Inception module is input with a 28×28 grayscale image. The first convolutional path in the parallel processing path (i.e., the first convolutional path) performs a 1×1 convolution operation. The 1×1 convolution operation can reduce or increase the number of channels without changing the size of the feature map space, reducing the computational cost of subsequent convolutional operations, and also playing a non-linear transformation role. The convolution operation performed by the first convolutional path is shown in the following formula:
[0082]
[0083] in, This indicates the input grayscale image. This represents the convolutional feature map obtained after a 1×1 convolution operation.
[0084] The second convolution path first performs a 1×1 convolution operation, followed by a 3×3 convolution operation. The 3×3 convolution kernel can capture local features better and performs better in extracting local details such as texture and edges of the image. The convolution operation performed by the second convolution path is shown in the following formula:
[0085]
[0086] in, It is the convolutional feature map output by the second convolutional path.
[0087] The third convolution path (i.e., the third convolutional path) includes 1×1 convolution operations and 5×5 convolution operations. The 5×5 convolution kernel can cover a larger receptive field, which is suitable for extracting macroscopic image features, such as the overall shape of the target and large structural information. The convolution operations performed by the third convolutional path are shown in the following formula:
[0088]
[0089] in, It is the convolutional feature map output by the third convolutional path.
[0090] The fourth convolution path consists of a 3×3 max pooling operation followed by a 1×1 convolution operation. Max pooling helps reduce the spatial dimension of the feature map, reduces computation, and ensures a certain degree of robustness against image deformation. The subsequent 1×1 convolution operation can further integrate information and perform nonlinear transformations on the pooled features. The convolution operation performed by the fourth convolution path is shown in the following formula:
[0091]
[0092] in, This is the convolutional feature map output by the fourth convolutional path.
[0093] In the above convolution operation paths, except for the 1×1 convolution operation in the first convolution path, the 1×1 convolution operation before the 3×3 or 5×5 convolution operation in each of the other convolution paths is to reduce the number of channels, thereby reducing the amount of computation.
[0094] Following each of the above convolutional paths is a CBAM module. The CBAM module adaptively assigns weights to the feature maps in both spatial and channel dimensions. Its purpose is to enhance important features and suppress unimportant features. The CBAM module consists of a channel attention module and a spatial attention module. The channel attention module evaluates the importance of each channel of the feature map and assigns different weights to each channel. This mechanism highlights channel features that contribute significantly to the task and suppresses channels that may introduce noise or irrelevant information. The spatial attention module weights the feature maps in the spatial dimension, making the network focus more on regions containing key information while ignoring irrelevant regions such as the background. Let the feature maps processed by the CBAM module (i.e., the channel-weighted feature maps) be as follows: , , as well as .
[0095] Finally, the feature maps obtained after processing through different convolutional paths and the CBAM module are... , , and The final spatial features are obtained by splicing along the channel dimension. As shown in the following formula:
[0096]
[0097] This method, which combines multi-scale convolutional parallel Inception structure with CBAM module, can effectively extract multi-scale spatial features of input image and enhance the discriminativeness of features through CBAM module, thus achieving more efficient and discriminative results in feature extraction.
[0098] 2) Temporal Feature Extraction Module:
[0099] The temporal feature extraction module is implemented based on the Encoder in Transformer. The Encoder can process time series data. Its advantage lies in the combination of multi-head self-attention mechanism and fully connected network, which can capture the temporal dependency features and complex patterns in the sequence. Compared with traditional recurrent neural networks, Transformer encoders are more efficient in processing long sequences, especially in parallel computing and capturing global dependencies.
[0100] In the temporal extraction process, the byte sequence is first embedded into a high-dimensional feature representation to obtain an embedding vector sequence. ( This indicates a sequence length of 784. This represents the dimension of the high-dimensional embedding vector obtained by transforming each byte in the 784 bytes. (representing the transformed embedding vector), then, positional encoding is added to each embedding vector in the transformed embedding vector sequence. This yields the corresponding new vector. The process is shown in the following formula.
[0101]
[0102] Among them, position coding This is achieved using trigonometric functions, thereby capturing the sequential relationships between different time steps and enabling positional encoding. The calculation process is shown in the following formula:
[0103]
[0104] Where t is the time step and i is the dimension index in the embedding vector.
[0105] The encoder, based on a self-attention mechanism, calculates... The self-attention mechanism captures global dependencies by comparing the similarity between each time step (i.e., each byte) in each vector within the sequence and other time steps (i.e., other bytes). Specifically, the computation process of the self-attention mechanism is shown in the following formula:
[0106]
[0107] in, These are the input query, key, and value matrix, respectively. It is the dimension of the key. The multi-head self-attention mechanism distributes the vector sequence obtained by adding positional encoding to the key. Each attention head performs computation in parallel, and finally... The result of each attention head output The splicing process is illustrated in the following formula:
[0108]
[0109] in, The output projection matrix is a learnable linear transformation matrix used to map the concatenated high-dimensional vector back to the desired output dimension.
[0110] Next, the obtained splicing result is subjected to residual connection and layer normalization processing, and then passed to the position-by-position feedforward neural network. The calculation process is shown in the following formula:
[0111]
[0112] in, Refers to the input basis of the current layer. This refers to the intermediate feature vector sequence obtained after the first residual connection and layer normalization process. It contains the fusion result of the original input information and the global dependency information extracted by the multi-head self-attention mechanism.
[0113]
[0114] in, Refers to the first The feature vector sequence output by the layer encoder contains the comprehensive features (i.e., sequential features) after processing by the self-attention mechanism and the position-by-position feedforward neural network.
[0115]
[0116] in, A position-wise feedforward neural network performs a nonlinear transformation on the input data. It typically consists of two linear layers and an activation function, used to extract local features and nonlinear representations. , , , These are the weights and biases of the fully connected layer.
[0117] It can be seen that, through the synergistic effect of multi-head self-attention mechanism and feedforward neural network, Transformer's Encoder can effectively extract global and local features in time series. The introduction of positional encoding ensures that the sequential information of time steps is preserved, which helps to improve the accuracy of the final obtained time series features.
[0118] 3) Spatiotemporal feature fusion processing:
[0119] In practice, technicians provided a method to fuse spatial features S and temporal features T into spatiotemporal features. Various methods were tested, including using S alone, using T alone, S+T, S·T, S+T+S·T, cat(S,T), and cat(S,T,S·T). Experiments on a pre-defined dataset showed that using spatial feature S or temporal feature T alone achieved detection accuracy of over 99%, confirming the effectiveness of each module in the detection system. When using the S+T fusion method, all metrics were superior to using S or T alone. However, when using the S·T fusion method, the evaluation results of S·T, S+T+S·T, and cat(S+T,S·T) strategies all decreased. This suggests that the S·T method disrupted the boundaries of spatiotemporal features, significantly negatively impacting detection. The cat(S,T) concatenation method showed the best test results. Therefore, when combining spatial and temporal features, the cat(S,T) concatenation method is preferred.
[0120] (3) MLP classification module:
[0121] In the spatiotemporal features that are fused Then, it is input into the multilayer perceptron and The classification module, composed of functions, is used to perform binary classification tasks. First, The first fully connected layer of the input MLP is given by the weight matrix of this layer. The bias vector is After activation function Processed output As shown in the following formula:
[0122]
[0123] Feature representation is obtained after multi-layer processing by MLP. Then input it. In binary classification tasks, the function... The function predicts that the encrypted traffic belongs to the first... The probability of the category is As shown in the following formula:
[0124]
[0125] in, The index value of the score for the i-th category. This is the normalized denominator.
[0126] Ultimately, based on Output probability to determine the category, if If the traffic is normal, the sample is classified as the first category (e.g., normal traffic type); otherwise, it is classified as the second category (e.g., attack traffic type). This is done by using spatiotemporal features to complete the binary classification task and determine the type of traffic data.
[0127] Example 2
[0128] This application embodiment can also provide an encrypted traffic type detection device. It should be noted that the encrypted traffic type detection device of this application embodiment can be used to execute the encrypted traffic type detection method provided in this application embodiment. The encrypted traffic type detection device provided in this application embodiment is described below.
[0129] According to an embodiment of this application, an apparatus for implementing the above-described encrypted traffic type detection method is also provided. Figure 6 This is a schematic diagram of an optional encrypted traffic type detection device according to an embodiment of this application, such as... Figure 6 As shown, the device includes: a preprocessing unit 601, used to preprocess the encrypted traffic file to obtain a target session, wherein the target session carries application layer data; a sequence determination unit 602, used to determine a target sequence based on the application layer data in the target session, wherein the target sequence includes T bytes, where T is a positive integer; a graph generation unit 603, used to generate a target grayscale image based on the target sequence, wherein each pixel in the target grayscale image represents one byte in the T bytes; a feature extraction unit 604, used to extract features from the target sequence to obtain the temporal features of the target session, and to extract features from the target grayscale image to obtain the spatial features of the target session; and a type detection unit 605, used to determine the traffic type of the encrypted traffic in the target session based on the temporal features and spatial features.
[0130] As described above, this device employs a spatiotemporal feature fusion detection method. Through a dual architecture of spatial feature extraction and temporal feature extraction of encrypted traffic, it achieves the purpose of classifying session traffic in encrypted traffic files. Specifically, this device first extracts the application layer data of the target session from the encrypted traffic file and generates a fixed-length byte sequence, which is then synchronously converted into a grayscale image representing the byte distribution characteristics. Subsequently, multi-scale spatial features are extracted from the grayscale image. At the same time, the byte sequence is embedded and self-attention mechanism is used to capture temporal features, thereby obtaining the global dependency relationship between any time steps in the byte sequence. Then, this device determines the traffic type of the encrypted traffic in the target session based on the temporal and spatial features.
[0131] As can be seen, through the above steps, this device achieves the capture of multi-dimensional traffic features in a traffic encryption environment, thereby overcoming the technical defects of traditional methods such as the lack of content features, insufficient single feature dimensions, and weak model generalization ability caused by traffic encryption. It achieves the technical effect of improving the accuracy and robustness of encrypted malicious traffic detection, and thus solves the technical problem of low accuracy in classifying encrypted traffic based on existing technologies.
[0132] Optionally, the preprocessing unit 601 includes: a segmentation subunit, used to segment the encrypted traffic file according to network sessions to obtain an initial session set, wherein the initial session set includes at least one initial session; and a filtering subunit, used to select the k-th initial session as the target session if the k-th initial session in the initial session set carries application layer data and the total length of the bytes corresponding to the carried application layer data is greater than a preset length threshold.
[0133] Optionally, the sequence determination unit 602 includes: a detection subunit, used to detect the number of original bytes included in the application layer data in the target session and obtain the original byte length; a padding subunit, used to pad the end of the application layer data with P zero bytes when the original byte length is less than T, and use all the original bytes and P zero bytes in the application layer data as the target sequence, where P is the difference between T and the original byte length; and a sequence determination subunit, used to use the first T original bytes in the application layer data as the target sequence when the original byte length is greater than or equal to T.
[0134] Optionally, the feature extraction unit 604 includes: a transformation subunit for performing vector transformation on T bytes in the target sequence to obtain an embedded vector sequence, wherein the embedded vector sequence includes T embedded vectors, each embedded vector having a dimension of d, where d is a positive integer; an encoding subunit for adding positional encoding to each embedded vector in the embedded vector sequence to obtain a target vector sequence, wherein the positional encoding is used to represent the positional information of the corresponding embedded vector; an extraction subunit for performing feature extraction on the target vector sequence through a multi-head attention module to obtain h sub-features, wherein h is a positive integer, the multi-head attention module includes h attention heads, and each sub-feature is a global dependency between target vectors extracted by an attention head; and a first processing subunit for performing residual connection and layer normalization processing on the h sub-features to obtain the temporal features of the target session.
[0135] Optionally, the feature extraction unit 604 further includes: a convolution subunit, used to perform convolution operations on the target grayscale image through Q convolution paths to obtain Q convolution features, where Q is a positive integer; a second processing subunit, used to perform channel weighting processing on each convolution feature through the convolution attention module corresponding to each convolution path to obtain Q channel weighted features; and a concatenation subunit, used to concatenate the Q channel weighted features to obtain the spatial features of the target session.
[0136] Optionally, the Q convolutional paths include a first convolutional path, a second convolutional path, a third convolutional path, and a fourth convolutional path. The convolutional sub-unit includes: a first convolutional module, used to perform a 1×1 convolution operation on the target grayscale image through the first convolutional path to obtain a first convolutional feature; a second convolutional module, used to perform a 1×1 convolution operation on the target grayscale image through the second convolutional path, followed by a 3×3 convolutional operation to obtain a second convolutional feature; a third convolutional module, used to perform a 1×1 convolution operation on the target grayscale image through the third convolutional path, followed by a 5×5 convolutional operation to obtain a third convolutional feature; a fourth convolutional module, used to perform a 3×3 convolution operation on the target grayscale image through the fourth convolutional path, followed by a 1×5 convolutional operation to obtain a fourth convolutional feature; and a feature determination module, used to use the first, second, third, and fourth convolutional features as the Q convolutional features.
[0137] Optionally, the type detection unit 605 includes: a feature fusion subunit for performing feature fusion on temporal features and spatial features to obtain the spatiotemporal features of the target session; and a type determination subunit for determining the traffic type of encrypted traffic in the target session based on the spatiotemporal features of the target session using a target model, wherein the target model includes a multilayer perceptron and a preset classification module.
[0138] It should be noted that units 601 to 605 correspond to steps S201 to S205 in the method embodiments. The instances and application scenarios implemented by the units and corresponding steps are the same, but are not limited to the content disclosed in the above embodiments. It should be noted that the modules or units may be hardware or software components stored in memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n). The modules may also be part of a device and run in the computer terminal 10 provided in the embodiments.
[0139] Example 3
[0140] Embodiments of this application can also provide an electronic device. Figure 7 This is a structural block diagram of an electronic device according to an embodiment of this application, such as... Figure 7 As shown, the electronic device includes: one or more ( Figure 7 (Only one is shown) processor 702, memory 704, memory controller, and peripheral interface, wherein the peripheral interface is connected to the radio frequency module, audio module and display.
[0141] The memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the methods and devices in the embodiments of this application. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby realizing the above-mentioned method for detecting the type of encrypted traffic.
[0142] The memory may include high-speed random access memory (RAM), and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, which can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks (LANs), mobile communication networks, and combinations thereof.
[0143] The processor can access information and applications stored in memory via a transmission device to perform the following steps: preprocessing the encrypted traffic file to obtain a target session, wherein the target session carries application layer data; determining a target sequence based on the application layer data in the target session, wherein the target sequence includes T bytes, where T is a positive integer; generating a target grayscale image based on the target sequence, wherein each pixel in the target grayscale image represents one byte out of the T bytes; extracting features from the target sequence to obtain the temporal features of the target session, and extracting features from the target grayscale image to obtain the spatial features of the target session; and determining the traffic type of the encrypted traffic in the target session based on the temporal and spatial features.
[0144] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: segment the encrypted traffic file according to network sessions to obtain an initial session set, wherein the initial session set includes at least one initial session; if the k-th initial session in the initial session set carries application layer data and the total length of the bytes corresponding to the carried application layer data is greater than a preset length threshold, the k-th initial session is taken as the target session.
[0145] The processor can invoke information and application programs stored in memory through the transmission device to perform the following steps: detect the number of raw bytes included in the application layer data in the target session to obtain the raw byte length; if the raw byte length is less than T, pad the end of the application layer data with P zero bytes, and take all the raw bytes and P zero bytes in the application layer data as the target sequence, where P is the difference between T and the raw byte length; if the raw byte length is greater than or equal to T, take the first T raw bytes in the application layer data as the target sequence.
[0146] The processor can access information and applications stored in memory via a transmission device to perform the following steps: Perform vector transformation on T bytes of the target sequence to obtain an embedded vector sequence, where the embedded vector sequence includes T embedded vectors, each with dimension d, where d is a positive integer; add positional encoding to each embedded vector in the embedded vector sequence to obtain a target vector sequence, where the positional encoding represents the positional information of the corresponding embedded vector; extract features from the target vector sequence using a multi-head attention module to obtain h sub-features, where h is a positive integer, the multi-head attention module includes h attention heads, and each sub-feature represents the global dependency between target vectors extracted by one attention head; perform residual connection and layer normalization on the h sub-features to obtain the temporal features of the target session.
[0147] The processor can access the information and application stored in the memory via the transmission device to perform the following steps: perform convolution operations on the target grayscale image through Q convolution paths to obtain Q convolution features, where Q is a positive integer; perform channel weighting on each convolution feature through the convolution attention module corresponding to each convolution path to obtain Q channel weighted features; and concatenate the Q channel weighted features to obtain the spatial features of the target session.
[0148] The processor can access information and applications stored in memory via a transmission device to execute the following steps: Q convolutional paths, including a first convolutional path, a second convolutional path, a third convolutional path, and a fourth convolutional path, are used. A 1×1 convolution operation is performed on the target grayscale image through the first convolutional path to obtain a first convolutional feature. A 1×1 convolution operation is then performed on the target grayscale image through the second convolutional path, followed by a 3×3 convolutional operation to obtain a second convolutional feature. A 1×1 convolution operation is then performed on the target grayscale image through the third convolutional path, followed by a 5×5 convolutional operation to obtain a third convolutional feature. A 3×3 convolution operation is then performed on the target grayscale image through the fourth convolutional path, followed by a 1×5 convolutional operation to obtain a fourth convolutional feature. The first, second, third, and fourth convolutional features are then used as the Q convolutional features.
[0149] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: perform feature fusion on temporal features and spatial features to obtain the spatiotemporal features of the target session; determine the traffic type of encrypted traffic in the target session based on the spatiotemporal features of the target session through the target model, wherein the target model includes a multilayer perceptron and a preset classification module.
[0150] This embodiment of the solution provides a method for detecting the type of encrypted traffic. As described above, this solution employs a spatiotemporal feature fusion detection approach. Through a dual architecture of spatial feature extraction and temporal feature extraction, it aims to classify session traffic within encrypted traffic files. Specifically, this solution first extracts the application layer data of the target session from the encrypted traffic file and generates a fixed-length byte sequence. This sequence is then synchronously converted into a grayscale image representing the byte distribution characteristics. Subsequently, multi-scale spatial features are extracted from the grayscale image. Simultaneously, embedding and self-attention mechanisms are used to calculate the temporal features of the byte sequence, thereby obtaining the global dependencies between any time steps in the byte sequence. Finally, this solution determines the traffic type of the encrypted traffic in the target session based on both temporal and spatial features.
[0151] As can be seen, this solution, through the above steps, achieves the capture of multi-dimensional traffic features in an encrypted traffic environment, thereby overcoming the technical defects of traditional methods such as missing content features, insufficient single feature dimensions, and weak model generalization ability caused by traffic encryption. It achieves the technical effect of improving the accuracy and robustness of encrypted malicious traffic detection, and thus solves the technical problem of low accuracy in classifying encrypted traffic based on existing technologies.
[0152] Those skilled in the art will understand that Figure 7 The structure shown is for illustrative purposes only. Electronic devices can also be smartphones, tablets, PDAs, mobile internet devices, PADs, and other terminal devices. Figure 7 This does not limit the structure of the aforementioned electronic device. For example, electronic devices may also include components that are more... Figure 7 The more or fewer components shown (such as network interfaces, display devices, etc.), or having the same Figure 7 The different configurations shown.
[0153] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0154] Example 4
[0155] Embodiments of this application may also provide a storage medium.
[0156] Optionally, in this embodiment of the application, the storage medium can be used to store the program code executed by the encrypted traffic type detection method provided in the above method embodiment.
[0157] Optionally, in this embodiment, the storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any mobile terminal in a group of mobile terminals.
[0158] This application also provides a computer program product, which, when executed on a data processing device, is suitable for performing steps of a method for detecting the type of encrypted traffic.
[0159] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0160] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0161] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0162] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0163] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0164] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0165] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A method for detecting the type of encrypted traffic, characterized in that, include: The encrypted traffic file is preprocessed to obtain the target session, wherein the target session carries application layer data; A target sequence is determined based on application layer data in the target session, wherein the target sequence comprises T bytes, where T is a positive integer; A target grayscale image is generated based on the target sequence, wherein each pixel in the target grayscale image represents one byte of the T bytes; Feature extraction is performed on the target sequence to obtain the temporal features of the target session, and feature extraction is performed on the target grayscale image to obtain the spatial features of the target session; The traffic type of encrypted traffic in the target session is determined based on the temporal and spatial characteristics.
2. The method for detecting the type of encrypted traffic according to claim 1, characterized in that, The encrypted traffic file is preprocessed to obtain the target session, including: The encrypted traffic file is segmented according to network sessions to obtain an initial session set, wherein the initial session set includes at least one initial session; If the kth initial session in the initial session set carries application layer data and the total length of the bytes corresponding to the application layer data carried is greater than a preset length threshold, then the kth initial session is taken as the target session.
3. The method for detecting the type of encrypted traffic according to claim 1, characterized in that, Determining the target sequence based on application layer data in the target session includes: The number of raw bytes included in the application layer data in the target session is detected to obtain the raw byte length; If the length of the original byte is less than T, P zero bytes are padded to the end of the application layer data, and all the original bytes and the P zero bytes in the application layer data are used as the target sequence, where P is the difference between T and the length of the original byte. If the length of the original bytes is greater than or equal to T, the first T original bytes in the application layer data are taken as the target sequence.
4. The method for detecting the type of encrypted traffic according to claim 1, characterized in that, Feature extraction is performed on the target sequence to obtain the temporal features of the target session, including: The T bytes in the target sequence are transformed into an embedded vector sequence, wherein the embedded vector sequence includes T embedded vectors, each embedded vector having a dimension of d, where d is a positive integer; Add a position code to each embedding vector in the embedding vector sequence to obtain a target vector sequence, wherein the position code is used to represent the position information of the corresponding embedding vector; The target vector sequence is feature extracted by a multi-head attention module to obtain h sub-features, where h is a positive integer. The multi-head attention module includes h attention heads, and each sub-feature is a global dependency between target vectors extracted by an attention head. The h sub-features are subjected to residual connection and layer normalization to obtain the temporal features of the target session.
5. The method for detecting the type of encrypted traffic according to claim 1, characterized in that, Feature extraction is performed on the target grayscale image to obtain the spatial features of the target session, including: The target grayscale image is convolved through Q convolutional paths to obtain Q convolutional features, where Q is a positive integer; Each convolutional feature is processed by channel weighting through the convolutional attention module corresponding to each convolutional path to obtain Q channel weighted features; The spatial features of the target session are obtained by concatenating the weighted features of the Q channels.
6. The method for detecting the type of encrypted traffic according to claim 5, characterized in that, The Q convolutional paths include a first convolutional path, a second convolutional path, a third convolutional path, and a fourth convolutional path. Convolutional operations are performed on the target grayscale image through these Q convolutional paths to obtain Q convolutional features, including: A 1×1 convolution operation is performed on the target grayscale image through the first convolution path to obtain the first convolution feature; The target grayscale image is subjected to a 1×1 convolution operation through the second convolution path, followed by a 3×3 convolution operation to obtain the second convolution feature. The target grayscale image is subjected to a 1×1 convolution operation through the third convolution path, followed by a 5×5 convolution operation to obtain the third convolution feature. The target grayscale image is subjected to a 3×3 convolution operation through the fourth convolution path, followed by a 1×5 convolution operation to obtain the fourth convolution feature. The first convolutional feature, the second convolutional feature, the third convolutional feature, and the fourth convolutional feature are taken as the Q convolutional features.
7. The method for detecting the type of encrypted traffic according to claim 1, characterized in that, Determining the traffic type of encrypted traffic in the target session based on the temporal and spatial characteristics includes: The temporal features and spatial features are fused to obtain the spatiotemporal features of the target session; The target model determines the traffic type of encrypted traffic in the target session based on the spatiotemporal characteristics of the target session, wherein the target model includes a multilayer perceptron and a preset classification module.
8. A device for detecting the type of encrypted traffic, characterized in that, include: A preprocessing unit is used to preprocess the encrypted traffic file to obtain a target session, wherein the target session carries application layer data; A sequence determination unit is used to determine a target sequence based on application layer data in the target session, wherein the target sequence includes T bytes, where T is a positive integer; The image generation unit is used to generate a target grayscale image based on the target sequence, wherein each pixel in the target grayscale image represents one byte of the T bytes; The feature extraction unit is used to extract features from the target sequence to obtain the temporal features of the target session, and to extract features from the target grayscale image to obtain the spatial features of the target session; A type detection unit is used to determine the traffic type of encrypted traffic in the target session based on the temporal and spatial characteristics.
9. A computer program product, characterized in that, The computer program product includes a computer program, wherein, when the computer program is executed, it controls the computer program product to perform the encrypted traffic type detection method according to any one of claims 1 to 7.
10. An electronic device, characterized in that, It includes one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the encrypted traffic type detection method according to any one of claims 1 to 7.
