|
原帖地址如下:
http://bbs.125.la/thread-13803945-1-1.html
原来是准备开源的- -不过奈何是用C++写的。在准备移植到易上各种麻烦- -
特别是数据类型上- -于是还是用文字帖把关键技术全部讲出来吧。
1:首先是创建一个普通进程
CreateProcess(NULL,程序路径, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi);
我们需要进程创建后,主线程处于等待状态。阻止其运行代码。
2:打开Token
OpenProcessToken(pi.hProcess, TOKEN_ALL_ACCESS, &hToken)
3:生成新Token数据
TOKEN_MANDATORY_LABEL TokenInfo;
DWORD dwSize = 0;
TokenInfo.Label.Attributes = SE_GROUP_INTEGRITY | SE_GROUP_INTEGRITY_ENABLED;
PSID sid;
SID_IDENTIFIER_AUTHORITY sia = SECURITY_MANDATORY_LABEL_AUTHORITY;
AllocateAndInitializeSid(&sia, 1, SECURITY_MANDATORY_LOW_RID, 0, 0, 0, 0, 0, 0, 0, &sid);
TokenInfo.Label.Sid = sid;
dwSize = sizeof(TokenInfo) + GetLengthSid(sid);
4:设置Token信息
SetTokenInformation(hToken, TokenIntegrityLevel, &TokenInfo, dwSize);
5:关闭内核对象(如果还要获取,就先别做第5步。先看第6步)
ResumeThread(pi.hThread);
CloseHandle(hToken);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
6:获得Token信息
GetTokenInformation(hToken, TokenIntegrityLevel, NULL, 0, &dwNeedSize)【先得到需要多大的缓冲区】
PTOKEN_MANDATORY_LABEL pTokenInfo = (PTOKEN_MANDATORY_LABEL)LocalAlloc(0, dwNeedSize);
GetTokenInformation(hToken, TokenIntegrityLevel, pTokenInfo, dwNeedSize, &dwNeedSize)
7:获得进程级别:
DWORD nIntegrityLevel = *GetSidSubAuthority(pTokenInfo->Label.Sid, (*GetSidSubAuthorityCount(pTokenInfo->Label.Sid) - 1));
switch (nIntegrityLevel)
{
case SECURITY_MANDATORY_LOW_RID:
strLevel = _T("安全模式");
break;
case SECURITY_MANDATORY_MEDIUM_RID:
strLevel = _T("普通用户");
break;
case SECURITY_MANDATORY_HIGH_RID:
strLevel = _T("管理员");
break;
case SECURITY_MANDATORY_SYSTEM_RID:
strLevel = _T("系统");
break;
default:
strLevel = _T("未知");
break;
}
8:跳到第5步
|
评分
-
查看全部评分
|