Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Reading Modbus traffic and spotting abnormal writes

After this lesson: I can spot a Modbus write that an allow-list does not expect.

65 min lesson2 commandsIndustrial control system security lab: a simulated PLC, Modbus, HMI and conduit

Twenty seconds of a plant talking

Reading Modbus traffic means decoding each request on a control network and asking whether it belongs there. A plant's network is quiet and regular, which makes a stranger easy to see.

An HMI asks the same questions every second. A request that writes, from a machine nobody expected, stands out. You read a fixed capture in your own lab, never a real plant's network.

By the end of this lesson

Note

I can spot a Modbus write that an allow-list does not expect.

Key words

WordWhat it meansExample
Capturea saved record of the requests on a network
Pollingasking the same question again and again on a timer
Allow-lista list of what is expected, so anything else stands out
Writera machine allowed to send writeseng
Reconnaissancelooking around before an attack

The cells students fill in are left blank in this preview.

The one rule

Warning

Capture and read traffic only on networks you own or have written permission to watch. The captures here are made up and fixed. Listening on somebody else's network can be a crime, and on a plant even a careless scan can stop a device.

Normal traffic is regular and boring

The capture in the lab is twenty seconds of requests to the PLC, one per line: the time, the source and the bytes in hex.

Most lines come from the HMI. Every second it reads the input registers and the discrete inputs, so the same two requests repeat twenty times. That rhythm is what normal looks like.

Decode the capture and count the requests

Command
docker exec work python3 steps/decode.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Worked example: the requests not from the HMI

TimeSourceFunctionWhat it did
6.5laptop3Read the setpoints
7.5laptop8Asked for diagnostics
8.5laptop3Read address 40, which does not exist
9.5 and 9.7laptop5Wrote manual mode, then pump on
12.5eng6Wrote 78 into the high setpoint
14.5laptop6Wrote 100 into the high setpoint

The cells students fill in are left blank in this preview.

Try it: tell reads from writes

Code: python
capture = ["0.0 hmi 000100000006010400000005",
           "9.5 laptop 00040000000601050001ff00",
           "12.5 eng 00010000000601060001004e"]

for line in capture:
    parts = line.split()
    data = bytes.fromhex(parts[2])
    fc = data[7]
    kind = "write" if fc in (5, 6, 15, 16) else "read"
    print(parts[0], parts[1], "function", fc, kind)
# Add the line "14.5 laptop 000600000006010600010064". What does it write, and where?

An allow-list says which writes are expected

Reads are rarely dangerous. Writes change the plant, so each one is checked against an allow-list.

The lab's list says three things. Only the engineering workstation, eng, may write. It may write only holding registers 0 and 1. The low setpoint must be 10 to 40, and the high one 60 to 85.

Check every write against the allow-list

Command
docker exec work python3 steps/spot.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

What the check found

Three writes came from the laptop, which is not an allowed writer: manual mode, pump on and a high setpoint of 100. Each is flagged.

The engineering write of 78 was from an allowed writer, to an expected register and inside its range. It is marked expected.

A common mistake

Warning

Many people think only writes matter, so reads can be ignored. Writes do the damage, but reads usually come first. The laptop read the setpoints and probed addresses before it wrote anything. Spotting those reads gives a warning before the plant is touched.

About this lab and its source: Industrial control system security lab: a simulated PLC, Modbus, HMI and conduit

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.