文章目錄
- Windows安全中心(病毒和威脅防護)的注冊
- 1. 簡介
- 2. WSC注冊初探
- 3. WSC注冊原理分析
- 4. 關于AMPPL
- 5. 參考
Windows安全中心(病毒和威脅防護)的注冊
本文我們來分析一下Windows安全中心(Windows Security Center簡稱WSC)的注冊原理,以及其中的一些比較有意思的技術性問題。
1. 簡介
通常情況下,如果我們安裝了一些第三方的安全軟件之后,就會接管Windows的安全服務(Windows Defender);這里主要的原因大概是防止系統安全軟件太多,導致Windows性能下降。可以看到如下:
以火絨為例,可以看到當系統安裝了火絨安全軟件之后,在Windows 安全中心的病毒和威脅防護就可以看到注冊的安全軟件信息了。
當系統注冊了第三方安全軟件之后,Windows Defender防病毒服務就停止了;這是Windows為第三方安全軟件提供的一個入口,但是目前市面上很大安全軟件還比不上Windows自帶的Defender,也是比較諷刺。
那么怎么樣才能將自己的安全軟件注冊到Windows安全中心呢?大致的步驟如下:
- 成為MVI會員。
- 微軟提供一個內部的私有接口。
- 提供相關簽名證書。
通過上面流程,我們就可以開發自己的安全軟件,并且將自己的安全軟件注冊到WSC種。那么有沒有辦法可以繞過上面這些呢?這就是本文需要分析的技術性知識點。
2. WSC注冊初探
WSC如果被注冊成功之后,可以通過命令get-wmiObject -namespace root\SecurityCenter2 -class AntiVirusProduct
來查詢相關信息,結果如下:
> get-wmiObject -namespace root\SecurityCenter2 -class AntiVirusProduct__GENUS : 2
__CLASS : AntiVirusProduct
__SUPERCLASS :
__DYNASTY : AntiVirusProduct
__RELPATH : AntiVirusProduct.instanceGuid="{D68DDC3A-831F-4fae-9E44-DA132C1ACF46}"
__PROPERTY_COUNT : 6
__DERIVATION : {}
__SERVER : DESKTOP-1SIKOAK
__NAMESPACE : ROOT\SecurityCenter2
__PATH : \\DESKTOP-1SIKOAK\ROOT\SecurityCenter2:AntiVirusProduct.instanceGuid="{D68DDC3A-831F-4fae-9E44-DA132C1ACF46}"
displayName : Windows Defender
instanceGuid : {D68DDC3A-831F-4fae-9E44-DA132C1ACF46}
pathToSignedProductExe : windowsdefender://
pathToSignedReportingExe : %ProgramFiles%\Windows Defender\MsMpeng.exe
productState : 393472
timestamp : Tue, 17 Dec 2024 02:37:41 GMT
PSComputerName : DESKTOP-1SIKOAK__GENUS : 2
__CLASS : AntiVirusProduct
__SUPERCLASS :
__DYNASTY : AntiVirusProduct
__RELPATH : AntiVirusProduct.instanceGuid="{4C17E7AE-043A-D732-91B8-D139C9EB6B26}"
__PROPERTY_COUNT : 6
__DERIVATION : {}
__SERVER : DESKTOP-1SIKOAK
__NAMESPACE : ROOT\SecurityCenter2
__PATH : \\DESKTOP-1SIKOAK\ROOT\SecurityCenter2:AntiVirusProduct.instanceGuid="{4C17E7AE-043A-D732-91B8-D139C9EB6B26}"
displayName : 火絨安全軟件
instanceGuid : {4C17E7AE-043A-D732-91B8-D139C9EB6B26}
pathToSignedProductExe : C:\Program Files\Huorong\Sysdiag\bin\wsctrlsvc.exe
pathToSignedReportingExe : C:\Program Files\Huorong\Sysdiag\bin\wsctrlsvc.exe
productState : 266240
timestamp : Tue, 17 Dec 2024 02:37:36 GMT
PSComputerName : DESKTOP-1SIKOAK
在這里可以看到有兩個類信息:
- Windows Defender表示默認的Windows Defender。
- 火絨安全軟件表示火絨。
這里可以看到一個非常重要的信息,WSC注冊的進程為C:\Program Files\Huorong\Sysdiag\bin\wsctrlsvc.exe
。
那么我們就可以請出IDA和調試神器WINDBG來分析和調試一下WSC注冊的原理。
3. WSC注冊原理分析
由于我們需要成為MVI會員之后,才能有相關私有SDK文檔,這里我們就分析一下wsctrlsvc.exe
這個程序,大致看一下私有SDK是怎么使用的。
我們可以看到WSC相關的主要文件有如下幾個:
- wscisvif.dll這個是WSC客戶端的接口提供DLL。
- wscapi.dll這個是WSC客戶端的核心DLL。
- wscsvc.dll這個是WSC的核心服務DLL。
可以看到私有SDK就是對wscisvif.dll
未公開的SDK的調用,我們可以對這些使用接口進行分析,可以看到核心接口如下:
virtual long _IWscAVStatus4<class CWscIsv>::Register(unsigned short *, unsigned short *, int, int)
virtual long _IWscAVStatus4<class CWscIsv>::Unregister(void)
virtual long _IWscAVStatus4<class CWscIsv>::UpdateStatus(enum _WSC_SECURITY_PRODUCT_STATE, int)
virtual long _IWscAVStatus4<class CWscIsv>::InitiateOfflineCleaning(unsigned short *, unsigned short *)
virtual long _IWscAVStatus4<class CWscIsv>::NotifyUserForNearExpiration(unsigned long)
可以發現核心接口就是如下三個:
Register
注冊WSC產品。Unregister
反注冊WSC產品。UpdateStatus
更新產品的狀態。
根據這些分析我們就可以自己向Windows安全中心注冊自己的安全軟件了,例如可以如下(這里注冊了一個我的安全軟件產品):
4. 關于AMPPL
通過上面的分析,我們成功向Windows安全中心注冊了自己的安全軟件,但是在某些情況下可能會失敗,并且Register
返回的結果為0x800704dc
;這就是AMPPL安全檢測導致的結果。
我們分析s_wscRegisterSecurityProduct
函數,可以導致得到如下的判斷:
if ( type == SECURITY_PRODUCT_TYPE_ANTIVIRUS )
{ValidateCallerAMPPL((int *)&v34, a1, L"s_wscRegisterSecurityProduct", a3, a4);v12 = (unsigned int)v34;if ( (_DWORD)v34 )goto Exit1;
}
ValidateCallerAMPPL
這個函數就是檢測AMPPL的,大致檢測的結果如下:
v12 = NtQueryInformationProcess(v9, 61, &v15, 1);
if ( (unsigned __int8)((v15.Level & 7) - 1) > IsAm1PPL || (v15.Level & 0xF0) != 0x30 )IsAmPPL = 0;
也就是說我們需要檢測進程AMPPL的標記,通過NtQueryInformationProcess
查詢ProcessProtectionInformation
,改查詢得到的結構體信息如下:
typedef enum _PS_PROTECTED_SIGNER
{PsProtectedSignerNone = 0,PsProtectedSignerAuthenticode = 1,PsProtectedSignerCodeGen = 2,PsProtectedSignerAntimalware = 3,PsProtectedSignerLsa = 4,PsProtectedSignerWindows = 5,PsProtectedSignerWinTcb = 6,PsProtectedSignerMax = 7
} PS_PROTECTED_SIGNER;typedef enum _PS_PROTECTED_TYPE
{PsProtectedTypeNone = 0,PsProtectedTypeProtectedLight = 1,PsProtectedTypeProtected = 2,PsProtectedTypeMax = 3
} PS_PROTECTED_TYPE;typedef union _PS_PROTECTION
{UCHAR Level;struct{int Type : 3;int Audit : 1;int Signer : 4;} Flags;
} PS_PROTECTION, *PPS_PROTECTION;
這些結構體字段中Type含義如下:
-
PsProtectedTypeNone (0)
- the process is not running as protected. -
PsProtectedTypeProtectedLight (1)
- the process is running as light-protected (PPL). -
PsProtectedTypeProtected (2)
- the process is running as fully-protected.
Signer字段的含義如下:
-
PsProtectedSignerNone (0)
- the process has no signature that grants it protection. -
PsProtectedSignerAuthenticode (1)
- the process has an Authenticode signature. -
PsProtectedSignerCodeGen (2)
- the process has a Code Generation signature. -
PsProtectedSignerAntimalware (3)
- the process has an Antimalware signature. -
PsProtectedSignerLsa (4)
- the process has an LSA signature. -
PsProtectedSignerWindows (5)
- the process has a Windows signature. -
PsProtectedSignerWinTcb (6)
- the process has a WinTCB (trusted computer base) signature. -
PsProtectedSignerWinSystem (7)
- the process has a WinSystem signature. -
PsProtectedSignerApp (8)
- the process has a Store Application signature.
在進程啟動的時候,內核會更加啟動進程是否有簽名(或者簽名的類型)來設置相關值,流程為:
NtCreateUserProcess --> SeQuerySigningPolicy
這里似乎看起來又比較麻煩了,因為需要防病毒MVI相關證書才行。這里NtQueryInformationProcess
查詢的是EPROCESS
中的字段的值,我們只要想辦法修改這些值就可以了,例如我們可以將我們自己的進程EPROCESS
修改為如下:
kd> dx -id 0,0,94040040 -r1 (*((ntkrpamp!_PS_PROTECTION *)0x940403a6))
(*((ntkrpamp!_PS_PROTECTION *)0x940403a6)) [Type: _PS_PROTECTION][+0x000] Level : 0x31 [Type: unsigned char][+0x000 ( 2: 0)] Type : 0x1 [Type: unsigned char][+0x000 ( 3: 3)] Audit : 0x0 [Type: unsigned char][+0x000 ( 7: 4)] Signer : 0x3 [Type: unsigned char]
這樣我們就可以完成ValidateCallerAMPPL
這個函數的檢測了,WSC也完全正常注冊了。
5. 參考
WSC本來就是一個私有的接口文檔,參考資料也非常少,下面是網上相關的一些參考文章:
- https://bbs.kanxue.com/thread-282498.htm
- https://github.com/m417z/ntdoc/blob/main/descriptions/ps_protection.md
- https://stackoverflow.com/questions/3698285/how-can-i-tell-the-windows-security-center-that-im-an-antivirus
- https://learn.microsoft.com/en-us/defender-xdr/virus-initiative-criteria