doug
December 30th, 2003, 00:18
Hello, part of this code is from the Platform SDK, the rest is from something I wrote a few months ago,
http://www.woodmann.net/forum/showpost.php?p=29119&postcount=9
Code:
/* straight from sdk */
BOOL AdjustPrivilege(
HANDLE hToken, // access token handle
LPCTSTR lpszPrivilege, // name of privilege to enable/disable
BOOL bEnablePrivilege // to enable or disable privilege
)
{
TOKEN_PRIVILEGES tp;
LUID luid;
if ( !LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid ) ) // receives LUID of privilege
{
printf("LookupPrivilegeValue error: %u\n", GetLastError() );
return FALSE;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// Enable the privilege or disable all privileges.
if ( !AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL) )
{
printf("AdjustTokenPrivileges error: %u\n", GetLastError() );
return FALSE;
}
return TRUE;
}
/*
Request debug privilege for the current process
otherwise it's not possible to get PROCESS_ALl_ACCESS on services.exe
*/
BOOL SetDebugPrivilege()
{
HANDLE TokHand;
BOOL retval;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &TokHand)==0)
return FALSE;
retval= AdjustPrivilege(TokHand, SE_DEBUG_NAME, TRUE);
CloseHandle(TokHand);
return retval;
}
/* gets handle to services.exe */
HANDLE getServicesProcessHandle(DWORD pid)
{
if (SetDebugPrivilege())
{
return OpenProcess( PROCESS_ALL_ACCESS, FALSE, pid );
}
else
return NULL;
}
Get the service's processID, then use:
Code:
services_hand=getServicesProcessHandle(services_pid)
I can assure you that method works, as I was injecting code into services.exe with an on/off switch to enable/disable the hook.