Created
May 27, 2025 11:47
-
-
Save vsl-iil/5179bad6e528bb6c1c89dfe34b8d33c1 to your computer and use it in GitHub Desktop.
Copy of Typical Sequence Of Antidebug Tricks by waleedassar; source: https://waleedassar.blogspot.com/2012/11/hidding-threads-from-debuggers.html
This file contains hidden or 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
| //http://waleedassar.blogspot.com | |
| //http://www.twitter.com/waleedassar | |
| #include "stdafx.h" | |
| #include "windows.h" | |
| #include "iostream.h" | |
| extern "C" | |
| { | |
| int __stdcall ZwSetInformationThread(HANDLE,int,unsigned long*,unsigned long); | |
| int __stdcall ZwQueryInformationProcess(HANDLE,int,unsigned long*,unsigned long,unsigned long*); | |
| } | |
| #define ThreadHideFromDebugger 0x11 | |
| #define ProcessDebugPort 0x7 | |
| #define ProcessDebugObjectHandle 0x1E | |
| #define ProcessDebugFlags 0x1F | |
| int main(int argc, char* argv[]) | |
| { | |
| //------------------------------------ | |
| unsigned long _port_=0; | |
| ZwQueryInformationProcess(GetCurrentProcess(),ProcessDebugPort,&_port_,0x4,0); | |
| if(_port_) | |
| { | |
| MessageBox(0,"BeingDebugged","waliedassar",0); | |
| ExitProcess(-1); | |
| } | |
| //------------------------------------ | |
| unsigned long DbgObjHand=0; | |
| int ret=ZwQueryInformationProcess(GetCurrentProcess(),ProcessDebugObjectHandle,&DbgObjHand,0x4,0); | |
| if(ret>=0 || DbgObjHand) | |
| { | |
| MessageBox(0,"BeingDebugged","waliedassar",0); | |
| ExitProcess(-2); | |
| } | |
| //------------------------------------ | |
| unsigned long DbgFlags=0; | |
| ZwQueryInformationProcess(GetCurrentProcess(),ProcessDebugFlags,&DbgFlags,0x4,0); | |
| if(DbgFlags==0) | |
| { | |
| //Only if Process was spawned by the "DEBUG_ONLY_THIS_PROCESS" flag of | |
| //The "CreateProcess" function i.e. No Child Debugging. | |
| //Does not harm you code, though. | |
| MessageBox(0,"BeingDebugged","waliedassar",0); | |
| ExitProcess(-2); | |
| } | |
| //------------------------------------ | |
| ZwSetInformationThread(GetCurrentThread(),ThreadHideFromDebugger,0,0); | |
| MessageBox(0,"Can you see me under debugger","waliedassar",0); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment