Hello,
I am working on a review for anti-debugging techniques. So there is this particular API based technique which suggests using ntqueryinformationprocess to acces the process debug flags using run time dynamic linking. Now as per
[msdn] the function takes five arguments however i get an error unless i compile it without any arguments (i also verified by looking up various websites that i was passing the arguments correctly.) But then for a previous method which i was working on had the same problem with NtSetinformationthread. So i simply compiled it with no arguments and later modified the exe in olly to pass the arguments like this
http://adwiteeya.com/blog/one-hell-of-a-debug/. But this isnt working for ntqueryinformationprocess function. I did try looking up the reason but i am not really a programmer so it would be really helpful if somebody can break this down for me. Also i have some other doubts
1. Is the handle to the current process a fixed value ? is italways equal to -2 or -1 by any chance ?
2. I always receive a pointer to ZwQueryInformationProcess or Zwsetinformationthread when looking up NTquery and Ntset. Are they same ? (because after reading about both the version on msdn i couldnt see any diff plus the Zwset worked!) ?
3. one of the parameter that was passed was > &debugFlags. To pass this i modified the code in Olly as
Lea eax,ebp+64 (because the value in hex was 64 below ebp)
push eax
4. Any bugs here :
{
HMODULE hmod;
FARPROC ZwQueryInformationProcess;
int status;
DWORD debugFlag=0;
hmod = LoadLibrary("ntdll.dll");
ZwQueryInformationProcess = GetProcAddress(hmod, "ZwQueryInformationProcess");
status=(_NtQueryInformationProcess) ();
//status = (_NtQueryInformationProcess) (-1, 0xf1, &debugFlag, 4, NULL); // 31 (0xf1)is the enum for DebugProcessFlags
printf("ProcessDebugFlag Returned: %08X\n", debugFlag);
if (debugFlag == 0x00000000) MessageBox(NULL, "Debugger Detected via ProcessDebugFlags", "Debugger Detected", MB_OK);
if (debugFlag == 0x00000001) MessageBox(NULL, "No Debugger Detected", "No Debugger", MB_OK);
}
5. And also after reading on various forums i do realize that ms can change the structure for this function and this might stop working any time... but i did try running this on xp sp2 too... plus when i actually call the function i can see the stack that all the arguments have been passed appropriately!