# A Deep Dive into the GetProcessHandleFromHwnd API

Win32k NtUserGetWindowProcessHandle opened target processes with KernelMode access, letting same-integrity or UIAccess callers bypass protection and fully compromise protected processes.

- Payout: Research
- Severity: high
- Program: Microsoft
- Write-up by: James Forshaw
- Disclosed: 2026-02-26
- CVE: CVE-2023-41772
- Write-up quality: 9/10
- Original: https://projectzero.google/2026/02/gphfh-deep-dive.html
- Library page: https://bugbountylibrary.com/r/blog%3Aprojectzero-google-2026-02-gphfh-deep-dive-html
- Tags: area:os domain:desktop impact:privesc impact:rce kind:research platform:research sev:high tech:windows technique:reverse-engineering technique:source-review vuln:access-control vuln:privilege-escalation

**Target:** Win32k NtUserGetWindowProcessHandle / GetProcessHandleFromHwnd API
**Root cause:** The kernel implementation called ObOpenObjectByPointer with AccessMode=KernelMode, skipping all access checks, and the UIPI check could be bypassed by merely having the UIAccess flag set.
**Steps:**
1. Obtain code execution at same-or-higher integrity than target, or with UIAccess flag (e.g. token stealing).
2. Ensure target process has created any window (even message-only, e.g. COM OleMainThreadWndClass).
3. Call `GetProcessHandleFromHwnd(hwnd)` / `NtUserGetWindowProcessHandle(hwnd, PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_VM_OPERATION|PROCESS_DUP_HANDLE)`.
4. Receive a handle to the target process opened with KernelMode access, bypassing protected-process checks.
5. For WerFaultSecure.exe: launch `WerFaultSecure.exe -u -p {PID} -ip {PARENT_PID} -s {SECTION_HANDLE}` with inherited section containing 0xF8, PID, TID; enumerate windows via FindWindowEx/GetWindowThreadProcessId; call GetProcessHandleFromHwnd on the found HWND.
6. Write shellcode into allocated executable memory and redirect an existing jump to execute it.
**How found:** Reading the API docs revealed three inaccurate claims; code archaeology across Vista oleacc.dll hook implementation, Windows 10 1803 Win32k rewrite, and 24H2 changes exposed that ObOpenObjectByPointer used KernelMode access mode, skipping access checks, and that UIAccess alone bypassed UIPI.
**Exploitation:** With a handle granting PROCESS_VM_OPERATION/READ/WRITE/DUP_HANDLE to a Protected TCB process like WerFaultSecure.exe, attacker allocates and writes executable memory and hijacks an existing jump to run shellcode, achieving code execution inside the protected process.
**Escalation:** Compromising a Protected TCB process allows opening any other user process regardless of protection state, escalating to full system compromise.
**Insight:** When an API is reimplemented from user-mode to kernel-mode, check whether the new path uses KernelMode access mode in ObOpenObjectByPointer—this silently skips all object access checks, including protected-process restrictions. Also watch for UIAccess flag short-circuits in UIPI checks.

## Proof of concept (copied exactly from the original report)

**Hook handler duplicating process handle to caller**

```
void HandleHookMessage(CWPSTRUCT *cwp) {
 UINT msg = RegisterWindowMessage(L"WM_OLEACC_HOOK");
 if (cwp->message != msg)
 return;
 WCHAR name[64];
 wParam = cwp->wParam;
 StringCchPrintf(name, _countof(name),
 L"OLEACC_HOOK_SHMEM_%d_%d", wParam,
 cwp->lParam);
 HANDLE mapping = OpenFileMapping(FILE_MAP_READ |
 FILE_MAP_WRITE, FALSE,
 name);
 DWORD* buffer = (DWORD*)MapViewOfFile(mapping,
 FILE_MAP_READ | FILE_MAP_WRITE,
 0, 0, sizeof(DWORD));
 HANDLE caller = OpenProcess(PROCESS_DUP_HANDLE, FALSE,
 cwp->wParam);
 HANDLE current = OpenProcess(PROCESS_DUP_HANDLE |
 PROCESS_VM_OPERATION | PROCESS_VM_READ |
 PROCESS_VM_WRITE | SYNCHRONIZE,
 FALSE, GetCurrentProcessId());
 HANDLE dup;
 DuplicateHandle(CurrentProcess, current, caller, &dup,
 0, 0, DUPLICATE_SAME_ACCESS);
 InterlockedExchange(buffer, (DWORD)dup);
```

**Kernel NtUserGetWindowProcessHandle implementation**

```
HANDLE NtUserGetWindowProcessHandle(HWND hWnd,
 ACCESS_MASK DesiredAccess) {
 WND* wnd = ValidateHwnd(Wnd);
 if (!wnd) {
 return NULL;
 }
 THREADINFO* curr_thread =
 W32GetThreadWin32Thread(KeGetCurrentThread());
 THREADINFO* win_thread = wnd->Thread;;
 if (curr_thread->Desktop != win_thread->Desktop) {
 goto access_denied;
 }

 PROCESSINFO* win_process = win_thread->ppi;
 PROCESSINFO* curr_process = curr_thread->ppi;
 if (gbEnforceUIPI) {
 if (!CheckAccess(curr_process->UIPIInfo,
 win_process->UIPIInfo)) {
 if (!curr_process->HasUiAccessFlag) {
 goto access_denied;
 }
 }
 }
 else if (win_thread->AuthId != curr_thread->AuthId) {
 goto access_denied;
 }
 if (win_thread->TIF_flags & (TIF_SYSTEMTHREAD |
 TIF_CSRSSTHREAD)) {
 goto access_denied;
 }

 KPROCESS process = NULL;
 DWORD process_id = PsGetThreadProcessId(win_thread->KThread);
 PsLookupProcessByProcessId(process_id, &process);
 HANDLE handle = NULL;
 ObOpenObjectByPointer(process, 0, NULL, DesiredAccess,
```

**Commands to disable UIPI feature flags**

```
ViveTool.exe /disable /id:56625134
```

