A Vehicle CAN Intrusion Detection Method Based on Protocol Space Features and Multi-Scale Bi-Mamba Model
By constructing multi-dimensional protocol space features and a multi-scale Bi-Mamba model, the problem of unified modeling of protocol semantics and temporal behavior in CAN intrusion detection is solved, achieving efficient and lightweight identification of multiple types of attacks and improving detection accuracy and real-time performance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-12
- Publication Date
- 2026-04-03
AI Technical Summary
Existing CAN intrusion detection methods struggle to effectively utilize the semantics and temporal behavior of the CAN protocol, making it difficult to distinguish between various types of attacks. They also suffer from high model complexity, insufficient real-time performance, and inadequate deployment capabilities.
A vehicle-mounted CAN intrusion detection method based on protocol space features and a multi-scale Bi-Mamba model is adopted. By constructing multi-dimensional protocol space features, combining multi-scale CNN and bidirectional Mamba stacked layers, and using a channel gating mechanism for adaptive reweighting and classification.
It significantly improves the separability of different attack types, enhances the model's generalization ability and robustness, can efficiently identify multiple types of attacks, and its lightweight design is suitable for the vehicle environment, enabling high-precision real-time detection.
Smart Images

Figure CN121486112B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of vehicle networking and communication security technology, specifically, it relates to an in-vehicle CAN intrusion detection method based on protocol space features and a multi-scale Bi-Mamba model. Background Technology
[0002] Modern vehicles commonly use the CAN bus as the primary communication method between onboard electronic control units (ECUs). While the CAN protocol boasts advantages such as simple structure, good real-time performance, and low cost, it also suffers from three major security flaws: First, messages are unencrypted and unauthenticated, allowing any node to send forged messages; second, the bus employs a broadcast mechanism, enabling attackers to listen to and inject messages once connected; and finally, the message structure is fixed, containing only an ID, DLC, and an 8-byte payload, lacking built-in security mechanisms.
[0003] Based on the aforementioned shortcomings, existing research has proposed various CAN intrusion attack methods, mainly including DoS attacks: high-frequency flooding of specific IDs to occupy bus bandwidth; Fuzzy attacks: randomly generating IDs and payloads to disrupt node logic; and Gear / RPM spoofing attacks: forging gear shift and speed signals to induce dangerous behavior.
[0004] Existing intrusion detection methods mainly fall into two categories: 1. Rule / threshold type IDS: Relies on manually setting ID frequency thresholds, payload ranges, etc., which is difficult to adapt to complex working conditions and multiple types of attacks; 2. Deep learning-based IDS: Uses CNN / LSTM / Transformer to model the original payload, but has the following drawbacks: (1) Only uses 8-byte payload and does not systematically utilize the semantic features of the CAN protocol; (2) Uses heavy models such as LSTM / Transformer, which is difficult to deploy on resource-constrained vehicle ECUs; (3) There is confusion between multiple types of attacks (Fuzzy, Gear, RPM), and the overall accuracy is difficult to break through 99%. Therefore, a CAN bus intrusion detection method that takes into account protocol semantics, timing behavior and model lightweightness is needed. Summary of the Invention
[0005] In view of the above-mentioned technical problems and defects, the present invention provides a vehicle CAN intrusion detection method based on protocol space features and multi-scale Bi-Mamba model. It aims to solve the problems of existing methods lacking unified modeling of CAN protocol semantics, temporal behavior and payload statistics, as well as the technical problems of difficulty in distinguishing multiple types of attacks, low overall detection accuracy, high model complexity, and insufficient real-time performance and deployment capabilities.
[0006] To achieve the above objectives, the present invention adopts the following technical solution:
[0007] A method for intrusion detection of vehicle-mounted CAN based on protocol space features and a multi-scale Bi-Mamba model, comprising the following steps:
[0008] Step S1. Data preprocessing:
[0009] The original messages are uniformly converted into standard fields. After data cleaning, a set of multi-dimensional protocol space features is constructed for each CAN message. The multi-dimensional protocol space features include: semantic features, statistical features and temporal features.
[0010] Step S2. Construct a multi-scale CNN + bidirectional Mamba intrusion detection model. The intrusion detection model includes multi-scale convolutional branches, bidirectional Mamba stacked layers, and a channel gating mechanism. The input sample is first transposed into a shape, and then passed through three 1D convolutional branches with different kernel sizes. The three outputs are averaged and fused to obtain multi-scale local features, which are then transposed into the shape required by Mamba. After processing by the bidirectional Mamba stacked layers, the temporal features are adaptively reweighted through a channel gating mechanism to obtain the gated and reweighted features. Finally, normalization, Dropout operation, global average pooling, and MLP classification are performed sequentially.
[0011] Step S3. Train the constructed multi-scale CNN + bidirectional Mamba intrusion detection model;
[0012] Step S4. Based on the trained intrusion detection model, identify and classify the real-time received CAN traffic data to determine the intrusion detection result.
[0013] As a preferred embodiment of the present invention, the semantic features include ID normalization features, DLC normalization features, and normalized 8-bit payload bytes; the statistical features include the sum of 8-bit payloads, the mean of 8-bit payloads, the standard deviation of 8-bit payloads, the maximum value of 8-bit payloads, the minimum value of 8-bit payloads, the proportion of non-zero bytes in 8-bit payloads, and the bit flip rate; the temporal features include the time difference between adjacent time messages, the time difference between globally adjacent frames, and the time difference between adjacent frames with the same ID.
[0014] As a preferred embodiment of the present invention, the sizes of the three branch convolution kernels in the multi-scale convolution branch are 3, 5, and 9, respectively.
[0015] As a preferred embodiment of the present invention, the bidirectional Mamba stacking layer has four layers, each layer including a forward Mamba and a reverse Mamba, and the third layer... The calculation form of a layer is as follows:
[0016] ;
[0017] ;
[0018] ;
[0019] ;
[0020] in, , Representing the The output of the layer, as the first Layer input, For the first The layer outputs forward in Mamba; Reverse indicates the sequence is reversed. Representing the The output of the layer reverse Mamba, This represents the fusion result of the forward and reverse Mamba outputs. Representing the The final output of the layer.
[0021] As a preferred embodiment of the present invention, MLP classification outputs five attack probabilities through a two-layer fully connected network, expressed as follows:
[0022] ;
[0023] Where Z represents the sample-level feature vector obtained by global average pooling. Represents the nonlinear activation function ReLU. and These are the learnable parameters of the first layer of an MLP, used to map global features to the latent space. and These are the learnable parameters of the MLP output layer, used to map the hidden representations to the category space, and Softmax represents the output layer activation function.
[0024] As a preferred embodiment of the present invention, the loss function during training is cross-entropy loss with class weights, and the learning rate is: lr = 1 × 10⁻⁶. -4 Batch size: 128; Number of epochs: 40; In the class weights, the weight of the Normal class is 0.4, and the weight of the Attack class is 1.5.
[0025] As a further preferred embodiment of the present invention, the expression for the bit flip rate is:
[0026] ;
[0027] Here, bit_flip_norm represents the bit flip rate. The payload represents the payload at the current time t. The payload representing the data with the same ID at the previous time step. For XOR operation, This represents the count of 1s in a binary number.
[0028] As a further preferred embodiment of the present invention, the global adjacent frame time difference ;
[0029] in, This represents the time difference between adjacent time messages. Represents the timestamp when the current CAN message arrived. The timestamp representing the previous CAN message. The 0.99 quantile represents the global adjacent time difference series, and normalization is performed using the 0.99 quantile. Used to restrict the normalized values to the range [0,1];
[0030] Time difference between adjacent frames with the same ID ;
[0031] in, , Represents the reception time of a message with a specific ID. This represents the time when the same ID last received a message. Represents the actual time interval between messages with the same ID; The 0.99 quantile represents the global adjacent time difference series, and normalization is performed using the 0.99 quantile. Used to restrict the normalized values to the range [0,1].
[0032] The present invention also provides an electronic device, comprising: one or more processors and a memory; wherein the memory is used to store one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the above-described vehicle CAN intrusion detection method based on protocol space features and multi-scale Bi-Mamba model.
[0033] The present invention also provides a computer-readable medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the above-described method for vehicle CAN intrusion detection based on protocol space features and a multi-scale Bi-Mamba model.
[0034] Advantages and beneficial effects of the present invention:
[0035] (1) Protocol semantic enhancement features significantly improve data separability and robustness: This invention constructs 25-dimensional protocol space enhancement features to structurally express information such as time characteristics, payload statistics, and protocol field semantics in CAN messages, enabling the model to obtain a complete protocol semantic description at the input end. Compared with traditional methods that directly use the original bitstream or are based solely on ID / Payload, the protocol enhancement features of this invention significantly improve the separability between different attack types, reduce the burden of "blindly searching" in low-level features for deep models, and give the model stronger generalization ability and training stability. This feature system effectively overcomes the problems of existing CAN intrusion detection methods, such as difficulty in fully utilizing protocol semantics and the strong reliance on human experience for feature extraction.
[0036] (2) Multi-scale convolutional structures can adapt to attack patterns at different time scales: The attack behavior of vehicle CAN messages varies significantly across time scales, with some exhibiting high-frequency local mutations and others showing mid-frequency disturbances or long-term periodic changes. This invention employs a multi-scale convolutional structure, extracting local temporal information through different convolutional kernel sizes to achieve joint modeling of short-term, medium-term, and long-term periodic patterns, enabling the model to simultaneously perceive the dynamic characteristics of multiple abnormal patterns. This design significantly improves the model's robustness against various attacks such as DoS, Fuzzy, gear, and RPM, effectively overcoming the problem of insufficient recognition ability of traditional single-scale models when facing cross-time scale attacks, and providing the model with the necessary flexibility and stability.
[0037] (3) The bidirectional Mamba module provides powerful long-term time-series modeling capabilities: Traditional time-series models often face problems such as high computational cost and insufficient context utilization when processing long-sequence data such as CAN messages. The MS-Mamba model of this invention performs state-space scanning of the sequence simultaneously through two paths, forward and backward, to achieve efficient modeling of long-range dependency patterns. This structure can not only capture the contextual relationship between attack behaviors before and after the sequence, but also effectively identify slow-varying periodic attacks and cross-frame dependency features, thereby significantly improving the accuracy of intrusion detection. The use of bidirectional Mamba overcomes the problem that existing methods are difficult to utilize global time-series information and maintain high inference efficiency at the same time, providing a high-performance and high-efficiency solution for CAN intrusion detection.
[0038] (4) Channel gating mechanism enhances key feature selection capability: In the intermediate representation of deep temporal models, the importance of different feature channels is often inconsistent. Some channels carry key attack information, while others are noise. The channel gating mechanism proposed in this invention generates channel-by-channel weights through a lightweight network, realizing adaptive adjustment of the importance of feature channels. It can strengthen the response of attack-related channels and suppress invalid or interfering channels, thereby improving the signal-to-noise ratio of the final feature representation. This mechanism effectively overcomes the performance instability problem caused by the indiscriminate processing of all channels in traditional models, and enhances the model's adaptability to feature differences and complex scenarios.
[0039] (5) The overall architecture is lightweight, efficient, and easy to deploy. In its design, this invention fully considers the computational limitations of the vehicle environment. By combining protocol-enhanced features, multi-scale convolution, and the Mamba model, it achieves a balance between high accuracy and high efficiency. Compared with Transformer-based methods, the MS-Mamba model of this invention has linear complexity, which significantly reduces the amount of inference computation. Compared with the traditional handmade feature + classifier structure, this invention implements an end-to-end processing flow, enabling the model to detect abnormal messages in real time. The overall system has the advantages of being lightweight, deployable, and having strong real-time performance, overcoming the problem that existing CAN intrusion detection methods are difficult to implement on vehicle devices.
[0040] (6) This invention combines Protocol-Space Features with MultiScale Bi-Mamba (CNN) to achieve high-precision identification of five types of messages (Normal, DoS, Fuzzy, gear, and RPM) on the Car-Hacking dataset. Experimental results show that the overall classification accuracy is close to 99.96% and the Macro-F1 score is close to 99.97%, which is significantly better than existing methods. Attached Figure Description
[0041] Other objects and results of the invention will become more apparent and readily understood with reference to the following description taken in conjunction with the accompanying drawings. In the drawings:
[0042] Figure 1 This is a flowchart of the data preprocessing process in the vehicle CAN intrusion detection method provided by the present invention;
[0043] Figure 2 This is a schematic diagram of the multi-scale CNN+bidirectional Mamba intrusion detection model (MS-Mamba) provided by the present invention;
[0044] Figure 3 This is the confusion matrix diagram of the present invention;
[0045] Figure 4 This is a bar chart showing the performance test results of this invention. Detailed Implementation
[0046] To enable those skilled in the art to better understand the technical solutions and advantages of the present invention, the present application will be described in detail below with reference to the accompanying drawings, but this is not intended to limit the scope of protection of the present invention.
[0047] The vehicle CAN intrusion detection method based on protocol space features and multi-scale Bi-Mamba model provided by this invention can be mainly divided into three stages. In the first stage, the original CAN message is parsed and the data is cleaned, and protocol space features are constructed to form samples with a fixed length time window. In the second stage, an intrusion detection model based on multi-scale CNN + bidirectional Mamba is constructed. In the third stage, a training strategy and inference process based on class weights and resampling are implemented.
[0048] like Figure 1 , Figure 2 As shown, the vehicle CAN intrusion detection method based on protocol space features and a multi-scale Bi-Mamba model provided in this embodiment specifically includes the following steps:
[0049] Step S1. Data preprocessing:
[0050] Step S1.1. Parsing the raw data (raw CAN message)
[0051] The vehicle CAN data used in this invention comes from a public dataset: the Car-Hacking dataset, which contains five types of files: normal running data: normal_run_data.txt; DoS attack: DoS_dataset.csv; Fuzzy attack: Fuzzy_dataset.csv; gear attack: gear_dataset.csv; RPM attack: RPM_dataset.csv.
[0052] The script automatically adapts to two original formats: text-based rows and 12-column CSV files. The specific processing flow is as follows: Figure 1 As shown, firstly, the original message is parsed, converting it into standard fields:
[0053]
[0054] Where timestamp is the timestamp, used in this dataset to record the time when the CAN message is received; id_int is an integer representing the priority of the CAN message; and dlc_int is an integer representing the length of the CAN message data. This refers to the data field of the CAN message.
[0055] Secondly, data cleaning is performed. Data with missing timestamps and missing id_int fields is discarded; timestamps are converted to floating-point numbers, ids are uniformly converted to integers, and data fields ( ) bytes are converted to unsigned integers of 0–255 when the data field ( If the number of bytes is less than 8, it will be automatically padded with 0s until it reaches 8 bytes. If the number of bytes is more than 8, it will be truncated and only the first 8 bytes will be kept. For illegal hexadecimal numbers, they will be forcibly converted to 0.
[0056] Finally, protocol space features are constructed. For each CAN message, a set of multi-dimensional protocol space features is built, including: semantic features: And the normalized 8-bit payload bytes; Statistical characteristics: , , , , And bit-flip feature; temporal features: delta_t_same_id_norm and delta_t_norm.
[0057] Specifically, in this embodiment, the expression for calculating semantic features is:
[0058] This can map the ID to [0,1]; where, This represents the normalized characteristics of the ID. id_int is the value of the ID after being converted to an integer (the integer of the CAN message priority). 2047 is the maximum value of the standard CAN identifier.
[0059] It can map the DLC to [0,1]; where, This represents the normalized characteristics of dlc, and dlc_int represents the integer length of the CAN message data, with 8 being the maximum value of the message data length.
[0060] Normalize the 8-byte payload: , ;in, This represents the data at the i-th position after normalization. 255 represents the i-th data element in the payload data field, where 255 is the maximum value of each digit in the payload.
[0061] Specifically, in this embodiment, the calculation expression for the statistical features is as follows:
[0062] ;
[0063] ;
[0064] in, Represents the sum of the 8-bit payload. This represents the average of the 8-bit payload. This represents the data at the i-th position after normalization.
[0065] ;
[0066] ;
[0067] ;
[0068] ;
[0069] in, This represents the standard deviation of the 8-bit payload. This represents the maximum value in the 8-bit payload. This represents the minimum value in the 8-bit payload. This represents the proportion of non-zero bytes in an 8-bit payload.
[0070] For two consecutive payload frames with the same CAN ID, calculate the number of bit flips after XORing each byte and normalize it to [0,1]:
[0071] This feature can effectively capture the mutation behavior of payloads in fuzzy and gear / RPM attacks;
[0072] Here, bit_flip_norm represents the bit flip rate. The payload represents the payload at the current time t. The payload representing the data with the same ID at the previous time step. For XOR operation, This represents the number of 1s in a binary number. Through the above operation, it is possible to calculate how many bit flips occurred in the payloads of two consecutive frames with the same CAN ID. 64 represents the maximum number of bits that can be flipped.
[0073] Specifically, in this embodiment, the expression for calculating the timing features is:
[0074] Global adjacent frame time difference ;
[0075] in, This represents the time difference between adjacent time messages. Represents the timestamp when the current CAN message arrived. The timestamp representing the previous CAN message. The 0.99 quantile represents the global adjacent time difference series, and normalization is performed using the 0.99 quantile. This is used to limit the normalized values to the [0,1] range, preventing extreme time differences from causing numerical shocks to the model and ensuring the stability of the input feature values.
[0076] Time difference between adjacent frames with the same ID ;
[0077] in, , Represents the reception time of a message with a specific ID. This represents the time when the same ID last received a message. Represents the actual time interval between messages with the same ID; The 0.99 quantile represents the global adjacent time difference series, and normalization is performed using the 0.99 quantile. This is used to limit the normalized values to the [0,1] range, preventing extreme time differences from causing numerical shocks to the model and ensuring the stability of the input feature values.
[0078] After the data normalization and feature extraction described above, each CAN message is mapped to a protocol space feature vector. : Where i is the total number of samples after preprocessing. The feature vector is obtained by concatenating the 20-dimensional features extracted through feature extraction. The feature dimension is 20. This represents the corresponding vector space. Finally, the time window is constructed and the dataset is partitioned.
[0079] In this embodiment, after extracting the complete feature sequence for each category (normal / DoS / Fuzzy / gear / RPM), the data is divided according to a fixed window length T = 256: each 256 frames constitute a sample. Data at the end of a window that is less than one window is discarded; and each window is assigned a category label. .
[0080] Then, all category window samples are concatenated sequentially, randomly shuffled, and divided into training set: 70%; validation set: 15%; test set: 15%. Each set is then saved as a corresponding npz file for the next training step. This completes the preprocessing stage.
[0081] Step S2. Construct a multi-scale CNN + bidirectional Mamba intrusion detection model (MS-Mamba).
[0082] The underlying backbone network is a multi-scale bidirectional Mamba (MultiScale BiMamba Backbone), such as... Figure 2 As shown, its structure mainly includes the following five parts:
[0083] 1. Multi-Scale CNN Branches
[0084] The input sample is first transposed into a shape: B is the batch size, representing the number of samples fed into the model in parallel at one time. =20 represents the 20-dimensional CAN protocol features, and T represents the number of messages contained in a sliding window.
[0085] Through three 1D convolution branches with different kernel sizes:
[0086] kernel size = 3
[0087] kernel size = 5
[0088] kernel size = 9
[0089] The number of output channels for each branch is: Then, channel splicing and multi-scale feature fusion are performed; specifically, the three outputs are averaged and fused to obtain multi-scale local features:
[0090]
[0091]
[0092] Then transpose it to the shape required by Mamba: .
[0093] 2. Bi-Mamba Stacked Layers;
[0094] The model internally contains four layers of forward and backward Mamba state space models, each layer including:
[0095] Forward Mamba: Modeling in the forward time direction;
[0096] Reverse Mamba: Modeling a time series after it has been reversed, and then reversing it back to its original order;
[0097] Residual connectivity and forward / backward feature fusion.
[0098] No. The calculation form of a layer is as follows:
[0099]
[0100]
[0101]
[0102] in, , representing the Bi-Mamba layer index, Representing the The output of the layer, as the first Layer input, For the first The output of a forward Mamba layer; Reverse indicates the reverse of the sequence. Representing the The output of backward Mamba. This represents the fusion result of the forward and reverse Mamba outputs (the main branch output after bidirectional Mamba fusion), using element-wise averaging, and finally performing residual joins. Representing the The final output of the layer, through multi-layer stacking, can capture bidirectional dependencies at different time scales, making it more suitable for identifying attack types such as gear / RPM that require joint judgment of context.
[0103] 3. Channel Gating Mechanism (Gate)
[0104] Following the Bi-Mamba layer, a channel-level gating network is introduced to adaptively reweight the temporal features:
[0105]
[0106]
[0107] in, H represents the Sigmoid activation function, and H represents the output feature of Bi-Mamba, which serves as the input to the gating unit. This represents the gating weight matrix, allowing us to learn the importance of different channels in gating computation. This represents the bias parameters in the gating network. For the gated weight tensor, Hadamard element-wise multiplication represents element-wise multiplication at each position, channel, and time step. This gated network can suppress noisy channels and highlight protocol features that are highly correlated with attack behavior. These are the features after gating and reweighting.
[0108] 4. Normalization, Dropout
[0109] To enhance training stability and alleviate overfitting, the time-series features after gating are... Layer Normalization and Dropout operations are applied sequentially to obtain the regularized temporal representation.
[0110] 5. Global Average Pooling and MLP Classification
[0111] Perform average pooling over time:
[0112]
[0113] in, Representing the The gated feature vectors at each time step, where T represents the time window length and the number of time steps (CAN messages) in a sample, are obtained by accumulating the features of all time steps along the time dimension and taking the arithmetic mean over the time dimension to eliminate the influence of the time window length on the feature scale.
[0114] Output the probability of five types of attacks through a two-layer fully connected network:
[0115]
[0116] Where Z represents the sample-level feature vector obtained by global average pooling. Represents the nonlinear activation function ReLU. and These are the learnable parameters of the first layer of a multilayer perceptron (MLP), used to map global features to the latent space. and These are the learnable parameters of the MLP output layer, used to map the hidden representations to the category space, and Softmax represents the output layer activation function.
[0117] Step S3. Train the constructed multi-scale CNN + bidirectional Mamba intrusion detection model;
[0118] The training strategy and loss function are as follows:
[0119] Training was performed using the AdamW optimizer, with the following key hyperparameters: Learning rate: lr = 1 × 10⁻⁶ -4 Batch size: 128; Number of epochs: 40; Channel normalization: --normalize (calculates μ / std per channel); Class weights: --class-weights "0.4,1.5,1.5,1.5,1.5" (where Normal class weights are smaller (0.4) and Attack class weights are larger (1.5) to balance training); Training set sampling method: --balanced-sampler (uses Weighted Random Sampler to resample samples of each class to further alleviate class imbalance.)
[0120] The loss function is cross-entropy loss with class weights:
[0121]
[0122] in, These are the weights for each category, used to alleviate the problem of imbalanced category distribution; One-hot representation of the true label. Let be the predicted probability of the model for class c.
[0123] Step S4. Based on the trained model, identify and classify the real-time received CAN traffic data to determine the intrusion detection result.
[0124] This embodiment also includes ablation experiments, which mainly involve the following three key modules: multi-scale convolution, bidirectional Mamba, and channel gating.
[0125] (1) Multi-scale convolution module
[0126] This invention extracts temporal local features with window lengths of 3, 5, and 9 using a multi-scale convolutional structure, enabling the model to simultaneously learn short-term fluctuations, medium-term disturbances, and long-term trends in the CAN communication process, thereby improving its adaptability to different types of attacks. This module also improves the representation capability of the original time-domain features, providing higher-quality feature inputs for subsequent Mamba long sequence modeling.
[0127] (2) Bidirectional Mamba module
[0128] This invention utilizes a bidirectional Mamba structure to model the state space of both forward and reverse sequences separately, and fuses the two types of features. This enables the simultaneous capture of the antecedent and consequence relationships of communication sequences, improving the ability to identify complex patterns such as slow-varying attacks and stealth attacks. Bidirectional Mamba significantly enhances the model's ability to model the global context and is a key module for overall performance improvement.
[0129] (3) Channel gate control module
[0130] This invention further introduces a channel gating mechanism, generating channel-wise attention weights based on MLP to achieve adaptive filtering and weighting of different semantic channels in temporal features, thereby enhancing key channels, suppressing noise dimensions, and improving the discriminative power of feature representations. This module helps improve the robustness of the model in environments with limited data.
[0131] The results of the ablation experiment are shown in the table below:
[0132] Table 1 Ablation Experiment Results
[0133] Model Accuracy (%) Accuracy (%) Recall rate (%) F1(%) Main model 0.9995 0.9996 0.9996 0.9996 Eliminate CNN 0.9554 0.9702 0.9646 0.9645 Mamba 0.9734 0.9790 0.9790 0.9790 Eliminate bi-Mamba 0.9533 0.9635 0.9627 0.9628 Eliminate channel gating 0.9571 0.9712 0.9659 0.9659
[0134] Ultimately, the model designed in this invention (the main model) achieved near 100% accuracy and recall in the experiment, significantly outperforming traditional CNN / RNN / Transformer methods.
[0135] This invention also tested the accuracy, precision, recall, and F1 score of P-LeNet (a publicly disclosed model of a deep transfer learning-based intrusion detection system for electric vehicular networks), KNN (nearest neighbor algorithm), SVM (support vector machine), DCNN (deep convolutional neural network), and CANet (an publicly disclosed model of an unsupervised intrusion detection system for high dimensional CAN bus data) on the Car-hacking dataset. The results are shown in the table below.
[0136] Table 2 Comparative test results
[0137] Model Accuracy (%) Accuracy (%) Recall rate (%) F1(%) P-LeNet 98.10 98.04 98.14 97.83 KNN 96.30 97.40 96.40 93.40 SVM 96.50 95.80 95.70 93.37 DCNN 99.93 99.84 99.84 99.91 CANet 98.75 98.75 99.09 98.89 Ours 99.95 99.96 99.96 99.96
[0138] Results: The MS-Mamba model of this invention outperforms traditional models in accuracy, precision, recall, and F1 score, demonstrating excellent performance. Specifically, its accuracy is 0.0185, 0.0365, 0.0345, 0.0002, and 0.0012 higher than P-LeNet, KNN, SVM, DCNN, and CANet, respectively. Its F1 score is 0.0213, 0.0656, 0.0659, 0.0005, and 0.0107 higher than P-LeNet, KNN, SVM, DCNN, and CANet, respectively. Furthermore... Figure 3 The resulting confusion matrix further demonstrates that the MS-Mamba lightweight model of this invention has an excellent ability to distinguish between various attack categories.
[0139] In addition, this invention also evaluated the CPU utilization, number of parameters, parameter memory, throughput, and average processing time of the MS-Mamba model, and the results are shown in the table below:
[0140] Table 3 Performance evaluation results of the MS-Mamba model
[0141] CPU utilization (%) Memory usage (MB) Number of parameters Throughput (samples / s) Average processing time (ms / sample) 63.38 2.13 558341 14004.36 0.067
[0142] As can be seen from Table 3, the MS-Mamba model of this invention exhibits excellent performance indicators during the evaluation process: CPU utilization is 63.38%, and memory usage is only 2.13MB, showing low resource consumption; the model's throughput reaches 14004.36 samples / second, while the average processing time per sample is 0.067 milliseconds, demonstrating efficient processing capabilities and fast response speed.
[0143] The present invention also provides an electronic device, comprising: one or more processors and a memory; wherein the memory is used to store one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the above-described vehicle CAN intrusion detection method based on protocol space features and multi-scale Bi-Mamba model.
[0144] The present invention also provides a computer-readable medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the above-described method for vehicle CAN intrusion detection based on protocol space features and a multi-scale Bi-Mamba model.
[0145] Those skilled in the art will understand that all or part of the functions of the various methods / modules in the above embodiments can be implemented by hardware or by computer programs. When all or part of the functions in the above embodiments are implemented by computer programs, the program can be stored in a computer-readable storage medium, which may include: read-only memory, random access memory, disk, optical disk, hard disk, etc., and the above functions can be implemented by executing the program with a computer. For example, the program can be stored in the memory of a device, and when the program in the memory is executed by the processor, all or part of the above functions can be implemented.
[0146] In addition, when all or part of the functions in the above embodiments are implemented by computer programs, the programs can also be stored in storage media such as servers, other computers, disks, optical discs, flash drives, or portable hard drives. They can be downloaded or copied to the memory of the local device, or the system of the local device can be updated. When the program in the memory is executed by the processor, all or part of the functions in the above embodiments can be implemented.
[0147] The above-described specific examples are for illustrative purposes only and are not intended to limit the scope of the invention. Those skilled in the art can make various simple deductions, modifications, or substitutions based on the principles of this invention. Therefore, the scope of protection of this invention should be determined by the scope of the claims.
Claims
1. A method for detecting intrusion into vehicle-mounted CAN based on protocol space features and a multi-scale Bi-Mamba model, characterized in that, The method includes the following steps: Step S1. Data preprocessing: The original messages are uniformly converted into standard fields. After data cleaning, a set of multi-dimensional protocol space features is constructed for each CAN message. The multi-dimensional protocol space features include: semantic features, statistical features and temporal features. Step S2. Construct a multi-scale CNN + bidirectional Mamba intrusion detection model. The intrusion detection model includes multi-scale convolutional branches, bidirectional Mamba stacked layers, and a channel gating mechanism. The input sample is first transposed into a shape, and then passed through three 1D convolutional branches with different kernel sizes. The three outputs are averaged and fused to obtain multi-scale local features, which are then transposed into the shape required by Mamba. After processing by the bidirectional Mamba stacked layers, the temporal features are adaptively reweighted through a channel gating mechanism to obtain the gated and reweighted features. Finally, normalization, Dropout operation, global average pooling, and MLP classification are performed sequentially. Step S3. Train the constructed multi-scale CNN + bidirectional Mamba intrusion detection model; Step S4. Based on the trained intrusion detection model, identify and classify the real-time received CAN traffic data to determine the intrusion detection result; The bidirectional Mamba stack has four layers, each including forward Mamba and reverse Mamba. The calculation form of a layer is: ; ; ; ; in, , Representing the The output of the layer, as the first Layer input, For the first The layer outputs forward in Mamba; Reverse indicates the sequence is reversed. Representing the The output of the layer reverse Mamba, This represents the fusion result of the forward and reverse Mamba outputs. Representing the The final output of the layer; MLP classification outputs the probabilities of five types of attacks using a two-layer fully connected network, expressed as follows: ; Where z represents the sample-level feature vector obtained by global average pooling. ReLU represents the nonlinear activation function. and These are the learnable parameters of the first layer of an MLP, used to map global features to the latent space. and These are the learnable parameters of the MLP output layer, used to map the hidden representations to the category space, and Softmax represents the output layer activation function.
2. The method for vehicle-mounted CAN intrusion detection based on protocol space features and a multi-scale Bi-Mamba model according to claim 1, characterized in that, The semantic features include ID normalization features, DLC normalization features, and normalized 8-bit payload bytes; the statistical features include the sum of 8-bit payloads, the mean of 8-bit payloads, the standard deviation of 8-bit payloads, the maximum value of 8-bit payloads, the minimum value of 8-bit payloads, the proportion of non-zero bytes in 8-bit payloads, and the bit flip rate; the temporal features include the time difference between adjacent time messages, the time difference between globally adjacent frames, and the time difference between adjacent frames with the same ID.
3. The intrusion detection method for vehicle CAN based on protocol space features and a multi-scale Bi-Mamba model according to claim 1, characterized in that, The kernel sizes of the three branches in the multi-scale convolution branch are 3, 5, and 9, respectively.
4. The intrusion detection method for vehicle CAN based on protocol space features and a multi-scale Bi-Mamba model according to claim 1, characterized in that, During training, the loss function is cross-entropy loss with class weights, and the learning rate is lr = 1 × 10⁻⁶. -4 Batch size: 128; Number of epochs: 40; In the class weights, the weight of the Normal class is 0.4, and the weight of the Attack class is 1.
5.
5. The method for vehicle-mounted CAN intrusion detection based on protocol space features and a multi-scale Bi-Mamba model according to claim 2, characterized in that, The expression for bit flip rate is: bit_flip_norm= ; Where bit_flip_norm represents the bit flip rate. The payload represents the payload at the current time t. The payload representing the data with the same ID at the previous time step. For XOR operation, This represents the count of 1s in a binary number.
6. The method for vehicle-mounted CAN intrusion detection based on protocol space features and a multi-scale Bi-Mamba model according to claim 2, characterized in that, Global adjacent frame time difference delta_t_norm ; in, This represents the time difference between adjacent time messages. Represents the timestamp when the current CAN message arrived. The timestamp representing the previous CAN message. The 0.99 quantile represents the global adjacent time difference series, and normalization is performed using the 0.99 quantile. Used to restrict the normalized values to the range [0,1]; Time difference between adjacent frames with the same ID: delta_t_same_id_norm= ; in, , Represents the reception time of a message with a specific ID. This represents the time when the same ID last received a message. Represents the actual time interval between messages with the same ID; The 0.99 quantile represents the global adjacent time difference series, and normalization is performed using the 0.99 quantile. Used to restrict the normalized values to the range [0,1].
7. An electronic device, comprising: One or more processors or memories; The memory is used to store one or more programs, characterized in that, when the one or more programs are executed by the one or more processors, the one or more processors implement the vehicle CAN intrusion detection method based on protocol space features and multi-scale Bi-Mamba model as described in any one of claims 1 to 6.
8. A computer-readable medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the vehicle CAN intrusion detection method based on protocol space features and multi-scale Bi-Mamba model as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Industrial control system intrusion detection method and system based on Mama model
CN119848749A
Hyperspectral image classification method based on S2CFM-spatial spectrum convolution fusion Mama network model
CN120707928A