Search code examples
c#.netbsod

Cannot call Process.EnterDebugMode() without causing the Exception


I try to BSOD myself(force blue screen of death) whenever I shutdown my application. Unfortunately when I call Process.EnterDebugMode(); I get an exception: Not all privileges or groups referenced are assigned to the caller.

I write keylogger(that part is done) which suppose to spy on the serviceman who will repair my laptop so I will know if he didn't make any funny business.

[DllImport("ntdll.dll", SetLastError = true)]
private static extern int NtSetInformationProcess(IntPtr hProcess, int processInformationClass, ref int processInformation, int processInformationLength);

public static void Main() {
    int isCritical = 1;  // we want this to be a Critical Process
    int BreakOnTermination = 0x1D;  // value for BreakOnTermination (flag)


    Process.EnterDebugMode();  //acquire Debug Privileges

    // setting the BreakOnTermination = 1 for the current process
    NtSetInformationProcess(Process.GetCurrentProcess().Handle, BreakOnTermination, ref isCritical, sizeof(int));

Solution

  • Your program will need to be running with administrator privileges. Your program will behave as you expect if you do so.

    You can use an app.manifest to easily have your program request privileges with an app.manfest - right click on your project in VS and add an Application manifest file. There's instructions in the generated comments, but you'll need to replace

    <requestedExecutionLevel level="asInvoker" uiAccess="false" />
    

    with

    <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />