A can-fd anomaly detection method based on real physical meaning

CN117278306BActive Publication Date: 2026-08-18JILIN UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311333860.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-16
Publication Date
2026-08-18
Estimated Expiration
2043-10-16

AI Technical Summary

Technical Problem

现有的异常检测系统大多基于报文的统计特征,往往没有考虑到报文数据字段携带的真实物理含义

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117278306B_ABST
    Figure CN117278306B_ABST
Patent Text Reader

Abstract

The application is suitable for the field of automatic driving of automobiles, and provides a CAN-FD anomaly detection method based on real physical meaning, which is used for detecting whether the timing sequence change of real physical meaning in the CAN-FD data field is abnormal in the process of vehicle operation, so as to identify the malicious traffic possibly existing in the CAN-FD network. The timing sequence correlation characteristics of the real physical meaning in the CAN-FD data field can be fully utilized, the understanding ability of the model to the input features is improved by respectively performing one-hot encoding and minimum-maximum scaling processing on each input feature, the capturing ability of the model to the time sequence features is enhanced by combining and enhancing the multi-layer features of the self-attention, the abnormal traffic in the CAN-FD network can be accurately identified, and the safety of the vehicle-mounted CAN-FD network is effectively ensured. The understanding ability of the model to the input features is improved, the capturing ability of the model to the time sequence features is enhanced by combining and enhancing the multi-layer features of the self-attention, and the accuracy of the anomaly detection system is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of autonomous driving technology, and in particular relates to a CAN-FD anomaly detection method based on real physical meaning. Background Technology

[0002] With the rapid development of automotive electronics technology, the level of intelligence and automation in automobiles is constantly improving. The in-vehicle network (IVN) undertakes the communication task between the vehicle's internal subsystems and the external environment, and is crucial for data exchange and intelligent decision-making. As the core of the IVN, the CAN bus allows real-time communication between different electronic control units within the vehicle, enabling various systems to send and receive data, thereby achieving information exchange and sharing within the vehicle. As the complexity of automotive electronic systems continues to increase, the traditional CAN bus protocol faces limitations in bandwidth and transmission rate. Based on CAN, CAN-FD was developed. CAN-FD improves the transmission rate by extending data fields, making it more suitable for applications requiring the transmission of large amounts of data. However, CAN-FD lacked robust security mechanisms in its initial design, making it vulnerable to malicious attacks. Various potential abnormal traffic flows may exist in the CAN-FD network, which could seriously affect vehicle driving safety. Attackers can remotely control vehicle functions such as braking, acceleration, and steering by forging CAN-FD messages; simultaneously, they may send a large number of invalid or malicious CAN-FD messages to the CAN bus, causing CAN bus congestion and affecting communication between various subsystems within the vehicle.

[0003] Common attack methods targeting CAN-FD include denial-of-service (DoS) attacks, obfuscation attacks, replay attacks, and spoofing attacks. DoS attacks on CAN-FD can overload the CAN bus by sending a large number of invalid, false, or duplicate messages, causing other ECUs in the vehicle to be unable to process legitimate messages properly. Attackers can use DoS attacks to interfere with, block, or paralyze the CAN bus, causing the vehicle to malfunction or fail to perform its critical functions. Obfuscation attacks trigger potential vulnerabilities and anomalies in the vehicle system by sending a large number of abnormal or random CAN-FD messages, potentially causing the vehicle system to crash. Replay attacks on CAN-FD intercept legitimate CAN-FD messages and resend them to the CAN bus to perform malicious operations or interfere with the normal functions of the vehicle, potentially causing the vehicle system to perform repetitive or inappropriate operations. Spoofing attacks on CAN-FD send forged CAN-FD messages to perform malicious operations or interfere with the normal functions of the vehicle, potentially causing the vehicle to lose control, perform unexpected operations, or cause chaos inside the vehicle.

[0004] Anomaly detection systems for vehicular networks are security mechanisms designed to monitor and detect abnormal behavior and potential threats within the vehicle's internal network. These systems analyze data traffic and messages within the vehicle's internal network, extracting key features from vehicle communication and building models based on historical data and normal behavior to help distinguish between normal communication patterns and malicious traffic. Most existing anomaly detection systems rely on statistical characteristics of messages, often neglecting the true physical meaning carried by message data fields. The true physical meaning of CAN-FD message data fields is crucial for vehicle control and operation. Understanding this true physical meaning helps anomaly detection systems more accurately identify potential malicious traffic in the CAN-FD network, enabling earlier detection of abnormal changes in key vehicle physical parameters, thereby ensuring the safety and stability of vehicle operation. Summary of the Invention

[0005] The purpose of this invention is to provide a CAN-FD anomaly detection method based on real physical meaning, aiming to solve the problems mentioned in the background art.

[0006] The present invention is implemented as follows: a CAN-FD anomaly detection method based on real physical meaning includes the following steps:

[0007] Step 1: Temporal Feature Extraction Based on Real Physical Meaning: First, collect attack-free original CAN-FD datasets from real vehicles and divide the data in the original dataset into training and test sets. Then, perform data augmentation processing on the training set by adjusting the window sliding step size and shuffling the sequence order. Insert attack packets into the test set to simulate DoS, obfuscation, replay, and spoofing attacks to generate an attack dataset. Extract the real physical meaning of the packet data fields according to the different CAN-FD ID physical meaning division rules. Preprocess the physical meaning features of each CAN-FD ID to maintain the integrity of the dataset. At the same time, reorder and combine the features of different CAN-FD IDs based on the number of data types to enhance the model's recognition of important features. Perform one-hot encoding and min-max scaling on each input feature to improve the model's understanding of input features.

[0008] Step 2: Anomaly Detection Based on Long Short-Term Memory Network with Self-Attention Mechanism: First, build a Long Short-Term Memory network model with self-attention mechanism; obtain the input features and expected output of the training set and the input features and actual output of the attack dataset according to the set sliding window and output sequence size; train the Long Short-Term Memory network model with self-attention mechanism using the input features and expected output of the training set; validate the trained anomaly detection model using the input features and actual output of the attack dataset, and evaluate the model's performance using metrics such as True Positive (TP), False Positive (FP), True Negative (TN), False Negative (FN), Accuracy, Precision, Recall, and F1 Score.

[0009] In a further technical solution, step 1 includes the following specific steps:

[0010] Step 1.1, Data Acquisition and Partitioning: A raw, attack-free dataset was collected from a real vehicle. All CAN-FD messages on the vehicle's CAN bus within a specific time period were collected, recording information including the CAN-FD message timestamp, CAN-FD ID, data fields, and their lengths. The collected raw CAN-FD dataset was divided into a training set and a test set. The training set serves as input for the next step of training data augmentation, while the test set serves as input for generating the attack dataset.

[0011] Step 1.2, Training Set Data Augmentation: The training set was augmented by adjusting the window sliding step size and shuffling the sequence order, which further enriched the data in the training set.

[0012] Step 1.3, Attack Dataset Generation: Classification labels were added to the test set, and the original packets in the test set were labeled as m. Ben DoS, obfuscation, replay, and spoofing attack packets are inserted into the test set and marked as m respectively. DoS m Fuz m Rep With m Spo This allows for the generation of the attack dataset.

[0013] Step 1.4, Data Preprocessing: By querying the data field partitioning methods corresponding to different CAN-FD IDs to understand their true physical meanings, data segments with different physical meanings are extracted and transformed into feature values ​​corresponding to their true physical meanings. Simultaneously, the physical meaning features of the data field partitions are completed and aligned. Unfilled portions of the physical meaning features are marked as "-1" to maintain dataset integrity. Furthermore, different CAN-FD ID features are reordered and combined according to the number of feature types. One-hot encoding and min-max scaling are performed on different features to enhance the model's understanding of the input features.

[0014] In a further technical solution, step 2 includes the following specific steps:

[0015] Step 2.1, Network Model Construction: A machine learning model containing a Long Short-Term Memory (LSTM) layer, a self-attention layer, and a fully connected (Dense) layer was constructed. The LSTM layer is used to capture the temporal dependencies in the input sequence. The self-attention layer assigns different weights to each time step according to the context information in the sequence to better understand the global relationships in the sequence. The fully connected layer is used to generate the final prediction result.

[0016] Step 2.2, Model Training: Based on the set sliding window and output sequence size, obtain the input features and expected output of the training set, and use them as the input of the model. Train the model by setting reasonable hyperparameters such as learning rate, number of rounds, and batch size.

[0017] Step 2.3, Model Validation and Performance Evaluation: The trained model is validated using the input features of the attack dataset and the actual output. TP, FP, TN, FN, Accuracy, Precision, Recall, and F1 Score are used as metrics to evaluate model performance.

[0018] This invention provides a CAN-FD anomaly detection method based on real physical meaning. This method is used to detect in real-time anomalies in the temporal changes of the real physical meaning in CAN-FD data fields during vehicle operation, thereby identifying potentially malicious traffic in the CAN-FD network. This method fully utilizes the temporal correlation features of the real physical meaning in CAN-FD data fields. By performing one-hot encoding and min-max scaling on each input feature, it improves the model's understanding of input features. The multi-layer feature combination with self-attention enhances the model's ability to capture time-series features, enabling accurate identification of abnormal traffic in the CAN-FD network and effectively ensuring the security of the vehicle-mounted CAN-FD network. It can effectively detect abnormal packets on real-vehicle CAN-FD attack test datasets, is easy to apply and deploy in practice, and has good application prospects in the field of intelligent connected vehicles. The method improves the model's understanding of input features by performing one-hot encoding and min-max scaling on each input feature based on the number of data types. The multi-layer feature combination with self-attention enhances the model's ability to capture time-series features, effectively improving the accuracy of the anomaly detection system. Experimental results show that the method disclosed in this invention achieves an accuracy of 99.52% on real vehicle datasets and an F1 score as high as 0.9971, effectively identifying four common attack packets: DoS, fuzzy attack, replay attack, and spoofing attack. Attached Figure Description

