DuplicateHandle:需要OpenProcess,但访问被拒绝

发布于 2024-09-12 16:48:46 字数 904 浏览 2 评论 0原文

我使用 Windows 挂钩向应用程序发送消息,系统上的每个应用程序都会向应用程序通知有关 Windows 事件的信息。

为了执行消息参数的编组,我使用共享内存。外部进程调用 DuplicateHandle,但用于共享我的应用程序实例的句柄,它将调用 OpenProcess 具有 PROCESS_DUP_HANDLE 权限要求。

实际上,每个应用程序都可以使用此架构发送消息,即使我需要向外部进程启用 SeDebugPrivilege。它实际上是有效的,除了“explorer”进程之外,它没有 SeDebugPrivilege 令牌...

AdjustTokenPrivileges 指出:

AdjustTokenPrivileges 函数无法向访问令牌添加新权限。它只能启用或禁用令牌的现有权限。要确定令牌的权限,请调用 GetTokenInformation 函数。

所以,问题是...如何将 SeDebugPrivilege 令牌添加到“explorer”进程,或者如何允许“explorer”进程调用 OpenProcess(PROCESS_DUP_HANDLE, FALSE, pId)

Using windows hooks I send messages to my application, which is notified about Windows events by every application on the system.

To execute marshal of the message parameters, I use shared memories. The external process calls DuplicateHandle, but for sharing the handle with my application instance, it shall call OpenProcess with PROCESS_DUP_HANDLE privilege requirements.

Actually every application is able to send messages using this architecture, even if I need to enable SeDebugPrivilege to the external process. It actually works, except for the 'explorer' process, which doesn't have the SeDebugPrivilege token...

The documentation of AdjustTokenPrivileges states:

The AdjustTokenPrivileges function cannot add new privileges to the access token. It can only enable or disable the token's existing privileges. To determine the token's privileges, call the GetTokenInformation function.

So, the question is... how to add the SeDebugPrivilege token to 'explorer' process, or alternatively, how to allow 'explorer' process to call OpenProcess(PROCESS_DUP_HANDLE, FALSE, pId)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尹雨沫 2024-09-19 16:48:46

我不明白你为什么不使用命名共享内存。如果您的共享内存对象有名称,则可以在不使用DuplicateHandle的情况下打开该对象。

如果您确实必须使用 DuplicateHandle 并且需要能够在任何进程内部使用 OpenProcess(PROCESS_DUP_HANDLE, FALSE, pId) 我发现您不应该使用 SeDebugPrivilege。相反,您应该向每个人pId授予PROCESS_DUP_HANDLE权限以进行该进程。如果创建进程,则可以指定安全描述符。如果进程已创建,您可以使用 OpenProcessGetSecurityInfo(请参阅 http://msdn.microsoft.com/en-us/library/aa446654.aspx) 和 SetSecurityInfo 修改进程的安全描述符。

要测试此方法,您只需启动 Process Explorer(请参阅 http://technet. microsoft.com/en-us/sysinternals/bb896653.aspx)具有管理权限,打开所选进程(带有 pId 的进程)的安全选项卡并修改其安全描述符。之后,所有进程都可以使用 OpenProcess(PROCESS_DUP_HANDLE, FALSE, pId),而无需启用 SeDebugPrivilege

I don't understand why you don't use named shared memory. If your shared memory objects have a name, then this objects can be opened without the usage of DuplicateHandle.

If you do have to use DuplicateHandle and need be able to use OpenProcess(PROCESS_DUP_HANDLE, FALSE, pId) inside of any process I find that you should don't use SeDebugPrivilege. Instead of that you should grant permission of PROCESS_DUP_HANDLE to everyone for the process with pId. If you create a process you can specify security descriptor. If the process is already created you can use OpenProcess, GetSecurityInfo (see http://msdn.microsoft.com/en-us/library/aa446654.aspx) and SetSecurityInfo to modify security descriptor of the process.

To test this approach you can just start Process Explorer (see http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) with administrative rights, open Security tab of the selected process (process with pId) and modify its security descriptor. After that all processes will be able to use OpenProcess(PROCESS_DUP_HANDLE, FALSE, pId) without to enable SeDebugPrivilege.

探春 2024-09-19 16:48:46

这就是你想要实现的目标吗?

  1. 在“外部”进程中创建共享内存块。
  2. 使用 DuplicateHandle 在应用程序中创建该内存的句柄
  3. 使用窗口消息将句柄值发送到应用程序
  4. 访问应用程序中的共享内存

如果我理解正确,那么您不需要打开您的应用程序的句柄申请过程完全。相反,只需为共享内存块指定一个确定性名称,例如 SharedMem_XXX,其中 XXX 是外部进程的 PID。然后,使用窗口消息将 PID 发送到您的应用程序。然后它可以重新创建该名称并使用它来打开共享内存块。

Is this what you're trying to accomplish?

  1. Create a block of shared memory in the "external" process.
  2. Use DuplicateHandle to create a handle to that memory in your application
  3. Use a window message to send the handle value to your application
  4. Access the shared memory in your application

If I've understood correctly, then you don't need to open the handle to your application process at all. Instead, just give the shared memory block a deterministic name, such as SharedMem_XXX where XXX is the PID of the external process. Then, send the PID to your application using a window message. It can then recreate the name and use it to open the shared memory block.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文