-
Notifications
You must be signed in to change notification settings - Fork 322
/
data_q_meta_fail.yaml
212 lines (212 loc) · 7.65 KB
/
data_q_meta_fail.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
metadata:
version: 1
description: Kql Sentinel Alert Queries
data_environments: [LogAnalytics]
tags: ['alert', 'securityalert']
defaults:
metadata:
data_source: 'security_alert'
parameters:
table:
description: Table name
type: str
default: 'SecurityAlert'
query_project:
description: Column project statement
type: str
default: '
| project-rename StartTimeUtc = StartTime, EndTimeUtc = EndTime,
AlertDisplayName = DisplayName, Severity = AlertSeverity
| extend AlertType = iif(isempty(AlertType), AlertName, AlertType)'
start:
description: Query start time
type: datetime
end:
description: Query end time
type: datetime
add_query_items:
description: Additional query clauses
type: str
default: ''
subscription_filter:
description: Optional subscription/tenant filter expression
type: str
default: 'true'
path_separator:
description: Path separator
type: str
default: '\\'
sources:
list_alerts:
description: Retrieves list of alerts
metadata:
args:
query: '
{table}
{query_project}
| where {subscription_filter}
| where TimeGenerated >= datetime({start})
| where TimeGenerated <= datetime({end})
| extend extendedProps = parse_json(ExtendedProperties)
| extend CompromisedEntity = tostring(extendedProps["Compromised Host"])
| project-away extendedProps
{add_query_items}'
uri: None
parameters:
list_alerts_counts:
description: Retrieves summary count of alerts by type
metadata:
args:
query: '
{table}
{query_project}
| where {subscription_filter}
| where TimeGenerated >= datetime({start})
| where TimeGenerated <= datetime({end})
| summarize alertCount=count(), firstAlert=min(TimeGenerated),
lastAlert=max(TimeGenerated) by AlertName
| order by alertCount desc
{add_query_items}'
parameters:
get_alert:
description: Retrieves a single alert by SystemAlertId
metadata:
args:
query: '
{table}
{query_project}
| where {subscription_filter}
| extend extendedProps = parse_json(ExtendedProperties)
| extend CompromisedEntity = tostring(extendedProps["Compromised Host"])
| project-away extendedProps
| where SystemAlertId == "{system_alert_id}"
{add_query_items}'
parameters:
system_alert_id:
description: 'The ID of the alert'
type: str
start:
description: Query start time
type: datetime
default: 0 # fake default to prevent this being viewed as required
end:
description: Query end time
type: datetime
default: 0 # fake default to prevent this being viewed as required
list_related_alerts:
description: Retrieves list of alerts with a common host, acount or process
metadata:
args:
query: '
let src_host = "{host_name}";
let src_acct = "{account_name}";
let src_proc = "{process_name}";
{table}
{query_project}
| where {subscription_filter}
| where TimeGenerated >= datetime({start})
| where TimeGenerated <= datetime({end})
| extend Computer = src_host
| extend src_hostname = tostring(split(src_host, ".")[0])
| extend src_accountname = iif(src_acct contains "\\\\",
tostring(split(src_acct, "\\\\")[-1]),
tostring(split(src_acct, "@")[0]))
| extend src_procname = tostring(split(src_proc, "{path_separator}")[-1])
| extend host_match = iif(isnotempty(src_host) and
(Entities has src_hostname or Entities has src_host
or ExtendedProperties has src_hostname
or ExtendedProperties has src_host), true, false)
| extend acct_match = iif(isnotempty(src_acct)
and (Entities has src_accountname or Entities has src_acct
or ExtendedProperties has src_accountname
or ExtendedProperties has src_acct), true, false)
| extend proc_match = iif(isnotempty(src_acct)
and (Entities has src_procname or Entities has src_proc
or ExtendedProperties has src_procname
or ExtendedProperties has src_proc), true, false)
| where host_match or acct_match or proc_match
{add_query_items}'
parameters:
host_name:
description: The hostname to find
type: str
account_name:
description: The account name to find
type: str
default: ''
process_name:
description: The process name to find
type: str
default: ''
list_alerts_for_ip:
description: Retrieves list of alerts with a common IP Address
metadata:
args:
query: '
let src_ips = "{source_ip_list}";
let src_ips_arr = split(src_ips, ",");
let IP_table = toscalar(range idx from 0 to array_length(src_ips_arr) - 1 step 1
| extend ip = trim(@"\\s*", tostring(src_ips_arr[idx]))
| project ip
| distinct ip
| summarize makeset(ip) );
let ip_extract = materialize(
{table}
{query_project}
| where TimeGenerated >= datetime({start})
| where TimeGenerated <= datetime({end})
| project SystemAlertId, ExtendedProperties, Entities
| extend source_ips_str =
extract("\\"Source IPs\\": \\"([^\\"]+)\\"", 1, ExtendedProperties)
| extend source_ips_1 =
iif(isnotempty(source_ips_str), split(source_ips_str, ","), dynamic([]))
| extend source_ips_2 =
extract_all("\\"Address\\": \\"([^\\"]+)\\"", dynamic([1]), Entities)
| mvexpand alert_ip_1 =
source_ips_1 to typeof(string), alert_ip_2 = source_ips_2 to typeof(string)
| where isnotempty(alert_ip_1) or isnotempty(alert_ip_2)
| where alert_ip_1 in (IP_table) or alert_ip_2 in (IP_table)
| extend matching_ips = case(isnotempty(alert_ip_1) and isnotempty(alert_ip_2),
strcat(alert_ip_1, ",", alert_ip_2),
isnotempty(alert_ip_1), alert_ip_1,
isnotempty(alert_ip_2), alert_ip_2,
"")
| extend MatchingIps = split(matching_ips, ",")
| project-away source_ips_str, source_ips_1, source_ips_2,
alert_ip_1, alert_ip_2, matching_ips
);
{table}
{query_project}
| where TimeGenerated >= datetime({start})
| where TimeGenerated <= datetime({end})
| join (ip_extract) on SystemAlertId
{add_query_items}'
parameters:
table:
description: Table name
type: str
default: 'SecurityAlert'
query_project:
description: Column project statement
type: str
default: '
| project-rename StartTimeUtc = StartTime, EndTimeUtc = EndTime,
AlertDisplayName = DisplayName, Severity = AlertSeverity
| extend AlertType = iif(isempty(AlertType), AlertName, AlertType)'
start:
description: Query start time
type: datetime
end:
description: Query end time
type: datetime
path_separator:
description: Path separator
type: str
default: '\\'
add_query_items:
description: Additional query clauses
type: str
default: ''
source_ip_list:
description: List of one or more IPs to match
type: str