Vehicle-mounted CAN intrusion detection method and system based on GRU, storage medium and computer system
By combining an automatic encoder and a one-dimensional convolutional network with a GRU-based intrusion detection method for vehicle CAN, the problems of low detection accuracy and high computational complexity in existing technologies are solved, achieving high-precision and low-error-rate intrusion detection results.
Patent Information
- Application Number
- CN202511513696.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-22
- Publication Date
- 2026-02-06
AI Technical Summary
Existing vehicle-mounted CAN intrusion detection methods have low accuracy and precision when detecting fuzz attacks, complex data preprocessing and high requirements for processors and memory, and complex machine learning algorithms lead to increased costs.
We employ a GRU-based intrusion detection method, combining an autoencoder (AE) and sliding window techniques for data preprocessing. We use one-dimensional convolution (Conv1D) and GRU networks for feature extraction and classification, and improve model performance through an attention mechanism. This simplifies the model structure and reduces computational complexity.
It achieves high-precision and high-reliability intrusion detection, effectively identifying most intrusion events, maintaining a low overall error rate, and achieving a good balance between security and availability.
Smart Images

Figure CN121485967A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of vehicle controller local area network intrusion detection technology, specifically involving a vehicle CAN intrusion detection method and system based on GRU, storage medium, and computer system. Background Technology
[0002] Controller Area Network (CAN) is currently the most widely used in-vehicle serial communication protocol in the automotive industry. However, CAN's unauthenticated encryption, broadcast transmission, and arbitration priority characteristics make it highly vulnerable to message injection and tampering attacks. Furthermore, domestic and international regulations have imposed mandatory regulatory requirements on this. Using encryption algorithms to protect in-vehicle CAN communication increases automakers' R&D costs and delays vehicle development cycles. Therefore, in-vehicle intrusion detection systems, with their dynamic response and real-time characteristics, have significant research value. Current research focuses on applying machine learning algorithms to in-vehicle CAN intrusion detection models. This approach enables the developed in-vehicle CAN intrusion detection system to achieve high accuracy and generalization performance.
[0003] Currently, there are also related intrusion detection methods for automotive CAN buses. For example, Chinese invention patent application number 202411056272.3 proposes an intrusion detection method for automotive CAN buses based on evidence-based deep learning, and Chinese invention patent application number 202411332021.3 proposes an intrusion detection method for automotive CAN buses based on convolution. Both of these propose new methods for intrusion detection of automotive CAN buses; however, they still have the following technical problems:
[0004] (1) The selected features cannot enable the detection model to learn the temporal, spatial and semantic features of CAN messages at the same time, which results in the model not being able to obtain high precision and accuracy when detecting fuzz-type attacks.
[0005] (2) Data preprocessing operations are too complex. CAN messages are in milliseconds. For example, converting CAN data in text form to image form requires complex visual processing models to operate the data after such visualization processing, which will place high demands on the processor and memory of the vehicle system.
[0006] (3) The machine learning algorithms used in building intrusion detection models are relatively complex. For example, stacking multiple convolutional networks or fully connected layers will increase the model parameters, which will place higher demands on the deployed vehicle equipment and increase the cost of automobile R&D.
[0007] Therefore, a vehicle-mounted CAN intrusion detection method and system based on GRU, storage medium, and computer system are needed to solve the above-mentioned technical problems. Summary of the Invention
[0008] To address the aforementioned technical problems, this invention designs a vehicle-mounted CAN intrusion detection method and system based on GRU, a storage medium, and a computer system. This method introduces an Autoencoder (AE) to deepen the model's understanding of the input sequence features. After preprocessing batches of CAN data using a sliding window, a 13-dimensional time-series data is obtained. This data is then processed by an encoder, GRU, decoder, fully connected layer, and sigmoid activation function to obtain a scalar value in the range [0,1] for anomaly data classification. This invention uses Conv1D as the hidden layer; compared to two-dimensional convolution, one-dimensional convolution has fewer parameters and is computationally simpler. The method of this invention exhibits high accuracy and reliability in detecting intrusion behavior, effectively identifying most intrusion events (low FNR) while maintaining a low overall error rate (low ER), thus achieving a good balance between security and availability.
[0009] To achieve the aforementioned technical effects, this invention discloses a GRU-based vehicle CAN intrusion detection method, comprising the following steps:
[0010] S1: Data Acquisition: Real-time acquisition of vehicle CAN data sets using PCAN;
[0011] S2: Dataset preprocessing: Preprocessing the dataset using statistical algorithms;
[0012] S3: Intrusion detection model design, specifically:
[0013] S3.1: First, the encoder of AE is used to compress and reduce the dimensionality of the input features, mapping the input data to a low-dimensional space and extracting the latent features of the data. In the encoder, the first layer has 13 input channels and 16 output channels; the second layer has 16 input channels and 32 output channels; the third layer has 32 input channels and 64 output channels. Each layer is activated using the ReLU nonlinear function, and a Dropout mechanism is added to reduce the fit and shrink the model. The convolutional kernel size of the convolutional layer is 3, the stride is 1, and the Dropout rate is chosen to be 0.1. Therefore, the hidden layers of the encoder are 3 one-dimensional convolutional layers with ReLU activation and Dropout.
[0014] The simplified formula for AE is as follows:
[0015]
[0016] In the formula, n represents the sample size. Represents the original data. This indicates the output data, and the loss function used is mean squared error.
[0017] The Conv1D formula is as follows:
[0018]
[0019] In the formula, L in The input sequence is represented by padding, the dilation coefficient is represented by the dilation factor, the kernel is represented by the kernel size, and the stride is represented by the stride.
[0020] The formula for the ReLU function is as follows:
[0021]
[0022] In the formula, when When, the input equals the output, when When the time is right, the output is 0;
[0023] S3.2: A two-layer GRU network is used to train the encoder output data, learning the sequence features extracted by the encoder from the data. The input dimension of the two middle GRU layers is 64, and the number of hidden units is 64. Batch processing is used, and an attention mechanism, i.e., the key-query-value mechanism, is used after the GRU to improve performance and efficiency. The essence of the attention mechanism is to introduce a small model into the model. During training, this model queries the value (attention) corresponding to the key, calculates it based on cosine similarity, normalizes it using the softmax function, and finally uses a weighted sum to affect the network parameter update. It is worth noting that a self-attention model is not used here because self-attention models are mostly used to capture long dependencies between interval data, while GRU has already learned dependencies, and overuse will cause overfitting.
[0024] S3.3: The decoder restores the feature sequences processed by the encoder and GRU to obtain an approximate reconstruction of the original data, thus optimizing performance. The hidden layers in the decoder are also Conv1D. The first layer has 64 input channels and 32 output channels; the second layer has 32 input channels and 16 output channels; the third layer has 16 input channels and 13 output channels. Therefore, the hidden layers of the decoder are three one-dimensional convolutional layers with ReLU activation and Dropout.
[0025] The formula for the Sigmoid function is shown below:
[0026] ;
[0027] In the formula, x represents the input sample value;
[0028] S3.3: A fully connected layer is used to map the 13-dimensional features to 1-dimensional data, and the sigmoid function is used to activate the binary classification result. The output is [0,1]. With 0.5 as the boundary, values less than 0.5 are counted as 0, which is considered normal data, and values greater than or equal to 0.5 are counted as 1, which is considered attack data.
[0029] The formula for the fully connected layer is:
[0030]
[0031] In the formula, x represents the input sample value.
[0032] Furthermore, in S1, the collected dataset includes normal data, Denial of Service (DoS) attack data, Fuzz attack data, Replay attack data, and Unified Diagnostic Services (UDS) attack data.
[0033] Furthermore, the data collection process mirrors the HCRL CH dataset collection method. Each attack dataset contains 300 message injections lasting 3-5 seconds, with a collection duration of 30-40 minutes. Dataset attributes include timestamps, IDs, DLCs, payloads, and tags.
[0034] Furthermore, in S2, the specific preprocessing process is as follows:
[0035] S2.1: First, convert the timestamp to a value in milliseconds and calculate the time interval between messages with the same ID; then convert the ID to decimal.
[0036] S2.2: After converting the data field to decimal as well, calculate the difference between each byte of the data field of messages with the same ID; then calculate the mean, variance and standard deviation of the data field of each message.
[0037] S2.3: The final preprocessed feature dimensions are: time interval, ID, difference of each byte in the data field, mean, variance and standard deviation, totaling 13 dimensions; attack data is marked with 1, while normal data is marked with 0;
[0038] Furthermore, in S3.2,
[0039] The GRU update gate synthesizes the current input xt with the previous time-state output ht-1, helping the model determine how many parameters will participate in the subsequent calculations:
[0040]
[0041] The GRU reset gate is calculated similarly to the update gate, but with different weights. It determines how much past information will be ignored: where W and U represent the weight matrices, and σ represents the sigmoid function.
[0042]
[0043] GRU calculates the current candidate hidden state based on the output of the reset gate:
[0044]
[0045] In the formula, r t To reset the gate's output, x t h is the current input. t-1 For the output of the previous time state, W and U represent the weight matrices, and tanh represents the tanh function;
[0046] GRU utilizes the output z of the update gate. t The output h from the previous time step t-1 and the output h of the reset gate ’ t Calculate and output the current hidden state:
[0047] .
[0048] On the other hand, the present invention discloses a vehicle-mounted CAN intrusion detection system based on GRU, including a data acquisition module, an intrusion detection module and a result processing module;
[0049] Data Acquisition Module: The data acquisition module is deployed in the vehicle gateway and is used to listen for and collect all CAN messages of the vehicle. The acquisition module uses a sliding window mechanism to read m data in batches. Then, the acquired data is processed according to the above preprocessing method to obtain serialized data with 13-dimensional feature values. The input sequence is formed into a square matrix, so the value of m in the sliding window is also set to 13.
[0050] Intrusion Detection Module: The intrusion detection module contains the pre-trained GRU-based intrusion detection model. After compiling the model using C++ code to be deployable on embedded devices, the developed intrusion detection module is deployed on a vehicle-mounted device with computing power. The intrusion detection module receives 13x13-dimensional serialized data from the data acquisition module, inputs the data into the model for detection, and obtains a 13x1 result. The data range in the result is [0,1]. Data less than 0.5 is counted as 0, which is considered normal data, and data greater than or equal to 0.5 is counted as 1, which is considered attack data.
[0051] Results Processing Module: The results processing module is deployed in a device with cloud network connectivity. This module receives the results calculated by the intrusion detection module. If attack data is found in the results, the data and related events are uploaded to the car manufacturer's security operations center.
[0052] The present invention also provides a computer-readable storage medium storing a computer program; when the computer program is executed, the above-described GRU-based vehicle CAN intrusion detection method can be implemented.
[0053] The present invention also provides a computer system, including a processor and a memory; the memory stores a computer program; when the computer program is executed by the processor, the above-mentioned GRU-based vehicle CAN intrusion detection method can be implemented.
[0054] The beneficial effects of this invention are:
[0055] This invention designs and discloses a vehicle-mounted CAN intrusion detection method and system based on GRU, a storage medium, and a computer system;
[0056] 1. This method introduces an autoencoder (AE) to deepen the model's understanding of the input sequence features. A sliding window is used to select batches of CAN data for preprocessing, resulting in a 13-dimensional time series dataset. This dataset is then processed by an encoder, GRU, decoder, fully connected layer, and sigmoid activation function to obtain a scalar value in the range [0,1] for classifying outlier data. This invention uses Conv1D as the hidden layer; compared to two-dimensional convolution, one-dimensional convolution has fewer parameters and is computationally simpler.
[0057] 2. The GRU-based intrusion detection model proposed in this invention demonstrates excellent performance in DoS, Gear, and RPM detection, completely distinguishing attack packets from normal packets with 100% accuracy and precision. In Fuzz detection, the precision is 0.9983. It has high accuracy and reliability in detecting intrusion behavior, effectively identifying most intrusion events (low FNR) while maintaining a low overall error rate (low ER), thus achieving a good balance between security and availability. Attached Figure Description
[0058] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below.
[0059] Figure 1 This is a sample diagram of the network structure of the intrusion detection model in this invention;
[0060] Figure 2This is the DoS attack detection obfuscation matrix diagram in this invention;
[0061] Figure 3 This is the obfuscation matrix diagram for Fuzz attack detection in this invention;
[0062] Figure 4 This is the obfuscation matrix diagram for Replay attack detection in this invention;
[0063] Figure 5 This is the UDS attack detection obfuscation matrix diagram in this invention. Detailed Implementation
[0064] Example 1
[0065] A GRU-based method for intrusion detection in vehicle CAN bus systems includes the following steps:
[0066] S1: Data Acquisition: Real-time acquisition of vehicle CAN data sets using PCAN; the acquired datasets include normal data, Denial of Service (DoS) attack data, Fuzz attack data, Replay attack data, and Unified Diagnostic Services (UDS) attack data. These four types are the most commonly used CAN attack methods by current connected vehicle security researchers and are of greatest concern to relevant regulations.
[0067] The dataset collection process mirrors that of the HCRL CH dataset, currently the most widely used dataset in academic research. Each attack dataset contains 300 message injections lasting 3 to 5 seconds each, with a collection duration of 30 to 40 minutes. Dataset attributes include timestamps, IDs, DLCs, payloads, and tags. DoS Attack Dataset: During the collection of the DoS attack dataset, three threads are simultaneously launched at 1-millisecond intervals to send CAN messages with the ID "0x000" to the target system. This high-frequency message transmission causes the target system to receive a large amount of invalid or interfering data in a short period, thus interfering with or blocking its normal communication functions. A single DoS attack lasts approximately 5 seconds. During these 5 seconds, the attacker continuously sends messages through the three threads, putting sufficient pressure on the target system to achieve the attack objective.
[0068] Fuzz Attack Dataset: A script was written in Python to generate the fuzz attack dataset. This script calls the SocketCAN interface, an interface used to communicate with the CAN bus in a Linux system. Through this interface, the attacker injects randomly generated ID and Data field combinations into the CAN bus at 10-millisecond intervals. The ID is the identifier of the CAN message, used to distinguish different message types and sources; the Data field contains the actual data content of the message. Because these ID and Data field combinations are randomly generated, the attacker cannot predict their specific impact on the target system, but this randomness increases the uncertainty and potential destructiveness of the attack. A single fuzz attack also lasts approximately 5 seconds, during which the attacker continuously injects a large number of random messages into the bus, attempting to trigger potential vulnerabilities or abnormal behavior in the target system.
[0069] Replay attack dataset: First, a dataset of normal communication processes is recorded using script code. This dataset contains various messages sent and received by the car during normal operation. Then, this recorded normal dataset is retransmitted back to the CAN bus at 5-10 millisecond intervals. The purpose of this attack is to disrupt the normal communication sequence and logic of the target system by repeatedly sending normal data, potentially causing the system to make incorrect judgments or exhibit abnormal behavior. A single replay attack lasts approximately 5 seconds. During these 5 seconds, the attacker repeatedly sends the previously recorded data at fixed intervals, attempting to confuse and interfere with the target system.
[0070] UDS Attack Dataset: The generation process of the UDS attack dataset is quite complex, simulating the attack logic of a hacker on a target system. Attackers first use scripts or other tools to search the target system for potential UDS IDs through traversal. UDS IDs are codes used to identify different diagnostic services and functions; attackers search for these IDs to try and find exploitable vulnerabilities or weaknesses in the target system. After finding a potential UDS ID, the attacker will launch a targeted injection attack against that specific ID. Attack commands include device resets, tampering with software and hardware version number parameters, and clearing fault information. The purpose of these attack commands may be to disrupt the normal operation of the target system, tamper with critical system information, or hide attack traces. During a UDS attack, exploratory attacks (i.e., the process of finding UDS IDs) and targeted attacks are executed alternately, but targeted attacks occupy the majority of the attack time. This attack method is highly targeted and destructive, posing a serious threat to the security and stability of the target system.
[0071] Normal Dataset: The normal dataset was generated for feature analysis to better understand the communication characteristics and behavioral patterns of the target system under normal operating conditions. To this end, this study used the official software compatible with the connection device to record several segments of data during normal communication. This data includes various messages sent and received by the target system during normal operation, covering various communication scenarios and functional implementations under normal conditions. By analyzing these normal datasets, we can extract the characteristic patterns of the target system during normal operation, thus providing important information for subsequent attack detection and defense strategy formulation.
[0072] S2: Dataset preprocessing: Preprocessing the dataset using statistical algorithms;
[0073] Specifically, the collected dataset contains labels including data sequence number, timestamp, ID, data length code (DLC), 8-byte data fields Data0~Data7, and message direction. The message direction value is Tx or Rx, representing data sent to the bus and data received, respectively. To ensure the model has a high learning efficiency with CAN data, the collected dataset needs to be preprocessed.
[0074] Timestamp processing: CAN messages are time-series data, and timestamps are a crucial feature. Timestamps are converted to milliseconds, and the time interval between CAN messages is calculated based on the same ID. If the ID appears for the first time, the time interval is recorded as the average time interval in the normal dataset. If the first-time occurrence of the ID indicates an injected fuzz attack, it is recorded as 0. The unit of time interval is milliseconds.
[0075] ID processing: The ID is a core feature of CAN, identifying the priority of a message in the vehicle communication architecture. During preprocessing, the hexadecimal ID is converted to decimal.
[0076] Data field processing: First, the 8-byte data field is converted to decimal format. Then, the absolute difference between the decimal values of each byte of the data field for the same ID message is calculated. This preprocessing method statistically analyzes the changes in the CAN data field, compresses the size of the data input to the network, and avoids impacting performance by directly inputting the data field into the network.
[0077] Mean, variance, and standard deviation calculation: Calculate the mean, variance, and standard deviation of the data field for each CAN message. First, sum the 8 bytes of data field after decimal processing to obtain the sum of the data payload. The calculation formula is as follows:
[0078]
[0079] Secondly, based on the calculation obtained in the first step, the average value of the data fields in this message is calculated using the following formula:
[0080]
[0081] Next, the variance of the data field of this message is calculated using the following formula:
[0082]
[0083] Finally, the standard deviation of the data field of this message is calculated using the following formula:
[0084]
[0085] In summary, the preprocessing operation mainly uses statistical algorithms, and the process is relatively simple. First, the timestamp is converted to milliseconds, and the time interval between packets with the same ID is calculated. Next, the ID is converted to decimal. Then, the data field is also converted to decimal, and the difference between each byte of the data field for packets with the same ID is calculated. Finally, the mean, variance, and standard deviation of the data field for each packet are calculated. The final preprocessed feature dimensions are: time interval, ID, difference between each byte of the data field, mean, variance, and standard deviation, totaling 13 dimensions. Attack data is marked with 1, while normal data is marked with 0.
[0086] S3: Intrusion detection model design, specifically:
[0087] S3.1: First, the encoder of AE is used to compress and reduce the dimensionality of the input features, mapping the input data to a low-dimensional space and extracting the latent features of the data. In the encoder, the first layer has 13 input channels and 16 output channels; the second layer has 16 input channels and 32 output channels; the third layer has 32 input channels and 64 output channels. Each layer is activated using the ReLU nonlinear function, and a Dropout mechanism is added to reduce the fit and shrink the model. The convolutional kernel size of the convolutional layer is 3, the stride is 1, and the Dropout rate is chosen to be 0.1. Therefore, the hidden layers of the encoder are 3 one-dimensional convolutional layers with ReLU activation and Dropout.
[0088] The simplified formula for AE is as follows:
[0089]
[0090] In the formula, n represents the sample size. Represents the original data. This indicates the output data, and the loss function used is mean squared error.
[0091] The Conv1D formula is as follows:
[0092]
[0093] In the formula, L in The input sequence is represented by padding, the dilation coefficient is represented by dilation, the kernel is represented by the kernel size, and the stride is represented by the stride.
[0094] The formula for the ReLU function is as follows:
[0095]
[0096] In the formula, when When, the input equals the output, when When the time is 0, the output is 0.
[0097] S3.2: A two-layer GRU network is used to train the encoder output data, learning the sequence features extracted by the encoder from the data. The input dimension of the two middle GRU layers is 64, and the number of hidden units is 64. Batch processing is used, and an attention mechanism, i.e., the key-query-value mechanism, is used after the GRU to improve performance and efficiency. The essence of the attention mechanism is to introduce a small model into the model. During training, this model queries the value (attention) corresponding to the key, calculates it based on cosine similarity, normalizes it using the softmax function, and finally uses a weighted sum to affect the network parameter update. It is worth noting that a self-attention model is not used here because self-attention models are mostly used to capture long dependencies between interval data, while GRU has already learned dependencies, and overuse will cause overfitting.
[0098] GRU update gate integrates current input x t Compared with the previous time-state output h t-1 Then, it helps the model determine how many parameters will participate in the subsequent calculations. W and U represent the weight matrix, and σ represents the sigmoid function, which transforms the data into values in the range of 0-1.
[0099]
[0100] The GRU reset gate is calculated similarly to the update gate, but with different weights, taking into account the current input x. t Compared with the previous time-state output h t-1 Then, it determines how much past information will be ignored. W and U represent the weight matrix, and σ represents the sigmoid function, which transforms the data into values in the range of 0-1.
[0101]
[0102] GRU based on the output r of the reset gatet Based on the current input x t Compared with the previous time-state output h t-1 Next, the current candidate hidden state is calculated, where W and U represent the weight matrices, and tanh represents the tanh function, which transforms the data into values in the range [-1, 1].
[0103]
[0104] GRU utilizes the output z of the update gate. t The output h from the previous time step t-1 and the output h of the reset gate ’ t Calculate and output the current hidden state:
[0105]
[0106] S3.3: The decoder restores the feature sequences processed by the encoder and GRU to obtain an approximate reconstruction of the original data, thus optimizing performance. The hidden layers in the decoder are also Conv1D. The first layer has 64 input channels and 32 output channels; the second layer has 32 input channels and 16 output channels; the third layer has 16 input channels and 13 output channels. Therefore, the hidden layers of the decoder are three one-dimensional convolutional layers with ReLU activation and Dropout.
[0107] The formula for the Sigmoid function is shown below:
[0108] ;
[0109] S3.3: A fully connected layer is used to map the 13-dimensional features to 1-dimensional data, and the sigmoid function is used to activate the binary classification result. The output is [0,1]. With 0.5 as the boundary, values less than 0.5 are counted as 0, which is considered normal data, and values greater than or equal to 0.5 are counted as 1, which is considered attack data.
[0110] The formula for the fully connected layer is:
[0111] .
[0112] Example 2
[0113] In this embodiment, the method described in Example 1 is further evaluated and verified, and the specific results are shown in Table 1. The evaluation metrics include Precision, False Negative Rate (FNR), Error Rate (ER), Recall, and F1 Score. Intrusion detection systems place particular emphasis on ER and FNR performance. A high false positive rate will harass users, while misclassifying a large number of attack packets as normal packets will cause losses to users. The above metrics are calculated using a confusion matrix, including True Positive (TP), True Negative (TN), False Positive (FP), and False Negative (FN). TP represents correctly classified attack data, TN represents correctly classified normal data, FP represents misclassified attack data, and FN represents misclassified normal data.
[0114] The formula for calculating accuracy is:
[0115]
[0116] The formula for calculating the false negative rate is:
[0117]
[0118] The formula for calculating the error rate is:
[0119]
[0120] The formula for calculating recall rate is:
[0121]
[0122] The formula for calculating the F1 score is:
[0123] .
[0124] Table 1. Comparative experimental results of the GRU-based intrusion detection model on a self-collected dataset.
[0125] type method Pre FNR ER Recall F1 DoS This method 1.0 0.0 0.0 1.0 1.0 DCNN 1.0 0.0 0.0 1.0 1.0 LSTM 1.0 0.0 0.0 1.0 1.0 Fuzz This method 0.9983 0.0061 0.0013 0.9938 0.9961 DCNN 0.8959 0.3175 0.0883 0.6824 0.7747 LSTM 0.9169 0.2844 0.0758 0.7155 0.8038 Replay This method 1.0 0.0 0.0 1.0 1.0 DCNN 0.9365 0.4270 0.0845 0.5729 0.7109 LSTM 0.9189 0.3297 0.0591 0.6702 0.7751 UDS This method 1.0 0.0 0.0 1.0 1.0 DCNN 1.0 0.0 0.0 1.0 1.0 LSTM 0.9904 0.0008 0.0017 0.9991 0.9947
[0126] As shown in Table 1, the GRU-based intrusion detection model proposed in this invention exhibits superior performance in DoS, Gear, and RPM detection, completely distinguishing attack packets from normal packets with 100% accuracy and precision. In Fuzz detection, the precision is 0.9983. This demonstrates that the GRU-based intrusion detection model proposed in this invention possesses high accuracy and reliability in detecting intrusion behavior. It effectively identifies most intrusion events (low FNR) while maintaining a low overall error rate (low ER), thus achieving a good balance between security and availability. In practical applications, pursuing low FNR and low ER is an important goal for intrusion detection system performance optimization, directly impacting driving safety.
[0127] Example 3
[0128] In this embodiment, a vehicle-mounted CAN network intrusion detection system based on GRU is provided, including a data acquisition module, an intrusion detection module, and a result processing module.
[0129] The data acquisition module should be deployed in the vehicle gateway to monitor and collect all CAN messages from the entire vehicle. The acquisition module uses a sliding window mechanism to read m data points in batches. The acquired data is then processed according to the preprocessing method described above, resulting in serialized data with 13-dimensional feature values. To improve model performance, the input sequences are arranged into a square matrix; therefore, the value of m in the sliding window is also set to 13.
[0130] The core of the intrusion detection module is the pre-trained GRU-based intrusion detection model. After compiling the model into C++ code for deployment on embedded devices, the developed intrusion detection module is deployed on in-vehicle devices with sufficient computing power, such as TBOX or in-vehicle infotainment systems. This module receives 13x13 dimensional serialized data from the data acquisition module, inputs the data into the model for detection, and obtains a 13x1 result. The data range in the result is [0,1]. Data less than 0.5 is counted as 0 (normal data), and data greater than or equal to 0.5 is counted as 1 (attack data).
[0131] The results processing module is deployed in devices with cloud network connectivity, such as TBOX or in-vehicle infotainment systems. This module receives the results calculated by the intrusion detection module. If attack data is found in the results, this data and related events are uploaded to the automaker's security operations center.
[0132] In addition, in this embodiment, the present invention also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above-described method embodiments;
[0133] A computer-readable storage medium is also provided, on which a computer program is stored, which, when executed by a processor, implements the steps in the above method embodiments.
[0134] In addition, this embodiment also provides a computer program product, including a computer program that, when executed by a processor, implements the steps in the above-described method embodiments.
[0135] Specifically, the memories, databases, and other storage media involved in the various embodiments of this application generally cover two core types, and include at least one of them: non-volatile memory, whose core characteristic is that it can maintain data integrity after power failure. Common types include, but are not limited to: read-only memory (ROM, suitable for fixed program storage), magnetic tape (traditional large-capacity archival storage), floppy disk (early portable storage medium), flash memory (such as the core storage unit of USB flash drives and solid-state drives), optical memory (such as optical discs, which rely on laser reading and writing), high-density embedded non-volatile memory (suitable for small electronic devices), and new storage technologies such as resistive random access memory (ReRAM, which stores data through resistance changes), magnetic random access memory (MRAM, which uses magnetoresistive effect to achieve storage), ferroelectric memory (FRAM, based on the polarization characteristics of ferroelectric materials), phase change memory (PCM, which records information through material phase changes), and graphene memory (which relies on the electrical properties of graphene to achieve high-speed storage), etc.
[0136] Volatile memory, which requires continuous power to maintain data, has the advantage of fast read and write speeds. It mainly includes: Random Access Memory (RAM, core memory that interacts directly with the processor) and external cache memory (such as CPU cache, used for temporary storage of frequently accessed data). RAM can be further subdivided into several specific forms, such as Static Random Access Memory (SRAM, which retains data without refresh circuitry, offering high speed but low integration density) and Dynamic Random Access Memory (DRAM, which requires periodic refresh to maintain data, offering low cost and high integration density, and is the mainstream choice for computer memory).
[0137] At the data management level, the databases involved in the various embodiments of this application also have diverse forms, including at least one type of relational database and non-relational database. Relational databases (such as MySQL and PostgreSQL) organize data in a table structure and are suitable for scenarios with strong transactional requirements and close data relationships; non-relational databases are more flexible and include key-value (such as Redis), document (such as MongoDB), and column-family (such as HBase). Among them, distributed databases based on blockchain technology, with their decentralized and tamper-proof characteristics, demonstrate unique value in scenarios such as data traceability and distributed collaboration, but are not limited to such applications.
[0138] Furthermore, the processors that undertake data processing tasks in the various embodiments of this application are of a wide variety of types: including general-purpose processors (suitable for various conventional computing tasks), central processing units (CPUs, the core of computer operations), graphics processing units (GPUs, which excel at parallel computing and are widely used in graphics rendering and artificial intelligence training), digital signal processors (DSPs, which focus on high-speed processing of audio, image and other signals), programmable logic devices (such as FPGAs, which can flexibly configure hardware functions through programming), and cutting-edge quantum computing-based data processing logic devices (which utilize quantum superposition states to achieve ultra-high-speed computing), etc.
[0139] The preferred embodiments of the present invention disclosed above are only for the purpose of illustrating the present invention. The preferred embodiments do not describe all the details in detail, nor do they limit the invention to the specific implementation described.
Claims
1. A method for detecting intrusion into a vehicle-mounted CAN bus based on a GRU, characterized in that, Includes the following steps: S1: Data Acquisition: Real-time acquisition of vehicle CAN data sets using PCAN; S2: Dataset preprocessing: Preprocessing the dataset using statistical algorithms; S3: Intrusion detection model design, specifically: S3.1: First, the encoder of AE is used to compress and reduce the dimensionality of the input features, mapping the input data to a low-dimensional space and extracting the latent features of the data. In the encoder, the first layer has 13 input channels and 16 output channels; the second layer has 16 input channels and 32 output channels; the third layer has 32 input channels and 64 output channels. Each layer is activated using the ReLU nonlinear function, and a Dropout mechanism is added to reduce the fit and shrink the model. The convolutional kernel size of the convolutional layer is 3, the stride is 1, and the Dropout rate is chosen to be 0.
1. Therefore, the hidden layers of the encoder are 3 one-dimensional convolutional layers with ReLU activation and Dropout. The simplified formula for AE is as follows: ; In the formula, n represents the sample size. Represents the original data. This indicates the output data, and the loss function used is mean squared error. The Conv1D formula is as follows: ; In the formula, L in The input sequence is represented by padding, the dilation coefficient is represented by the dilation factor, the kernel is represented by the kernel size, and the stride is represented by the stride. The formula for the ReLU function is as follows: ; In the formula, when When, the input equals the output, when When the time is right, the output is 0; S3.2: A two-layer GRU network is used to train the data output by the encoder, learning the sequence features extracted by the encoder from the data. The input dimension of the two middle GRU layers is 64, and the number of hidden units is 64. Batch-first processing is used, and an attention mechanism, i.e., key-query-value mechanism, is used after GRU to improve performance and efficiency. During training, the model queries the value (attention) corresponding to the key, calculates it based on cosine similarity, normalizes it using the softmax function, and finally uses weighted summation to affect the parameter update of the network. S3.3: The decoder restores the feature sequences processed by the encoder and GRU to obtain an approximate reconstruction of the original data, thus optimizing performance. The hidden layers in the decoder are also Conv1D. The first layer has 64 input channels and 32 output channels; the second layer has 32 input channels and 16 output channels; the third layer has 16 input channels and 13 output channels. Therefore, the hidden layers of the decoder are three one-dimensional convolutional layers with ReLU activation and Dropout. The formula for the Sigmoid function is shown below: ; In the formula, x represents the input sample value; S3.3: A fully connected layer is used to map the 13-dimensional features to 1-dimensional data, and the sigmoid function is used to activate the binary classification result. The output is [0,1]. With 0.5 as the boundary, values less than 0.5 are counted as 0, which is considered normal data, and values greater than or equal to 0.5 are counted as 1, which is considered attack data. The formula for the fully connected layer is: ; In the formula, x represents the input sample value.
2. The vehicle-mounted CAN intrusion detection method based on GRU according to claim 1, characterized in that, In S1, the collected dataset includes normal data, Denial of Service (DoS) attack data, Fuzz attack data, Replay attack data, and Unified Diagnostic Services (UDS) attack data.
3. The vehicle-mounted CAN intrusion detection method based on GRU according to claim 1, characterized in that, The data collection process mirrors the HCRL CH dataset collection method. Each attack dataset contains 300 message injections lasting 3-5 seconds, with a collection duration of 30-40 minutes. Dataset attributes include timestamp, ID, DLC, payload, and label.
4. The vehicle-mounted CAN intrusion detection method based on GRU according to claim 1, characterized in that, In S2, the specific preprocessing process is as follows: S2.1: First, convert the timestamp to a value in milliseconds and calculate the time interval between messages with the same ID; then convert the ID to decimal. S2.2: After converting the data field to decimal as well, calculate the difference between each byte of the data field of messages with the same ID; then calculate the mean, variance and standard deviation of the data field of each message. S2.3: The final preprocessed feature dimensions are: time interval, ID, difference of each byte in the data field, mean, variance and standard deviation, totaling 13 dimensions; attack data is marked with 1, while normal data is marked with 0.
5. The vehicle-mounted CAN intrusion detection method based on GRU according to claim 1, characterized in that, In S3.2, The GRU update gate synthesizes the current input xt with the previous time-state output ht-1, helping the model determine how many parameters will participate in the subsequent calculations: ; The GRU reset gate is calculated similarly to the update gate, but with different weights. It determines how much past information will be ignored: where W and U represent the weight matrices, and σ represents the sigmoid function. ; In the formula, r t To reset the gate's output, x t h is the current input. t-1 For the output of the previous time state, W and U represent the weight matrices, and tanh represents the tanh function; GRU calculates the current candidate hidden state based on the output of the reset gate: ; GRU utilizes the output z of the update gate. t The output h from the previous time step t-1 and the output h of the reset gate ’ t Calculate and output the current hidden state: 。 6. A GRU-based vehicle CAN intrusion detection system, characterized in that, It includes a data acquisition module, an intrusion detection module, and a result processing module; Data acquisition module: The data acquisition module is deployed in the vehicle gateway and is used to listen for and collect all CAN messages of the entire vehicle; In the acquisition module, a sliding window mechanism is used to read m data in batches. Then, the acquired data is processed according to the preprocessing method described above to obtain serialized data with 13-dimensional feature values. The input sequence is formed into a square matrix, so the value of m in the sliding window is also set to 13. Intrusion Detection Module: The intrusion detection module contains the pre-trained GRU-based intrusion detection model. After compiling the model into C++ code so that it can be deployed on embedded devices, the developed intrusion detection module is deployed on a vehicle-mounted device with computing power. The intrusion detection module receives 13x13-dimensional serialized data from the data acquisition module, inputs the data into the model for detection, and obtains a 13x1 result. The data range in the results is [0,1]. Data less than 0.5 is counted as 0 and is considered normal data. Data greater than or equal to 0.5 is counted as 1 and is considered attack data. Results Processing Module: The results processing module is deployed in a device with cloud network connectivity. This module receives the results calculated by the intrusion detection module. If attack data is found in the results, the data and related events are uploaded to the car manufacturer's security operations center.
7. A computer-readable storage medium storing a computer program therein; when the computer program is executed, it can implement the above-described GRU-based vehicle CAN intrusion detection method.
8. A computer system, comprising a processor and a memory; wherein the memory stores a computer program; when the computer program is executed by the processor, the above-described GRU-based vehicle CAN intrusion detection method can be implemented.
Citation Information
Patent Citations
Vehicle-mounted intrusion detection system and method based on evidence deep learning
CN118869317A
Intrusion detection method, device, vehicle and storage medium for vehicle-mounted CAN network
CN118870367B
Cited By
Vehicle-mounted abnormity comprehensive detection method and system based on evidence deep learning
CN121997183A
