<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Security assessment of common open source MQT T brokers and clients</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Edoardo Di Paolo</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Enrico Bassetti</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Angelo Spognardi</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Computer Science dept., Sapienza University of Rome</institution>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>Security and dependability of devices are paramount for the IoT ecosystem. Message Queuing Telemetry Transport protocol (MQTT) is the de facto standard and the most common alternative for those limited devices that cannot leverage HTTP. However, the MQTT protocol was designed with no security concern since initially designed for private networks of the oil and gas industry. Since MQTT is widely used for real applications, it is under the lens of the security community, also considering the widespread attacks targeting IoT devices. Following this direction research, in this paper we present an empirical security evaluation of several widespread implementations of MQTT system components, namely five broker libraries and three client libraries. While the results of our research do not capture very critical lfaws, there are several scenarios where some libraries do not fully adhere to the standard and leave some margins that could be maliciously exploited and potentially cause system inconsistencies.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>
        The protocol was conceived with no security concern, since initially designed for private
networks of the oil and gas industry [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. The adoption of the protocol has ramped up, and
several statistics show that many devices use it without any protection [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. Also, considering the
privacy aspects, given its quite limited features, the MQTT protocol has no built-in encryption
features; farther, the use of TLS to provide a secure communication channels is very limited: at
the time of writing, comparing with the Shodan search engine the prevalence of the exposed IoT
and IIoT devices using MQTT, we have that those that use port 8883 (MQTT over SSL/TLS) is 42,
while those using port 1883 (MQTT-unencrypted) is 154632 [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. Moreover, MQTT applications
keep receiving critiques, with the claim that they adopt weak protocol implementations, even
if some of them, like the Mosquitto library, ofer extension plugins to improve security 1 (i.e.
role-based authentication or Access Control List, not part of the MQTT standard).
      </p>
      <p>
        Since MQTT is widely used for real applications, it is under the lens of the security
community, also considering the widespread attacks targeting IoT devices. The research is focusing
on shifting towards ensuring secure IoT systems, for example, implementing access control
mechanisms [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], lightweight cryptography [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] or remote attestation of devices [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ]. An essential
aspect of this context is discovering unforeseen security risks resulting from the necessary
interoperability with diferent implementations of MQTT libraries.
      </p>
      <p>Following this research direction, in this paper we present an empirical security evaluation of
several widespread implementations of MQTT system components, namely five broker libraries
and three client libraries. Moreover, we also applied our security analysis to an MQTT client
embedded in a real IoT device, namely a Shelly DUO Bulb. This IoT device is a remote-controlled
LED light bulb. It supports Wi-Fi connectivity and acts as an MQTT subscriber to receive
commands, like powering on/of or light dimming.</p>
      <p>Our evaluation has aimed to verify the responses of the components of the diferent libraries
to diferent MQTT messages to see their behaviour in situations where the standard does not
indicate clearly how the message (or the connection itself) is supposed to be handled. These
mishandling might create interoperability issues or even open doors to malicious attackers.
While the results of our research do not capture very critical flaws, there are several scenarios
where some of the libraries do not fully adhere to the standard and leave some margins that
could be maliciously exploited and potentially cause system inconsistencies.</p>
      <p>The structure of the paper is the following: Section 2 reports the state of the art concerning
the security analysis of MQTT, while in Section 3 we provide the details about our research
methodology. Section 4 reports the results of our security analysis, and the last section concludes
the paper with some remarks and future directions.</p>
    </sec>
    <sec id="sec-2">
      <title>2. Related works</title>
      <p>
        As the abundance of surveys suggests [
        <xref ref-type="bibr" rid="ref10 ref11 ref9">9, 10, 11</xref>
        ], security and dependability of IoT devices is
paramount for the whole ecosystem. In this context, the MQTT protocol plays a determinant
role. In 1999 Andy Stanford-Clark (IBM) and Arlen Nipper (then working for Eurotech, Inc.)
proposed the MQTT protocol [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ] to monitor oil pipelines within the SCADA framework [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ].
Since then, it has been revised in two main versions, namely 3.1.1 (last update December 2015)
1https://mosquitto.org/documentation/dynamic-security
and 5 (last update March 2019). To date, the former is by far the most used in real applications,
the latter being much newer and still not well adopted [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ].
      </p>
      <p>
        Like all the network protocols becoming a standard, it has undergone many reviews both
formally and empirically. Several papers focus on MQTT formal modelling and performance
analysis [
        <xref ref-type="bibr" rid="ref14 ref15 ref16">14, 15, 16</xref>
        ], others on its possible vulnerabilities, and many others on its security
analysis. In this research, we focused on the security analysis and the comparison of several
of the most spread software libraries implementing the MQTT protocol. Instead of using
static analysis of their code, as in [
        <xref ref-type="bibr" rid="ref17">17</xref>
        ], we performed a dynamic analysis using the fuzzing
methodology. In [
        <xref ref-type="bibr" rid="ref18">18</xref>
        ], the authors proposed a template-based fuzzing framework and tested
its efectiveness against two implementations of MQTT. Using this method, they found some
security issues: Moquette and Mosquitto brokers were afected by a vulnerability that would
have led to a DoS attack in specific settings if exploited. In our research, we are focusing not
only on possible DoS attacks but also on the efects of standard violations of both brokers and
clients. Moreover, our analysis applies to five diferent brokers, three clients and a physical
device.
      </p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref19">19</xref>
        ], the authors evaluated the robustness of several MQTT implementations against a
subtle family of attacks known as low-rate denial of service. Similarly to this work, a real
testbed was set up, and several experiments performed, validating the open vulnerability of all
the MQTT implementations.
      </p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref20">20</xref>
        ], authors describe a new strategy to test MQTT through fuzzing and how much it is
eficient against the protocol. However, they do not present any results about the application of
their strategy. A similar approach is adopted in [
        <xref ref-type="bibr" rid="ref21">21</xref>
        ], where the authors propose to apply fuzzing
techniques in a container-based environment (Docker). This would allow a large scale test of
the MQTT protocol. However, again, the authors do not compare diferent implementations
(they only consider Mosquitto), neither describe the type of attacks they performed.
      </p>
      <p>
        A diferent methodology based on attack patterns [
        <xref ref-type="bibr" rid="ref22">22</xref>
        ] was proposed by Sochor et al. and was
used to spot hidden vulnerabilities in diferent broker implementations. They adopted a method
to randomly generate test sequences (Randoop) to challenge the diferent brokers, and they
were able to find several failures and unhandled exceptions. Our research adopted a diferent
methodology, tested diferent broker MQTT implementations, and included clients.
      </p>
      <p>
        Another methodology to perform a dynamic analysis is model-based testing, as proposed
for MQTT applications in [
        <xref ref-type="bibr" rid="ref23">23</xref>
        ]. The methodology considers using a finite state machine that
verifies the properties of the software and proposes extensions to model-based tools for MQTT
applications.
      </p>
      <sec id="sec-2-1">
        <title>2.1. MQTT overview</title>
        <p>MQTT implements the publish-subscribe communication paradigm (Figure 1): clients send
messages on a topic to servers (named brokers) that are responsible for delivering them to the
interested clients, the final recipients of the messages. Brokers are, then, intermediaries that
accept messages and forward a copy of each message to the clients who previously subscribed for
a given topic. A topic is a UTF-8 string obtained joining one or more topic levels with the slash
character, like in /home/basement/kitchen/temperature/ and the client subscriptions
can be made to a topic or part of it, thanks to the use of wildcards, like in /home/basement/#.</p>
        <p>In a general MQTT session, a client establishes a connection with a broker
(CONNECTCONNACK exchange), subscribes to one or several topics (SUBSCRIBE-SUBACK exchange),
publishes contents (PUBLISH-PUBACK exchange), receives other client contents (PUBLISH or
PUBLISH-PUBREC-PUBREL exchange, according to the QoS) and terminates the session (client
DISCONNECT). The CONNECT packet can implement an authentication mechanism, based on
username and password. All the exchanges happen using a clear text TCP session on port 1883
or, if TLS is used, using an encrypted session on port 8883. Encrypted exchanges are mainly
used when authentication is enforced, so that username and password are protected against
eavesdropping.</p>
        <p>In addition to the topic, any message also has a Quality-of-Service value (QoS), taken in the
range 0–2. A QoS equals 0 corresponds to no guarantees, and it means that the message can be
lost or delivered multiple times. A client sending a message with QoS equals 1 requires that
the message should never be discarded, while it might be delivered multiple times; in this case
the sender stores the message until it receives back a PUBACK packet that ensures reception.
Similarly, with a QoS set to 2, the message should never be discarded and it should be delivered
exactly one time; in this case the client will wait for a PUBREC packet and, once received, it
will discard the PUBLISH and it will send a PUBREL packet. The last packet that the client will
receive in this exchange is the PUBCOMP that will release the id of the PUBLISH for reuse. It
is important to highlight that the publisher QoS is not associated with the subscriber QoS –
unless the implementation supports this non-standardized feature.</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3. Methodology</title>
      <p>The purpose of our research was to compare the behaviour of diferent implementations of
MQTT. The first step has been finding and setting up the most popular open-source brokers and
client libraries that people use to manage their devices or develop common software solutions.
To determine the popularity, we took into account the number of stars and forks on GitHub
repositories and the number of blog posts citing the examined brokers.</p>
      <p>We focused only on open source libraries, namely: Mosquitto, EMQ X, HiveMQ, Moquette and
Aedes for the brokers, paho, mqttools and mqtt.js for the clients. We will discuss the brokers
and the clients respectively in Section 4.1 and in Section 4.2. Some of these have thousands
of instances running in “production” environments, in common consumer and
business-tobusiness solutions. We also tested a popular low-cost Internet-of-Things device, namely the
Shelly DUO Bulb (Section 4.3).</p>
      <p>The next step has been to evaluate the type of tests to apply, considering the MQTT standard
specification, version 3.1.1. We specifically looked for undefined behaviours, unspecified states
or other missing information about message handling. Also, we looked for parts of the standard
that might lead to a wrong implementation (e.g. expected actions by the broker/client that are
implied but not specified or not clearly specified). This allowed us to focus our testing on a
restricted subset of cases, as explained in Section 4.</p>
      <p>We created diferent sets of experiments to find possible anomalies in MQTT implementations,
developing our fuzzer written in python, with the help of the twisted library2. Our custom
fuzzer allowed us to manage diferent streams correctly and send custom packets: for example,
we could change every bit of the packets to see the brokers behaviour even in the presence
of malformed packets. Standard, common MQTT libraries, instead, implement some
statemachine which are expected in some part of the protocol (e.g. QoS2): a straightforward use of
such libraries would not allow arbitrary changes in the flow of the messages, like out-of-order
messages. Each experiment has been codified in a JSON file that specifies the sequence of
actions or packets that the test should run on/against the software under test, and the final
behaviour of the involved parties have been logged and analyzed.</p>
    </sec>
    <sec id="sec-4">
      <title>4. Experimental results</title>
      <sec id="sec-4-1">
        <title>4.1. Brokers</title>
        <p>A broker is a fundamental component in an MQTT architecture. Its job is to accept messages
from clients (acting as “publishers") and then forward them to all clients with subscriptions
(“subscribers") matching the topic of the message. This loosely coupled architecture allows the
clients to not communicate directly with each other.</p>
        <p>Modern brokers support many concurrent connections and messages per second. A flaw in
message state machines, packet parsing, topic logic, etc., might expose a high impact
vulnerability, which a malicious actor might exploit to launch some attacks like a Denial-of-Service.</p>
        <p>We analyzed five common MQTT brokers:</p>
        <p>• Mosquitto3: it is one of the most used MQTT brokers in the world. It is a single-threaded,
lightweight broker written in C. This broker has been widely used thanks to its flexibility.
• EMQ X4: it is written in Erlang and it claims to be so eficient to be “the Leader in Open</p>
        <p>Source MQTT Broker for IoT".
• HiveMQ5: a broker written in Java. It supports MQTT version 3.x and 5.0 and it is widely
used in automation and industrial systems. We tested the Community Edition.
• Moquette6: another Java-powered open-source broker. It is very lightweight but it is
less-known and less-used, when compared to other brokers.
• Aedes7: a broker written in JavaScript/NodeJS. It is the successor of MoscaJS. It does
not support version 5 of MQTT, but it is fully compatible with version 3.x and supports
several extension libraries.</p>
        <p>Each broker underwent the same set of tests specified in the next section. We performed more
than 60 diferent experiments on a consumer-grade PC with local connections. A summary of
the results is in Table 1.
4.1.1. Experiments and results
Publish QoS 2 and 1. In this experiment, the client performs the following steps:</p>
        <sec id="sec-4-1-1">
          <title>1. it sends a SUBSCRIBE packet with a specific topic;</title>
          <p>2. it sends the first PUBLISH packet with a quality of service 2 and with id 1 over the topic
specified in the subscription;
3. it sends the second PUBLISH packet with a quality of service 1, still with id 1 over the
topic specified in the subscription;
4. it sends a PUBREL packet for the first packet sent.</p>
          <p>We noticed diferent broker behaviours: Mosquitto publishes the first received packet with QoS
2, but then it loses the second packet that is not published to the clients due to the PUBCOMP
3https://mosquitto.org/
4https://www.emqx.io/
5https://www.hivemq.com/developers/community/
6https://github.com/moquette-io/moquette
7https://github.com/moscajs/aedes
packet that is not received, and so the packet id is not available for use. The EMQ X broker
publishes both packets; it handles the flow for the first packet and then the flow for the second
one. In HiveMQ and in Moquette, the client that sends packets receives the publication first and
after the pubcomp, concerning the first packet. Additionally, in HiveMQ the client receives the
pubcomp back first and then the pubrec. Aedes publishes both packets, but the pubcomp arrives
at the client after the two publications. This behaviour repeated several times, also in the other
experiments regarding the quality of service that are described below.</p>
          <p>Publish QoS 2 and 0. This experiment is very similar to the one described above, but in this
case, the client performs the following steps:</p>
        </sec>
        <sec id="sec-4-1-2">
          <title>1. it sends a SUBSCRIBE packet with a specific topic;</title>
          <p>2. it sends the first PUBLISH packet with a quality of service 2 and with the id 1 over the
topic specified in the subscription;
3. it sends the second PUBLISH packet with a quality of service 0 and with the id 1 over the
topic specified in the subscription;
4. it sends a PUBREL packet for the first packet sent.</p>
          <p>Mosquitto, in this case, publishes both packets but in reverse order: it handles the one with
quality of service 0 first, and then it handles, correctly, all the flow regarding the first packet
sent with quality of service 2. EMQ X and HiveMQ maintain the order of the packets published
by the client; also, in the case of HiveMQ, the client received back the pubcomp first and then
the pubrec regarding the packet with quality of service 2. Moquette behaves similarly to EMQ X,
but, in this case, the pubcomp arrives after the publication of the second packet. Aedes has the
same behaviour as Mosquitto, but the pubcomp arrives after the publication as in the previous
experiment.</p>
          <p>Double publish QoS 2. In this experiment, the client performs the following steps:</p>
        </sec>
        <sec id="sec-4-1-3">
          <title>1. it sends a SUBSCRIBE packet with a specific topic;</title>
          <p>2. it sends the first PUBLISH packet with a quality of service 2 and with the id 1 over the
topic specified in the subscription;
3. it sends the second PUBLISH packet with a quality of service 2 and with the id 1 over the
topic specified in the subscription;
4. it sends a PUBREL packet for the first packet sent;
5. it sends a PUBREL packet for the second packet sent.</p>
          <p>In Mosquitto, only one publication referred to the first packet sent, but the flow regarding the
quality of service is properly handled. EMQ X, in this case, has the same behaviour as Mosquitto.
Instead, HiveMQ and Moquette publish both packets in the correct order. In Aedes, there is a
diferent behaviour: the broker publishes two packets, but they are the same packet, the first
one sent by the client.</p>
          <p>Long topic. In the MQTT standard, the maximum length topic is 65536 bytes, but we saw
that in the source code of EMQ X there is a constant that represents the maximum length, and
its value is 4096. So, we tried to subscribe to a topic with more than 4096 bytes. In Mosquitto
the subscription to the topic is successful. Instead, HiveMQ cuts the topic to which the client
is subscribing to. In Moquette there is an IOException and then the client disconnection. In
Aedes there is a crash of the broker and the client; in particular, the exception thrown by the
experiment generated an error like “too many words”. In EMQ X the client disconnects.
Other experiments. Further experiments are listed below. They have been briefly
summarized, since the behaviour of all the brokers was correct.</p>
          <p>• some experiment where the client id value in the packet contains characters non-UTF-8
encoded: no anomalies. In detail, we have built a connection packet with the client id
containing particular characters and the experiment was handled correctly by all brokers;
• Keep-alive field in connection packet as a string: in all brokers there is the client
disconnection due to malformed packet;
• subscription (or publication) in an invalid wildcard: in all brokers there is the client
disconnection due to “invalid topic”;
• topics and wildcard encoded in: utf-16, zzlib, bz2 and base64. In the last three cases, there
were no anomalies to report. In the utf-16 experiment, in all brokers the client disconnects.
A particular experiment was the one with many “ / ” in the topic value; in Mosquitto, EMQ
X, Moquette and Aedes there was client disconnection while in HiveMQ there was a cut
of the topic and then the client subscription;
• packets flood with QoS 0: all brokers handled the flood well;
• invalid protocol name (or version) in the connection packet: in all cases, the client
disconnects;
• sending a pubrel packet that references a publication packet that was never sent: all
brokers, except for Aedes, sent back a pubcomp message. In Aedes there is the client
disconnection.</p>
        </sec>
      </sec>
      <sec id="sec-4-2">
        <title>4.2. Clients</title>
        <p>In addition to tests on brokers, we also carried out tests on client libraries available in the web.
In particular, we studied three diferent client libraries: paho-mqtt8, mqttools9 and mqtt.js10; the
ifrst two are written in python while the third is written in javascript. Again, we considered
metrics like the number of stars and forks on GitHub repositories. However, the experiments
have not found particular anomalies. Here there is a list of tests we tried:
• invalid QoS level: all libraries report an error about the QoS, blocking the sending of the
packet;
• invalid wildcard subscription: in this case mqtt.js generates an “Invalid topic" error, while
the other two libraries timeout;
• client id not encoded in utf-8: in mqttools the client cannot connect to the broker, in
paho-mqtt there is a successful connection to the broker and mqtt.js generates an error
with the consequent client disconnection;
• publication (or subscription) to a topic with a length more than 65536 characters: in all
libraries there is the client disconnection.</p>
      </sec>
      <sec id="sec-4-3">
        <title>4.3. Physical device</title>
        <p>In “home automation” the MQTT protocol is widely used as most smart devices supports it.
Many software applications allow you to use the protocol to manage the smart devices, and one
of them, for example, is Home Assistant; also Amazon, in AWS IoT, uses MQTT to connect the
user’s devices to other devices and other services.</p>
        <p>We decided to perform the previous experiments on a physical device. In this case, we tested
a Shelly light bulb that supports MQTT: it is possible, for example, to turn on or of the device
through specific commands sent in the local network. In this device, the protocol configuration
can be done in a simple web interface, available in the local network, where the user has to
8https://pypi.org/project/paho-mqtt/
9https://pypi.org/project/mqttools/
10https://github.com/mqttjs/MQTT.js
specify the broker’s IP and port. The username and password are not mandatory during the
configuration; this could be a security issue, depending on the context. This device does not
have an “anti-flood” regarding the packets it receives; for example, it is possible to turn of and
on the light bulb repeatedly and quickly by sending a PUBLISH packet on the specific topic with
specific content. The software that runs in the light bulb is the same as other Shelly devices, so
this problem also afects them. Therefore, it is possible to send many packets that overload the
device’s electronic components to make it useless.</p>
        <p>To confirm the obtained results in the brokers, we performed on the device the same set of
experiments previously carried out on both brokers and clients. For example, the experiment
“Publish QoS 2 and 1" (discussed in Section 4.1) has confirmed the expected results. In this case,
we sent a “turn on packet” with QoS 2 and then we sent a “turn of packet” with QoS 1. When
Mosquitto was the broker used, the light bulb turned on but then did not go of, while in all
other cases, the light bulb turned on and then turned of.</p>
        <p>In addition to these experiments already performed for the various brokers, we have tried
to generate some bufer overflows , through the payload sent to the device, with a consequent
DoS. However, the light bulb passed all tests without errors; in particular, the device ignores
any form of payload other than what it expects to receive.</p>
      </sec>
      <sec id="sec-4-4">
        <title>4.4. Discussion</title>
        <p>
          Interesting results have been obtained from the experiments carried out on brokers, clients,
and the physical device. In [
          <xref ref-type="bibr" rid="ref5">5</xref>
          ] Kant et al. shown that many consumer-grade devices do not
use a secure transport for MQTT (like TLS); this is due to the few resources on-board (in turn,
this is caused by the target price of these devices in the consumer market, which is very low).
Sometimes these devices lack proper authentication protocols, again due to missing resources
or insecure default configurations. These security issues could lead attackers to control devices
(e.g. they could control an entire home environment remotely) directly in some cases (e.g. with
Man-in-the-Middle attacks).
        </p>
        <p>
          In our work, the model of the attacker includes the capability to modify the MQTT packet
lfow, delaying the transmission or making it out of order, or modifying MQTT packets payload,
injecting invalid values. This capability can be exploited with limited access to the broker or
intermediate network devices, or even remotely, by using other attacks like Distributed
Denial-ofService or flooding against a network device in the path of the packet flow (for delaying packets,
for example). Some of these vulnerabilities can be exploited with an older version of TLS
protocol itself11: for example, SSL used a vulnerable Message Authentication Code until TLS [
          <xref ref-type="bibr" rid="ref24">24</xref>
          ];
vulnerabilities in TLS HMAC implementations are still found years after the standard [
          <xref ref-type="bibr" rid="ref25">25</xref>
          ].
        </p>
        <p>We described bad behaviours for brokers in Section 4.1.1. Some of them can be classified as
vulnerabilities, and they can lead to attacks if some conditions happen. In fact, we saw that
brokers publish some messages violating the protocol state machine in some tests. An example
of this is the out-of-order Aedes (and other brokers) use of pubcomp, which might be used to
trigger a replay attack if the pubcomp itself is delayed or dropped by a malicious actor. This
attack can disrupt or even damage some devices: for example, IoT-mechanical devices can be
continuously triggered until the mechanical part is over-stressed.</p>
        <p>11Note that low-cost IoT devices often implement old protocols, sometimes even partially</p>
        <p>Another violation of the standard which leads to a vulnerability (in all brokers but Mosquitto)
is the bad handling of long topics: in the MQTT standard, the maximum length topic is 65536
bytes. However, trying to publish to a very long topic (&gt;4096 bytes) leads to a disconnection of
the client. A malicious actor that can inject (even indirectly, think user-provided information)
some characters in the topic may cause a Denial of Service for that client. Even worst, in
Aedes there is a crash of the broker itself, leading to a Denial of Service for the entire
MQTT network.</p>
        <p>Some violations of the standard are so misinterpreted that each broker does a diferent thing:
in Double publish QoS 2 test, nearly all brokers (the only exception is Mosquitto) violates the
"unique identifier" feature of MQTT in diferent ways. This causes no direct impact as a violation,
but it can be exploited if some client library shows some bad handling of this situation.</p>
        <p>Among all brokers, our tests show that Mosquitto seems to be the strongest one in terms of
MQTT standard adoption, and so the safest from a security point of view.</p>
        <p>Instead, client libraries have shown only minor issues, many of them relating to encoding
errors or long topic subscription issues. Our tests show that they are quite robust, sometimes
even better than some brokers.</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>5. Conclusions</title>
      <p>MQTT is considered one of the enabling technologies for the IoT ecosystem. It is adopted
by almost all IoT applications that run on devices with limited computational power, thanks
to the high availability of open source libraries implementing MQTT. In this paper, we have
presented an empirical study of the most popular implementations of both brokers and clients,
considering the possible behaviour deviations from the standard that could lead applications
to possibly inconsistent or even critical states. We also tested a physical smart-home device.
The results of our experiments were noticeable: while almost all the considered libraries are
correctly handling most of the interactions, as expected, some anomalies have been detected
that could be exploited and target the applications, mainly exposing them to denial of service
attacks.</p>
      <p>Given the promising results, we plan to expand the number of considered libraries further and
to include in our experiments some real applications to create some proof-of-concept attacks
that exploit the found anomalies. Similarly, we plan to extend the experiments also considering
the libraries that also support the new version of the MQTT protocol, namely version 5.</p>
    </sec>
    <sec id="sec-6">
      <title>Acknowledgments</title>
      <p>This research has been partially supported by MIUR (Italian Ministry of Education, University,
and Research) under grant “Dipartimenti di eccellenza 2018-2022” of the Computer Science
Department of Sapienza University of Rome.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>N.</given-names>
            <surname>Naik</surname>
          </string-name>
          ,
          <article-title>Choice of efective messaging protocols for iot systems: Mqtt, coap, amqp and http</article-title>
          ,
          <source>in: 2017 IEEE International Systems Engineering Symposium (ISSE)</source>
          ,
          <year>2017</year>
          , pp.
          <fpage>1</fpage>
          -
          <lpage>7</lpage>
          . doi:
          <volume>10</volume>
          .1109/SysEng.
          <year>2017</year>
          .
          <volume>8088251</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>J. E.</given-names>
            <surname>Luzuriaga</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Perez</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Boronat</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. C.</given-names>
            <surname>Cano</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Calafate</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Manzoni</surname>
          </string-name>
          ,
          <article-title>A comparative evaluation of amqp and mqtt protocols over unstable and mobile networks</article-title>
          ,
          <source>in: 2015 12th Annual IEEE Consumer Communications and Networking Conference (CCNC)</source>
          ,
          <year>2015</year>
          , pp.
          <fpage>931</fpage>
          -
          <lpage>936</lpage>
          . doi:
          <volume>10</volume>
          .1109/CCNC.
          <year>2015</year>
          .
          <volume>7158101</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <surname>ISO</surname>
          </string-name>
          , ISO/IEC 20922:2016 Information technology - Message
          <source>Queuing Telemetry Transport (MQTT) v3.1.1</source>
          ,
          <year>2016</year>
          . URL: https://www.iso.org/standard/69466.html.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4] MQTT.org, Who invented
          <string-name>
            <surname>MQTT</surname>
          </string-name>
          ,
          <year>2021</year>
          . https://mqtt.org/faq/, last accessed:
          <volume>28</volume>
          /02/
          <year>2021</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>D.</given-names>
            <surname>Kant</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Johannsen</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Creutzburg</surname>
          </string-name>
          ,
          <article-title>Analysis of IoT Security Risks based on the exposure of the MQTT Protocol</article-title>
          ,
          <source>Technical Report, Technische Hochschule Brandenburg</source>
          ,
          <year>2021</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>P.</given-names>
            <surname>Colombo</surname>
          </string-name>
          , E. Ferrari,
          <article-title>Access Control Enforcement within MQTT-Based Internet of Things Ecosystems</article-title>
          ,
          <source>in: Proceedings of the 23nd ACM on Symposium on Access Control Models and Technologies</source>
          , SACMAT '18,
          <string-name>
            <surname>Association</surname>
          </string-name>
          for Computing Machinery, New York, NY, USA,
          <year>2018</year>
          , p.
          <fpage>223</fpage>
          -
          <lpage>234</lpage>
          . URL: https://doi.org/10.1145/3205977.3205986. doi:
          <volume>10</volume>
          .1145/ 3205977.3205986.
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <surname>Dinculeană</surname>
          </string-name>
          , Dan and Cheng, Xiaochun,
          <source>Vulnerabilities and Limitations of MQTT Protocol Used between IoT Devices</source>
          ,
          <source>Applied Sciences</source>
          <volume>9</volume>
          (
          <year>2019</year>
          ). URL: https://www.mdpi.com/ 2076-3417/9/5/848. doi:
          <volume>10</volume>
          .3390/app9050848.
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>A.</given-names>
            <surname>Francillon</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Q.</given-names>
            <surname>Nguyen</surname>
          </string-name>
          ,
          <string-name>
            <surname>K. B. Rasmussen</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          <string-name>
            <surname>Tsudik</surname>
          </string-name>
          ,
          <article-title>A minimalist approach to remote attestation</article-title>
          , in: 2014 Design, Automation Test in Europe Conference Exhibition (DATE),
          <source>DATE '14</source>
          ,
          <string-name>
            <surname>Leuven</surname>
            ,
            <given-names>BEL</given-names>
          </string-name>
          ,
          <year>2014</year>
          , pp.
          <fpage>1</fpage>
          -
          <lpage>6</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>J.</given-names>
            <surname>Lin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>W.</given-names>
            <surname>Yu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Zhang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>X.</given-names>
            <surname>Yang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Zhang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>W.</given-names>
            <surname>Zhao</surname>
          </string-name>
          ,
          <article-title>A survey on internet of things: Architecture, enabling technologies, security and privacy, and applications</article-title>
          ,
          <source>IEEE Internet of Things Journal</source>
          <volume>4</volume>
          (
          <year>2017</year>
          )
          <fpage>1125</fpage>
          -
          <lpage>1142</lpage>
          . doi:
          <volume>10</volume>
          .1109/JIOT.
          <year>2017</year>
          .
          <volume>2683200</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>A.</given-names>
            <surname>Al-Fuqaha</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Guizani</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Mohammadi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Aledhari</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Ayyash</surname>
          </string-name>
          ,
          <article-title>Internet of things: A survey on enabling technologies, protocols, and applications</article-title>
          ,
          <source>IEEE Communications Surveys Tutorials</source>
          <volume>17</volume>
          (
          <year>2015</year>
          )
          <fpage>2347</fpage>
          -
          <lpage>2376</lpage>
          . doi:
          <volume>10</volume>
          .1109/COMST.
          <year>2015</year>
          .
          <volume>2444095</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>M. A.</given-names>
            <surname>Razzaque</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Milojevic-Jevric</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Palade</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Clarke</surname>
          </string-name>
          ,
          <article-title>Middleware for internet of things: A survey</article-title>
          ,
          <source>IEEE Internet of Things Journal</source>
          <volume>3</volume>
          (
          <year>2016</year>
          )
          <fpage>70</fpage>
          -
          <lpage>95</lpage>
          . doi:
          <volume>10</volume>
          .1109/JIOT.
          <year>2015</year>
          .
          <volume>2498900</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>A.</given-names>
            <surname>Banks</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Gupta</surname>
          </string-name>
          ,
          <source>MQTT version 3.1.1 plus errata 01</source>
          ,
          <year>2014</year>
          . http://docs.oasis-open.
          <source>org/ mqtt/mqtt/v3.1.1/mqtt-v3.1</source>
          .1.html.
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <surname>Dave</surname>
            <given-names>Locke</given-names>
          </string-name>
          , IBM UK Labs, MQTT Past, Present and Future: 20 Years
          <string-name>
            <surname>of</surname>
            <given-names>MQTT</given-names>
          </string-name>
          ,
          <year>2019</year>
          . https: //info.thingstream.io/hubfs/IBMWatsonMQTT,MQTT-SNpresentation.pdf, last accessed:
          <volume>28</volume>
          /02/
          <year>2021</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <given-names>M.</given-names>
            <surname>Houimli</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Kahloul</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Benaoun</surname>
          </string-name>
          ,
          <article-title>Formal specification, verification and evaluation of the mqtt protocol in the internet of things</article-title>
          , in: 2017
          <source>International Conference on Mathematics and Information Technology (ICMIT)</source>
          ,
          <year>2017</year>
          , pp.
          <fpage>214</fpage>
          -
          <lpage>221</lpage>
          . doi:
          <volume>10</volume>
          .1109/MATHIT.
          <year>2017</year>
          .
          <volume>8259720</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <given-names>K.</given-names>
            <surname>Hofer-Schmitz</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Stojanović</surname>
          </string-name>
          ,
          <article-title>Towards formal methods of iot application layer protocols</article-title>
          ,
          <source>in: 2019 12th CMI Conference on Cybersecurity and Privacy (CMI)</source>
          ,
          <year>2019</year>
          , pp.
          <fpage>1</fpage>
          -
          <lpage>6</lpage>
          . doi:
          <volume>10</volume>
          . 1109/CMI48017.
          <year>2019</year>
          .
          <volume>8962139</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          [16]
          <string-name>
            <given-names>M.</given-names>
            <surname>Collina</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Bartolucci</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Vanelli-Coralli</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G. E.</given-names>
            <surname>Corazza</surname>
          </string-name>
          ,
          <article-title>Internet of things application layer protocol analysis over error and delay prone links</article-title>
          ,
          <source>in: 2014 7th Advanced Satellite Multimedia Systems Conference and the 13th Signal Processing for Space Communications Workshop (ASMS/SPSC)</source>
          ,
          <year>2014</year>
          , pp.
          <fpage>398</fpage>
          -
          <lpage>404</lpage>
          . doi:
          <volume>10</volume>
          .1109/ASMS-SPSC.
          <year>2014</year>
          .
          <volume>6934573</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          [17]
          <string-name>
            <surname>Ferrara</surname>
          </string-name>
          , Pietro and Mandal, Amit Kr and Cortesi, Agostino and Spoto, Fausto,
          <article-title>Static analysis for discovering IoT vulnerabilities</article-title>
          ,
          <source>International Journal on Software Tools for Technology Transfer</source>
          <volume>23</volume>
          (
          <year>2021</year>
          )
          <fpage>71</fpage>
          -
          <lpage>88</lpage>
          . doi:
          <volume>10</volume>
          .1007/s10009-020-00592-x.
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          [18]
          <string-name>
            <given-names>S.</given-names>
            <surname>Hernández Ramos</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M. T.</given-names>
            <surname>Villalba</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Lacuesta</surname>
          </string-name>
          , MQTT Security:
          <article-title>A novel fuzzing approach</article-title>
          ,
          <source>Wireless Communications and Mobile Computing</source>
          <year>2018</year>
          (
          <year>2018</year>
          ). doi:
          <volume>10</volume>
          .1155/
          <year>2018</year>
          /8261746.
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          [19]
          <string-name>
            <given-names>I.</given-names>
            <surname>Vaccari</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Aiello</surname>
          </string-name>
          , E. Cambiaso,
          <article-title>Slowite, a novel denial of service attack afecting mqtt</article-title>
          ,
          <source>Sensors</source>
          (Basel, Switzerland)
          <volume>20</volume>
          (
          <year>2020</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          [20]
          <string-name>
            <given-names>L. G.</given-names>
            <surname>Araujo Rodriguez</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D. Macêdo</given-names>
            <surname>Batista</surname>
          </string-name>
          ,
          <article-title>Program-aware fuzzing for mqtt applications</article-title>
          ,
          <source>in: Proceedings of the 29th ACM SIGSOFT International Symposium on Software Testing and Analysis</source>
          ,
          <source>ISSTA</source>
          <year>2020</year>
          ,
          <article-title>Association for Computing Machinery</article-title>
          , New York, NY, USA,
          <year>2020</year>
          , p.
          <fpage>582</fpage>
          -
          <lpage>586</lpage>
          . URL: https://doi.org/10.1145/3395363.3402645. doi:
          <volume>10</volume>
          .1145/3395363. 3402645.
        </mixed-citation>
      </ref>
      <ref id="ref21">
        <mixed-citation>
          [21]
          <string-name>
            <given-names>G.</given-names>
            <surname>Casteur</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Aubaret</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Blondeau</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Clouet</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Quemat</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Pical</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Zitouni</surname>
          </string-name>
          ,
          <article-title>Fuzzing attacks for vulnerability discovery within MQTT protocol</article-title>
          ,
          <source>in: 16th International Wireless Communications and Mobile Computing Conference, IWCMC</source>
          <year>2020</year>
          , Limassol, Cyprus, June 15-19,
          <year>2020</year>
          , IEEE,
          <year>2020</year>
          , pp.
          <fpage>420</fpage>
          -
          <lpage>425</lpage>
          . URL: https://doi.org/10.1109/IWCMC48107.
          <year>2020</year>
          .
          <volume>9148320</volume>
          . doi:
          <volume>10</volume>
          .1109/IWCMC48107.
          <year>2020</year>
          .
          <volume>9148320</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref22">
        <mixed-citation>
          [22]
          <string-name>
            <given-names>H.</given-names>
            <surname>Sochor</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Ferrarotti</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Ramler</surname>
          </string-name>
          ,
          <article-title>Automated security test generation for mqtt using attack patterns</article-title>
          ,
          <source>in: Proceedings of the 15th International Conference on Availability, Reliability and Security</source>
          , ARES '20,
          <string-name>
            <surname>Association</surname>
          </string-name>
          for Computing Machinery, New York, NY, USA,
          <year>2020</year>
          , pp.
          <fpage>1</fpage>
          -
          <lpage>9</lpage>
          . URL: https://doi.org/10.1145/3407023.3407078. doi:
          <volume>10</volume>
          .1145/3407023.3407078.
        </mixed-citation>
      </ref>
      <ref id="ref23">
        <mixed-citation>
          [23]
          <string-name>
            <given-names>K.</given-names>
            <surname>Tanabe</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Tanabe</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Hagiya</surname>
          </string-name>
          ,
          <article-title>Model-based testing for mqtt applications</article-title>
          , in: M.
          <string-name>
            <surname>Virvou</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          <string-name>
            <surname>Nakagawa</surname>
          </string-name>
          , L. C. Jain (Eds.),
          <source>Knowledge-Based Software Engineering: 2020</source>
          , Springer International Publishing, Cham,
          <year>2020</year>
          , pp.
          <fpage>47</fpage>
          -
          <lpage>59</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref24">
        <mixed-citation>
          [24]
          <string-name>
            <given-names>T.</given-names>
            <surname>Dierks</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Allen</surname>
          </string-name>
          , et al.,
          <source>The tls protocol version 1</source>
          .0,
          <year>1999</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref25">
        <mixed-citation>
          [25]
          <string-name>
            <surname>MITRE</surname>
          </string-name>
          , CVE-2015-
          <volume>4458</volume>
          ., Available from
          <string-name>
            <given-names>MITRE</given-names>
            ,
            <surname>CVE-ID</surname>
          </string-name>
          <string-name>
            <surname>CVE</surname>
          </string-name>
          -2015-
          <volume>4458</volume>
          .,
          <year>2015</year>
          . URL: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-4458.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>