Query Details

Rule : New External FQDNs Contacted by Workload

C2 New External Destinations

Query

let baseline=14d;
let recent=1d;
let older=DeviceNetworkEvents
| where Timestamp between (ago(baseline)..ago(recent))
| where isnotempty(RemoteUrl) and RemoteIPType == "Public"
| summarize by DeviceId, RemoteUrl;
DeviceNetworkEvents
| where Timestamp > ago(recent)
| where isnotempty(RemoteUrl) and RemoteIPType == "Public"
| join kind=leftanti older on DeviceId, RemoteUrl
| summarize Connections=count(), NewDomains=dcount(RemoteUrl), DomainExamples=make_set(RemoteUrl,15), Processes=make_set(InitiatingProcessFileName,8) by DeviceId, DeviceName, InitiatingProcessAccountName, bin(Timestamp,1h)
| where NewDomains >= 5
| order by NewDomains desc

About this query

Explanation

This query is designed to identify devices that suddenly start communicating with five or more new external domains that they haven't contacted in the past 14 days. This behavior could indicate a compromised device reaching out to new malicious infrastructure.

Here's a simple breakdown of how the query works:

  1. Baseline Creation: It first creates a 14-day baseline of device and domain pairs from network events, focusing only on public IPs.

  2. Recent Activity Check: It then looks at the last 24 hours of network activity to find any new domains contacted by each device that weren't in the 14-day baseline.

  3. Alert Criteria: If a device contacts five or more new domains within a one-hour period, it triggers an alert.

  4. Data Output: The query provides a count of new domains, examples of these domains, and the processes that initiated the connections for each device.

  5. False Positives: The query accounts for potential false positives, such as software updates or new machines, and suggests focusing on specific device groups for more accurate results.

  6. Triage Steps: It recommends reviewing the new domains for signs of malicious activity and checking the processes that initiated the connections.

Overall, this query helps detect unusual network behavior that could indicate a security threat, allowing for further investigation and response.