T1071.005 Microsoft Sentinel · KQL

Detect Publish/Subscribe Protocols in Microsoft Sentinel

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/

KQL Detection Query

Microsoft Sentinel (KQL)
kusto
let TimeWindow = 24h;
let PubSubPorts = dynamic([1883, 8883, 5222, 5223, 5269, 5672, 5671, 61613, 61614]);
// Detect connections to pub/sub protocol ports
DeviceNetworkEvents
| where Timestamp > ago(TimeWindow)
| where RemotePort in (PubSubPorts)
| where ActionType == "ConnectionSuccess"
| extend Protocol = case(
    RemotePort in (1883, 8883), "MQTT",
    RemotePort in (5222, 5223, 5269), "XMPP",
    RemotePort in (5672, 5671), "AMQP",
    RemotePort in (61613, 61614), "STOMP",
    "Unknown")
| extend IsExternal = RemoteIPType == "Public"
| summarize
    ConnectionCount = count(),
    BytesSent = sum(SentBytes),
    BytesReceived = sum(ReceivedBytes),
    FirstSeen = min(Timestamp),
    LastSeen = max(Timestamp)
    by DeviceName, InitiatingProcessFileName, RemoteIP, RemotePort, Protocol, IsExternal, AccountName
| where ConnectionCount > 1
| extend Suspicion = case(
    IsExternal and Protocol in ("XMPP", "STOMP"), "high",
    IsExternal and Protocol == "MQTT" and InitiatingProcessFileName !in~ ("mosquitto_pub", "mosquitto_sub", "mosquitto"), "high",
    IsExternal and Protocol == "AMQP", "medium",
    not(IsExternal) and Protocol in ("XMPP", "STOMP"), "medium",
    "low")
| where Suspicion in ("high", "medium")
| project LastSeen, DeviceName, AccountName, InitiatingProcessFileName, RemoteIP, Protocol, RemotePort, IsExternal, ConnectionCount, BytesSent, BytesReceived, Suspicion
| sort by Suspicion asc, ConnectionCount desc
high severity medium confidence

Detects connections to publish/subscribe protocol ports (MQTT 1883/8883, XMPP 5222/5223/5269, AMQP 5672/5671, STOMP 61613/61614). These messaging protocols are increasingly abused for C2 — WailingCrab malware uses MQTT, and APT1's GLOOXMAIL uses XMPP (Jabber) via Google servers. External connections to XMPP and STOMP ports from non-standard processes are high-confidence C2 indicators. Filters by process name to reduce false positives from legitimate IoT/messaging applications.

Data Sources

Network Traffic: Network Connection CreationNetwork Traffic: Network Traffic FlowMicrosoft Defender for Endpoint

Required Tables

DeviceNetworkEvents

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
Download portable Sigma rule (.yml)

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.

  1. 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.

  2. 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.

  3. 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.

Unlock Pro Content

Get the full detection package for T1071.005 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections