利用防火墙规则静默Microsoft Defender for Endpoint的技术解析

本文详细探讨了通过Windows防火墙规则阻断Microsoft Defender for Endpoint与云端通信的技术方法,包括进程识别、PowerShell脚本实现及检测方案,为红队测试提供实用绕过方案。

利用防火墙规则静默Microsoft Defender for Endpoint

Windows Defender for Endpoint(前身为Windows Defender ATP)是一款“云驱动”的EDR产品[1],其警报和事件会被推送到云端供防御人员响应。

在红队任务中,最大的挑战通常是规避EDR产品并确保行动不被检测。虽然已有大量研究关注如何规避和绕过Windows Defender for Endpoint,但很少研究探索直接静默该产品使其无法向云端发送数据的可能性。

本文探讨了一种通过防火墙规则阻止事件发送到Microsoft Defender安全中心(即https://securitycenter.windows.com)来静默Defender for Endpoint的方法,以及如何检测此类活动。

已知的篡改方法

Chris Thompson(@retBandit)在BlackHat Europe 2017的演讲[4]中详细介绍了已知的Defender for Endpoint篡改方法。该演讲讨论了使用防火墙规则阻断已知Defender for Endpoint URL流量的技术。虽然这种技术仍然有效,但为所有服务URL创建防火墙规则非常繁琐[2][3]。此外,URL列表还包含如*.blob.core.windows.net*.azure-automation.net等可能破坏某些Windows服务的条目。在红队或渗透测试中,应避免不必要地影响客户或通过干扰常规工作流引起防御者警觉。

新方法:阻断特定进程

我们评估了是否可以通过阻断特定服务和进程的通信来静默Defender for Endpoint。为此,需要确定哪些进程与已知Defender for Endpoint URL通信,并阻断这些特定进程。有多种方法可以检查进程连接的域,包括Microsoft Network Monitor[5]、Wireshark[6]等工具。但Defender for Endpoint已收集所有必要信息,可通过Microsoft Defender安全中心获取!

Defender for Endpoint收集所有运行进程的网络连接,因此可用于确定哪些进程与已知Defender for Endpoint URL通信。以下Kusto查询可显示这些进程:

查找连接到已知Defender for Endpoint URL的进程的Kusto查询

[按Enter键或点击查看完整图片]

连接到已知Defender for Endpoint URL的进程

浏览列表时,我们发现一些与Defender for Endpoint无关的进程。例如,Teams.exe(微软官方Teams客户端)显然会向已知URL发送事件。此外,还有一个无名称的进程,我们未进一步研究。

其余进程对于熟悉Defender for Endpoint的用户应该非常熟悉。深入了解这些进程将有助于使用Windows防火墙有效阻断它们:

  • SenseIR.exe:通过Microsoft Defender安全中心启动“实时响应会话”时,作为MsSense.exe的子进程生成
  • SenseCncProxy.exe:作为MsSense.exe的子进程生成。描述称其为“通信模块”,可能负责与上述URL的通信及代理设置
  • MsSense.exe:Defender for Endpoint的主服务可执行文件,在Windows 10上以“Sense”服务运行
  • MsMpEng.exe:Microsoft Defender Antivirus的主服务可执行文件,在Windows 10上以“WinDefend”服务运行
  • MpCmdRun.exe:执行各种Microsoft Defender Antivirus功能的命令行工具
  • MonitoringHost.exe:作为HealthService服务的子进程生成。是Microsoft Monitoring Agent的一部分,在旧版Windows设备上线时安装[6][7]
  • HealthService.exe:Microsoft Monitoring Agent的主服务可执行文件,在旧版Windows设备上线时安装[6][7]

此外,还有许多原生Windows服务(如utcsvc和diagtrack)也与已知URL通信,但在测试中它们未发送任何与Defender for Endpoint相关的事件或警报数据。

PoC — 防火墙规则

Windows 10和Windows Server 2019

在Windows 10和Windows Server 2019上静默Defender for Endpoint相对简单,只需阻止MsMpEng、SenseCncProxy和MsSense三个进程在443端口上发送出站流量。运行以下PowerShell脚本可在撰写本文时有效静默Windows Defender且不触发警报:

在Windows 10和Windows Server 2019上静默Defender for Endpoint的防火墙规则

1
2
3
New-NetFirewallRule -DisplayName "Block MsMpEng" -Direction Outbound -Program "C:\ProgramData\Microsoft\Windows Defender\Platform\*\MsMpEng.exe" -Action Block -Protocol TCP -RemotePort 443
New-NetFirewallRule -DisplayName "Block SenseCncProxy" -Direction Outbound -Program "C:\Program Files\Windows Defender Advanced Threat Protection\SenseCncProxy.exe" -Action Block -Protocol TCP -RemotePort 443
New-NetFirewallRule -DisplayName "Block MsSense" -Direction Outbound -Program "C:\Program Files\Windows Defender Advanced Threat Protection\MsSense.exe" -Action Block -Protocol TCP -RemotePort 443

在Windows中添加防火墙规则需要本地管理员权限,因此无法从低权限用户帐户执行此攻击。从Microsoft Defender安全中心的截图可见,应用防火墙规则后未收到任何事件。

[按Enter键或点击查看完整图片]

如图所示,应用防火墙规则后安全中心未显示任何事件

所有事件似乎都在本地缓存,一旦移除防火墙规则,事件和警报将开始出现在Microsoft Defender安全中心。

旧版Windows?

虽然我们可以给出答案,但将此留给读者作为练习。所有信息均已提供,只需进行一些研究和尝试即可。

检测

如果仅依赖Defender for Endpoint进行基于主机的入侵检测,此时将无能为力。由于没有事件或警报发送到云解决方案,在撰写本文时无法通过Defender for Endpoint进行有效检测。幸运的是,Defender for Endpoint会在Microsoft-Windows-SENSE/Operational事件日志中记录连接错误(事件ID 5)。示例如下:

[按Enter键或点击查看完整图片]

检测Defender for Endpoint客户端无法联系云服务器时的事件日志

虽然也可以基于进程执行或PowerShell日志检测攻击,但这并非稳健解决方案,因为Windows中存在多种添加防火墙规则的方法,例如使用GUI或netsh.exe[9]。我未找到检测防火墙规则创建的合适方法,因为大多数资源指向事件ID 4947(已更改Windows防火墙例外列表。规则已修改),但该事件仅显示RuleId和RuleName,不显示规则内容。

补充说明

补充1:当Defender for Endpoint被阻断7天后,健康状态将变为非活动[11]。这意味着在前7天内,即使设备未发送任何警报或事件,也不会被标记为非活动。

补充2:在设备清单概述中,可以筛选具有“通信受损”或“无传感器数据”的设备[11]。据@SiliconShecky称,此列表将在24小时内显示设备。

补充3:@bh4b3sh发布了一篇描述如何通过注册表审核检测防火墙规则创建的文章。详见:https://bhabeshraj.com/post/detect-addition-of-new-firewall-rules-in-defender-firewall/

防护

虽然可以在Defender for Endpoint中创建自定义检测规则[10],但这些规则仅在服务器端评估,不会在终端上阻止任何操作。它们仅会警报以便操作员采取行动。因此,要防止此特定攻击,我们必须等待微软决定通过AMSI或类似方法在Microsoft Defender中直接阻止该操作。

希望您喜欢本文。如有任何问题,请通过Twitter @fritzboger联系我。

参考文献

[1] https://www.microsoft.com/en/microsoft-365/security/endpoint-defender
[2] https://docs.microsoft.com/en-us/windows/security/threat-protection/microsoft-defender-atp/configure-proxy-internet#enable-access-to-microsoft-defender-for-endpoint-service-urls-in-the-proxy-server
[3] https://github.com/MicrosoftDocs/windows-itpro-docs/raw/public/windows/security/threat-protection/microsoft-defender-atp/downloads/mdatp-urls.xlsx
[4] https://www.blackhat.com/docs/eu-17/materials/eu-17-Thompson-Red-Team-Techniques-For-Evading-Bypassing-And-Disabling-MS-Advanced-Threat-Protection-And-Advanced-Threat-Analytics.pdf
[5] https://docs.microsoft.com/en-us/troubleshoot/windows-server/networking/network-monitor-3
[6] https://docs.microsoft.com/en-us/windows/security/threat-protection/microsoft-defender-atp/onboard-downlevel
[7] https://docs.microsoft.com/en-us/windows/security/threat-protection/microsoft-defender-atp/configure-server-endpoints
[8] https://docs.microsoft.com/en-us/sysinternals/downloads/sysmon
[9] https://docs.microsoft.com/en-us/troubleshoot/windows-server/networking/netsh-advfirewall-firewall-control-firewall-behavior
[10] https://docs.microsoft.com/en-us/windows/security/threat-protection/microsoft-defender-atp/custom-detection-rules
[11] https://docs.microsoft.com/en-us/windows/security/threat-protection/microsoft-defender-atp/fix-unhealthy-sensors#inactive-devices

comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计