我们无法在 Windows 10 中设置自定义密码过滤器

We are not able to set customized passwordFilter in windows 10

本文关键字:设置 自定义 密码 过滤器 Windows 我们      更新时间:2023-10-16

我创建了自己的密码过滤器.dll,但我无法将其设置为Windows系统。

我把它附加到LSA->Notificationpackage下,我也复制到c:\Window\System32中。

在我的密码过滤器中,我一开始创建了日志文件,但它没有创建它。

请让我知道在 Windows 10 中设置密码过滤器还需要执行更多步骤。

请找到我的密码过滤器的这一段:

#include <regex>
#include <fstream>
#include "Ntsecapi.h"
#define MAX_SIZE 4028
using namespace std;
using namespace std::tr1;
fstream writeLog;
BOOLEAN __stdcall InitializeChangeNotify(void)
{
wchar_t *pLogFile = L"c:AmitPasswordFilter.log";
wchar_t aLogFileExp[64];
ExpandEnvironmentStrings(pLogFile, aLogFileExp, sizeof(aLogFileExp)/sizeof(wchar_t));
writeLog.open(aLogFileExp, ios::out|ios::app);
writeLog<<"InitializeChangeNotify"<<endl;
return TRUE;
}
BOOLEAN __stdcall PasswordFilter(PUNICODE_STRING AccountName, PUNICODE_STRING FullName, PUNICODE_STRING Password, BOOLEAN SetOperation)
{
writeLog<<"BabaPasswordFilter"<<endl;
writeLog<< "PasswordFilterAmit"<<endl;
wcmatch mr;
BOOL match = FALSE;
std::wstring seperator(L")(?=");
std::wstring regExp(L"(?=");
const int cathegories=4;
unsigned int aRegCondition[cathegories]={2,2,2,2};
for(int i=0;i<cathegories;i++)
{

for(int i=0;i<aRegCondition[0];i++)
regExp+=L".*\d";
regExp+=seperator;
for(int i=0;i<aRegCondition[1];i++)
regExp+=L".*\W";
regExp+=seperator;
for(int i=0;i<aRegCondition[2];i++)
regExp+=L".*[A-Z]";
regExp+=seperator;
for(int i=0;i<aRegCondition[3];i++)
regExp+=L".*[a-z]";
regExp+=L")(?![.\n]).*$";// check for newline characters and end
wregex rx(regExp);
if (Password)
{
match = regex_search(Password->Buffer, mr, rx);
if (match)
{
match = TRUE;
writeLog<<"SumitPassword matches the complexity"<<endl;
}
else
{
match = FALSE;
writeLog<<"SumitPassword does not matche the complexity"<<endl;
}
}
else
{
writeLog<<"SumitPassword is NULL"<<endl;
}
return match;
}

您的域密码策略是否已启用"密码必须满足复杂性要求"?根据 Microsoft 关于启用自定义密码筛选器的文档,需要启用此策略才能应用密码筛选器(大约五年前,当我们实施密码筛选器时,我确认该策略也是必需的(。

如果启用了复杂性策略,请针对 LSASS.EXE 运行远程调试会话(在 WinDBG 中,需要使用"qd"{quit and detach} 关闭调试会话,否则 lsass.exe 会意外终止,并且您的计算机在重新启动之前会搞砸(。

我建议不要在InitializeChangeNotive下放置任何东西,除非您有彻底的异常处理。通过此调用发生的异常可能会产生广泛的问题。我的初始化更改通知只是一个返回真...这是准确的,因为我的过滤器有一个单独的服务,它应用业务逻辑来测试密码有效性——如果我的 DLL 足以响应 InitializeChangeNotify,那么它启动了。

作为参考,我的密码过滤器功能:

extern "C" __declspec(dllexport) BOOLEAN __stdcall PasswordFilter(PUNICODE_STRING AccountName,
PUNICODE_STRING FullName,
PUNICODE_STRING Password,
BOOLEAN SetOperation) {
//build the account struct
PasswordFilterAccount *pfAccount = new PasswordFilterAccount();
pfAccount->AccountName = AccountName;
pfAccount->Password = Password;
//start an asynchronous thread to be able to kill the thread if it exceeds the timout
HANDLE pfHandle = (HANDLE)_beginthreadex(0, 0, CreateSocket, (LPVOID *)pfAccount, 0, 0);
// timeout is milliseconds. Is 30 seconds too long?
DWORD dWaitFor = WaitForSingleObject(pfHandle, 30000); //do not exceed the timeout. 
if (dWaitFor == WAIT_TIMEOUT) {
//timeout exceeded
writeWindowsEventLog("Timeout exceeded", "OPF", "ERROR", 5);
}
else if (dWaitFor == WAIT_OBJECT_0) {
//here is where we want to be
}
else {
//WAIT_ABANDONED
//WAIT_FAILED
writeWindowsEventLog("WAIT abandoned or failed", "OPF", "ERROR", 5);
}
if (pfHandle != INVALID_HANDLE_VALUE && pfHandle != 0) {
if (CloseHandle(pfHandle)) {
pfHandle = INVALID_HANDLE_VALUE;
}
}
return bPasswordOk;
}