Search code examples
c#.netvb.netwindowsbsod

It's possible from .Net managed code to cause an arbitrary BSOD?


I wonder whether from .Net managed code, or maybe p/invoking the needed NT dll, if I could generate a BSOD (Blue Screen Of Death) with specific bugcheck-code reason.

I know this is possible from a kernel-mode driver by calling KeBugCheck or KeBugCheckEx methods, but I think there is no way to call those methods from user-mode applications.

Someone could clarify me things, and bring an alternative way (if exists) for managed code?.


Solution

  • I had some code that did exactly that here we go: you might just need ntdll.dll but I used it without installing anything... though the bug check codes don't seem to be the normal types

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.InteropServices;
    using System.IO;
    
    namespace bsod
    {
        class Program
        {
    
    
            private static uint STATUS_ASSERTION_FAILURE = 0xC0000420;
          //  private static uint KMODE_EXEPTION_NOT_HANDLED=0x0000008E;
            static void Main(string[] args) {
    
                while (Console.ReadKey(true).Key == ConsoleKey.W) 
                {
    
                        crash();
    
                }
    
            }
            static void crash()
            {
    
                bool previousValue=false;
               // Console.WriteLine("Adjusting privileges");
                RtlAdjustPrivilege(19, true, false, out previousValue);
               // Console.WriteLine("Triggering BSOD");
                uint oul = 0;
                IntPtr sptr = Marshal.StringToHGlobalAnsi("");
                NtRaiseHardError(STATUS_ASSERTION_FAILURE, 0, 0, IntPtr.Zero, 6, out oul);
    
            }
    
            [DllImport("ntdll.dll")]
            private static extern uint RtlAdjustPrivilege(
    int Privilege,
    bool bEnablePrivilege,
    bool IsThreadPrivilege,
    out bool PreviousValue
    );
    
            [DllImport("ntdll.dll")]
            private static extern uint NtRaiseHardError(
                uint ErrorStatus,
                uint NumberOfParameters,
                uint UnicodeStringParameterMask,
                IntPtr Parameters,
                uint ValidResponseOption,
                out uint Response
            );
    
        }
    }
    

    let me clarify that this can be very dangerous, as you are one step away from an infinite loop constantly crashing your computer...