Getting client's process handle from a COM/WinRT Server

This might be the shortest article ever written, so basically there's a private built-in Call Context interface that allows you to get a handle to client's process.
This can be useful for various of things, for example verifying the caller client identity from your server without having a custom interface for that which can actually be exploited
So let's start!
Here's the interface definition:
MIDL_INTERFACE("68C6A1B9-DE39-42C3-8D28-BF40A5126541")
ICallingProcessInfo : public IUnknown
{
public:
virtual STDMETHOD(OpenCallerProcessHandle)(DWORD dwDesiredAccess, HANDLE* handle) = 0;
};And here's the usage:
HANDLE handle;
ComPtr<ICallingProcessInfo> callingProcessInfo; // ComPtr is from WRL, you can use the interface directly instead
CoGetCallContext(__uuidof(ICallingProcessInfo), (void**)callingProcessInfo.GetAddressOf());
callingProcessInfo->OpenCallerProcessHandle(PROCESS_QUERY_LIMITED_INFORMATION, &handle);You can use that handle to get the PID, for example, by using the GetProcessId function
And that's it, bye!
Comments