A specifically malformed MQTT Subscribe packet crashes MQTT Brokers using the mqtt-packet module for decoding
A malformed MQTT Subscribe packet causes an out-of-range buffer read in the mqtt-packet module, throwing a RangeError. MQTT brokers like mosca and aedes that use this module can be crashed by an unauthenticated attacker, leading to denial of service.
- Triaged in under an hour
- Fixed in 11 days
- Disclosed after 11 days
I would like to report a buffer over-read in mqtt-packet respectively BufferList module. It allows triggering an out of range read on a buffer which throws a RangeError. MQTT Brokers like mosca and aedes using this module can be forced to crash by sending a specifically malformed MQTT Subscribe packet.
Module
module name: mqtt-packet
version: 6.1.1
npm page: https://www.npmjs.com/package/mqtt-packet
Module Description
Encode and Decode MQTT 3.1.1, 5.0 packets the node way.
Module Stats
114,635 weekly downloads
Vulnerability
Vulnerability Description
From the original E-Mail to the Author: Hey Matteo, while playing around with mosca/aedes and our fuzzing approach from IoT-Testware, I discovered some flaws which cause mosca/aedes to crash. Though, I assume the reasons originate from the mqtt-packet respectively bl modules. I didn't open an issue because the issue is IMHO quite critical. One could try to abuse to crash mosca/aedes without requiring any credentials, thus might lead to easy DoS attacks. The malformed Subscribe Packet crashes mosca (v2.8.3) and aedes (v0.37.0), no valid credentials required.
Steps To Reproduce:
Detailed steps to reproduce with all required references/steps/commands. If there is any exploit code or reference to the package source code this is the place where it should be put.
- start either mosca or aedes MQTT Broker
- shoot the following command against the Broker (on localhost)
echo -ne '\x104\x00\x04MQTT\x04\xc2\x00\xff\x00\x19alicedoesnotneedaclientid\x00\x05alice\x00\x06secret\x82\x19\xa5\xa6\x00\x15hello/topic/of/alice\x00' | nc localhost 1883- the sent byte string contains 2 accumulated MQTT Packets. The second packet is a subscribe packet and is processed in any case and the Broker's Auth mechanisms are undermined.
Patch
Please find a GitHub patch attached.
Supporting Material/References:
State all technical information about the stack where the vulnerability was found
- Ubuntu 18.04.2 LTS
- nodejs -v
v6.17.1 - npm -v
3.10.10
Wrap up
- I contacted the maintainer to let them know: [Y]
- I opened an issue in the related repository: [N]
Impact
An attacker can harm the availability of MQTT services which are using these modules.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely a buffer over-read in the mqtt-packet or bl module when parsing a malformed Subscribe packet, causing an out-of-range read that throws a RangeError.
Impact
An unauthenticated attacker could crash MQTT brokers that use the module, harming the availability of the service.
What the attacker needed
Network access to the MQTT broker; no credentials required
The fix
A GitHub patch was attached to the report, but the text does not state that it was applied or released.
How it was found
- Start either a mosca or aedes MQTT broker.
- Send a crafted byte string containing two MQTT packets to the broker on port 1883.
- The second packet is a Subscribe packet that is processed regardless of authentication and triggers the crash.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
MQTT is a messaging protocol used by many internet-of-things devices. The mqtt-packet library reads incoming messages, and a specially crafted Subscribe message makes it read past the end of a buffer, which throws an error and crashes the broker. No login is needed, so anyone who can reach the broker can take it down.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.