Industrial Protocols
ICS protocols trade confidentiality for determinism: most put a complete data model on the wire and ask the client for nothing but a well-formed request. Reading the container, the function code and the address separates a finding from a guess.
Modbus
Modbus is small and stateless. A client sends a function code and its data; the server repeats the code with the values, or sets bit 7 and appends an exception code. Any host that reaches TCP 502 can send the request the legitimate master sends.
Variants
- Modbus RTU - Serial (RS-232/485)
- Modbus ASCII - Serial, human readable
- Modbus TCP - Ethernet, Port 502
Security Issues
- No authentication
- No encryption
- No integrity checking
- Easily spoofable
Modbus Function Codes
The function code is the first PDU byte and the only field separating a read from a control action; port 502 permits both.
| Code | Function | Risk |
|---|---|---|
| 0x01 | Read Coils | Info disclosure |
| 0x03 | Read Holding Registers | Info disclosure |
| 0x05 | Write Single Coil | Control manipulation |
| 0x06 | Write Single Register | Control manipulation |
| 0x0F | Write Multiple Coils | Mass control manipulation |
| 0x10 | Write Multiple Registers | Mass control manipulation |
| 0x2B | Encapsulated Interface Transport; MEI 0x0E reads device identification | Fingerprinting |
An error reply sets bit 7 and appends one exception byte, so a failed holding-register read returns 0x83. Exception 0x02, illegal data address, says the address does not exist. Reading until it appears is the least invasive way to find the edge of a map, and a wrong address model therefore looks like a missing feature.
The MBAP Header
Modbus TCP prefixes every PDU with a seven-byte MBAP header: two bytes of transaction identifier, two of protocol identifier (0x0000), two of length, then one unit-identifier byte. The PDU follows, beginning with its function code.
All multi-byte fields are big-endian, and the length counts the unit identifier and the PDU but not the six bytes before it: a ten-register read has length 6. A wrong count gets the frame dropped with no exception.
Read 10 holding registers from unit 1, starting at PDU address 0
offset bytes field
0 00 01 transaction identifier (chosen by the client)
2 00 00 protocol identifier (Modbus)
4 00 06 length: unit identifier + 5-byte PDU
6 01 unit identifier
7 03 function code: read holding registers
8 00 00 starting address, PDU-relative
10 00 0A quantity: 10 registersEverything after the function code is interpreted by that function code, which is why one header carries a read, a write and an identification request.
MBAP Header Bytes and the Zero-Based PDU Address
Scroll sideways to see the whole diagram
The Address Model
Two numbering systems differ by one. The address in the PDU is zero-based: the first holding register is 0. The four-digit convention manuals use is one-based: the same register is 40001. The prefix names the area, not the address.
| Prefix | Area | Width and access | Function codes |
|---|---|---|---|
| 0xxxx | Coils | 1 bit, read/write | 0x01, 0x05, 0x0F |
| 1xxxx | Discrete inputs | 1 bit, read only | 0x02 |
| 3xxxx | Input registers | 16 bit, read only | 0x04 |
| 4xxxx | Holding registers | 16 bit, read/write | 0x03, 0x06, 0x10 |
Holding register 40001 is PDU address 0, 40002 is 1, 40100 is 99. An engineer who reads 40001 off a wiring diagram and puts 40001 on the wire asks for the second register, or for one that does not exist and returns exception 0x02. A wrong model usually returns a plausible number rather than an error.
A 32-bit value occupies two consecutive registers, and which half comes first is a device setting, not a protocol rule. Read both in one request, because two reads can straddle a scan and return a combination that never existed. Confirm the order against the point list, or in a lab, with a known value in a scratch register.
Modbus Testing
Enumeration is read-only: ten holding registers from PDU address 0 on unit 1, and ten coils.
from pymodbus.client import ModbusTcpClient
client = ModbusTcpClient("192.168.1.100", port=502)
client.connect()
# Unit 1, holding registers starting at PDU address 0 (= 40001 in 4xxxx maps)
result = client.read_holding_registers(address=0, count=10, device_id=1)
print(result.registers)
# Coils are the 0xxxx area and use the same zero-based PDU addressing
coils = client.read_coils(address=0, count=10, device_id=1)
print(coils.bits)
client.close()Client calls take keyword arguments and the unit-identifier argument has been renamed between releases, so read the API page for the release you installed.
pip install pymodbus
# Enumerate unit identifiers and read device identification (0x2B, MEI type 0x0E)
nmap -sV -p 502 --script modbus-discover 192.168.1.100Write Operations
Siemens S7comm
Siemens' protocol for S7 PLCs, inside ISO-TSAP on TCP 102, which is the same port IEC 61850 MMS uses, so the first session bytes identify it. A TPKT header wraps COTP, which wraps the S7 PDU.
Two generations answer there. Classic S7comm carries the session in plaintext and checks a protection-level password inside the protocol, so a capture shows the credential exchange. S7comm-plus, on later S7-1200 and S7-1500 firmware, uses a certificate-based handshake and an encrypted payload, so there is no plaintext password and an offline password attack has nothing to work against.
import snap7
client = snap7.client.Client()
client.connect("192.168.1.100", 0, 1) # address, rack, slot
info = client.get_cpu_info()
print(info.ModuleTypeName, info.SerialNumber)
# 100 bytes from data block 1, starting at offset 0
data = client.db_read(1, 0, 100)
print(data.hex())
client.disconnect()# s7-info reads CPU identity over ISO-TSAP without an authenticated session
nmap -p 102 --script s7-info 192.168.1.100The library's API page is the authority for argument names; a write is the same PDU with a different job.
EtherNet/IP (CIP)
Common Industrial Protocol in an EtherNet/IP encapsulation header: explicit messages over TCP 44818, implicit I/O over UDP 44818. A few commands in that header do most of the work. ListIdentity (0x0063) needs no session, RegisterSession (0x0065) returns a handle that is a number rather than a credential, and SendRRData (0x006F) carries the CIP message whose service byte says read or write.
from pycomm3 import LogixDriver, CIPDriver
# Generic CIP identity: vendor, product name, revision
with CIPDriver("192.168.1.100") as plc:
info = plc.get_plc_info()
print(info["vendor"], info["product_name"], info["revision"])
# ControlLogix/CompactLogix: browse the tag database, then read one tag
with LogixDriver("192.168.1.100") as plc:
tags = plc.get_tag_list()
for tag in tags[:10]:
print(tag["tag_name"], tag["data_type"])
print(plc.read("MyTag").value)# ListIdentity over UDP: no session, no credential
nmap -p 44818 --script enip-info 192.168.1.100DNP3 (Distributed Network Protocol)
A master/outstation protocol: the outstation owns a typed data model of binary and analog inputs and outputs, counters, and time-stamped events. The link layer has a ten-byte header (start bytes 0x05 0x64, length, control, destination, source, CRC) then data blocks of up to sixteen bytes, each with its own CRC; its control byte selects confirmed or unconfirmed user data. The transport layer is one byte with a more-fragments bit and a sequence number. The application layer is a control byte, a function code, then objects introduced by group, variation and qualifier.
Class 0 is the static image; classes 1 to 3 are event buffers, class 1 first, and an integrity poll reads all four as object group 60 variations 1 to 4. An outstation can push events as unsolicited responses (0x82) once the master enables them (0x14), and stops on disable (0x15). Without secure authentication that is one unauthenticated write, and its result is quiet: the master still receives correct static values while the events behind them never arrive.
Control is select-before-operate: Select (0x03) reserves a point and returns its status, Operate (0x04) executes only if it matches the select being held, and Direct Operate (0x05) skips the reservation. Secure Authentication (IEEE 1815, IEC 62351-5) adds an HMAC challenge-response over writes, select and operate, restarts and the unsolicited controls: authentication and integrity, no confidentiality, so a capture still shows every value and control target.
# dnp3-info performs the link-layer and application-layer exchange and reports the outstation
nmap -p 20000 --script dnp3-info 192.168.1.100dnp3 # all DNP3 traffic
dnp3.al.func == 0x01 # application read (integrity or class poll)
dnp3.al.func == 0x03 # select
dnp3.al.func == 0x04 # operate
dnp3.al.func == 0x82 # unsolicited response
# Field names below dnp3. belong to the dissector; type "dnp3." in the
# filter bar to list the ones this build exposes.OPC UA
A binary client-server protocol on TCP 4840. A secure channel performs an asymmetric handshake and then protects the session with symmetric keys; a session on top carries user authentication as an anonymous token, a username and password, or a certificate. Both are negotiated per endpoint.
Each endpoint advertises a security policy and a message security mode: None, Sign, or SignAndEncrypt. None is valid and common: the channel is unsigned and unencrypted, and the token that follows crosses the network in the clear.
Basic128Rsa15 and Basic256 are deprecated; Basic256Sha256, Aes128_Sha256_RsaOaep and Aes256_Sha256_RsaPss supersede them. Record the policy URI and the mode, because Sign without encryption is integrity without confidentiality.
GetEndpoints needs no session, token or encryption. One request returns endpoint URLs, policy URIs, security modes, the user token policies (including whether Anonymous is offered) and the server certificate, which answers whether an endpoint accepts a session with no security and no credential.
import asyncio
from asyncua import Client
async def main():
async with Client("opc.tcp://192.168.1.100:4840") as client:
# GetEndpoints: policy URI, security mode, user token policies
for ep in await client.get_endpoints():
print(ep.EndpointUrl, ep.SecurityPolicyUri, ep.SecurityMode)
# Browse the address space from the root node
for child in await client.nodes.root.get_children():
print(child)
asyncio.run(main())A connection to a server that refuses the None policy fails during the handshake, which is itself an answer about what the device enforces.
BACnet (Building Automation)
BACnet/IP carries the BACnet network layer over UDP 47808 behind a BVLC header. There is no connection or handshake, so a UDP scan needs -sU plus an application probe: the script below sends Who-Is, which every device on the broadcast domain answers with an I-Am carrying its device instance.
WriteProperty writes at a priority from 1 to 16 and the lowest wins, so a setpoint written at 8 does nothing while anything lower commands it. BACnet/IP has no authentication; BACnet/SC carries the same services over a TLS-protected WebSocket through a hub.
import BAC0
bacnet = BAC0.lite() # pass this host's interface address if the default is wrong
# Global Who-Is; every device answers with its I-Am
for device in bacnet.whois():
print(device)
# Read Present Value of analog input 0 on device 1234
value = bacnet.read("1234 analogInput 0 presentValue")
print(value)# UDP only: -sU is required, and the script supplies the Who-Is that a port scan cannot
nmap -sU -p 47808 --script bacnet-info 192.168.1.100Setpoints, schedules, alarm enables and access-control decisions are the same WriteProperty service, so the boundary has to be the conduit.
PROFINET
PROFINET is defined in IEC 61158 and IEC 61784 and maintained by PROFIBUS & PROFINET International; Siemens is the dominant supplier, not the owner. An IO controller assigns each device a station name and address with DCP, then establishes an application relation.
Cyclic real-time IO rides Ethernet frames with EtherType 0x8892 and is never IP-routed, so its protection is the switch and the segment. Acyclic services such as record read and write, alarms and the engineering channel travel over UDP/IP by RPC, which is routable and is the only part an IP rule describes. A rule for the cyclic traffic protects nothing that reaches the firewall; a rule for the acyclic path opens the only routable way in.
DCP has no authentication, so a Set-Request can rename a device and the controller loses the one it knew.
eth.type == 0x8892 # every PROFINET real-time frame, routable or not
pn_dcp # discovery and configuration: name and address assignment
pn_rt # cyclic real-time IO
pn_io # IO data and application relationsIEC 60870-5-104 (IEC-104)
The dominant telecontrol protocol in European and international power utilities. TCP port 2404. Base IEC-104 has no authentication or encryption; IEC 62351 adds TLS and authentication but is inconsistently deployed. The Industroyer/CRASHOVERRIDE malware included a dedicated IEC-104 module used against the Ukrainian grid.
Each frame starts with 0x68 and a length byte, then four control bytes. An I-format frame carries an ASDU plus 15-bit sequence numbers, an S-format frame is a bare acknowledgement, and a U-format frame carries STARTDT, STOPDT and TESTFR. An ASDU is a type identification, a structure qualifier with the object count, a cause of transmission and the station's common address, then objects with three-byte addresses. Station, point and value are all in the frame and none of it is authenticated.
# Confirm 2404 before spending time on the capture
nmap -p 2404 192.168.1.100# IEC 60870-5-104 display filters
104apci # APCI frames: I, S and U formats
104asdu # application data units
104asdu.typeid == 45 # C_SC_NA_1 single command (control)
104asdu.typeid == 46 # C_DC_NA_1 double command (control)
104asdu.typeid == 100 # C_IC_NA_1 general interrogation
# ASDU type IDs worth recognising
1 M_SP_NA_1 single-point status
13 M_ME_NC_1 measured value, short floating point
45 C_SC_NA_1 single command
46 C_DC_NA_1 double command
100 C_IC_NA_1 general interrogation# LAB ONLY: point this at a local server or an isolated replica
import c104
client = c104.Client()
conn = client.add_connection(ip="192.168.1.100", port=2404)
client.start()
# General interrogation (type 100) enumerates a station's data points.
# Left commented: it is a station poll, but a live station should be asked
# through its operator, not by a test client.
# conn.interrogation(common_address=1)Grid Control Commands
IEC 61850 (Substation Automation)
The substation automation standard is a family of protocols rather than one wire format: MMS (client/server over TCP 102, the port S7comm also uses), GOOSE (Layer 2 multicast, EtherType 0x88B8, for fast protection trips) and Sampled Values (Layer 2, EtherType 0x88BA, digitised measurements).
A GOOSE frame is identified by its APPID and control-block reference and carries stNum, which increments on a dataset change, sqNum, which increments on each retransmission, and timeAllowedToLive, the window after which a subscriber declares the publisher lost. Neither GOOSE nor SV authenticates at the data-link layer and IEC 62351-6 signing is rarely enabled, so an attacker on a process bus can forge a frame with a higher stNum and a spoofed trip dataset, which is an attack on a protection function and one for an isolated replica only.
# MMS shares TCP 102 with S7comm; confirm which protocol answered
nmap -p 102 192.168.1.100
# libiec61850 ships reference clients for MMS browsing
git clone https://github.com/mz-automation/libiec61850
# examples/ -> mms_client_example, iec61850_client_examplemms # MMS: the client/server data model
goose # GOOSE protection messages
sv # Sampled Values
goose.stNum # state number: increments on a dataset change
goose.sqNum # sequence number: increments on retransmission
goose.timeAllowedToLive # subscriber liveness window, in milliseconds
goose.appid # identifies the control block's traffic
# Weaknesses to look for
# GOOSE and SV have no link-layer authentication by default
# MMS commonly allows unauthenticated reads of the data model
# IEC 62351-6 signing is rarely enabledProtocol Comparison
Read the security columns as deployed capability: every optional entry is a setting on the device in front of you.
| Protocol | Port | Auth | Encryption |
|---|---|---|---|
| Modbus TCP | 502/TCP | No | No |
| S7comm | 102/TCP | Optional, protection level | No |
| S7comm-plus | 102/TCP | Certificate handshake | Yes, encrypted payload |
| EtherNet/IP | 44818/TCP and UDP | No | No |
| DNP3 | 20000/TCP | Optional, secure authentication | No, SA is authentication and integrity only |
| OPC UA | 4840/TCP | Optional, per endpoint | Optional, per endpoint |
| BACnet/IP | 47808/UDP | Optional, BACnet/SC | Optional, BACnet/SC |
| IEC-104 | 2404/TCP | Optional, IEC 62351 | Optional, IEC 62351 |
| IEC 61850 MMS | 102/TCP | Optional, IEC 62351 | Optional, IEC 62351 |
| GOOSE / SV | L2, 0x88B8 and 0x88BA | No | No |
Protocol Analysis with Wireshark
A filter tests the fields one dissector exposes. A device on a non-standard port is not dissected as its protocol until the port is added in preferences or Decode As is used, and field names belong to the build in front of you: type a protocol prefix and a dot to list them.
# Protocol families
modbus # Modbus TCP
s7comm # Siemens S7
enip # EtherNet/IP encapsulation
cip # Common Industrial Protocol
dnp3 # DNP3
bacnet # BACnet
opcua # OPC UA
pn_io # PROFINET IO data
pn_dcp # PROFINET discovery and configuration
104apci # IEC 60870-5-104 frames
mms # IEC 61850 MMS
goose # IEC 61850 GOOSE
# Fields that answer a question
modbus.func_code == 6 # Write Single Register
s7comm.param.func == 0x05 # S7 Write Var
enip.command == 0x006f # EtherNet/IP Send RR Data
dnp3.al.func == 0x04 # DNP3 operate
104asdu.typeid == 45 # IEC-104 single command
# Statistics > Protocol Hierarchy shows what the capture contains
# Statistics > Conversations shows who is talking to whom
# File > Export Objects pulls files out of the ones that carry themThe same filter is a repeatable query:
# Every single and multiple register write, with the hosts that carried them
tshark -r plant.pcapng -Y "modbus.func_code == 6 || modbus.func_code == 16" \
-T fields -e ip.src -e ip.dst -e modbus.func_codeServe It Yourself
Run a Modbus server on your own machine with pymodbus or ModbusPal and read one holding register twice: once by the one-based 4xxxx convention and once by the zero-based PDU address, capturing both. Done when you can show which register actually moved, state the byte-level address the wire carried in each case, and confirm the result against the server's own register view. Loading a 32-bit value across two registers afterwards demonstrates word order, and an asyncua server exposes the same GetEndpoints enumeration for the OPC UA policy set.
Evidence to Capture
Protocol findings are claims about what a conduit permits and what a device accepts. Both are visible on the wire and in configuration.
Function code observed: The actual service in the capture: Modbus function code 3 reads against 5, 6, 15 or 16 writes; the S7 job type; the DNP3 function. A write function crossing a zone boundary is a different finding from a read.
Deployed security mode: The OPC UA security policy URI and message security mode, the DNP3 secure authentication state and aggressive mode setting, or the IEC 104 transport. The deployed value, not what the standard permits.
Conduit rule: The rule that allows this protocol and port between these zones, with its source, destination, and service definition. Every protocol conversation should map to exactly one conduit.
Write acceptance: Whether the controller accepts a write from a host other than the engineering workstation, evidenced by the device configuration or a supervised test, never by an unsupervised write to a running process.
Conversation baseline: Who polls whom, on what interval, and which direction the data flows. An unexpected master or a read direction reversal is often the real finding.
Likely False Positives
Most protocol weaknesses are properties of the protocol, not defects in the design that deployed it.
- Modbus has no authentication: This is the protocol. The reviewable question is whether the conduit and the deep-packet inspection compensate, not whether the field was secured.
- OPC UA security policy None: Acceptable where the endpoint is confined to one zone and nothing routes to it. The finding appears when the endpoint is reachable across a conduit.
- DNP3 without secure authentication: On a serial link with no routable path, physical and zone controls are the boundary. On routable TCP the absence is a genuine gap.
- PROFINET RT with no security: Real-time class 1 traffic does not leave the segment. Treating a non-routable fieldbus as an unprotected network overstates the finding.
- Writes seen on a mirrored port: A passive mirror shows traffic the device receives, not that it accepted it. Confirm acceptance through the device state or a supervised test.
Review Checklist
Conduit
- ☐ Map each observed protocol conversation to a conduit rule and list the conversations with no rule.
- ☐ Check the conduit names a service and port rather than a protocol family or an any-service rule.
- ☐ Confirm permitting rules are paired with inspection where the protocol cannot authenticate.
- ☐ Check the direction of each conduit: a read-only data path should not permit writes.
Protocol posture
- ☐ Read the deployed security mode for every protocol that supports one, and list those left at None or unauthenticated.
- ☐ Confirm the certificate or key material on the secured endpoints is current and renews before expiry.
- ☐ Check the login and role model on the controller, including whether the default account was changed.
- ☐ Confirm time synchronisation exists, since secure authentication and certificate validation both depend on it.
Baseline
- ☐ Record the expected polling pairs and compare the live capture against them.
- ☐ Check for a second master on a segment that should have one.
- ☐ Confirm a write function seen during the capture is explained by an approved action.
- ☐ Check the capture covers a full process cycle, so periodic traffic is not mistaken for an anomaly.
Remediation
Turn on the protocol security that exists, control the rest at the conduit
Structural
- • Where the protocol supports security, deploy it: OPC UA with a signing and encryption policy, DNP3 secure authentication, IEC 104 over TLS. A capable protocol left open is a configuration choice, not a constraint.
- • Where the protocol cannot authenticate, put the control in the conduit: a rule restricted to the engineering workstation address, plus deep-packet inspection of write function codes.
- • Terminate fieldbus protocols in the zone they belong to and carry data upward through a mediated gateway rather than a routed link.
Compensating
- • For legacy controllers that cannot be replaced, add write-function detection at the zone boundary and alert on any programming session outside a change window.
- • Where certificates cannot be deployed, restrict the endpoint to a named peer and record the concession in the zone risk assessment.