Skip to content

Modbus probe

The Modbus probe opens a Modbus/TCP connection to a device and runs one or several operations on it in order, recording each one with its request and the bytes that came back. VirtuProbe speaks Modbus directly, written against the MODBUS Application Protocol Specification and the Messaging on TCP/IP Implementation Guide rather than wrapped around a third-party library, so you can put an illegal quantity or a deliberately malformed frame on the wire and see what the device did with it.

A probe is a host, a port, a unit id and an ordered list of operations. One send opens the connection, runs the operations on it in order and closes it. Modbus is strict request and response, one transaction at a time, so each operation is sent and its single reply read before the next begins.

The Modbus probe editor: a connection to a device on port 502, the Write arm switch set to read-only and an operation list holding a register read, a SunSpec scan and a register write marked as modifying the target.

FieldDescription
HostThe address of the device (default: localhost)
PortThe TCP port (default: 502)
Unit idThe Modbus unit (slave) id used by any operation that does not set its own (default: 1)

Modbus/TCP as this probe speaks it carries no transport authentication and no encryption, so there is no credential or TLS field. A per-operation Unit id overrides the probe’s for one operation, which is how you address several devices behind one gateway in a single probe.

Each operation is a function and the arguments that function needs. Add operations with Add operation, reorder or remove them, switch any one off with its checkbox so it stays in the probe without being sent. An operation may carry a Label, which names it in the response and the history and is how an extractor or a later chain step addresses it. Without a label it is named by a generated summary, for example READ_HOLDING_REGISTERS @0 x10.

FunctionReadsFields
READ_COILSCoils (bits)Address, Quantity
READ_DISCRETE_INPUTSDiscrete inputs (bits)Address, Quantity
READ_HOLDING_REGISTERSHolding registers (16-bit words)Address, Quantity
READ_INPUT_REGISTERSInput registers (16-bit words)Address, Quantity
READ_FIFO_QUEUEA FIFO queueAddress
FunctionWritesFields
WRITE_SINGLE_COILOne coilAddress, Value (zero is off, non-zero is on)
WRITE_SINGLE_REGISTEROne registerAddress, Value
WRITE_MULTIPLE_COILSA block of coilsAddress, Coils (a comma list of 1/0)
WRITE_MULTIPLE_REGISTERSA block of registersAddress, Values (a comma list of numbers)
MASK_WRITE_REGISTEROne register, through an AND and an OR maskAddress, And mask, Or mask
READ_WRITE_MULTIPLE_REGISTERSWrites a block, then reads a block, in one transactionRead address, Read quantity, Write address, Values

The specification classifies these five as serial line usage. They are sendable over Modbus/TCP all the same, because many gateways and PLCs do answer them (Report server id is a common fingerprint), and how a target reacts to one it was not expected to receive is itself the finding.

FunctionAsks forFields
READ_EXCEPTION_STATUSThe device’s exception status bytenone
DIAGNOSTICSA diagnostic sub-functionSub function, Data (hex)
GET_COMM_EVENT_COUNTERThe communication event counternone
GET_COMM_EVENT_LOGThe communication event lognone
REPORT_SERVER_IDThe device’s own id and run statenone
FunctionDoesFields
READ_FILE_RECORDReads a record from a fileFile number, Record number, Record length
WRITE_FILE_RECORDWrites a record to a fileFile number, Record number, Values
ENCAPSULATED_INTERFACE_TRANSPORTDevice identification (MEI type 14), or any encapsulated interface payloadMEI type, Read device id code, Object id, Data (hex)

Encapsulated interface transport with no MEI type, or with MEI type 14 and a Read device id code, sends a Read device identification request. Any other MEI type carries the Data (hex) payload as raw bytes. The payload inside the envelope (a CANopen request, for example) is a separate protocol and is returned raw.

FunctionDoesFields
SUNSPEC_SCANWalks the SunSpec model chain and decodes the models the bundled catalog knowsBase address (default: 40000)

A SunSpec scan confirms the SunS marker at the base address, walks the chain of model blocks to its end marker. For every model the catalog knows it renders the named engineering values beside the raw registers. A scale factor in a model is applied, so a scaled integer reads as its real value. The catalog is a bundled data file; a model it does not know still appears as its id and length.

FunctionDoesFields
RAWSends an arbitrary function code and data bytes with no argument validationFunction code, Data (hex)

Raw is the fuzzing and MITM escape hatch: it puts whatever bytes you give it on the wire, including a function code the specification does not define. A raw send counts as changing the target unless its code is a known read, because a frame of unknown effect is treated as a write so the write-safety gate still applies.

