Detect Publish/Subscribe Protocols in Splunk
Adversaries may communicate using publish/subscribe (pub/sub) application layer protocols to avoid detection/network filtering by blending in with existing traffic. Commands to the remote system, and often the results of those commands, will be embedded within the protocol traffic between the client and server. Protocols such as MQTT, XMPP, AMQP, and STOMP use a publish/subscribe design, with message distribution managed by a centralized broker. Publishers categorize their messages by topics, while subscribers receive messages according to their subscribed topics. An adversary may abuse publish/subscribe protocols to communicate with systems under their control from behind a message broker while also mimicking normal, expected traffic.
MITRE ATT&CK
- Tactic
- Command and Control
- Technique
- T1071 Application Layer Protocol
- Sub-technique
- T1071.005 Publish/Subscribe Protocols
- Canonical reference
- https://attack.mitre.org/techniques/T1071/005/
SPL Detection Query
index=network OR index=firewall sourcetype IN ("stream:tcp", "pan:traffic", "cisco:asa")
(dest_port IN (1883, 8883, 5222, 5223, 5269, 5672, 5671, 61613, 61614))
action=allowed
| eval Protocol=case(
dest_port IN (1883, 8883), "MQTT",
dest_port IN (5222, 5223, 5269), "XMPP",
dest_port IN (5672, 5671), "AMQP",
dest_port IN (61613, 61614), "STOMP",
1=1, "Unknown")
| eval IsExternal=if(NOT (dest_ip="10.*" OR dest_ip="172.16.*" OR dest_ip="192.168.*" OR dest_ip="127.*"), "yes", "no")
| stats count as ConnectionCount, sum(bytes_out) as BytesSent, sum(bytes_in) as BytesReceived, earliest(_time) as FirstSeen, latest(_time) as LastSeen, values(src_user) as Users by src_ip, dest_ip, dest_port, Protocol, IsExternal, process_name
| where ConnectionCount > 1
| eval Suspicion=case(
IsExternal="yes" AND Protocol IN ("XMPP", "STOMP"), "high",
IsExternal="yes" AND Protocol="MQTT" AND NOT match(process_name, "(?i)mosquitto"), "high",
IsExternal="yes" AND Protocol="AMQP", "medium",
IsExternal="no" AND Protocol IN ("XMPP", "STOMP"), "medium",
1=1, "low")
| where Suspicion IN ("high", "medium")
| table FirstSeen, LastSeen, src_ip, dest_ip, Protocol, dest_port, IsExternal, process_name, Users, ConnectionCount, BytesSent, BytesReceived, Suspicion
| sort Suspicion, - ConnectionCount Detects connections to pub/sub messaging protocol ports from network and firewall logs. Assigns suspicion levels based on protocol, direction (internal/external), and process name. XMPP to external servers from non-chat-client processes is flagged as high suspicion — APT1's GLOOXMAIL communicated via Google's XMPP servers. MQTT from non-IoT processes to external brokers indicates potential WailingCrab-style C2.
Data Sources
Required Sourcetypes
False Positives & Tuning
- IoT platforms and home automation systems that legitimately use MQTT for device communication (Home Assistant, AWS IoT Core)
- Chat and messaging applications using XMPP (Pidgin, Conversations, Cisco Jabber)
- Message queue infrastructure (RabbitMQ, ActiveMQ, Apache Kafka) used for application integration
- Development and testing environments with MQTT brokers for IoT prototyping
Other platforms for T1071.005
Testing Methodology
Validate this detection against 3 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.
- Test 1MQTT C2 Publish Simulation
Expected signal: Sysmon for Linux Event ID 3: Network connection from mosquitto_pub to 127.0.0.1:1883. Process creation event for mosquitto_pub with topic name 'c2/beacon' and system data in the message payload.
- Test 2XMPP C2 Connection Simulation
Expected signal: Sysmon for Linux Event ID 3: Network connection from nc to 127.0.0.1:5222. Process creation event for nc with XMPP XML stanza in piped input.
- Test 3MQTT Subscribe for Commands Simulation
Expected signal: Sysmon for Linux Event ID 3: Network connection from mosquitto_sub to 127.0.0.1:1883. Long-lived connection (up to 10 seconds) as the client waits for messages on the 'c2/commands/#' wildcard topic.
References (6)
- https://attack.mitre.org/techniques/T1071/005/
- https://securityintelligence.com/x-force/wailingcrab-malware-misues-mqtt-messaging-protocol/
- https://www.mandiant.com/sites/default/files/2021-09/mandiant-apt1-report.pdf
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1071.005/T1071.005.md
- https://mqtt.org/
- https://xmpp.org/
Unlock Pro Content
Get the full detection package for T1071.005 including response playbook, investigation guide, and atomic red team tests.