簡體   English   中英

如何確定進程的完整性級別?

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

我最近需要獲取進程的完整性級別,我從 MSDN 找到了幫助。 示例代碼如下所示:

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");
  }
 }

眾所周知,

SECURITY_MANDATORY_LOW_RID == 0x00001000L
SECURITY_MANDATORY_MEDIUM_RID == 0x00002000L
SECURITY_MANDATORY_HIGH_RID == 0x00003000L
SECURITY_MANDATORY_SYSTEM_RID == 0x00004000L.

這是我的問題:
如果這個示例代碼是正確的,那么如果進程 A 的dwIntegrityLevel0x00004100L它的完整性級別是0x00004100L SECURITY_MANDATORY_HIGH_RIDSECURITY_MANDATORY_SYSTEM_RID 這是否意味着具有SECURITY_MANDATORY_SYSTEM_RID級別的進程也具有SECURITY_MANDATORY_HIGH_RID級別?

如果示例代碼是錯誤的,那么確定流程完整性級別的正確方法是什么?

請注意 WinNT.h 中的等效聲明:

#define SECURITY_MANDATORY_MEDIUM_PLUS_RID  (SECURITY_MANDATORY_MEDIUM_RID + 0x100)

所以聽起來你遇到了一個 SYSTEM_PLUS 進程。

我建議您查看https://github.com/chromium/chromium/blob/master/base/process/process_info_win.cc上的 Chrome/Chromium GetCurrentProcessIntegrityLevel實現。 這可能是一個值得信賴的參考。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM