CVE-2025-59947
Executive Summary
CVE-2025-59947 is a critical buffer overflow vulnerability in NanoMQ, an MQTT messaging broker for IoT Edge and SDV (Software-Defined Vehicles). The flaw is triggered when PUBLISH packets are processed that match both a shared subscription and a vanilla (non-shared) subscription. This dual-subscription condition leads to a heap-based buffer overflow, potentially allowing an attacker to crash the broker or execute arbitrary code. The vulnerability affects all versions prior to 0.24.4. The vendor has released a fix in version 0.24.4, and a workaround is to disable shared subscriptions. No public exploit code or proof-of-concept is currently available, but the risk is elevated due to the widespread use of MQTT in IoT environments.
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
NanoMQ is distributed as a binary package and source code. The vulnerability is in the core broker logic, not in a third-party dependency. Users should verify the integrity of the downloaded package using checksums provided by the vendor. The fix is included in the official release 0.24.4.
CVSS Breakdown & Threat Level
The CVSS score is not provided in the NVD data. However, based on the nature of the vulnerability (buffer overflow in a network service), a reasonable estimate is:
- Attack Vector (AV): Network (N) – The vulnerability is exploitable over the network via MQTT PUBLISH packets.
- Attack Complexity (AC): Low (L) – No special conditions are required beyond sending a crafted PUBLISH packet.
- Privileges Required (PR): None (N) – No authentication is needed to trigger the overflow.
- User Interaction (UI): None (N) – No user action is required.
- Scope (S): Unchanged (U) – The overflow affects the broker process only.
- Confidentiality (C): High (H) – Potential for memory disclosure.
- Integrity (I): High (H) – Potential for memory corruption leading to code execution.
- Availability (A): High (H) – The overflow can crash the broker.
Estimated CVSS Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
Estimated Base Score: 9.8 (Critical)
Threat Level: Critical. The vulnerability is remotely exploitable without authentication and can lead to full compromise of the MQTT broker.
Deep Dive & Mechanics
The vulnerability resides in the handling of PUBLISH packets when a topic matches both a shared subscription (e.g., $share/group/topic) and a vanilla subscription (e.g., topic). In NanoMQ, the broker maintains separate data structures for shared and vanilla subscriptions. When a PUBLISH packet arrives, the broker iterates over matching subscriptions to deliver the message. The bug occurs in the code path that handles the intersection of these two subscription types.
Specifically, when a PUBLISH packet triggers both a shared subscription and a vanilla subscription, the broker attempts to copy the message payload into a buffer that is sized based on the number of subscribers. However, due to an off-by-one or miscalculation in the buffer size, the copy operation overflows the allocated buffer. This heap-based buffer overflow can corrupt adjacent memory, leading to a crash or, with careful crafting, arbitrary code execution.
The vulnerable code is in the pub_handler function or similar, where the broker calculates the required buffer size for delivering messages to multiple subscribers. The calculation does not account for the additional overhead when both shared and vanilla subscriptions are present, resulting in a buffer that is too small.
Vulnerable vs. Patched Code
The exact code diff is not publicly available, but the fix in version 0.24.4 addresses the buffer size calculation. The vulnerable code likely resembles:
// Vulnerable pseudo-code
int total_size = num_subscribers * sizeof(message);
char *buffer = malloc(total_size);
// Copy message for each subscriber
for (int i = 0; i < num_subscribers; i++) {
memcpy(buffer + i * sizeof(message), &msg, sizeof(message));
}
The patched code corrects the size calculation to include the overhead for shared subscriptions:
// Patched pseudo-code
int total_size = (num_vanilla + num_shared) * sizeof(message) + extra_overhead;
char *buffer = malloc(total_size);
// Copy message for each subscriber
for (int i = 0; i < num_vanilla; i++) {
memcpy(buffer + i * sizeof(message), &msg, sizeof(message));
}
for (int i = 0; i < num_shared; i++) {
memcpy(buffer + (num_vanilla + i) * sizeof(message), &msg, sizeof(message));
}
Exploitation & Lab Setup
Red Team
Prerequisites:
- A NanoMQ broker running a vulnerable version (< 0.24.4) with shared subscriptions enabled.
- Network access to the broker's MQTT port (default 1883 for TCP, 8883 for TLS).
Exploitation Steps:
- Identify Target: Scan for NanoMQ brokers using Shodan or Nmap with the MQTT script.
nmap -p 1883 --script mqtt-subscribe <target> - Craft PUBLISH Packet: Use a tool like
mosquitto_pubor a custom script to send a PUBLISH packet that matches both a shared and vanilla subscription.# Subscribe to a shared topic and a vanilla topic mosquitto_sub -h <target> -t '$share/group/test' & mosquitto_sub -h <target> -t 'test' & # Publish to the topic mosquitto_pub -h <target> -t 'test' -m 'A'*1000 - Trigger Overflow: The large payload may cause a buffer overflow. For code execution, a more sophisticated payload is needed to overwrite function pointers or return addresses.
Note: No public exploit code is available. The above is a conceptual approach.
Blue Team
Detection:
- Monitor MQTT traffic for unusually large PUBLISH packets.
- Alert on broker crashes or restarts.
- Use the YARA and Sigma rules provided in the Detection Engineering section.
Mitigation:
- Immediately upgrade to NanoMQ 0.24.4 or later.
- If upgrade is not possible, disable shared subscriptions in the configuration file (
nanomq.conf):shared_subscription.enable = false - Restrict network access to the MQTT broker using firewall rules.
- Enable logging and monitor for suspicious activity.
Indicators of Compromise (IOCs)
- Network: MQTT PUBLISH packets with topic strings that match both shared and vanilla subscriptions, especially with large payloads.
- Host: Broker process crash logs or core dumps.
- File: Unexpected modifications to broker memory or configuration files.
- Logs: Entries indicating buffer overflow errors or segmentation faults in the broker logs.
Detection Engineering
YARA Rule
rule CVE_2025_59947_NanoMQ_Buffer_Overflow {
meta:
description = "Detects NanoMQ binary with vulnerable buffer overflow in PUBLISH handling"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2025-59947"
strings:
$vuln_func = "pub_handler" ascii wide nocase
$vuln_str = "shared_subscription" ascii wide nocase
condition:
$vuln_func and $vuln_str
}
Sigma Rule
title: NanoMQ Buffer Overflow Attempt
id: 8a9b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d
status: experimental
description: Detects potential exploitation of CVE-2025-59947 via large PUBLISH packets
author: Valters IT
logsource:
category: application
product: nanomq
detection:
selection:
event: "publish"
payload_size: "> 10000"
condition: selection
falsepositives:
- Legitimate large messages from IoT devices
level: high
Suricata Rule
alert tcp any any -> any 1883 (msg:"CVE-2025-59947 NanoMQ Buffer Overflow Attempt"; flow:to_server,established; content:"|10|"; depth:1; content:"|00|"; distance:1; within:2; content:"|03|"; distance:0; within:1; pcre:"/^.{2,}/R"; sid:1000001; rev:1;)
Note: The Suricata rule is a basic example. A more precise rule would require deep packet inspection of the MQTT payload.
Remediation & Mitigation
Immediate Actions:
- Upgrade: Update NanoMQ to version 0.24.4 or later.
# For source builds git pull origin master git checkout tags/0.24.4 mkdir build && cd build cmake .. make sudo make install - Workaround: If upgrade is not possible, disable shared subscriptions in
nanomq.conf:shared_subscription.enable = false - Network Segmentation: Restrict access to the MQTT broker to trusted IPs only.
- Monitoring: Enable detailed logging and monitor for anomalies.
Long-Term:
- Implement a vulnerability management program for IoT components.
- Regularly update all software in the IoT pipeline.
- Use network intrusion detection systems (NIDS) to detect exploitation attempts.
Valters IT
DevSecOps & Cyber Threat Intelligence Expert