Intrusion detection method for vehicle-mounted CAN network
Through deep learning technology and Bi-LSTM neural network model, combined with the attention mechanism, it solves the problem of modern automobile CAN bus being vulnerable to attacks, achieves efficient intrusion detection, and enhances the security and detection performance of vehicle networks.
Patent Information
- Application Number
- CN202410857129.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-10-29
AI Technical Summary
The CAN bus of modern automobiles is easily attacked due to its broadcast transmission, no encryption, and no authentication characteristics, making the in-vehicle network vulnerable to confidentiality, integrity, and availability attacks. Traditional intrusion detection systems have false positives or negatives for new attacks and unknown threats. question.
Using deep learning technology, by extracting features from CAN message data, we build a Bi-LSTM neural network model and introduce an attention mechanism. We combine it with the CAR-HACKING DATASET data set to perform intrusion detection, using zero-padding strategy and Min-Max normalization. Process the data, divide the data set and conduct model training to achieve effective intrusion detection.
It improves the accuracy and efficiency of intrusion detection, reduces noise interference, and enhances the security of the vehicle network. It has a small number of model parameters, fast detection speed, can effectively deal with sudden anomalies, and provides high performance and interpretability.
Smart Images

Figure CN118869263A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of mobile communications and relates to an intrusion detection method for a vehicle-mounted CAN network. Background Art
[0002] With the rise of the Internet of Vehicles era, intelligent connected cars have brought convenience to transportation and improved the comfort, safety and economy of car driving. The electronic control units (ECUs) inside the car interact through the controller area network (CAN) bus, and the CAN bus has become the standard for automotive computer control systems due to its advantages such as low cost, high fault tolerance and stability.
[0003] However, with the development of artificial intelligence, the number of ECUs in modern cars has increased dramatically, and most of them are connected using CAN bus. Although CAN bus has advantages such as fast data transmission, low cost, high reliability and real-time performance, and has performed well in the field of automotive electronics, the following characteristics of CAN bus make it easy to be attacked:
[0004] (1) Broadcast transmission: A malicious node can easily steal CAN bus messages sent by all other nodes.
[0005] (2) No encryption: By counting a large number of CAN bus messages, the communication behavior between electronic control units can be reverse analyzed and the encoding method of the messages can be deduced.
[0006] (3) No authentication: After understanding the message encoding method, the attacker can control the vehicle by sending specific forged messages to the CAN bus through a malicious node.
[0007] Therefore, although the vehicle bus is a bus hidden at the bottom of the intelligent networked car information system, due to its high authority to directly control vehicle behavior and weak security of broadcast transmission, no encryption and authentication, the vehicle network is vulnerable to confidentiality, integrity and availability attacks. Since 2016, Kenn Lab has been conducting continuous research on Tesla's information security. The experimental video shows that attackers can send CAN bus messages through remote commands to open the trunk and sunroof of a normally moving car.
[0008] Traditional intrusion detection systems (IDS) play an important role in monitoring vehicle network intrusion behaviors. However, for new attacks and unknown threats, traditional IDS may have the problem of false positives or false negatives. Therefore, it is urgent to design a new intrusion detection for CAN to solve the above problems. Summary of the invention
[0009] In view of this, the purpose of the present invention is to provide an intrusion detection method for an in-vehicle CAN network. The method realizes an effective intrusion detection scheme for the in-vehicle network CAN bus by extracting features from CAN message data and combining deep learning technology.
[0010] In order to achieve the above object, the present invention provides the following technical solutions:
[0011] An intrusion detection method for a vehicle-mounted CAN network, the method comprising the following steps:
[0012] S1: Collection and acquisition;
[0013] The CAR-HACKING DATASET dataset released by HCEL is used. The dataset includes normal message data, DoS attack, fuzzy attack and spoofing attack information. The construction of CAR-HACKING DATASET is based on recording CAN (Controller Area Network) traffic from the OBD (On-Board Diagnostics) port of a real vehicle, which is used to perform message injection attacks.
[0014] S2: data preprocessing;
[0015] Adopt zero padding strategy, fill the shorter message data with zeros on the right side in CAN message data to make it equal to the longest message data, and ensure the consistent length of all message data; convert the message data from hexadecimal to decimal; when the network is attacked, use Min-Max normalization to convert the data linearly to the range of 0 to 1;
[0016] S3: partition the dataset;
[0017] The preprocessed CAN message data is divided into a training set and a test set in a ratio of 8:2;
[0018] S4: Build a Bi-LSTM neural network model and add an attention mechanism module;
[0019] S5: Input the processed data into the model, complete the model training and obtain the final model evaluation results.
[0020] Further, in S2, a zero padding strategy is adopted to ensure the consistency of the length of the CAN message data; the shorter message is padded with zeros on the right to be equal to the longest message; the message data is converted from hexadecimal to decimal; the hexadecimal value of the i-th byte is converted to a decimal value according to formula (1), where d m is the mth value of the data packet in decimal, and h is in hexadecimal;
[0021] Hexadecimal data "2F" is converted to decimal data 47: 2×16 1 +15×16 0 =47, where 15 is the hexadecimal value of F;
[0022] The entire process of CAN message data preprocessing and providing fixed input values for the classification algorithm;
[0023]
[0024] The decimal value range of each byte of CAN message data is 0 to 255. When the network is attacked, Min-Max normalization is used to linearly convert the data to the range of 0 to 1. From formula (2), we know that Data Normalization is the result after normalization.
[0025]
[0026] Further, in S4, the constructed Bi-LSTM neural network model includes five modules, namely, Input Layer, Bi-LSTM Layer, Attention Layer, Fully Connected Layer and Output Layer;
[0027] Input Layer: responsible for receiving raw data and converting it into a format that can be processed by the Bi-LSTM network;
[0028] Bi-LSTM Layer: Uses two layers of Bidirectional Long Short-Term Memory (Bi-LSTM) as the backbone network to extract CAN message data features;
[0029] Attention Layer: The attention mechanism is introduced to improve the model's ability to classify CAN message attacks, capture key information, adapt to different data lengths, and capture contextual relationships;
[0030] Dense Layer: For the data features extracted by Bi-LSTM, further combination and nonlinear transformation are performed to capture the complex relationships in the data; the output feature map is converted into a one-dimensional vector for category mapping;
[0031] Output Layer: predicts the probability of attack categories; each node in the output layer represents a category; after the softmax activation function, the value of the output node Indicates the model's predicted probability for each category; the confidence of the model for different categories is determined based on the probability.
[0032] Furthermore, in S4, the specific steps of training and optimizing the model include:
[0033] Use TensorFlow's API to divide the dataset into training and test sets;
[0034] Load a dataset containing input images and labels into the model for training;
[0035] Use callback function to save model weights at the time of highest validation accuracy and add early stopping function to prevent overfitting;
[0036] Use the saved model to evaluate the test set and calculate the accuracy, F1 value, and AUC indicators to evaluate the performance of the entire intrusion detection system.
[0037] Furthermore, in S4, the model is trained, specifically including: batch size is set to 32, epoch is set to 200, cross entropy is used as loss function, Adam is used as optimizer, and learning rate is set to 0.001; wherein the calculation formula of the loss function is as follows:
[0038]
[0039] Where N is the number of samples, y i ={0,1} is a binary label, and p(y) is the probability that the output belongs to the y label.
[0040] The beneficial effects of the present invention are as follows: Compared with the existing intrusion detection algorithms, the intrusion detection technology proposed by the present invention has, firstly, fewer model parameters, faster detection speed and higher efficiency. Secondly, compared with the traditional intrusion detection algorithm, the algorithm can effectively deal with sudden anomalies through learning. Finally, the algorithm introduces the attention mechanism based on Bi-LSTM, which effectively improves the performance and efficiency of the model, strengthens the processing of key information, reduces noise interference, and provides a certain degree of interpretability for the model, thereby improving the security of the vehicle network.
[0041] Other advantages, objectives and features of the present invention will be described in the following description to some extent, and to some extent, will be obvious to those skilled in the art based on the following examination and study, or can be taught from the practice of the present invention. The objectives and other advantages of the present invention can be realized and obtained through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention will be described in detail below in conjunction with the accompanying drawings, wherein:
[0043] Figure 1 It is the binary conversion process;
[0044] Figure 2 Data normalization process;
[0045] Figure 3 It is a neural network structure diagram;
[0046] Figure 4 Intrusion detection flow chart. DETAILED DESCRIPTION
[0047] The following describes the embodiments of the present invention by specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the illustrations provided in the following embodiments only illustrate the basic concept of the present invention in a schematic manner, and the following embodiments and features in the embodiments can be combined with each other without conflict.
[0048] Among them, the drawings are only used for illustrative explanations, and they only represent schematic diagrams rather than actual pictures, and should not be understood as limitations on the present invention. In order to better illustrate the embodiments of the present invention, some parts of the drawings may be omitted, enlarged or reduced, and do not represent the size of actual products. For those skilled in the art, it is understandable that some well-known structures and their descriptions in the drawings may be omitted.
[0049] The same or similar numbers in the drawings of the embodiments of the present invention correspond to the same or similar parts; in the description of the present invention, it should be understood that if the terms "upper", "lower", "left", "right", "front", "rear", etc. indicate the orientation or position relationship, they are based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operate in a specific orientation. Therefore, the terms describing the position relationship in the drawings are only used for illustrative purposes and cannot be understood as limiting the present invention. For ordinary technicians in this field, the specific meanings of the above terms can be understood according to specific circumstances.
[0050] See also Figure 1 to Figure 4 , an embodiment of the present invention provides a vehicle-mounted CAN bus intrusion detection solution based on deep learning, and the steps are as follows:
[0051] 1) The data in this article comes from the CAR-HACKING DATASET dataset released by HCEL (Host-Based Cybersecurity Resilience Laboratory). Table 1 is the original data of CAN messages.
[0052] Table 1
[0053]
[0054]
[0055] CAR-HACKINGDATASET contains normal message data (Normal), DoS attack (DosAttack), fuzzy attack (FuzzyAttack) and spoofing attack (SpoofingAttack). The dataset is constructed by recording CAN traffic through the OBD-port of a real vehicle when performing a message injection attack. Each dataset contains 300 message injection intrusions. Each intrusion lasts 3 to 5 seconds, and each dataset contains a total of 30 to 40 minutes of CAN traffic records.
[0056] 2) Using Python, first convert the data from hexadecimal to decimal, and then normalize the data.
[0057] (i) Due to the different information carried in CAN message data, it may contain different fields and data. Some messages may only need to transmit a small amount of data, so the length is shorter. Some messages may need to transmit more data, resulting in a longer length. Therefore, in the process of CAN message data preprocessing, all data packets need to be the same size. This article adopts a zero-padding strategy. For shorter message data, it is padded with zeros on the right to make it the same length as the longest message data. This can keep the length of all message data consistent. Next, in order to better process and analyze the data, the data packet data is converted from hexadecimal to decimal. Convert the hexadecimal value of the i-th byte to a decimal value according to formula (1), where d m is the mth value of the data packet in decimal format, and h is in hexadecimal format.
[0058] For example, the conversion of "2F": 2×16 1 +15×16 0 =47, where 15 is the hexadecimal value corresponding to F. Figure 1 The entire process of CAN message data preprocessing and providing fixed input values to the classification algorithm is shown.
[0059] (ii) CAN message data, each byte has a decimal value range of 0 to 255. When the network is attacked, some features take larger values. For example, when it is attacked by FuzzyAttack, additional data is carried in the data field. This deception attack may cause the data field to increase. Some features may take smaller values. For example, in a DoS attack, the CANID is modified. This kind of continuous data with large differences may cause gradient explosion and vanishing problems in the model during training. Therefore, in order to alleviate this problem, this paper uses Min-Max normalization (linear normalization) to linearly convert the data to between 0 and 1. As can be seen from formula (2), Data Normalization is the normalized result. The results are as follows Figure 2 shown.
[0060] 3) Dataset division. The preprocessed CAN data is randomly split into a training set and a test set in a ratio of 8:2.
[0061] 4) Use the tensorflow deep learning framework to build a deep learning model. The entire model consists of five modules. The first is InputLayer, which is mainly responsible for receiving raw data and converting it into a format that can be processed by the Bi-LSTM network. Figure 3 In the input layer, x j1 , x j2 , …x jn The first layer is the input data; followed by the Bi-LSTM Layer, which uses a two-layer bidirectional long short-term memory network (Bi-LSTM, Bidirectional Long Short-Term Memory) as the backbone network to extract the features of the CAN message data. Bi-LSTM is a neural network structure used for sequence data modeling. It combines two LSTMs in opposite directions to extract features and can capture the forward and backward context information in the sequence data. When processing CAN message data, Bi-LSTM can effectively capture the dependencies in the CAN message sequence for detecting attacks or anomalies. The specific structure of Bi-LSTM is as follows Figure 3 shown.
[0062] AttentionLayer, the self-attention mechanism looks for correlations in the sequence and summarizes the information weighted according to the degree of correlation, thereby enhancing the network's ability to process key information. In the invention, in the CAN bus communication intrusion detection system, the use of the self-attention mechanism can more accurately capture key information, adapt to different data lengths, capture contextual relationships, and improve the interpretability of the model. The attention mechanism layer is mainly composed of three parts: feature similarity calculation layer, softmax weight importance allocation layer and feature reconstruction layer. The feature similarity calculation layer mainly converts the output y of Bi-LSTM intot-1 ,y t and t+1 It is used as input to mine the correlation between known CAN message data and output the correlation coefficient r.
[0063]
[0064] Where activation is the activation function, and b are the parameters to be trained for the attention mechanism module. The weight importance distribution layer uses the softmax function to implement the attention scoring operation. Softmax converts the correlation coefficient of the output of the previous layer of the network into a weight, that is, the state signal weight matrix a t , and obtain the importance of each feature.
[0065]
[0066] Then, the input message data is weighted accordingly, and the weighted message data is used as the input of the fully connected layer for prediction;
[0067] Dense Layer: Further combine and nonlinearly transform the data features extracted by Bi-LSTM. Better capture the complex relationships in the data and improve the performance of the model. Convert the output feature map into a one-dimensional vector to map the class.
[0068] Output Layer: Its main function is to predict the probability of attack categories. Each node in the output layer represents a category. After the softmax activation function, the value of the output node Represents the model's predicted probability for each category. This allows us to judge the model's confidence in different categories based on the probability.
[0069] 5) In order to effectively verify and evaluate our proposed method, the CAR-HACKING DATASET dataset is used. The dataset contains four types: Normal Data, DoS Attack, Fuzzy Attack, and Spoofing Attack. 80% of each attack type is a training set and 20% is a test set. Server configuration information: 9700K CPU, 32GB RAM, and 3070TI graphics card. The deep learning framework is tensorflow2.5. Regarding parameter settings, relu is used in the Bi-LSTM Layer activation function, softmax is used in the Output Layer activation function, adam is used in the optimizer and the learning rate is initialized, and cross entropy is used in the loss function. The number of iterations is set to 100.
[0070] 6) Model testing. The dataset contains a total of 12,936,645 samples. After shuffling, the dataset is divided into a test set and a validation set in the ratio of 8:2. The dataset division can be done using the TensorFlow API method. The batch size is set to 32 during data training. The specific test steps are as follows: After training, the sklearn library method is used to evaluate the model performance using the test dataset to obtain the test loss and test accuracy.
[0071] In the above embodiment, a trained intrusion detection system is deployed on the gateway of the vehicle bus through traditional technology, and the data packets generated by the ECU in the CAN bus are collected and input into the intrusion detection system for detection. The intrusion detection system of this method is composed of a neural network detector. The process of the entire intrusion detection algorithm is as follows: Figure 4 shown.
[0072] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the purpose and scope of the technical solution, which should be included in the scope of the claims of the present invention.
Claims
1. An intrusion detection method for a vehicle-mounted CAN network, characterized in that: The method comprises the following steps: S1: Acquisition; The CAR-HACKING DATASET dataset released by HCEL is used. The dataset includes normal message data, DoS attack, fuzzy attack and spoofing attack information. The construction of CAR-HACKING DATASET is based on recording the Controller Area Network (CAN) traffic of the On-Board Diagnostics (OBD) port of a real vehicle, which is used to perform message injection attacks. S2: data preprocessing; Adopt zero padding strategy, fill the shorter message data with zeros on the right side in CAN message data to make it equal to the longest message data, and ensure the consistent length of all message data; convert the message data from hexadecimal to decimal; when the network is attacked, use Min-Max normalization to convert the data linearly to the range of 0 to 1; S3: partition the dataset; The preprocessed CAN message data is divided into a training set and a test set in a ratio of 8:2; S4: Build a Bi-LSTM neural network model and add an attention mechanism module; S5: Input the processed data into the model, complete the model training and obtain the final model evaluation results.
2. The intrusion detection method for a vehicle-mounted CAN network according to claim 1, characterized in that: In S2, a zero padding strategy is adopted to ensure the consistency of the length of the CAN message data; the shorter message is padded with zeros on the right to be equal to the longest message; the message data is converted from hexadecimal to decimal; the hexadecimal value of the i-th byte is converted to a decimal value according to formula (1), where d m is the mth value of the data packet in decimal, and h is in hexadecimal; "2F" is a hexadecimal data in the CAN message. To convert the hexadecimal data "2F" to decimal data 47, the formula is as follows: 2×16 1 +15×16 0 =47, where 15 is the hexadecimal value of F; The entire process of CAN message data preprocessing and providing fixed input values for the classification algorithm; The decimal value range of each byte of CAN message data is 0 to 255. When the network is attacked, Min-Max normalization is used to linearly convert the data to the range of 0 to 1. From formula (2), we know that Data Normalization is the result after normalization.
3. The intrusion detection method for a vehicle-mounted CAN network according to claim 2, characterized in that: In S4, the constructed Bi-LSTM neural network model includes five modules, namely, input layer, bidirectional long short-term memory network layer, Bi-LSTM layer, attention layer, fully connected layer, and output layer; Input Layer: responsible for receiving raw data and converting it into a format that can be processed by the Bi-LSTM network; Bi-LSTM Layer: Uses two layers of bidirectional long short-term memory (Bidirectional Long Short-Term Memory, Bi-LSTM) as the backbone network to extract CAN message data features; Attention Layer: The attention mechanism is introduced to improve the model's ability to classify CAN message attacks, capture key information, adapt to different data lengths, and capture contextual relationships; Dense Layer: For the data features extracted by Bi-LSTM, further combination and nonlinear transformation are performed to capture the complex relationships in the data; the output feature map is converted into a one-dimensional vector for category mapping; Output Layer: predicts the probability of attack categories; each node in the output layer represents a category; after the softmax activation function, the value of the output node Indicates the model's predicted probability for each category; the confidence of the model for different categories is determined based on the probability.
4. The intrusion detection method for a vehicle-mounted CAN network according to claim 3, characterized in that: In S4, the specific steps of training and optimizing the model include: Use TensorFlow's API to divide the dataset into training and test sets; Load a dataset containing input images and labels into the model for training; Use callback function to save model weights at the time of highest validation accuracy and add early stopping function to prevent overfitting; Use the saved model to evaluate the test set and calculate the accuracy, F1 value, and AUC indicators to evaluate the performance of the entire intrusion detection system.
5. The intrusion detection method for a vehicle-mounted CAN network according to claim 4, characterized in that: In S4, the model is trained, specifically including: batchsize is set to 32, epoch is set to 200, cross entropy is used as loss function, Adam is used as optimizer, and learning rate is set to 0.001; wherein the calculation formula of the loss function is as follows: Where N is the number of samples, y i ={0,1} is a binary label, and p(y) is the probability that the output belongs to the y label.
Citation Information
Patent Citations
CAN-FD anomaly detection method based on time sequence content attention and long and short term memory network
CN117176421A
Internet of vehicles CAN bus intrusion detection method based on spatial-temporal characteristics
CN117478410A
Intrusion detection method for vehicle-mounted LIN (Local Interconnect Network)
CN117479169A
Internet of vehicles intrusion detection method and system based on attention CNN-BiLSTM algorithm
CN117955704A
Cited By
Method and device for evaluating influence of network attack on vehicle network layer CAN bus
CN119996064A
A method and device for assessing the impact of network attacks on the CAN bus of a vehicle's network layer.
CN119996064B
CAN intrusion detection method based on signal relation graph Transform
CN120567578A
