如何关闭WFP

 

关于windows文件保护的讨论有许多,最近对他进行了一些整理,下面将整理的心得写下来:

微软为了提高 Windows 系统的可靠性和稳定性,从 Windows 2000 开始使用一种叫做 WFP ( Windows File Protection,
Windows 文件保护)的机制。现在,Windows 2000和Windows XP都有这个功能。

WFP 把某些文件认为是非常重要的系统文件,例如所有的dll文件,exe、fon、ocx、sys还有tff等后缀的文件。在Windows
2000/XP刚装好后,系统会自动备份这些文件到一个专门的叫做 dllcache 的文件夹,这个dllcache 文件夹的位置默认保
存在%SYSTEMROOT%/system32/dllcache。显示了所有受保护文件的正确版本和类型。一旦检测到文件被替代或者覆盖,就
可以自动从备份的文件中恢复。而如果备份的文件由于某些原因也不可用,那么Windows就会要求你插入系统光盘,以便从
光盘上恢复。


1、设置注册表值
在 HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Winlogon 下添加
"SFCDisable" DWORD值:FFFFFF9D.

SFCDisable 取值说明:
------------------------
0 = 启用WFP
1 = 禁用WFP,但是在系统每次启动的时候会询问你是否重新启用
2 = 只在下一次系统启动时禁用WFP
4 = 启用 WFP,但不跳出提示对话框
FFFFFF9D = 禁用 WFP

但是这个方法需要重新启动机器,另外改注册表的时候卡巴怕是又会吼起来了。

2、修改文件

Windows 2000 是: %SystemRoot%/system32/sfc.dll
Windows XP 是: %SystemRoot%/system32/sfc_os.dll
将此文件复制出来,用UltraEdit进行修改。
修改之前一定要先删除 %SystemRoot%/system32/dllcache下的同名文件。
具体修改如下:
---------------------------------------------------
Windows 2000 SP1 及以下版本不需要修改
Windows 2000 SP2 将 6211 处的 8BC6 改成 9090
Windows 2000 SP3 将 6211 处的 8BC6 改成 9090
Windows 2000 SP4 将 62DB 处的 8BC6 改成 9090
Windows XP 将 E2B8 处的 8BC6 改成 9090
Windows XP SP1 将 E3BB 处的 8BC6 改成 9090
Windows XP SP2 将 ECE9 处的 33C0 改成 EB01
---------------------------------------------------

这个方法有点自相矛盾,应为本身sfc.dll及sfc_os.dll就出现在WFP所保护的文件列表中。要修改这两个文件首先
就需要关闭文件保护。faint呀!

枚举文件保护所监控的文件列表的代码如下:
   if ((SfcGetNextProtectedFile =(TSfcGetNextProtectedFile) GetProcAddress( hSFC,
    "SfcGetNextProtectedFile")) == NULL)
   {
    FreeLibrary( hSFC) ;
    printf( "Error: Api SfcGetNextProtectedFile not found/n/n", argv[ 0]) ;
    return -1 ;
   }
  
   printf( "List of protected files:/n/n") ;
  
   pfd.FileNumber = 0 ;
  
   while(SfcGetNextProtectedFile( NULL, &pfd) != 0)
   {
    printf( "%ws/n", &pfd.FileName) ;
   }
}

进行反汇编了一下WFPdisable.exe,理出它的大概处理流程。

3、调用sfc.dll中的未导出函数

主要是插入winlogon进程中,调用sfc.dll(xp中是sfc_os.dll)中的未导出的2号函数,来关闭
windows系统的文件保护。

这种做法得到了一定程度的普及,如WFPdisable、黑客之门等就是这样做的。

HMODULE hSfc = LoadLibary( "sfc.dll" );
LPTHREAD_START_ROUTINE pThread = (LPTHREAD_START_ROUTINE)GetProcAddress( hSfc, 2 );

4、关闭执行windows文件签名的服务

windows之所以知道文件发生了变化主要的方法是对实施保护的文件执行签名保护,关闭了执行文件编录的服务,
WFP服务做校验,当然也就失效了。当是文件编录服务在第一次关闭以后还会自动启用。

