Modbus = Basics + Traffic + Attack
Zakhar Bernhardt
ICS/OT Cybersecurity Expert | Labshock & Patented NVIDIA AI IDS & 1st OT SIEM Creator | 10k+ Followers | Pentesting & SOC
?? Introduction
Let’s talk about Modbus. It’s one of the most common communication protocols in industrial automation. It’s been around since 1979 and is still widely used to connect devices like PLCs, sensors, and actuators.
The thing is, Modbus was built for simplicity, not security. That makes it a potential risk in modern OT environments. If you’re working with OT systems, understanding how Modbus works - and how it can be exploited - is key to securing your environment.
In this article, I’ll walk you through:
By the end, you’ll know Modbus inside out and have the tools to test, analyze, and secure systems using it. Whether you’re an engineer, security expert, or just getting started with OT, this guide will give you both theory and practical knowledge.
Check Demo Video – better to see it 1 than hear about it 100 times
?? Theory
let's talk
Let’s start with the basics of Modbus and how it works. It’s a communication protocol that allows devices in industrial systems to talk to each other. Think of it as a simple language used in OT environments.
[>] Modbus Basics
Different Types of protocol:
Master-Slave Model:
Lightweight and Simple:
[>] Why Modbus is Still Used
Modbus sticks around because it’s:
However, its simplicity is also its weakness.
Understanding how it works will help you secure it.
?? Coils, Registers & Function Codes
what inside
Modbus organizes data into different types, and each type serves a specific purpose. Let’s break them down.
[>] Coils
What are they?
Coils are binary values: ON (1) or OFF (0).
Think of them like switches or relays you can control.
Use case:
Operations:
[>] Registers
Registers store 16-bit data and come in two types:
Input Registers:
Holding Registers:
[>] Function Codes
Function codes are like instructions for Modbus devices.
Here are the most common ones:
?? Practical Examples
network packets
Now that you know the basics of Modbus, let’s see it in action. We’ll use Labshock to simulate a Modbus environment and perform basic read/write operations on coils and registers.
[>] Setting Up Labshock
Getting Labshock up and running is simple. You only need Docker, Docker Compose, and optional Git installed on your system. No extra libraries or tools are required.
Readme can be found here: Github project
Full install guide here: Quickstart Guide
This article based on Labshock v1.3
[>] Requirements
What you need to crack Modbus:
[1] Python and one library:
sudo apt update
sudo apt install python3-pip
python3 -m pip install pymodbus --break-system-packages
[2] modbus_client.py for 4 operations:
[>] Basic Operations
Once the setup is done, let’s perform some basic tasks:
Read Coils:
Read Registers:
Example of Packets to Read Coils & Registers, same as Wireshark output:
Let's explain what we get:
Write Coils:
Write Registers:
Example of Packets to Write Coils & Registers, same as Wireshark output:
Let's explain what we get:
?? Modbus Attack
simple & devastating
In this section, you'll see a Modbus write attack step by step. This example will show how attackers can manipulate devices by exploiting the protocol’s lack of security. We’ll use Labshock to simulate a Modbus environment and standard tools to scan, modify, and analyze the traffic.
[>] Attack Overview
The goal of the attack is to:
[>] Step 1: Scanning the Network
The first step is to discover Modbus-enabled devices on the network. Using a tool like nmap, we perform a scan to identify devices running the Modbus service (port 502). The scan reveals active devices, their Unit IDs, and additional device information.
[>] Step 2: Writing to a Coil
Once a Modbus device is identified, the next step is to manipulate a coil. Coils control binary operations, such as turning devices ON or OFF. Writing to a coil can
[>] Step 3: Writing to a Register
Registers store critical data such as sensor readings or configuration values. By modifying a register:
[>] Step 4: Monitoring Network Traffic
Using a Network Swiftness service like Wireshark, we capture and analyze the network traffic generated during the attack. The captured packets show:
These packets highlight how easy it is to execute a Modbus attack due to the lack of encryption or authentication in the protocol.
[>] Key Takeaways
This practical example demonstrates the inherent risks of using Modbus in OT environments without additional security measures. Attackers can exploit the protocol to:
To secure Modbus environments, it’s essential to use techniques like network segmentation, intrusion detection systems, and protocol gateways.
?? Conclusion
Modbus remains a cornerstone of industrial automation, but its simplicity comes at the cost of security. As demonstrated, a lack of authentication or encryption makes it easy for attackers to manipulate devices, disrupt operations, and compromise safety.
Understanding how Modbus works, from reading and writing data to analyzing network traffic, is critical for anyone working in OT environments. With tools like Labshock, you can safely simulate, test, and learn about these vulnerabilities in a controlled setting.
The takeaway is clear: while Modbus is efficient and widely supported, relying on it without additional security measures is risky. Implement solutions like network segmentation, secure gateways, and OT monitoring systems (e.g., OT SIEM) to protect your operations.
Security in OT isn’t just about knowing the risks - it’s about actively mitigating them.
You are at Level 3 Industrial Tree - Protocols 1/5 Skill
Don't forget to check your main Leveling Guide
And put ?? comments or ?? likes, it helps a lot to get your feedback!
Yours, Zakhar
?? please put Stars here ??
Cybersecurity Advisory | Vulnerability Mgt | Cloud Security & Governance | Cybersecurity Solution Architecture | Third-party Risk Mgt | OT & ICS Cybersecurity | Secure SDLC | Product Security | DevSecOps | GRC
3 周Zakhar Bernhardt. Thanks for sharing about ModBus protocol. It's a widely used protocol in OT/ICS automation. Understanding the vulnerabilities and countermeasures are very much important for OT defenders.
PLC, SCADA,DCS, ICS OT Security ICS/OT NIST 800-82, ISCA 62443 Industrial Automation, Third Party Communication
3 周Very important as per interview prospective. Thank you sir for sharing.
ICS/OT Cybersecurity Expert | Labshock & Patented NVIDIA AI IDS & 1st OT SIEM Creator | 10k+ Followers | Pentesting & SOC
1 个月Practice hands-on Modbus Lab ready! You can find Lab to this Article: https://www.dhirubhai.net/posts/zakharb_ics-level3-protocols-modbus-activity-7298038683201425408-soWn?utm_source=share&utm_medium=member_desktop&rcm=ACoAADqgKYQBXBk7F_RfyEoCyJ49OVlyhr8JDa4
ICS/OT Cybersecurity Expert | Labshock & Patented NVIDIA AI IDS & 1st OT SIEM Creator | 10k+ Followers | Pentesting & SOC
1 个月Labshock v1.3 is released You can easily check and control your network traffic! https://www.dhirubhai.net/posts/zakharb_otsiem-ot-ics-activity-7297313894543376384-xsFZ
OT Cybersecurity Engineer@ Saudi Aramco | GRC Certified Cybersecurity Pro
1 个月Thanks a lot dear Zakhar Bernhardt for this informative article, as usual, highly appreciated