이쿠의 슬기로운 개발생활

함께 성장하기 위한 보안 개발자 EverNote 내용 공유

코딩/C and C++

C++ windows 로컬 그룹 정책 확인

이쿠우우 2021. 12. 22. 11:33
반응형

 

C++ windows 로컬 그룹 정책 확인

 

목표

windows의 로컬 그룹 정책 값을 C++에서 확인.
예제로 로컬 그룹 정책 중에서 
보안설정 > 로컬 정책 > 보안 옵션 > 네트워크 액세스 : 익명 SID/이름 변환 허용
(Access allow anonymous SID/Name Translation)
항목 설정값을 확인하는것이 목표.
 
[로컬 그룹 정책 편집기 실행 단축키]
Win+R 
gpedit.msc 

 

 

로컬 그룹 정책 확인할 수 있는 다양한 방법

로컬 그룹 정책을 확인 할 수 있는 방법들로는

NetUserModalsGet 함수 사용, Registry, secedit로
총 4가지 방법이 있음.

순서대로 장,단점을 비교해보도록함.

 

 


 

NetUserModalsGet 함수 사용 (결과 :  일부 사용 가능)

 

[Header]

windows.h
lm.h
 

[함수 사용 예제]

NET_API_STATUS nStatus;
DWORD dwLevel = 0;
USER_MODALS_INFO_0 *pBuf = NULL;
nStatus = NetUserModalsGet(NULL, dwLevel, (LPBYTE *)pBuf);
 

함수 리서치 내용

NetUserModalsGet의 첫 번째 매개변수가 NULL인 경우는 
해당 함수를 실행시킨 로컬의 정보를 확인함.
NULL이 아닌 경우는 확인하고자 하는 컴퓨터 이름을 넣어주면 됨.
(GetComputerName 함수를 사용해서 컴퓨터 이름을 확인.)
dwLevel에 따라 수집하는 결과가 다름.
pBuf 에 결과가 저장됨.
dwLevel의 변수의 USER_MODALS_INFO_0,1,2,3 와
dwLevel과 일치해야함
 

암호 정책 중 확인 가능 항목

Enforce password history        USER_MODALS_INFO_0->usrmod0_password_hist_len
Maximum password age         USER_MODALS_INFO_0->usrmod0_max_passwd_age
Minimum password age         USER_MODALS_INFO_0->usrmod0_min_passwd_age
Minimum password length     USER_MODALS_INFO_0->usrmod0_min_passwd_len
Store passwords using reversible encryption    확인 불가
Network security : Force log off when log on hours expire 확인 불가
Password must meet complexity requirements  확인 불가
 

함수 사용 예제 코드


#include <stdio.h>
#include <windows.h>
#include <lm.h>
#include <string>
#pragma comment(lib, "netapi32.lib")
int main()
{
    DWORD dwLevel = 0;
    USER_MODALS_INFO_0 *pBuf = NULL;
    NET_API_STATUS nStatus;
     
     
    // Call the NetUserModalsGet function; specify level 0.
    nStatus = NetUserModalsGet(NULL, dwLevel, (LPBYTE *)&pBuf);
    // If the call succeeds, print the global information.
    if (nStatus == NERR_Success)
    {
        wprintf(L"NetUserModalsGet() should be fine!\n");
        if (pBuf != NULL)
        {
            wprintf(L"\tMinimum password length : %d\n", pBuf->usrmod0_min_passwd_len);
            wprintf(L"\tMaximum password age(d) : %d\n", pBuf->usrmod0_max_passwd_age / 86400);
            wprintf(L"\tMinimum password age(d) : %d\n", pBuf->usrmod0_min_passwd_age / 86400);
            wprintf(L"\tForced log off time(s) : %d\n", pBuf->usrmod0_force_logoff);
            wprintf(L"\tPassword history length : %d\n", pBuf->usrmod0_password_hist_len);
        }
    }
    // Otherwise, print the system error.
    else
    {
        wprintf(L"NetUserModalsGet() failed!\n");
        fwprintf_s(stderr, L"LA system error has occurred : %d\n", nStatus);
    }
    // Free the allocated memory.
    if (pBuf != NULL)
        NetApiBufferFree(pBuf);
    return 0;
}

 

 

결과

해당 함수는 gpedit.msc의 목록 중 
컴퓨터 구성 > Windows 설정 > 보안 설정 > 계정 정책 > 암호 정책 중 일부만 확인 할 수 있음.
전부는 확인하지 못하기에 적합하지 않아서 제외함.

 

 

 


 

 

Registry 를 사용한 확인방법 리서치 (결과 :  일부 사용 가능)

 
로컬그룹 정책의 네트워크 액세스 : 익명 SID/이름 변환 허용 값에 해당하는 registry key는 아래와 같다고함.

 

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\LanManServer\Parameters\RestrictNullSessAccess
 
HKLM\System\CurrentControlSet\Control\Lsa\TurnOffAnonymousBlock
 
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SeCEdit\Reg Values
 

RestrictNullSessAccess 리서치 결과

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\LanManServer\Parameters\RestrictNullSessAccess
해당 경로에 key가 존재하지만 
실제 확인해보니 네트워크 액세스 : 익명 SID/이름 변환 허용 값에 해당하지 않음. 
값을 변경해도 반영되지 않음.
 

TurnOffAnonymousBlock 리서치 결과

HKLM\System\CurrentControlSet\Control\Lsa\TurnOffAnonymousBlock
Default로 해당 경로에 key가 존재하지 않음.
직접 생성해서 Test 진행해봄
TurnOffAnonymousBlock Key 생성 후 값 변경해도 네트워크 액세스 : 익명 SID/이름 변환 허용 값에 반영되지 않음.
생성 후 재기동해도 반영되지 않음.
"gpupdate /force" 명령 적용해도 반영되지 않음.
"gpupdate /force" 명령 적용 후 재기동 해도 반영되지 않음
 
 

SeCEdit\Reg Values 리서치 결과

C:\Windows\INF\sceregvl.inf  파일의 내용과 동일함.
해당 sceregvl.inf 파일 내용 또는 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SeCEdit\Reg Values]
레지스트리 key를 확인해보면 
key가 또 다시 레지스트리를 가리키는데 
이동해보면 gpedit.msc의 내용 중
컴퓨터 구성 > Windows 설정 > 보안 설정 > 로컬 정책 > 보안 옵션 
내용과 일치함.
하지만 이외 내용은 조회 안됨.
 
 

결론

실제로 gpedit 에 해당하는 registry key가 존재하지 않는다고함..
일부는 레지스트리로 존재하지만 
보안 설정의 일부는 (예를 들어, 사용자 권한 , 암호 정책 , 감사 정책 등) 레지스트리 키가 없음.
결론에 참고한 링크

 

 


 

 

secedit 사용 (결과 : 사용 가능)

 
[명령어]
secedit /export /cfg .\test.inf
secedit /export /cfg .\test.inf /areas SECURITYPOLICY
 
[명령어 실행 결과]
[Unicode]
Unicode=yes
 
[System Access]
MinimumPasswordAge = 0
MaximumPasswordAge = 42
MinimumPasswordLength = 0
PasswordComplexity = 0
PasswordHistorySize = 0
LockoutBadCount = 0
RequireLogonToChangePassword = 0
ForceLogoffWhenHourExpire = 0
NewAdministratorName = "Administrator"
NewGuestName = "Guest"
ClearTextPassword = 0
LSAAnonymousNameLookup = 0
EnableAdminAccount = 0
EnableGuestAccount = 0
[Event Audit]
AuditSystemEvents = 0
AuditLogonEvents = 0
AuditObjectAccess = 0
AuditPrivilegeUse = 0
AuditPolicyChange = 0
AuditAccountManage = 0
AuditProcessTracking = 0
AuditDSAccess = 0
AuditAccountLogon = 0
 
