A can bus intrusion detection method and system of graph perception state space

CN123020239APending Publication Date: 2026-10-30SHENZHEN AUTOMOTIVE RES INST BEIJING INST OF TECH (SHENZHEN RES INST OF NAT ENG LAB FOR ELECTRIC VEHICLES) +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611488901.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-23
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

[0009]3)在线聚类虽然不需要异常标签,但高度依赖手工设计的8个统计特征,这些特征主要是计数、和、熵等,仍然属于低维、粗粒度统计,其检测效果与泛化能力存在进一步提升的空间

Benefits of technology

[0102]1、本发明通过由正常通信流量构建 CAN 标识符关系图,模型能够在处理当前报文窗口时利用不同报文类型之间的统计共现关系和时序协同变化关系,而不仅依赖单条报文字段。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123020239A_ABST
    Figure CN123020239A_ABST
Patent Text Reader

Abstract

The application discloses a CAN bus intrusion detection method and system of a graph perception state space, and belongs to the technical field of bus intrusion detection. The method comprises the following steps: S1, preprocessing CAN bus messages, constructing a co-occurrence relationship graph and a time sequence correlation graph, and performing fusion and normalization processing to obtain a normalized fusion adjacency matrix; S2, based on the normalized fusion adjacency matrix, performing context broadcast injection to obtain a sequence after graph knowledge injection; S3, inputting the sequence after graph knowledge injection into a Mamba encoder for coding; and S4, determining a prediction category according to the sequence representation after coding by the Mamba encoder. The sequence processing part of the selective state space sequence coding module has approximate linear complexity with respect to the window length, and the calculation overhead of long sequence window coding can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of bus intrusion detection technology, specifically relating to a CAN bus intrusion detection method and system based on graph-aware state space. Background Technology

[0002] With the rapid development of intelligent sensors, wireless communication technologies, and big data analytics, vehicle-to-everything (V2X) technology is experiencing explosive growth. This evolution has reshaped vehicle functionality and performance, but it has also made V2X security a core challenge. In-vehicle networks are a core component of modern automobiles, with 70 to 100 electronic control units (ECUs) interconnected through various bus protocols to form a distributed real-time control network. CAN, as the dominant standard, is widely used in powertrain systems, chassis control, and body electrical systems due to its low cost and high fault tolerance; however, its lack of authentication and encryption makes it vulnerable to forgery or eavesdropping.

[0003] With the increasing number of vehicle networking interfaces, remote diagnostic interfaces, and intelligent driving-related electronic systems, the onboard CAN bus faces more external input paths. Once an attacker gains access to the in-vehicle network through a diagnostic interface, gateway, or attacked controller, they can potentially influence vehicle status perception and control logic through message injection, replay, flooding, or spoofing. Therefore, it is necessary to deploy intrusion detection methods capable of handling continuous CAN message sequences in onboard gateways or edge processors.

[0004] Currently, conventional intrusion detection methods include traditional rule-based detection systems and machine learning-based detection systems. Traditional non-learning intrusion detection systems (IDS) do not rely on data training but instead judge anomalies based on predefined rules or statistical thresholds. This method is simple and efficient, suitable for resource-constrained automotive environments, but its limitation is its reliance on predefined rules or thresholds, making it unable to handle unknown attacks. For example, timed IDS assumes a fixed normal interval, but if an attacker simulates a normal time sequence, it becomes difficult to detect, leading to a high false negative rate. Learning-based intrusion detection systems, on the other hand, utilize complex network structures to analyze data, significantly improving detection accuracy, but also increasing computational overhead.

[0005] In recent years, State Space Models (SSMs) have made groundbreaking progress in the field of sequence modeling. Selective State Space Models, exemplified by Mamba, introduce an input-dependent selective mechanism into the Structured State Space Sequence Model (S4). This means that both state transition parameters and discretization step size depend on the current input, enabling dynamic selective memorization or forgetting of sequence content. Unlike the quadratic complexity of Transformer self-attention, selective State Space Models, such as Mamba, can process sequence data through an input-related state update mechanism, with its sequence encoding part exhibiting approximately linear complexity with respect to the window length. The standard Mamba model primarily learns temporal dependencies from the input sequence itself and does not directly specify how to inject the CAN identifier relationship graph formed by normal CAN communication traffic as a window-level context into the sequence features.

[0006] Current rule-based traditional detection methods and learning model-based methods have the following drawbacks:

[0007] 1) Some rules or threshold methods rely on predefined patterns. When attack messages use legitimate CAN identifiers, legitimate DLCs, and seemingly normal payload formats, it may be difficult to make judgments based on the contextual relationships across message types.

[0008] 2) Some supervised learning methods rely on window samples with class labels for classification training. This invention does not deny that labeled samples can be used for classification training, but rather makes it so that the relational graph construction stage does not require manual provision of ECU topology, DBC files, or attack tags, and can automatically generate structural priors from normal CAN communication data.

[0009] 3) Although online clustering does not require outlier labels, it relies heavily on eight manually designed statistical features, which are mainly counts, sums, entropy, etc. These features are still low-dimensional and coarse-grained statistics, and there is room for further improvement in their detection performance and generalization ability.

[0010] 4) Some existing sequence detection methods mainly treat CAN identifiers as independent numerical or category features, failing to fully utilize the CAN identifier relationship graph and message sequence timing features formed by normal communication traffic within the same model. In this invention, CAN identifiers are used as functional message nodes or message type nodes to represent the statistical co-occurrence relationship and timing coordination change relationship between different message types, rather than being directly equivalent to ECU identity or ECU physical topology.

[0011] 5) Some long sequence models based on self-attention have high computational overhead as the window length increases. The sequence processing part of the selective state-space sequence encoding module has approximately linear complexity with respect to the window length, making it more suitable for online encoding of high-frequency CAN message windows. However, the complete model also includes graph augmentation, window aggregation, input projection, and classifier computation; therefore, the overall complexity should be explained separately for each module.

[0012] The above limitations result in current automotive CAN bus anomaly detection having problems such as insufficient detection rate against abnormal attacks, large blind spots in detectable attacks, high dependence on high-quality labeled data, poor cross-vehicle detection effect, and poor protection capabilities, which can bring huge hidden dangers during normal vehicle operation. Summary of the Invention

[0013] To address the above problems, this invention proposes a CAN bus intrusion detection method and system based on graph-aware state space.

[0014] The technical solution of the present invention is: a CAN bus intrusion detection method based on graph-aware state space, comprising the following steps:

[0015] S1. Preprocess the CAN bus messages, construct the co-occurrence relationship diagram and timing correlation diagram, and perform fusion and normalization processing to obtain the normalized fused adjacency matrix.

[0016] S2. Based on the normalized fused adjacency matrix, perform context broadcast injection to obtain the sequence after graph knowledge injection;

[0017] S3. Input the sequence after graph knowledge injection into the Mamba encoder for encoding;

[0018] S4. Determine the predicted category based on the sequence representation encoded by the Mamba encoder.

[0019] Furthermore, S1 includes the following sub-steps:

[0020] S11. Convert the heterogeneous fields of the CAN bus message into numerical features and complete them;

[0021] S12. After the completion process, construct the input features;

[0022] S13. Normalize the input features and construct a sliding window sequence;

[0023] S14. Based on the number of times any two CAN identifiers co-occur in the same window of the sliding window sequence, obtain the co-occurrence count matrix and construct the co-occurrence relationship graph;

[0024] S15. Obtain the equal-length message rate vector of the identifier based on the message rate of the identifier. After standardizing the equal-length message rate vector, determine the temporal relationship edge weights based on the normalized equal-length message rate vector of the identifier, and construct a temporal correlation graph.

[0025] S16. Merge the row-normalized adjacency matrix of the co-occurrence relation graph and the row-normalized adjacency matrix of the temporal correlation graph to obtain a merged adjacency matrix, and then normalize the merged adjacency matrix to obtain a normalized merged adjacency matrix.

[0026] Furthermore, in S12, if the dataset in the CAN bus information has a timestamp, the ID arrival time interval and time regularity are calculated, and the input features are constructed based on the identifier, data length code, bytes 0 to 7 of the data field, ID arrival time interval and time regularity; otherwise, the input features are constructed based on the identifier, data length code and bytes 0 to 7 of the data field.

[0027] ID arrival time interval for:

[0028] ;

[0029] in, Let be the CAN identifier of the t-th message. For timestamps, For the first The timestamp of the most recent historical message with the same CAN identifier as the current message before the current message arrived;

[0030] Time regularity for:

[0031] ;

[0032] ;

[0033] ;

[0034] in, The online coefficient of variation, For identifiers The online standard deviation of the ID arrival time interval. The online average, It is the numerical stability constant. It is a second-order cumulant. Number of valid IAT samples;

[0035] In S13, the sliding window sequence of the first... window for:

[0036] ;

[0037] in, For sliding window index, For the first One CAN message, For the first One CAN message, For the first One CAN message, This represents the number of messages contained in the sliding window.

[0038] In S14, the elements of the co-occurrence counting matrix for:

[0039] ;

[0040] in, The total number of windows, For the first A set of CAN identifiers within a window. For indicator functions, CAN identifier , CAN identifier ;

[0041] In S15, the identifier message rate for:

[0042] ;

[0043] in, For identifiers The number of messages, The length of a continuous time slice, The number of consecutive time slices;

[0044] In S15, the identifier Equal-length message rate vector for:

[0045] ;

[0046] in, The first time slice identifier message rate, For the second time slice identifier message rate, For the third time slice identifier message rate, For the first Time slice identifier Message rate;

[0047] In S15, the temporal relation edge weights for:

[0048] ;

[0049] in, For identifiers with identifier The time-series correlation coefficient between them For threshold;

[0050] In S16, the elements of the merged adjacency matrix are... for:

[0051] ;

[0052] in, The elements of the row-normalized adjacency matrix of the co-occurrence graph are... These are the elements of the row-normalized adjacency matrix of the temporal cooperative change graph. This is the fusion coefficient.

[0053] Furthermore, S2 includes the following sub-steps:

[0054] S21. Determine a dense embedding vector for each CAN identifier and generate a CAN identifier embedding.

[0055] S22. A lightweight graph attention network is constructed using the normalized fused adjacency matrix, and the CAN identifier embedding is enhanced using the lightweight graph attention network.

[0056] S23. Based on the enhanced CAN identifier embedding, perform separation enhancement;

[0057] S24. After separation enhancement, calculate the graph context vector and generate the projection result based on the graph context vector;

[0058] S25. Based on the projection results and learnable gating coefficients, perform context broadcast injection to obtain the sequence after graph knowledge injection.

[0059] Furthermore, in S22, the graph augmentation node representation of the lightweight graph attention network... for:

[0060] ;

[0061] ;

[0062] ;

[0063] ;

[0064] ;

[0065] ;

[0066] in, The aggregated output of the first attention head. This is the aggregated output of the h-th attention head. This is the aggregated output of the Hth attention head. This is a vector concatenation operation. It is the activation function of the exponential linear unit. For nodes CAN identifier embedding, Gather for the neighbors, For the first The nodes in each attention head are adjusted by the edge weights of the fused adjacency matrix. For neighboring nodes Attention coefficient For the first Nodes in each attention head The node representation after linear transformation For the first Neighboring nodes in each attention head The node representation after linear transformation To merge nodes in the adjacency matrix with neighboring nodes The corresponding element, To merge nodes in the adjacency matrix With nodes The corresponding element, For the first Attention Head Nodes with neighboring nodes Attention score normalization weights, For the first Attention Head Nodes With nodes Attention score normalization weights, It is the numerical stability constant. For the first Nodes in each attention head with neighboring nodes Unnormalized attention scores between them For the first Nodes in each attention head With nodes Unnormalized attention scores between them For the activation function of the linear unit with leakage correction, For the first A learnable attention vector for each attention head. For the first The learnable linear transformation matrix of each attention head It is an exponential function. For transpose;

[0067] In S23, the separation enhancement is specifically performed as follows:

[0068] ;

[0069] in, CAN identifier The enhanced embedding vector after separation CAN identifier The original embedding vector, This is the normalized fused adjacency matrix. Graph augmentation computation for lightweight graph attention networks. It is a set of known CAN identifiers that appear in the normal traffic during the training phase;

[0070] In S24, the projection result for:

[0071] ;

[0072] ;

[0073] in, For layer normalization operation, The weight matrix is ​​the projection of the graph context. For the first The graph context vector of each window, Let be the bias vector of the graph context projection. This is the embedded vector of the CAN identifier after separation and enhancement, corresponding to the first time step in the b-th window. This is the embedded vector of the CAN identifier after separation and enhancement, corresponding to the second time step in the b-th window. For the th window b, the th Each time step corresponds to the embedded vector of the CAN identifier after separation and enhancement. Pooling operations are performed to aggregate the CAN identifier embedding of the window in-graph.

[0074] In S25, the first The first window Sequence after time step graph knowledge injection for:

[0075] ;

[0076] in, For the first The first window The original sequence features at each time step For learnable gating coefficients, This represents the number of messages contained in the sliding window.

[0077] Furthermore, in S3, the Mamba encoder includes several layers of Mamba modules, and the Mamba modules are connected by Pre-Norm residual connections.

[0078] The first in the Mamba encoder Output of layer Mamba module for:

[0079] ;

[0080] in, For the Mamba encoder The output of the layer Mamba module, For the first Mamba modules in the layer, This is a layer normalization operation.

[0081] Furthermore, S4 includes the following sub-steps:

[0082] S41. Perform pooling operation on the sequence representation encoded by the Mamba encoder;

[0083] S42. Input the global representation after pooling operation into the fully connected classifier to obtain the category score;

[0084] S43. Use the Softmax function to convert the category scores into a normalized probability distribution;

[0085] S44. Determine the prediction category based on the normalized probability distribution.

[0086] Furthermore, in S41, the pooling operations include mean pooling, last-position pooling, maximum-position pooling, and attention pooling.

[0087] Furthermore, in S42, category scores for:

[0088]

[0089] in, This is the first layer weight matrix. For the first layer bias, This is the weight matrix for the second layer. For the second layer bias, for;

[0090] In S44, the predicted category is... for:

[0091] ;

[0092] in, For normalized probability distribution, for.

[0093] Based on the above methods, this invention also proposes a graph-aware state-space CAN bus intrusion detection system, comprising:

[0094] The data preprocessing and window generation module is used to preprocess CAN bus messages and construct a sliding window sequence;

[0095] The identifier relationship graph construction module is used to construct co-occurrence relationship graphs;

[0096] The edge-weighted graph enhancement module is used to construct temporal correlation graphs;

[0097] The fusion module is used to perform fusion and normalization processing to obtain a normalized fused adjacency matrix;

[0098] The gated broadcast injection module is used to perform context broadcast injection based on the normalized fused adjacency matrix to obtain the sequence after graph knowledge injection.

[0099] The selective state-space sequence encoding module is used to input the sequence after graph knowledge injection into the Mamba encoder for encoding;

[0100] The pooling and classification module is used to determine the predicted category based on the sequence representation encoded by the Mamba encoder.

[0101] The beneficial effects of this invention are:

[0102] 1. This invention constructs a CAN identifier relationship graph from normal communication traffic. The model can utilize the statistical co-occurrence relationship and temporal coordinated change relationship between different message types when processing the current message window, rather than relying solely on a single message field.

[0103] 2. This invention uses a separation mechanism to ensure that only known identifiers that have appeared in normal traffic participate in graph enhancement, and the identifiers are not assigned to the normal relation graph context, thereby reducing the risk of newly added identifiers being incorrectly propagated into normal graph relations.

[0104] 3. This invention injects graph relation priors into the sequence encoding process by using window-level graph context aggregation and gated broadcast injection, eliminating the need for the model to repeatedly perform full graph message propagation at each time step.

[0105] 4. The sequence processing part of the selective state space sequence encoding module of the present invention has an approximately linear complexity with respect to the window length, which can reduce the computational overhead of long sequence window encoding.

[0106] 5. The lightweight methods such as knowledge distillation that can be selected in this invention can reduce the number of model parameters and the model forward inference time, but the specific deployment adaptability needs to be determined in combination with the target hardware and end-to-end test conditions. Attached Figure Description

[0107] Figure 1 A flowchart of a CAN bus intrusion detection method for graph-aware state space;

[0108] Figure 2 A schematic diagram of the confusion matrix when the model was tested on the CHD dataset;

[0109] Figure 3 This is a schematic diagram of the ROC curve of the model tested on the CHD dataset;

[0110] Figure 4 This is a schematic diagram of the confusion matrix when the model is tested on the CHADC dataset.

[0111] Figure 5 This is a schematic diagram of the ROC curve of the model tested on the CHADC dataset. Detailed Implementation

[0112] The embodiments of the present invention will be further described below with reference to the accompanying drawings.

[0113] CAN: Controller Area Network.

[0114] CAN Identifier: An arbitration identifier in a CAN message, used to indicate the message type, priority, or function message.

[0115] DLC: Data Length Code.

[0116] IAT: Inter-Arrival Time, the time interval between message arrivals.

[0117] OOV: Out-of-Vocabulary, an index of unknown identifiers outside the vocabulary.

[0118] GAT: Graph Attention Network.

[0119] Mamba: Selective state-space sequence model.

[0120] Window-level graph context: A context vector obtained by graph-enhanced embedding aggregation of CAN identifiers within the current window.

[0121] Known identifiers: CAN identifiers that have appeared in normal traffic during the training phase and participated in the construction of the relationship graph.

[0122] like Figure 1 As shown, this invention provides a CAN bus intrusion detection method based on graph-aware state space, comprising the following steps:

[0123] S1. Preprocess the CAN bus messages, construct the co-occurrence relationship diagram and timing correlation diagram, and perform fusion and normalization processing to obtain the normalized fused adjacency matrix.

[0124] S2. Based on the normalized fused adjacency matrix, perform context broadcast injection to obtain the sequence after graph knowledge injection;

[0125] S3. Input the sequence after graph knowledge injection into the Mamba encoder for encoding;

[0126] S4. Determine the predicted category based on the sequence representation encoded by the Mamba encoder.

[0127] This invention constructs statistical co-occurrence relationships and time-slice-aligned temporal cooperative change relationships between CAN identifiers from normal CAN communication traffic, forming a trusted CAN identifier relationship graph; graph enhancement is performed only on known CAN identifiers appearing in normal traffic, while non-graph enhancement representations are retained for OOV identifiers; then, the graph enhancement identifier representations within the current message window are aggregated into a window-level graph context, which is injected into each message time step via learnable gated broadcast, and finally input into a selective state space sequence encoding module for intrusion detection.

[0128] This invention adds a graph context generation and gated broadcast injection module before Mamba sequence encoding, enabling the sequence model to utilize the structural priors formed by normal communication relationships.

[0129] Graph neural networks can aggregate information about graph structure nodes and their neighbors. Existing methods have disclosed schemes such as CAN identifier graph construction, graph neural network anomaly detection, and the combination of graph structures and long sequence models. Compared with these schemes, the focus of this invention is not on using GAT or Mamba alone, but on: constructing a trusted CAN identifier relationship graph from normal traffic, performing edge-weighted graph enhancement only on known identifiers, and aggregating the graph-enhanced identifier representations within the current window into a window-level context, which is then injected into a selective state-space sequence encoding module via gated broadcast.

[0130] First, the original CAN message undergoes field parsing, numericalization, normalization, and windowing to obtain a fixed-length message feature sequence and a frame-by-frame CAN identifier index within the window. Then, a CAN identifier relationship graph is constructed from normal CAN communication traffic. This graph integrates statistical co-occurrence relationships and temporal co-variance relationships aligned to a fixed time slice. During model inference, known CAN identifiers are used to generate graph-enhanced embeddings through an edge-weighted graph attention network, while OOV identifiers retain their original embeddings or unified OOV embeddings. All identifier embeddings within the window are pooled to obtain a window-level graph context, which is then injected with features at each time step via learnable gated broadcasting. Finally, this is input into a selective state-space sequence encoding module, which outputs several categories or anomaly scores.

[0131] In this invention, the CAN identifier is used to represent message type, priority, or function message. It is not directly equivalent to the unique identity of the sending ECU, nor is it used to directly infer the vehicle's physical topology. The relationship graph constructed from normal traffic represents the statistical co-occurrence relationship and temporal cooperative change relationship between different message types, which belongs to the structural prior that the model can utilize.

[0132] In this embodiment of the invention, S1 includes the following sub-steps:

[0133] S11. Convert the heterogeneous fields of the CAN bus message into numerical features and complete them;

[0134] S12. After the completion process, construct the input features;

[0135] S13. Normalize the input features and construct a sliding window sequence;

[0136] S14. Based on the number of times any two CAN identifiers co-occur in the same window of the sliding window sequence, obtain the co-occurrence count matrix and construct the co-occurrence relationship graph;

[0137] S15. Obtain the equal-length message rate vector of the identifier based on the message rate of the identifier. After standardizing the equal-length message rate vector, determine the temporal relationship edge weights based on the normalized equal-length message rate vector of the identifier, and construct a temporal correlation graph.

[0138] S16. Merge the row-normalized adjacency matrix of the co-occurrence relation graph and the row-normalized adjacency matrix of the temporal correlation graph to obtain a merged adjacency matrix, and then normalize the merged adjacency matrix to obtain a normalized merged adjacency matrix.

[0139] CAN bus messages contain heterogeneous fields: the CAN identifier is an 11-bit or 29-bit hexadecimal identifier, the data payload is a maximum of 8 bytes of hexadecimal value, and the timestamp is a floating-point number with second-level precision. The preprocessing process first converts the data into numerical characteristics; when the data length is less than 8 bytes, it is padded with 0s to fill the corresponding bytes.

[0140] For datasets with timestamp information, this application employs an online causal approach to extract the arrival time interval and time regularity of the same ID. Online causality refers to... The time signature of a message uses only the current message timestamp and the CAN identifier. Historical message states that have arrived before a certain time are not used; future messages are not used, nor are entire sequence backfill statistics used.

[0141] In this embodiment of the invention, in S12, if the dataset in the CAN bus information has a timestamp, the ID arrival time interval and time regularity are calculated, and input features are constructed based on the identifier, data length code, bytes 0 to 7 of the data field, ID arrival time interval and time regularity; otherwise, input features are constructed based on the identifier, data length code and bytes 0 to 7 of the data field.

[0142] ID arrival time interval for:

[0143] ;

[0144] in, Let be the CAN identifier of the t-th message. For timestamps, For the first The timestamp of the most recent historical message with the same CAN identifier as the current message before the current message arrived;

[0145] when At that time, the IAT statistics of the CAN identifier are updated using the Welford online update method:

[0146] ;

[0147] ;

[0148] ;

[0149] in, The number of valid IAT samples. This represents the online average arrival time interval of the CAN identifier before this online update.

[0150] When the number of valid historical IATs for the same CAN identifier reaches Calculate the online coefficient of variation and time regularity, where, The minimum number of valid IDs required to begin calculating the online coefficient of variation and time regularity is the threshold of the time interval between arrivals.

[0151] like or online average If the time regularity is close to 0, the time regularity is set to the default value of 0.5. The closer the time regularity is to 1, the more stable the observed transmission intervals of the CAN identifier; the lower the time regularity, the stronger the fluctuations in the current and historical arrival intervals. This calculation method is consistent with online detection and does not use global median truncation or full-sequence IAT coefficient of variation backfilling, thus it does not introduce future information.

[0152] Time regularity for:

[0153] ;

[0154] ;

[0155] ;

[0156] in, The online coefficient of variation, For identifiers The online standard deviation of the ID arrival time interval. The online average, It is the numerical stability constant. It is a second-order cumulant. Number of valid IAT samples;

[0157] Datasets with timestamps use 12-dimensional input features; datasets without timestamps omit these features. and The system comprises 10 features. In this invention, the CAN identifier is used to identify message type, priority, or function message; the feature encoding stage does not assume that one CAN identifier uniquely corresponds to one ECU, nor does it directly infer the vehicle's physical topology from the CAN identifier.

[0158] In S13, Min-Max normalization is used to scale all features to the [0,1] interval to eliminate the impact of dimensional differences on gradient optimization.

[0159] ;

[0160] in, These are the normalized eigenvalues. The minimum value of the corresponding feature dimension in the training set. The maximum value of the corresponding feature dimension in the training set. These are the original eigenvalues ​​before normalization;

