Detect DNS queries reporting multiple errors from different clients - Anomaly Based (ASIM DNS Solution)
Id | cf687598-5a2c-46f8-81c8-06b15ed489b1 |
Rulename | Detect DNS queries reporting multiple errors from different clients - Anomaly Based (ASIM DNS Solution) |
Description | This rule makes use of the series decompose anomaly method to generate an alert when multiple clients report errors for the same DNS query. This rule monitors DNS traffic over a period of 14 days to detect possible similar C2 communication originating from different clients. \n\nIt utilizes ASIM normalization and is applied to any source that supports the ASIM DNS schema. |
Severity | Medium |
Tactics | CommandAndControl |
Techniques | T1568 T1573 T1008 |
Required data connectors | AIVectraStream ASimDnsActivityLogs AzureFirewall CiscoUmbrellaDataConnector Corelight DNS GCPDNSDataConnector InfobloxNIOS ISCBind NXLogDnsLogs WindowsForwardedEvents Zscaler |
Kind | Scheduled |
Query frequency | 1d |
Query period | 14d |
Trigger threshold | 0 |
Trigger operator | gt |
Source Uri | https://github.com/Azure/Azure-Sentinel/blob/master/Solutions/DNS Essentials/Analytic Rules/MultipleErrorsReportedForSameDNSQueryAnomalyBased.yaml |
Version | 1.0.0 |
Arm template | cf687598-5a2c-46f8-81c8-06b15ed489b1.json |
let threshold = materialize (_GetWatchlist('DNS_Solution_Monitoring_Configuration')
| where wl_RuleName == 'Anomaly - Multiple errors reported for same DNSQuery'
and wl_Type == 'Detection'
| project todouble(wl_AnomalyThreshold));
let min_t = ago(14d);
let max_t = now();
let dt = 1d;
let Errors = dynamic(['NXDOMAIN', 'SERVFAIL', 'REFUSED']);
// calculate avg. eps(events per second)
let eps = materialize (_Im_Dns | project TimeGenerated | where TimeGenerated > ago(5m) | count | extend Count = Count/300);
let maxSummarizedTime = toscalar (
union isfuzzy=true
(
DNS_Summarized_Logs_ip_CL
| where EventTime_t >= min_t
| summarize max_TimeGenerated=max(EventTime_t)
| extend max_TimeGenerated = datetime_add('hour',1,max_TimeGenerated)
),
(
print(min_t)
| project max_TimeGenerated = print_0
)
| summarize maxTimeGenerated = max(max_TimeGenerated)
);
let summarizationexist = materialize(
union isfuzzy=true
(
DNS_Summarized_Logs_ip_CL
| where EventTime_t > ago(1d)
| project v = int(2)
),
(
print int(1)
| project v = print_0
)
| summarize maxv = max(v)
| extend sumexist = (maxv > 1)
);
let allData = union isfuzzy=true
(
(datatable(exists:int, sumexist:bool)[1,false] | where toscalar(eps) > 1000 | join (summarizationexist) on sumexist) | join (
_Im_Dns(starttime=todatetime(ago(2d)), endtime=now())
| where TimeGenerated > maxSummarizedTime and EventResultDetails in (Errors)
| summarize Count=count() by SrcIpAddr, DnsQuery, bin(TimeGenerated,1h)
| extend EventTime = TimeGenerated, Count = toint(Count), exists=int(1)
) on exists
| project-away exists, maxv, sum*
),
(
(datatable(exists:int, sumexist:bool)[1,false] | where toscalar(eps) between (501 .. 1000) | join (summarizationexist) on sumexist) | join (
_Im_Dns(starttime=todatetime(ago(3d)), endtime=now())
| where TimeGenerated > maxSummarizedTime and EventResultDetails in (Errors)
| summarize Count=count() by SrcIpAddr, DnsQuery, bin(TimeGenerated,1h)
| extend EventTime = TimeGenerated, Count = toint(Count), exists=int(1)
) on exists
| project-away exists, maxv, sum*
),
(
(datatable(exists:int, sumexist:bool)[1,false] | where toscalar(eps) <= 500 | join (summarizationexist) on sumexist) | join (
_Im_Dns(starttime=todatetime(ago(4d)), endtime=now())
| where TimeGenerated > maxSummarizedTime and EventResultDetails in (Errors)
| summarize Count=count() by SrcIpAddr, DnsQuery, bin(TimeGenerated,1h)
| extend EventTime = TimeGenerated, Count = toint(Count), exists=int(1)
) on exists
| project-away exists, maxv, sum*
),
(
DNS_Summarized_Logs_ip_CL
| where EventTime_t > min_t and EventResultDetails_s in (Errors)
| project-rename SrcIpAddr=SrcIpAddr_s, DnsQuery=DnsQuery_s, Count=count__d, EventTime=EventTime_t
| extend Count = toint(Count)
);
allData
| make-series TotalIPCount=dcount(SrcIpAddr) on EventTime from min_t to max_t step dt by DnsQuery
| extend (anomalies, score, baseline) = series_decompose_anomalies(TotalIPCount, toscalar(threshold), -1, 'linefit')
| mv-expand anomalies, score, baseline, EventTime, TotalIPCount
| extend
anomalies = toint(anomalies),
score = toint(score),
baseline = toint(baseline),
EventTime = todatetime(EventTime),
TotalIPs = tolong(TotalIPCount)
| where EventTime >= ago(dt)
| where score >= (toscalar(threshold) * 2)
| join kind=inner(allData | where TimeGenerated>ago(dt) | summarize SrcIps = make_set(SrcIpAddr,1000) by DnsQuery) on DnsQuery
| project-away DnsQuery1
queryFrequency: 1d
alertDetailsOverride:
alertDisplayNameFormat: "[Anomaly] Multiple errors for the same DNS query has been detected - '{{DnsQuery}}'"
alertDescriptionFormat: |-
Multiple errors were detected on different clients for the same DNS query. These unsuccessful responses can be an indication of C2 communication.
Baseline for total clients reporting errors for this DNS query: '{{baseline}}'
Current count of clients reporting errors for this DNS query: '{{TotalIPs}}'
Clients requesting this DNS query include:
'{{SrcIps}}'
triggerOperator: gt
tactics:
- CommandAndControl
description: |
'This rule makes use of the series decompose anomaly method to generate an alert when multiple clients report errors for the same DNS query. This rule monitors DNS traffic over a period of 14 days to detect possible similar C2 communication originating from different clients. \n\nIt utilizes [ASIM](https://aka.ms/AboutASIM) normalization and is applied to any source that supports the ASIM DNS schema.'
eventGroupingSettings:
aggregationKind: AlertPerResult
status: Available
relevantTechniques:
- T1568
- T1573
- T1008
name: Detect DNS queries reporting multiple errors from different clients - Anomaly Based (ASIM DNS Solution)
OriginalUri: https://github.com/Azure/Azure-Sentinel/blob/master/Solutions/DNS Essentials/Analytic Rules/MultipleErrorsReportedForSameDNSQueryAnomalyBased.yaml
severity: Medium
triggerThreshold: 0
version: 1.0.0
entityMappings:
- entityType: DNS
fieldMappings:
- identifier: DomainName
columnName: DnsQuery
tags:
- Schema: ASimDns
SchemaVersion: 0.1.6
customDetails:
TotalIPs: TotalIPs
baseline: baseline
SrcIps: SrcIps
AnomalyScore: score
id: cf687598-5a2c-46f8-81c8-06b15ed489b1
requiredDataConnectors:
- connectorId: ASimDnsActivityLogs
dataTypes:
- ASimDnsActivityLogs
- connectorId: GCPDNSDataConnector
dataTypes:
- GCP_DNS_CL
- connectorId: AzureFirewall
dataTypes:
- AzureDiagnostics
- connectorId: CiscoUmbrellaDataConnector
dataTypes:
- Cisco_Umbrella_proxy_CL
- connectorId: Corelight
dataTypes:
- Corelight_CL
- connectorId: InfobloxNIOS
dataTypes:
- Syslog
- connectorId: NXLogDnsLogs
dataTypes:
- NXLog_DNS_Server_CL
- connectorId: DNS
dataTypes:
- DnsEvents
- connectorId: AIVectraStream
dataTypes:
- VectraStream_CL
- connectorId: WindowsForwardedEvents
dataTypes:
- WindowsEvents
- connectorId: Zscaler
dataTypes:
- CommonSecurityLog
- connectorId: ISCBind
dataTypes:
- Syslog
kind: Scheduled
query: |
let threshold = materialize (_GetWatchlist('DNS_Solution_Monitoring_Configuration')
| where wl_RuleName == 'Anomaly - Multiple errors reported for same DNSQuery'
and wl_Type == 'Detection'
| project todouble(wl_AnomalyThreshold));
let min_t = ago(14d);
let max_t = now();
let dt = 1d;
let Errors = dynamic(['NXDOMAIN', 'SERVFAIL', 'REFUSED']);
// calculate avg. eps(events per second)
let eps = materialize (_Im_Dns | project TimeGenerated | where TimeGenerated > ago(5m) | count | extend Count = Count/300);
let maxSummarizedTime = toscalar (
union isfuzzy=true
(
DNS_Summarized_Logs_ip_CL
| where EventTime_t >= min_t
| summarize max_TimeGenerated=max(EventTime_t)
| extend max_TimeGenerated = datetime_add('hour',1,max_TimeGenerated)
),
(
print(min_t)
| project max_TimeGenerated = print_0
)
| summarize maxTimeGenerated = max(max_TimeGenerated)
);
let summarizationexist = materialize(
union isfuzzy=true
(
DNS_Summarized_Logs_ip_CL
| where EventTime_t > ago(1d)
| project v = int(2)
),
(
print int(1)
| project v = print_0
)
| summarize maxv = max(v)
| extend sumexist = (maxv > 1)
);
let allData = union isfuzzy=true
(
(datatable(exists:int, sumexist:bool)[1,false] | where toscalar(eps) > 1000 | join (summarizationexist) on sumexist) | join (
_Im_Dns(starttime=todatetime(ago(2d)), endtime=now())
| where TimeGenerated > maxSummarizedTime and EventResultDetails in (Errors)
| summarize Count=count() by SrcIpAddr, DnsQuery, bin(TimeGenerated,1h)
| extend EventTime = TimeGenerated, Count = toint(Count), exists=int(1)
) on exists
| project-away exists, maxv, sum*
),
(
(datatable(exists:int, sumexist:bool)[1,false] | where toscalar(eps) between (501 .. 1000) | join (summarizationexist) on sumexist) | join (
_Im_Dns(starttime=todatetime(ago(3d)), endtime=now())
| where TimeGenerated > maxSummarizedTime and EventResultDetails in (Errors)
| summarize Count=count() by SrcIpAddr, DnsQuery, bin(TimeGenerated,1h)
| extend EventTime = TimeGenerated, Count = toint(Count), exists=int(1)
) on exists
| project-away exists, maxv, sum*
),
(
(datatable(exists:int, sumexist:bool)[1,false] | where toscalar(eps) <= 500 | join (summarizationexist) on sumexist) | join (
_Im_Dns(starttime=todatetime(ago(4d)), endtime=now())
| where TimeGenerated > maxSummarizedTime and EventResultDetails in (Errors)
| summarize Count=count() by SrcIpAddr, DnsQuery, bin(TimeGenerated,1h)
| extend EventTime = TimeGenerated, Count = toint(Count), exists=int(1)
) on exists
| project-away exists, maxv, sum*
),
(
DNS_Summarized_Logs_ip_CL
| where EventTime_t > min_t and EventResultDetails_s in (Errors)
| project-rename SrcIpAddr=SrcIpAddr_s, DnsQuery=DnsQuery_s, Count=count__d, EventTime=EventTime_t
| extend Count = toint(Count)
);
allData
| make-series TotalIPCount=dcount(SrcIpAddr) on EventTime from min_t to max_t step dt by DnsQuery
| extend (anomalies, score, baseline) = series_decompose_anomalies(TotalIPCount, toscalar(threshold), -1, 'linefit')
| mv-expand anomalies, score, baseline, EventTime, TotalIPCount
| extend
anomalies = toint(anomalies),
score = toint(score),
baseline = toint(baseline),
EventTime = todatetime(EventTime),
TotalIPs = tolong(TotalIPCount)
| where EventTime >= ago(dt)
| where score >= (toscalar(threshold) * 2)
| join kind=inner(allData | where TimeGenerated>ago(dt) | summarize SrcIps = make_set(SrcIpAddr,1000) by DnsQuery) on DnsQuery
| project-away DnsQuery1
queryPeriod: 14d
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspace": {
"type": "String"
}
},
"resources": [
{
"id": "[concat(resourceId('Microsoft.OperationalInsights/workspaces/providers', parameters('workspace'), 'Microsoft.SecurityInsights'),'/alertRules/cf687598-5a2c-46f8-81c8-06b15ed489b1')]",
"name": "[concat(parameters('workspace'),'/Microsoft.SecurityInsights/cf687598-5a2c-46f8-81c8-06b15ed489b1')]",
"type": "Microsoft.OperationalInsights/workspaces/providers/alertRules",
"kind": "Scheduled",
"apiVersion": "2022-11-01",
"properties": {
"displayName": "Detect DNS queries reporting multiple errors from different clients - Anomaly Based (ASIM DNS Solution)",
"description": "'This rule makes use of the series decompose anomaly method to generate an alert when multiple clients report errors for the same DNS query. This rule monitors DNS traffic over a period of 14 days to detect possible similar C2 communication originating from different clients. \\n\\nIt utilizes [ASIM](https://aka.ms/AboutASIM) normalization and is applied to any source that supports the ASIM DNS schema.'\n",
"severity": "Medium",
"enabled": true,
"query": "let threshold = materialize (_GetWatchlist('DNS_Solution_Monitoring_Configuration')\n | where wl_RuleName == 'Anomaly - Multiple errors reported for same DNSQuery'\n and wl_Type == 'Detection'\n | project todouble(wl_AnomalyThreshold));\nlet min_t = ago(14d);\nlet max_t = now();\nlet dt = 1d;\nlet Errors = dynamic(['NXDOMAIN', 'SERVFAIL', 'REFUSED']);\n// calculate avg. eps(events per second)\nlet eps = materialize (_Im_Dns | project TimeGenerated | where TimeGenerated > ago(5m) | count | extend Count = Count/300);\nlet maxSummarizedTime = toscalar (\n union isfuzzy=true \n (\n DNS_Summarized_Logs_ip_CL \n | where EventTime_t >= min_t\n | summarize max_TimeGenerated=max(EventTime_t)\n | extend max_TimeGenerated = datetime_add('hour',1,max_TimeGenerated)\n ),\n (\n print(min_t)\n | project max_TimeGenerated = print_0\n )\n | summarize maxTimeGenerated = max(max_TimeGenerated) \n );\n let summarizationexist = materialize(\n union isfuzzy=true \n (\n DNS_Summarized_Logs_ip_CL\n | where EventTime_t > ago(1d) \n | project v = int(2)\n ),\n (\n print int(1) \n | project v = print_0\n )\n | summarize maxv = max(v)\n | extend sumexist = (maxv > 1)\n );\nlet allData = union isfuzzy=true\n(\n (datatable(exists:int, sumexist:bool)[1,false] | where toscalar(eps) > 1000 | join (summarizationexist) on sumexist) | join (\n _Im_Dns(starttime=todatetime(ago(2d)), endtime=now())\n | where TimeGenerated > maxSummarizedTime and EventResultDetails in (Errors)\n | summarize Count=count() by SrcIpAddr, DnsQuery, bin(TimeGenerated,1h)\n | extend EventTime = TimeGenerated, Count = toint(Count), exists=int(1)\n ) on exists\n | project-away exists, maxv, sum*\n),\n(\n (datatable(exists:int, sumexist:bool)[1,false] | where toscalar(eps) between (501 .. 1000) | join (summarizationexist) on sumexist) | join (\n _Im_Dns(starttime=todatetime(ago(3d)), endtime=now())\n | where TimeGenerated > maxSummarizedTime and EventResultDetails in (Errors)\n | summarize Count=count() by SrcIpAddr, DnsQuery, bin(TimeGenerated,1h)\n | extend EventTime = TimeGenerated, Count = toint(Count), exists=int(1)\n ) on exists\n | project-away exists, maxv, sum*\n),\n(\n (datatable(exists:int, sumexist:bool)[1,false] | where toscalar(eps) <= 500 | join (summarizationexist) on sumexist) | join (\n _Im_Dns(starttime=todatetime(ago(4d)), endtime=now())\n | where TimeGenerated > maxSummarizedTime and EventResultDetails in (Errors)\n | summarize Count=count() by SrcIpAddr, DnsQuery, bin(TimeGenerated,1h)\n | extend EventTime = TimeGenerated, Count = toint(Count), exists=int(1)\n ) on exists\n | project-away exists, maxv, sum*\n),\n(\n DNS_Summarized_Logs_ip_CL\n | where EventTime_t > min_t and EventResultDetails_s in (Errors)\n | project-rename SrcIpAddr=SrcIpAddr_s, DnsQuery=DnsQuery_s, Count=count__d, EventTime=EventTime_t\n | extend Count = toint(Count) \n);\nallData\n| make-series TotalIPCount=dcount(SrcIpAddr) on EventTime from min_t to max_t step dt by DnsQuery\n| extend (anomalies, score, baseline) = series_decompose_anomalies(TotalIPCount, toscalar(threshold), -1, 'linefit')\n| mv-expand anomalies, score, baseline, EventTime, TotalIPCount\n| extend\n anomalies = toint(anomalies),\n score = toint(score),\n baseline = toint(baseline),\n EventTime = todatetime(EventTime),\n TotalIPs = tolong(TotalIPCount)\n| where EventTime >= ago(dt)\n| where score >= (toscalar(threshold) * 2)\n| join kind=inner(allData | where TimeGenerated>ago(dt) | summarize SrcIps = make_set(SrcIpAddr,1000) by DnsQuery) on DnsQuery\n| project-away DnsQuery1\n",
"queryFrequency": "P1D",
"queryPeriod": "P14D",
"triggerOperator": "GreaterThan",
"triggerThreshold": 0,
"suppressionDuration": "PT1H",
"suppressionEnabled": false,
"tactics": [
"CommandAndControl"
],
"techniques": [
"T1568",
"T1573",
"T1008"
],
"alertRuleTemplateName": "cf687598-5a2c-46f8-81c8-06b15ed489b1",
"eventGroupingSettings": {
"aggregationKind": "AlertPerResult"
},
"alertDetailsOverride": {
"alertDisplayNameFormat": "[Anomaly] Multiple errors for the same DNS query has been detected - '{{DnsQuery}}'",
"alertDescriptionFormat": "Multiple errors were detected on different clients for the same DNS query. These unsuccessful responses can be an indication of C2 communication. \n\nBaseline for total clients reporting errors for this DNS query: '{{baseline}}'\n\nCurrent count of clients reporting errors for this DNS query: '{{TotalIPs}}'\n\nClients requesting this DNS query include:\n'{{SrcIps}}'"
},
"customDetails": {
"TotalIPs": "TotalIPs",
"baseline": "baseline",
"SrcIps": "SrcIps",
"AnomalyScore": "score"
},
"entityMappings": [
{
"entityType": "DNS",
"fieldMappings": [
{
"identifier": "DomainName",
"columnName": "DnsQuery"
}
]
}
],
"status": "Available",
"templateVersion": "1.0.0",
"tags": [
{
"Schema": "ASimDns",
"SchemaVersion": "0.1.6"
}
],
"OriginalUri": "https://github.com/Azure/Azure-Sentinel/blob/master/Solutions/DNS Essentials/Analytic Rules/MultipleErrorsReportedForSameDNSQueryAnomalyBased.yaml"
}
}
]
}