Created
May 26, 2023 17:18
-
-
Save puppis42/86efa2e1df71ca5add53bec69b5f7f23 to your computer and use it in GitHub Desktop.
Block terminate current process from unprivileged process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include "aclapi.h" | |
#include <chrono> | |
#include <thread> | |
DWORD ProtectProcess(void) | |
{ | |
HANDLE hProcess = GetCurrentProcess(); | |
PACL pEmptyDacl; | |
DWORD dwErr; | |
pEmptyDacl = (PACL)malloc(sizeof(ACL)); | |
if (!InitializeAcl(pEmptyDacl, sizeof(ACL), ACL_REVISION)) | |
{ | |
dwErr = GetLastError(); | |
} | |
else | |
{ | |
dwErr = SetSecurityInfo(hProcess, SE_KERNEL_OBJECT, | |
DACL_SECURITY_INFORMATION, NULL, NULL, pEmptyDacl, NULL); | |
} | |
free(pEmptyDacl); | |
return dwErr; | |
} | |
int main() | |
{ | |
ShowWindow(GetConsoleWindow(), SW_HIDE); | |
ProtectProcess(); | |
while (true) { | |
std::this_thread::sleep_for(std::chrono::milliseconds(500)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment