Rileva privilegi di debug su un processo (Windows, C)
-
06-07-2019 - |
Domanda
in una domanda precedente ho chiesto come superare il fatto che in alcuni utenti i privilegi di debug non esistessero. Ora, poiché non riesco a impostare qualcosa che non esiste, come verificherei se un utente ha i privilegi di debug?
So che devo usare LookupPrivilegeValue (), non riesco proprio a capire dove leggere il valore restituito che indicherebbe se un particolare privilegio è presente o meno.
Il codice è apprezzato.
Grazie
Soluzione
Da http://msdn.microsoft. com / it-it / library / aa446619% 28VS.85% 29.aspx
BOOL SetPrivilege(
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;
}
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
{
printf("The token does not have the specified privilege. \n");
return FALSE;
}
return TRUE;
}
se la funzione restituisce ERROR_NOT_ALL_ASSIGNED quando si richiede di impostare i privilegi di debug, il token non è presente.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow