试图更改 Windows 中互斥对象的所有者
Trying to change owner of mutex object in Windows
我正在尝试更改互斥对象的所有权,但似乎这段代码不起作用,试图将 "Everyone" 设置为所有者,我得到 ERROR_INVALID_OWNER 错误代码,任何想法?
#include <Aclapi.h>
BOOLEAN SetEveryone(HANDLE handle)
{
SID_IDENTIFIER_AUTHORITY Auth = SECURITY_WORLD_SID_AUTHORITY;
PSID pSID = NULL;
if (AllocateAndInitializeSid(
&Auth, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &pSID))
{
if (SetSecurityInfo(
handle,
SE_KERNEL_OBJECT,
OWNER_SECURITY_INFORMATION,
pSID,
NULL,
NULL,
NULL) == ERROR_SUCCESS)
{
printf("success\n");
}
FreeSid(pSID);
}
return TRUE;
}
int main()
{
HANDLE Token;
LUID luid;
TOKEN_PRIVILEGES privs;
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &Token);
LookupPrivilegeValue(NULL, SE_TAKE_OWNERSHIP_NAME, &luid);
privs.PrivilegeCount = 1;
privs.Privileges[0].Luid = luid;
privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (AdjustTokenPrivileges(
Token,
FALSE,
&privs,
sizeof(TOKEN_PRIVILEGES),
NULL,
NULL))
{
HANDLE mutex = CreateMutex(NULL, FALSE, TEXT("test1"));
SetEveryone(mutex);
}
CloseHandle(Token);
return 0;
}
通常,您只能为自己或在您的访问令牌中并设置了 SE_GROUP_OWNER
标志的组设置所有权。
但是,您可以通过启用备份和恢复权限来覆盖此规则。
我正在尝试更改互斥对象的所有权,但似乎这段代码不起作用,试图将 "Everyone" 设置为所有者,我得到 ERROR_INVALID_OWNER 错误代码,任何想法?
#include <Aclapi.h>
BOOLEAN SetEveryone(HANDLE handle)
{
SID_IDENTIFIER_AUTHORITY Auth = SECURITY_WORLD_SID_AUTHORITY;
PSID pSID = NULL;
if (AllocateAndInitializeSid(
&Auth, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &pSID))
{
if (SetSecurityInfo(
handle,
SE_KERNEL_OBJECT,
OWNER_SECURITY_INFORMATION,
pSID,
NULL,
NULL,
NULL) == ERROR_SUCCESS)
{
printf("success\n");
}
FreeSid(pSID);
}
return TRUE;
}
int main()
{
HANDLE Token;
LUID luid;
TOKEN_PRIVILEGES privs;
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &Token);
LookupPrivilegeValue(NULL, SE_TAKE_OWNERSHIP_NAME, &luid);
privs.PrivilegeCount = 1;
privs.Privileges[0].Luid = luid;
privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (AdjustTokenPrivileges(
Token,
FALSE,
&privs,
sizeof(TOKEN_PRIVILEGES),
NULL,
NULL))
{
HANDLE mutex = CreateMutex(NULL, FALSE, TEXT("test1"));
SetEveryone(mutex);
}
CloseHandle(Token);
return 0;
}
通常,您只能为自己或在您的访问令牌中并设置了 SE_GROUP_OWNER
标志的组设置所有权。
但是,您可以通过启用备份和恢复权限来覆盖此规则。