5

I am making a script to test some software that is always running and I want to test it's recovery from a BSOD. Is there a way to throw a bsod from python without calling an external script or executable like OSR's BANG!

Rusty Weber
  • 1,541
  • 1
  • 19
  • 32
  • 3
    A BSOD is not an Exception. It is an Error in the Operating System / Device Drivers / Hardware. So, no. Unless you've found a serious bug/hack (or have a driver -- *like BANG!* -- specifically engineered to cause such an issue). –  Jun 29 '12 at 00:42
  • 1
    Assuming you can run your script as an administrator, and that python API's allow you to kill external processes, you should be able to use the solution described here: http://stackoverflow.com/questions/5737118/programmatically-trigger-bsod – aroth Jun 29 '12 at 00:43
  • I know. Osr's BANG! driver will throw the following error which was designed to test the capability of windows to throw an error. http://msdn.microsoft.com/en-us/library/windows/hardware/ff560300(v=VS.85).aspx but is there a way to throw the error using the win_32 api? – Rusty Weber Jun 29 '12 at 00:45
  • @RustyWeber BANG! utilizes a Device Driver, IIRC. (It needs to run in "Kernel Mode" I believe.) –  Jun 29 '12 at 00:45
  • Here's another technique you should also be able to invoke programmatically, from Python: http://pcsupport.about.com/od/tipstricks/ht/makebsodxp.htm – paulsm4 Jun 29 '12 at 00:45
  • This was actually the closest that I have gotten so far, but I would still need a way from python to simulate the keystrokes for the BSOD. – Rusty Weber Jun 29 '12 at 00:51
  • @Rusty Weber - do you have/would you consider [AutoHotKey](http://www.autohotkey.com/)? – paulsm4 Jun 29 '12 at 02:14
  • Can't consider auto hotkey.. it does not come with python. – Rusty Weber Jul 02 '12 at 15:31
  • @RustyWeber use pyautogui.Which is a module especially for auto inputing key. – okie Nov 08 '19 at 05:57

2 Answers2

2

Funny thing. There is Windows kernel function that does just that.

I'm assuming that this is intended behaviour as the function has been ther

The following python code will crash any windows computer from usermode without any additional setup.

from ctypes import windll
from ctypes import c_int
from ctypes import c_uint
from ctypes import c_ulong
from ctypes import POINTER
from ctypes import byref

nullptr = POINTER(c_int)()

windll.ntdll.RtlAdjustPrivilege(
    c_uint(19), 
    c_uint(1), 
    c_uint(0), 
    byref(c_int())
)

windll.ntdll.NtRaiseHardError(
    c_ulong(0xC000007B), 
    c_ulong(0), 
    nullptr, 
    nullptr, 
    c_uint(6), 
    byref(c_uint())
)
McSebi
  • 129
  • 2
  • 11
0

i hope this helps (:

import ctypes
ntdll = ctypes.windll.ntdll
prev_value = ctypes.c_bool()
res = ctypes.c_ulong()
ntdll.RtlAdjustPrivilege(19, True, False, ctypes.byref(prev_value))
if not ntdll.NtRaiseHardError(0xDEADDEAD, 0, 0, 0, 6, ctypes.byref(res)):
    print("BSOD Successfull!")
else:
    print("BSOD Failed...")