-
Notifications
You must be signed in to change notification settings - Fork 121
/
GetDomainPasswordPolicy.cpp
88 lines (79 loc) · 2.12 KB
/
GetDomainPasswordPolicy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <windows.h>
#include <lm.h>
#pragma comment(lib, "netapi32.lib")
int wmain(int argc, wchar_t *argv[])
{
DWORD dwLevel = 0;
USER_MODALS_INFO_0 *pBuf0 = NULL;
USER_MODALS_INFO_3 *pBuf3 = NULL;
NET_API_STATUS nStatus;
LPTSTR pszServerName = NULL;
if (argc != 2)
{
printf("Usage:\n");
printf("\t%ws [\\\\ServerName]\n", argv[0]);
exit(1);
}
// The server is not the default local computer.
//
if (argc == 2)
pszServerName = (LPTSTR)argv[1];
//
// Call the NetUserModalsGet function; specify level 0.
//
nStatus = NetUserModalsGet((LPCWSTR)pszServerName,
dwLevel,
(LPBYTE *)&pBuf0);
//
// If the call succeeds, print the global information.
//
if (nStatus == NERR_Success)
{
if (pBuf0 != NULL)
{
printf("[+] Global password information:\n");
printf("\tMinimum password length: %d\n", pBuf0->usrmod0_min_passwd_len);
printf("\tMaximum password age (d): %d\n", pBuf0->usrmod0_max_passwd_age / 86400);
printf("\tMinimum password age (d): %d\n", pBuf0->usrmod0_min_passwd_age / 86400);
printf("\tForced log off time (s): %d\n", pBuf0->usrmod0_force_logoff);
printf("\tPassword history length: %d\n", pBuf0->usrmod0_password_hist_len);
}
}
// Otherwise, print the system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf0 != NULL)
NetApiBufferFree(pBuf0);
dwLevel = 3;
nStatus = NetUserModalsGet((LPCWSTR)pszServerName,
dwLevel,
(LPBYTE *)&pBuf3);
//
// If the call succeeds, print the global information.
//
if (nStatus == NERR_Success)
{
if (pBuf3 != NULL)
{
printf("[+] Lockout information:\n");
printf("\tLockout duration (m): %d\n", pBuf3->usrmod3_lockout_duration / 60);
printf("\tLockout observation window (m): %d\n", pBuf3->usrmod3_lockout_observation_window / 60);
printf("\tLockout threshold: %d\n", pBuf3->usrmod3_lockout_threshold);
}
}
// Otherwise, print the system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf3 != NULL)
NetApiBufferFree(pBuf3);
return 0;
}