因此有人提出替换服务的方法来关闭文件保护,但是这样做的缺点是文件保护就永远的被关闭了。其实我想此时服务的
关闭为crack sfc.dll创造了条件。另外,再次地关闭该服务的话,该服务也就不会在启动了。再狠一点,编程的时候
直接禁用该服务。并没有什么依赖该服务的服务,一般情况下也用不到,所以还是可以一试的。

有个这方面的内容可以参考以下:
在Win2000-XP上安静地替换正在使用的系统文件
Windows File Protection: How To Disable It On The Fly

好的,我可以为您提供一个 WFP 的 demo,您可以参考以下代码: #include <windows.h> #include <stdio.h> #include <stdlib.h> #include <wfp.h> #pragma comment(lib, "Fwpkclnt.lib") int main(int argc, char* argv[]) { FWPM_SESSION session = { }; FWPM_FILTER filter = { }; FWPM_FILTER_CONDITION filterConditions[1] = { }; FWPM_PROVIDER provider = { }; FWPM_SUBLAYER subLayer = { }; HANDLE engineHandle = NULL; UINT64 filterId = ; DWORD errorCode = ERROR_SUCCESS; // 初始化 WFP 引擎 errorCode = FwpmEngineOpen(NULL, RPC_C_AUTHN_WINNT, NULL, &session, &engineHandle); if (errorCode != ERROR_SUCCESS) { printf("Failed to open WFP engine. Error code: %d\n", errorCode); return -1; } // 创建 WFP 提供程序 provider.displayData.name = L"My WFP Provider"; provider.displayData.description = L"Demo WFP Provider"; provider.providerKey = (GUID) { x12345678, x1234, x1234, { x12, x34, x12, x34, x12, x34, x12, x34 } }; errorCode = FwpmProviderAdd(engineHandle, &provider, NULL); if (errorCode != ERROR_SUCCESS) { printf("Failed to add WFP provider. Error code: %d\n", errorCode); FwpmEngineClose(engineHandle); return -1; } // 创建 WFP 子层 subLayer.displayData.name = L"My WFP SubLayer"; subLayer.displayData.description = L"Demo WFP SubLayer"; subLayer.subLayerKey = (GUID) { x12345678, x1234, x1234, { x12, x34, x12, x34, x12, x34, x12, x34 } }; subLayer.weight = FWP_EMPTY; errorCode = FwpmSubLayerAdd(engineHandle, &subLayer, NULL); if (errorCode != ERROR_SUCCESS) { printf("Failed to add WFP sublayer. Error code: %d\n", errorCode); FwpmProviderDeleteByKey(engineHandle, &provider.providerKey); FwpmEngineClose(engineHandle); return -1; } // 创建 WFP 过滤器条件 filterConditions[].fieldKey = FWPM_CONDITION_IP_REMOTE_ADDRESS; filterConditions[].matchType = FWP_MATCH_EQUAL; filterConditions[].conditionValue.type = FWP_BYTE_ARRAY16_TYPE; filterConditions[].conditionValue.byteArray16 = (FWP_BYTE_ARRAY16) { x01, x02, x03, x04, x05, x06, x07, x08, x09, xA, xB, xC, xD, xE, xF, x10 }; // 创建 WFP 过滤器 filter.providerKey = provider.providerKey; filter.subLayerKey = subLayer.subLayerKey; filter.displayData.name = L"My WFP Filter"; filter.displayData.description = L"Demo WFP Filter"; filter.action.type = FWP_ACTION_BLOCK; filter.weight.type = FWP_EMPTY; filter.filterCondition = filterConditions; filter.numFilterConditions = ARRAYSIZE(filterConditions); errorCode = FwpmFilterAdd(engineHandle, &filter, NULL, &filterId); if (errorCode != ERROR_SUCCESS) { printf("Failed to add WFP filter. Error code: %d\n", errorCode); FwpmSubLayerDeleteByKey(engineHandle, &subLayer.subLayerKey); FwpmProviderDeleteByKey(engineHandle, &provider.providerKey); FwpmEngineClose(engineHandle); return -1; } // 关闭 WFP 引擎 FwpmFilterDeleteById(engineHandle, filterId); FwpmSubLayerDeleteByKey(engineHandle, &subLayer.subLayerKey); FwpmProviderDeleteByKey(engineHandle, &provider.providerKey); FwpmEngineClose(engineHandle); return ; }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值