Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi, all
I recently need to get the integrity level of a process, and I found help from MSDN. The sample code looks like this:
C++
if (GetTokenInformation(hToken, TokenIntegrityLevel, 
         pTIL, dwLengthNeeded, &dwLengthNeeded))
     {
      dwIntegrityLevel = *GetSidSubAuthority(pTIL->Label.Sid, 
        (DWORD)(UCHAR)(*GetSidSubAuthorityCount(pTIL->Label.Sid)-1));
 
      if (dwIntegrityLevel == SECURITY_MANDATORY_LOW_RID)
      {
       // Low Integrity
       wprintf(L"Low Process");
      }
      else if (dwIntegrityLevel >= SECURITY_MANDATORY_MEDIUM_RID && 
           dwIntegrityLevel < SECURITY_MANDATORY_HIGH_RID)
      {
       // Medium Integrity
       wprintf(L"Medium Process");
      }
      else if (dwIntegrityLevel >= SECURITY_MANDATORY_HIGH_RID)
      {
       // High Integrity
       wprintf(L"High Integrity Process");
      }
      else if (dwIntegrityLevel >= SECURITY_MANDATORY_SYSTEM_RID)
      {
       // System Integrity
       wprintf(L"System Integrity Process");
      }
     }

As you all know, SECURITY_MANDATORY_LOW_RID == 0x00001000L, SECURITY_MANDATORY_MEDIUM_RID == 0x00002000L, SECURITY_MANDATORY_HIGH_RID == 0x00003000L, and SECURITY_MANDATORY_SYSTEM_RID == 0x00004000L.

Here is my question:
If this sample code is correct, then what integrity level does process A have if it has the dwIntegrityLevel of 0x00004100L? SECURITY_MANDATORY_HIGH_RID and SECURITY_MANDATORY_SYSTEM_RID? Does it mean that a process have SECURITY_MANDATORY_SYSTEM_RID level also have a SECURITY_MANDATORY_HIGH_RID?

If the sample code is wrong, then what is the right way to determine the integrity level of a process?

Thanks for any of your suggestion.
Posted
Updated 7-Oct-12 21:32pm
v3

1 solution

0x4100 is SECURITY_MANDATORY_SYSTEM_RID + 0x100 (not 0x1000).

See Well-known SIDs[^] in the MSDN.

There is no definition for 0x4100 but one for 0x2100. It seems that an offset of 0x100 can be treated as 'PLUS'.
 
Share this answer
 
Comments
ericchan1336 8-Oct-12 21:31pm    
What I really wanna know is whether the sample code is the right way to determine the integrity level of a process?
Jochen Arndt 9-Oct-12 3:07am    
It is the recommended way because the code is from the MSDN (I assume from the article 'Getting the Integrity Level for an Access Token').

Regarding the 0x100 offset: The code uses if - else conditions with comparisons. So the 0x100 offset is ignored printing 'System Integrity Process' for a level of 0x4100.
ericchan1336 9-Oct-12 3:57am    
If the code is correct, then wprintf(L"System Integrity Process"); will never be executed, since a dwIntegrityLevel which is larger than SECURITY_MANDATORY_SYSTEM_RID is also larger than SECURITY_MANDATORY_HIGH_RID.
Jochen Arndt 9-Oct-12 4:14am    
You are right. I missed that. It must be:
else if (dwIntegrityLevel >= SECURITY_MANDATORY_HIGH_RID &&
dwIntegrityLevel < SECURITY_MANDATORY_SYSTEM_RID)

Another option would be using a switch statement with a masked value:
switch (dwIntegrityLevel & 0x7000)
{
case SECURITY_MANDATORY_LOW_RID : wprintf(L"Low Process"); break;
...
}

You may also add the missing codes SECURITY_MANDATORY_UNTRUSTED_RID (0x0000) and SECURITY_MANDATORY_PROTECTED_PROCESS_RID (0x5000).
ericchan1336 9-Oct-12 4:23am    
That's what I think it should be. Thanks Jochen.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900