-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsentinel-generic-rule-ioc-kusto.kql
285 lines (285 loc) · 10.1 KB
/
sentinel-generic-rule-ioc-kusto.kql
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
let iocs = externaldata(DateAdded: string, IoC: string, Type: string, TLP: string) [@"https://raw.githubusercontent.com/intelequia/Security.IOCs/main/Revive_IoCs.csv"] with (format="csv", ignoreFirstRecord=True);
let IPList = (iocs | where Type =~ "ip" | project IoC);
let sha256Hashes = (iocs | where Type == "sha256" | project IoC);
let FilePaths = (iocs | where Type =~ "FilePath" | project IoC);
let POST_URI = (iocs | where Type =~ "URI1" | project IoC);
let GET_URI = (iocs | where Type =~ "URI2" | project IoC);
(union isfuzzy=true
(CommonSecurityLog
| where isnotempty(SourceIP) or isnotempty(DestinationIP)
| where SourceIP in (IPList) or DestinationIP in (IPList) or Message has_any (IPList) or FileHash in (sha256Hashes)
| extend IPMatch = case(SourceIP has_any (IPList), "SourceIP", DestinationIP has_any (IPList), "DestinationIP", "Message")
| summarize StartTimeUtc = min(TimeGenerated), EndTimeUtc = max(TimeGenerated)
by
SourceIP,
DestinationIP,
DeviceProduct,
DeviceAction,
Message,
Protocol,
SourcePort,
DestinationPort,
DeviceAddress,
DeviceName,
IPMatch
| extend
timestamp = StartTimeUtc,
IPCustomEntity = case(IPMatch == "SourceIP", SourceIP, IPMatch == "DestinationIP", DestinationIP, "IP in Message Field")
),
(OfficeActivity
| extend SourceIPAddress = ClientIP, Account = UserId
| where SourceIPAddress has_any (IPList)
| extend
timestamp = TimeGenerated,
IPCustomEntity = SourceIPAddress,
AccountCustomEntity = Account
),
(_Im_Dns
| where DstIPAddr has_any (IPList) or SrcIpAddr has_any (IPList)
| extend DestinationIPAddress = ResponseName, Host = SrcIpAddr
| extend
timestamp = TimeGenerated,
IPCustomEntity = DestinationIPAddress,
HostCustomEntity = Host
),
(_Im_NetworkSession
| where DstIPAddr has_any (IPList) or SrcIpAddr has_any (IPList)
| extend
timestamp = TimeGenerated,
IPCustomEntity = SrcIpAddr,
HostCustomEntity = Hostname,
AccountCustomEntity=User
),
(_Im_NetworkSession
| where DstIPAddr has_any (IPList) or SrcIpAddr has_any (IPList)
| extend
timestamp = TimeGenerated,
IPCustomEntity = DstIpAddr,
HostCustomEntity = Hostname,
AccountCustomEntity = User
),
(WireData
| where isnotempty(RemoteIP)
| where RemoteIP has_any (IPList)
| extend
timestamp = TimeGenerated,
IPCustomEntity = RemoteIP,
HostCustomEntity = Computer
),
(SigninLogs
| where isnotempty(IPAddress)
| where IPAddress has_any (IPList)
| extend
timestamp = TimeGenerated,
AccountCustomEntity = UserPrincipalName,
IPCustomEntity = IPAddress
),
(AADNonInteractiveUserSignInLogs
| where isnotempty(IPAddress)
| where IPAddress has_any (IPList)
| extend
timestamp = TimeGenerated,
AccountCustomEntity = UserPrincipalName,
IPCustomEntity = IPAddress
),
(W3CIISLog
| where isnotempty(cIP)
| where cIP has_any (IPList) or (csMethod == 'GET' and csUriStem has_any (GET_URI)) or (csMethod == 'POST' and csUriStem has_any (POST_URI))
| extend
timestamp = TimeGenerated,
IPCustomEntity = cIP,
HostCustomEntity = Computer,
AccountCustomEntity = csUserName
),
(AzureActivity
| where isnotempty(CallerIpAddress)
| where CallerIpAddress has_any (IPList)
| extend
timestamp = TimeGenerated,
IPCustomEntity = CallerIpAddress,
AccountCustomEntity = Caller
),
(
DeviceNetworkEvents
| where isnotempty(RemoteIP)
| where RemoteIP has_any (IPList) or InitiatingProcessSHA256 has_any (sha256Hashes) or InitiatingProcessFolderPath has_any (FilePaths)
| extend
timestamp = TimeGenerated,
IPCustomEntity = RemoteIP,
HostCustomEntity = DeviceName
),
(
AzureDiagnostics
| where ResourceType == "AZUREFIREWALLS"
| where Category == "AzureFirewallApplicationRule"
| parse msg_s with Protocol 'request from ' SourceHost ':' SourcePort 'to ' DestinationHost ':' DestinationPort '. Action:' Action
| where isnotempty(DestinationHost)
| where DestinationHost has_any (IPList)
| extend DestinationIP = DestinationHost
| extend IPCustomEntity = SourceHost
),
(
AzureDiagnostics
| where ResourceType == "AZUREFIREWALLS"
| where Category == "AzureFirewallNetworkRule"
| parse msg_s with Protocol 'request from ' SourceHost ':' SourcePort 'to ' DestinationHost ':' DestinationPort '. Action:' Action
| where isnotempty(DestinationHost)
| where DestinationHost has_any (IPList)
| extend DestinationIP = DestinationHost
| extend IPCustomEntity = SourceHost
),
(Event
| where Source == "Microsoft-Windows-Sysmon" and EventID == '7'
| extend EvData = parse_xml(EventData)
| extend EventDetail = EvData.DataItem.EventData.Data
| extend ImageLoaded = EventDetail.[5].["#text"], Hashes = EventDetail.[11].["#text"]
| parse Hashes with * 'SHA256=' SHA256 '",' *
| where ImageLoaded has_any (FilePaths) or SHA256 has_any (sha256Hashes)
| project
TimeGenerated,
EventDetail,
UserName,
Computer,
Type,
Source,
SHA256,
ImageLoaded,
EventID
| extend
Type = strcat(Type, ":", EventID, ": ", Source),
Account = UserName,
FileHash = SHA256,
Image = EventDetail.[4].["#text"]
| extend
timestamp = TimeGenerated,
HostCustomEntity = Computer,
AccountCustomEntity = Account,
ProcessCustomEntity = tostring(split(Image, '\\', -1)[-1]),
AlgorithmCustomEntity = "SHA256",
FileHashCustomEntity = FileHash
),
(DeviceEvents
| extend FilePath = strcat(FolderPath, '\\', FileName)
| where InitiatingProcessSHA256 has_any (sha256Hashes) or FilePath has_any (FilePaths)
| project
TimeGenerated,
ActionType,
DeviceId,
DeviceName,
InitiatingProcessAccountDomain,
InitiatingProcessAccountName,
InitiatingProcessCommandLine,
InitiatingProcessFolderPath,
InitiatingProcessId,
InitiatingProcessParentFileName,
InitiatingProcessFileName,
InitiatingProcessSHA256,
Type
| extend
Account = InitiatingProcessAccountName,
Computer = DeviceName,
CommandLine = InitiatingProcessCommandLine,
FileHash = InitiatingProcessSHA256,
Image = InitiatingProcessFolderPath
| extend
timestamp = TimeGenerated,
HostCustomEntity = Computer,
AccountCustomEntity = Account,
ProcessCustomEntity = InitiatingProcessFileName,
AlgorithmCustomEntity = "SHA256",
FileHashCustomEntity = FileHash
),
(DeviceFileEvents
| where FolderPath has_any (FilePaths) or SHA256 has_any (sha256Hashes)
| project
TimeGenerated,
ActionType,
DeviceId,
DeviceName,
InitiatingProcessAccountDomain,
InitiatingProcessAccountName,
InitiatingProcessCommandLine,
InitiatingProcessFolderPath,
InitiatingProcessId,
InitiatingProcessParentFileName,
InitiatingProcessFileName,
InitiatingProcessSHA256,
Type
| extend
Account = InitiatingProcessAccountName,
Computer = DeviceName,
CommandLine = InitiatingProcessCommandLine,
FileHash = InitiatingProcessSHA256,
Image = InitiatingProcessFolderPath
| extend
timestamp = TimeGenerated,
HostCustomEntity = Computer,
AccountCustomEntity = Account,
ProcessCustomEntity = InitiatingProcessFileName,
AlgorithmCustomEntity = "SHA256",
FileHashCustomEntity = FileHash
),
(DeviceImageLoadEvents
| where FolderPath has_any (FilePaths) or SHA256 has_any (sha256Hashes)
| project
TimeGenerated,
ActionType,
DeviceId,
DeviceName,
InitiatingProcessAccountDomain,
InitiatingProcessAccountName,
InitiatingProcessCommandLine,
InitiatingProcessFolderPath,
InitiatingProcessId,
InitiatingProcessParentFileName,
InitiatingProcessFileName,
InitiatingProcessSHA256,
Type
| extend
Account = InitiatingProcessAccountName,
Computer = DeviceName,
CommandLine = InitiatingProcessCommandLine,
FileHash = InitiatingProcessSHA256,
Image = InitiatingProcessFolderPath
| extend
timestamp = TimeGenerated,
HostCustomEntity = Computer,
AccountCustomEntity = Account,
ProcessCustomEntity = InitiatingProcessFileName,
AlgorithmCustomEntity = "SHA256",
FileHashCustomEntity = FileHash
),
(Event
| where Source == "Microsoft-Windows-Sysmon"
| extend EvData = parse_xml(EventData)
| extend EventDetail = EvData.DataItem.EventData.Data
| parse EventDetail with * 'SHA256=' SHA256 '",' *
| where EventDetail has_any (sha256Hashes)
| project TimeGenerated, EventDetail, UserName, Computer, Type, Source, SHA256
| extend
Type = strcat(Type, ": ", Source),
Account = UserName,
FileHash = SHA256,
Image = EventDetail.[4].["#text"]
| extend
timestamp = TimeGenerated,
HostCustomEntity = Computer,
AccountCustomEntity = Account,
ProcessCustomEntity = tostring(split(Image, '\\', -1)[-1]),
AlgorithmCustomEntity = "SHA256",
FileHashCustomEntity = FileHash
),
(imFileEvent
| where TargetFileSHA256 has_any (sha256Hashes) or FilePath has_any (FilePaths)
| extend
Account = ActorUsername,
Computer = DvcHostname,
IPAddress = SrcIpAddr,
CommandLine = ActingProcessCommandLine,
FileHash = TargetFileSHA256
| project Type, TimeGenerated, Computer, Account, IPAddress, CommandLine, FileHash
),
(VMConnection
| where Direction == 'outbound' and DestinationIp has_any (IPList)
)
)