Jump to content

0x00 前言Windows Defender是一款內置在Windows操作系統的殺毒軟件程序,本文僅在技術研究的角度介紹Windows Defender相關的滲透方法,分析利用思路,給出防禦建議。

0x01 簡介本文將要介紹以下內容:

查看Windows Defender版本

查看已存在的查殺排除列表

關閉Windows Defender的Real-time protection

添加查殺排除列表

移除Token導致Windows Defender失效

恢復被隔離的文件

0x02 查看Windows Defender版本1.通過面板查看依次選擇Windows Security-Settings-About,Antimalware Client Verions為Windows Defender版本,如下圖

12a2682d5d5579d327fc0280bbb5a3b.png

2.通過命令行查看image.png

數字大的為最新版本

0x03 查看已存在的查殺排除列表1.通過面板查看依次選擇Windows Security-Virus theat protection settings-Add or remove exclusions,如下圖

4430e255f99a377325b7659b48941fb.png

2.通過命令行查看image.png

3.通過Powershell查看image.png

0x04 關閉Windows Defender的Real-time protection1.通過面板關閉依次選擇Windows Security-Virus theat protection settings,關閉Real-time protection

2.通過命令行關閉利用條件:

需要TrustedInstaller權限

需要關閉Tamper Protection

image.png

注:

運行成功時,桌面右下角會彈框提示Windows Defender已關閉

補充1:開啟Windows Defender的Real-time protection

利用條件:

需要TrustedInstaller權限

需要關閉Tamper Protection

image.png

補充2:獲得TrustedInstaller權限

可參考之前的文章《渗透技巧——Token窃取与利用》

也可以藉助AdvancedRun,命令示例:

image.png

補充3:Tamper Protection

參考資料:

https://docs.microsoft.com/en-us/microsoft-365/security/defender-endpoint/prevent-changes-to-security-settings-with-tamper-protection?view=o365-worldwide

當開啟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的狀態:

image.png

返回結果中的數值5代表開啟,數值4代表關閉

補充4:通過Powershell關閉Windows Defender的Real-time protection

image.png

注:新版本的Windows已經不再適用

補充5:通過組策略關閉Windows Defender的Real-time protection

依次打開gpedit.msc-Computer Configuration-Administrative Templates-Windows Components-Microsoft Defender Antivirus-Real-time Protection,選擇Turn off real-time protection,配置成Enable

注:新版本的Windows已經不再適用

0x05 添加查殺排除列表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命令示例:

image.png

3.通過Powershell添加利用條件:

需要管理員權限

參考資料:

https://docs.microsoft.com/en-us/powershell/module/defender/add-mppreference?view=windowsserver2022-ps

Powershell命令示例:

image.png

補充:刪除排除列表

image.png

0x06 移除Token導致Windows Defender失效學習地址:

https://elastic.github.io/security-research/whitepapers/2022/02/02.sandboxing-antimalware-products-for-fun-and-profit/article/

簡單理解:

●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失效

POC地址:https://github.com/pwn1sher/KillDefender

利用條件:

●需要System權限

測試如下圖

d59589e1e6bda303f4706e5f0ca3e56.png

0x07 恢復被隔離的文件參考資料:

https://docs.microsoft.com/en-us/microsoft-365/security/defender-endpoint/command-line-arguments-microsoft-defender-antivirus?view=o365-worldwide

1.定位MpCmdRun image.png

得到

MpCmdRun的位置為:C:\ProgramData\Microsoft\Windows Defender\Platform\

2.常用命令查看被隔離的文件列表:

image.png

恢復指定名稱的文件至原目錄:

image.png

恢復所有文件至原目錄:

image.png

查看指定路徑是否位於排除列表中:

image.png

0x08 防禦建議阻止通過命令行關閉Windows Defender:開啟Tamper Protection

阻止通過移除Token導致Windows Defender失效:阻止非PPL進程修改PPL進程MsMpEng.exe的token,工具可參考:https://github.com/elastic/PPLGuard

0x09 小結本文在僅在技術研究的角度介紹Windows Defender相關的滲透方法,分析利用思路,給出防禦建議。對於移除Token導致Windows Defender失效的利用方法,可能會在未來版本的Windows中默認解決這個問題。

0 Comments

Recommended Comments

There are no comments to display.

Guest
Add a comment...