Skip to content

Instantly share code, notes, and snippets.

@Unknown6656
Created January 11, 2019 16:04
Show Gist options
  • Save Unknown6656/09325bf1951400071b942a359852eba0 to your computer and use it in GitHub Desktop.
Save Unknown6656/09325bf1951400071b942a359852eba0 to your computer and use it in GitHub Desktop.
Generates a BSoD on Win32- and a kernel-panic on UNIX-Systems
using using System.Runtime.InteropServices;
public static unsafe class HardError
{
[DllImport("ntdll.dll")]
private static extern int RtlAdjustPrivilege(int Privilege, bool bEnablePrivilege, bool IsThreadPrivilege, out bool _);
[DllImport("ntdll.dll")]
private static extern int NtRaiseHardError(uint ErrorStatus, uint NumberOfParameters, uint UnicodeStringParameterMask, void* Parameters, uint ValidResponseOption, out uint _);
private static string Bash(string command)
{
using (Process process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
Arguments = $"-c \"{command.Replace("\"", "\\\"")}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = false,
}
})
{
process.Start();
string result = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return result;
}
}
public static void Raise()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
RtlAdjustPrivilege(19, true, false, out _);
NtRaiseHardError(0xc0000420u, 0, 0, null, 6, out _);
}
else
{
Bash("echo 1 > /proc/sys/kernel/sysrq");
Bash("echo c > /proc/sysrq-trigger");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment