gpt4 book ai didi

windows - 使用 CreateRestrictedToken(LUA_TOKEN) 从提升的进程创建低/中进程

转载 作者:行者123 更新时间:2023-12-04 17:59:54 26 4
gpt4 key购买 nike

我正在尝试从提升的过程中创建一个中等或低完整性的过程。我知道还有其他类似的问题,但它们主要集中在使用资源管理器或任务计划程序等解决方法上,我想坚持使用 CreateRestrictedToken() + CreateProcessAsUser() .

我认为一定有可能以某种方式执行此操作,因为我相信 UAC 在您登录时会这样做,但我无法使 token 中的所有内容看起来都像普通的 UAC Medium IL token 。

您可以通过使用 CreateRestrictedToken(hThisProcessToken, LUA_TOKEN, ...) 创建 token 来获得 80%。然后设置 TokenOwner , TokenDefaultDaclTokenIntegrityLevel调用前 CreateProcessAsUser() .

剩下的问题是TokenVirtualizationAllowed , TokenVirtualizationEnabled , TokenElevation , TokenElevationTypeTokenMandatoryPolicy哪里SetTokenInformation()因 ERROR_PRIVILEGE_NOT_HELD 或 ERROR_INVALID_PARAMETER 而失败。

如果我以 SYSTEM @ SECURITY_MANDATORY_SYSTEM_RID 身份运行并启用所有权限而不是管理员 @ SECURITY_MANDATORY_HIGH_RID 那么我可以设置 TokenMandatoryPolicyTokenVirtualization*但设置 TokenElevation*仍然失败! (目前仅在 Windows 8 上测试过)

没有正确的 TokenElevation* token 中的值是一个大问题,因为 Internet Explorer 无法在保护模式下启动,因为它认为 token 已提升。

documentationSetTokenInformation()不说哪个TOKEN_INFORMATION_CLASS可以设置的项目以及需要哪些权限(如果有),我不明白为什么不允许您将这些设置为与 token 的实际完整性级别( TokenIntegrityLevel )相匹配的较低安全值。

使用 Safer API创建一个 SAFER_LEVELID_NORMALUSER token 不会解决任何这些问题,并且还会创建一个比普通 Medium IL token 更受限制的 token 。

我找到了一个人 a similar issue从早期的 Vista/Longhorn 时代开始,从那时起就没有任何变化吗?

最佳答案

function CreateLowProcess(szProcessName: WideString; const IntegritySid: UnicodeString=''): Boolean;
var
hToken: THandle;
hNewToken: THandle;
szIntegritySid: WideString;
pIntegritySid: PSID;
TIL: TOKEN_MANDATORY_LABEL;
ProcInfo: PROCESS_INFORMATION;
startupInfo: TStartupInfo;
const
SE_GROUP_INTEGRITY = $00000020;
TokenIntegrityLevel = 25;
SLowIntegritySid: UnicodeString = 'S-1-16-4096';
SMediumIntegritySid: UnicodeString = 'S-1-16-8192';
SHighIntegritySid: UnicodeString = 'S-1-16-12288';
SSystemIntegritySid: UnicodeString = 'S-1-16-16384';
begin
{
Designing Applications to Run at a Low Integrity Level
http://msdn.microsoft.com/en-us/library/bb625960.aspx

To start a low-integrity process:

- Duplicate the handle of the current process, which is at medium integrity level.
- Use SetTokenInformation to set the integrity level in the access token to Low.
- Use CreateProcessAsUser to create a new process using the handle to the low integrity access token.

CreateProcessAsUser updates the security descriptor in the new child process and the security descriptor
for the access token to match the integrity level of the low-integrity access token.
}

// Low integrity SID
if IntegritySid <> '' then
szIntegritySid := IntegritySid
else
szIntegritySid := SLowIntegritySid;
// szIntegritySid := 'S-1-5-32-545'; //BUILTIN\USERS

ZeroMemory(@startupInfo, sizeof(startupInfo));

if (not OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE or TOKEN_ADJUST_DEFAULT or TOKEN_QUERY or TOKEN_ASSIGN_PRIMARY,
{var}hToken)) then
RaiseLastOSError;
try
if (not DuplicateTokenEx(hToken, 0, nil, SecurityImpersonation, TokenPrimary, {var}hNewToken)) then
RaiseLastOSError;
try
pIntegritySid := StringToSid(szIntegritySid); //free with LocalFree
try
TIL._Label.Attributes := SE_GROUP_INTEGRITY;
TIL._Label.Sid := pIntegritySid;

// Set the process integrity level
if (not SetTokenInformation(hNewToken, TTokenInformationClass(TokenIntegrityLevel), @TIL,
sizeof(TOKEN_MANDATORY_LABEL) + GetLengthSid(pIntegritySid))) then
RaiseLastOSError;

//Create the new process at Low integrity
Result := CreateProcessAsUserW(
hNewToken,
nil,
PWideChar(szProcessName),
nil, //ProcessAttributes
nil, //ThreadAttributes
False, //bInheritHandles
0, //dwCreationFlags
nil, //lpEnvironment
nil, //lpCurrentDirectory
startupInfo,
ProcInfo);
finally
LocalFree(HLOCAL(pIntegritySid));
end;
finally
CloseHandle(hNewToken);
end;
finally
CloseHandle(hToken);
end;
end;

关于windows - 使用 CreateRestrictedToken(LUA_TOKEN) 从提升的进程创建低/中进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36752182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com