// MaverickProbe3.exe — mede o flag BREAK_ON_TERMINATION (processo critico). // Handle ALL_ACCESS + dono igual + TerminateProcess negado + suspend negado // e a assinatura de processo critico: matar derrubaria a VM (bugcheck). // csc /nologo /optimize+ /out:MaverickProbe3.exe MaverickProbe3.cs using System; using System.Diagnostics; using System.Runtime.InteropServices; internal static class MaverickProbe3 { const uint PROCESS_QUERY_LIMITED_INFORMATION = 0x1000; const uint PROCESS_QUERY_INFORMATION = 0x0400; const uint TOKEN_QUERY = 0x0008; const uint TokenUser = 1; // 29 = ProcessBreakOnTermination (ULONG 0/1) const int ProcessBreakOnTermination = 29; // 61 = ProcessProtectionInformation (struct, byte[0]=type, byte[1]=level) const int ProcessProtectionInformation = 61; [DllImport("kernel32.dll", SetLastError = true)] static extern IntPtr OpenProcess(uint access, bool inherit, int pid); [DllImport("kernel32.dll", SetLastError = true)] static extern bool CloseHandle(IntPtr h); [DllImport("advapi32.dll", SetLastError = true)] static extern bool OpenProcessToken(IntPtr p, uint access, out IntPtr t); [DllImport("advapi32.dll", SetLastError = true)] static extern bool GetTokenInformation(IntPtr t, uint cls, IntPtr info, int len, out int ret); [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)] static extern bool ConvertSidToStringSid(IntPtr sid, out IntPtr str); [DllImport("kernel32.dll")] static extern IntPtr LocalFree(IntPtr p); [DllImport("ntdll.dll")] static extern int NtQueryInformationProcess(IntPtr h, int cls, IntPtr buf, int size, out int ret); static string OwnerOf(IntPtr h) { IntPtr token; if (!OpenProcessToken(h, TOKEN_QUERY, out token)) return "?"; IntPtr buf = Marshal.AllocHGlobal(256); try { int ret; if (!GetTokenInformation(token, TokenUser, buf, 256, out ret)) return "?"; IntPtr sid = Marshal.ReadIntPtr(buf); IntPtr str; if (ConvertSidToStringSid(sid, out str)) { string s = Marshal.PtrToStringUni(str); LocalFree(str); return s; } return "?"; } finally { Marshal.FreeHGlobal(buf); CloseHandle(token); } } static string Critical(IntPtr h) { IntPtr buf = Marshal.AllocHGlobal(4); try { Marshal.WriteInt32(buf, 0); int ret; int st = NtQueryInformationProcess(h, ProcessBreakOnTermination, buf, 4, out ret); if (st != 0) return "n/d (0x" + st.ToString("X8") + ")"; int v = Marshal.ReadInt32(buf); return v != 0 ? "CRITICO (matar = BSOD na VM)" : "normal"; } finally { Marshal.FreeHGlobal(buf); } } static string Protection(IntPtr h) { IntPtr buf = Marshal.AllocHGlobal(4); try { Marshal.WriteInt32(buf, 0); int ret; int st = NtQueryInformationProcess(h, ProcessProtectionInformation, buf, 4, out ret); if (st != 0) return "n/d"; byte level = Marshal.ReadByte(buf, 1); byte type = Marshal.ReadByte(buf, 0); return level == 0 ? "NENHUMA" : "PROTEGIDO type=" + type + " level=" + level; } finally { Marshal.FreeHGlobal(buf); } } static void Probe(string name) { Process[] list; try { list = Process.GetProcessesByName(name); } catch { Console.WriteLine(name + ": erro"); return; } if (list.Length == 0) { Console.WriteLine(name + ": nao rodando"); return; } foreach (Process p in list) { IntPtr h = OpenProcess(PROCESS_QUERY_INFORMATION, false, p.Id); string owner = "?", prot = "?", crit = "?"; if (h != IntPtr.Zero) { owner = OwnerOf(h); prot = Protection(h); crit = Critical(h); CloseHandle(h); } else { IntPtr h2 = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, p.Id); if (h2 != IntPtr.Zero) { owner = OwnerOf(h2); prot = Protection(h2); crit = Critical(h2); CloseHandle(h2); } } Console.WriteLine(string.Format("{0,-14} PID {1,-6} critico={2,-22} prot={3,-12} dono={4}", name, p.Id, crit, prot, owner)); p.Dispose(); } } static int Main() { Console.WriteLine("=== MaverickProbe3 ==="); Console.WriteLine("user=" + Environment.UserName + " session=" + Process.GetCurrentProcess().SessionId); Console.WriteLine(); foreach (string n in new[] { "nvstreamer", "nvcontainer", "gs2-agent", "nvmon", "steam", "explorer" }) Probe(n); Console.WriteLine(); Console.WriteLine("leitura: critico=CRITICO significa que o TerminateProcess e bloqueado pelo kernel"); Console.WriteLine(" e que mata-lo derrubaria a VM inteira (CRITICAL_PROCESS_DIED)."); return 0; } }