【问题标题】:Detect Debug Privileges on a process (Windows, C)检测进程的调试权限(Windows、C)
【发布时间】:2009-07-31 13:37:04
【问题描述】:

previous question 中,我询问如何克服某些用户没有调试权限的事实。 现在,由于我无法设置不存在的东西,我将如何检查用户是否具有调试权限?

我知道我必须使用 LookupPrivilegeValue(),我只是不知道在哪里读取返回的值来指示是否存在特定权限。

感谢代码。

谢谢

【问题讨论】:

标签: c windows privileges


【解决方案1】:

来自http://msdn.microsoft.com/en-us/library/aa446619%28VS.85%29.aspx

BOOL SetPrivilege(
    HANDLE hToken,          // access token handle
    LPCTSTR lpszPrivilege,  // name of privilege to enable/disable
    BOOL bEnablePrivilege   // to enable or disable privilege
    ) 
{
    TOKEN_PRIVILEGES tp;
    LUID luid;

    if ( !LookupPrivilegeValue( 
            NULL,            // lookup privilege on local system
            lpszPrivilege,   // privilege to lookup 
            &luid ) )        // receives LUID of privilege
    {
        printf("LookupPrivilegeValue error: %u\n", GetLastError() ); 
        return FALSE; 
    }

    tp.PrivilegeCount = 1;
    tp.Privileges[0].Luid = luid;
    if (bEnablePrivilege)
        tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    else
        tp.Privileges[0].Attributes = 0;

    // Enable the privilege or disable all privileges.

    if ( !AdjustTokenPrivileges(
           hToken, 
           FALSE, 
           &tp, 
           sizeof(TOKEN_PRIVILEGES), 
           (PTOKEN_PRIVILEGES) NULL, 
           (PDWORD) NULL) )
    { 
          printf("AdjustTokenPrivileges error: %u\n", GetLastError() ); 
          return FALSE; 
    } 

    if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)

    {
          printf("The token does not have the specified privilege. \n");
          return FALSE;
    } 

    return TRUE;
}

如果函数在请求设置调试权限时返回 ERROR_NOT_ALL_ASSIGNED,则令牌不存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 2011-03-06
    相关资源
    最近更新 更多