[0019] Figure 1 A flowchart of a CAN-FD anomaly detection method based on real physical meaning provided in an embodiment of the present invention;

[0020] Figure 2 Inject a scene graph into the attack message;

[0021] Figure 3 This is a diagram of the architecture of an LSTM network model incorporating a self-attention mechanism. Detailed Implementation

[0022] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0023] The specific implementation of the present invention will be described in detail below with reference to specific embodiments.

[0024] like Figure 1 As shown, an embodiment of the present invention provides a CAN-FD anomaly detection method based on real physical meaning, comprising the following steps:

[0025] Step 1: Temporal Feature Extraction Based on Real Physical Meaning: First, collect the original, attack-free CAN-FD dataset from real vehicles and divide it into training and test sets. Then, perform data augmentation on the training set by adjusting the window sliding step and shuffling the sequence order. Insert attack packets into the test set to simulate DoS, obfuscation, replay, and spoofing attacks to generate an attack dataset. Extract the real physical meaning of the packet data fields according to the different CAN-FD ID physical meaning division rules. Preprocess the physical meaning features of each CAN-FD ID to maintain the integrity of the dataset. At the same time, reorder and combine the features of different CAN-FD IDs based on the number of data types to enhance the model's recognition of important features. Perform one-hot encoding and min-max scaling on each input feature to improve the model's understanding of input features.

[0026] Step 2: Anomaly Detection Based on Long Short-Term Memory Network with Self-Attention Mechanism: First, a long short-term memory network model with self-attention mechanism is built; according to the set sliding window and output sequence size, the input features and expected output of the training set and the input features and actual output of the attack dataset are obtained. The long short-term memory network model with self-attention mechanism is trained using the input features and expected output of the training set; the trained anomaly detection model is validated using the input features and actual output of the attack dataset, and the model performance is evaluated using metrics such as true positives, false positives, true negatives, false negatives, accuracy, precision, recall, and F1 score.

[0027] In a preferred embodiment of the present invention, step 1 includes the following specific steps:

[0028] Step 1.1, Data Acquisition and Division: Divide the acquired raw CAN-FD dataset... The data in the dataset is divided into training sets. The remaining data is assigned to the test set. m represents a message instance, m s With m t These represent message instances in the training and test sets, respectively. origin n represents the total number of messages in the original dataset. s With n t These represent the total number of packets in the training set and the test set, respectively. Training set As input for training set data augmentation, the test set As input for generating the attack dataset.

[0029] Step 1.2, Training Set Data Augmentation: To further enrich the data in the training set, data augmentation was performed. This was done by adjusting the window sliding step and shuffling the sequence order. This helps the model better learn the correlations between data points and prevents the model from over-relying on the sequence order. The training set is then fed a message sequence as input. The sliding window size is u, the sliding step size is z, and the output message sequence is... If the size is v, then:

[0030]

[0031]

[0032]

[0033] in and They are and The corresponding input and output sequences, where ceil is the floor function, satisfy the following conditions:

[0034]

[0035]

[0036] By using different step sizes z i (i∈[1,2,...,N) step ], N step The total step size is used to control the sliding interval of the window, thereby creating more input sequences on the original data. and target output sequence

[0037]

[0038]

[0039] Simultaneously, by shuffling the order of the input sequence and the target output sequence, the i-th time (i∈[1,2,...,N) shuffle ], N shuffle To obtain the shuffled input message sequence (to shuffle the total number of times). With output message sequence It can be represented as:

[0040]

[0041] function f shuffle Shuffle in a random but identical order To ensure and The elements between them still maintain a one-to-one correspondence. The generated data is then concatenated to obtain the input sequence after data augmentation. With output sequence

[0042]

[0043]

[0044] Step 1.3, Attack Dataset Generation: DoS attacks targeting the CAN bus overload the CAN bus by sending a large number of invalid, false, or duplicate messages, causing other ECUs in the vehicle to be unable to process legitimate messages properly, such as... Figure 2 As shown in (a). Attackers can use DoS attacks to interfere with, block, or paralyze the CAN bus, thereby causing the vehicle to malfunction or fail to perform its critical functions.

[0045] Obfuscated attacks targeting automotive CAN-FD networks trigger potential vulnerabilities and anomalies in the vehicle system by sending a large number of anomalous or random CAN-FD messages. Figure 2 (b) shows this. This may cause the vehicle's ECU to behave abnormally, such as system crashes, error handling, or denial of service.

