如何用KQL实现Azure Sentinel管理员跨工作站登录异常检测
调整后完整KQL语句
SecurityEvent // 筛选过去24小时、管理员账号、登录相关事件 | where TimeGenerated >= ago(24h) and Account matches regex @".*admin.*" and AccountType == "User" and EventID in (4624, 4625) // 去重重复的单条日志 | distinct Account, WorkstationName, IpAddress, EventID, TimeGenerated, Computer // 按5分钟窗口+账号维度聚合统计 | summarize 登录总次数 = count(), 不同工作站数量 = dcount(WorkstationName), 涉及工作站列表 = make_set(WorkstationName), 涉及IP列表 = make_set(IpAddress), 涉及事件ID列表 = make_set(EventID), 窗口最早登录时间 = min(TimeGenerated), 窗口最晚登录时间 = max(TimeGenerated) by bin(TimeGenerated, 5m), Account // 仅保留5分钟内登录≥2个不同工作站的可疑记录 | where 不同工作站数量 >= 2 | sort by Account asc, 窗口最早登录时间 desc
调整说明
- 新增
TimeGenerated >= ago(24h)过滤条件,限定仅查询过去24小时的日志,匹配你的排查范围要求 - 优化语法逻辑:用
in简化多EventID匹配逻辑,修正原正则写法,KQL的matches regex匹配任意位置含admin的账号需用@".*admin.*",原*admin*写法会触发语法报错 - 聚合维度调整为「5分钟时间窗口+账号」,用
dcount统计不同工作站数量,make_set将关联的工作站、IP等信息汇总为数组,不需要手动关联多条日志 - 最后新增
where 不同工作站数量 >= 2过滤规则,仅返回同一账号5分钟内登录多设备的可疑记录,自动过滤正常单设备登录的无效日志
样例数据测试代码
注意你提供的原测试数据存在语法错误:IP地址字段类型应为字符串而非int、每行字段数量不匹配,下方代码已做修正
let Table = datatable(TimeGenerated:datetime, Account:string, Computer:string, WorkstationName:string, IPAddress:string, EventID:int) [ datetime(2021-07-21 17:15:00), "1", "A", "123", "11.63.24.357", 4624, datetime(2021-07-22 13:20:00), "2", "G", "195", "19.26.83.257", 4624, datetime(2021-07-22 13:25:00), "2", "P", "275", "192.64.9.432", 4624 ]; Table | where TimeGenerated >= ago(365d) // 样例数据时间较早,调整时间范围适配测试 and Account matches regex @".*" // 测试用,匹配所有账号 and EventID in (4624, 4625) | distinct Account, WorkstationName, IpAddress, EventID, TimeGenerated, Computer | summarize 登录总次数 = count(), 不同工作站数量 = dcount(WorkstationName), 涉及工作站列表 = make_set(WorkstationName), 涉及IP列表 = make_set(IpAddress), 涉及事件ID列表 = make_set(EventID), 窗口最早登录时间 = min(TimeGenerated), 窗口最晚登录时间 = max(TimeGenerated) by bin(TimeGenerated, 5m), Account | where 不同工作站数量 >= 2
内容的提问来源于stack exchange,提问作者EStrong
相关产品推荐
相关产品推荐

