Skip to content

About

Modbus RTU 侦察:扫从站、映射寄存器、给证据画像,只读无写路径 | Recon Modbus RTU slaves, map registers, evidence-based — read-only by design

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

modbus-lens · Modbus RTU 侦察器

CI License: MIT Python 3.10+

指向一个串口,它扫出哪些从站应答、哪些寄存器可读,再对寄存器逐个采样、给出基于证据的画像——全程只读,代码里不存在写路径。

English: Point it at a serial port: it finds which Modbus RTU slaves answer, maps readable registers, and probes them for an evidence-based profile — read-only, with no write path at all.

Sibling project of SerialLens (same philosophy: face unknown hardware, report only evidence) and comfy-preflight.

python modbus_lens.py --demo                 # full workflow on virtual slaves, no hardware
python modbus_lens.py --port COM3 --baud 9600 --probe 8

Safety by default: every bus operation is a READ — function codes are whitelisted to 0x03/0x04 in code (_check_func rejects anything else), and there is no write path at all. On an industrial bus, that is the whole point.

Demo output (trimmed):

== Slave discovery (addr 1-247): 2 found
  - slave 1 responds

== Slave 1 readable ranges (regs 0-200):
  - 0 .. 4 (5 regs)
  - 20 .. 25 (6 regs)

== Slave 1 probe (8 samples/reg):
  - reg 0     CHANGING  min=250 max=252 mean=250.6  looks like x10 fixed-point (e.g. 250 -> 25.0)
  - reg 2     static    value=263 (0x0107)

What it does

Step How
Slave discovery Read Holding Registers (0x03), 1 register, addr 1-247; an exception response still proves the slave is alive
Register mapping Block reads (default 8); an answering block proves its whole span; illegal-address blocks are hole-probed one register at a time
Probing N samples per register: min/max/mean, CHANGING vs static, hex of static values
Hunches Evidence-based only: "range fits 0-100 (percent?)", "looks like x10 fixed-point", "uses high bits". Never a claim.

Demo mode

--demo simulates two virtual slaves in memory:

  • slave 1 — temperature/humidity sensor: temp (x10, moving), humidity (x10, moving), firmware version, serial, status bits, calibration block
  • slave 17 — I/O module: 8 static channel registers

so you can see discovery → mapping → probing in seconds without a single wire attached.

Real hardware

pip install pyserial
python modbus_lens.py --port COM3 --baud 9600 [--reg-hi 999] [--probe 8]
  • The full slave sweep (1-247) takes ~100 s at the default 0.4 s timeout; progress is printed to stderr so silence doesn't look like a hang.
  • Register scan speed is bounded by the bus (65535 registers at 9600 baud is hours), so keep --reg-hi sane first; widen after the first map.
  • Probing is a burst (N samples within a short window): minute-scale drift will read as static. Corrupted frames (CRC mismatch) are skipped, never fatal - a noisy link bends the map, it doesn't kill the scan.

Hints

  • --probe 0 skips probing (discovery + mapping only)
  • --slave-lo/--slave-hi, --reg-lo/--reg-hi bound the scans
  • Probing reads are single-register; interleaved writes from other masters will show up as noise — that is evidence too

The Lens series

modbus-lens is part of the Lens series — one philosophy: face unknown hardware and protocols, report only evidence, never claim certainty.

Tool Domain Status
SerialLens Serial / UART protocol identification & decoding ✅ available
modbus-lens Modbus RTU slave discovery & register recon ✅ available
can-lens CAN bus traffic profiling 🚧 planned
ble-lens BLE GATT service recon 💡 idea

License

MIT


English

Full English documentation: README_EN.md

About

Modbus RTU 侦察:扫从站、映射寄存器、给证据画像,只读无写路径 | Recon Modbus RTU slaves, map registers, evidence-based — read-only by design

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages