如何使用Sentinel观察名单排除结果中的部分字符串?
解决KQL中用观察名单排除指定域名邮箱的问题
我用观察名单存储需要从查询结果中排除的域名(无@符号),但在SMTPS场景下无法过滤掉这些域名对应的收件人邮箱。观察名单示例:
| SearchKey | SMTP |
|---|---|
| hotmail.com | hotmail.com |
| gmail.com | gmail.com |
之前的尝试(注释部分)因为无法实现精确匹配@后的域名部分而失效,现提供两种可行方案:
方案一:使用leftanti join排除匹配域名的记录
// 提前加载需排除的域名观察名单 let exclude_domains = _GetWatchlist('SMTP-exceptions') | project SearchKey; EmailAttachmentInfo | join kind=inner _GetWatchlist('FriendsList') on $left.SenderFromAddress == $right.Email // 提取收件人邮箱中@后的域名部分 | extend RecipientDomain = split(RecipientEmailAddress, '@')[1] // 通过leftanti join排除域名在观察名单中的记录 | join kind=leftanti exclude_domains on $left.RecipientDomain == $right.SearchKey | summarize arg_max(TimeGenerated, *) by SHA256, RecipientEmailAddress | project SenderFromAddress, TimeGenerated, RecipientEmailAddress, FileName, SHA256, FileType, FileSize, RecipientObjectId
方案二:使用数组匹配排除指定域名
// 将观察名单中的域名转换为动态数组 let exclude_domains_array = toscalar(_GetWatchlist('SMTP-exceptions') | summarize make_list(SearchKey)); EmailAttachmentInfo | join kind=inner _GetWatchlist('FriendsList') on $left.SenderFromAddress == $right.Email // 提取收件人邮箱的域名部分 | extend RecipientDomain = split(RecipientEmailAddress, '@')[1] // 过滤掉域名在排除数组中的记录 | where RecipientDomain !in (exclude_domains_array) | summarize arg_max(TimeGenerated, *) by SHA256, RecipientEmailAddress | project SenderFromAddress, TimeGenerated, RecipientEmailAddress, FileName, SHA256, FileType, FileSize, RecipientObjectId
为什么之前的尝试无效?
- 注释中的
leftanti join用了RecipientEmailAddress == $right.SearchKey作为匹配条件:收件人邮箱是带@的完整地址,和观察名单中的纯域名无法相等匹配,所以无法过滤。 where not(RecipientEmailAddress has_any(...))的问题:has_any会匹配邮箱中任意位置包含域名的内容(比如用户名包含hotmail的邮箱也会被误排除),无法实现仅匹配@后域名的精确过滤。
内容的提问来源于stack exchange,提问作者CurlyCrank
相关产品推荐
相关产品推荐