[0046] Replay attacks targeting CAN-FD networks intercept legitimate CAN-FD messages and resend them to the CAN bus to perform malicious operations or interfere with the normal functions of the vehicle, such as... Figure 2 As shown in (d). This could cause the vehicle system to perform repetitive or inappropriate operations, or even have a serious impact on vehicle safety.

[0047] Spoofing attacks targeting the CAN bus perform malicious operations or interfere with the normal functions of a vehicle by sending forged CAN messages. Attackers simulate legitimate ECU communication by forging CAN-FD messages, thereby deceiving other ECUs or vehicle control systems, such as... Figure 2 (c) shows this. This can cause the vehicle to lose control, perform unexpected actions, or cause chaos inside the vehicle.

[0048] This study simulates scenarios where attackers launch DoS, obfuscation, replay, and spoofing attacks against CAN-FD networks by generating attack datasets. Required initialization parameters include the test set. The total number of data segments N selected attack The number of messages n contained in each data segment attack Range of inserted data frames and attack message m attackTo determine the insertion point of the attack packet, the algorithm initially uses the training set... Randomly select non-overlapping data segments Then, k is randomly inserted after each frame of these data segments. attack Frame attack message m attack k attack for The attack dataset can be obtained by generating random numbers between the given values. It is worth noting that when simulating different types of attacks, there are N attack n attack , With m attack All parameters can be adjusted according to the characteristics of the attack. This invention specifies that when simulating a DoS attack, m attack For messages with an ID field of 0x00 and all data fields set to zero; when performing a fuzzy attack, m attack A message with a CAN ID between 0x000 and 0x7FF and a random data field; m in a replay attack attack The message is identical to the preceding frame at its insertion position; the generation of the spoofing attack message requires selecting a message with a specific CAN ID from the test set, selecting a physical feature x from this type of message, and setting the starting bit of x in the message to b. start The termination bit is b end In m attack Before the insertion position, find the nearest normal message m with the same ID. Ben Change m Ben of Within the data range, in order to make the generated attack packets as realistic as possible in simulating the scenario of an attacker conducting a deception attack, the modified feature value x should be... Spo Compared with the original normal characteristic value x Ben There are some differences, therefore the following is stipulated:

[0049]

[0050] Step 1.4, Data Preprocessing: The data in the training set underwent real physical meaning feature extraction and normalization. Required initialization parameters include the training set... Rule base for extracting the true physical meaning features of different ID messages Filling feature f fill and the maximum number of features with true physical meaning n max Based on the corresponding ID and extraction rules For the training set Extract the true physical meaning feature F from each frame of the message, maintaining the integrity of the dataset. If the number of extracted features is less than n... max Then use f fillAdd the eigenvalues ​​of F to n. max The extracted features are rearranged in descending order based on the number of data categories for each feature of each ID. This significantly reduces dimensionality inflation caused by subsequent selective one-hot encoding, and the rearranged features are also normalized. Finally, feature values ​​of features with unchanged values ​​are merged, enabling the model to better capture the variation patterns of other important features and reduce the risk of overfitting.

[0051] To normalize the features, a min-max scaling method was applied. That is, for each class of feature X, its minimum value X was calculated. min and maximum value X max The eigenvalues ​​x in X are mapped to x using the following formula. nor :

[0052]

[0053] The features used include the ID of each message and its actual physical meaning, and the number of variable types does not exceed n. encode The features were one-hot encoded, which effectively avoids the influence of weight bias and distance metrics. Meanwhile, for variables with more than n types... encose The characteristics of the model are preserved, and its physical numerical relationships are retained to enhance the model's understanding of its true physical meaning.

[0054] It is worth noting that, for For messages without a corresponding ID extraction rule, their characteristics will be represented by f. fill =-1 padding. For the test set When performing feature rearrangement, the order of feature rearrangement for each ID and the minimum value X of each feature X during normalization. min and maximum value X max With training set Maintain consistency.

[0055] In a preferred embodiment of the present invention, step 2 includes the following specific steps:

[0056] Step 2.1, Network Model Construction: A machine learning model containing LSTM layers, self-attention layers, and fully connected (Dense) layers was built for time series prediction. The model architecture is as follows: Figure 3 As shown. For all the features learned by the model x represents the i-th type of feature extracted from the message. ji (j∈{1,2,...,n) S}) represents a feature value extracted from the j-th frame of the message in the training set, and n S Let X be the total number of training samples, therefore for X s have:

[0057]

[0058] Input layer:

[0059] X input =(X input,1 X input,2 , ..., X input,l ) T (14)

[0060] X output =(X output,1 X output,2 , ..., X output,l ) T (15)

