Is there a way in windows to throw a BSOD on demand from python?
Asked Answered
J

2

6

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!

Jolt answered 29/6, 2012 at 0:39 Comment(9)
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).Holocene
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: #5737618Fanya
I know. Osr's BANG! driver will throw the following error which was designed to test the capability of windows to throw an error. msdn.microsoft.com/en-us/library/windows/hardware/… but is there a way to throw the error using the win_32 api?Jolt
@RustyWeber BANG! utilizes a Device Driver, IIRC. (It needs to run in "Kernel Mode" I believe.)Holocene
Here's another technique you should also be able to invoke programmatically, from Python: pcsupport.about.com/od/tipstricks/ht/makebsodxp.htmGreer
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.Jolt
@Rusty Weber - do you have/would you consider AutoHotKey?Greer
Can't consider auto hotkey.. it does not come with python.Jolt
@RustyWeber use pyautogui.Which is a module especially for auto inputing key.Buran
T
3

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

I'm assuming that this is intended behavior as the function has been there

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())
)
Timbering answered 12/3, 2022 at 16:25 Comment(0)
P
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...")
Psid answered 11/7, 2022 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.