A hex field accepts spaces, commas and 0x prefixes, so 11 03 00, 110300 and 0x11,0x03,0x00 are the same three bytes.

Modbus devices run plant, so a write is sent only when three conditions hold: writes are enabled for the workspace in Settings > Advanced, the probe is armed for writes with the Write arm switch above the operation list and, on an interactive send from the editor, you confirm it. A chain, headless or MCP send has nobody to confirm, so the two gates decide and a write with either unmet fails cleanly. A blocked operation is a visible, failed exchange that was never sent, not an error on the probe. Reads never need arming.

The write functions and a raw send change the target; the reads, the diagnostics and the SunSpec scan do not. An operation that changes the target carries a modifies target chip in the editor, drawn from the same catalogue the write-safety gate reads, so the chip cannot say one thing while the gate does another.

The response lists every operation as a row with a pass or fail marker, its command summary, its duration and a chip for anything notable (an exception, a blocked write with its reason, or a mocked reply). A chip at the top names the transport outcome when it is not OK. A transport error shows above the list.

A Modbus response: the holding-register read and the SunSpec scan pass, the register write is held back with the reason WORKSPACE_WRITES_DISABLED because writes are not armed for the probe.

A row expands to the reply. A register read shows registers=[...], a bit read shows coils=[...], and everything else shows the response PDU as hex. When an operation carried a typed decode, the decoded value is shown beside the registers. The raw response PDU is shown as hex under the reply.

A completed transaction is OK even when the device answered with a Modbus exception: the bytes arrived, so the transport succeeded and only the protocol disagreed. An exception response shows its code, one of ILLEGAL_FUNCTION, ILLEGAL_DATA_ADDRESS, ILLEGAL_DATA_VALUE, SERVER_DEVICE_FAILURE, ACKNOWLEDGE, SERVER_DEVICE_BUSY, MEMORY_PARITY_ERROR, GATEWAY_PATH_UNAVAILABLE or GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND.

When the transport itself did not complete, the outcome names how it ended: CONNECT_REFUSED (nothing listening), CONNECT_TIMEOUT, READ_TIMEOUT, CONNECTION_RESET, EOF (the peer closed early), MALFORMED_FRAME (bytes arrived that were not a Modbus frame) or RESOLVE_FAILED. For a port probe the difference between nothing listening and answered then reset is often the whole finding, which is why the outcome is named rather than collapsed into one error. A transport failure part way through a probe ends the remaining operations, because nothing further can reach the device.

A write that the gate refused reports BLOCKED. The probe as a whole passes when every operation ran, none came back as a Modbus exception and none was blocked.

The per-exchange extractors take a command prefix, matched case-insensitively against an operation’s summary or its label, so an operation you labelled setpoint is addressed as setpoint. A blank expression means the last operation, since a probe’s verdict is usually whatever it finished by asking.

ExtractorReturns
MODBUS_SUCCESStrue when the probe as a whole passed, otherwise false. Ignores the expression
MODBUS_TRANSPORT_OUTCOMEThe transport outcome of the probe as a whole (OK, CONNECT_REFUSED, READ_TIMEOUT, …). Ignores the expression
MODBUS_REGISTERSThe registers a read returned, comma-separated, or blank when the operation was not a register read
MODBUS_COILSThe coil or discrete-input bits a read returned, comma-separated as 1/0, or blank when the operation was not a bit read
MODBUS_EXCEPTION_CODEThe Modbus exception code of one operation, or blank when the device did not answer with an exception
MODBUS_DECODEDThe typed-decoded value of a register read that carried a decode, or blank when it had none
MODBUS_REPLYThe reply of one operation, as it reads in the response
MODBUS_RAW_PDUThe raw response PDU as hex (function code plus data), the lossless handle for a raw or fuzz operation whose reply has no register shape

Modbus is a chain step. {{variable}} placeholders resolve into the host and the text fields of an operation, its label and its hex data, before the probe is sent. The numeric addressing fields (the address, the quantity, a register value) are literal in a chain step and do not take a placeholder.

A chain step is an automated send, so a write needs writes enabled for the workspace and the probe armed; there is nobody to confirm. With either unmet the step fails and nothing is sent, with MODBUS_TRANSPORT_OUTCOME set to BLOCKED. One pattern is to write a register, read it back in the next operation and assert on MODBUS_REGISTERS. Another is HTTP then Modbus: change a setpoint through the system’s own API, then read the register it is supposed to drive.

