SamQueryInformationDomain:使用 _DOMAIN_PASSWORD_INFORMATION 获取 DOMAIN_PASSWORD_COMPLEX

发布于 2025-01-10 02:48:33 字数 342 浏览 1 评论 0原文

我正在尝试获取密码复杂性,寻找 WINAPI 发现 SamQueryInformationDomain 但似乎没有公开的 MSDN 文档。不是头文件。找到了一些 C# 代码片段 这里但没有找到一些示例c++代码SamQueryInformationDomain。如果可以分享示例代码将会有很大帮助

I am trying to get Password Complexity, looking for WINAPI found SamQueryInformationDomain
But seems like there no public MSDN documentation for it. not header files. found soem C# code snippet here but did not find some sample c++ code snipped for SamQueryInformationDomain. Would be great help if can share sample code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

維他命╮ 2025-01-17 02:48:33

最后经过多次尝试和搜索我发现了

NTSTATUS status, enumDomainStatus, enumUserStatus;
UNICODE_STRING serverName;
ACCESS_MASK mask = 0;
mask = SAM_SERVER_CONNECT | SAM_SERVER_ENUMERATE_DOMAINS | SAM_SERVER_LOOKUP_DOMAIN;
SAMPR_HANDLE hServerHandle, hBuiltinHandle = NULL, hDomainHandle, hUserHandle;
DWORD domainEnumerationContext = 0, domainCountRetourned, userEnumerationContext, userCountRetourned, groupsCountRetourned, i, j, k, aliasCountRetourned, *alias;
PSAMPR_RID_ENUMERATION pEnumDomainBuffer, pEnumUsersBuffer;
PSID domainSid, userSid;
SID builtin = { SID_REVISION, 1, SECURITY_NT_AUTHORITY, {SECURITY_BUILTIN_DOMAIN_RID} };
PGROUP_MEMBERSHIP pGroupMemberShip;


PSAMPR_DOMAIN_INFO_BUFFER buff;

RtlInitUnicodeString(&serverName, L"");

status = SamConnect(&serverName, &hServerHandle, SAM_SERVER_ALL_ACCESS, FALSE);
if (0 != status)
{
    printf("SamConnect error (?) %08x\n", status);
    return;
}

status = SamOpenDomain(hServerHandle, DOMAIN_READ_PASSWORD_PARAMETERS, &builtin, &hDomainHandle);
if (0 != status)
{
    printf("SamOpenDomain Builtin (?) %08x\n", status);
    return;
}

status = SamQueryInformationDomain(hDomainHandle, DomainPasswordInformation, &buff);

if (0 != status)
{
    printf("SamQueryInformation failed with %08x\n", status);
    return ;
}

ULONG properties = buff->Password.PasswordProperties;


printf("SamQueryInformation success with password properties value : %ld\n", properties);
printf("SamQueryInformation success with password MaxPasswordAge value : %ld\n", buff->Password.MaxPasswordAge);
printf("SamQueryInformation success with password MinPasswordAge value : %ld\n", buff->Password.MinPasswordAge);
printf("SamQueryInformation success with password MinPasswordLength value : %ld\n", buff->Password.MinPasswordLength);
printf("SamQueryInformation success with password PasswordHistoryLength value : %ld\n", buff->Password.PasswordHistoryLength);

Finally after many tryouts and searches I figured out

NTSTATUS status, enumDomainStatus, enumUserStatus;
UNICODE_STRING serverName;
ACCESS_MASK mask = 0;
mask = SAM_SERVER_CONNECT | SAM_SERVER_ENUMERATE_DOMAINS | SAM_SERVER_LOOKUP_DOMAIN;
SAMPR_HANDLE hServerHandle, hBuiltinHandle = NULL, hDomainHandle, hUserHandle;
DWORD domainEnumerationContext = 0, domainCountRetourned, userEnumerationContext, userCountRetourned, groupsCountRetourned, i, j, k, aliasCountRetourned, *alias;
PSAMPR_RID_ENUMERATION pEnumDomainBuffer, pEnumUsersBuffer;
PSID domainSid, userSid;
SID builtin = { SID_REVISION, 1, SECURITY_NT_AUTHORITY, {SECURITY_BUILTIN_DOMAIN_RID} };
PGROUP_MEMBERSHIP pGroupMemberShip;


PSAMPR_DOMAIN_INFO_BUFFER buff;

RtlInitUnicodeString(&serverName, L"");

status = SamConnect(&serverName, &hServerHandle, SAM_SERVER_ALL_ACCESS, FALSE);
if (0 != status)
{
    printf("SamConnect error (?) %08x\n", status);
    return;
}

status = SamOpenDomain(hServerHandle, DOMAIN_READ_PASSWORD_PARAMETERS, &builtin, &hDomainHandle);
if (0 != status)
{
    printf("SamOpenDomain Builtin (?) %08x\n", status);
    return;
}

status = SamQueryInformationDomain(hDomainHandle, DomainPasswordInformation, &buff);

if (0 != status)
{
    printf("SamQueryInformation failed with %08x\n", status);
    return ;
}

ULONG properties = buff->Password.PasswordProperties;


printf("SamQueryInformation success with password properties value : %ld\n", properties);
printf("SamQueryInformation success with password MaxPasswordAge value : %ld\n", buff->Password.MaxPasswordAge);
printf("SamQueryInformation success with password MinPasswordAge value : %ld\n", buff->Password.MinPasswordAge);
printf("SamQueryInformation success with password MinPasswordLength value : %ld\n", buff->Password.MinPasswordLength);
printf("SamQueryInformation success with password PasswordHistoryLength value : %ld\n", buff->Password.PasswordHistoryLength);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文