Set file permissions to critical
 

 

 

I decided to describe one speciality and practice, as the name says, which will be worth

It is about setting permissions for the process in which the code is running, directed in Critical. The process is simply set to Critical. When shutting down or shutting down, the system crashes (hard shutdown - BSOD), which deletes unsaved data and so on.

The function will be described and added to the header WinAPI.h : WinAPI.h

To describe this Kung Fu, I'll start with the codes.

The whole functionality is hidden in the library ntdll.lib (is part of the header WinAPI.zip).


To load the library content into the resource of our project:


       #pragma comment(lib,"ntdll.lib")



Predefining the functions we will work with:


extern "C" 
{  
   NTSTATUS _stdcall RtlAdjustPrivilege(ULONG,BOOLEAN,BOOLEAN,PBOOLEAN); 
   NTSTATUS _stdcall NtSetInformationProcess(HANDLE,ULONG,PVOID,ULONG); 
} 


Declaration of the enum structure:


enum CriticalPrivilege:ULONG 
{ 
   EnableCriticalPrivilege = 1, // Definuje nastavenie kritickeho procesu.  
   DisableCriticalPrivilege = 0 // Nedefinuje nastavenie kritickeho procesu.  
}; 



Set SeDebugPrivilege rights for the process.
The following function is used to assign rights:


BOOLEAN SetAdjustPrivilege(void)
{
   BOOLEAN status;
   ::RtlAdjustPrivilege(20,TRUE,FALSE,&status);
   return status;
}



To set / cancel Critical rights for a process:


NTSTATUS SetCriticalProcess(CriticalPrivilege isset)
{
   ::NTSTATUS status;
   if(isset == CriticalPrivilege::EnableCriticalPrivilege)
   {
      status = NtSetInformationProcess((HANDLE)-1,0x1d,&isset,sizeof(ULONG));
} else if(isset == CriticalPrivilege::DisableCriticalPrivilege) { status = NtSetInformationProcess((HANDLE)-1,0x1d,&isset,sizeof(ULONG)); }
return status; }

 

 

 

-----------------------------------------------------------------

The whole function is built into the header WinAPI.h WinAPI.h



Source code main.cpp


#include <stdio.h>
#include "convert.h"//https://www.netbot.sk/en/14-blog-headers/86-convert-h-en
#include "winapi.h" //hhttps://www.netbot.sk/en/14-blog-headers/44-winapi-en
int _cdecl main (void) { ::Diall_WinApi::WinApi::GetInstance()->SystemIntegrity(::Diall_WinApi::Privilege::ENABLE);
::Diall_WinApi::WinApi::GetInstance()->WindowOfConsoleApplication(
::Diall_WinApi::SelfWindow::SHOW); ::Diall_WinApi::WinApi::GetInstance()->SetAdjustPrivilege();

while(1) { ::Diall_WinApi::WinApi::GetInstance()->SetCriticalProcess(
::Diall_WinApi::CriticalPrivilege::EnableCriticalPrivilege); }

return 0 ; }