Through the proxy, Modbus/TCP is recognised by its MBAP header, which the client sends first. The capture decodes each message: the unit id, the function, the address and quantity of a read request, the registers or coils of a read reply, an exception, or the raw PDU for anything else.

A mock rule matches on host, unit (the unit id) and function (by name such as READ_HOLDING_REGISTERS, or by code such as 3 or 0x03); a blank field matches anything. Its one action is MOCK, which answers the request in place of the device with one of:

  • values, the coil bits or register values a read is answered with (sized to the quantity the request asked for, zeros where the list runs short),
  • responseBytes, a raw PDU payload as hex, for a data-carrying function with no register shape such as report server id or device identification,
  • exception, an exception code by name or number, which fault-injects any function.

A matched MOCK never reaches the device. When the rule names nothing the function can be answered with, the request is dropped rather than relayed, which shows as a matched-but-blocked exchange. A write with no explicit payload is answered with the acknowledgement the device would have sent. The proxy can also draft a mock from a captured session, pre-filled with what the device really answered, as a starting point to change.

VirtuProbe’s own probe, chain and script sends honour a mock rule marked to apply to outgoing traffic: a matched operation is answered from the rule and never sent, showing a mocked chip in the response.

virtuprobe-docker/modbus-simple is one Modbus/TCP server on port 502, unit id 1 (it answers any unit id), with a seeded data model and a SunSpec map. Writes are accepted, so a write followed by a read confirms it landed.

Terminal window
cd virtuprobe-docker/modbus-simple && docker compose up --build -d
TableFunction codesSeed
Holding registersread with FC03, write with FC06 / 16 / 22 / 23address 0 to 9 hold 100, 200, … 1000
Input registersread with FC04address 0 to 9 hold 11, 22, … 110
Coilsread with FC01, write with FC05 / 15address 0 to 15 alternate off, on
Discrete inputsread with FC02address 0 to 15 alternate on, off

A read past the end of a block comes back as ILLEGAL_DATA_ADDRESS, a Modbus exception rather than a transport error, so the probe sees the device answer and refuse. A SunSpec model chain sits at base 40000: the SunS marker, a Common model with identity strings (Mn=VirtuProbe, Md=modbus-simple, Vr=0.0.1, SN=SN-0001), an inverter model, then the end marker.

Things to try:

  • Read: READ_HOLDING_REGISTERS address 0 quantity 10 returns 100 to 1000; READ_COILS address 0 quantity 16 returns the alternating pattern.
  • Write (writes enabled, probe armed): WRITE_SINGLE_REGISTER address 0 value 4242, then READ_HOLDING_REGISTERS address 0 quantity 1 returns 4242.
  • Exception: READ_HOLDING_REGISTERS address 60000 quantity 1 returns ILLEGAL_DATA_ADDRESS.
  • SunSpec: SUNSPEC_SCAN base 40000 returns the Common model identity and the inverter model.
  • Modbus RTU and ASCII, the serial line framings. This probe speaks Modbus/TCP. The serial line diagnostics codes are still sendable over TCP, because a gateway may answer them.
  • Transport security. Modbus/TCP as this probe speaks it has no authentication and no encryption.
  • The payload inside an encapsulated interface transport. A CANopen or other inner protocol is carried and returned as raw bytes, not decoded.

A probe file written by hand or over MCP is shaped like this. An absent key takes the default a person would have chosen and never arms writes.

  • Operations are the operations list, each an object with a function and the fields that function needs. {"function": "READ_HOLDING_REGISTERS", "address": 0, "quantity": 10} is a whole read.
  • writeArmed is the per-probe arm. Absent or false means a write is held back.
  • A typed decode rides on a register read as a decode object and is read by MODBUS_DECODED. It is not in the editor. type is one of INT16, UINT16, INT32, UINT32, INT64, UINT64, FLOAT32, FLOAT64, STRING; offset is the register offset into the read; wordOrder and byteOrder are BIG_ENDIAN (the Modbus and SunSpec default) or LITTLE_ENDIAN; scaleFactor is a base-10 exponent applied to an integer type; length is the register count for a STRING.
{
"host": "localhost",
"port": 502,
"unitId": 1,
"writeArmed": false,
"operations": [
{"function": "READ_HOLDING_REGISTERS", "address": 40072, "quantity": 2,
"label": "power",
"decode": {"type": "FLOAT32", "wordOrder": "BIG_ENDIAN"}}
]
}