文章目录
- 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-9E
                           44-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-91
                           B8-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



















