Vehicle-mounted can bus intrusion detection system and method based on contrast self-supervised learning
By comparing self-supervised learning and multi-task joint training methods, the improved Transformer autoencoder achieves lightweighting and cross-vehicle adaptability of the vehicle CAN bus intrusion detection system, solving the problems of high model complexity, low computational efficiency and weak cross-vehicle generalization ability in the existing technology, and realizing efficient and accurate multi-type attack identification.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WUXI UNIV
- Filing Date
- 2025-12-24
- Publication Date
- 2026-04-10
AI Technical Summary
Existing in-vehicle CAN bus intrusion detection methods have shortcomings in terms of data dependence, model efficiency, functional completeness, and generalization adaptability, making it difficult to achieve real-time deployment and accurate identification of multiple types of attacks on resource-constrained in-vehicle terminals.
An in-vehicle CAN bus intrusion detection system based on contrastive self-supervised learning is adopted. Through a multi-task joint training method, combined with an improved Transformer autoencoder, and utilizing unsupervised reconstruction, supervised classification, and self-supervised contrastive learning tasks, a lightweight model can be trained and adapted to different vehicle models.
It improves data utilization efficiency, reduces reliance on expensive label data, can accurately identify multiple types of attacks, and achieves efficient and lightweight intrusion detection, making it suitable for resource-constrained in-vehicle environments.
Smart Images

