Skip to content

Lesson 12 of 14 · 15m

MQTT Is a Room With a Microphone

Anonymous brokers, wildcard subscriptions, retained commands, and the ACLs that separate telemetry from control.

MQTT gets described as a telemetry channel, and that framing hides what it actually is: a broker-mediated broadcast bus. Anything that can connect and reach a topic can read it — and publish to it. Sensor readings and the commands that unlock doors ride the same topics. "It's just telemetry" is the wrong model; the commands live there too.

The wire facts

MQTT runs over TCP on 1883 unencrypted and 8883 under TLS, plus WebSocket variants that ride ports 80/443. Brokers are Mosquitto, EMQX, HiveMQ, VerneMQ — Mosquitto dominates the exposed-broker population. Topics are hierarchical strings; # is the multi-level wildcard matching everything, + matches one level. $SYS/# is the broker's own stats tree — client counts, load, uptime — readable even on brokers where data topics are ACL'd, which makes it the recon first stop.

Authentication rides in the CONNECT packet — username, password, client ID — and on 1883 it travels cleartext. On a credentialed broker TLS isn't a bonus layer; it's the only thing between those credentials and anyone on path.

Payloads are unencrypted by the protocol itself — TLS protects transit, not the broker, so the broker sees every message's plaintext. Whatever telemetry reveals (occupancy, door state, machine cycles) sits readable in the broker's memory and to anyone with subscribe rights.

Anonymous brokers are a genre, not an edge case

Mosquitto shipped configs with allow_anonymous true for years — version 2.0 finally flipped the default to deny anonymous non-localhost clients. In 2018, Avast researcher Martin Hron enumerated roughly 49,000 publicly reachable Mosquitto brokers, a large share with no authentication at all: smart-home sensors, industrial telemetry, even device command channels, all world-readable.

The recon costs one command — no scan, no exploit, just a subscribe:

mosquitto_sub -h broker.example -t '#' -v

A wildcard subscription dumps every topic the ACL lets you see — and on an unauthenticated broker, that is every topic. Read access alone leaks device IDs, locations, habits. Write access is the other half:

mosquitto_pub -h broker.example -t 'home/door/lock' -m 'unlock'

If publish is open, the "telemetry channel" is a remote-control channel — and MQTT's + and # wildcards mean one subscription pattern can harvest an entire topic tree instead of guessing topic names one at a time.

Retained messages persist across reboots

MQTT's retained-message flag makes the broker store the last retained payload per topic and deliver it instantly to every new subscriber — it's how devices learn current state on connect, and it's exactly as abusable as it sounds. An attacker who leaves a retained unlock on a command topic gets execution on every reconnect — the command doesn't need to be re-sent. Clearing it requires publishing an empty retained payload:

mosquitto_pub -h broker.example -t 'home/door/lock' -r -n

Analysts miss this because the broker looks empty when the attacker stops publishing — the retained payload is still there.

Persistent sessions are the other quiet trap: clean_session=false makes the broker queue messages and keep subscriptions for a client ID while it's offline. Reconnect with a device's client ID and you inherit its queued commands — one more reason per-device credentials and unpredictable client IDs matter.

What correct looks like

allow_anonymous false
password_file /etc/mosquitto/passwd
acl_file /etc/mosquitto/acl

ACLs grant topic read/topic write per user — the file format is literal lines like topic read sensor/# under each user entry: devices publish to their own telemetry topics and nothing else; command topics are write-restricted to the control plane; $SYS denied to ordinary users; the only public listener is 8883 under TLS. Per-device credentials are the IoT-specific control — a compromised unit reads its own topics, not the fleet's. Shared fleet-wide broker credentials are the MQTT version of one root hash in /etc/shadow.

The audit

Connect anonymously, subscribe #, check $SYS, attempt a publish to a non-critical topic, then verify a retained-payload clear actually clears. Also check which listeners exist at all — 1883 shouldn't be reachable from the internet on a TLS-required deployment. Whatever works unauthenticated is the device's real attack surface, regardless of what the config file claims.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.