Industrial control system security lab: a simulated PLC, Modbus, HMI and conduit

This lab gives each student a small simulated plant of their own: a water tank with a level sensor, a pump and an outlet, run by a simulated PLC that speaks Modbus/TCP. Beside it are an operator’s screen (an HMI) that only reads, a conduit that passes Modbus reads and refuses writes, and a box of short Python scripts that decode requests, read a capture, force the pump and watch the plant.

It is defensive: the one rule, on every page and in the file itself, is that a student touches only their own copy and never a real plant or device. Every copy has no route to the internet and none to any other student, and nothing is downloaded into it.

What students learn

How a PLC runs a plant in scans, reading a sensor and driving a pump, and why the HMI only shows it. They build a Modbus request byte by byte, see the PLC refuse three with exception codes 1, 2 and 3, and change a setpoint with no password, because Modbus has none. They decode a capture and flag the writes an allow-list does not expect, force the pump on and watch the safety trip latch at exactly 95 per cent, reset it only at the PLC’s own panel, send writes through a conduit that refuses them, and alert on a capture against a baseline. It suits network security, security operations and embedded systems courses; check your own awarding body’s unit for the exact wording, none is quoted here.

Run it in your browser

The lab starts four services, plc, gateway, hmi and work, each writing its own short Python program when it starts, with nothing downloaded. The HMI is the one web page. The terminal beside the lab has no Python of its own, so it reaches the scripts with docker exec work and the PLC’s panel with docker exec plc, followed by the command to run inside.

  1. Open the Container page. Open Build on the bar and choose Run a container. Anybody may open it, and the Git lab and the SQL lab start with no account. Every other lab needs a free account: create one, sign in, then press Start.
  2. Find the lab. The Sample labs card lists every sample. Find Industrial control: a simulated tank, PLC and Modbus.
  3. Press Start. Start runs it as it is, in one press. Edit the file first opens the compose file so you can change it before you start.
  4. Open it. On the lab’s page, the lab bar has a link called HMI: press it to watch the tank’s level, pump, mode and safety trip, refreshed every second. Then press Open terminal and type docker exec work python3 steps/plant.py to read the PLC’s setpoints, 20 and 80, without changing anything.

What to ask students to hand in

The commands they ran and what they printed: one request decoded field by field, one write they flagged in the capture and why, the safety trip holding against a forced pump, and the conduit refusing a write. Then a sentence or two in their own words on why the safety function is not something Modbus can change. Nothing is marked automatically: the sentence shows whether it was understood. For stronger work ask why the write straight to the PLC was accepted, and what a real site would change.

A basic lesson on this lab

Industrial Control System Basics is a small lesson worked in this lab. In it a student reads the PLC, builds a Modbus request, changes a setpoint with no password, forces the pump and watches the safety trip stop it, resets the trip at the panel and sends writes through the conduit.

Free personal accounts have it in the Basics module, which is on Home, and every college can copy it from the Library’s Basics folder. It is deliberately small: it shows a teacher what a lesson worked in a lab is, and the lab does the rest. Copy it into a module of your own to change it. The undergraduate module Industrial control system security is worked in the same lab.

The code on GitHub

The compose file has no Dockerfile: it runs four services of one stock public image, the official Python image pinned to an exact tag, each as an unprivileged account with no capabilities and 48 or 64 MB of memory, using only Python’s standard library. Python is under the PSF licence and is not distributed by us. The file writes every program and both captures from fixed text when it starts, so every copy prints the same and nothing is downloaded. The limits are honest ones: no real PLC runtime, HMI product or hardware runs here, so the PLC is a short Python program speaking real Modbus/TCP, and the lab is one flat network, which lesson 5 of the module uses on purpose. Nothing is kept when the lab stops.

Set it as work

Say in the task what to hand in.

  1. Make the lab. In your module add a task and choose the Container lab card, then In a GitHub repository. Give https://github.com/mitsurutech/lab-ics-lab with the branch main. The compose file is the default, compose.yaml. Fork the repository first if you want to change it, for example to give the conduit a different allow-list or the tank other setpoints.
  2. Publish and try it. Publish pins the commit you were shown, so a later change in the repository does not alter a lab you have already set. Start your own copy first.
  3. Hand it out. Assign it like any task, with a due date if you want one, and say in the task what to do and what to hand in.
  4. Mark what is handed in. Open a student’s copy and the work they handed in, mark it, and send it back with a reason if it needs more.

Try this lab, and what it costs

A free personal account can work through the basic lessons in this lab, with enough free credit each month to follow most lessons and no card. For a class, a school or college has its first 365 days free for up to 50 students, then pays per student a year, with every lab included and staff free.

Questions people ask

Is this an attack lab?
No. It is a defensive lab with one simulated plant per student. The writes it sends show why Modbus needs defending, and each is made in the student’s own copy, which has no way out. Never send Modbus, a scan or a probe to a real plant or a device that is not yours.
Why does the terminal use docker exec work?
The lab’s terminal carries a few clients and no Python. docker exec work runs a command inside the lab’s Python box, which holds the scripts. docker exec plc runs one inside the PLC, which is how the panel reset works.
Why does the PLC listen on port 5020 and not 502?
Real Modbus devices use port 502. A program that runs as an unprivileged account, as every service in a lab does, may not open a port below 1024, so the lab uses 5020. Everything else in the frames is as a real device sends it.
Does the lab run OpenPLC or a real PLC?
No. No pinned image of a PLC runtime runs offline without being built, and a lab may not build one. So the PLC is a short Python program you can read in full, with the same Modbus frames, function codes and exception codes as a real device.