Alex Rivera | Logout

Why does OpenProcessToken fail with ERROR_ACCESS_DENIED

Asked 2010-01-15T17:33:41.257
14

I'm running a process as a user in the Administrators group, trying to get a process token for another process. The other process is run by a user not in the Administrators group. Here's the gist of the code I'm using. pid in this code represents the process id of the non-admin process. All of this is on Windows XP SP 2 and all on the same machine. No remote access going on here.

HANDLE handle;
HANDLE token;

handle = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,pid);
token = NULL;
OpenProcessToken(handle,TOKEN_DUPLICATE,&token);

Reference for OpenProcess here: http://msdn.microsoft.com/en-us/library/ms684320%28VS.85%29.aspx

Reference for OpenProcessToken here: http://msdn.microsoft.com/en-us/library/aa379295%28VS.85%29.aspx

OpenProcess succeeds, but no matter what I pass for the DesiredAccess argument to OpenProcessToken, it fails and GetLastError() return ERROR_ACCESS_DENIED. I added some code to understand the privileges of the process running this code and to enable as many as possible, as well as to gather information about the process I'm trying to get a token for. That involved requesting more access (READ_CONTROL | ACCESS_SYSTEM_SECURITY in addition to PROCESS_QUERY_INFORMATION) from OpenProcess and calling GetKernelObjectSecurity(handle). Here's what I've got:

current user: PLEASE_T\dbyron (S-1-5-21-3405506234-1792454352-3826119157-1005)
current process: group 0: flags: 0x00000007 sid: S-1-5-21-3405506234-1792454352-3826119157-513 (PLEASE_T\None)
current process: group 1: flags: 0x00000007 sid: S-1-1-0 (\Everyone)
current process: group 2: flags: 0x0000000F sid: S-1-5-32-544 (BUILTIN\Administrators)
current process: group 3: flags: 0x00000007 sid: S-1-5-32-545 (BUILTIN\Users)
current process: gro
Edit
Report

1 Answer

1

Instead of going into details head first, have you gone down the route of elimination ? -- run the process as LOCAL_SYSTEM and see if that does the trick. After all if God can't do it then no one can :P.

answered 2010-01-15T18:53:09.147

Your Answer