Attack protection method and device for CAN bus

Encrypting CAN bus data using XOR and bitwise XOR operations solves the problem of CAN bus plaintext communication being vulnerable to sniffing attacks, achieving data transmission that balances security and real-time performance.

CN121486089APending Publication Date: 2026-02-06BEIJING TOPSEC NETWORK SECURITY TECH +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202512057453.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-31
Publication Date
2026-02-06

AI Technical Summary

Technical Problem

Plaintext broadcast communication on the CAN bus is vulnerable to sniffing attacks. Existing physical isolation methods cannot defend against wireless interface sniffing, which affects data transmission security and incurs high computational overhead.

Method used

The session key, CAN identifier, and serial number are processed using an XOR operation strategy. The data frame is encrypted using a bitwise XOR operation, and the obfuscated data is transmitted on the CAN bus. The target receiving node recovers the original data through reverse operation.

Benefits of technology

It effectively prevents sniffing attacks, reduces encryption computation overhead, lowers transmission latency, and improves the security of CAN bus data transmission.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121486089A_ABST
    Figure CN121486089A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of communication security, and provides an attack protection method and device for a CAN bus. The method comprises the following steps: according to a first exclusive-or operation strategy, performing exclusive-or operation on a session key, a CAN identifier corresponding to a current data frame and a serial number corresponding to the current data frame to obtain a transformation parameter; according to a second exclusive-or operation strategy, performing bitwise exclusive-or operation on the transformation parameter and the current data frame to obtain target data; and transmitting the target data to a target receiving node through the CAN bus, so that the target receiving node performs reverse transformation on the target data according to the second exclusive-or operation strategy and the first exclusive-or operation strategy in sequence to obtain a current data frame. According to the attack protection method for the CAN bus provided by the embodiment of the invention, the security of data transmission through the CAN bus can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of communication security, in particular to a CAN bus attack protection method and device. BACKGROUND

[0002] The CAN bus is a communication protocol widely used in automotive electronic systems, which adopts plaintext broadcast communication, and all nodes can read bus data. However, since the CAN bus adopts plaintext broadcast communication, sniffing attackers can capture sensitive information by accessing the bus, providing a basis for subsequent attacks.

[0003] Therefore, in related technologies, physical isolation such as limiting OBD-II access is usually used to prevent the access of sniffing devices. However, this method cannot prevent sniffing of wireless interfaces, resulting in ineffective prevention of sniffing attacks on the CAN bus and affecting the security of data transmission through the CAN bus. SUMMARY

[0004] The present application aims to at least solve one of the technical problems in the related art. To this end, the present application provides a CAN bus attack protection method, which can improve the security of data transmission through the CAN bus.

[0005] The CAN bus attack protection method according to the first aspect of the present application comprises: According to the first XOR operation strategy, the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are subjected to XOR operation to obtain a transformation parameter; According to the second XOR operation strategy, the transformation parameter and the current data frame are subjected to bitwise XOR operation to obtain target data; The target data is transmitted to a target receiving node through the CAN bus, so that the target receiving node sequentially performs reverse transformation on the target data according to the second XOR operation strategy and the first XOR operation strategy to obtain the current data frame; The target receiving node pre-stores the first XOR operation strategy and the second XOR operation strategy.

[0006] The session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are subjected to the exclusive OR operation according to the first exclusive OR operation strategy, to obtain a transformation parameter, and the transformation parameter and the current data frame are subjected to the bit-wise exclusive OR operation according to the second exclusive OR operation strategy, to obtain target data, which is transmitted to a target receiving node through the CAN bus, so that the target receiving node of the target data sequentially subjects the target data to reverse transformation according to the second exclusive OR operation strategy and the first exclusive OR operation strategy, to obtain the current data frame. Thus, the temporary session key, the CAN identifier, and the sequence number are combined by the exclusive OR operation and the bit-wise exclusive OR operation to encrypt the current data frame data, the encrypted current data frame is subjected to data transmission, sniffed data of an attacker is confused, and plaintext data is difficult to parse, to prevent sniffing attack on the CAN bus, while effectively reducing the calculation overhead required for encryption, reducing transmission delay, reducing the influence on real-time communication of the CAN bus, and further improving the security of data transmission through the CAN bus.

[0007] According to one embodiment of the present application, the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are subjected to the exclusive OR operation according to the first exclusive OR operation strategy, to obtain a transformation parameter, including: determining that the sending timestamp of the current data frame reaches a predetermined sending moment, and subjecting the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame to the exclusive OR operation according to the first exclusive OR operation strategy, to obtain the transformation parameter; wherein the predetermined sending moment is determined according to the message period determined according to the CAN identifier corresponding to the current data frame, and the sending timestamp of the last data frame with the same CAN identifier as the current data frame.

[0008] According to one embodiment of the present application, the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are subjected to the exclusive OR operation according to the first exclusive OR operation strategy, to obtain a transformation parameter, including: obtaining the sending time interval between the current data frame and the last data frame with the same CAN identifier as the current data frame; determining that the sending time interval is less than or equal to a preset delay interval, adjusting the sequence number corresponding to the last data frame according to a preset step, to obtain the sequence number corresponding to the current data frame; subjecting the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame to the exclusive OR operation according to the first exclusive OR operation strategy, to obtain the transformation parameter; wherein the preset delay interval is determined according to the CAN identifier corresponding to the current data frame.

[0009] According to one embodiment of the present application, further comprising: determining that the sending time interval is greater than the preset delay interval, and generating a sequence number corresponding to the current data frame according to a sending timestamp of the current data frame and a CAN identifier corresponding to the current data frame.

[0010] According to one embodiment of the present application, performing an exclusive OR operation on the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame according to a first exclusive OR operation strategy to obtain a transformation parameter, comprising: performing an exclusive OR operation on the session key and the CAN identifier to obtain a mixed value; performing a second exclusive OR operation on the mixed value and a target field of a transformation sequence number generated according to the sequence number to obtain the transformation parameter; wherein the transformation sequence number is generated by performing confusion processing on the sequence number according to at least one of a fixed coefficient and a fixed offset; the target field is extracted from the transformation sequence number according to a preset starting bit and a preset extraction length.

[0011] According to one embodiment of the present application, performing a bitwise exclusive OR operation on the transformation parameter and the current data frame according to a second exclusive OR operation strategy to obtain target data, comprising: segmenting the current data frame to obtain a first data block and a second data block; performing a bitwise exclusive OR operation on the first M bits of the N-bit transformation parameter and the first data block to obtain first intermediate data, and performing a bitwise exclusive OR operation on the last N-M bits of the N-bit transformation parameter and the second data block to obtain second intermediate data; obtaining the target data according to the first intermediate data and the second intermediate data.

[0012] According to one embodiment of the present application, obtaining the target data according to the first intermediate data and the second intermediate data, comprising: performing byte position exchange on the first intermediate data and the second intermediate data respectively to obtain first data and second data; performing data combination on the first data and the second data to obtain the target data.

[0013] According to one embodiment of the present application, further comprising: injecting a camouflage message into the CAN bus during an idle period in which the CAN bus does not transmit the target data.

[0014] According to one embodiment of the present application, injecting a camouflage message into the CAN bus, comprising: determine an injection frequency of the camouflage message according to a current load state of the CAN bus; inject the camouflage message into the CAN bus according to the injection frequency.

[0015] The electronic control unit according to the second aspect of the present application comprises a processor and a memory storing a computer program, and the processor implements the CAN bus attack protection method according to any one of the above embodiments when executing the computer program.

[0016] The computer readable storage medium according to the third aspect of the present application stores a computer program, and the computer program is executed by a processor to implement the CAN bus attack protection method according to any one of the above embodiments.

[0017] The computer program product according to the fourth aspect of the present application comprises a computer program, and the computer program is executed by a processor to implement the CAN bus attack protection method according to any one of the above embodiments. BRIEF DESCRIPTION OF DRAWINGS

[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments of the present application. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as a limitation on the scope, and for those skilled in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.

[0019] Figure 1 The first flowchart of the CAN bus attack protection method provided by the embodiments of the present application is shown in the figure. Figure 2 The second flowchart of the CAN bus attack protection method provided by the embodiments of the present application is shown in the figure. Figure 3 The structure diagram of the CAN bus attack protection device provided by the embodiments of the present application is shown in the figure. Figure 4 The structure diagram of the electronic device provided by the embodiments of the present application is shown in the figure. DETAILED DESCRIPTION

[0020] In order to make the purpose, technical solutions and advantages of the present application more clear, the following will combine the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the present application. Obviously, the described embodiments are some of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.

[0021] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the present application; the use of the terms "including," "comprising," "having" and "with" in the specification and claims hereof, along with their variants, are intended to be equivalent to the term "consisting of." The use of the term "about" in relation to a geographic location refers to a location within a 10 mile radius of the geographic location.

[0022] In the description of the embodiments of the present application, the technical terms "first", "second", etc. are only used to distinguish different objects, and cannot be understood as indicating or implying relative importance or implicitly indicating the number, specific order or primary and secondary relationship of the indicated technical features. In the description of the embodiments of the present application, the meaning of "a plurality of" is two or more, unless otherwise explicitly specified and limited.

[0023] Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearance of the phrase in various places in the specification does not necessarily all refer to the same embodiment, nor is it necessarily independent or alternative embodiments to each other. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0024] In the description of the embodiments of the present application, the term "and / or" is only a description of the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B, which means that there are three cases of A alone, A and B together, and B alone. In addition, the character " / " in this paper generally represents that the front and rear associated objects are a "or" relationship.

[0025] In the description of the embodiments of the present application, the term "a plurality of" refers to two or more (including two), and the same applies to "a plurality of".

[0026] In the description of the embodiments of the present application, unless otherwise explicitly specified and limited, the technical terms "mounting", "connecting", "connecting", "fixing" and the like should be understood in a broad sense, for example, it can be fixedly connected, or it can be detachably connected, or it can be integrated; it can be mechanical connection, or it can be electrical connection; it can be directly connected, or it can be indirectly connected through an intermediate medium; it can be the internal communication of two elements or the interaction relationship between two elements. For those skilled in the art, the specific meaning of the above terms in the embodiments of the present application can be understood according to the specific circumstances.

[0027] In the following, the attack protection method and device of the CAN bus provided by the embodiments of the present application will be described and explained in detail through several specific embodiments.

[0028] CAN bus is a communication protocol widely used in automotive electronic systems, known for its efficiency and reliability. However, CAN protocol uses clear text broadcast communication, all nodes can read bus data, lack of encryption and access control mechanism, so sniffing attackers can capture sensitive information by accessing the bus, such as OBD-II interface, to provide a basis for subsequent attacks. Therefore, in the related art, physical isolation is usually used to prevent the access of sniffing devices, such as limiting OBD-II access.

[0029] However, this way cannot prevent sniffing of wireless interfaces, resulting in ineffective prevention of sniffing attacks on CAN bus, affecting the security of data transmission through CAN bus. Based on this, modern block ciphers such as AES can be used to encrypt data transmitted through CAN bus, so that the attacker sniffs encrypted data, which is difficult to parse plaintext data, thereby preventing sniffing attacks on CAN bus. However, the encryption method using modern block ciphers has high computational overhead, and the resources of electronic control units are limited, resulting in high latency of data transmission when preventing sniffing attacks on CAN bus, affecting real-time communication of CAN bus, and even destroying the transmission timing of CAN bus.

[0030] To solve the above technical problems, the embodiments of the present application obtain a transformation parameter by performing XOR operation on the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame according to a first XOR operation strategy, and perform bitwise XOR operation on the transformation parameter and the current data frame according to a second XOR operation strategy to obtain target data, and then transmit the target data to the target receiving node through the CAN bus, so that the target receiving node of the target data sequentially performs inverse transformation on the target data according to the second XOR operation strategy and the first XOR operation strategy to obtain the current data frame. Thus, the temporary session key, the CAN identifier, and the sequence number are combined by XOR operation and bitwise XOR operation to encrypt the current data frame data, and then the encrypted current data frame is transmitted, so that the attacker sniffs the confused data and it is difficult to parse the plaintext data, to prevent sniffing attacks on CAN bus, while effectively reducing the computational overhead required for encryption, reducing transmission delay, reducing the impact on real-time communication of CAN bus, and further improving the security of data transmission through CAN bus.

[0031] According to some embodiments of the present application, the embodiments of the present application provide a CAN bus attack protection method, which can be applied to electronic devices such as ECU (Electronic Control Unit) to implement attack protection of CAN bus.

[0032] As Figure 1As shown, the method for protecting CAN bus from attack provided by the embodiment includes: S101, performing XOR operation on a session key, a CAN identifier corresponding to a current data frame, and a sequence number corresponding to the current data frame according to a first XOR operation strategy to obtain a transformation parameter; S102, performing bitwise XOR operation on the transformation parameter and the current data frame according to a second XOR operation strategy to obtain target data; S103, transmitting the target data to a target receiving node through a CAN bus, so that the target receiving node sequentially performs reverse transformation on the target data according to the second XOR operation strategy and the first XOR operation strategy to obtain the current data frame; The target receiving node pre-stores the first XOR operation strategy and the second XOR operation strategy.

[0033] In some embodiments, the session key can be a temporary session key negotiated by the ECU with the target receiving node through a secure channel, and the first XOR operation strategy and the second XOR operation strategy can also be synchronized through the secure channel. The target receiving node can be a legal node such as another ECU of the vehicle, a vehicle controller, a battery management system, or another electronic device of the vehicle.

[0034] The current data frame is a CAN data frame transmitted through the CAN bus. The CAN identifier corresponding to the data frame is a unique field in the data frame for identifying the message content and priority, which determines the priority and filtering rule of the message. The smaller the CAN identifier value is, the higher the priority is. In normal cases, for each data frame with the same CAN identifier, a basic sequence number can be generated based on the sending timestamp and the CAN identifier of the first data frame in each data frame with the same CAN identifier. The basic sequence number is the sequence number of the first data frame, and the sequence number of the next data frame is sequentially incremented based on the sequence number of the previous data frame. For example, assuming that the CAN identifier of the first data frame in each data frame with the same CAN identifier is 0x123, the basic sequence number generated based on the CAN identifier and the sending timestamp is 11 (0x0B), and the sequence number of the second data frame is the previous sequence number + 1 = 12, the sequence number of the third data frame is the previous sequence number + 1 = 13, and so on. In this way, the sequence number corresponding to the current data frame can be determined.

[0035] In some embodiments, according to the first XOR operation strategy, the session key, the CAN identifier corresponding to the current data frame and the sequence number corresponding to the current data frame are subjected to XOR operation to obtain the transformation parameter. The transformation parameter can be obtained by directly performing XOR operation on the session key, the CAN identifier corresponding to the current data frame and the sequence number corresponding to the current data frame. Alternatively, the transformation parameter can be obtained by performing XOR operation on the session key and the CAN identifier corresponding to the current data frame to obtain a mixed value, and then performing XOR operation again on the mixed value and the sequence number to generate the transformation parameter. Alternatively, the transformation parameter can be obtained by performing XOR operation on the session key and the CAN identifier corresponding to the current data frame to obtain a mixed value, and then performing XOR operation again on the mixed value and a processing result of multiplying the sequence number by a fixed coefficient and / or adding a fixed offset to generate the transformation parameter.

[0036] In some embodiments, according to the second XOR operation strategy, the transformation parameter and the current data frame are subjected to bitwise XOR operation to obtain the target data. The target data can be obtained by directly performing bitwise XOR operation on the transformation parameter and the current data frame. Alternatively, the current data frame can be divided into a first data block and a second data block, the transformation parameter and the first data block are subjected to bitwise XOR operation to obtain first intermediate data, the transformation parameter and the second data block are subjected to bitwise XOR operation to obtain second intermediate data, and the first intermediate data and the second intermediate data are combined to form the final target data.

[0037] After obtaining the target data, the target data can be transmitted to the target receiving node through the CAN bus. After receiving the target data, the target node can perform first-level reverse transformation on the target data through the second XOR operation strategy, and then obtain the same transformation parameter through the first XOR operation strategy to perform second-level reverse transformation on the data obtained by the first-level reverse transformation, thereby recovering the current data frame.

[0038] The session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are subjected to the XOR operation according to the first XOR operation strategy to obtain a transformation parameter, the target data is obtained by performing the bitwise XOR operation on the transformation parameter and the current data frame according to the second XOR operation strategy, and the target data is transmitted to the target receiving node through the CAN bus, so that the target receiving node of the target data sequentially performs reverse transformation on the target data according to the second XOR operation strategy and the first XOR operation strategy to obtain the current data frame. Thus, the temporary session key, the CAN identifier, and the sequence number are combined by the XOR operation and the bitwise XOR operation to encrypt the current data frame data, and the encrypted current data frame is transmitted, so that the attacker sniffed is the confused data, and it is difficult to parse the plaintext data, to prevent the sniffing attack on the CAN bus, while effectively reducing the calculation overhead required for encryption, reducing the transmission delay, reducing the influence on the real-time communication of the CAN bus, and further improving the security of data transmission through the CAN bus.

[0039] In addition, since the session key is a temporary session key negotiated with the target receiving node through a secure channel, even if a node of a non-target receiving node is tampered as a malicious node to sniff the CAN bus due to a security vulnerability, the data obtained by the node is confused data. The malicious node cannot obtain the temporary session key, so even if the malicious node can determine the first XOR operation strategy and the second XOR operation strategy, it is difficult to parse the plaintext data, and the security of data transmission through the CAN bus is further improved.

[0040] To further improve the security of data transmission through the CAN bus, in some embodiments, the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are subjected to the XOR operation according to the first XOR operation strategy to obtain a transformation parameter, including: When the sending timestamp of the current data frame reaches a predetermined sending moment, the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are subjected to the XOR operation according to the first XOR operation strategy to obtain a transformation parameter; The predetermined sending moment is determined according to the message period determined according to the CAN identifier corresponding to the current data frame and the sending timestamp of the last data frame with the same CAN identifier as the CAN identifier corresponding to the current data frame.

[0041] In some embodiments, each CAN identifier is pre-configured with a corresponding message period. According to the sending timestamp t1 of the last data frame corresponding to the same CAN identifier as the current data frame, and the message period T corresponding to the CAN identifier, the predetermined sending time t2 = t1 + T can be determined. Wherein, the last data frame is a data frame that has been sent through the CAN bus.

[0042] For the current data frame, it can be detected whether the sending timestamp t0 reaches the predetermined sending time t2, that is, whether t0 is greater than or equal to t2. If so, it means that the current data frame meets the corresponding message period requirement, and then according to the first XOR operation strategy, the session key, the CAN identifier corresponding to the current data frame and the sequence number corresponding to the current data frame are XORed to obtain the transformation parameter, and the subsequent bitwise XOR operation and data sending operation are performed according to the transformation parameter. If the sending timestamp t0 of the current data frame does not reach the predetermined sending time t2, such as t0 < t2, the current data frame is skipped.

[0043] Therefore, when an attacker performs a replay attack, such as when the attacker intercepts a valid CAN data frame and immediately replays it, the replay attack will be rejected due to the sending timestamp not reaching the predetermined sending time, thereby reducing the illegal message entering the bus, effectively limiting the attack traffic of the replay attack, protecting the CAN bus bandwidth and the passing ability of other key messages, and further improving the security of data transmission through the CAN bus.

[0044] In addition, since the automobile control system highly depends on the timely arrival of messages, this method can also ensure the time determinacy of the data frame, so that the receiver can receive the message within the expected time window, and improve the stability of the automobile control system.

[0045] In order to further improve the security of data transmission through the CAN bus, in some embodiments, according to the first XOR operation strategy, the session key, the CAN identifier corresponding to the current data frame and the sequence number corresponding to the current data frame are XORed to obtain the transformation parameter, including: Obtaining the sending time interval between the current data frame and the last data frame corresponding to the same CAN identifier as the current data frame; Determining that the sending time interval is less than or equal to a preset delay interval, adjusting the sequence number corresponding to the last data frame according to a preset step size to obtain the sequence number corresponding to the current data frame; According to the first XOR operation strategy, the session key, the CAN identifier corresponding to the current data frame and the sequence number corresponding to the current data frame are XORed to obtain the transformation parameter; Wherein, the preset delay interval is determined according to the CAN identifier corresponding to the current data frame.

[0046] In some embodiments, a preset delay interval can be configured for each CAN identifier in advance. Wherein, the higher the priority corresponding to the CAN identifier is, the lower the preset delay interval is.

[0047] When it is needed to send the current data frame through the CAN bus, the sending timestamp of the current data frame and the sending timestamp of the last data frame with the same CAN identifier as the current data frame can be obtained first, and the sending time interval between the current data frame and the last data frame can be obtained according to the sending timestamp of the current data frame and the sending timestamp of the last data frame. For example, the sending time interval can be obtained by subtracting the sending timestamp of the last data frame from the sending timestamp of the current data frame.

[0048] The sending time interval is compared with the preset delay interval. If the sending time interval is less than or equal to the preset delay interval, the sequence number corresponding to the last data frame can be adjusted according to a preset step, for example, the sequence number corresponding to the last data frame can be increased by the preset step to obtain the sequence number corresponding to the current data frame.

[0049] Wherein, the preset step can be set according to actual conditions, for example, it can be set to 1. At this time, if the sending time interval between the current data frame and the last data frame is less than or equal to the preset delay interval, the sequence number of the current data frame is the sequence number of the last data frame plus 1.

[0050] Since the sequence number is dynamically changed, if the attacker repeatedly sends the old data frame with a valid sequence number just captured, the target receiving node can judge that the data frame is an invalid data frame by identifying the sequence number, thereby effectively resisting the replay attack of the attacker and improving the security of data transmission through the CAN bus.

[0051] In some embodiments, if it is determined that the sending time interval is greater than the preset delay interval, the sequence number corresponding to the current data frame can be generated according to the sending timestamp of the current data frame and the CAN identifier corresponding to the current data frame.

[0052] For example, assuming that the preset delay interval is 100 ms, the sending timestamp of the current data frame is 1151 ms, and the sending timestamp of the last data frame is 1050 ms, the sending time interval between the two is 101 ms, which is greater than 100 ms. At this time, the reset rule of the sequence number is triggered, a new base sequence number is generated according to the sending timestamp of the current data frame and the CAN identifier, and the base sequence number is taken as the sequence number of the current data frame. If the sending time interval between the next data frame with the same CAN identifier as the current data frame and the current data frame is less than or equal to the preset delay interval, the sequence number of the next data frame is the sequence number of the current data frame plus 1; otherwise, the reset rule of the sequence number is triggered again according to the sending timestamp of the next data frame and the CAN identifier. And so on.

[0053] By resetting the sequence number when the time interval between two adjacent data frames with the same CAN identifier is long, the message after a long interruption can be identified as a new independent communication session, avoiding misjudging the old data frame that arrives late as the current valid data, ensuring the strict continuity and logical correctness of the sequence number in each continuous session, and preventing the logical confusion of the data stream.

[0054] In some embodiments, it can also be detected whether the sending timestamp of the current data frame reaches the predetermined sending time. If not, the current data frame is skipped. If so, the sending time interval between the current data frame and the last data frame corresponding to the CAN identifier of the current data frame is detected. If the sending time interval is less than or equal to the preset delay interval, the sequence number corresponding to the last data frame is adjusted according to the preset step size to obtain the sequence number corresponding to the current data frame; if the sending time interval is greater than the preset delay interval, the sequence number corresponding to the current data frame is generated according to the sending timestamp of the current data frame and the CAN identifier corresponding to the current data frame.

[0055] After obtaining the sequence number of the current data frame, the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are subjected to an XOR operation according to the first XOR operation strategy to obtain a transformation parameter, so that subsequent bitwise XOR operations and data sending operations are performed through the transformation parameter.

[0056] To further improve the security of data transmission through the CAN bus, in some embodiments, the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are subjected to an XOR operation according to the first XOR operation strategy to obtain a transformation parameter, including: performing an XOR operation on the session key and the CAN identifier to obtain a mixed value; performing a secondary XOR operation on the mixed value and a target field of a transformation sequence number generated according to the sequence number to obtain the transformation parameter; wherein the transformation sequence number is generated by performing confusion processing on the sequence number according to at least one of a fixed coefficient and a fixed offset; the target field is extracted from the transformation sequence number according to a preset starting bit and a preset extraction length.

[0057] In some embodiments, the target field of the transformation sequence number generated by the sequence number can be obtained by multiplying the sequence number by a fixed coefficient and adding a fixed offset to obtain a transformation sequence number, and then taking a number of bits in the middle of the transformation sequence number according to a preset starting bit and a preset extraction length to obtain the target field.

[0058] For example, assuming that the preset starting bit is the 15th bit, the preset extraction length is 8 bits, and the transformed serial number is a 32-bit binary number, such as (b31 b30... b2 b1 b0), the b31 bit being the highest bit, the binary number from the 15th bit to the 8th bit can be taken to obtain an 8-bit field of (b15 b14... b9 b8). Thus, the regularity possibly existing in the high bits of the transformed serial number and the periodicity possibly existing in the low bits can be evaded, the statistical characteristics of the obtained target field bits are better pseudo-random bits, and the confusion effect is enhanced.

[0059] In some embodiments, the session key and the CAN identifier can be subjected to an exclusive OR operation to obtain a mixed value, and then the mixed value and the target field can be subjected to a second exclusive OR operation to obtain the transformed parameter, such as a 32-bit dynamic transformed parameter.

[0060] Through the two exclusive OR operations and the exclusive OR operation of the intercepted target field in the second exclusive OR operation, the linear relationship of the output result can be destroyed, the output transformed parameter is more random, the confusion effect is enhanced, the difficulty of decryption of the sniffed attack on the obtained confused data is increased, and the security of the data transmission through the CAN bus is further improved.

[0061] To further improve the security of the data transmission through the CAN bus, in some embodiments, according to a second exclusive OR operation strategy, the transformed parameter and the current data frame are subjected to a bit-by-bit exclusive OR operation to obtain target data, including: The current data frame is segmented to obtain a first data block and a second data block; The first M bits of the N-bit transformed parameter and the first data block are subjected to a bit-by-bit exclusive OR operation to obtain first intermediate data, and the last N-M bits of the N-bit transformed parameter and the second data block are subjected to a bit-by-bit exclusive OR operation to obtain second intermediate data; The target data is obtained according to the first intermediate data and the second intermediate data.

[0062] In some embodiments, the segmentation of the current data frame can be equal segmentation of the current data frame to obtain the first data block and the second data block. For example, a 64-bit current data frame is segmented into a 32-bit first data block and a 32-bit second data block.

[0063] In some embodiments, the N-bit transform parameter can be divided into a first M-bit parameter and a second N-M-bit parameter. The first M-bit parameter and the first data block can be subjected to a bitwise XOR operation to obtain a first intermediate data, and the second N-M-bit parameter and the second data block can be subjected to a bitwise XOR operation to obtain a second intermediate data. For example, the transform parameter is a 32-bit transform parameter. The upper 16 bits of the 32-bit transform parameter, i.e., the first 16 bits, and the first data block of the upper 32 bits are subjected to a bitwise XOR operation to obtain the first intermediate data, and the lower 16 bits of the 32-bit transform parameter, i.e., the last 16 bits, and the second data block of the lower 32 bits are subjected to a bitwise XOR operation to obtain the second intermediate data.

[0064] After obtaining the first intermediate data and the second intermediate data, the first intermediate data and the second intermediate data can be combined to form the target data. Thus, the confusion effect of the target data is enhanced, so as to improve the decryption difficulty of the sniffing attack on the obtained confused data, and further improve the security of data transmission through the CAN bus.

[0065] In order to further enhance the confusion effect of the target data and further improve the security of data transmission through the CAN bus, in some embodiments, the target data is obtained according to the first intermediate data and the second intermediate data, including: The first intermediate data and the second intermediate data are subjected to byte position exchange respectively to obtain first data and second data; The first data and the second data are subjected to data combination to obtain the target data.

[0066] In some embodiments, the first intermediate data can be subjected to a byte position exchange operation according to a corresponding first preset position exchange strategy to obtain the first data, and the first intermediate data can be subjected to a byte position exchange operation according to a corresponding second preset position exchange strategy to obtain the second data. For example, the first byte and the fourth byte of the first intermediate data can be exchanged to obtain the first data, and the second byte and the third byte of the second intermediate data can be exchanged to obtain the second data.

[0067] After obtaining the first data and the second data, the first data and the second data can be combined to form the final target data, so as to transmit the target data through the CAN bus to a target receiving node, so that the target receiving node performs reverse transformation on the target data to obtain the current data frame.

[0068] For example, taking the vehicle brake ECU sending a periodic brake instruction through the CAN bus as an example, assuming that the CAN identifier of the data frame sent by the vehicle brake ECU is 0x200, the message period is 10 ms, and the attacker sniffs through the OBD-II interface.

[0069] Assuming the current data frame is 0x01A5B7C8D9, according to the first XOR budget strategy, the session key and the CAN identifier of the current data frame are XORed to obtain a mixed value, and then the mixed value and the target field of the transformed sequence number generated according to the sequence number are twice XORed to obtain a transformation parameter.

[0070] According to the first XOR operation strategy, the current data frame is segmented to obtain a first data block of high 32 bits and a second data block of low 32 bits, the high 16 bits, i.e. the first 16 bits, of the 32-bit transformation parameter are XORed with the first data block of high 32 bits to obtain first intermediate data, and the low 16 bits, i.e. the last 16 bits, of the 32-bit transformation parameter are XORed with the second data block of low 32 bits to obtain second intermediate data. The first byte and the fourth byte of the first intermediate data are exchanged to obtain first data, and the second byte and the third byte of the second intermediate data are exchanged to obtain second data, and the first data and the second data are combined to obtain target data 0xC8D9B7A501.

[0071] The target data is sent to the target receiving node, and the target node sequentially performs reverse transformation on the target data 0xC8D9B7A501 according to the second XOR operation strategy and the first XOR operation strategy to obtain the current data frame 0x01A5B7C8D9. At this time, the attacker sniffs the confused data 0xC8D9B7A501 and cannot parse the real brake instruction 0x01A5B7C8D9. Thus, the brake instruction is effectively protected.

[0072] In order to further improve the security of data transmission through the CAN bus, in some embodiments, the method further comprises: During an idle period when the CAN bus does not transmit the target data, injecting a fake message into the CAN bus.

[0073] In some embodiments, a reserved CAN identifier range such as 0x700 to 0x7FF can be used to generate a fake message, and the data content of the fake message is generated by a pseudo-random number generator. For the generation of data messages, the generation process of the target data is similar, and according to the first XOR operation strategy and the second XOR operation strategy, any one of the session key, the data content generated by the pseudo-random number generator, and the reserved CAN identifier range is XORed and bitwise XORed to obtain the fake message.

[0074] The target receiving node synchronously records the reserved CAN identifier range, so that when the CAN identifier of the parsed data frame falls within the CAN identifier range, it can be determined that the data frame is a fake message, and the fake message is discarded.

[0075] For example, in the case of the speed sensor ECU sending speed data through the CAN bus, in the idle period when the CAN bus does not transmit target data generated by the speed data frame collected by the speed sensor ECU, the speed sensor ECU can randomly select a CAN identifier based on the reserved CAN identifier range, generate a fake message based on the CAN identifier, and transmit it through the CAN bus. When the target receiving node receives the fake message, it can parse the corresponding CAN identifier and determine that the CAN identifier falls within the reserved CAN identifier range, thereby filtering the fake message. When the attacker sniffs the fake message, even if it is parsed, the real speed value cannot be obtained, so that the real fixed mapping of the speed value and the transformation parameter cannot be established, the statistical analysis of the attacker is interfered, and the security of data transmission through the CAN bus is further improved.

[0076] To reduce the impact of transmitting fake messages on the transmission of effective data frames of the CAN bus, in some embodiments, injecting fake messages into the CAN bus includes: determining the injection frequency of the fake messages according to the current load state of the CAN bus; injecting the fake messages into the CAN bus according to the injection frequency.

[0077] In some embodiments, it can be detected whether the current load state of the CAN bus is less than the preset load state. If yes, the first injection frequency is used to inject fake messages into the CAN bus; otherwise, the second injection frequency is used to inject fake messages into the CAN bus. Wherein, the first injection frequency is greater than the second injection frequency.

[0078] Alternatively, the current load state of the CAN bus can be detected in a preset load interval. Wherein, the preset load interval can be divided into a low load interval, a medium load interval and a high load interval, the low load interval corresponds to a CAN bus utilization rate of less than 30%, the medium load interval corresponds to a CAN bus utilization rate of between 30% and 70%, and the high load interval corresponds to a CAN bus utilization rate of more than 70%. If the current load state of the CAN bus is in the low load interval, the first injection frequency is used to inject fake messages into the CAN bus to fill the idle bus time; if the current load state of the CAN bus is in the medium load interval, the second injection frequency is used to inject fake messages into the CAN bus to balance security and data transmission performance; if the current load state of the CAN bus is in the low load interval, the third injection frequency is used to inject fake messages into the CAN bus or to suspend the injection of fake messages to ensure the real-time performance of critical communication. Wherein, the first injection frequency is greater than the second injection frequency, and the second injection frequency is greater than the third injection frequency.

