The following code is really simple. It restricts access to the current process. In this way no other process can open the process handle and for example terminate this process.
var
SD : TJwSecurityDescriptor;
hProcess : TJwProcessHandle;
begin
JwInitWellKnownSIDs;
hProcess := OpenProcess(READ_CONTROL or WRITE_DAC, false, GetCurrentProcessId());
if hProcess <> 0 then
try
SD := TJwSecureGeneralObject.GetSecurityInfo(hProcess,SE_KERNEL_OBJECT, [siDaclSecurityInformation]);
try
SD.DACL.Clear;
SD.DACL.Add(TJwDiscretionaryAccessControlEntryAllow.Create(nil, [], GENERIC_ALL, JwLocalSystemSID));
//allow read access to the current user
SD.DACL.Add(TJwDiscretionaryAccessControlEntryAllow.Create(nil, [], GENERIC_READ, JwSecurityProcessUserSID));
TJwSecureGeneralObject.SetSecurityInfo(hProcess, SE_KERNEL_OBJECT, [siDaclSecurityInformation], SD);
finally
SD.Free;
end;
finally
CloseHandle(hProcess);
end;
end;
However there are some problems:
The only way to prevent a restricted user from terminating the application is to run the process with a foreign account (e.g. CreateProcessAsUser) and make sure that the user is not listed in the DACL. However if this user gets the DEBUG privilege the game is over.
2 Responses
Pablo
25|Nov|2008 1Hi Christian, may you post something about running a process as foreign account and make sure he is not int the DACL? (Like you propose in this article)
Im working in a application for Cyber-Cafes and would be great if my service can’t be stopped/killed (like Anti Virus does)
Thanks in advance.
Christian Wimmer
28|Nov|2008 2Comments are only for questions and remarks about the article.
You should ask this question in an expert forum or contact us directly. For professionals we host a service that you can use to get support. Consider that JEDI API&WSCL are free but our support is not!
Leave a reply