MCPcopy Create free account
hub / github.com/SafeBreach-Labs/PoolParty / HijackProcessHandle

Function HijackProcessHandle

PoolParty/HandleHijacker.cpp:4–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2
3
4std::shared_ptr<HANDLE> HijackProcessHandle(std::wstring wsObjectType, std::shared_ptr<HANDLE> p_hTarget, DWORD dwDesiredAccess)
5{
6 auto pProcessInformation = w_QueryInformation<decltype(NtQueryInformationProcess), HANDLE, PROCESSINFOCLASS>("NtQueryInformationProcess", NtQueryInformationProcess, *p_hTarget, static_cast<PROCESSINFOCLASS>(ProcessHandleInformation));
7 const auto pProcessHandleInformation = reinterpret_cast<PPROCESS_HANDLE_SNAPSHOT_INFORMATION>(pProcessInformation.data());
8
9 std::shared_ptr<HANDLE> p_hDuplicatedObject;
10 std::vector<BYTE> pObjectInformation;
11 PPUBLIC_OBJECT_TYPE_INFORMATION pObjectTypeInformation;
12
13 for (auto i = 0; i < pProcessHandleInformation->NumberOfHandles; i++)
14 {
15 try {
16
17 p_hDuplicatedObject = w_DuplicateHandle(
18 *p_hTarget,
19 pProcessHandleInformation->Handles[i].HandleValue,
20 GetCurrentProcess(),
21 dwDesiredAccess,
22 FALSE,
23 NULL);
24
25 pObjectInformation = w_QueryInformation<decltype(NtQueryObject), HANDLE, OBJECT_INFORMATION_CLASS>("NtQueryObject", NtQueryObject, *p_hDuplicatedObject, ObjectTypeInformation);
26 pObjectTypeInformation = reinterpret_cast<PPUBLIC_OBJECT_TYPE_INFORMATION>(pObjectInformation.data());
27
28 if (wsObjectType != std::wstring(pObjectTypeInformation->TypeName.Buffer)) {
29 continue;
30 }
31
32 return p_hDuplicatedObject;
33 }
34 catch (std::runtime_error){}
35 }
36
37 throw std::runtime_error("Failed to hijack object handle");
38}
39
40std::shared_ptr<HANDLE> HijackWorkerFactoryProcessHandle(std::shared_ptr<HANDLE> p_hTarget)
41{

Calls 1

w_DuplicateHandleFunction · 0.85

Tested by

no test coverage detected