[0079] For the purposes of the present application, the technical solutions and advantages will be more clearly described below. In some embodiments, as shown in Figure 2 The attack protection method of the CAN bus includes: S201, detecting whether the sending timestamp of the current data frame reaches the predetermined sending moment; if yes, performing S202, otherwise, skipping the current data frame.

[0080] The predetermined sending moment is determined according to the message period of the CAN identifier corresponding to the current data frame and the sending timestamp of the last data frame with the same CAN identifier as the current data frame.

[0081] S202, judging whether the sending time interval between the current data frame and the last data frame with the same CAN identifier as the current data frame is less than or equal to the preset delay interval; if yes, performing S203; otherwise, performing S204.

[0082] The preset delay interval is determined according to the CAN identifier corresponding to the current data frame.

[0083] S203, adjusting the sequence number corresponding to the last data frame according to the preset step to obtain the sequence number corresponding to the current data frame.

[0084] S204, generating the sequence number corresponding to the current data frame according to the sending timestamp of the current data frame and the CAN identifier corresponding to the current data frame.

[0085] S205, performing XOR operation on the session key and the CAN identifier to obtain a mixed value.

[0086] S206, performing secondary XOR operation on the mixed value and the target field of the transformed sequence number generated according to the sequence number to obtain a transformation parameter.

[0087] The transformed sequence number is obtained by multiplying the sequence number by a fixed coefficient and adding a fixed offset, and the target field is extracted from the transformed sequence number according to a preset starting bit and a preset extraction length.

[0088] S207, segmenting the current data frame to obtain a first data block and a second data block.

[0089] S208, performing bitwise XOR operation on the first M bits of the N-bit transformation parameter and the first data block to obtain first intermediate data, and performing bitwise XOR operation on the last N-M bits of the N-bit transformation parameter and the second data block to obtain second intermediate data.

[0090] S209, performing byte position exchange on the first intermediate data and the second intermediate data respectively and then combining the data to obtain target data.

[0091] S210, transmitting the target data to a target receiving node through the CAN bus, so that the target receiving node performs reverse transformation on the target data to obtain a current data frame.

[0092] S211, during an idle period in which the CAN bus does not transmit the target data, determining an injection frequency of the camouflage message according to a current load state of the CAN bus.

[0093] S212, injecting the camouflage message into the CAN bus according to the injection frequency.

[0094] The CAN bus attack protection device provided in the present application is described below. The CAN bus attack protection device described below can be referred to in correspondence with the CAN bus attack protection method described above.

[0095] In an embodiment, as shown in FIG. 3, a CAN bus attack protection device is provided, comprising: Figure 3 a transformation parameter acquisition module 310, configured to perform XOR operation on a session key, a CAN identifier corresponding to a current data frame and a sequence number corresponding to the current data frame according to a first XOR operation strategy to obtain a transformation parameter; a target data acquisition module 320, configured to perform bitwise XOR operation on the transformation parameter and the current data frame according to a second XOR operation strategy to obtain target data; a target data transmission module 330, configured to transmit the target data to a target receiving node through the CAN bus, so that the target receiving node sequentially performs reverse transformation on the target data according to the second XOR operation strategy and the first XOR operation strategy to obtain the current data frame; wherein the target receiving node pre-stores the first XOR operation strategy and the second XOR operation strategy.

[0096] ​By performing an XOR operation on the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame according to the first XOR operation strategy, transformation parameters are obtained. Then, according to the second XOR operation strategy, a bitwise XOR operation is performed on the transformation parameters and the current data frame to obtain the target data. After obtaining the target data, the target data is transmitted to the target receiving node via the CAN bus. The target receiving node then performs the reverse transformation on the target data according to the second and first XOR operation strategies to obtain the current data frame. In this way, the temporary session key, CAN identifier, and sequence number are encrypted using a combination of XOR and bitwise XOR operations. The encrypted current data frame is then transmitted, so that attackers only receive obfuscated data, making it difficult to parse the plaintext data. This prevents sniffing attacks on the CAN bus, effectively reduces the computational overhead required for encryption, lowers transmission latency, and minimizes the impact on real-time communication on the CAN bus, thereby improving the security of data transmission via the CAN bus.

[0097] Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4 As shown, the electronic device may include: a processor 810, a communication interface 820, a memory 830, and a communication bus 840, wherein the processor 810, the communication interface 820, and the memory 830 communicate with each other via the communication bus 840. The processor 810 can call a computer program in the memory 830 to execute CAN bus attack protection methods, such as: According to the first XOR operation strategy, the session key, the CAN identifier corresponding to the current data frame and the sequence number corresponding to the current data frame are XORed to obtain the transformation parameters. According to the second XOR operation strategy, a bitwise XOR operation is performed on the transformation parameters and the current data frame to obtain the target data; The target data is transmitted to the target receiving node via the CAN bus, so that the target receiving node performs reverse transformation on the target data according to the second XOR operation strategy and the first XOR operation strategy in sequence to obtain the current data frame; The target receiving node pre-stores the first XOR operation strategy and the second XOR operation strategy.

[0098] In some embodiments, the electronic device may be an electronic control unit.

[0099] Further, the logic instructions in the memory 830 described above can be implemented in the form of software functional units and sold or used as independent products, and can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or the parts that make contributions to the prior art or parts of the technical solutions can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the embodiments of the method of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.

[0100] In another aspect, the embodiments of the present application also provide a storage medium, the storage medium includes a computer program, the computer program can be stored on a non-transitory computer readable storage medium, and the computer program is executed by a processor, and the computer can execute the CAN bus attack protection method provided by the above-mentioned embodiments, for example, including: According to the first XOR operation strategy, the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are subjected to XOR operation to obtain a transformation parameter; According to the second XOR operation strategy, the transformation parameter and the current data frame are subjected to bitwise XOR operation to obtain target data; The target data is transmitted to a target receiving node through the CAN bus, so that the target receiving node sequentially performs reverse transformation on the target data according to the second XOR operation strategy and the first XOR operation strategy to obtain the current data frame; The target receiving node pre-stores the first XOR operation strategy and the second XOR operation strategy.

[0101] In another aspect, the embodiments of the present application also provide a computer program product, characterized in that the computer program product includes a computer program, and the computer program is executed by a processor to implement the CAN bus attack protection method provided by the above-mentioned embodiments.

[0102] The device embodiments described above are merely illustrative, wherein the units illustrated as separate components can or can not be physically separate, and the components illustrated as units can or can not be physical units, i.e., can be located in one place, or can be distributed to multiple network units. Part or all of the modules can be selected to achieve the purposes of the embodiments according to actual needs. Those skilled in the art can understand and implement without creative labor.

[0103] Through the description of the above embodiments, those skilled in the art can clearly understand that the embodiments can be realized by means of software and the necessary general hardware platform, and of course can also be realized by hardware. Based on such understanding, the above technical solutions can be embodied in the form of software products, and the computer software products can be stored in a computer readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and include a plurality of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute the methods described in each embodiment or some parts of the embodiments.

[0104] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for attack protection of CAN bus, characterized in that, include: According to the first XOR operation strategy, the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are XORed to obtain the transformation parameters. According to the second XOR operation strategy, a bitwise XOR operation is performed on the transformation parameters and the current data frame to obtain the target data; The target data is transmitted to the target receiving node via the CAN bus, so that the target receiving node performs reverse transformation on the target data according to the second XOR operation strategy and the first XOR operation strategy in sequence to obtain the current data frame; The target receiving node pre-stores the first XOR operation strategy and the second XOR operation strategy.

2. The attack protection method for the CAN bus according to claim 1, characterized in that, According to the first XOR operation strategy, the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are XORed to obtain the transformation parameters, including: Once the transmission timestamp of the current data frame is determined to have reached the predetermined transmission time, the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are XORed according to the first XOR operation strategy to obtain the transformation parameters. The predetermined transmission time is determined based on the message period determined by the CAN identifier corresponding to the current data frame, and the transmission timestamp of the previous data frame that has the same CAN identifier as the current data frame.

3. The attack protection method for the CAN bus according to claim 1 or 2, characterized in that, According to the first XOR operation strategy, the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are XORed to obtain the transformation parameters, including: Obtain the current data frame and the transmission time interval between the previous data frame that has the same CAN identifier as the current data frame; Determine that the transmission time interval is less than or equal to a preset delay interval, adjust the sequence number corresponding to the previous data frame according to a preset step size, and obtain the sequence number corresponding to the current data frame; According to the first XOR operation strategy, the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are XORed to obtain the transformation parameters. The preset delay interval is determined based on the CAN identifier corresponding to the current data frame.

4. The attack protection method for the CAN bus according to claim 3, characterized in that, Also includes: If the transmission time interval is determined to be greater than the preset delay interval, a sequence number corresponding to the current data frame is generated based on the transmission timestamp of the current data frame and the CAN identifier corresponding to the current data frame.

5. The attack protection method for the CAN bus according to any one of claims 1, 2, or 4, characterized in that, According to the first XOR operation strategy, the session key, the CAN identifier corresponding to the current data frame, and the sequence number corresponding to the current data frame are XORed to obtain the transformation parameters, including: Perform an XOR operation between the session key and the CAN identifier to obtain a mixed value; The transformation parameters are obtained by performing a double XOR operation between the mixed value and the target field of the transformation sequence number generated according to the sequence number; The transformation sequence number is generated by obfuscating the sequence number based on at least one of a fixed coefficient and a fixed offset. The target field is extracted from the transformation sequence number according to a preset start position and a preset extraction length.

6. The attack protection method for the CAN bus according to claim 1, characterized in that, According to the second XOR operation strategy, a bitwise XOR operation is performed on the transformation parameters and the current data frame to obtain the target data, including: The current data frame is segmented to obtain a first data block and a second data block; Perform a bitwise XOR operation on the first M bits of the N-bit transformation parameters and the first data block to obtain the first intermediate data, and perform a bitwise XOR operation on the last NM bits of the N-bit transformation parameters and the second data block to obtain the second intermediate data; The target data is obtained based on the first intermediate data and the second intermediate data.

7. The attack protection method for the CAN bus according to claim 6, characterized in that, The target data is obtained based on the first intermediate data and the second intermediate data, including: Perform byte position swapping on the first intermediate data and the second intermediate data respectively to obtain the first data and the second data; The first data and the second data are combined to obtain the target data.

8. The attack protection method for the CAN bus according to claim 1, characterized in that, Also includes: During idle periods when the CAN bus is not transmitting the target data, a spoofed message is injected into the CAN bus.

9. The attack protection method for the CAN bus according to claim 8, characterized in that, Injecting spoofed messages into the CAN bus includes: The injection frequency of spoofed messages is determined based on the current load status of the CAN bus. The spoofed message is injected into the CAN bus according to the injection frequency.

10. An electronic control unit, comprising a processor and a memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the attack protection method for the CAN bus as described in any one of claims 1 to 9.

11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the attack protection method for the CAN bus as described in any one of claims 1 to 9.

12. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the attack protection method for the CAN bus as described in any one of claims 1-9.