[Registry Values]
MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\CachedLogonsCount=1,"10"
MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\ForceUnlockLogon=4,0
MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\PasswordExpiryWarning=4,5
MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\ScRemoveOption=1,"0"
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin=4,5
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorUser=4,3
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\DontDisplayLastUserName=4,0
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableInstallerDetection=4,1
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA=4,1
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableSecureUIAPaths=4,1
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableUIADesktopToggle=4,0
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableVirtualization=4,1
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeCaption=1,""
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeText=7,
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\PromptOnSecureDesktop=4,1
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ScForceOption=4,0
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ShutdownWithoutLogon=4,1
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\UndockWithoutLogon=4,1
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ValidateAdminCodeSignatures=4,0
MACHINE\Software\Policies\Microsoft\Windows\Safer\CodeIdentifiers\AuthenticodeEnabled=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\AuditBaseObjects=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\CrashOnAuditFail=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\DisableDomainCreds=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\EveryoneIncludesAnonymous=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy\Enabled=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\ForceGuest=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\FullPrivilegeAuditing=3,0
MACHINE\System\CurrentControlSet\Control\Lsa\LimitBlankPasswordUse=4,1
MACHINE\System\CurrentControlSet\Control\Lsa\MSV1_0\NTLMMinClientSec=4,536870912
MACHINE\System\CurrentControlSet\Control\Lsa\MSV1_0\NTLMMinServerSec=4,536870912
MACHINE\System\CurrentControlSet\Control\Lsa\NoLMHash=4,1
MACHINE\System\CurrentControlSet\Control\Lsa\RestrictAnonymous=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\RestrictAnonymousSAM=4,1
MACHINE\System\CurrentControlSet\Control\Print\Providers\LanMan Print Services\Servers\AddPrinterDrivers=4,0
MACHINE\System\CurrentControlSet\Control\SecurePipeServers\Winreg\AllowedExactPaths\Machine=7,System\CurrentControlSet\Control\ProductOptions,System\CurrentControlSet\Control\Server Applications,Software\Microsoft\Windows NT\CurrentVersion
MACHINE\System\CurrentControlSet\Control\SecurePipeServers\Winreg\AllowedPaths\Machine=7,System\CurrentControlSet\Control\Print\Printers,System\CurrentControlSet\Services\Eventlog,Software\Microsoft\OLAP Server,Software\Microsoft\Windows NT\CurrentVersion\Print,Software\Microsoft\Windows NT\CurrentVersion\Windows,System\CurrentControlSet\Control\ContentIndex,System\CurrentControlSet\Control\Terminal Server,System\CurrentControlSet\Control\Terminal Server\UserConfig,System\CurrentControlSet\Control\Terminal Server\DefaultUserConfiguration,Software\Microsoft\Windows NT\CurrentVersion\Perflib,System\CurrentControlSet\Services\SysmonLog
MACHINE\System\CurrentControlSet\Control\Session Manager\Kernel\ObCaseInsensitive=4,1
MACHINE\System\CurrentControlSet\Control\Session Manager\Memory Management\ClearPageFileAtShutdown=4,0
MACHINE\System\CurrentControlSet\Control\Session Manager\ProtectionMode=4,1
MACHINE\System\CurrentControlSet\Control\Session Manager\SubSystems\optional=7,
MACHINE\System\CurrentControlSet\Services\LanManServer\Parameters\EnableForcedLogOff=4,1
MACHINE\System\CurrentControlSet\Services\LanManServer\Parameters\EnableSecuritySignature=4,0
MACHINE\System\CurrentControlSet\Services\LanManServer\Parameters\NullSessionPipes=7,
MACHINE\System\CurrentControlSet\Services\LanManServer\Parameters\RequireSecuritySignature=4,0
MACHINE\System\CurrentControlSet\Services\LanManServer\Parameters\RestrictNullSessAccess=4,1
MACHINE\System\CurrentControlSet\Services\LanmanWorkstation\Parameters\EnablePlainTextPassword=4,0
MACHINE\System\CurrentControlSet\Services\LanmanWorkstation\Parameters\EnableSecuritySignature=4,1
MACHINE\System\CurrentControlSet\Services\LanmanWorkstation\Parameters\RequireSecuritySignature=4,0
MACHINE\System\CurrentControlSet\Services\LDAP\LDAPClientIntegrity=4,1
MACHINE\System\CurrentControlSet\Services\Netlogon\Parameters\DisablePasswordChange=4,0
MACHINE\System\CurrentControlSet\Services\Netlogon\Parameters\MaximumPasswordAge=4,30
MACHINE\System\CurrentControlSet\Services\Netlogon\Parameters\RequireSignOrSeal=4,1
MACHINE\System\CurrentControlSet\Services\Netlogon\Parameters\RequireStrongKey=4,1
MACHINE\System\CurrentControlSet\Services\Netlogon\Parameters\SealSecureChannel=4,1
MACHINE\System\CurrentControlSet\Services\Netlogon\Parameters\SignSecureChannel=4,1
 
[Version]
signature="$CHICAGO$"
Revision=1
 

결과

secedit로 생성된 결과를 확인해보면
c:\windows\INF\Sceregvl.inf파일 내용과
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SeCEdit\Reg Values]
레지스트리의 내용과 동일 부분이 있음.
secedit는 해당 2가지 경와는 다른 점으로
gpedit.msc의 내용 중
컴퓨터 구성 > Windows 설정 > 보안 설정 > 로컬 정책 > 보안 옵션 
내용과 일치하고  
컴퓨터 구성 > Windows 설정 > 보안 설정 > 계정 정책 > 암호 정책 
등등 내용도 [System Access] 부분에서 확인가능함.

 

참고

 

 


 

리서치 결과

secedit를 사용하는 것이 가장 적합함.
secedit /export /cfg .\test.inf /areas SECURITYPOLICY
명령어로 파일 생성 후 해당 파일에서 원하는 정보 가져오는 방향으로 진행

c++에서 사용하는 방법으로는

c++로 powershell 실행 및 결과를 받아오는 방식으로 하면 됨.

반응형

'코딩 > C and C++' 카테고리의 다른 글

C/C++ base64 encoding/decoding  (0) 2021.12.22
C++ WMI library사용  (0) 2021.12.22
C++ Windows console 결과 영어로 출력  (0) 2021.12.22
동적라이브러리 (DLL) 코딩 및 적용  (0) 2020.11.30
네임드 파이프 (Named-Pipe)  (0) 2020.10.04