[0061] Where X input,i X output,i (i∈{1, 2, ..., l}) are X input With X output A pair of corresponding elements in the input X input,i When the expected output is X output,i For X input,i With X output,i have:

[0062]

[0063]

[0064] LSTM Layer 1: Input sequence X input First, it passes through an LSTM layer with 512 hidden units, using the tanh activation function, and its output X... LSTM1,output The shape is (None, u, 512), and 'dropout' is applied to randomly set a portion of the LSTM's input and hidden states to zero with a probability of 0.2, thereby reducing the model's dependence on specific inputs and preventing overfitting.

[0065] LSTM 2nd layer: The input to this layer is X LSTM1,outtput It has 256 hidden units and its output X LSTM2,output The shape is (None, u, 256), and the activation function and 'dropout' settings are the same as those of LSTM layer 1.

[0066] SelfAttention Layer 1: The input to this layer is X. LSTM1,output It has 128 hidden units and its output X SA1 The shape is (None, u, 128).

[0067] SelfAttention 2nd layer: The input to this layer is X LSTM2,output It has 128 hidden units and its output X SA2 The shape is (None, u, 128).

[0068] Add layer: The input to this layer is X. SA1 With X SA2 By combining the output features of the self-attention layer, the model can better capture the important features of the input data, and its output X add The shape is (None, u, 128).

[0069] LSTM 3 layers: The input to this layer is X add It has 64 hidden units and its output X LSTM3,output The shape is (None, u, 64), and the activation function and 'dropout' settings are the same as those of LSTM layer 1.

[0070] Output layer: This layer is a fully connected layer with one neuron, whose output Y output The shape is (None, u, 1).

[0071] Step 2.2: Obtain the training set input features and expected output based on the set sliding window and output sequence size. Use these as the model input and train the model by setting reasonable hyperparameters such as learning rate, number of epochs, and batch size. This invention extracts the corresponding input features and expected output from the preprocessed training set. 'Adam' is selected as the optimizer, with the training epochs set to 100, batch size to 32, and learning rate to 1×10⁻⁶. -3 The Mean Squared Error (MSE) is chosen as the loss function, and its mathematical expression is as follows:

[0072]

[0073] Where N is the number of samples, y ture,i Let y be the true value of the i-th sample. predict,i This is the predicted value for the i-th sample. After completing 100 training rounds, save the trained model.

[0074] Step 2.3, Model Validation and Performance Evaluation: This step validates the trained model using the input features of the attack dataset and the actual output. TP, FP, TN, FN, Accuracy, Precision, Recall, and F1 Score are used as performance metrics. The trained model is loaded, and predictions are made for each element of the input features in the attack dataset. The mean squared error (MSE) loss is calculated for each prediction based on the predicted value and its corresponding actual output. A MSE threshold θ is set. If the MSE loss is less than θ, the prediction result meets expectations, and the message is considered normal. If the MSE loss exceeds θ, the prediction result does not meet expectations, and the message is abnormal. The TP, FP, TN, and FN metrics are obtained by comparing the model's prediction results with the actual labels of the messages.

[0075] TP: Represents true positives, which is the number of positive cases that the model correctly predicts as positive.

[0076] FP: represents false positives, which is the number of negative examples that the model incorrectly predicts as positive examples.

[0077] TN: Represents a true negative example, meaning the model correctly represents the true negative example. The number of negative examples predicted as negative.

[0078] FN: represents false negatives, that is, the number of positive examples that the model incorrectly predicts as negative examples.

[0079] Accuracy: Represents the proportion of samples correctly predicted by the model out of the total number of samples. The higher the accuracy, the better the model performance. The calculation formula is:

[0080]

[0081] Precision: Represents the proportion of samples correctly predicted as positive by the model out of all samples predicted as positive. High precision indicates high accuracy of the model in predicting positive examples. The calculation formula is:

[0082]

[0083] Recall: Represents the proportion of actual positive examples that the model correctly predicts as positive. A high recall rate indicates that the model has a strong ability to identify positive examples. The calculation formula is:

[0084]

[0085] F1 Score: A metric that comprehensively considers precision and recall. The F1 score combines precision and recall to provide a more holistic evaluation of model performance. The calculation formula is as follows:

[0086]

[0087] The above formulas can be used to calculate evaluation metrics such as Accuracy, Precision, Recall, and F1 Score, thereby enabling the analysis of the performance of the anomaly detection model.

[0088] As a preferred embodiment of the present invention, the above method was simulated and verified. Python PyCharm IDE 2023.1.2 and Keras were used, with TensorFlow as the backend. The experiment was conducted using an AMD Ryzen 7925HX with Radeon Graphics CPU 2.50GHz, 16GB RAM, Windows 11 (64-bit), and an NVIDIA GeForce GTX 4060 Laptop GPU. A raw, attack-free CAN-FD dataset was collected from a real vehicle, capturing all CAN-FD messages on the vehicle's CAN bus within a specific time period. Recorded information included the timestamp, CAN-FD ID, data fields, and their length. The original dataset was in hexadecimal format and contained 84,956 frames. 80% of the collected raw CAN-FD dataset was allocated to the training set, and the remaining 20% ​​to the test set. The training set contained 67,964 frames, and the test set contained 16,992 frames. Data augmentation of the training set was performed by using different sliding window step sizes z = [1, 2, 3] and shuffling the data twice.