Figure CN121388896B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of information processing, and particularly relates to a vehicle-mounted CAN bus intrusion detection system and method based on contrast self-supervised learning. BACKGROUND
[0002] With the rapid development of intelligent connected vehicles (ICV), the complexity and openness of in-vehicle networks (IVN) are increasing, which makes them gradually become the main target of network attacks. At present, as the de facto standard for communication between electronic control units (ECU) in vehicles, the controller area network (CAN) is widely used due to its efficiency and low cost advantages. However, the CAN bus protocol lacks necessary security mechanisms at the beginning of its design, its communication content is broadcast in plaintext, and it lacks authentication and encryption functions, which makes attackers can inject malicious messages through various ways (such as OBD-II port or wireless interface), implement denial of service (DoS), spoofing or fuzzy attacks, and pose a serious threat to driving safety.
[0003] To cope with the security threats faced by CAN networks, intrusion detection systems (IDS) have become a key technical means to ensure the security of vehicle-mounted communication. Compared with traditional IDS based on rules or feature matching, deep learning (DL) based methods have become the mainstream direction of current research due to their powerful ability to automatically learn complex attack patterns from massive data. These methods analyze the sequence, content or frequency characteristics of CAN messages, aiming to build models that can identify malicious behavior in real time, providing more intelligent and dynamic protection for vehicle network security.
[0004] However, existing intrusion detection techniques still face multiple challenges in practical applications. First, most high-performance models rely heavily on large-scale labeled data, but in the real world, attack events are rare, and manual labeling is costly and time-consuming. Second, many advanced models have a contradiction between model complexity and real-time requirements in the vehicle environment, and their large parameter quantity and computational complexity are difficult to deploy in real time on resource-constrained vehicle terminals. Third, existing research lacks accurate identification ability for multi-class attacks, usually only performing binary classification of "normal" and "abnormal", and cannot provide specific attack type information for subsequent defense. Finally, existing models generally lack cross-vehicle generalization ability, as the communication protocols of different vehicles differ, a model trained for one vehicle cannot be directly applied to another vehicle, and an effective transfer learning mechanism is urgently needed.
[0005] Kabilan N. et al. proposed an unsupervised in-vehicle network intrusion detection system based on autoencoder and fuzzy C-means clustering (FCM) (Kabilan, N., Vinayakumar Ravi, and V. Sowmya. "Unsupervised intrusion detection system for in-vehicle communication networks." Journal of Safety Science and Resilience 5.2 (2024): 119-129.). This method first uses an autoencoder to extract features and reduce noise from CAN message data, then classifies the extracted features using the FCM clustering algorithm, aiming to identify intrusion behavior without relying on any attack labels. However, the method explicitly states in its conclusion that while the model can detect attacks, it cannot distinguish specific attack types, and can only perform binary classification of "normal" and "abnormal", lacking multi-class attack identification ability.
[0006] Alqahtani H. et al. proposed a hybrid deep learning intrusion detection system named HDL-IDS (Alqahtani, Hamed, and Gulshan Kumar. "Deep learning-based intrusion detection system for in-vehicle networks with knowledge graph and statistical methods." International Journal of Machine Learning and Cybernetics 16.5 (2025): 3539-3555.). This system integrates knowledge graph, statistical methods, convolutional neural network (CNN) and long short-term memory network (LSTM) to capture the semantic, spatial and temporal features of CAN data to improve detection accuracy. Although this method shows potential in improving detection accuracy, its model architecture integrates multiple heterogeneous technologies, resulting in large computational overhead and parameter quantity. At the same time, as a supervised learning model, its limitations and future work are explicitly pointed out, and further exploration of transfer learning technology is needed to deal with unknown attacks, indicating that there is room for improvement in its cross-model generalization ability.
[0007] In summary, the existing technology has deficiencies in data dependence, model efficiency, functional completeness and generalization adaptability when dealing with CAN bus intrusion detection. Therefore, there is an urgent need for a vehicle CAN bus intrusion detection method that is efficient in data, lightweight in model, can accurately identify multiple types of attacks and has good generalization adaptability, to ensure high detection accuracy while meeting the strict requirements of real-time response, low computational overhead and fast cross-platform deployment in vehicle environment. SUMMARY
[0008] In view of the problems in the prior art, the present application provides a vehicle CAN bus intrusion detection system and method based on contrastive self-supervised learning, which at least partially solves the problems of low efficiency and inaccurate recognition in the prior art.
[0009] In a first aspect, the present disclosure provides a vehicle CAN bus intrusion detection system based on contrastive self-supervised learning, comprising:
[0010] A data preprocessing module is configured to receive CAN bus data stream in real time, extract features from each CAN message in the CAN bus data stream to generate a multi-dimensional feature vector, and stack the feature vectors of the continuous W messages to construct a two-dimensional time series sample using a sliding window method.
[0011] An intrusion detection model is configured to perform inference on the two-dimensional time series sample and output a classification label; the intrusion detection model is trained by a multi-task joint training method, and the training method fuses an unsupervised reconstruction task, a supervised classification task and a self-supervised contrast learning task;
[0012] A decision module is configured to determine whether a CAN bus intrusion behavior exists according to the classification label output by the intrusion detection model.
[0013] Optionally, the intrusion detection model comprises:
[0014] An encoder, a decoder and a projection head;
[0015] The encoder is configured to compress the input time series sample into continuous latent variables and category latent variables;
[0016] The decoder is configured to reconstruct the original input based on the continuous latent variables and the category latent variables;
[0017] The projection head is connected to the output of the encoder and is configured to map the reconstructed features to a metric space of the self-supervised contrast learning.
[0018] Optionally, the encoder comprises:
[0019] An initial linear projection layer is configured to map the feature dimension of the input time series sample to the working dimension of the intrusion detection model;
[0020] A positional encoding layer is configured to add time sequence information to the sequence;
[0021] A receptive field attention convolution module is configured to extract local time sequence features;
[0022] A plurality of Transformer layers adopting a cross-layer parameter sharing mechanism;
[0023] A contrast normalization layer is configured to optimize the final feature representation processed by the Transformer layer;
[0024] A mean pooling layer and at least two linear layers are configured to generate continuous latent variables and category latent variables, respectively.
[0025] Optionally, the decoder comprises an initial linear projection layer, a Transformer decoding network, a positional encoding layer and a final linear projection layer;
[0026] The initial linear projection layer is configured to map the spliced vector of the continuous latent variables and the category latent variables into a sequence form;
[0027] The Transformer decoding network comprises a plurality of Transformer layers with independent and non-shared parameters.
[0028] a final linear projection layer for mapping the processed sequence back to the original feature dimension to generate a reconstructed sample.
[0029] Optionally, the data preprocessing module comprises:
[0030] acquiring a CAN bus data stream;
[0031] performing data cleaning and format conversion on the CAN bus data stream to form a multi-dimensional numerical vector;
[0032] extracting multi-modal features from each CAN message in the cleaned and format-converted CAN bus data stream to obtain a feature vector;
[0033] stacking the feature vectors of the continuous W messages using a sliding window method to construct a two-dimensional time series sample, wherein the label of the sample is determined according to whether at least one attack message is contained in the window;
[0034] dividing all the constructed two-dimensional time series samples into a training set, a validation set, and a test set, and then dividing the training set into an unlabeled training set and a labeled training set for multi-task joint training.
[0035] Optionally, the multi-modal feature extraction from each CAN message in the cleaned and format-converted CAN bus data stream comprises:
[0036] calculating the time interval between the current message and the previous message, concatenating a binary vector, a time interval, and a multi-dimensional numerical vector into a multi-dimensional feature vector of a single message, wherein the binary vector is converted according to the CAN ID.
[0037] Optionally, the multi-task joint training method comprises:
[0038] an unsupervised reconstruction task: inputting unlabeled data into an encoder to generate a latent variable, and then reconstructing the original input based on the latent variable by a decoder, and optimizing the encoder and the decoder by minimizing the mean square error loss between the reconstructed input and the original input;
[0039] a supervised classification task: inputting labeled data into the encoder to obtain a classification prediction result, and optimizing the encoder by minimizing the cross-entropy loss between the prediction result and the true label;
[0040] Self-supervised contrastive learning task: the input data is augmented to generate different view samples, the augmented samples are input into the encoder to extract the pooled feature representation, and then the feature representation is mapped to the metric space by the projection head, and the parameters of the encoder and the projection head are optimized by minimizing the hybrid loss function combining the unsupervised contrastive loss and the supervised contrastive loss, so as to pull the representations of semantically similar samples and push the representations of dissimilar samples in the feature space.
[0041] Optionally, the system also supports a transfer learning application, and the transfer learning application includes:
[0042] Pre-training the intrusion detection model on a source vehicle model dataset to obtain a pre-trained model;
[0043] Migrating the encoder weights of the pre-trained model to a target vehicle model;
[0044] Completing model adaptation through a two-stage process of training only the classification head by freezing the encoder parameters and then performing overall fine-tuning by unfreezing the encoder parameters on a target vehicle model dataset.
[0045] In a second aspect, the embodiments of the present disclosure also provide a vehicle-mounted CAN bus intrusion detection method based on contrastive self-supervised learning, which applies the system of the first aspect, and has the characteristics that it includes:
[0046] Receiving CAN bus data streams in real time, and extracting features from each CAN message to generate a multi-dimensional feature vector;
[0047] Stacking the multi-dimensional feature vectors of the continuous W messages to construct two-dimensional time series samples using a sliding window method;
[0048] Inputting the two-dimensional time series samples into the trained intrusion detection model to perform inference classification and output a classification label;
[0049] According to the classification label, it is determined whether there is a CAN bus intrusion behavior.
[0050] In a third aspect, the embodiments of the present disclosure also provide an electronic device, which includes:
[0051] At least one processor; and
[0052] A memory in communication connection with the at least one processor; wherein
[0053] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the vehicle-mounted CAN bus intrusion detection method based on contrastive self-supervised learning of the second aspect.
[0054] The application provides a vehicle CAN bus intrusion detection system and method based on contrast self-supervised learning, wherein the vehicle CAN bus intrusion detection system based on contrast self-supervised learning greatly improves data utilization efficiency and reduces dependence on expensive label data by adopting a multi-task joint training method. The multi-task joint training method enables the model to accurately distinguish normal traffic and various types of attacks, thereby achieving the purposes of high efficiency, model lightweight, and accurate identification of multiple types of attacks. BRIEF DESCRIPTION OF DRAWINGS
[0055] The above and other objects, features and advantages of the present disclosure will become more apparent from the following detailed description when taken in conjunction with the accompanying drawings in which like reference characters refer to like parts throughout the figures, in which exemplary embodiments of the present disclosure are shown.
[0056] Figure 1 A flowchart of a vehicle CAN bus intrusion detection method based on contrast self-supervised learning provided by an embodiment of the present disclosure;
[0057] Figure 2 A principle block diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0058] The embodiments of the present disclosure will be described in detail below with reference to the drawings.
[0059] It should be apparent that the following describes the embodiments of the present disclosure through specific concrete examples, and those skilled in the art can easily understand other advantages and effects of the present disclosure from the disclosure. Obviously, the described embodiments are only some of the embodiments of the present disclosure, not all. The present disclosure can also be implemented or applied by other different specific embodiments, and the details in the specification can be modified or changed based on different views and applications without departing from the spirit of the present disclosure. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present disclosure.
[0060] It is to be appreciated that various aspects of the embodiments described below are presented in terms of sequences of actions or process steps. It is to be appreciated that the aspects described herein can be implemented in any number of ways, and that the embodiments described below are simpy one way in which the aspects can be implemented. Additionally, the various aspects described below can be implemented alone or in combination with one another.
[0061] It is also to be understood that the present disclosure will be described in terms of exemplary embodiments only, and should not be construed to be limited to those embodiments. Rather, the present disclosure describes objects, advantages, and techniques that can be employed in accordance with the embodiments of the present disclosure.
[0062] Furthermore, in the following description, numerous specific details are set forth in order to provide a thorough understanding of the examples. However, it will be apparent to one skilled in the art that the aspects described herein can be practiced without these specific details.
[0063] The present application aims to overcome the shortcomings of existing vehicle CAN bus intrusion detection methods in terms of high model complexity, low computational efficiency, heavy dependence on large-scale labeled data, and weak cross-model generalization ability. In the prior art, detection methods rely on complex deep network structures, which have huge parameter quantity and computational complexity, making it difficult to deploy in real time on resource-constrained vehicle terminals, and it is difficult to balance feature expression ability and the demand for lightweight and real-time of vehicle equipment. At the same time, the dependence on artificial labeling leads to high cost, and most existing models lack accurate recognition ability for multi-class attacks and cross-model generalization ability, affecting the overall detection robustness.
[0064] Embodiment one:
[0065] The embodiment discloses a vehicle CAN bus intrusion detection system based on contrastive self-supervised learning, and an intrusion detection model of the intrusion detection system is obtained based on an improved Transformer autoencoder model training,
[0066] The intrusion detection model includes an encoder, a decoder, and a projection head, and the core is built by a Transformer layer;
[0067] The encoder is used to compress the input time sequence sample into continuous latent variable Z and category latent variable The architecture is mixed enhanced before and after the core Transformer layers: the front-end integrates a Receptive Field Attention Convolution (RFAConv) module before the multi-head attention mechanism to capture local temporal patterns, the back-end appends a ContraNorm layer after all the Transformer layers to optimize the feature representation space, and the multiple Transformer layers inside the encoder share parameters across layers to achieve lightweight;
[0068] The decoder is used to reconstruct the original input from the latent variables, and its structure is based on the continuous latent variable Z and the category latent variable generated by the encoder to perform input reconstruction without the Cross-Attention mechanism in the standard Transformer decoder;
[0069] The encoder internally contains a classifier connected to the output of the encoder feature processing to generate the category latent variable and output the probability distribution of the attack type;
[0070] The projection head is also connected to the output of the encoder to map the features to a metric space dedicated to self-supervised contrastive learning.
[0071] The encoder includes: an initial linear projection layer for mapping the feature dimension of the input time series sample to the model working dimension; a position encoding layer for adding temporal information to the sequence; a Receptive Field Attention Convolution (RFAConv) module containing a backbone convolution branch and a receptive field attention branch for extracting local temporal features before the Transformer layer processing; multiple Transformer core layers realized by a cross-layer parameter sharing mechanism, where each layer contains a multi-head self-attention module and a feedforward network; a ContraNorm layer containing group normalization or layer normalization and L2 norm regularization steps to optimize the final feature representation after the Transformer layer processing; and a mean pooling layer followed by two independent linear layers for generating the continuous latent variable Z and the category latent variable , where the linear layer for generating the category latent variable also serves as an internal self-classifier;
[0072] The decoder includes: an initial linear projection layer for mapping the concatenated vector of the continuous latent variable Z and the category latent variable to a sequence form; a position encoding layer; multiple Transformer decoding networks composed of independent, non-shared parameter Transformer core layers; and a final linear projection layer for mapping the processed sequence back to the original feature dimension to generate the reconstructed sample;
[0073] The self-supervised contrastive learning task is implemented by a projection head connected to the output of the encoder pooling layer, which is composed of a multi-layer perceptron network.
[0074] The steps of the improved Transformer autoencoder intrusion detection model training include:
[0075] S1, obtain source vehicle model and target vehicle model data sets, clean and format convert the data sets, after feature extraction of each CAN message and construction of a two-dimensional time series sample by sliding window method, then divide the sample set into unlabeled training set, labeled training set and validation set;
[0076] S2, input the labeled and unlabeled training data divided in S1 into the model for pre-training, the pre-training adopts a multi-task joint training method, which combines unsupervised reconstruction, supervised classification and self-supervised contrastive learning tasks in a unified training process, and determines the optimal pre-training model on the source data set by evaluating the model performance through the validation set; and further through the fine-tuning step, the encoder weight of the optimal pre-training model is applied to the target vehicle data set to complete the application of the model on the new vehicle model;
[0077] S3, infer and verify the final model obtained after pre-training or fine-tuning in S2, and evaluate the recognition accuracy, detection delay and parameter size of the model on the test set.
[0078] Step S1 includes:
[0079] S11, obtain the public Car-Hacking and Survival data sets;
[0080] S12, clean and format convert the data sets, the cleaning includes filling in the missing data fields in the message, and the format conversion specifically includes: converting the CAN ID hexadecimal field into a binary vector, and converting each byte of the Payload data field into a numerical value and then normalizing to form a multi-dimensional numerical vector;
[0081] S13, perform multi-modal feature extraction on each CAN message after cleaning and conversion, which includes calculating the time interval Δt between the current message and the previous message, and concatenating the binary vector, time interval and normalized multi-dimensional numerical vector into a single feature vector;
[0082] S14, stack the feature vectors of the continuous W messages by sliding window method to construct a two-dimensional time series sample with shape (W, F), wherein the label of the sample is determined according to whether at least one attack message is contained in the window;
[0083] S15, all the two-dimensional time sequence samples constructed in step S14 are first divided into a training set, a validation set and a test set, and then the training set is further divided into an unlabeled training set and a labeled training set for subsequent multi-task joint training.
[0084] Step S2 comprises:
[0085] S21, input the source data set samples divided in S1 into the model for pre-training, the pre-training adopts a multi-task joint training method, which performs the following tasks in parallel in a unified training process: an unsupervised reconstruction task optimized by using unlabeled data and a mean square error loss; a supervised classification task optimized by using labeled data and a cross-entropy loss; and a self-supervised contrast learning task optimized by using all training data, through data augmentation and a contrast loss function;
[0086] S22, after the end of each round of pre-training, the performance indicators of the current model are evaluated using the validation set, and the optimal pre-training model weight is saved according to the performance indicators;
[0087] S23, based on the encoder of the optimal pre-training model saved in S22, the model application is completed on the target vehicle data set through a fine-tuning step, which includes: first performing frozen training, that is, fixing the parameters of the pre-training encoder and only training the new classification head; then performing overall fine-tuning, that is, unfreezing the parameters of the pre-training encoder and training the entire model using a smaller learning rate.
[0088] Step S21 comprises:
[0089] The source data set samples divided in S1 are input into the model for pre-training, and the pre-training adopts a multi-task joint training method, which performs the following tasks in parallel in a unified training process:
[0090] An unsupervised reconstruction task, which includes inputting unlabeled data into an encoder to generate latent variables, and then reconstructing the original input based on the latent variables by a decoder, and optimizing the encoder and the decoder by minimizing the mean square error loss (LMSE) between the reconstructed input and the original input, and the loss function is expressed as:
[0091] ,
[0092] Wherein, is the i-th original input sample, N is the batch size, E represents the encoder, and D represents the decoder;
[0093] A supervised classification task, which includes inputting labeled data into the encoder to obtain original classification logits, and optimizing the encoder by minimizing the cross-entropy loss (LCE) between the classification logits and the true labels, the loss function for a single sample (X, y) is expressed as:
[0094] ,
[0095] where, is the C-dimensional classification score vector output by the encoder, is the score corresponding to the true class y, and C is the total number of classes;
[0096] A self-supervised contrastive learning task, which includes first performing data augmentation on the input data to generate different view samples, the data augmentation includes time segment shuffling or ID field permutation, then inputting the augmented samples into the encoder to extract the pooled feature representation, then mapping the feature representation to a metric space by a projection head, and optimizing the parameters of the encoder and the projection head by minimizing a hybrid loss function combining the unsupervised contrastive loss and the supervised contrastive loss to pull the representations of semantically similar samples closer together and push the representations of dissimilar samples further apart in the feature space. The loss function is expressed as:
[0097] ,
[0098] ,
[0099] where, and are the feature representations of two augmented views of the same original sample after passing through the encoder and the projection head, is the feature representation of other samples in the batch, is a temperature hyperparameter, is the index of all samples in the batch, is the set of all other samples in the batch that belong to the same class as sample i, .
[0100] Embodiment II:
[0101] The embodiment provides a vehicle-mounted CAN bus intrusion detection method based on contrastive self-supervised learning, which comprises the following steps:
[0102] Step 1: Real-time reception of CAN bus data stream and extraction of message field information;
[0103] Step 2: Sample construction is performed on the received CAN data. First, feature extraction is performed on each CAN message to generate a multi-dimensional feature vector. Then, the multi-dimensional feature vectors of W consecutive messages are stacked using the sliding window method to construct a two-dimensional time series sample.
[0104] Step 3: The converted two-dimensional time series sample is input into the CAN bus intrusion detection system based on contrastive self-supervised learning.
[0105] Step 4: The trained model is used to infer and classify the real-time received CAN traffic data, and the corresponding classification label is output.
[0106] Step 5: Based on the classification label result, it is judged whether there is a CAN bus intrusion behavior.
[0107] Specifically, the vehicle-mounted CAN bus intrusion detection method based on the mixed attention Transformer network directly processes the CAN message time sequence to realize end-to-end detection of the CAN bus traffic. The method improves the lightweight and feature modeling capability based on the Transformer architecture: by introducing the RFAConv module to capture local timing patterns, and combining the cross-layer parameter sharing Transformer structure to reduce the model parameter quantity and computational complexity; at the same time, the ContraNorm regularization layer is embedded at the end of the encoder to improve the feature separation ability of the model for different attack categories. At the same time, the semi-supervised multi-task joint training method and efficient transfer learning mechanism are combined to train and optimize the model, guide the model to improve the recognition accuracy of various attack samples under extremely low label data, and solve the problem of model difficult to deploy across vehicle types. The experimental results show that the present application realizes extremely high detection accuracy and extremely low inference time under multiple CAN attack types, has good lightweight deployment performance, and is suitable for resource-constrained vehicle-mounted control unit actual scenes.
[0108] Figure 1 is the overall framework diagram of the method of the present embodiment, which shows the complete process from data processing (including feature extraction and construction of time series samples) to model training (including hybrid training framework and transfer learning) and inference prediction.
[0109] As shown in 1, in the present embodiment, the SSC-HIDS model, i.e. the intrusion detection model, the specific steps of training the SSC-HIDS (Self-Supervised Contrastive Hybrid IDS) model are as follows:
[0110] Step 1: Obtain the source vehicle model and target vehicle model dataset, clean and format the dataset, and after extracting features from each CAN message and constructing a two-dimensional time series sample using the sliding window method, then divide the sample set into unlabeled training set, labeled training set, validation set and test set;
[0111] Step 1.1: Obtain Car-Hacking dataset and Survival dataset, both of which are collected by the HCRL laboratory of a university in Korea through real vehicles. Among them, the Car-Hacking dataset is collected through the CAN bus interface of the Hyundai Sonata vehicle in the actual running environment, covering normal communication traffic and multiple attack scenarios (DoS, Fuzzy, Gear deception, speed deception) CAN message data; The Survival dataset contains CAN message data collected from multiple different vehicle models such as Kia Soul and Chevrolet Spark, covering normal traffic and multiple attack scenarios (such as Flooding, Fuzzy, Malfunction).
[0112] Step 1.2: Data cleaning and format conversion of the dataset, cleaning includes filling in missing data fields in the message, format conversion specifically includes: converting the CAN ID hexadecimal field into a binary vector, and converting each byte of the Payload data field into a numerical value and then normalizing it to form a multi-dimensional numerical vector;
[0113] First, extract the key fields from each CAN message as data features, including CAN identifier (CAN_ID), timestamp (Timestamp) and data field (Data[0], Data[1], Data[2], Data[3], Data[4], Data[5], Data[6], Data[7]), and add field names as column identifiers to the extracted data for these fields. In the field extraction process, if it is detected that there is a field missing in the CAN message (such as CAN_ID field less than four bits or DATA field length less than 8 bytes), a preset filling strategy is used to fill it. Specifically, if the CAN_ID field is insufficient, it is filled with "0000" to ensure its length is 4 bits; for the DATA field, use "00" to fill the missing bytes until the length is 8 bytes.
[0114] The extracted CAN ID and DATA fields need to be uniformly formatted: the original hexadecimal representation of the CAN ID field is converted into a 29-bit binary vector; and the 8 bytes of the DATA field are converted from hexadecimal to integer values in the range of 0 to 255, and then further normalized to floating-point values in the [0, 1] interval. A label field (Label) is added to each CAN message sample to identify its category.
[0115] Step 1.3: Multi-modal feature extraction is performed on each CAN message after cleaning and conversion, including calculating the time interval At between the current message and the previous message, and concatenating the binary vector, time interval, and normalized multi-dimensional numerical vector into a single feature vector.
[0116] Multi-modal feature fusion and concatenation are performed on each CAN message after cleaning and conversion. This step aims to integrate different types of information (such as identifiers, time dynamics, and data content) extracted from a single message into a unified numerical representation for subsequent time series modeling. Specifically, the CAN ID binary vector obtained in step 1.2 , the calculated time interval , and the normalized Payload numerical vector are horizontally concatenated in a predetermined order. This concatenation operation forms a single, higher-dimensional comprehensive feature vector :
[0117] ,
[0118] This vector is the final numerical feature representation of a single CAN message after preprocessing, which encapsulates the identity, content, and timing information of the message at a specific time point, and will be used as a basic unit to construct the time series sample sequence in the subsequent steps.
[0119] Step 1.4: Using the sliding window method, stack the feature vectors of W consecutive messages to construct a two-dimensional time series sample with shape (W, F), where the label of the sample is determined according to whether at least one attack message is contained in the window.
[0120] Sliding window method is used to construct time series samples. This step aims to serialize the static feature vectors of single messages to capture the time dependence of CAN traffic. Specifically, a fixed window size W and a sliding step S are set. From the sequence of feature vectors processed in step 1.3, the feature vectors of W consecutive messages are stacked in turn. Each time W F-dimensional feature vectors are formed, where F is The W x F matrix is a time sequence sample, representing the CAN bus traffic segment in a specific time window. Subsequently, the window slides S message positions along the time sequence, and the above stacking process is repeated to generate the next time sequence sample. If S < W, there is an overlap between the generated windows; if S = W, there is no overlap between the generated windows. Each generated W x F time sequence sample is assigned a single label. The determination of the label is based on checking whether there is at least one message with the original label "attack" in the W original CAN messages that constitute the sample. If there is at least one attack message, the time sequence sample is marked as "attack" as a whole; otherwise, it is marked as "normal". Through this sliding window processing, the original one-dimensional CAN message feature sequence is converted into a series of two-dimensional time sequence samples with fixed time length W and feature dimension F, and is assigned a corresponding classification label, making it ready for subsequent input into a sequence-based model for training and detection.
[0121] Step 1.5: All two-dimensional time sequence samples constructed in step 1.4 are first divided into training set, validation set and test set, and then the training set is further divided into unlabeled training set and labeled training set for subsequent multi-task joint training.
[0122] The data set division is performed on all two-dimensional time sequence samples constructed in step 1.4. First, all samples are divided into training set, validation set and test set according to the ratio of 70%:15%:15%. Then, in order to adapt to the subsequent multi-task joint training framework, the training set is further divided into unlabeled training set for unsupervised reconstruction task and self-supervised contrast learning task, and labeled training set for supervised classification task according to the set labeled data ratio (e.g. 1% to 5%).
[0123] Step 2: The divided labeled and unlabeled training data are input into the model for pre-training. The pre-training adopts a multi-task joint training method, which integrates unsupervised reconstruction, supervised classification and self-supervised contrast learning tasks in a unified training process, and determines the optimal pre-training model on the source data set by evaluating the model performance on the validation set. Further, through the fine-tuning step, the encoder weights of the optimal pre-training model are applied to the target vehicle data set to complete the application of the model on the new vehicle. To avoid overfitting, the training hyperparameter settings are shown in Table 1:
[0124] Table 1, training hyperparameter settings
[0125]
[0126] Step 2.1: The divided training data set in step 1.5, including the unlabeled training set and the labeled training set, is input into the model for multi-task joint training. This method performs and optimizes the following three tasks in parallel in a unified training process:
[0127] Unsupervised reconstruction task: Using unlabeled training data, the model's autoencoder part, including the encoder and decoder, is trained to learn the effective low-dimensional representation and reconstruction ability of the data by optimizing the mean square error (MSE) loss function.
[0128] Supervised classification task: Using labeled training data, the model's encoder and classifier part are trained to have the ability to distinguish different attack types by optimizing the cross-entropy (Cross-Entropy) loss function.
[0129] Self-supervised contrastive learning task: Using all training data including unlabeled and labeled, first generate positive sample pairs through data augmentation strategies, including random masking one time step, adding Gaussian noise, time segment shuffling, and ID field replacement, then train the model's encoder and projection head to learn more robust feature representations that are invariant to augmentation operations by optimizing the contrastive loss function composed of the sum of InfoNCE loss and SupCon loss.
[0130] Step 2.2: At the end of each round of multi-task joint training, the performance of the current model is evaluated using the validation set divided in step 1.5. The evaluation uses accuracy (Accuracy), precision (Precision), recall (Recall), and F1 score (F1-Score) as indicators to measure the comprehensive performance of the model in multiple dimensions, ensuring that the trained model maintains stable and reliable recognition ability under different data conditions. According to the key performance indicators (such as F1 score), compare the current round model with the saved optimal model, if the current performance is better, save the current model weight as the new optimal model weight. The calculation methods of accuracy, precision, recall, and F1 score are as follows:
[0131] ,
[0132] ,
[0133] ,
[0134] ,
[0135] Where TP is the correct identification of attacks, TN is the correct identification of normal, FP is the misjudgment of normal as attack, and FN is the misjudgment of attack as normal.
[0136] Step 2.3: Based on the encoder of the saved best pre-trained model in Step 2.2, the model application is completed by fine-tuning on the target vehicle dataset (Spark or Soul vehicle dataset in Survival dataset). The fine-tuning step adopts a two-stage strategy:
[0137] The first stage is frozen training. In this stage, all parameter layers of the loaded pre-trained encoder are set to non-trainable state (frozen), and only the newly initialized classification head layer is trained. Using the training samples in the target vehicle dataset and the set frozen training learning rate, the weight parameters of the classification head layer are updated by the backpropagation algorithm. The goal of this stage is to quickly train a classifier suitable for the target dataset, which is built on the fixed features extracted by the source model.
[0138] The second stage is encoder fine-tuning. After completing the frozen training, all parameter layers of the pre-trained encoder are set to trainable state (unfrozen). Using a usually smaller, set fine-tuning learning rate, the entire model (including the unfrozen encoder and the classification head trained in the previous stage) is trained end-to-end. This stage allows the features extracted by the encoder to be slightly adjusted according to the characteristics of the target vehicle data to further improve the performance of the model on this specific task.
[0139] After each round of training in the frozen training and encoder fine-tuning, the model performance is evaluated using the corresponding validation set of the target vehicle dataset, and the model weight with the best performance (such as F1 score) is saved according to the evaluation results. Finally, the model weight optimized for the target vehicle is obtained.
[0140] Step 3: Inference verification and performance evaluation of the best model obtained after pre-training or fine-tuning in Step 2. This step uses the test set divided in Step 1.5, which the model has never touched in the training and validation stages, to objectively evaluate the final generalization ability, efficiency and complexity of the model.
[0141] In the experimental setup, for the Car-Hacking dataset, considering its large data size and in order to simulate the actual scenario of data scarcity, only a certain proportion of the total amount of processed training data is used for training in the semi-supervised learning experiment. For the Survival dataset, given its inherently relatively small sample size, all available training samples after division of the dataset are used for model fine-tuning and evaluation in the transfer learning experiment.
[0142] To verify the effectiveness of the method of the present application in the scenario of label data scarcity, a series of semi-supervised learning experiments were conducted on the Car-Hacking dataset. In the experiment, the total amount of training set was fixed, only the proportion of labeled data in it was changed, ranging from 1% to 5%, and the performance of the model was evaluated on an independent test set. The results are shown in Table 2:
[0143] Table 2, Semi-supervised learning performance on Car-hacking dataset
[0144]
[0145] As can be seen from Table 2, the performance of the model steadily improves with the increase of the proportion of labeled data. It is worth noting that in the extreme case where the proportion of labeled data is only 1%, the F1 score of the model has reached a high level of 0.9810. This fully proves the effectiveness of the multi-task joint training framework adopted by the present application, especially the unsupervised reconstruction task and the self-supervised contrastive learning task can fully utilize the massive unlabeled data to learn high-quality feature representations. When the proportion of labeled data reaches 5%, the model reaches 1.0000 in all four key indicators, showing its strong learning ability and high data utilization efficiency.
[0146] To further verify the performance advantage of the model (SSC-HIDS) of the present application, it was compared with a variety of existing vehicle network intrusion detection methods, and the results are shown in Table 3. The comparison covers models of different learning paradigms and label data dependence, including semi-supervised models CAAE and VARL-IDS, fully supervised model ECF-IDS, and purely unsupervised model XIPHOS.
[0147] Table 3, Performance comparison of different intrusion detection models
[0148]
[0149] As can be seen from the data in Table 3, the SSC-HIDS model proposed in the present application achieves optimal performance of 1.0000 in the three indicators of Precision, Recall and F1-Score, using only 5% labeled data. Compared with CAAE and VARL-IDS which also use semi-supervised learning, SSC-HIDS not only significantly reduces the amount of labeled data required, but also has better performance. Compared with ECF-IDS which relies entirely on labeled data, SSC-HIDS achieves the same or slightly better detection effect while significantly reducing label dependence. In addition, compared with the unsupervised method XIPHOS which does not require any labeled data, the performance indicators of SSC-HIDS are significantly improved, which shows that introducing a small amount of labeled information can effectively guide model learning and greatly improve detection accuracy. In summary, SSC-HIDS not only guarantees high detection performance, but also shows high data utilization efficiency and low label dependence, and its overall performance is better than the baseline models compared.
[0150] To further test the performance robustness of the model (SSC-HIDS) of the present application in the challenging scenario of more complex data distribution and more advanced attack means, we introduced the "Car-Hacking: Attack & Defense Challenge 2020" public competition dataset for verification. The dataset is designed for attack and defense competitions, and the core challenge is to include more complex and hidden "replay attacks". We conducted experiments under the semi-supervised setting using 20% labeled data, and the detailed performance evaluation results are shown in Table 4.
[0151] Table 4, semi-supervised learning performance on Car-hacking 2020 dataset
[0152]
[0153] As shown in Table 4, the model (SSC-HIDS) of the application is semi-supervised trained on the Car-Hacking 2020 challenge dataset using 20% labeled data, showing high level of detection performance, with a macro F1-Score of 0.9981. The model faces more complex and hidden replay attacks (Replay Attack), and all four key indicators reach 1.0000. This fully proves that the multi-task joint training framework adopted by the application is effective, which can learn deep temporal context information to identify advanced hidden attacks, and the F1-Score of other types of attacks also remains above 0.9935. The results show that the learning ability and robustness of the framework of the application in dealing with complex attack threats. To verify the cross-model generalization ability of the method of the application, the optimal model pre-trained on the Car-Hacking dataset is migrated to the Spark and Soul two different vehicle models in the Survival dataset for fine-tuning and evaluation. The experimental results are shown in Tables 5 and 6:
[0154] Table 5, transfer learning performance-Spark vehicle
[0155]
[0156] Table 6, transfer learning performance-Soul vehicle
[0157]
[0158] The experimental results show that after two-stage fine-tuning, the pre-trained model on the test set of the Spark and Soul two target vehicles achieves 1.0000 precision, recall and F1 score for all attack categories (including normal traffic). This proves that the feature representation learned by the encoder on the source dataset has strong universality, and the transfer learning mechanism proposed by the application can efficiently adapt these knowledge to new target vehicles with different data patterns, solving the problem of model difficult to deploy across platforms.
[0159] To further verify the applicability of the method of the application to different communication protocols, we additionally introduce the CAN FD (Flexible Data-Rate) dataset for evaluation. CAN FD is a new generation of vehicle bus protocol, and its data frame structure and transmission rate are significantly different from the traditional CAN bus used in the foregoing application. To be consistent with the foregoing experiments (such as Car-Hacking), we also use the framework (such as SSC-HIDS) proposed by the application to perform complete training and evaluation under the semi-supervised setting of 5% labeled data on the CAN FD dataset. The experimental results are shown in Table 7.
[0160] Table 7. Semi-supervised performance on CAN FD dataset (5% labels)
[0161]
[0162] The model of the application achieves 1.0000 in Accuracy, Precision, Recall and F1-Score on all classes using only 5% labeled data on the CAN FD dataset. This result fully demonstrates that the framework (such as SSC-HIDS) of the application is not only suitable for traditional CAN bus, but also can efficiently learn the feature representation of CAN FD data and achieve high-precision attack detection. This further demonstrates the wide applicability of the method of the application on different vehicle network platforms.
[0163] To verify the lightweight characteristics and real-time detection capability of the model of the application, the parameter size and inference delay are evaluated. The single sample input is used for delay test to simulate real-time detection scenarios, and the test is performed on GPU and CPU hardware platforms respectively. The results are shown in Table 8 below:
[0164] Table 8. Model complexity evaluation:
[0165]
[0166] The results of Table 8 show that the total parameter amount of the model of the application is only 0.25M (million), which verifies the lightweight structure design. In terms of inference delay, the real-time detection delay of the model on GPU is 0.83ms, and the real-time detection delay on CPU is as low as 1.47ms. The small amount of parameters and millisecond-level detection delay indicate that the model of the application realizes low resource consumption and high computing efficiency while ensuring high detection performance, and has the feasibility of deployment in the vehicle ECU environment with limited computing power.
[0167] In summary, the vehicle network intrusion detection model based on mixed attention Transformer proposed by the application can significantly reduce model complexity and response delay while ensuring high detection accuracy, can effectively deal with various malicious traffic attack problems in vehicle networking, and has low label dependence. The good real-time performance and cross-model deployment adaptability of the model can effectively improve the security protection capability of the vehicle system and ensure the driving safety in the intelligent driving environment.
[0168] The embodiment has the following beneficial effects:
[0169] 1. In detecting typical five types of CAN bus attacks (including DoS, Fuzzy, Gear, RPM and normal traffic), it shows strong semi-supervised learning and transfer learning ability. Under the semi-supervised training condition of only 5% labeled data, the model reaches 100% in accuracy, precision, recall and F1-score; When the proportion of labeled data decreases to 1%, the F1-Score still maintains a high level of 0.981. At the same time, in the cross-model transfer learning task, the model achieves 100% detection accuracy on both Spark and Soul target vehicles, fully verifying the effectiveness and generalization ability of the method.
[0170] 2. In response to complex attacks and new communication protocols, it shows strong robustness and applicability. In the Car-Hacking 2020 challenge data set containing advanced covert attacks, under the semi-supervised training condition of 20% labeled data, the model's F1-Score reaches a high level of 0.9981, especially in detecting replay attacks (Replay Attack), F1-Score reaches 1.0000. At the same time, in the detection task of CAN FD new generation bus protocol, under the semi-supervised training condition of 5% labeled data, the detection of all attack categories and normal traffic achieves 1.0000 in four key indicators. This fully verifies the robustness of the method to complex attacks and the applicability to different communication protocols.
[0171] 3. The mixed encoder enhanced structure improves the comprehensiveness of feature extraction. The RFAConv module integrated at the front end of the encoder can first efficiently capture local and short-term temporal patterns in the CAN message sequence; The ContraNorm layer attached at the back end regularizes the final output feature representation, making it achieve higher intra-class clustering and inter-class separation in the feature space. This "local + global" hybrid design and representation optimization significantly improves the model's perception and discrimination ability for various attack features.
[0172] 4. By introducing a cross-layer parameter sharing mechanism in the encoder, i.e. multiple Transformer core layers reuse the same set of weight parameters, the total parameter quantity and computational complexity of the model are significantly reduced while maintaining the network depth. This design enables the model to maintain strong feature extraction ability while achieving efficient lightweight, effectively adapting to the power-limited vehicle ECU environment and meeting the requirements of real-time intrusion detection.
[0173] 5、Adopt multi-task joint training method, greatly improve the data utilization efficiency, reduce the dependence on expensive label data. This method in the unified training process, fusion using mass of unsupervised reconstruction task and self-supervised contrast learning task with a small amount of labeled data optimization supervised classification task. Through the collaborative optimization of the three tasks, the model can learn more robust and generalizable feature representation in the data sparse scene.
[0174] 6、With accurate multi-class attack recognition ability and good cross-model generalization adaptability. On the one hand, the multi-task joint training method enables the model to accurately distinguish normal traffic and various types of attacks, rather than simple binary classification. On the other hand, an efficient transfer learning mechanism is provided, which quickly applies the encoder pre-trained on the source vehicle data to the new target vehicle through two-stage fine-tuning (freeze training and overall fine-tuning) steps, solving the problem that existing models are difficult to deploy across platforms, and reducing time and data costs.
[0175] 7、Realize the light weight of model, the parameter quantity is only 0.25M, significantly reduce the system resource consumption and calculation complexity. At the same time, the model has very low inference time delay, the real-time detection time delay on GPU is only 0.83ms, and the real-time detection time delay on CPU is as low as 1.47ms. The design makes it have the potential and feasibility to realize efficient and timely deployment in the power-limited vehicle-mounted ECU environment.
[0176] The electronic device according to an embodiment of the disclosure includes a memory and a processor. The memory is configured to store non-transitory computer-readable instructions. Specifically, the memory can include one or more computer program products, which can include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may, for example, include random access memory (RAM) and / or cache memory, etc. The non-volatile memory may, for example, include read-only memory (ROM), hard disk, flash memory, etc.
[0177] The processor can be a central processing unit (CPU) or other forms of processing units with data processing and / or instruction execution capabilities, and can control other components in the electronic device to perform desired functions. In an embodiment of the disclosure, the processor is configured to run the computer-readable instructions stored in the memory, so that the electronic device performs all or part of the steps of the vehicle-mounted CAN bus intrusion detection method based on contrast self-supervised learning according to the embodiments of the disclosure.
[0178] Those skilled in the art should understand that, in order to solve the technical problem of how to obtain a good user experience effect, the embodiment can also include well-known structures such as a communication bus, an interface, and the like, which should also be included in the protection scope of the present disclosure.
[0179] As Figure 2 A structural schematic diagram of an electronic device is provided for the embodiments of the present disclosure. It shows a structural schematic diagram suitable for implementing the electronic device in the embodiments of the present disclosure. Figure 2 The electronic device shown is only an example and should not bring any limitation to the functions and use range of the embodiments of the present disclosure.
[0180] As Figure 2 As shown, the electronic device can include a processing device (for example, a central processor, a graphics processor, and the like), which can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) or loaded from a storage device into a random access memory (RAM). In the RAM, various programs and data required for the operation of the electronic device are also stored. The processing device, the ROM, and the RAM are connected to each other through a bus. An input / output (I / O) interface is also connected to the bus.
[0181] Generally, the following devices can be connected to the I / O interface: input devices including, for example, sensors or visual information collection devices; output devices including, for example, display screens; storage devices including, for example, magnetic tapes, hard disks, and the like; and communication devices. The communication devices can allow the electronic device to communicate with other devices (such as edge computing devices) wirelessly or by wire to exchange data. Although Figure 2 The electronic device with various devices is shown, but it should be understood that it is not required to implement or have all the devices shown. More or fewer devices can be alternatively implemented or provided.
[0182] In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts can be implemented as a computer software program. For example, the embodiments of the present disclosure include a computer program product including a computer program carried on a non-transitory computer readable medium, which contains program codes for executing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network through the communication device, or installed from the storage device, or installed from the ROM. When the computer program is executed by the processing device, all or part of the steps of the vehicle-mounted CAN bus intrusion detection method based on contrastive self-supervised learning of the embodiments of the present disclosure are performed.
[0183] The detailed description of the embodiments can refer to the corresponding description in the foregoing embodiments, which will not be repeated here.
[0184] A computer readable storage medium according to embodiments of the present disclosure has non-transitory computer readable instructions stored thereon. When the non-transitory computer readable instructions are run by a processor, all or part of the steps of the vehicle CAN bus intrusion detection method based on contrast self-supervised learning of the foregoing embodiments of the present disclosure are performed.
[0185] The computer readable storage medium described above includes, but is not limited to, an optical storage medium (for example, a CD-ROM and a DVD), a magneto-optical storage medium (for example, an MO), a magnetic storage medium (for example, a magnetic tape or a mobile hard disk), a medium with a built-in rewritable nonvolatile memory (for example, a memory card), and a medium with a built-in ROM (for example, a ROM cartridge).
[0186] The detailed description of the present embodiment can refer to the corresponding description in the foregoing embodiments, which will not be described here.
[0187] The above describes the basic principles of the present disclosure in combination with specific embodiments, but it should be noted that the advantages, advantages, effects and the like mentioned in the present disclosure are only examples and not limitations, and these advantages, advantages, effects and the like cannot be considered as the must-have of each embodiment of the present disclosure. In addition, the specific details of the above disclosure are only for the purpose of example and for the purpose of understanding, and not for the purpose of limitation, and the above details do not limit the present disclosure to the must-use specific details.
[0188] In the present disclosure, the relationship terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between the entities or operations. The block diagrams of devices, apparatuses, equipment, systems involved in the present disclosure are only illustrative examples and are not intended to require or imply the connection, arrangement, configuration shown in the block diagram. As those skilled in the art will recognize, these devices, apparatuses, equipment, systems can be connected, arranged, configured in any manner. Words such as "include", "contain", "have" and the like are open-ended words, which mean "including but not limited to", and can be used interchangeably. The words "or" and "and" used herein mean the word "and / or", and can be used interchangeably unless the context clearly indicates otherwise. The word "such as" used herein means the phrase "such as but not limited to", and can be used interchangeably.
[0189] In addition, as used herein, "or" used in the list of items preceded by "at least one of" means a disjunctive list, such that, for example, a list of "at least one of A, B, or C" means A or B or C, or AB or AC or BC, or ABC (i.e., A and B and C). Furthermore, the word "example" does not mean that the described example is preferred or better than other examples.
[0190] It is also important to note that the systems and methods of the present disclosure can be embodied in a variety of contexts. For example, the systems and methods of the present disclosure can be implemented in the context of a computer system, a mobile device, a server, a network, a distributed computing environment, etc. It is also important to note that the various components and steps of the systems and methods of the present disclosure can be decomposed and / or recombined. Such decompositions and / or recombinations should be considered equivalents of the present disclosure.
[0191] Various changes, modifications, and alterations to the techniques described herein can be made without departing from the teachings of the technology defined by the appended claims. In addition, the scope of the claims of the present disclosure is not limited to the specific aspects described above. The presently existing or later developed processes, machines, manufactures, compositions of matter, means, methods, or steps that perform substantially the same function or achieve substantially the same results as those described herein can be utilized according to the teachings of the present disclosure. Accordingly, the appended claims include within their scope such processes, machines, manufactures, compositions of matter, means, methods, or steps.
[0192] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the generic principles defined herein can be applied to other aspects without departing from the scope of the disclosure. Thus, the present disclosure is not intended to be limited to the aspects shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
[0193] The above description has been presented for the purpose of illustration and description. Furthermore, this description is not intended to limit the embodiments of the present disclosure to the forms disclosed herein. Although various example aspects and embodiments have been discussed above, those of skill in the art will recognize certain variations, modifications, changes, additions, and sub-combinations thereof.
Claims
1. A vehicle-mounted CAN bus intrusion detection system based on contrast self-supervised learning, characterized in that, The method comprises the following steps: a data preprocessing module is used to receive CAN bus data stream in real time, extract features of each CAN message in the CAN bus data stream to generate a multi-dimensional feature vector, and stack the feature vectors of continuous W messages to build a two-dimensional time sequence sample by using a sliding window method; an intrusion detection model is used to infer the two-dimensional time sequence sample and output a classification label; the intrusion detection model is trained by a multi-task joint training method, which combines an unsupervised reconstruction task, a supervised classification task and a self-supervised contrast learning task; a decision module is used to determine whether there is a CAN bus intrusion behavior according to the classification label output by the intrusion detection model; the intrusion detection model comprises an encoder, a decoder and a projection head; the encoder is used to compress the input time sequence sample into continuous latent variables and category latent variables; the decoder is used to reconstruct the original input based on the continuous latent variables and the category latent variables; the projection head is connected to the output of the encoder and is used to map the reconstructed features to a metric space of the self-supervised contrast learning; the multi-task joint training method comprises: an unsupervised reconstruction task: unlabelled data is input into the encoder to generate latent variables, and then the decoder reconstructs the original input based on the latent variables, and the encoder and the decoder are optimized by minimizing the mean square error loss between the reconstructed input and the original input; a supervised classification task: labelled data is input into the encoder to obtain a classification prediction result, and the encoder is optimized by minimizing the cross-entropy loss between the prediction result and the true label; a self-supervised contrast learning task: the input data is enhanced to generate samples with different views, the enhanced samples are input into the encoder to extract the pooled feature representation, then the projection head maps the feature representation to the metric space, and the parameters of the encoder and the projection head are optimized by minimizing the hybrid loss function combining the unsupervised contrast loss and the supervised contrast loss, so as to pull the representations of semantically similar samples and push the representations of dissimilar samples in the feature space.
2. The contrast self-supervised learning based vehicle-mounted CAN bus intrusion detection system according to claim 1, wherein, The encoder comprises an initial linear projection layer used to map the feature dimension of the input time sequence sample to the working dimension of the intrusion detection model; a position encoding layer used to add time sequence information to the sequence; a receptive field attention convolution module used to extract local time sequence features; a plurality of Transformer layers adopting a cross-layer parameter sharing mechanism; a contrast normalization layer used to optimize the final feature representation processed by the Transformer layer; a mean pooling layer and at least two linear layers, which are respectively used to generate continuous latent variables and category latent variables.
3. The contrastive self-supervised learning based vehicle-mounted CAN bus intrusion detection system according to claim 1, wherein, The decoder comprises an initial linear projection layer, a Transformer decoding network, a position encoding layer and a final linear projection layer; the initial linear projection layer is used to map the splicing vector of the continuous latent variables and the category latent variables into a sequence form; the Transformer decoding network comprises a plurality of Transformer layers with independent and non-shared parameters; the position encoding layer is used to add time sequence information to the sequence; the final linear projection layer is used to map the sequence to the original input. A final linear projection layer for mapping the processed sequence back to the original feature dimension to generate a reconstructed sample.
4. The contrastive self-supervised learning based vehicle-mounted CAN bus intrusion detection system according to claim 1, wherein, The data preprocessing module comprises: Obtain CAN bus data stream; Perform data cleaning and format conversion on the CAN bus data stream to form a multi-dimensional numerical vector; Extract multi-modal features from each CAN message in the cleaned and formatted CAN bus data stream to obtain a feature vector; Stack the feature vectors of the continuous W messages using a sliding window method to construct a two-dimensional time series sample, wherein the label of the sample is determined according to whether at least one attack message is contained in the window. Divide all the constructed two-dimensional time series samples into a training set, a validation set and a test set, and then divide the training set into an unlabeled training set and a labeled training set for multi-task joint training.
5. The contrast-based self-supervised learning based vehicle-mounted CAN bus intrusion detection system according to claim 4, characterized in that, The multi-modal feature extraction of each CAN message in the cleaned and formatted CAN bus data stream comprises: Calculate the time interval between the current message and the previous message, concatenate the binary vector, time interval and multi-dimensional numerical vector into a multi-dimensional feature vector of a single message, and the binary vector is converted according to CAN ID.
6. The contrastive self-supervised learning based vehicle-mounted CAN bus intrusion detection system according to claim 1, wherein, The system also supports transfer learning applications, which include: Pre-training the intrusion detection model on the source vehicle data set to obtain a pre-trained model; Migrate the encoder weights of the pre-trained model to the target vehicle; Complete model adaptation through a two-stage process of freezing encoder parameters to only train the classification head and then unfreezing the encoder parameters for overall fine-tuning on the target vehicle data set.
7. A vehicle CAN bus intrusion detection method based on contrastive self-supervised learning, applying the system of any one of claims 1 to 6, characterized in that, It includes: Real-time reception of CAN bus data stream, and feature extraction of each CAN message to generate a multi-dimensional feature vector; Stack the multi-dimensional feature vectors of the continuous W messages using a sliding window method to construct a two-dimensional time series sample; Input the two-dimensional time series sample into the trained intrusion detection model for inference classification and output the classification label; Determine whether there is a CAN bus intrusion behavior according to the classification label.
8. An electronic device, comprising: The electronic device comprises: At least one processor; and The memory is in communication connection with the at least one processor; wherein The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the vehicle-mounted CAN bus intrusion detection method based on contrast self-supervised learning according to claim 7.
Citation Information
Patent Citations
Vehicle-mounted CAN bus intrusion detection method based on CAN message characteristics
CN114900331A
Lightweight network intrusion detection method integrating multiple tasks and transfer learning
CN120185858A