Modbus accepts a write to a holding register from any host that can reach the device, with no authentication and no integrity check, and that is how it is still deployed in most plants, buildings and utilities. The protocol dates from serial networks where physical access was the only control, and its TCP form simply carried that trust onto Ethernet. A secure variant, Modbus/TCP Security on port 802, exists but needs support at both ends. This guide explains how Modbus works from a defender's point of view, what attackers can do with it, how to choose between protecting legacy Modbus and moving to the secure variant, and how to segment, filter and monitor it. It is written for OT engineers, network and detection teams, and integrators who specify Modbus devices.
Key takeaways
- Reachability equals control. Any device that can open TCP 502 to a Modbus server can read and write its data model; the network path is the only access control legacy Modbus has.
- Function codes are the policy language. Reads (codes 1 to 4) and writes (5, 6, 15, 16, 22, 23), plus diagnostics and vendor programming codes, can be allowed or blocked per source with protocol-aware firewalls and IDS rules.
- Modbus/TCP Security is worth it for new builds. TLS with mutual certificate authentication on TCP 802 fixes spoofing and tampering, but only when both client and server support it and certificates are managed.
- Never expose Modbus to the internet. The FrostyGoop incident disrupted district heating in Ukraine using legitimate Modbus commands against controllers reachable on port 502.
- Baseline writes and alert on deviation. Most Modbus networks have a small, stable set of masters and write patterns; anything new is worth investigating.
How Modbus works, from a defender's view
Modbus is a request and response protocol between a client (historically the master, typically a SCADA server, HMI or PLC) and a server (historically the slave, typically a PLC, RTU, meter, drive or gateway). It exists in three main forms.
- Modbus RTU: binary framing over serial links such as RS-485, with a device address (1 to 247, 0 is broadcast) and a CRC. Physical access to the bus means full access.
- Modbus ASCII: the same model with text framing, rare in new installations.
- Modbus TCP: the Modbus PDU wrapped in an MBAP header (transaction identifier, protocol identifier, length and unit identifier) over TCP. IANA registers the service
mbapon port 502 andmbap-s, the secure variant, on port 802.
The data model has four tables: coils (read and write bits), discrete inputs (read-only bits), input registers (read-only 16-bit words) and holding registers (read and write 16-bit words). What a register means (a setpoint, a valve position, a speed limit) is defined only by the device vendor's register map. That is why reconnaissance matters to an attacker and why register maps should be treated as sensitive engineering documents.
The unit identifier routes requests through Modbus TCP to RTU gateways: the IP address is the gateway, and the unit ID selects the serial device behind it. One exposed gateway can therefore expose an entire serial bus.
Function codes and what they allow
The function code tells the server what to do. Defenders should know which codes their process actually uses, because allowlisting them is the most effective control available for legacy Modbus. Names below follow the Zeek Modbus analyzer constants.
| Code (decimal / hex) | Name | Effect | Typical policy |
|---|---|---|---|
| 1 / 0x01 | Read Coils | Read output bits | Allow from SCADA, HMI and historian |
| 2 / 0x02 | Read Discrete Inputs | Read input bits | Allow from SCADA, HMI and historian |
| 3 / 0x03 | Read Holding Registers | Read read/write registers | Allow from SCADA, HMI and historian |
| 4 / 0x04 | Read Input Registers | Read measured values | Allow from SCADA, HMI and historian |
| 5 / 0x05 | Write Single Coil | Switch an output on or off | Only from named control masters |
| 6 / 0x06 | Write Single Register | Change a setpoint or parameter | Only from named control masters, ideally to defined address ranges |
| 15 / 0x0F | Write Multiple Coils | Switch several outputs | Only from named control masters |
| 16 / 0x10 | Write Multiple Registers | Change several parameters at once | Only from named control masters; alert on new address ranges |
| 22 / 0x16 and 23 / 0x17 | Mask Write Register; Read/Write Multiple Registers | Modify register bits; combined read and write | Treat as writes |
| 8 / 0x08 | Diagnostics | Includes sub-functions that restart communications or force listen-only mode | Block except from maintenance hosts |
| 17 / 0x11 and 43 / 0x2B | Report Server ID; Encapsulated Interface Transport (device identification) | Reveal device type and firmware details | Allow from asset inventory tools only; alert otherwise |
| 20 / 0x14 and 21 / 0x15 | Read File Record; Write File Record | Access file-structured memory | Block unless the process needs it |
| 90 / 0x5A, 125 / 0x7D and other vendor codes | Vendor programming (for example Schneider Unity), firmware replacement | Program download, firmware change, run/stop | Only from engineering workstations, ideally only during change windows |
A server answering with an exception (the function code with the high bit set plus an exception code such as Illegal Function or Illegal Data Address) is useful evidence: bursts of exceptions often mean someone is scanning the register map.
Threats and how attacks use Modbus
| Threat | What it looks like on the wire | ATT&CK for ICS | Control |
|---|---|---|---|
| Unauthorised parameter change | Writes (6, 16) from a host that does not normally write | T0836 Modify Parameter, T1692 Unauthorized Message | Write allowlist per source, protocol-aware firewall, alerting |
| Process reconnaissance | Sequential reads across address ranges, device identification requests, exception bursts | T0861 Point & Tag Identification, T0888 Remote System Information Discovery | Block identification codes from non-inventory hosts, alert on scans |
| Loss of view and false readings | Changed scaling or calibration registers, firmware downgrade | T0829 Loss of View, T0832 Manipulation of View, T1693.001 System Firmware | Restrict programming codes, monitor firmware versions |
| Denial of service | Floods of requests, Diagnostics sub-functions that force listen-only mode, malformed frames | T0814 Denial of Service | Rate limits, block code 8 from non-maintenance hosts, connection limits |
| Spoofing and man in the middle | Injected or modified responses on a flat network | T0830 Adversary-in-the-Middle | Segmentation, port security, Modbus/TCP Security where supported |
| Internet exposure | Inbound TCP 502 from the internet | T0883 Internet Accessible Device | Remove exposure, external scanning, secure remote access |
FrostyGoop: MITRE ATT&CK records the FrostyGoop Incident (C0041) as taking place in January 2024 against a municipal district heating company in Ukraine, where the FrostyGoop malware (S1165) was used to manipulate ENCO controllers through legitimate Modbus commands. The software reads and writes holding registers over TCP 502. ATT&CK records modified parameters that made controllers report incorrect measurements and a firmware downgrade to a version lacking monitoring. Dragos, which found the binaries in April 2024, reported a two-day loss of heating, assessed with moderate confidence that the controllers had port 502 exposed to the internet, and noted that the router, management servers and controllers were not adequately segmented. Nothing in that attack required a vulnerability in Modbus itself: the protocol did exactly what it was told. See the FrostyGoop Modbus Malware Guide.
Legacy Modbus or Modbus/TCP Security: the decision
Modbus/TCP Security, published by the Modbus Organization, wraps Modbus in TLS on TCP port 802 with mutual authentication using X.509v3 certificates, and allows the server to authorise requests based on a role carried in the client certificate. Wireshark and other tools dissect it as Modbus over TLS on port 802. The decision is about where the protection gets you most risk reduction for the effort.
| Factor | Protect legacy Modbus TCP (502) | Adopt Modbus/TCP Security (802) |
|---|---|---|
| Device support | Works with any device | Needs firmware support on every client and server in the path |
| Protection | Network controls only: anyone on the permitted path can still write | Authenticates both ends, protects integrity and confidentiality, supports role-based authorisation |
| Operations | No certificates to manage | Certificate issuance, renewal and revocation for every device; expiry can stop communications |
| Monitoring | Full visibility of function codes to IDS and protocol-aware firewalls | Payload is encrypted; visibility needs endpoint logging or inspection at a trusted proxy |
| Performance | Minimal overhead | TLS handshake and processing on small devices; keep sessions long-lived |
| Best fit | Brownfield sites, serial gateways, devices with long remaining life | Greenfield projects, links crossing untrusted networks, remote sites, high-consequence writes |
For most organisations the answer is both: specify Modbus/TCP Security in procurement for new devices and links that leave a protected zone, and protect the installed base with segmentation and function code filtering. Where devices cannot be upgraded, a secure tunnel (IPsec or TLS between gateways) protects Modbus across an untrusted network, but it does not authenticate which host inside the zone sent a command. Treat device certificates as machine identities with owners, expiry tracking and a renewal process. See the Device and IoT Identity Guide and the OT Product Procurement Guide.
Segmentation and filtering
- Zone the servers: place Modbus devices in zones with conduits that admit TCP 502 only from named clients. See the OT Network Segmentation, Purdue Model and IEC 62443 Zones and Conduits Guide.
- Use protocol-aware enforcement at high-consequence conduits: industrial firewalls and deep packet inspection modules can allow reads from the historian, writes from the SCADA server only, and block programming and diagnostics codes except from engineering hosts.
- Restrict by address range: where the enforcement point supports it, permit writes only to the register ranges the process uses.
- Protect gateways: Modbus TCP to RTU gateways expose whole serial buses; restrict which unit IDs each client may address and keep gateway management interfaces on a separate network.
- Remote access through a broker: no port forwarding of 502 or 802; vendors and engineers connect through a recorded, MFA-protected broker. See the OT Remote Access Guide.
- Device-side settings: many PLCs and gateways offer an IP allowlist for Modbus clients, a read-only Modbus mode, or the option to disable the Modbus server entirely when unused; use them as a second layer.
Monitoring and detection
Modbus is easy to monitor because it is unencrypted and regular. Use passive sensors on SPAN ports or taps and build a baseline before alerting.
- Zeek: the Modbus analyzer is registered on 502/tcp and writes
modbus.logwith ts, uid, connection id, transaction id (tid), unit, func, pdu_type and exception fields. That is enough to baseline who talks to whom, with which function codes. See the Zeek Network Monitoring Guide. - Suricata: the
modbusrule keyword matches on function (including categories such as public, user and reserved, and negation), on access (read or write, by table such as coils or holding, with address and value conditions) and on unit identifier. Rules can, for example, alert on any write to holding register ranges from a host other than the SCADA server, or on any reserved function code. Suricata documentation notes that Modbus addresses in rules start at 1. See the Suricata IDS Guide. - Commercial OT monitoring: protocol-aware platforms add asset identification from Modbus device identification responses and process-variable baselines.
| Detection | Logic | Priority |
|---|---|---|
| New Modbus client | Source IP not in baseline opens TCP 502 or 802 | High |
| Write from a read-only client | Function 5, 6, 15, 16, 22 or 23 from historian, HMI view station or unknown host | High |
| Programming or firmware code | Vendor programming or firmware replacement codes outside a change window | High |
| Diagnostics use | Function 8 from any non-maintenance host | Medium |
| Register map scanning | Burst of exceptions or sequential reads across wide address ranges | Medium |
| Inbound internet traffic | External source to TCP 502 or 802 at any boundary | Critical |
How to implement
- Inventory: passively capture Modbus traffic for at least one full operating cycle (including shift changes and batch changeovers) and list clients, servers, unit IDs and function codes in use.
- Close external exposure: check for TCP 502 and 802 reachable from the internet or from corporate IT, and remove it first, as the five CISA primary OT mitigations recommend for all OT devices.
- Segment: move Modbus servers into zones and restrict conduits to the inventoried clients. Apply rules in log-only mode first, compare against the baseline, then enforce during a planned outage with the previous rule set kept for rollback.
- Filter function codes: at high-consequence conduits, allow reads broadly and writes only from control masters; block diagnostics, file record and programming codes except from engineering hosts.
- Monitor: deploy Zeek or Suricata rules for the six detections above, routed to someone who can contact operations.
- Upgrade selectively: require Modbus/TCP Security in new procurement and on links crossing untrusted networks; pilot on one link with certificate renewal tested before expiry becomes a production risk.
Small sites with a handful of devices can often achieve most of the value with an IP allowlist on the device, a single industrial firewall and Zeek on a low-cost sensor. Large estates should standardise a register-range and function code policy per device type and push it through central firewall management.
Framework mapping
| Control area | NIST SP 800-53 Rev. 5 | NIST CSF 2.0 | MITRE D3FEND |
|---|---|---|---|
| Segmentation and conduits | SC-7 Boundary Protection | PR.IR | D3-NTF Network Traffic Filtering |
| Function code and address allowlisting | AC-3 Access Enforcement, CM-7 Least Functionality | PR.PS | D3-NTF Network Traffic Filtering |
| Modbus/TCP Security and device certificates | IA-3 Device Identification and Authentication, SC-8, SC-23, SC-12 | PR.AA, PR.DS | None mapped |
| Traffic monitoring and baselines | SI-4 System Monitoring | DE.CM | D3-NTA Network Traffic Analysis |
| Denial of service resilience | SC-5 Denial-of-service Protection | PR.IR | None mapped |
Common failure patterns
- Port forwarding for convenience: TCP 502 forwarded through a router for remote monitoring, the exposure pattern behind FrostyGoop.
- Allowing everything inside the zone: segmentation stops at the zone boundary, so any compromised HMI can write to every PLC.
- Read-only assumptions: historians and dashboards given full Modbus access because "they only read", leaving a write path from a less protected system.
- Forgotten gateways: serial gateways with default management passwords and no restriction on unit IDs.
- Secure variant without certificate operations: Modbus/TCP Security enabled with long-lived self-signed certificates and no renewal plan, then disabled after an expiry outage.
- Monitoring without a baseline: IDS rules that alert on every write, so alerts are ignored within a week.
Practitioner checklist
- Confirm no Modbus port (502 or 802) is reachable from the internet or the corporate network.
- Inventory every Modbus client, server, gateway, unit ID and function code from passive capture.
- Restrict TCP 502 at zone conduits to named clients and keep a rollback rule set.
- Allow writes only from control masters; block diagnostics, file record and programming codes elsewhere.
- Use device-side IP allowlists, read-only modes or disable unused Modbus servers.
- Protect and restrict serial gateways by unit ID and management access.
- Deploy Zeek or Suricata detections for new clients, unexpected writes and programming codes.
- Treat register maps as sensitive engineering documents.
- Specify Modbus/TCP Security for new devices and untrusted links, with certificate renewal tested.
Standards and references
- IANA: Service Name and Transport Protocol Port Number Registry (mbap, mbap-s)
- MITRE ATT&CK: FrostyGoop Incident (C0041)
- MITRE ATT&CK: FrostyGoop (S1165)
- Suricata: Modbus keyword documentation
- Zeek: Modbus analyzer constants and log
- CISA: Primary Mitigations to Reduce Cyber Threats to Operational Technology
- Dragos: Protect Against FrostyGoop ICS Malware Targeting Operational Technology
- MITRE D3FEND: Network Traffic Filtering
Related NHI Mgmt Group resources: OT Security Guide · FrostyGoop Modbus Malware Guide · PLC Security Guide · OT Network Security Monitoring Guide · DNP3 Secure Authentication Guide