[0089] A Python program sequentially performed four attacks on the test set: Denial-of-Service (DoS) attacks, obfuscation, replay attacks, and spoofing attacks. Newly added abnormal packets were marked according to the attack type to generate an attack dataset. To simulate a DoS attack, six data segments containing 100 frames each were randomly selected from the original test set. Within each segment, 0-6 packets with an ID field of 0x00 were randomly inserted after each frame. To simulate an obfuscation attack, six data segments containing 100 frames each were randomly selected from the original test set. Within each segment, 0-3 packets with CAN-FD IDs between 0x000 and 0x7FF and random data fields were randomly inserted after each frame. To simulate an obfuscation attack, five data segments containing 120 frames each were randomly selected from the original test set. Within each segment, 0-2 identical packets were randomly inserted after each frame. To simulate a replay attack, five data segments containing 120 frames each were randomly selected from the original test set. Five data segments containing 120 frames of messages were randomly selected from the original test set. 0-2 frames of spoofing attack messages were randomly inserted after each frame in each segment. The spoofing attack messages inserted into these five data segments were constructed as follows: Bits [20, 36] of the normal message data field with CAN-FD ID 0x10 were modified, corresponding to the motor feedback torque; bits [24, 32] of the normal message data field with CAN-FD ID 0x142 were modified, corresponding to the front wheel braking system pressure; bits [32, 40] of the normal message data field with CAN-FD ID 0x60 were modified, corresponding to the controller temperature; bits [1, 16] of the normal message data field with CAN-FD ID 0x304 were modified, corresponding to the vehicle speed; and bits [48, 56] of the normal message data field with CAN-FD ID 0x18F were modified, corresponding to the EPS. ECU temperature; this is used to simulate a scenario where an attacker launches a deception attack.

[0090] Among the newly added category labels in the dataset, m Ben The normal message, m DoS This indicates a denial-of-service attack message, m Fuz Indicates an obfuscated attack message, m Bep Indicates replaying the attack message, m SpoThis represents spoofing attack packets. The generated CAN-FD attack dataset contains 20,928 packets, including 1,789 denial-of-service attack packets, 837 obfuscated attack packets, 571 replay attack packets, and 607 spoofing attack packets. As shown in Table 1, the generated attack dataset contains 81.71% normal packets, 8.60% denial-of-service attack packets, 4.02% obfuscated attack packets, 2.75% replay attack packets, and 2.92% spoofing attack packets.

[0091] Table 1. Packet types and percentages in the attack dataset.

[0092]

[0093]

[0094] This invention extracts data segments with different physical meanings by querying the data fields corresponding to different CAN-FD IDs and dividing them into feature values ​​with corresponding physical meanings. The original CAN-FD ID dataset includes CAN-FD IDs 0x10, 0x142, 0x60, 0x304, and 0x18f. Specifically, the data fields of a message with CAN-FD ID 0x10 represent the physical quantities related to the torque feedback of the MCU; the data fields of a message with CAN ID 0x142 represent the physical quantities related to the DBS state; the data fields of a message with CAN-FD ID 0x60 represent the physical quantities related to the MCU drive motor feedback; the data fields of a message with CAN-FD ID 0x304 represent the physical quantities related to VCU vehicle state 2; and the data fields of a message with CAN-FD ID 0x18f represent the physical quantities related to the EPS state. Extract all data segments containing real physical meaning from the data fields, convert the values ​​in these data segments to decimal, and classify these feature values ​​according to Table 2, then fill them into the corresponding feature labels in sequence.

[0095] Table 2. The True Physical Meaning of Different CAN-FD ID Data Fields

[0096]

[0097]

[0098] Set the input sequence X input The sliding window size u = 4, and the output sequence X outputThe size v = i is used to extract the corresponding input features and expected output from the preprocessed training set, completing the training of the Long Short-Term Memory (LSTM) network model incorporating the attention mechanism. The trained model is validated using the input features and actual output of the attack dataset. The model's TP, FP, TN, FN, Accuracy, Precision, Recall, and F1 Score are shown in Table 3. The highest F1 score (0.9971) is achieved when the threshold θ = 0.205. At this threshold, the accuracy is 99.52%, the precision is 99.43%, and the recall is 99.98%.

[0099] Table 3 Performance evaluation metrics of the CAN-FD anomaly detection model based on real physical meaning

[0100]

