Skip to content

Instantly share code, notes, and snippets.

@matterpreter
Created June 24, 2019 18:08
Show Gist options
  • Save matterpreter/719a3eb4bc254992ac390164f52657e3 to your computer and use it in GitHub Desktop.
Save matterpreter/719a3eb4bc254992ac390164f52657e3 to your computer and use it in GitHub Desktop.
Set process to be critical
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace UnkillableTest
{
class Program
{
[DllImport("ntdll.dll", SetLastError = true)]
private static extern void RtlSetProcessIsCritical(uint bNew, uint pbOld, uint bNeedScb);
public static void MakeProcessUnkillable()
{
Process.EnterDebugMode();
RtlSetProcessIsCritical(1, 0, 0);
}
public static void MakeProcessKillable()
{
RtlSetProcessIsCritical(0, 0, 0);
}
static void Main()
{
MakeProcessUnkillable();
Environment.Exit(0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment