I'm writing a logging service that may collect privileges of a process and I'm trying to understand attributes for each process privilege. Let me explain with this code:
HANDLE hToken;
if(OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &hToken))
{
DWORD dwSize = 0;
if(!GetTokenInformation(hToken, TokenPrivileges, NULL, dwSize, &dwSize) &&
::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
BYTE* pb = new (std::nothrow) BYTE[dwSize];
if(pb)
{
TOKEN_PRIVILEGES* pTPs = (TOKEN_PRIVILEGES*)pb;
DWORD dwSize2;
if(GetTokenInformation(hToken, TokenPrivileges, pTPs, dwSize, &dwSize2) &&
dwSize2 <= dwSize)
{
for(UINT i = 0; i < pTPs->PrivilegeCount; i++)
{
//Analyze privilege attributes to understand if it's enabled or disabled?
DWORD dwPrivAttr = pTPs->Privileges[i].Attributes;
//...
}
}
delete[] pb;
}
}
CloseHandle(hToken);
}
So let's see the structure of TOKEN_PRIVILEGES and LUID_AND_ATTRIBUTES
in particular:
#define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
#define SE_PRIVILEGE_ENABLED (0x00000002L)
#define SE_PRIVILEGE_REMOVED (0X00000004L)
#define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
It looks like it is defined as a bitmask, but that brings up the following questions of interpreting these flags:
What is the difference between
ENABLED
andENABLED_BY_DEFAULT
?What is
SE_PRIVILEGE_USED_FOR_ACCESS
and how can it be used?What if both
SE_PRIVILEGE_ENABLED
andSE_PRIVILEGE_REMOVED
are set? Or, reset?I just ran a simple test and for my process the
SeShutdownPrivilege
privilege had those attributes set as0
. So what is that supposed to mean?
I'm more confused over this structure, but I'll keep it at just these points for now.
Thank you!