MQTT Topic Data Capture and Exfiltration
MQTT message payloads constitute the exfiltration target — credentials embedded in messages, device telemetry, configuration values, and operational data all flow through the broker. This page covers structured capture from specific high-value topics, staging the output, and transferring it off the target network. This is distinct from the broad harvest in the exploitation phase: here the goal is clean, targeted collection of specific data for reporting or further use.
Targeted Topic Capture
Once high-value topics have been identified from the enumeration and exploitation phases, capture them individually:
Capture live traffic from device topics over a defined window:
timeout 300 runs for 5 minutes then exits cleanly. Adjust based on device publish intervals.
Capture with Authentication
If credentials were recovered during the exploitation phase, use them to access ACL-restricted topics:
Authenticated access may unlock topics invisible to anonymous subscribers.
Stage and Compress
Combine capture files and compress for transfer:
Check size before transferring:
Transfer Off the Target Network
If you have a shell on the target machine running the MQTT client, transfer the staged file to your attacker machine:
If running the MQTT client directly from your attacker machine against a reachable broker, the capture files are already local — no transfer needed.
If the broker is only reachable through a pivot, route the mosquitto_sub through proxychains:
Parse JSON Payloads
Many MQTT payloads are JSON. Extract and pretty-print them for analysis:
awk '{$1=""; print $0}' /tmp/mqtt-all-loot.txt | while read payload; do
echo "$payload" | python3 -m json.tool 2>/dev/null
done | tee /tmp/mqtt-parsed.txt
Extract all key-value pairs from JSON payloads:
Clean Up
Remove staging files after transfer:
If you published any test messages during the exploitation phase, clear retained ones:
References
-
Mosquitto — mosquitto_sub man pagemosquitto.org/man/mosquitto_sub-1.html (opens in new tab)
Full flag reference for targeted subscription, timeout handling, and output formatting
-
timeout(1) — Linux man pageman7.org/linux/man-pages/man1/timeout.1.html (opens in new tab)
Run mosquitto_sub for a defined window and exit cleanly
Was this helpful?
Your feedback helps improve this page.