[0101] The accuracy of the anomaly detection model in identifying various types of attacks is shown in Table 4:

[0102] Table 4 shows the accuracy of attack identification for various types of attacks.

[0103]

[0104] Experimental results show that the CAN-FD anomaly detection method based on real physical meaning proposed in this invention can effectively identify four common attack messages, namely DoS, fuzzy, replay and spoofing, on real vehicle datasets.

[0105] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A CAN-FD anomaly detection method based on real physical meaning, characterized in that, Includes the following steps: Step 1: Temporal Feature Extraction Based on Real Physical Meaning: First, collect the original, attack-free CAN-FD dataset from real vehicles and divide it into training and test sets. Then, perform data augmentation on the training set by adjusting the window sliding step and shuffling the sequence order. Insert attack packets into the test set to simulate DoS, obfuscation, replay, and spoofing attacks to generate an attack dataset. Extract the real physical meaning of the packet data fields according to the different CAN-FD ID physical meaning division rules. Preprocess the physical meaning features of each CAN-FD ID to maintain the integrity of the dataset. At the same time, reorder and combine the features of different CAN-FD IDs based on the number of data types to enhance the model's recognition of important features. Perform one-hot encoding and min-max scaling on each input feature. Step 2: Anomaly Detection Based on Long Short-Term Memory Network with Self-Attention Mechanism: First, build a long short-term memory network model with self-attention mechanism; obtain the input features and expected output of the training set and the input features and actual output of the attack dataset according to the set sliding window and output sequence size; train the long short-term memory network model with self-attention mechanism using the input features and expected output of the training set; validate the trained anomaly detection model using the input features and actual output of the attack dataset, and evaluate the model performance using true positives, false positives, true negatives, false negatives, accuracy, precision, recall, and F1 score; In step 1, the extracted features are rearranged in descending order according to the number of data categories for each feature of each ID, and the rearranged features are normalized. Finally, feature values ​​of features with unchanged values ​​were merged; to normalize the features, min-max scaling was applied; the features used included the IDs of each message and their true physical meaning features, and the number of variable types did not exceed [a certain limit]. The features were one-hot encoded; meanwhile, for variables with more than [number of types], [the following was also performed]. The characteristics of the model are preserved, and its physical numerical relationships are retained to enhance the model's understanding of its true physical meaning. In step 2, the model includes: LSTM 1 layer: input sequence First, it passes through an LSTM layer with 512 hidden units, using the tanh activation function, and its output... The shape is ,in The size of the sliding window is given, and dropout is applied to randomly set a portion of the LSTM's input and hidden states to zero with a probability of 0.

2. LSTM 2nd layer: The input to this layer is It has 256 hidden units and its output The shape is The activation function and dropout settings are the same as those for LSTM layer 1; SelfAttention Layer 1: The input to this layer is... It has 128 hidden units and its output The shape is ; SelfAttention 2nd layer: The input to this layer is It has 128 hidden units and its output The shape is ; Add layer: The input for this layer is... and The output features of the self-attention layer are combined, and its output... The shape is ; LSTM 3 layers: The input to this layer is It has 64 hidden units and its output The shape is The activation function and dropout settings are the same as those for LSTM layer 1; Output layer: This layer is a fully connected layer with one neuron, whose output... The shape is .

2. The CAN-FD anomaly detection method based on real physical meaning according to claim 1, characterized in that, Step 1 includes the following specific steps: Step 1.1, Data Acquisition and Division: Divide the acquired raw CAN-FD dataset... The data in the dataset is divided into training sets. The remaining data is assigned to the test set. , This represents a message instance. and These represent message instances in the training and test sets, respectively. This represents the total number of messages in the original dataset. and These represent the total number of packets in the training set and the test set, respectively; the training set... As input for training set data augmentation, the test set As input for generating the attack dataset; Step 1.2, Training Set Data Augmentation: Data augmentation of the training set is performed by adjusting the window sliding step size and shuffling the sequence order; the training set is then fed with the message sequence. The size of the sliding window is The sliding step size is Output message sequence The size is Then we have: (1); (2); (3); in, and They are and The corresponding input and output sequences in the sequence are... , For floor functions, they satisfy: (4); (5); By using different step sizes To control the sliding interval of the window, where , This is the total step size, thus creating more input sequences on the original data. and target output sequence : (6); (7); At the same time, by shuffling the order of the input sequence and the target output sequence, To shuffle the total number of times, the first The input message sequence was then shuffled. With output message sequence It is represented as follows, where : (8); function Shuffle in a random but identical order , To ensure and The elements maintain a one-to-one correspondence, and the generated data is concatenated to obtain the input sequence after data augmentation. With output sequence : (9); (10); Step 1.3, Attack Dataset Generation: Required initialization parameters include the test set. Total number of data segments selected The number of messages contained in each data segment Range of inserted data frames and attack messages To determine the insertion position of the attack packet, the algorithm initially uses the training set... Randomly select non-overlapping data segments , Then, randomly insert... Frame attack message , for The attack dataset can be obtained by generating random numbers between the given values. It also stipulates that during simulated DoS attacks, For messages with an ID field of 0x00 and all data fields set to zero; when performing a fuzzy attack, A message with a CANID between 0x000 and 0x7FF and a random data field; used in replay attacks. The message is identical to the preceding frame at its insertion position; the generation of a spoofing attack message requires selecting a message with a specific CAN ID from the test set and choosing a physical characteristic from that type of message. ,make The start bit in the message is The terminating bit is ;exist Before the insertion position, find the nearest normal message with the same ID. ,Change of Within the data range, in order to make the generated attack packets realistically simulate the scenario of an attacker conducting a deception attack, the modified feature values... Compared with the original normal characteristic value There are differences, therefore the following is stipulated: (11) ; Step 1.4, Data Preprocessing: Required initialization parameters include the training set. Rule base for extracting the true physical meaning features of messages with different IDs Filling features and the maximum number of features with true physical meaning Based on the corresponding ID and extraction rules For the training set Extracting the true physical meaning features of each frame of the message To maintain the integrity of the dataset, if the number of extracted features is less than... Then utilize Will Feature numbers supplemented For each type of feature Calculate its minimum value and maximum value The following formula will be used to... eigenvalues ​​in Mapped to : (12); for For messages without a corresponding ID extraction rule, their characteristics will be used... Fill; for the test set When performing feature rearrangement, the order of feature rearrangement for each ID and the normalization of various features... minimum value and maximum value With training set Maintain consistency.

3. The CAN-FD anomaly detection method based on real physical meaning according to claim 2, characterized in that, Step 2 includes the following specific steps: Step 2.1, Network Model Construction: A machine learning model containing LSTM layers, self-attention layers, and fully connected layers was built for time series prediction. This model learns all the features... , This represents the first extracted from the message. Class features, , For the training set A feature value extracted from the frame message. , For the total number of training samples, therefore for have: (13); Input layer: (14); (15); in , They are and A pair of corresponding elements in the array, where That is, input When, the expected output is ,for and have: (16); (17); Step 2.2: Obtain the input features and expected output of the training set according to the set sliding window and output sequence size. Use these as the input to the model, and train the model by setting the learning rate, number of epochs, and batch size. Select the mean squared error as the loss function, and its mathematical expression is as follows: (18); in For the sample size, For the first The true value of each sample For the first The predicted value for each sample is calculated, and after 100 training rounds, the trained model is saved. Step 2.3, Model Validation and Performance Evaluation: This step validates the trained model using the input features and actual outputs of the attack dataset. True Positive Examples (TP), False Positive Examples (FP), True Negative Examples (TN), False Negative Examples (FN), accuracy, precision, recall, and F1 score are used as metrics to evaluate model performance. The trained model is loaded, and predictions are made for each element in the input features of the attack dataset. The mean squared error loss value for each prediction is calculated based on the predicted value and its corresponding actual output. Set a mean squared error threshold If the mean squared error loss is less than If the prediction result meets expectations, the message is a normal message; if the mean squared error loss exceeds... If the prediction result does not meet expectations, it indicates that the message is abnormal. By comparing the model's prediction results with the actual labels of the message, we can obtain the true positives, false positives, true negatives, false negatives, accuracy, precision, recall, and F1 score, among which: True cases are the number of positive cases that the model correctly predicts as positive cases. False positives are the number of negative examples that the model incorrectly predicts as positive examples. True negatives are the number of negatives that the model correctly predicts as negatives. False negatives are the number of positive examples that the model incorrectly predicts as negative examples. Accuracy represents the proportion of samples correctly predicted by the model out of the total number of samples. The calculation formula is: (19); Precision represents the proportion of samples that the model correctly predicts as positive out of all samples predicted as positive. The formula for calculation is: (20); Recall rate represents the proportion of actual positive examples that the model correctly predicts as positive. The formula for calculating recall is: (21); The F1 score is a metric combining precision and recall, calculated using the following formula: (22); The above formulas can be used to calculate true positives, false positives, true negatives, false negatives, accuracy, precision, recall, and F1 score, thereby enabling the analysis of the performance of the anomaly detection model.

4. The CAN-FD anomaly detection method based on real physical meaning according to claim 3, characterized in that, In step 2.2, the corresponding input features and expected outputs are extracted from the training set after data preprocessing. Adam is selected as the optimizer, the training epochs are set to 100, the batch size to 32, and the learning rate to [value missing]. .

Citation Information

Patent Citations

  • Network intrusion detection method based on LSTM and attention mechanism

    CN116502091A

  • Method and apparatus for detecting attack in CAN BUS

    KR102477705B1