How to get a handle to a JobObject without knowing its name?

五迷三道 提交于 2019-12-01 00:55:34
Harry Johnston

OK, doesn't look like there's any supported method. That doesn't mean it can't be done! :-)

To enumerate all the handles in the system, see this question. The sample code here filters the handles and only looks for those belonging to a particular process, but that's easy to change. You might need to enable debug privilege first.

For each handle, duplicate it into your process, then call IsProcessInJob to find out whether it's the right handle or not.

Once you've got that working, check whether SYSTEM_HANDLE.ObjectTypeNumber is always the same for job objects. It probably is (on any given OS, at least) in which case you can drastically increase the efficiency of the code by only checking job object handles.

You could perhaps also filter to just the process running the Secondary Logon service, since this seems to be what creates the job objects for runas.

(If you do get this working, please post code - it could be very useful for future visitors.)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!