[0161] Normalized parameters ( and To avoid data leakage during the evaluation phase, based on fitting the entire training data, the experimental implementation first divides the original packets into training and test sets according to chronological order or the original log order, and then generates sliding windows within each set. The normalizer only fits the features of the training set packets, and is subsequently used to transform the training, validation, and test sets. Class balancing, oversampling, or undersampling are performed only on the training set window, while the test set maintains its natural class distribution.

[0162] A sliding window of fixed length 16 is used to segment the continuous CAN message stream into sequential samples. Let the original CAN message stream be... for ,in, This is the first message. For the second message, the t-th message It includes a CAN identifier, a data length code, and an 8-byte data payload.

[0163] In a binary classification task, if any attack packet exists within a window, the window is labeled as an attack; if all packets within the window are normal, the window is labeled as normal. In a multi-class classification task, if an attack packet exists within a window, the window label can be determined using the first attack category, the category with the highest percentage, or a preset category priority. This embodiment uses the first attack category rule to respond to the attack category that first appears within the window in an online detection scenario, specifically:

[0164] ;

[0165] in, For the first Category labels for a sliding window sample.

[0166] This strategy ensures that the detection system does not miss attacks because some messages within the window appear normal.

[0167] CAN bus data inherently suffers from severe class imbalance, with normal messages making up the vast majority. To mitigate this problem, a truncated sampling strategy is adopted: a maximum of 500,000 samples per class is set, with random undersampling performed on the excess and random oversampling performed on the insufficient portion.

[0168] All CAN identifiers appearing in the normal traffic of the training set are extracted to form a set of known CAN identifiers. A compact mapping is constructed to map each ID in the set of known CAN identifiers to a consecutive integer index, while all IDs in the set of unknown CAN identifiers are uniformly mapped to OOV (out-of-vocabulary) indices. The core motivation of this design is that graph structure knowledge should only be learned from trusted normal traffic, and unknown CAN identifiers (which may come from attack traffic) should not obtain graph association information.

[0169] In S13, the sliding window sequence of the first... window for:

[0170] ;

[0171] in, For sliding window index, For the first One CAN message, For the first One CAN message, For the first One CAN message, This represents the number of messages contained in the sliding window.

[0172] In S14, the co-occurrence graph is constructed based on the following observation: In normal communication traffic, some function-related or communication behavior-related message types may exhibit stable co-occurrence patterns within adjacent windows. Therefore, a fixed message count window or a fixed time window can be used to scan normal messages, and the number of times any two CAN identifiers co-occur in the same window can be counted to obtain a co-occurrence count matrix. A sliding window with a window size of 100 messages and a step size of 50 messages is used to scan the normal CAN log, and the frequency of any two CAN identifiers co-occurring in the same window is counted. The co-occurrence graph is used to represent the statistical co-occurrence relationship between CAN identifiers, and does not directly represent the physical connection relationship of the ECU. Window size, step size, minimum co-occurrence threshold, self-loop weight, and normalization method can all be used as parameters in the implementation example and adjusted according to the target vehicle or dataset.

[0173] Elements of the co-occurrence counting matrix for:

[0174] ;

[0175] in, The total number of windows, For the first A set of CAN identifiers within a window. For indicator functions, CAN identifier , CAN identifier ;

[0176] Indicator function, takes the value 1 if the condition is true, otherwise takes the value 0.

[0177] The following post-processing is performed on the counting matrix:

[0178] Symmetrization: For any identifier, take To ensure the undirectedness of the graph, where, The first co-occurrence number in the co-occurrence counting matrix Line number The elements of a column, i.e., identifiers. with identifier The number of times they appear together in the same statistical window. To obtain the maximum value.

[0179] Adding on a loop: Set the diagonal element to 0.5 times the size of the largest off-diagonal element. ,in, Identifiers in the co-occurrence counting matrix The corresponding diagonal element is its self-loop weight.

[0180] L1 row normalization: Perform L1 normalization on each row to obtain a stable attention distribution. :

[0181] ;

[0182] in, The first co-occurrence number in the co-occurrence counting matrix Line number Column elements, The total number of known CAN identifiers that participate in the construction of the relationship graph.

[0183] In S15, the co-occurrence relationship mainly describes whether different CAN identifiers appear together in adjacent message windows, which is insufficient to reflect the coordinated changes in the transmission rates of different message types over time. Therefore, this embodiment uses a fixed-time-slice message rate correlation to construct a timing correlation diagram to represent the coordinated changes in the transmission rates of different CAN identifiers under normal communication conditions. This relationship is a statistical correlation and does not represent the physical connection between ECUs, nor is it used to infer causal relationships. This application uses a fixed-time-slice message rate correlation to construct the timing correlation diagram. This method first aligns the normal traffic to time slices, and then calculates the correlation coefficient on an equal-length vector to describe the coordinated changes in the transmission rates of different CAN identifiers under normal communication conditions. This relationship only represents statistical correlation and is not interpreted as physical linkage or causal relationship between ECUs.

[0184] identifier message rate for:

[0185] ;

[0186] in, For identifiers The number of messages, The length of a continuous time slice, The number of consecutive time slices;

[0187] In S15, the identifier Equal-length message rate vector for:

[0188] ;

[0189] in, The first time slice identifier message rate, For the second time slice identifier message rate, For the third time slice identifier message rate, For the first Time slice identifier Message rate;

[0190] In S15, the temporal relation edge weights for:

[0191] ;

[0192] in, For identifiers with identifier The time-series correlation coefficient between them For threshold;

[0193] When an identifier appears too infrequently in an effective time slice, or its message rate variance is close to zero, the temporal correlation edge between the identifier and other identifiers is not calculated, or the weight of the corresponding edge is set to 0, in order to avoid unstable correlation values ​​generated by sparse samples or constant sequences.

[0194] In S16, the elements of the merged adjacency matrix are... for:

[0195] ;

[0196] in, The elements of the row-normalized adjacency matrix of the co-occurrence graph are... These are the elements of the row-normalized adjacency matrix of the temporal cooperative change graph. This is the fusion coefficient.

[0197] Identifier Not participating in identifiers Neighbors gather, This indicates that there is a relationship edge between the two obtained from normal traffic statistics, and the value indicates the relative strength of this relationship in subsequent graph attention aggregation.

[0198] To ensure the stability of edge weights across different nodes, L1 normalization is performed on each row after merging.

[0199] ;

[0200] in, To merge the adjacency matrix of the first... Line number The elements of the column.

[0201] The fused adjacency matrix is ​​constructed only on the set K of known CAN identifiers that appear in normal traffic; unknown or attack-specific IDs are mapped to OOV slots and are not assigned edges in the normal relationship graph. This design avoids the pollution of the prior knowledge of normal communication relationships by forged IDs or anomalous co-occurrence patterns in attack traffic.

[0202] In this embodiment of the invention, S2 includes the following sub-steps:

[0203] S21. Determine a dense embedding vector for each CAN identifier and generate a CAN identifier embedding.

[0204] S22. A lightweight graph attention network is constructed using the normalized fused adjacency matrix, and the CAN identifier embedding is enhanced using the lightweight graph attention network.

[0205] S23. Based on the enhanced CAN identifier embedding, perform separation enhancement;

[0206] S24. After separation enhancement, calculate the graph context vector and generate the projection result based on the graph context vector;

[0207] S25. Based on the projection results and learnable gating coefficients, perform context broadcast injection to obtain the sequence after graph knowledge injection.

[0208] The graph-aware knowledge injection module transforms the CAN identifier relationship graph formed by normal communication traffic into a window-level context bias in the sequence model input space, enabling the sequence encoding module to utilize both message field features and structural priors formed by normal communication relationships when processing the current message window.

[0209] A learnable dense embedding vector is assigned to each CAN identifier (including the OOV index). The embedding matrix is ​​initialized uniformly using Xavier and optimized via backpropagation during end-to-end training. Each embedding vector corresponds to a CAN identifier index or OOV index, representing a learnable feature of the message type in the detection task. This embedding does not represent the unique identity of the ECU.

[0210] Design a single-layer, multi-head, lightweight graph attention network to enhance CAN identifier embedding using a fused adjacency matrix. This module is implemented purely in PyTorch, without relying on external graph neural network libraries, and is suitable for small-scale CAN identifier graphs and automotive embedded deployments.

[0211] The attention head first performs a linear transformation on the node features, then calculates unnormalized attention scores for the nodes and their neighbors. Normalized weights based on these attention scores are first obtained within the neighbor set. Unlike GAT, which only uses a binary mask, this application explicitly multiplies the continuous edge weights in the fused adjacency matrix into the attention weights and normalizes them again to determine the aggregated output of the attention head. After concatenating the multi-head outputs, the results are activated by an ELU and connected to the original embedding residual to obtain the graph-enhanced node representation. This residual connection preserves the original CAN identifier embedding information, allowing GAT to learn incremental relational information from graph neighbors, rather than completely replacing the original representation with the graph aggregation result.

[0212] To ensure the reliability of graph knowledge, GAT enhancement is applied only to known CAN identifiers appearing in normal traffic, while unknown CAN identifiers (OOV, which may come from attack traffic) retain their original embedding. The theoretical basis for this design is: (1) The graph structure is entirely built from normal traffic, and the associations of attack-specific CAN identifiers on the graph are unreliable. They have never appeared in normal driving, so their true physical associations with other ECUs are unknown; (2) Attackers may bypass graph-based detection by forging new CAN identifiers, so false graph association information should not be assigned to them; (3) Excluding unknown CAN identifiers from graph attention is a conservative security strategy to prevent attackers from using graph mechanisms for adversarial attacks.

[0213] For an input window containing several message time steps, the model first reads the node representations output by the graph attention network based on the CAN identifiers corresponding to each time step within the window, and then obtains the graph context vector for that window through pooling. The graph context vector is then broadcast into each time step within the window using gating coefficients. This "broadcasting" refers to copying the same window-level graph context vector to several time step positions within the window for element-wise addition. Therefore, changes in window length do not additionally amplify the graph context bias magnitude.

[0214] In this embodiment of the invention, in S22, the graph augmentation node representation of the lightweight graph attention network... for:

[0215] ;

[0216] ;

[0217] ;

[0218] ;

[0219] ;

[0220] ;

[0221] in, The aggregated output of the first attention head. This is the aggregated output of the h-th attention head. This is the aggregated output of the Hth attention head. This is a vector concatenation operation. It is the activation function of the exponential linear unit. For nodes CAN identifier embedding, Gather for the neighbors, For the first The nodes in each attention head are adjusted by the edge weights of the fused adjacency matrix. For neighboring nodes Attention coefficient For the first Nodes in each attention head The node representation after linear transformation For the first Neighboring nodes in each attention head The node representation after linear transformation To merge nodes in the adjacency matrix with neighboring nodes The corresponding element, To merge nodes in the adjacency matrix With nodes The corresponding element, For the first Attention Head Nodes with neighboring nodes Attention score normalization weights, For the first Attention Head Nodes With nodes Attention score normalization weights, It is the numerical stability constant. For the first Nodes in each attention head with neighboring nodes Unnormalized attention scores between them For the first Nodes in each attention head With nodes Unnormalized attention scores between them For the activation function of the linear unit with leakage correction, For the first A learnable attention vector for each attention head. For the first The learnable linear transformation matrix of each attention head It is an exponential function. For transpose;

[0222] In S23, the separation enhancement is specifically performed as follows:

[0223] ;

[0224] in, CAN identifier The enhanced embedding vector after separation CAN identifier The original embedding vector, This is the normalized fused adjacency matrix. Graph augmentation computation for lightweight graph attention networks. It is a set of known CAN identifiers that appear in the normal traffic during the training phase;

[0225] In S24, the projection result for:

[0226] ;

[0227] ;

[0228] in, For layer normalization operation, The weight matrix is ​​the projection of the graph context. For the first The graph context vector of each window, Let be the bias vector of the graph context projection. This is the embedded vector of the CAN identifier after separation and enhancement, corresponding to the first time step in the b-th window. This is the embedded vector of the CAN identifier after separation and enhancement, corresponding to the second time step in the b-th window. For the th window b, the th Each time step corresponds to the embedded vector of the CAN identifier after separation and enhancement. Pooling operations are performed to aggregate the CAN identifier embedding of the window in-graph.

[0229] In S25, the first The first window Sequence after time step graph knowledge injection for:

[0230] ;

[0231] in, For the first The first window The original sequence features at each time step For learnable gating coefficients, This represents the number of messages contained in the sliding window.

[0232] In this embodiment of the invention, in S3, the Mamba encoder includes several layers of Mamba modules, and each layer of Mamba modules is connected by a Pre-Norm residual connection.

[0233] The first in the Mamba encoder Output of layer Mamba module for:

[0234] ;

[0235] in, For the Mamba encoder The output of the layer Mamba module, For the first Mamba modules in the layer, This is a layer normalization operation.

[0236] The sequence after graph knowledge injection is fed into the Mamba encoder for time series modeling. Mamba belongs to the family of structured state-space sequence models, and its continuous-time dynamics equations are described by a linear time-invariant system.

[0237] ;

[0238] ;

[0239] in, A continuous-time hidden state vector Regarding time The first derivative, It is a continuous-time hidden state vector. For input signal, This is the output signal. Here is the state transition matrix. For the input projection vector, To output the projection vector, For pass-through scalars.

[0240] Mamba's core innovation compared to traditional models lies in its introduction of an input-dependent selectivity mechanism. This mechanism makes the state-space parameters and discretization step size dependent on the current input, thereby enabling dynamic selective memorization or forgetting of sequence content. Specifically:

[0241] ;

[0242] in, For the first Each time step generates input projection parameters from the current input. For the first The output projection parameters generated by the current input at each time step For the first The input at each time step depends on the discretization step size. These are state-space selectivity parameters. , and Both are input-dependent learnable linear projection functions. It is a softplus activation function to ensure that the discretization step size is always positive.

[0243] To process discrete sequence data on a digital computer, the continuous-time state-space equations need to be discretized. A zero-order preserve discretization rule is adopted:

[0244]

[0245]

[0246] in, A continuous-time state transition matrix The discrete state transition matrix obtained after discretization Input projection parameters for continuous time Discrete input parameters obtained after discretization To discretize the step size, For matrix exponentiation operations, It is the identity matrix. The discretized recursive form is:

[0247] ;

[0248] ;

[0249] in, For the first Discrete hidden state vectors at each time step For the first Discrete state transition matrix corresponding to each time step For the first Discrete input parameters corresponding to each time step For the first The output vector at each time step.

[0250] Selective mechanisms are particularly crucial for CAN bus intrusion detection: (1) Normal periodic messages (such as engine speed sent at 10ms intervals) should be selectively memorized to establish baseline behavior patterns, and the model should allocate a smaller number of such messages. (Slow update state); (2) Deviations in the characteristics of abnormal messages (such as high-frequency flooding of DoS attacks or random data of Fuzzy attacks) should trigger larger state updates to mark potential attacks, and the model should assign larger values ​​to such messages. (Update status soon).

[0251] Mamba achieves parallel computation of the entire sequence through a parallel scanning algorithm, significantly outperforming the time and space complexity of the Transformer's self-attention mechanism. This enables GAMamba to efficiently process long CAN message sequences in automotive embedded environments.

[0252] To enhance the model's expressive power, multiple layers of Mamba modules are stacked in depth. Pre-Norm residual connections between layers (i.e., normalization before sub-layer computation, and finally addition with the input) stabilize the training of deep networks. The Pre-Norm design allows gradients to be directly backpropagated to shallow layers along the residual path (skip connections), effectively alleviating the gradient vanishing and training instability problems of deep networks.

[0253] The basic configuration of the teacher model is as follows: hidden dimension of 128, state space dimension of 40, convolutional kernel width of 4, channel expansion factor of 2, and number of Mamba layers of 2. This configuration results in approximately 288K parameters and approximately 53.6K FLOPs (calculated with a 16-window architecture), achieving a good balance between model capacity and inference efficiency.

[0254] Ablation experiments show that residual connections make a significant positive contribution to both training convergence speed and final accuracy. A 3-layer Mamba configuration without residual connections is inferior to a 2-layer configuration with residual connections in both convergence speed and final accuracy.

[0255] In this embodiment of the invention, S4 includes the following sub-steps:

[0256] S41. Perform pooling operation on the sequence representation encoded by the Mamba encoder;

[0257] S42. Input the global representation after pooling operation into the fully connected classifier to obtain the category score;

[0258] S43. Use the Softmax function to convert the category scores into a normalized probability distribution;

[0259] S44. Determine the prediction category based on the normalized probability distribution.

[0260] In this embodiment of the invention, S41 includes average pooling, last-position pooling, maximum-position pooling, and attention pooling.

[0261] Mean pooling: This method uses equal-weighted averaging across all time steps, resulting in the lowest computational complexity and is the default choice for teacher models.

[0262] ;

[0263] in, This is the global sequence representation after pooling. The number of time steps contained in the current input window. For the last layer of the Mamba encoder in the first The output representation at each time step.

[0264] Last-order pooling: only takes the representation of the last time step of the sequence.

[0265] ;

[0266] Max pooling: Takes the maximum value across all time steps for each feature dimension.

[0267] ;

[0268] in, For the Bureau to express The Each feature dimension value, For the last layer of the Mamba encoder in the first The output vector at time step i is the first... Each feature component;

[0269] Attention Pooling: Learnable CLS query tags are introduced to adaptively aggregate information from key time steps through a multi-head self-attention mechanism.

[0270] Experimental results show that there is no significant performance difference between different pooling strategies. Mean pooling achieves comparable performance with the lowest computational cost to other methods. Therefore, the teacher model adopts mean pooling.

[0271] The pooled global representation outputs five intrusion detection logits through a two-layer fully connected classifier. The output can also be replaced with binary classification results or anomaly scores. The hidden layers use the ReLU activation function, and Dropout regularization is applied between the two linear layers to prevent overfitting.

[0272] The final class probabilities are converted into a normalized probability distribution using the Softmax function, and the predicted class is the one with the highest probability.

[0273] In this embodiment of the invention, in S42, the category score... for:

[0274]

[0275] in, This is the first layer weight matrix. For the first layer bias, This is the weight matrix for the second layer. For the second layer bias, for;

[0276] In S44, the predicted category is... for:

[0277] ;

[0278] in, For normalized probability distribution, for.

[0279] Based on the above methods, this invention also proposes a graph-aware state-space CAN bus intrusion detection system, comprising:

[0280] The data preprocessing and window generation module is used to preprocess CAN bus messages and construct a sliding window sequence;

[0281] The identifier relationship graph construction module is used to construct co-occurrence relationship graphs;

[0282] The edge-weighted graph enhancement module is used to construct temporal correlation graphs;

[0283] The fusion module is used to perform fusion and normalization processing to obtain a normalized fused adjacency matrix;

[0284] The gated broadcast injection module is used to perform context broadcast injection based on the normalized fused adjacency matrix to obtain the sequence after graph knowledge injection.

[0285] The selective state-space sequence encoding module is used to input the sequence after graph knowledge injection into the Mamba encoder for encoding;

[0286] The pooling and classification module is used to determine the predicted category based on the sequence representation encoded by the Mamba encoder.

[0287] In this embodiment of the invention, label smoothing cross-entropy loss is used to soften the training target in order to prevent the model from becoming overconfident in the training labels. For a smoothing factor of 0.05, the target distribution changes from one-hot hard labels... Adjusted to:

[0288] ;

[0289] in, The label smoothing factor is set to 0.05 in this embodiment. For the true class label of the sample, For category indexing.

[0290] The mechanism of label smoothing is as follows: absolutely correct hard labels (one-hot vectors) encourage the model to push the logit of the correct class to infinity, resulting in an overly sharp decision boundary and decreased generalization performance. Label smoothing retains a small amount of uncertainty in the target distribution, forcing the model to learn a smoother decision boundary, thereby achieving better calibration and generalization performance on the test set. Ablation experiments show that label smoothing contributes approximately 0.17 percentage points to the accuracy improvement in high-precision scenarios.

[0291] Cross-entropy loss function Defined as:

[0292] ;

[0293] in, The total number of categories, It is a logarithmic function. This is the true category.

[0294] Optimizer configuration: The AdamW optimizer is used with momentum parameters of 0.9 and 0.98, and a weight decay coefficient of 0.05. Learning rate scheduling employs a 5-epoch linear warm-up followed by cosine annealing to the minimum learning rate. Strategy:

[0295] ;

[0296] in, For the first The learning rate corresponding to each training epoch. For training rounds, Based on the learning rate, To minimize the learning rate, This is the maximum number of training rounds.

[0297] Other training strategies include:

[0298] FP16 Automatic Mixed Precision: Uses half-precision floating-point numbers to accelerate forward and backward propagation calculations while maintaining FP32 precision for critical operations to ensure numerical stability;

[0299] Gradient clipping: Clip the L2 norm of all parameter gradients to 1.0 to prevent gradient explosion;

[0300] Gaussian noise online augmentation: The training data is perturbed online with Gaussian noise of zero mean and standard deviation of 0.005 to improve the robustness of the model to input noise;

[0301] Early stopping mechanism: Monitor the macro-average F1-score of the validation set. If there is no improvement after 25 consecutive epochs, terminate training and restore the optimal model weights.

[0302] The above classification training can use window samples with category labels.

[0303] The statement in this invention that it does not rely on human priors means that the relationship graph construction stage does not require manual provision of ECU topology or DBC files, and does not mean that the entire classification model does not use labeled data at all.

[0304] In an optional embodiment, to reduce the number of model parameters and the model's forward inference time, a lightweight student model can be obtained using teacher-student knowledge distillation. Knowledge distillation, as a subordinate lightweight implementation, does not change the core chain of this invention: "trustworthy relationship graph—window-level graph context—gated broadcast injection—selective state-space sequence detection." By using knowledge distillation technology to compress the large teacher model into a lightweight student model, the number of model parameters and inference latency are significantly reduced while maintaining high detection accuracy.

[0305] The teacher model uses a full GAMamba configuration with approximately 288K parameters. The student model is compressed into a compact architecture with only about 19K parameters. The student model removes attention pooling (replacing it with mean pooling) while retaining the core functionality of the graph injection module.

[0306] Distillation loss loss due to hard label cross-entropy KL divergence loss with soft labels Weighted composition:

[0307] ;

[0308] in, and The logits output for the student model and the teacher model are respectively. For real hard labels, For temperature parameters, For hard label weights. Temperature parameter controls the smoothness of soft labels: high temperature ( Large (high) levels tend to even out the distribution of teacher output, revealing subtle differences between categories; low temperature ( The smaller value makes the soft label sharper, approaching the hard label. The τ² multiplier before the KL divergence is used to compensate for the gradient scaling effect caused by temperature scaling.

[0309] Temperature parameters A cosine annealing strategy is used to gradually reduce the value from an initial value of 8.0 to a final value of 2.0:

[0310] ;

[0311] in, For the first Temperature parameters corresponding to each training round This is the final value of the temperature parameter. These are the initial values ​​for the temperature parameters. =8.0, =2.0, This represents the total number of epochs in the first phase.

[0312] Hard label weight It increases linearly from 0.3 to 0.8:

[0313] ;

[0314] in, For the first The hard-label loss weights corresponding to each training round;

[0315] This scheduling causes students to rely more on teacher soft labels to acquire implicit knowledge in the early stages of training (at this time) big, (small), in the later stages of training, more reliance is placed on real hard labels for fine calibration (at this time) Small, big).

[0316] Distillation training is divided into two stages:

[0317] The first stage (distillation stage), accounting for approximately 65% ​​of the total iterations, involves training using the full distillation loss while simultaneously learning hard labels and teacher soft labels. The optimizer learning rate is based on the base learning rate, and the weights decay to 0.05.

[0318] The second stage (fine-tuning stage), accounting for approximately 35% of the total iterations, involves fine-tuning using only hard-labeled cross-entropy loss, with the learning rate reduced to... Weight decay decreased to This is to further calibrate the decision boundary of the student model on the target data distribution and eliminate any bias that may be introduced during the distillation process.

[0319] This invention is primarily validated on two publicly available vehicle CAN bus intrusion detection datasets: the Car-Hacking Dataset (CHD) and the CarHacking: Attack & Defense Challenge 2020 Dataset (CHADC).

[0320] The CHD dataset is collected from real vehicle CAN bus communication environments and includes normal communication data as well as data from various typical injection attacks. This dataset covers five scenarios: Normal, DoS, RPM Spoofing, Fuzzy, and Gear Spoofing. It can be used to verify the model's ability to identify denial-of-service attacks, random injection attacks, and targeted spoofing attacks targeting RPM and gear signals.

[0321] The CHADC dataset is also a publicly available CAN intrusion detection benchmark dataset, containing five data categories: Normal, Flooding, Replay, Fuzzing, and Spoofing. Compared to CHD, CHADC provides more complete timestamp information, so in addition to the CAN identifier, DLC, and 8-byte payload, it can also extract timing features such as the arrival time interval between adjacent messages with the same CAN identifier and the time regularity score.

[0322] This invention uses a fixed-length window to construct the input sequence, with a preferred window length of 16. If all messages within the window are normal, the window is labeled "Normal"; if an attack message exists within the window, the first attack category in the window is used as the window label. This method can simulate online vehicle intrusion detection scenarios, enabling the model to promptly detect malicious messages within a short communication segment.

[0323] On the CHD dataset, the teacher model has 287,562 parameters and an accuracy of 99.9730%. The student model, after knowledge distillation, has 19,128 parameters, a compression ratio of approximately 15.03 times, an accuracy of 99.9546%, a single-window inference time of approximately 15.22 microseconds, and approximately 12.420K FLOPs. The student model's single-class accuracy on Normal, DoS, RPM, Fuzzy, and Gear categories is approximately 99.9827%, 99.9867%, 100%, 99.7920%, and 99.9987%, respectively.

[0324] In the multi-class classification experiments on the CHADC dataset, the GAMamba student model achieved an accuracy of 99.85%, an F1 score of 99.89%, a single-window inference time of approximately 16.46 microseconds, approximately 20.1K parameters, and approximately 13.70K FLOPs, significantly lower than comparable models such as MobileNet, CNN, HyDL-IDS, and DCNN. In the binary attack detection experiments, it achieved near-perfect scores against attacks such as Flooding, Fuzzing, and Spoofing, and also achieved an F1 score of approximately 0.9971 against the more subtle Replay attack.

[0325] Ablation experiments show that the complete graph-aware structure outperforms variants without GAT, graph, and ID branches in replay attack detection; after removing the arrival time interval feature of the same CAN identifier, the replay F1-score drops significantly, indicating that the CAN identifier relationship graph and time features play a key role in the identification of covert replay attacks.

[0326] like Figure 2 As shown, the confusion matrix results of the student model on the CHD dataset indicate that the prediction results for each category are mainly concentrated on the diagonal of the confusion matrix. Specifically, the diagonal recognition ratios for normal, denial-of-service attack, speed spoofing attack, fuzzy attack, and gear shift spoofing attack categories are approximately 0.9998, 0.9999, 1.0000, 0.9979, and 1.0000, respectively, with an overall model accuracy of approximately 99.95%. Notably, the fuzzy attack category has a small number of instances where it is identified as either the normal or gear shift spoofing attack category; the confusion levels among the other categories are low, indicating that the student model can effectively distinguish normal CAN communication from different types of attack packets.

[0327] like Figure 3 As shown, the receiver operating characteristic curves of the student model for each category on the CHD dataset are all close to the upper left region of the coordinate graph. The area under the curve for the normal, denial-of-service attack, speed spoofing attack, fuzzy attack, and gear spoofing attack categories is approximately 1.0000, and the area under the curve for the macro-average is also approximately 1.0000, indicating that the student model has a high class discrimination ability under different discrimination thresholds.

[0328] like Figure 4As shown, the confusion matrix results of the student model on the CHADC dataset indicate that the diagonal recognition rates for normal, flooding attack, replay attack, fuzzy attack, and spoofing attack categories are approximately 0.9988, 1.0000, 0.9958, 0.9998, and 0.9998, respectively, with an overall model accuracy of approximately 99.85%. Notably, a small number of samples in the replay attack category were misclassified as normal, while the misclassification rates for the other categories were low, demonstrating that the student model possesses good classification and detection capabilities for different CAN bus attack types.

[0329] like Figure 5 As shown, the receiver operating characteristic (ROC) curves of the student model for each category on the CHADC dataset are generally close to the upper left region of the coordinate graph. Specifically, the area under the curve (AUC) for the normal, flooding attack, fuzzy attack, and deception attack categories is approximately 1.0000, the AUC for the replay attack category is approximately 0.9999, and the AUC for the macro-average category is approximately 1.0000, indicating that the student model has high overall classification and discriminative ability on the CHADC dataset.

[0330] Those skilled in the art will recognize that the embodiments described herein are intended to help the reader understand the principles of the invention, and should be understood that the scope of protection of the invention is not limited to such specific statements and embodiments. Those skilled in the art can make various other specific modifications and combinations based on the technical teachings disclosed in this invention without departing from the spirit of the invention, and these modifications and combinations are still within the scope of protection of this invention.

Claims

1. A CAN bus intrusion detection method based on graph-aware state space, characterized in that, Includes the following steps: S1. Preprocess the CAN bus messages, construct the co-occurrence relationship diagram and timing correlation diagram, and perform fusion and normalization processing to obtain the normalized fused adjacency matrix. S2. Based on the normalized fused adjacency matrix, perform context broadcast injection to obtain the sequence after graph knowledge injection; S3. Input the sequence after graph knowledge injection into the Mamba encoder for encoding; S4. Determine the predicted category based on the sequence representation encoded by the Mamba encoder.

2. The CAN bus intrusion detection method based on graph-aware state space according to claim 1, characterized in that, S1 includes the following sub-steps: S11. Convert the heterogeneous fields of the CAN bus message into numerical features and complete them; S12. After the completion process, construct the input features; S13. Normalize the input features and construct a sliding window sequence; S14. Based on the number of times any two CAN identifiers co-occur in the same window of the sliding window sequence, obtain the co-occurrence count matrix and construct the co-occurrence relationship graph; S15. Obtain the equal-length message rate vector of the identifier based on the message rate of the identifier. After standardizing the equal-length message rate vector, determine the temporal relationship edge weights based on the normalized equal-length message rate vector of the identifier, and construct a temporal correlation graph. S16. Merge the row-normalized adjacency matrix of the co-occurrence relation graph and the row-normalized adjacency matrix of the temporal correlation graph to obtain a merged adjacency matrix, and then normalize the merged adjacency matrix to obtain a normalized merged adjacency matrix.

3. The CAN bus intrusion detection method based on graph-aware state space according to claim 2, characterized in that, In S12, if the dataset in the CAN bus information has a timestamp, the ID arrival time interval and time regularity are calculated, and the input features are constructed based on the identifier, data length code, bytes 0 to 7 of the data field, ID arrival time interval and time regularity; otherwise, the input features are constructed based on the identifier, data length code and bytes 0 to 7 of the data field. The ID arrival time interval for: ; in, Let be the CAN identifier of the t-th message. For timestamps, For the first The timestamp of the most recent historical message with the same CAN identifier as the current message before the current message arrived; The time regularity for: ; ; ; in, The online coefficient of variation, For identifiers The online standard deviation of the ID arrival time interval. The online average, It is the numerical stability constant. It is a second-order cumulant. Number of valid IAT samples; In S13, the sliding window sequence of the first... window for: ; in, For sliding window index, For the first One CAN message, For the first One CAN message, For the first One CAN message, This represents the number of messages contained in the sliding window. In S14, the elements of the co-occurrence counting matrix for: ; in, The total number of windows, For the first A set of CAN identifiers within a window. For indicator functions, CAN identifier , CAN identifier ; In S15, the identifier message rate for: ; in, For identifiers The number of messages, The length of a continuous time slice, The number of consecutive time slices; In S15, the identifier Equal-length message rate vector for: ; in, The first time slice identifier message rate, For the second time slice identifier message rate, For the third time slice identifier message rate, For the first Time slice identifier Message rate; In S15, the temporal relation edge weights for: ; in, For identifiers with identifier The time-series correlation coefficient between them For the threshold; In step S16, the elements of the merged adjacency matrix are... for: ; in, The elements of the row-normalized adjacency matrix of the co-occurrence graph are... These are the elements of the row-normalized adjacency matrix of the temporal cooperative change graph. This is the fusion coefficient.

4. The CAN bus intrusion detection method based on graph-aware state space according to claim 1, characterized in that, S2 includes the following sub-steps: S21. Determine a dense embedding vector for each CAN identifier and generate a CAN identifier embedding. S22. A lightweight graph attention network is constructed using the normalized fused adjacency matrix, and the CAN identifier embedding is enhanced using the lightweight graph attention network. S23. Based on the enhanced CAN identifier embedding, perform separation enhancement; S24. After separation enhancement, calculate the graph context vector and generate the projection result based on the graph context vector; S25. Based on the projection results and learnable gating coefficients, perform context broadcast injection to obtain the sequence after graph knowledge injection.

5. The CAN bus intrusion detection method with graph-aware state space according to claim 4, characterized in that, In S22, the graph augmentation node representation of the lightweight graph attention network for: ; ; ; ; ; ; in, The aggregated output of the first attention head. This is the aggregated output of the h-th attention head. This is the aggregated output of the Hth attention head. This is a vector concatenation operation. It is the activation function of the exponential linear unit. For nodes CAN identifier embedding, Gather for the neighbors, For the first The nodes in each attention head are adjusted by the edge weights of the fused adjacency matrix. For neighboring nodes Attention coefficient For the first Nodes in each attention head The node representation after linear transformation For the first Neighboring nodes in each attention head The node representation after linear transformation, To merge nodes in the adjacency matrix with neighboring nodes The corresponding element, To merge nodes in the adjacency matrix With nodes The corresponding element, For the first Attention Head Node with neighboring nodes Attention score normalization weights, For the first Attention Head Nodes With nodes Attention score normalization weights, It is the numerical stability constant. For the first Nodes in each attention head with neighboring nodes Unnormalized attention scores between them For the first Nodes in each attention head With nodes Unnormalized attention scores between them For the activation function of the linear unit with leakage correction, For the first A learnable attention vector for each attention head. For the first Learnable linear transformation matrix for each attention head It is an exponential function. For transpose; In step S23, the separation enhancement specifically involves: ; in, CAN identifier The embedded vector after separation and enhancement CAN identifier The original embedding vector, This is the normalized fused adjacency matrix. Graph augmentation computation for lightweight graph attention networks. It is a set of known CAN identifiers that appear in the normal traffic during the training phase; In S24, the projection result for: ; ; in, For layer normalization operation, The weight matrix for the graph context projection. For the first The graph context vector of each window, Let be the bias vector of the graph context projection. For the first time step in the b-th window, the embedded vector of the CAN identifier after separation and enhancement is given. This is the embedded vector of the CAN identifier after separation and enhancement, corresponding to the second time step in the b-th window. For the th window b, the th Each time step corresponds to the embedded vector of the CAN identifier after separation and enhancement. Pooling operations are performed to aggregate the CAN identifier embedding of the window in-graph. In S25, the first The first window Sequence after time step graph knowledge injection for: ; in, For the first The first window The original sequence features at each time step For learnable gating coefficients, This represents the number of messages contained in the sliding window.

6. The CAN bus intrusion detection method based on graph-aware state space according to claim 1, characterized in that, In S3, the Mamba encoder includes several layers of Mamba modules, and each layer of Mamba modules is connected by a Pre-Norm residual connection. The Mamba encoder in the first Output of layer Mamba module for: ; in, For the Mamba encoder The output of the layer Mamba module, For the first Mamba modules in the layer, This is a layer normalization operation.

7. The CAN bus intrusion detection method based on graph-aware state space according to claim 1, characterized in that, S4 includes the following sub-steps: S41. Perform pooling operation on the sequence representation encoded by the Mamba encoder; S42. Input the global representation after pooling operation into the fully connected classifier to obtain the category score; S43. Use the Softmax function to convert the category scores into a normalized probability distribution; S44. Determine the prediction category based on the normalized probability distribution.

8. The CAN bus intrusion detection method with graph-aware state space according to claim 7, characterized in that, In S41, the pooling operations include mean pooling, last-position pooling, maximum-position pooling, and attention pooling.

9. The CAN bus intrusion detection method based on graph-aware state space according to claim 7, characterized in that, In S42, the category score for: ; in, This is the first layer weight matrix. For the first layer bias, This is the weight matrix for the second layer. For the second layer bias, To modify the activation function of the linear unit; In S44, the predicted category is... for: ; in, For normalized probability distribution, For all categories The operation selects the class with the highest predicted probability.

10. A graph-aware state-space CAN bus intrusion detection system, characterized in that, include: The data preprocessing and window generation module is used to preprocess CAN bus messages and construct a sliding window sequence; The identifier relationship graph construction module is used to construct co-occurrence relationship graphs; The edge-weighted graph enhancement module is used to construct temporal correlation graphs; The fusion module is used to perform fusion and normalization processing to obtain a normalized fused adjacency matrix; The gated broadcast injection module is used to perform context broadcast injection based on the normalized fused adjacency matrix to obtain the sequence after graph knowledge injection. The selective state-space sequence encoding module is used to input the sequence after graph knowledge injection into the Mamba encoder for encoding; The pooling and classification module is used to determine the predicted category based on the sequence representation encoded by the Mamba encoder.