21

Purely for academic reasons.

is it possible to programmatically cause a BSOD to occur under windows xp/windows 7 in C#/.NET.

I'm suggesting there's got to be some dirty hack, or some vulnerability to abuse to cause this.

I'm looking for a snippet of code to run that guarantees a BSOD in a finite period of time.

Raynos
  • 166,823
  • 56
  • 351
  • 396
  • I think you would have to do this at a driver level. – Chad Moran Apr 20 '11 at 21:58
  • @ChadMoran if you can interface with a driver and trick it into causing a BSOD then that's fair game. I guess it becomes very machine specific then. – Raynos Apr 20 '11 at 21:59
  • 2
    Well, you can always enable the CrashOnCtrlScroll feature and then programmatically send a Ctrl+ScrollLock+ScrollLock. But that would require you to modify the Windows registry. – Jonas Engström Apr 20 '11 at 22:06
  • @JonasGulle can we modify the registry through c# ? – Raynos Apr 20 '11 at 22:06
  • @Raynos yes, but you have to reboot the machine to make the setting effective. – Jonas Engström Apr 20 '11 at 22:08
  • @JonasGulle you can continue to run C# code on startup again, right? Just like an installer. – Raynos Apr 20 '11 at 22:09
  • 8
    @Jonas: "the CrashOnCtrlScroll *feature*" Awesome. – R. Martinho Fernandes Apr 20 '11 at 22:11
  • @Raynos of course, use the AppInitDLLs key, RunOnce/Run, Startup or any other autorun feature in Windows. [Autoruns](http://technet.microsoft.com/en-us/sysinternals/bb963902) list all executables that is run automatically, just take your pick :) – Jonas Engström Apr 20 '11 at 22:13
  • 2
    @Martinho It's actually very useful to collect a memory dump for post-mortem when you're investigating or reproducing some bug in a kernel driver. – Jonas Engström Apr 20 '11 at 22:16
  • 5
    Presenting a new operating system feature to a large audience usually does the trick. Try finding a old or new beta version of Windows, gather a large audience and call the new API :-) – Danny Varod Apr 20 '11 at 22:31
  • I posted an answer for the same question in python. You should be able to easily port the functionality implemented by this script in C#: https://stackoverflow.com/a/71451311/3970359 – McSebi Mar 16 '22 at 14:48

7 Answers7

29

Killing process "csrss.exe" causes BSOD.

But you need Administrator privileges to do this. I'm not sure there is a way to do this purely with restricted privileges.

EDIT:

Yep, it works alright. I cooked myself a nice little BSOD :)

System.Diagnostics.Process.GetProcessesByName("csrss")[0].Kill();
Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114
4

Use Process.Start to run the SysInternals NotMyFault tool which causes a BSOD (it uses a diver to do this which is the only way).

Killing csrss.exe would also work currently but that that's an undocumented way that might just go away in future version of Windows. NotMyFault uses a documented and clean way to do it.

usr
  • 168,620
  • 35
  • 240
  • 369
  • Critical processes are documented: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocesscritical, although I suppose it's true that it may not be documented that csrss.exe is one. It's possible to use the service control manager to create critical processes so worst comes to worst, you can create your own and then kill it. – Benj Dec 07 '20 at 11:35
0

Create a ping. Kill the program. Instant bsod courtesy of microsoft's tcpip.sys in .net 4.

You'll get a process has locked pages. :)

Bryan
  • 1
0

For all versions of windows you can kill svchost.exe and you will see the BSoD with Critical_Process_Died

0

I once had "problems" under Windows 7, causing BSOD when using the Ping::Send method during debugging. So Debugger::Attach and then pinging might work for you, as well. :)

Yam Marcovic
  • 7,953
  • 1
  • 28
  • 38
0

You could make the process critical and then kill it

using System;
using System.Runtime.InteropServices;

then:

[DllImport("ntdll.dll", SetLastError = true)]
private static extern void RtlSetProcessIsCritical(UInt32 v1, UInt32 v2, UInt32 v3);
System.Diagnostics.Process.EnterDebugMode();
RtlSetProcessIsCritical(1, 0, 0);
System.Diagnostics.Process.GetCurrentProcess().Kill();
iknow
  • 8,358
  • 12
  • 41
  • 68
-11

Over ping your localhost, it will overload your cpu causing a bsod.

Pat
  • 1