Modbus Function Code Tutorial: Tell Reads from Writes Online and Block Unauthorized PLC Writes
At the end of September, CISA and partner agencies refreshed their advisory on industrial PLCs and named internet-exposed Siemens S7 and Rockwell controllers as actively scanned by AI-assisted scripts; the UK's NCSC separately warned small manufacturers that their PLCs and SCADA may already be indirectly reachable from the public internet. The common denominator: legacy OT protocols such as Modbus, S7comm and DNP3 were "built for trust, not authentication"—no encryption, no identity check in the frame. And the first line of defense is the Modbus function code: one frame with function code 0x03 merely reads holding registers, while 0x10 can rewrite many of them at once. Knowing whether a function code reads or writes is step one in stopping unauthorized PLC writes.
What is a Modbus function code
Modbus is the most common serial and Ethernet protocol on the factory floor. Every master request carries a single byte called the function code, telling the slave what to do. Codes run from 0x01 to 0x6x and split into two families: read-only (coils, inputs, registers) and write (coils, registers). Because the protocol neither encrypts nor authenticates, whoever can send a write can change field-device state—which is exactly why OT security keeps stressing "protocol-aware inspection that rejects unauthorized writes."
Reads vs writes at a glance
- 0x01 Read Coils: read-only, reads a group of digital outputs.
- 0x02 Read Discrete Inputs: read-only, reads digital inputs.
- 0x03 Read Holding Registers: read-only, the most used; reads setpoints and parameters.
- 0x04 Read Input Registers: read-only, reads analog or measured values.
- 0x05 Write Single Coil: write, sets or clears one DO.
- 0x06 Write Single Register: write, changes one parameter.
- 0x0F Write Multiple Coils: write, batches DO set/clear.
- 0x10 Write Multiple Registers: write, rewrites many parameters—the high-risk code abused most.
Rule of thumb: 0x01–0x04 look, 0x05/0x06/0x0F/0x10 change. Any write-class code deserves extra scrutiny on an OT network.
Why write codes are the security focus
Back to those late-September advisories: the CISA/NSA joint report calls "ability to write logic or configuration" the single most decisive exposure, and NCSC explicitly asks that PLCs stay in write-protect mode and not linger in programming/maintenance mode. After scanning an exposed PLC, attackers often start not by breaking things but by reading process data with 0x03 to map the topology, then rewriting setpoints with 0x10. "Protocol-aware detection" boils down to: identify the function code and reject write codes (0x05/0x06/0x0F/0x10) from untrusted sources, allowing only the reads you need.
Decode any frame in three steps (online)
- Open antpact's Modbus Function Code lookup(https://antpact.com/modbus/modbus-fc/) and enter the function-code byte from your frame to get its name, class (read/write) and typical use.
- For a TCP capture, use the Modbus TCP decoder(https://antpact.com/modbus/modbus-tcp/) to split the MBAP header and PDU and locate the function code; for a serial frame, use the Modbus RTU decoder(https://antpact.com/modbus/modbus-rtu/) to see the address field, function code and CRC.
- Verify the frame tail with the Modbus CRC16 checker(https://antpact.com/modbus/modbus-crc/), and when you need to turn a 4xxxx/3xxxx address into a byte offset, use the Modbus address converter(https://antpact.com/modbus/modbus-address/).
Everything runs locally in your browser—no upload—so you can verify frames on a workshop or field laptop without ever sending OT traffic to a cloud.
A protection checklist for engineers
- Segment: keep OT separate from IT and the internet; PLCs must not be directly exposed.
- Kill default credentials: factory and shared passwords are the number-one OT weakness—replace them and add MFA.
- Write-protect: keep PLCs in write-protect mode in normal operation; block 0x05/0x06/0x0F/0x10 outside maintenance windows.
- Function-code allowlist: at the gateway, permit only needed reads from known sources and deny all unauthorized writes.
- Monitor behavior: alert on engineering-station connections outside windows and on logic changes without a work order.
These steps and "knowing your function codes" are two sides of one coin: you must know what writes are before you can block them at the boundary.
Understanding the protocol beats waiting for a patch—many OT devices are past vendor support and can't be patched. antpact's Modbus toolkit(https://antpact.com/modbus/) bundles a function-code lookup, TCP/RTU decoders, CRC16 check, address converter, ASCII mode and bit-packing into a set of local, no-upload online tools, handy for debugging, auditing and teaching. Next time a suspicious frame shows up, don't reboot first—decode it with the function code.