简体   繁体   English

如何确定进程的完整性级别?

[英]How to determine the integrity level of a process?

I recently needed to get the integrity level of a process, and I found help from MSDN.我最近需要获取进程的完整性级别,我从 MSDN 找到了帮助。 The sample code looks like this:示例代码如下所示:

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
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 ?如果这个示例代码是正确的,那么如果进程 A 的dwIntegrityLevel0x00004100L它的完整性级别是0x00004100L SECURITY_MANDATORY_HIGH_RID and SECURITY_MANDATORY_SYSTEM_RID ? SECURITY_MANDATORY_HIGH_RIDSECURITY_MANDATORY_SYSTEM_RID Does it mean that a process that has the SECURITY_MANDATORY_SYSTEM_RID level also has the SECURITY_MANDATORY_HIGH_RID level?这是否意味着具有SECURITY_MANDATORY_SYSTEM_RID级别的进程也具有SECURITY_MANDATORY_HIGH_RID级别?

If the sample code is wrong, then what is the right way to determine the integrity level of a process?如果示例代码是错误的,那么确定流程完整性级别的正确方法是什么?

Note an equivalent declaration in WinNT.h:请注意 WinNT.h 中的等效声明:

#define SECURITY_MANDATORY_MEDIUM_PLUS_RID  (SECURITY_MANDATORY_MEDIUM_RID + 0x100)

So that sounds like you ran into a process that's SYSTEM_PLUS.所以听起来你遇到了一个 SYSTEM_PLUS 进程。

I would recommend taking a look at the Chrome/Chromium GetCurrentProcessIntegrityLevel implementation that you'll find on https://github.com/chromium/chromium/blob/master/base/process/process_info_win.cc .我建议您查看https://github.com/chromium/chromium/blob/master/base/process/process_info_win.cc上的 Chrome/Chromium GetCurrentProcessIntegrityLevel实现。 This is likely a trustworthy reference.这可能是一个值得信赖的参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM