Reputation: 1582
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!
Upvotes: 6
Views: 11801
Reputation: 173
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())
)
Upvotes: 3
Reputation: 9
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...")
Upvotes: 0