Last active
June 17, 2022 13:09
-
-
Save DarkCoderSc/f40f97be2b179681e76ba366236e6d00 to your computer and use it in GitHub Desktop.
https://unprotect.it/technique/ntqueryinformationprocess/ - (Author: Jean-Pierre LESUEUR (@DarkCoderSc)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
[DllImport("ntdll.dll", SetLastError = true)] | |
static extern int NtQueryInformationProcess( | |
IntPtr processHandle, | |
int processInformationClass, | |
ref IntPtr processInformation, | |
uint processInformationLength, | |
ref IntPtr returnLength | |
); | |
[DllImport("kernel32.dll", SetLastError = true)] | |
static extern IntPtr GetCurrentProcess(); | |
bool isBeingDebugged() | |
{ | |
var ERROR_SUCCESS = 0x0; | |
var ProcessDebugPort = 0x7; | |
IntPtr currProcessHandle = GetCurrentProcess(); | |
if (currProcessHandle == IntPtr.Zero) | |
{ | |
throw new Exception("Could not retrieve current process handle."); | |
} | |
IntPtr returnLength = IntPtr.Zero; | |
IntPtr portNumber = IntPtr.Zero; | |
int ntStatus = NtQueryInformationProcess(currProcessHandle, ProcessDebugPort, ref portNumber, (uint)IntPtr.Size, ref returnLength); | |
if (ntStatus != ERROR_SUCCESS) | |
{ | |
throw new Exception("Could not query information process."); | |
} | |
return (portNumber != IntPtr.Zero); | |
} | |
if (isBeingDebugged()) | |
{ | |
throw new Exception("Debugger Detected !"); | |
} | |
Console.WriteLine("No Debugger Detected :)"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment