Modbus protocol security enhancement method and system in unicast communication scenario
By introducing a custom function code 0x6D into the Modbus protocol for authentication and key negotiation, the issues of identity legitimacy, data integrity, and confidentiality in unicast communication scenarios of the Modbus protocol are resolved, and secure data transmission and device authentication are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- XIDIAN UNIV
- Filing Date
- 2025-04-21
- Publication Date
- 2026-05-19
AI Technical Summary
The existing Modbus protocol cannot effectively guarantee the identity legitimacy, data integrity and confidentiality of the communicating parties in unicast communication scenarios. It is vulnerable to attacks by malicious devices and lacks a dynamic key negotiation mechanism.
By introducing a custom function code 0x6D into the Modbus protocol for authentication and key negotiation, the master and slave nodes share ciphertext, generate and verify message authentication codes, and ensure two-way authentication and session key generation.
It implements authentication and data encryption of the Modbus protocol in unicast communication scenarios, prevents unauthorized devices from accessing the network, ensures the integrity and confidentiality of data transmission, and resists replay attacks and man-in-the-middle attacks.
Smart Images

Figure CN120342628B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial control network technology, and in particular to a method and system for enhancing the security of the Modbus protocol in a unicast communication scenario. Background Technology
[0002] In the field of industrial control systems, enhanced security is crucial to protecting systems from malicious attacks and data breaches. The core technologies for enhanced security primarily include authentication, key negotiation, and data encryption / decryption. These core technologies collectively form the foundation for protecting data transmission and device communication. Authentication refers to the mutual verification of each other's identities by the two parties in network communication (usually a master node and a slave node) before data exchange, ensuring that only legitimate devices can participate in the communication. The authentication process is a vital component of ensuring system security, especially in protocols without built-in authentication mechanisms (such as the Modbus protocol). Adding authentication can prevent unauthorized devices from accessing the network, thereby reducing potential security risks. Key negotiation is the process by which communicating parties securely generate a shared key over an insecure channel. Commonly used Modbus protocols (such as Modbus TCP and Modbus RTU / ASCII protocols) transmit data in plaintext, making the communication channel vulnerable to eavesdropping. The Modbus protocol lacks security enhancement mechanisms; therefore, any device can communicate with either the master or slave node, creating risks of unverifiable identities and easily tampered data. Therefore, enhancing the security of point-to-point communication has become an urgent problem to be solved in the field of industrial automation when applying the Modbus protocol.
[0003] Currently, security enhancements for the Modbus protocol typically employ traditional methods. However, these methods allow any device to communicate with the Modbus master or slave, making it impossible to verify the legitimacy of the communicating parties. Therefore, malicious devices (such as hackers or forged devices) can easily access the network and communicate, steal data, or launch attacks, compromising the validity of the identities of both parties. Attackers can capture and modify data packets or replay legitimate commands to induce abnormal system behavior, compromising data integrity during transmission. Furthermore, the lack of dynamic key negotiation during communication means that communication between devices may lack effective encryption protection, or the keys may be static and easily stolen. Once the keys are leaked, attackers can decrypt and forge communication data, compromising data confidentiality during transmission. Summary of the Invention
[0004] The purpose of this invention is to provide a method and system for enhancing the security of the Modbus protocol in unicast communication scenarios, which solves the problems that existing technologies cannot guarantee the validity of the identities of the communicating parties, and cannot guarantee the integrity and confidentiality of data during transmission.
[0005] To address the aforementioned technical problems, the embodiments of the present invention provide the following technical solutions:
[0006] The first aspect of this invention provides a method for enhancing the security of the Modbus protocol in a unicast communication scenario. The Modbus protocol includes a target function code that uses messages for authentication and key negotiation. The method includes:
[0007] The master node and the slave node share the first ciphertext and the second ciphertext. The first ciphertext is the ciphertext corresponding to the master node, and the second ciphertext is the ciphertext corresponding to the slave node.
[0008] The master node generates a first message authentication code based on the second ciphertext, the preset key and the first random number, and sends the first message to the slave node using the target function code. The first message is a message generated based on the first message authentication code and includes the first message authentication code.
[0009] The slave node authenticates the identity of the master node based on the first message authentication code, the first ciphertext, the preset key, and the second random number;
[0010] When the slave node successfully authenticates the master node's identity, the slave node generates a second message authentication code based on the first ciphertext, the preset key, and the second random number, and sends the second message to the master node using the target function code. The second message is a message generated based on the second message authentication code and includes the second message authentication code.
[0011] The master node authenticates the identity of the slave node based on the second message authentication code, the second ciphertext, the preset key, and the first random number, thereby enhancing the security of the Modbus protocol.
[0012] A second aspect of this invention provides a security enhancement system for the Modbus protocol in a unicast communication scenario. The Modbus protocol includes a target function code that uses messages for authentication and key negotiation. The system includes:
[0013] The shared module is used for sharing the first ciphertext and the second ciphertext between the master node and the slave node. The first ciphertext is the ciphertext corresponding to the master node, and the second ciphertext is the ciphertext corresponding to the slave node.
[0014] The first generation module is used by the master node to generate a first message authentication code based on the second ciphertext, the preset key and the first random number, and to send the first message to the slave node using the target function code. The first message is a message generated based on the first message authentication code and includes the first message authentication code.
[0015] The first authentication module is used by slave nodes to authenticate the identity of the master node based on the first message authentication code, the first ciphertext, the preset key, and the second random number.
[0016] The second generation module is used to generate a second message authentication code based on the first ciphertext, the preset key and the second random number when the slave node successfully authenticates the identity of the master node, and send the second message to the master node using the target function code. The second message is a message generated based on the second message authentication code and includes the second message authentication code.
[0017] The second authentication module is used by the master node to authenticate the identity of the slave node based on the second message authentication code, the second ciphertext, the preset key and the first random number, so as to realize the security enhancement of the Modbus protocol.
[0018] Compared to existing technologies, the Modbus protocol security enhancement method and system provided by this invention for unicast communication scenarios includes a target function code for identity authentication and key negotiation using messages. The master node and slave nodes share a first ciphertext and a second ciphertext. The master node generates a first message authentication code based on the second ciphertext, a preset key, and a first random number, and sends the first message to the slave node using the target function code. The slave node authenticates the master node's identity based on the first message authentication code, the first ciphertext, the preset key, and the second random number. When the slave node successfully authenticates the master node's identity, it generates a second message authentication code based on the first ciphertext, the preset key, and the second random number, and sends the second message to the master node using the target function code. The master node authenticates the slave node's identity based on the second message authentication code, the second ciphertext, the preset key, and the first random number, thereby achieving security enhancement of the Modbus protocol. In this way, by sharing the first and second ciphertexts, the communication between the master node and the slave node can be ensured, and the legitimacy of the master node and the slave node can be verified. The slave node can authenticate the identity of the master node by generating the first message authentication code, and the master node can authenticate the identity of the slave node by generating the second message authentication code. Furthermore, the message is sent using the target function code for negotiation and authentication, which can ensure the validity of the identities of both communicating parties and guarantee the integrity and confidentiality of the data during transmission. Attached Figure Description
[0019] The above and other objects, features, and advantages of exemplary embodiments of the present invention will become readily apparent upon reading the following detailed description with reference to the accompanying drawings. In the drawings, several embodiments of the invention are illustrated by way of example and not limitation, with the same or corresponding reference numerals denoteing the same or corresponding parts, wherein:
[0020] Figure 1A flowchart illustrating a method for enhancing Modbus protocol security in a unicast communication scenario is shown.
[0021] Figure 2 A schematic diagram of the Modbus TCP message format is shown.
[0022] Figure 3 A schematic diagram of the Modbus RTU / ASCII message format is shown.
[0023] Figure 4 The diagram illustrates the identity authentication and session key negotiation process of Embodiment 1 of the present invention.
[0024] Figure 5 The diagram illustrates the structure of a Modbus protocol security enhancement system in a unicast communication scenario. Detailed Implementation
[0025] Exemplary embodiments of the invention will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the invention are shown in the drawings, it should be understood that the invention can be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of the invention and to fully convey the scope of the invention to those skilled in the art.
[0026] It should be noted that, unless otherwise stated, the technical or scientific terms used in this invention should have the ordinary meaning as understood by one of ordinary skill in the art.
[0027] The methods described in the embodiments of the present invention will be explained in detail below.
[0028] Figure 1 A flowchart illustrating a Modbus protocol security enhancement method in a unicast communication scenario according to an embodiment of the present invention is shown schematically. See [link / reference]. Figure 1 As shown, the Modbus protocol includes target function codes for authentication and key negotiation using messages. This method may include:
[0029] S101. The master node and slave nodes share the first ciphertext and the second ciphertext.
[0030] The first ciphertext is the ciphertext corresponding to the master node, and the second ciphertext is the ciphertext corresponding to the slave node.
[0031] Before sharing the first and second ciphertexts between the master and slave nodes, the method also includes:
[0032] Step A1: Use the custom function to set the unused function code as the target function code.
[0033] The target function code is used to indicate the use of the first and second messages for authentication and key negotiation.
[0034] The Modbus protocol includes the Modbus TCP protocol and the Modbus RTU / ASCII protocol.
[0035] To ensure compatibility with the traditional Modbus protocol, this invention fully considers the use of Modbus protocol function codes. Function codes are core fields in the Modbus protocol used to distinguish different operation types, such as reading from a register and writing to a register.
[0036] In the traditional Modbus protocol, function codes are used to specify the operations that the master requests the slave to perform. Standard function codes range from 0x01 to 0x7F, covering commonly used read and write operations. However, the protocol also reserves some function code ranges (such as 0x65 to 0x72 and 0x64 to 0x6E) for users to define specific functions. In this invention, the unused function code 0x6D (decimal 109) can be selected, utilizing the custom functions of the 0x6D function code.
[0037] In this invention, the custom functionality of the 0x6D function code is utilized to designate it as a function code for instructing authentication and key exchange using the first and second messages. This function code not only identifies the type of communication operation but also the authentication and key exchange process, ensuring enhanced security without altering the existing Modbus protocol framework. Specifically, this invention expands the use of the unused 0x6D function code to support secure operations such as encrypted communication, authentication, and key exchange, while maintaining compatibility with traditional Modbus devices.
[0038] By using function code 0x6D, this invention identifies the message transmission of the authentication and key negotiation process without changing the existing system architecture, thus ensuring the authentication of both communicating parties and the negotiation of security keys.
[0039] Figure 2 A schematic diagram illustrating the Modbus TCP message format is shown below. Figure 2As shown, in the Modbus TCP protocol, a message frame consists of three parts: a header (Modbus Application Protocol, MBAP), a Protocol Data Unit (PDU), and a checksum. The MBAP header is 7 bytes long and consists of a transaction identifier, a protocol identifier, a length, and a unit identifier. The PDU consists of a function code and a data field; the function code is 1 byte long, and the data field length is variable. The checksum is 2 bytes long and is responsible for verifying the data in the message. Table 1 shows the MBAP header format, which includes: a transaction identifier (2 bytes long) indicating the message sequence number; each transaction identifier initiated by the master device should be unique to distinguish different requests; a protocol identifier (2 bytes long) indicating the protocol to which the message belongs; in the Modbus TCP protocol, this field is generally 0x0000, indicating the Modbus TCP protocol; and a length (2 bytes long) indicating how many bytes (including the data field) remain after this field. The unit identifier, 1 byte in length, represents the node address of the receiving slave node for this message, including a 3-bit field ID and a 5-bit node ID. The PDU consists of two parts: a function code and data. The function code, one byte in length, indicates the operation type of the message, such as reading a saved register, writing to a single register, or writing to multiple registers.
[0040] Table 1. MBAP Message Header Format
[0041]
[0042] Figure 3 A schematic diagram of the Modbus RTU / ASCII message format is shown below. Figure 3 As shown, in the Modbus RTU / ASCII protocol, a message frame mainly consists of four parts: device address, function code, data, and checksum. The device address and function code fields are both 1 byte long. The device address field is similar to the unit identifier field in the Modbus TCP protocol, and the custom part of the function code field is the same as in the Modbus TCP protocol. The data field has a variable length. In Modbus RTU, the checksum is a CRC checksum, which is 2 bytes long; in Modbus ASCII, the checksum is an LRC checksum, also 2 bytes long.
[0043] Specifically, the master node and slave nodes share the first and second ciphertexts, including:
[0044] Step B1: The master node generates a first ciphertext based on the first random number, the preset key and the master node address, and generates a third message based on the first ciphertext. The master node then sends the third message to the slave node using the target function code.
[0045] The third message includes the first ciphertext.
[0046] Specifically, the expression for generating the first ciphertext is:
[0047] C1 = F enc (K pre,l ,R1||MID);
[0048] Where C1 is the first ciphertext, K pre,l R1 is the preset key, MID is the first random number, and F is the master node address. enc (·) represents the function that performs encryption operations, and || represents the concatenation operator.
[0049] A third message is generated based on the first ciphertext. The third message is then sent to the slave node using the target function code. Specifically, the first ciphertext is placed in the data field of the Modbus TCP protocol, the MBAP header of the message frame is filled in, and the checksum is calculated to generate the third message. The third message is then sent to the slave node using the target function code, and the master node increments the corresponding counter CTR1 by 1. Alternatively, the first ciphertext is placed in the data of a Modbus RTU / ASCII protocol message frame, the slave node address is filled in, and the checksum is calculated to generate the third message. The third message is then sent to the slave node using the target function code, and the master node increments the corresponding counter CTR1 by 1. l Add 1.
[0050] Counter CTR l It can prevent message replay.
[0051] Step B2: The slave node generates a second ciphertext based on the second random number, the preset key, and the slave node address, and generates a fourth message based on the second ciphertext. The fourth message is then sent to the master node using the target function code.
[0052] The fourth message includes the second ciphertext.
[0053] Specifically, the expression for generating the second ciphertext is:
[0054] C2 = F enc (K pre,l ,R2||SID);
[0055] Where C2 is the second ciphertext, K pre,l R2 is the preset key, SID is the slave node address, and F is the second random number. enc (·) represents the function that performs encryption operations, and || represents the concatenation operator.
[0056] A fourth message is generated based on the second ciphertext. The fourth message is then sent to the master node using the target function code. Specifically, the second ciphertext is placed in the data field of the Modbus TCP protocol, the MBAP header of the message frame is filled in, and the checksum is calculated to generate the fourth message. The fourth message is then sent to the master node using the target function code. The slave node then uses the corresponding counter CTR. l Increment by 1; or, place the second ciphertext into the data of the Modbus RTU / ASCII protocol message frame, fill in the master node address and calculate the checksum to generate the fourth message, and send the fourth message to the master node using the target function code. The slave node will then increment the corresponding counter CTR. l Add 1.
[0057] S102. The master node generates a first message authentication code based on the second ciphertext, the preset key and the first random number, and sends the first message to the slave node using the target function code.
[0058] The first message is a message generated based on the first message authentication code, and the first message includes the first message authentication code.
[0059] Specifically, the master node generates a first message authentication code based on the second ciphertext, the preset key, and the first random number, and sends the first message to the slave node using the target function code, including:
[0060] Step C1: The master node generates the first session key using the key derivation function based on the second ciphertext, the preset key, and the first random number.
[0061] Specifically, step C1 includes:
[0062] Step C11: The master node decrypts the second ciphertext using the preset key to obtain the decrypted second random number.
[0063] The expression for the second random number to be decrypted is:
[0064] R2'||SID=F dec (K pre,l C2);
[0065] Where R2' is the second random number for decryption, SID is the slave node address, and F dec (·) is the function for performing the decryption operation, K pre,l C2 is the preset key, and C2 is the second ciphertext.
[0066] Step C12: The master node generates the first session key using the key derivation function based on the first random number and the decrypted second random number.
[0067] The expression for the first session key is:
[0068] K1 sess,l =KDF(R1||R2');
[0069] Among them, K1 sess,l Let R1 be the first session key, KDF be the key derivation function, R1 be the first random number, and R2′ be the second random number for decryption.
[0070] Step C2: The master node generates a first message authentication code based on the first session key and the first random number, generates a first message based on the first message authentication code, and sends the first message to the slave node using the target function code.
[0071] Specifically, the expression for the first message authentication code is:
[0072] AUTH1 = F mac (K1 sess,l ,R1);
[0073] Wherein, AUTH1 is the first message authentication code, F mac (·) is a one-way function used to generate message authentication codes, K1 sess,l R1 is the first session key, and R2 is the first random number.
[0074] The master node generates a first message based on the first message authentication code and sends it to the slave node using the target function code. Specifically, the first message authentication code is placed in the data field of the Modbus TCP protocol, the MBAP header in the message frame is filled in, and the checksum is calculated to generate the first message. The master node then sends the first message to the slave node using the target function code. The master node then sets the corresponding counter CTR. l Increment by 1; or, insert the first message authentication code into the data of the Modbus RTU / ASCII protocol message frame, fill in the slave node address and calculate the checksum to generate the first message, and send the first message to the slave node using the target function code. The master node will then increment the corresponding counter CTR. l Add 1.
[0075] S103. The slave node authenticates the identity of the master node based on the first message authentication code, the first ciphertext, the preset key, and the second random number.
[0076] Specifically, the slave node authenticates the master node's identity based on the first message authentication code, the first ciphertext, the preset key, and the second random number, including:
[0077] Step D1: The node decrypts the first ciphertext using the preset key to obtain the first random number.
[0078] The expression for the first random number to be decrypted is:
[0079] R1'||MID=Fdec (K pre,l ,C1);
[0080] Where R1' is the first random number for decryption, MID is the master node address, and F... dec (·) is the function for performing the decryption operation, K pre,l C1 is the first ciphertext, which is the preset key.
[0081] Step D2: The node generates a second session key using the key derivation function based on the first and second random numbers obtained from decryption.
[0082] The expression for the second session key is:
[0083] K2 sess,l =KDF(R1'||R2);
[0084] Among them, K2 sess,l R1 is the second session key, KDF is the key derivation function, R2 is the second random number, and R1′ is the first random number for decryption.
[0085] Step D3: The slave node generates the first verification message authentication code based on the second session key and the decrypted first random number.
[0086] The expression for the first verification message authentication code is:
[0087] XAUTH1=F mac (K2 sess,l ,R1');
[0088] Where XAUTH1 is the first verification message authentication code, F mac (·) is a one-way function used to generate message authentication codes, K2 sess,l R1′ is the second session key, and R1′ is the first random number for decryption.
[0089] Step D4: Determine from the node whether the first verification message authentication code is the same as the first message authentication code.
[0090] The node determines whether the first verification message authentication code is the same as the first message authentication code. If they are the same, proceed to step D5; otherwise, proceed to step D6.
[0091] Step D5: The slave node successfully authenticated the master node.
[0092] If the slave node determines that the first verification message authentication code is the same as the first message authentication code, the slave node successfully authenticates the master node, and then continues to execute step S104.
[0093] Step D6: The slave node failed to authenticate the master node.
[0094] If the authentication code of the first verification message is different from the authentication code of the first message, the slave node fails to authenticate the master node. After the slave node fails to authenticate the master node, it can return to step S101 and continue to execute until the slave node successfully authenticates the master node. The authentication can also end after the slave node fails to authenticate the master node.
[0095] S104. When the slave node successfully authenticates the master node's identity, the slave node generates a second message authentication code based on the first ciphertext, the preset key, and the second random number, and sends the second message to the master node using the target function code.
[0096] The second message is a message generated based on the second message authentication code, and the second message includes the second message authentication code.
[0097] Specifically, when the slave node successfully authenticates the master node's identity, the slave node generates a second message authentication code based on the first ciphertext, the preset key, and the second random number, and sends the second message to the master node using the target function code, including:
[0098] Step E1: When the slave node successfully authenticates the master node's identity, the slave node generates a second session key using a key derivation function based on the first ciphertext, the preset key, and the second random number.
[0099] Specifically, step E1 includes:
[0100] Step E11: When the slave node successfully authenticates the master node's identity, the slave node uses the preset key to decrypt the first ciphertext and obtain the first decrypted random number.
[0101] The expression for the first random number decrypted in step E11 is the same as the expression for the first random number decrypted in step D1.
[0102] Step E12: Generate a second session key using the key derivation function based on the first and second random numbers obtained from decryption.
[0103] The expression for the second session key in step E12 is the same as the expression for the second session key in step D2.
[0104] Step E2: The slave node generates a second message authentication code based on the second session key and the second random number, generates a second message based on the second message authentication code, and sends the second message to the master node using the target function code.
[0105] Specifically, the expression for the second message authentication code is:
[0106] AUTH2=F mac (K2 sess,l ,R2);
[0107] Wherein, AUTH2 is the second message authentication code, Fmac (·) is a one-way function used to generate message authentication codes, K2 sess,l R1 is the second session key, and R2 is the second random number.
[0108] A second message is generated based on the second message authentication code. The second message is then sent to the master node using the target function code. Specifically, the second message authentication code is placed in the data field of the Modbus TCP protocol, the MBAP header in the message frame is filled in, and the checksum is calculated to generate the second message. The second message is then sent to the master node using the target function code. The slave node then sets the corresponding counter CTR. l Increment by 1; or, insert the second message authentication code into the data of the Modbus RTU / ASCII protocol message frame, fill in the master node address and calculate the checksum to generate the second message, and send the second message to the master node using the target function code. The slave node will then increment the corresponding counter CTR. l Add 1.
[0109] S105. The master node authenticates the identity of the slave node based on the second message authentication code, the second ciphertext, the preset key and the first random number, so as to realize the security enhancement of the Modbus protocol.
[0110] Specifically, the master node authenticates the slave node's identity based on the second message authentication code, the second ciphertext, the preset key, and the first random number to enhance the security of the Modbus protocol, including:
[0111] Step F1: The master node uses the preset key to decrypt the second ciphertext and obtains the decrypted second random number.
[0112] The expression for the second random number decrypted in step F1 is the same as the expression for the second random number decrypted in step C11.
[0113] Step F2: Generate the first session key using the key derivation function based on the first random number and the decrypted second random number.
[0114] The expression for the first session key in step F2 is the same as the expression for the first session key in step C12.
[0115] Step F3: The master node generates a second verification message authentication code based on the first session key and the decrypted second random number.
[0116] The expression for the second verification message authentication code is:
[0117] XAUTH2=F mac (K1 sess,l ,R2');
[0118] Where XAUTH2 is the message authentication code for the second verification, Fmac (·) is a one-way function used to generate message authentication codes, K1 sess,l R2 is the first session key, and R2′ is the second random number for decryption.
[0119] Step F4: The master node determines whether the second verification message authentication code and the second message authentication code are the same.
[0120] The master node determines whether the second verification message authentication code and the second message authentication code are the same. If they are the same, step F5 is executed; if they are not the same, step F6 is executed.
[0121] Step F5: The master node successfully authenticates the slave node's identity to achieve security enhancements to the Modbus protocol.
[0122] Step F6: Master node authentication of slave node identity failed.
[0123] If the master node determines that the second verification message authentication code is different from the second message authentication code, the master node fails to authenticate the slave node's identity. After the master node fails to authenticate the slave node's identity, it can return to step S101 and continue execution until the master node successfully authenticates the slave node's identity. The authentication process can also end after the master node fails to authenticate the slave node's identity.
[0124] The following embodiment one is a security enhancement of the Modbus TCP protocol in a unicast communication scenario. The Modbus TCP protocol includes target function codes for instructing the use of messages for authentication and key negotiation:
[0125] The two nodes for identity authentication are the master node and the slave node.
[0126] Figure 4 The diagram illustrates the identity authentication and session key negotiation process of Embodiment 1 of the present invention. See [link / reference] Figure 4 As shown, the security enhancement methods for the Modbus TCP protocol in unicast communication scenarios include:
[0127] Step S1: The master node generates a random number R. 11 Using the preset key K pre,l1 Encrypted random number R 11 The ciphertext C is obtained from the master node address MID1 of the master node. 11 , ciphertext C 11 Place it into the data field of the Modbus TCP protocol, fill in the MBAP header, and calculate the checksum to generate a message containing ciphertext C. 11 The message, using the 0x6D function code, contains the ciphertext C. 11 The message is sent to the slave node, and the master node will send the corresponding counter CTR. l1 Add 1.
[0128] Ciphertext C 11 The expression is the same as the expression for the first ciphertext in step B1.
[0129] Step S2: Generate a random number R from the node 21 Using the preset key K pre,l1 Encrypted random number R 21 And obtain the ciphertext C from node address SID1 21 , ciphertext C 21 Place it into the data field of the Modbus TCP protocol, fill in the MBAP header, and calculate the checksum to generate a message containing ciphertext C. 21 The message, using the 0x6D function code, contains the ciphertext C. 21 The message is sent to the master node, and the slave node sends the corresponding counter CTR. l1 Add 1.
[0130] Ciphertext C 21 The expression is the same as the expression for the second ciphertext in step B2.
[0131] Step S3: The master node receives the ciphertext C 21 Then, use the preset key K pre,l1 Decryption: Obtain the decryption random number R from the data field of the Modbus TCP protocol from the slave node. 21 ', and based on the decrypted random number R 21 'and random number R 11 The session key K1 is generated using the key derivation function. sess,l1 .
[0132] Session key K1 sess,l1 The expression is the same as the expression for the first session key in step C12.
[0133] Similarly, the slave node uses the preset key K pre,l1 For ciphertext C 11 Decryption is performed to obtain the decryption random number R corresponding to the master node from the data field of the Modbus TCP protocol. 11 ', and based on the decrypted random number R 11 'and random number R 21 The session key K2 is generated using the key derivation function. sess,l1 .
[0134] Session key K2 sess,l1 The expression is the same as the expression for the second session key in step D2.
[0135] Step S4: The master node uses session key K1 sess,l1 Calculate random number R 11 Message Authentication Code AUTH 11Authenticator code AUTH 11 Place it into the data field of the Modbus TCP protocol, fill in the MBAP header, and calculate the checksum to generate an AUTH message containing the message authentication code. 11 The message, using function code 0x6D, contains the message authentication code AUTH. 11 The master node sends the message to the slave node, and the master node sets the corresponding counter CTR. l1 Add 1.
[0136] Message Authentication Code AUTH 11 The expression is the same as the expression for the first message authentication code in step C2.
[0137] Step S5: Receive the message authentication code AUTH from the node. 11 Then, based on session key K2 sess,l1 and the decrypted random number R 11 'Calculate and verify the message authentication code XAUTH' 11 And compare and verify the message authentication code XAUTH. 11 With message authentication code AUTH 11 Whether they are equal, the verification message authentication code XAUTH. 11 With message authentication code AUTH 11 If they are equal, then the slave node successfully authenticates the master node's identity.
[0138] Verification message authentication code XAUTH 11 The expression is the same as the expression for the message authentication code in the first verification step D3.
[0139] Verification message authentication code XAUTH 11 With message authentication code AUTH 11 If they are not equal, the slave node fails to authenticate the master node's identity. After failing to authenticate the master node, the process can return to step S1 and continue until the slave node successfully authenticates the master node. The authentication process can also end after the slave node fails to authenticate the master node.
[0140] Step S6: The slave node uses session key K2 sess,l1 Calculate random number R 21 Message Authentication Code AUTH 21 Authenticator code AUTH 21 Place it into the data field of the Modbus TCP protocol, fill in the MBAP header, and calculate the checksum to generate an AUTH message containing the message authentication code. 21 The message, using function code 0x6D, contains the message authentication code AUTH. 21 The message is sent to the master node, and the slave node sends the corresponding counter CTR. l1 Add 1.
[0141] Message Authentication Code AUTH 21 The expression is the same as the expression for the second message authentication code in step E2.
[0142] Step S7: The master node receives the message authentication code AUTH. 21 Then, based on session key K1 sess,l1 and the decrypted random number R 21 'Calculate and verify the message authentication code XAUTH' 21 And compare and verify the message authentication code XAUTH. 21 With message authentication code AUTH 21 Whether they are equal, the verification message authentication code XAUTH. 21 With message authentication code AUTH 21 If they are equal, then the master node successfully authenticates the slave node's identity.
[0143] Verification message authentication code XAUTH 21 The expression is the same as the expression for the message authentication code in the second verification step F3.
[0144] Verification message authentication code XAUTH 21 With message authentication code AUTH 21 If they are not equal, the master node fails to authenticate the slave node's identity. After the master node fails to authenticate the slave node's identity, it can return to step S1 and continue execution until the master node successfully authenticates the slave node's identity. The authentication process can also end after the master node fails to authenticate the slave node's identity.
[0145] The Modbus TCP protocol is based on symmetric cryptographic algorithms. For example, it can use the Chinese national cryptographic SM4 symmetric key algorithm for encryption or decryption, and the Chinese national cryptographic SM3 algorithm for generating verification message authentication codes.
[0146] The following second embodiment is a security enhancement for the Modbus RTU / ASCII protocol in a unicast communication scenario. The Modbus RTU / ASCII protocol includes target function codes for indicating the use of messages for authentication and key negotiation:
[0147] The two nodes for identity authentication are the master node and the slave node.
[0148] Security enhancement methods for the Modbus RTU / ASCII protocol in unicast communication scenarios include:
[0149] Step 1: The master node generates a random number R. 12 Use the preset key Kpre,l2 to encrypt a random number R 12 The ciphertext C is obtained by MID2 of the master node's address. 12 , ciphertext C 12The data is inserted into the Modbus RTU / ASCII protocol data, the slave node address is filled in, and the checksum is calculated to generate a data containing ciphertext C. 12 The message, using the 0x6D function code, contains the ciphertext C. 12 The message is sent to the slave node, and the master node will send the corresponding counter CTR. l2 Add 1.
[0150] Ciphertext C 12 The expression is the same as the expression for the first ciphertext in step B1.
[0151] Step 2: Generate a random number R from the node 22 Using the preset key K pre,l2 Encrypted random number R 22 And obtain the ciphertext C from node address SID2 22 , ciphertext C 22 The data is inserted into the Modbus RTU / ASCII protocol data, the master node address is filled in, and the checksum is calculated to generate a data containing ciphertext C. 22 The message, using the 0x6D function code, contains the ciphertext C. 22 The message is sent to the master node, and the slave node sends the corresponding counter CTR. l2 Add 1.
[0152] Ciphertext C 22 The expression is the same as the expression for the second ciphertext in step B2.
[0153] Step 3: The master node receives the ciphertext C 22 Then, use the preset key K pre,l2 Decryption: Obtain the random number R for decryption from the Modbus RTU / ASCII protocol data from the slave node. 22 ', and based on the decrypted random number R 22 'and random number R 12 The session key K1 is generated using the key derivation function. sess,l2 .
[0154] Session key K1 sess,l2 The expression is the same as the expression for the first session key in step C12.
[0155] Similarly, the slave node uses the preset key K pre,l2 For ciphertext C 12 Decryption is performed to obtain the decryption random number R corresponding to the master node from the Modbus RTU / ASCII protocol data. 12 ', and based on the decrypted random number R 12 'and random number R 22 The session key K2 is generated using the key derivation function. sess,l2 .
[0156] Session key K2 sess,l2 The expression is the same as the expression for the second session key in step D2.
[0157] Step 4: The master node uses session key K1 sess,l2 Calculate random number R 12 Message Authentication Code AUTH 12 Authenticator code AUTH 12 The data is inserted into the Modbus RTU / ASCII protocol data, the slave node address is filled in, and the checksum is calculated to generate a message authentication code AUTH. 12 The message, using function code 0x6D, contains the message authentication code AUTH. 12 The master node sends the message to the slave node, and the master node sets the corresponding counter CTR. l2 Add 1.
[0158] Message Authentication Code AUTH 12 The expression is the same as the expression for the first message authentication code in step C2.
[0159] Step 5: Receive the AUTH message authentication code from the node. 12 Then, based on session key K2 sess,l2 and the decrypted random number R 12 'Calculate and verify the message authentication code XAUTH' 12 And compare and verify the message authentication code XAUTH. 12 With message authentication code AUTH 12 Whether they are equal, the verification message authentication code XAUTH. 12 With message authentication code AUTH 12 If they are equal, then the slave node successfully authenticates the master node's identity.
[0160] Verification message authentication code XAUTH 12 The expression is the same as the expression for the message authentication code in the first verification step D3.
[0161] Verification message authentication code XAUTH 12 With message authentication code AUTH 12 If they are not equal, the slave node fails to authenticate the master node's identity. After failing to authenticate the master node, the slave node can return to step 1 and continue execution until it successfully authenticates the master node. The authentication process can also end after the slave node fails to authenticate the master node.
[0162] Step 6: Use session key K2 on the slave node sess,l2 Calculate random number R 22 Message Authentication Code AUTH 22 Authenticator code AUTH 22The data is inserted into the Modbus RTU / ASCII protocol data, the master node address is filled in, and the checksum is calculated to generate the message authentication code AUTH. 22 The message, using function code 0x6D, contains the message authentication code AUTH. 22 The message is sent to the master node, and the slave node sends the corresponding counter CTR. l2 Add 1.
[0163] Message Authentication Code AUTH 22 The expression is the same as the expression for the second message authentication code in step E2.
[0164] Step 7: The master node receives the message authentication code AUTH. 22 Then, based on session key K1 sess,l2 and the decrypted random number R 22 'Calculate and verify the message authentication code XAUTH' 22 And compare and verify the message authentication code XAUTH. 22 With message authentication code AUTH 22 Whether they are equal, the verification message authentication code XAUTH. 22 With message authentication code AUTH 22 If they are equal, then the master node successfully authenticates the slave node's identity.
[0165] Verification message authentication code XAUTH 22 The expression is the same as the expression for the message authentication code in the second verification step F3.
[0166] Verification message authentication code XAUTH 22 With message authentication code AUTH 22 If they are not equal, the master node fails to authenticate the slave node's identity. After the master node fails to authenticate the slave node's identity, it can return to step 1 and continue execution until the master node successfully authenticates the slave node's identity. The authentication process can also end after the master node fails to authenticate the slave node's identity.
[0167] The Modbus RTU / ASCII protocol is implemented based on symmetric cryptographic algorithms. For example, it can use the Chinese national cryptographic SM4 symmetric key algorithm for encryption or decryption, and can use the Chinese national cryptographic SM3 algorithm to generate verification message authentication codes.
[0168] Embodiments 1 and 2 of this invention introduce two-way authentication to ensure that both communicating parties (master node and slave node) authenticate each other before communication begins. The master node and slave node generate encrypted data using their respective preset keys, ensuring the legitimacy of their identities and preventing unauthorized devices from accessing the system. By introducing random number generation during the authentication process, both parties can generate independent session keys before each communication. Encrypting the random numbers using their respective preset keys ensures that the generated keys are confidential and unique, preventing the theft or forgery of session keys. This invention fully complies with the current national standard GB / T19582—2008 "Industrial Automation Network Specification Based on Modbus Protocol," requires no modification to the current Modbus protocol frame format, is compatible with traditional Modbus TCP and Modbus RTU / ASCII protocols, and requires no hardware or significant software updates to existing equipment. Authentication and key negotiation functions can be supported simply by adding custom function codes, facilitating seamless integration and deployment in existing systems.
[0169] In terms of security, this invention effectively prevents common network attacks and ensures communication security by introducing technologies such as random numbers, key negotiation, and message authentication codes. Each session generates a new session key and random number, preventing replay attacks; that is, the same message cannot be reused in different sessions. Furthermore, through identity authentication and message integrity verification, this invention effectively prevents man-in-the-middle attacks, avoiding attackers from tampering with data or impersonating legitimate devices for communication. Simultaneously, all communication data undergoes encryption and authentication processing, ensuring that only authenticated devices can participate in communication, thereby effectively preventing counterfeit devices from accessing the network. These security mechanisms collectively guarantee the integrity, confidentiality, and trustworthiness of the system, reducing potential security risks.
[0170] In terms of performance, compared with existing identity authentication schemes based on public key infrastructure or digital signatures, this invention employs symmetric encryption and message authentication code mechanisms, significantly reducing computational overhead. Furthermore, this invention uses only four types of cryptographic elements: a pre-set key, a session key, a first random number, and a second random number, while existing schemes use as many as 11 cryptographic elements. Managing so many cryptographic elements in industrial control systems is complex. This involves asymmetric cryptographic operations, and considering the limited computing power of device nodes in actual industrial control networks—specifically, current industrial control devices such as Remote Terminal Units (RTUs), Programmable Logic Controllers (PLCs), and sensors—mostly have microcontrollers that are 8-bit, 16-bit, or 32-bit, with clock speeds ranging from 10MHz to 200MHz. These asymmetric cryptographic operations are time-consuming, on the order of seconds, resulting in high latency. Traditional public key algorithms and digital signatures are often difficult to implement on these devices and are not suitable for industrial control network scenarios. For example, for an 84MHz Arduino Due, the operation time for generating a single key using the P521 public-key signature algorithm is 1860ms / byte, and even using only public-key encryption, the operation time for a single encryption operation is 1503ms / byte. In contrast, this invention, by using a pre-set key and a symmetric encryption-based authentication method, achieves a single encryption operation time of only 6.58µs / byte using the AES128 symmetric encryption algorithm, ensuring that authentication and key negotiation for low-performance devices are not limited by resources. This invention introduces a key negotiation mechanism based on random number generation, enabling rapid generation of session keys between devices and ensuring data integrity and authentication through message authentication codes. The key negotiation and authentication methods of this invention can be completed in a short time, making them suitable for industrial control systems with high real-time requirements. Compared to traditional authentication mechanisms based on public-key encryption and multi-round interactions, this invention reduces the number of message exchanges during the authentication process, lowers latency, and improves overall communication efficiency.
[0171] The authentication process of this invention is performed directly between the master and slave nodes in a decentralized manner, eliminating the need for an external authentication server. This reduces system complexity and potential points of failure, thereby improving system reliability. This invention is applicable not only to the Modbus TCP protocol but also to the Modbus RTU / ASCII protocol, exhibiting strong adaptability and compatibility. Whether via Ethernet connection (Modbus TCP) or serial communication (Modbus RTU / ASCII), this solution provides effective authentication and security for Modbus communication in different environments, enhancing its deployability in various industrial control systems. It can be easily integrated into existing industrial automation systems without large-scale system reconstruction or protocol replacement, reducing implementation complexity and cost. Due to its low computational requirements and simplified protocol flow, equipment manufacturers and system integrators can easily apply this solution to existing Modbus devices and networks, thereby improving the overall system security.
[0172] The Modbus protocol security enhancement method in unicast communication scenarios of the present invention has broad application prospects. It is not limited to industrial control networks, but can also be used for various purposes such as device authentication and secure data transmission in multiple fields (such as intelligent transportation, industrial IoT, smart homes, autonomous driving, digital currency, etc.).
[0173] Based on the above Figure 1 As can be seen from the implementation, the Modbus protocol of this invention includes a target function code for identity authentication and key negotiation using messages. The master node and slave node share a first ciphertext and a second ciphertext. The master node generates a first message authentication code based on the second ciphertext, a preset key, and a first random number, and sends the first message to the slave node using the target function code. The slave node authenticates the identity of the master node based on the first message authentication code, the first ciphertext, the preset key, and the second random number. When the slave node successfully authenticates the identity of the master node, the slave node generates a second message authentication code based on the first ciphertext, the preset key, and the second random number, and sends the second message to the master node using the target function code. The master node authenticates the identity of the slave node based on the second message authentication code, the second ciphertext, the preset key, and the first random number, thereby achieving security enhancement of the Modbus protocol. In this way, by sharing the first and second ciphertexts, the communication between the master node and the slave node can be ensured, and the legitimacy of the master node and the slave node can be verified. The slave node can authenticate the identity of the master node by generating the first message authentication code, and the master node can authenticate the identity of the slave node by generating the second message authentication code. Furthermore, the message is sent using the target function code for negotiation and authentication, which can ensure the validity of the identities of both communicating parties and guarantee the integrity and confidentiality of the data during transmission.
[0174] Based on the same inventive concept, as an implementation of the above-mentioned method for enhancing the security of the Modbus protocol in a unicast communication scenario, this embodiment of the invention also provides a system for enhancing the security of the Modbus protocol in a unicast communication scenario. Figure 5 This is a structural diagram of the Modbus protocol security enhancement system in a unicast communication scenario according to an embodiment of the present invention. See [link / reference]. Figure 5 As shown, the Modbus protocol includes target function codes that utilize messages for authentication and key negotiation. The system may include:
[0175] The shared module 501 is used for sharing a first ciphertext and a second ciphertext between the master node and the slave node. The first ciphertext is the ciphertext corresponding to the master node, and the second ciphertext is the ciphertext corresponding to the slave node.
[0176] The first generation module 502 is used by the master node to generate a first message authentication code based on the second ciphertext, the preset key and the first random number, and to send the first message to the slave node using the target function code. The first message is a message generated based on the first message authentication code and includes the first message authentication code.
[0177] The first authentication module 503 is used for slave nodes to authenticate the identity of the master node based on the first message authentication code, the first ciphertext, the preset key and the second random number;
[0178] The second generation module 504 is used to generate a second message authentication code based on the first ciphertext, the preset key and the second random number when the slave node successfully authenticates the identity of the master node, and send the second message to the master node using the target function code. The second message is a message generated based on the second message authentication code and includes the second message authentication code.
[0179] The second authentication module 505 is used by the master node to authenticate the identity of the slave node based on the second message authentication code, the second ciphertext, the preset key and the first random number, so as to realize the security enhancement of the Modbus protocol.
[0180] The device may also include:
[0181] The configuration module is used to set unused function codes as target function codes using custom functions. The target function codes are used to indicate the use of the first message and the second message for authentication and key negotiation.
[0182] The shared module 501 is specifically used by the master node to generate a first ciphertext based on a first random number, a preset key, and the master node address, and to generate a third message based on the first ciphertext. The master node then sends the third message to the slave node using a target function code. The third message includes the first ciphertext. The slave node generates a second ciphertext based on a second random number, a preset key, and the slave node address, and to generate a fourth message based on the second ciphertext. The slave node then sends the fourth message to the master node using a target function code. The fourth message includes the second ciphertext.
[0183] The first generation module 502 is specifically used by the master node to generate a first session key based on the second ciphertext, the preset key and the first random number through a key derivation function; the master node generates a first message authentication code based on the first session key and the first random number, generates a first message based on the first message authentication code, and sends the first message to the slave node using the target function code.
[0184] The first generation module 502, the master node generates a first session key through a key derivation function based on the second ciphertext, a preset key and a first random number, including: the master node decrypts the second ciphertext using the preset key to obtain a decrypted second random number; the master node generates the first session key through a key derivation function based on the first random number and the decrypted second random number.
[0185] The first authentication module 503 is specifically used for the slave node to decrypt the first ciphertext using a preset key to obtain a first random number; the slave node generates a second session key using a key derivation function based on the first and second random numbers; the slave node generates a first verification message authentication code based on the second session key and the first random number; the slave node determines whether the first verification message authentication code is the same as the first message authentication code; if they are the same, the slave node successfully authenticates the master node; if they are different, the slave node fails to authenticate the master node.
[0186] The second generation module 504 is specifically used to generate a second session key by the slave node based on the first ciphertext, the preset key, and the second random number through a key derivation function when the slave node successfully authenticates the identity of the master node; the slave node generates a second message authentication code based on the second session key and the second random number, generates a second message based on the second message authentication code, and sends the second message to the master node using the target function code.
[0187] The second generation module 504, when the slave node successfully authenticates the master node's identity, generates a second session key based on the first ciphertext, a preset key, and a second random number through a key derivation function. This includes: when the slave node successfully authenticates the master node's identity, the slave node decrypts the first ciphertext using the preset key to obtain a decrypted first random number; and generates the second session key based on the decrypted first random number and the second random number through a key derivation function.
[0188] The second authentication module 505 is specifically used by the master node to decrypt the second ciphertext using a preset key to obtain a decrypted second random number; based on the first random number and the decrypted second random number, a first session key is generated through a key derivation function; the master node generates a second verification message authentication code based on the first session key and the decrypted second random number; the master node determines whether the second verification message authentication code and the second message authentication code are the same; if they are the same, the master node successfully authenticates the slave node's identity to achieve security enhancement of the Modbus protocol; if they are different, the master node fails to authenticate the slave node's identity.
[0189] It should be noted that the above description of the Modbus protocol security enhancement system embodiment in unicast communication scenarios is similar to the description of the Modbus protocol security enhancement method embodiment in unicast communication scenarios, and has similar beneficial effects. For technical details not disclosed in the embodiments of the Modbus protocol security enhancement system in unicast communication scenarios of this invention, please refer to the description of the Modbus protocol security enhancement method embodiment in unicast communication scenarios of this invention for understanding.
[0190] The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for enhancing the security of the Modbus protocol in a unicast communication scenario, characterized in that, The Modbus protocol includes target function codes for authentication and key negotiation using messages, including: The master node and the slave node share a first ciphertext and a second ciphertext, where the first ciphertext is the ciphertext corresponding to the master node and the second ciphertext is the ciphertext corresponding to the slave node. The master node generates a first message authentication code based on the second ciphertext, the preset key, and the first random number, and sends a first message to the slave node using the target function code. The first message is a message generated based on the first message authentication code and includes the first message authentication code. The slave node authenticates the identity of the master node based on the first message authentication code, the first ciphertext, the preset key, and the second random number. When the slave node successfully authenticates the identity of the master node, the slave node generates a second message authentication code based on the first ciphertext, the preset key and the second random number, and sends a second message to the master node using the target function code. The second message is a message generated based on the second message authentication code and includes the second message authentication code. The master node authenticates the identity of the slave node based on the second message authentication code, the second ciphertext, the preset key, and the first random number, thereby enhancing the security of the Modbus protocol.
2. The Modbus protocol security enhancement method in unicast communication scenarios according to claim 1, characterized in that, Before sharing the first and second ciphertexts between the master and slave nodes, the method further includes: Using a custom function, an unused function code is set as the target function code, which is used to indicate the use of the first message and the second message for authentication and key negotiation.
3. The Modbus protocol security enhancement method in unicast communication scenarios according to claim 1, characterized in that, The master node and slave nodes share a first ciphertext and a second ciphertext, including: The master node generates the first ciphertext based on the first random number, the preset key, and the master node address, and generates a third message based on the first ciphertext. The master node then sends the third message to the slave node using the target function code. The third message includes the first ciphertext. The slave node generates the second ciphertext based on the second random number, the preset key, and the slave node address, and generates a fourth message based on the second ciphertext. The fourth message is sent to the master node using the target function code. The fourth message includes the second ciphertext.
4. The Modbus protocol security enhancement method in unicast communication scenarios according to claim 1, characterized in that, The master node generates a first message authentication code based on the second ciphertext, a preset key, and a first random number, and sends the first message to the slave node using the target function code, including: The master node generates a first session key based on the second ciphertext, the preset key, and the first random number using a key derivation function; The master node generates the first message authentication code based on the first session key and the first random number, generates the first message based on the first message authentication code, and sends the first message to the slave node using the target function code.
5. The Modbus protocol security enhancement method in a unicast communication scenario according to claim 4, characterized in that, The master node generates a first session key based on the second ciphertext, the preset key, and the first random number using a key derivation function, including: The master node uses the preset key to decrypt the second ciphertext and obtains the decrypted second random number; The master node generates the first session key using the key derivation function based on the first random number and the second random number used for decryption.
6. The Modbus protocol security enhancement method in a unicast communication scenario according to claim 1, characterized in that, The slave node authenticates the identity of the master node based on the first message authentication code, the first ciphertext, the preset key, and the second random number, including: The slave node uses the preset key to decrypt the first ciphertext and obtains the first random number after decryption; The slave node generates a second session key using a key derivation function based on the first and second random numbers obtained from the decryption. The slave node generates a first verification message authentication code based on the second session key and the decrypted first random number; The node determines whether the first verification message authentication code is the same as the first message authentication code. If they are the same, then the slave node has successfully authenticated the master node; If they are not the same, the slave node fails to authenticate the master node.
7. The Modbus protocol security enhancement method in a unicast communication scenario according to claim 1, characterized in that, When the slave node successfully authenticates the master node's identity, the slave node generates a second message authentication code based on the first ciphertext, the preset key, and the second random number, and sends a second message to the master node using the target function code, including: When the slave node successfully authenticates the identity of the master node, the slave node generates a second session key using a key derivation function based on the first ciphertext, the preset key, and the second random number. The slave node generates the second message authentication code based on the second session key and the second random number, generates the second message based on the second message authentication code, and sends the second message to the master node using the target function code.
8. The Modbus protocol security enhancement method in a unicast communication scenario according to claim 7, characterized in that, When the slave node successfully authenticates the master node's identity, the slave node generates a second session key using a key derivation function based on the first ciphertext, the preset key, and the second random number, including: When the slave node successfully authenticates the identity of the master node, the slave node uses the preset key to decrypt the first ciphertext and obtains the first decrypted random number. The second session key is generated using the key derivation function based on the first and second random numbers obtained from the decryption.
9. The Modbus protocol security enhancement method in a unicast communication scenario according to claim 1, characterized in that, The master node authenticates the identity of the slave node based on the second message authentication code, the second ciphertext, the preset key, and the first random number, thereby enhancing the security of the Modbus protocol, including: The master node uses the preset key to decrypt the second ciphertext and obtains the decrypted second random number; Based on the first random number and the decrypted second random number, a first session key is generated using a key derivation function; The master node generates a second verification message authentication code based on the first session key and the decrypted second random number; The master node determines whether the second verification message authentication code and the second message authentication code are the same; If they are the same, the master node successfully authenticates the slave node's identity, thereby achieving security enhancement of the Modbus protocol; If they are different, the master node fails to authenticate the slave node's identity.
10. A Modbus protocol security enhancement system for unicast communication scenarios, characterized in that, The Modbus protocol includes target function codes for authentication and key negotiation using messages, including: A sharing module is used for sharing a first ciphertext and a second ciphertext between a master node and a slave node. The first ciphertext is the ciphertext corresponding to the master node, and the second ciphertext is the ciphertext corresponding to the slave node. The first generation module is used by the master node to generate a first message authentication code based on the second ciphertext, a preset key and a first random number, and to send a first message to the slave node using the target function code. The first message is a message generated based on the first message authentication code and includes the first message authentication code. The first authentication module is used for the slave node to authenticate the identity of the master node based on the first message authentication code, the first ciphertext, the preset key, and the second random number; The second generation module is used to, when the slave node successfully authenticates the identity of the master node, generate a second message authentication code based on the first ciphertext, the preset key and the second random number, and send a second message to the master node using the target function code. The second message is a message generated based on the second message authentication code and includes the second message authentication code. The second authentication module is used by the master node to authenticate the identity of the slave node based on the second message authentication code, the second ciphertext, the preset key and the first random number, so as to realize the security enhancement of the Modbus protocol.