🇰🇷 한글 설명
nanoMODBUS v1.23.0 이하 버전의 handle_read_file_record() 함수에서 누적 응답 크기를 검증하지 않아 발생하는 경계 외 쓰기(Out-of-bounds Write) 취약점입니다. 공격자가 조작된 FC 0x14 요청을 보내면 uint8_t 변수 오버플로우를 유발하여 260바이트 크기의 버퍼를 넘어 약 8490바이트의 데이터를 메모리에 써버릴 수 있습니다. 이로 인해 서비스 거부(DoS) 또는 원격 코드 실행(RCE)이 발생할 수 있습니다.
💡 쉬운 설명
데이터를 담는 그릇의 크기를 제대로 확인하지 않아, 너무 많은 데이터를 한꺼번에 넣으려고 할 때 옆에 있는 중요한 메모리 영역까지 덮어쓰는 문제입니다. 이를 통해 해커가 시스템을 멈추게 하거나 컴퓨터를 마음대로 조종할 위험이 있습니다.
🇺🇸 원문 (English)
nanoMODBUS through v1.23.0 contains an out-of-bounds write in the Modbus server-side handle_read_file_record() function (FC 0x14, Read File Record) in nanomodbus.c. The function validates that the total request size does not exceed 245 bytes and that each sub-request's record_length is at most 124, but it never validates the CUMULATIVE response size across all sub-requests before processing them. The accumulator response_data_size is declared as uint8_t and is incremented by 2 + record_length*2 for each of up to 35 sub-requests; with 35 sub-requests of record_length=124, the cumulative demand is 8750 bytes, which overflows the uint8_t accumulator. A subsequent loop then calls get_n(), an internal function with no bounds checking, once per sub-request to obtain a pointer into the 260-byte msg.buf receive buffer and advances the internal buf_idx by up to 248 bytes per call; swap_regs() then writes to that pointer unconditionally. A single crafted FC 0x14 request from an unauthenticated network client can cause up to ~8490 bytes to be written out of bounds past the 260-byte buffer, corrupting adjacent memory in the server process and leading to denial of service or potential remote code execution, particularly on embedded/bare-metal targets without memory protection.
📍 영향받는 시스템
nanoMODBUS v1.23.0 및 그 이전 버전
⚔️ 공격 벡터
인증되지 않은 네트워크 클라이언트가 조작된 Modbus FC 0x14(Read File Record) 요청을 전송
🛡️ 대응 방법
nanoMODBUS를 최신 보안 패치가 적용된 버전으로 업데이트하거나, 해당 기능(FC 0x14)에 대한 네트워크 접근을 차단하십시오.
🔧 검증 코드
출력된 Version이 1.23.0 이하인지 확인하여 취약 여부를 판단합니다.
pip show nanomodbus 2>/dev/null | grep -E 'Version'