IoT protocols move sensor readings, actuator commands, and device management traffic between constrained devices and the systems that control them. MQTT brokers, CoAP servers, Zigbee and Z-Wave gateways, and LwM2M servers are frequently deployed with no authentication, default credentials, cleartext transport, or overly broad topic and resource permissions. A single exposed broker can let an attacker read every sensor feed, publish forged actuator commands, or enroll rogue devices. This skill covers authorized assessment of those protocols: discovering services, inspecting traffic, testing authentication and authorization, checking encryption, and writing detection guidance. Test only systems you have written permission to test, and never publish actuator commands to devices outside the agreed scope.
Quick Workflow
- Scope the protocols in play from the asset inventory, gateway documentation, and network diagrams before sending any traffic.
- Discover IoT services with a targeted port scan for MQTT, CoAP, and common gateway management ports.
- Capture traffic passively and identify protocol versions, cleartext credentials, and topic or resource structures.
- Test broker and endpoint authentication, including anonymous access, default credentials, and missing TLS.
- Test authorization: subscribe to wildcard topics, publish to restricted topics, and read resources meant for other devices.
- Test device onboarding and management flows, including LwM2M bootstrap and gateway pairing procedures.
- Check encryption in transit and at rest for credentials, keys, and firmware update channels.
- Document findings with packet evidence and write detection rules for each confirmed issue.
1. Discovering IoT services
MQTT normally listens on TCP 1883, or 8883 when TLS is used. CoAP uses UDP 5683, or 5684 with DTLS. Zigbee and Z-Wave gateways usually expose a web or MQTT interface on the LAN rather than the radio protocol itself, so scan the gateway host as well as the devices.
# Targeted scan for common IoT protocol ports
sudo nmap -sV -p 1883,8883,5683,5684,8080,8443,9001 \
-oN iot_ports.txt 192.168.1.0/24
# UDP scan for CoAP (slower, run it against known gateway hosts)
sudo nmap -sU -sV -p 5683,5684 -oN coap_udp.txt 192.168.1.10
# Banner check on a suspected MQTT broker
timeout 5 bash -c 'exec 3<>/dev/tcp/192.168.1.10/1883; echo -e "\x10\x0d\x00\x04MQTT\x04\x02\x00\x3c\x00\x00" >&3; head -c 64 <&3 | xxd' || true
A version banner alone proves little. Confirm the protocol by capturing a real session in Wireshark and checking the dissector output for the protocol name, version, and flags.
2. Testing MQTT authentication and authorization
Anonymous access is the most common MQTT finding. Test it before trying credential guesses, and use only credentials the engagement provides or that are documented defaults the client has approved for testing.
# Anonymous connection test: list topics if the broker allows it
mosquitto_sub -h 192.168.1.10 -p 1883 -t '#' -v -C 20 \
2>&1 | head -40
# Authenticated test with engagement-supplied credentials
mosquitto_sub -h 192.168.1.10 -p 1883 \
-u labuser -P 'lab-password-from-scope' \
-t 'sensors/#' -v -C 20 2>&1 | head -40
# Check whether TLS is offered, and what it actually negotiates
openssl s_client -connect 192.168.1.10:8883 -tls1_2 </dev/null 2>&1 \
| grep -E "Protocol|Cipher|Verify return code" | head -10
If the wildcard subscription returns traffic from topics outside your test device, authorization is broken: the broker is not isolating clients. Record the topic names and a redacted sample, then stop. Do not publish to actuator topics unless the scope explicitly allows a controlled publish test, and restore any value you change.
# Controlled publish test, only where the scope allows it
# Publish a harmless retained-state probe to YOUR test device topic
mosquitto_pub -h 192.168.1.10 -p 1883 \
-u labuser -P 'lab-password-from-scope' \
-t 'lab/test-device/status' -m 'probe' -r
# Confirm what a second client can see from that topic
mosquitto_sub -h 192.168.1.10 -p 1883 \
-u labuser -P 'lab-password-from-scope' \
-t 'lab/test-device/status' -v -C 5
3. Inspecting CoAP traffic
CoAP is a lightweight request and response protocol over UDP, often used by constrained sensors. Without DTLS it carries everything in cleartext, and many deployments skip access control entirely because the devices sit behind a gateway that was assumed to be a boundary.
# Capture CoAP traffic for offline analysis
sudo tshark -i eth0 -f "udp port 5683 or udp port 5684" \
-w coap_capture.pcapng -a duration:120
# List CoAP methods, URIs, and response codes from the capture
tshark -r coap_capture.pcapng -Y coap -T fields \
-e frame.number -e coap.code -e coap.uri_path -e coap.type 2>/dev/null \
| head -40
# Check for cleartext payloads and credentials in the capture
tshark -r coap_capture.pcapng -Y "coap && data" -T fields \
-e data-text-lines 2>/dev/null | head -20
Test a CoAP endpoint with a small client script rather than guessing at packet bytes by hand. Query the standard discovery resource first, then request only resources the scope allows.
# CoAP discovery probe using aiocoap (install it in a venv first)
import asyncio
from aiocoap import Context
async def main():
ctx = await Context.create_client_context()
req = ctx.request_uri("coap://192.168.1.20/.well-known/core")
resp = await req.response
print("discovery status:", resp.code)
print((await resp.payload).decode(errors="replace"))
asyncio.run(main())
If discovery lists actuator resources or credentials with no authentication challenge, that is a finding on its own. Note whether DTLS is offered on port 5684 and whether the plain port still answers the same resources.
4. Reviewing Zigbee and Z-Wave gateways
You cannot assess a Zigbee or Z-Wave radio from a laptop alone, but the gateway is in scope for most engagements and is where the serious flaws usually live: an unauthenticated web panel, an MQTT bridge with no credentials, or a pairing mode that never times out.
# Inventory the gateway: open ports, web panel, MQTT bridge
sudo nmap -sV -p 80,443,1883,8883,8080,8443,9001 \
-oN gateway_scan.txt 192.168.1.5
# Check whether the gateway MQTT bridge allows anonymous clients
mosquitto_sub -h 192.168.1.5 -p 1883 -t '#' -v -C 20 2>&1 | head -30
# Capture gateway traffic while a lab device pairs, then review it
sudo tshark -i eth0 -f "host 192.168.1.5" -w gateway_pairing.pcapng \
-a duration:180
Review the pairing capture for the network key or install code crossing the network in cleartext, and check the gateway settings for a pairing window that stays open indefinitely. Confirm whether removing a device from the gateway revokes its key material, or whether a removed device can still rejoin. Record the gateway firmware version and the pairing procedure exactly as observed.
5. Testing LwM2M device management
LwM2M servers manage fleets of devices: firmware updates, remote configuration, and observation of sensor objects. A server that accepts unauthenticated registrations, or a device that accepts commands from any server, hands fleet control to whoever finds it.
# Scan for LwM2M ports (CoAP based, UDP 5683 and 5684)
sudo nmap -sU -sV -p 5683,5684 -oN lwm2m_scan.txt 192.168.1.0/24
# Capture registration traffic from a lab device booting up
sudo tshark -i eth0 -f "udp port 5683 or udp port 5684" \
-w lwm2m_register.pcapng -a duration:180
# Inspect registrations and server URIs in the capture
tshark -r lwm2m_register.pcapng -Y coap -T fields \
-e frame.number -e coap.code -e coap.uri_path \
-e coap.uri_query 2>/dev/null | head -40
Check three things: whether the device verifies the server identity before accepting write or execute commands, whether bootstrap credentials are per device or shared across the fleet, and whether firmware update URIs are authenticated and integrity checked. A shared bootstrap secret or an unauthenticated update URI is a fleet-wide finding, not a single device bug.
6. Detection guidance for defenders
Every confirmed finding should ship with a detection idea so the defender can find the same behavior in production logs.
# Hunt for anonymous MQTT clients in broker logs
grep -i "anonymous\|unauthenticated" /var/log/mosquitto/mosquitto.log \
| tail -50
# Hunt for wildcard subscriptions, a classic recon signal
grep -E "subscribe.*#|subscribe.*\+" /var/log/mosquitto/mosquitto.log \
| tail -50
# Count CoAP requests per source to spot scanning or enumeration
tshark -r coap_capture.pcapng -Y coap -T fields -e ip.src 2>/dev/null \
| sort | uniq -c | sort -nr | head -20
Useful detections include: anonymous MQTT connections, wildcard subscriptions from unexpected hosts, CoAP requests to actuator resources from outside the gateway subnet, LwM2M registrations from unknown device identities, and gateway pairing events outside change windows. Alert on the first occurrence, not on volume, since a single rogue publish can matter.
Edge cases
- Encrypted brokers hide topic names: when TLS or DTLS is in use, confirm authentication and authorization with a test client instead of relying on passive capture, and verify certificate validation rather than assuming encryption means security.
- Gateways that bridge protocols can mask the real flaw: a secure Zigbee radio means nothing if the gateway MQTT bridge is open, so test every bridge hop, not just the radio link.
- Retained MQTT messages persist: a probe published with the retain flag stays on the broker, so clean up test messages and confirm the topic is empty before closing the engagement.
- Constrained devices may crash under scanning: run UDP scans slowly, against lab devices first, and stop immediately if a device stops responding.
- Shared fleet credentials make single device findings fleet findings: confirm whether a leaked key or password works on other devices before writing the impact statement.
- CoAP over UDP has no connection state: a single captured packet is not proof of an exploitable flow, so confirm with a live request and response before reporting.
- Some gateways rate limit or lock out after failed logins: use the credentials the client supplied, keep attempts low, and coordinate lockout testing with the client in advance.
Key references
- MQTT Version 5.0 specification, OASIS Standard, covering CONNECT authentication, topic authorization, retained messages, and session handling.
- RFC 7252, The Constrained Application Protocol (CoAP), and RFC 9147, Datagram Transport Layer Security for CoAP.
- Zigbee Cluster Library Specification and Zigbee PRO standard, covering network keys, install codes, and trust center policy.
- Z-Wave Plus and Z-Wave Security 2 (S2) specifications, covering inclusion, key exchange, and device authentication classes.
- OMA Lightweight M2M (LwM2M) 1.1 specification, covering device registration, bootstrap, object model, and firmware update.
- OWASP IoT Top 10, for mapping protocol findings to common IoT weakness classes and remediation priorities.
- Mosquitto broker documentation on authentication plugins, access control lists, and TLS listener configuration.
