Modbus Master-Slave Communication

An accurate visualization of Modbus protocol communication & security vulnerabilities

Modbus is a serial communication protocol developed in 1979 for use with programmable logic controllers (PLCs). It has become a de facto standard in industrial communication and is now commonly used for connecting industrial electronic devices.

In a Modbus network:

  • Master (Client): Initiates communication by sending requests to slaves
  • Slave (Server): Responds to the master's requests by providing data or performing actions
  • Each slave has a unique address (1-247)
  • Only one master can exist on a standard Modbus network

Modbus Communication Modes

RTU Mode

Uses binary encoding with CRC error checking

More efficient, compact messages

Typically used over RS-485 or RS-232

ASCII Mode

Uses ASCII characters with LRC error checking

Less efficient but easier to debug

More tolerant of transmission delays

TCP/IP Mode

Extension of Modbus for use over TCP/IP networks

Uses MBAP header instead of address field and error check

Allows multiple simultaneous connections

Data Model

Data Type Access Size Address Range
Coils Read/Write 1 bit 00001-09999
Discrete Inputs Read-only 1 bit 10001-19999
Input Registers Read-only 16 bits 30001-39999
Holding Registers Read/Write 16 bits 40001-49999

Common Modbus Function Codes

Code Function Description
01 Read Coils Read status of discrete output coils
02 Read Discrete Inputs Read status of discrete inputs
03 Read Holding Registers Read contents of holding registers
04 Read Input Registers Read contents of input registers
05 Write Single Coil Write value to a single coil
06 Write Single Register Write value to a single register
15 Write Multiple Coils Write values to multiple coils
16 Write Multiple Registers Write values to multiple registers
08 Diagnostics Various diagnostic functions

Error Codes (Exception Responses)

  • 01: Illegal Function - Function code not supported
  • 02: Illegal Data Address - Address outside valid range
  • 03: Illegal Data Value - Value outside valid range
  • 04: Server Device Failure - Unrecoverable error
  • 05: Acknowledge - Request being processed (long duration)
  • 06: Server Device Busy - Server busy with another request

Modbus Security Vulnerabilities

Modbus was designed in the late 1970s when industrial networks were isolated and security was not a primary concern. As a result, the protocol has several inherent security weaknesses:

No Authentication

Modbus has no built-in authentication mechanism. Any device can send commands to a Modbus slave if it can access the network.

No Encryption

Data is transmitted in plaintext, allowing attackers to intercept and read all communications, including sensitive control commands.

No Integrity Checking

While CRC/LRC checks detect transmission errors, they don't prevent deliberate tampering with message content.

No Session Tracking

Modbus is stateless with no session management, making it vulnerable to replay attacks and message injection.

Common Attack Scenarios

Man-in-the-Middle Attack

An attacker intercepts communications between master and slave, potentially modifying commands or responses.

Impact: Can manipulate industrial processes by changing setpoints, altering sensor readings, or issuing unauthorized commands.

Replay Attack

An attacker captures valid Modbus messages and replays them later to cause the same action to occur repeatedly.

Impact: Can disrupt operations by repeating critical commands out of sequence or at inappropriate times.

Unauthorized Command Execution

An attacker sends unauthorized write commands to Modbus slaves to alter settings or operations.

Impact: Can change critical parameters, disable safety systems, or cause equipment damage.

Denial of Service (DoS)

An attacker floods the Modbus network with invalid requests or excessive traffic.

Impact: Can prevent legitimate commands from being processed, potentially causing system failures or safety issues.

Security Recommendations

Network Segmentation

Isolate control systems networks from corporate networks and the internet using firewalls and DMZs.

Encrypted Tunnels

Use VPN or SSL/TLS tunnels to encrypt Modbus TCP traffic when it must traverse untrusted networks.

Access Control

Implement strict access controls on network equipment and use whitelisting to allow only known devices.

Monitoring & Intrusion Detection

Deploy IDS/IPS systems that understand industrial protocols to detect anomalous Modbus traffic.

Secure Protocols

Consider using secure alternatives like OPC UA, Modbus with TLS, or other secure industrial protocols.

Regular Security Assessments

Conduct periodic security assessments and penetration testing of industrial control systems.

Interactive Modbus Communication Simulation

MASTER
Function: Read Holding
Target: Slave 1
Initiates all communication
SLAVE ID: 1
Status: Idle
Registers: 40001-40003
Temperature Sensor
SLAVE ID: 2
Status: Idle
Registers: 40101-40103
Pressure Controller
SLAVE ID: 3
Status: Idle
Registers: 40201-40203
Flow Meter
⚠️

Device Data Values

Slave 1: Temperature Sensor

Holding Registers:
0x00A1 0x00B2 0x00C3
Addresses: 40001-40003 (Temperature values)
Coils:
Addresses: 00001-00008 (Control bits)

Slave 2: Pressure Controller

Holding Registers:
0x0145 0x0278 0x03AB
Addresses: 40101-40103 (Pressure values)
Coils:
Addresses: 00101-00108 (Control bits)

Slave 3: Flow Meter

Holding Registers:
0x0064 0x00C8 0x012C
Addresses: 40201-40203 (Flow values)
Coils:
Addresses: 00201-00208 (Control bits)

Communication Log

System initialized. Ready for Modbus communication.

Modbus Frame Structure

RTU Frame Format

Slave Address
(1 byte)
Function Code
(1 byte)
Data
(n bytes)
CRC
(2 bytes)

CRC = Cyclic Redundancy Check for error detection

TCP/IP Frame Format

Transaction ID
(2 bytes)
Protocol ID
(2 bytes)
Length
(2 bytes)
Unit ID
(1 byte)
Function Code
(1 byte)
Data
(n bytes)

MBAP Header (Modbus Application Protocol) = Transaction ID + Protocol ID + Length + Unit ID

Example: Read Holding Registers (Function 03)

Request Frame:

01
03
00 6B
00 03
76 87
Slave
ID
Function
Code
Starting
Address
Quantity of
Registers
CRC

Response Frame:

01
03
06
02 2B
00 00
00 64
B9 AF
Slave
ID
Function
Code
Byte
Count
Register
Value 1
Register
Value 2
Register
Value 3
CRC