Security · Python
modbus: a Python CLI for industrial protocol testing
The problem
Industrial devices expose values through registers and coils, but interpreting them requires the correct address notation, register type, byte order, word order and datatype. A successful connection alone does not prove that the value being read or written has been interpreted correctly.
The modbus project provides a command-line client for PLCs, VFDs, energy meters and RTUs. It combines protocol-aware operations, readable terminal output and machine-readable JSON so the same workflow can support an interactive lab session or a controlled automation script.
Architecture
CLI or interactive shell
Select a connection, operation, address range and datatype.
Validation and conversion
Resolve register notation, protocol limits, byte order and scale.
pymodbus transport
Use TCP, UDP, serial RTU/ASCII, or TLS according to the target.
Simulator or authorized device
Exchange protocol requests and responses within an approved scope.
Implementation
- Read, scan and watch operations support inspecting register ranges and observing changes. Write, fill and restore operations can modify writable device state and must be treated differently from read-only inspection.
- Datatype conversion covers integers, floating-point values and strings, with configurable byte order, word order and scaling. Standard register notation is converted to the underlying protocol offsets.
- The client enforces documented function-code limits before sending requests and provides deterministic exit codes for usage errors, connection failures, protocol exceptions and timeouts.
- An embedded TCP/UDP simulator provides changing sensor values for local experimentation. The interactive shell supports named connections and session settings, while JSON output supports scripted workflows.
Security takeaways
- Traditional Modbus deployments should not be assumed to provide authentication or confidentiality. Network segmentation and access control remain important even when a client can successfully exchange requests.
- Write, fill and restore operations can affect physical processes. Use the simulator first, define authorization and change boundaries, and do not treat an industrial production network as a test environment.
- When TLS is used, verify the server certificate and protect client keys. An optional certificate-verification bypass is a diagnostic exception, not a secure deployment default.
Scope and limitations
A protocol client is not a complete OT security assessment. Device-specific register maps, safety constraints, operational approvals and the surrounding network architecture still determine what can be tested safely. No production-device assessment or certification is claimed by this case study.
Source references
Related articles
Related projects
CC1101_DRIVER
ESP-IDF C driver for CC1101 sub-GHz radio modules: set frequency, modulation and packet options, then send, receive or capture the demodulator output.
Updated Source on GitHub
RTSP_TO_HTTP
HiveHack @ CyberSea challenge pipeline: find an RTSP camera, convert the stream to HLS with FFmpeg and play it over HTTP in a smart TV browser.
Updated Source on GitHub