Description
nanoMODBUS through v1.23.0 contains an off-by-one buffer overflow in the recv_msg_header() function of the Modbus/TCP server that allows remote unauthenticated attackers to write one attacker-controlled byte past the end of the 260-byte receive buffer by sending a crafted MBAP frame whose Length field is set to 255. The overflow corrupts the adjacent buffer-index field of the nanoMODBUS state structure, resulting in denial of service through invalid memory accesses and, on bare-metal and RTOS targets without memory protection, one-byte information disclosure and writes to unintended register addresses on the Write Multiple Registers (FC16) handler path.
An attacker who can reach the TCP listening port of a Modbus/TCP server built on nanoMODBUS (typically TCP/502 on industrial / OT networks) sends a single crafted MBAP frame with Length=255 to corrupt the buf_idx field of the nmbs_t struct, causing denial of service or, on memory-protection-less embedded targets, additional information disclosure or unintended register writes.
Problem types
Product status
Any version
Credits
Burxonov Muslimbek
References
github.com/debevv/nanoMODBUS (nanoMODBUS - upstream repository (vendor))
github.com/debevv/nanoMODBUS/blob/v1.23.0/nanomodbus.c (Vulnerable bounds check at nanomodbus.c line 369 (v1.23.0))
cwe.mitre.org/data/definitions/193.html (CWE-193: Off-by-one Error)
cwe.mitre.org/data/definitions/787.html (CWE-787: Out-of-bounds Write)