码迷,mamicode.com
首页 > Windows程序 > 详细

win7下提权代码

时间:2014-12-27 00:12:29      阅读:463      评论:0      收藏:0      [点我收藏+]

标签:

inline BOOL SetPrivilege()
{
    HANDLE hProcess, hToken; 
    TOKEN_PRIVILEGES NewState;
    LUID luidPrivilegeLUID; 
    hProcess = GetCurrentProcess();
    if(!OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken))
        return FALSE;
    if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luidPrivilegeLUID))
        return FALSE;
    NewState.PrivilegeCount = 1;
    NewState.Privileges[0].Luid = luidPrivilegeLUID;
    NewState.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    if(!AdjustTokenPrivileges(hToken, FALSE, &NewState, NULL, NULL, NULL))
        return FALSE;
    return TRUE;
}
bool enableDebugPriv()  
{  
    HANDLE hToken;  
    LUID sedebugnameValue;  
    TOKEN_PRIVILEGES tkp;  
  
    if (!OpenProcessToken(GetCurrentProcess(),  
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {  
        return false;  
    }  
    if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &sedebugnameValue)) 
    {  
        CloseHandle(hToken);  
        return false;  
    }  
    tkp.PrivilegeCount = 1;  
    tkp.Privileges[0].Luid = sedebugnameValue;  
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;  
    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(tkp), NULL, NULL)) 
    {  
        CloseHandle(hToken);  
        return false;  
    }  
    return true;  
} 

 

win7下提权代码

标签:

原文地址:http://www.cnblogs.com/wumac/p/4187702.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!