[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M78550R6TZ97C1JW3W2M5574":3,"skill-same:01M78550R6TZ97C1JW3W2M5574":47},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":6,"ownerDescription":31,"updatedAt":32,"install":33,"resources":46},"01M78550R6TZ97C1JW3W2M5574","anti-debugging-techniques",null,"Anti-debugging detection and bypass playbook. Use when reversing protected binaries that detect debuggers via ptrace, PEB flags, timing checks, or signal\u002Fexception handlers on Linux and Windows.","Lord1Egypt\u002Fawesome-skill-forge","Lord1Egypt","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F99746359?v=4","01M7592YDNT0XK9WJ0T2MQVPDN","Mohamed Mounir Ali AL Keshita","01M75GRFNHC8VZNWEB8DKDE433",3,"MIT","https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fcommunity\u002Fskills_sh\u002Fs\u002Fskills-sh_yaklang_hack-skills_anti-debugging-techniques\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: anti-debugging-techniques\ndescription: >-\n  Anti-debugging detection and bypass playbook. Use when reversing protected\n  binaries that detect debuggers via ptrace, PEB flags, timing checks, or\n  signal\u002Fexception handlers on Linux and Windows.\n---\n\n# SKILL: Anti-Debugging Techniques — Detection & Bypass Playbook\n\n> **AI LOAD INSTRUCTION**: Expert anti-debug techniques across Linux and Windows. Covers ptrace, PEB flags, NtQueryInformationProcess, timing attacks, signal-based detection, TLS callbacks, VEH tricks, and all corresponding bypass methods. Base models often miss the distinction between user-mode and kernel-mode detection and the correct patching strategy for each.\n\n## 0. RELATED ROUTING\n\n- [code-obfuscation-deobfuscation](..\u002Fcode-obfuscation-deobfuscation\u002FSKILL.md) when the binary also uses control flow flattening, VM protection, or string encryption\n- [vm-and-bytecode-reverse](..\u002Fvm-and-bytecode-reverse\u002FSKILL.md) when the anti-debug sits inside a custom VM dispatcher\n- [symbolic-execution-tools](..\u002Fsymbolic-execution-tools\u002FSKILL.md) when you want to symbolically skip anti-debug checks entirely\n\n### Advanced Reference\n\nAlso load [ANTI_DEBUG_MATRIX.md](.\u002FANTI_DEBUG_MATRIX.md) when you need:\n- Complete cross-reference matrix of technique × OS × detection method × bypass method\n- Per-technique reliability ratings and false-positive notes\n- Tool compatibility chart (GDB, x64dbg, WinDbg, Frida, ScyllaHide)\n\n### Quick bypass picks\n\n| Detection Class | First Bypass | Backup |\n|---|---|---|\n| ptrace-based (Linux) | `LD_PRELOAD` hook `ptrace()` → return 0 | Kernel module to hide tracer |\n| PEB.BeingDebugged (Windows) | Patch PEB byte at `fs:[0x30]+0x2` | ScyllaHide auto-patch |\n| Timing check (rdtsc) | Conditional BP after rdtsc, fix registers | Frida hook `rdtsc` return |\n| IsDebuggerPresent | NOP the call \u002F hook return 0 | x64dbg built-in hide |\n| INT 2D \u002F UD2 exception | Set VEH to handle gracefully | TitanHide driver |\n\n---\n\n## 1. LINUX ANTI-DEBUG TECHNIQUES\n\n### 1.1 ptrace(PTRACE_TRACEME)\n\nThe classic self-attach: a process calls `ptrace(PTRACE_TRACEME, 0, 0, 0)`. If a debugger is already attached, the call fails (returns -1).\n\n```c\nif (ptrace(PTRACE_TRACEME, 0, 0, 0) == -1) {\n    exit(1); \u002F\u002F debugger detected\n}\n```\n\n**Bypass methods**:\n\n| Method | How |\n|---|---|\n| `LD_PRELOAD` shim | Compile shared lib: `long ptrace(int r, ...) { return 0; }` and set `LD_PRELOAD` |\n| Binary patch | NOP the `ptrace` call or patch return value check |\n| GDB catch | `catch syscall ptrace` → modify `$rax` to 0 on return |\n| Kernel module | Hook `sys_ptrace` to allow multiple tracers |\n\n### 1.2 \u002Fproc\u002Fself\u002Fstatus — TracerPid\n\n```c\nFILE *f = fopen(\"\u002Fproc\u002Fself\u002Fstatus\", \"r\");\n\u002F\u002F parse TracerPid: if non-zero → debugger attached\n```\n\n**Bypass**: Mount a FUSE filesystem over `\u002Fproc\u002Fself`, or `LD_PRELOAD` hook `fopen`\u002F`fread` to filter `TracerPid` to 0.\n\n### 1.3 Timing Checks (rdtsc \u002F clock_gettime)\n\nMeasures elapsed time between two points; debugger single-stepping causes noticeable delay.\n\n```asm\nrdtsc\nmov ebx, eax       ; save low 32 bits\n; ... protected code ...\nrdtsc\nsub eax, ebx\ncmp eax, 0x1000    ; threshold\nja  debugger_detected\n```\n\n**Bypass**: Set hardware breakpoint after second `rdtsc`, modify `eax` to pass the comparison. Or use Frida to replace the timing function.\n\n### 1.4 Signal-Based Detection (SIGTRAP)\n\n```c\nvolatile int caught = 0;\nvoid handler(int sig) { caught = 1; }\nsignal(SIGTRAP, handler);\nraise(SIGTRAP);\nif (!caught) exit(1); \u002F\u002F debugger swallowed the signal\n```\n\nWhen a debugger is attached, `SIGTRAP` is consumed by the debugger rather than delivered to the handler. **Bypass**: In GDB, use `handle SIGTRAP nostop pass` to forward the signal.\n\n### 1.5 \u002Fproc\u002Fself\u002Fmaps & LD_PRELOAD Detection\n\nChecks for injected libraries or memory regions characteristic of debuggers\u002Finstrumentation.\n\n```c\nFILE *f = fopen(\"\u002Fproc\u002Fself\u002Fmaps\", \"r\");\nwhile (fgets(buf, sizeof(buf), f)) {\n    if (strstr(buf, \"frida\") || strstr(buf, \"LD_PRELOAD\"))\n        exit(1);\n}\n```\n\n**Bypass**: Hook `fopen(\"\u002Fproc\u002Fself\u002Fmaps\")` to return a filtered version, or rename Frida's agent library.\n\n### 1.6 Environment Variable Checks\n\nSome protections check for `LD_PRELOAD`, `LINES`, `COLUMNS` (set by GDB's terminal), or debugger-specific env vars.\n\n**Bypass**: Unset suspicious env vars before launch, or hook `getenv()`.\n\n---\n\n## 2. WINDOWS ANTI-DEBUG TECHNIQUES\n\n### 2.1 IsDebuggerPresent \u002F CheckRemoteDebuggerPresent\n\n```c\nif (IsDebuggerPresent()) ExitProcess(1);\n\nBOOL debugged = FALSE;\nCheckRemoteDebuggerPresent(GetCurrentProcess(), &debugged);\nif (debugged) ExitProcess(1);\n```\n\n**Bypass**: Hook `kernel32!IsDebuggerPresent` to return 0, or patch PEB directly.\n\n### 2.2 PEB Flags\n\n| Field | Offset (x64) | Debugged Value | Normal Value |\n|---|---|---|---|\n| `BeingDebugged` | `PEB+0x02` | 1 | 0 |\n| `NtGlobalFlag` | `PEB+0xBC` | `0x70` (FLG_HEAP_*) | 0 |\n| `ProcessHeap.Flags` | Heap+0x40 | `0x40000062` | `0x00000002` |\n| `ProcessHeap.ForceFlags` | Heap+0x44 | `0x40000060` | 0 |\n\n```asm\nmov rax, gs:[0x60]    ; PEB\nmovzx eax, byte [rax+0x02]  ; BeingDebugged\ntest eax, eax\njnz debugger_detected\n```\n\n**Bypass**: Zero all four fields. ScyllaHide does this automatically.\n\n### 2.3 NtQueryInformationProcess\n\n| InfoClass | Value | Debugged Return |\n|---|---|---|\n| `ProcessDebugPort` | 0x07 | Non-zero port |\n| `ProcessDebugObjectHandle` | 0x1E | Valid handle |\n| `ProcessDebugFlags` | 0x1F | 0 (inverted!) |\n\n**Bypass**: Hook `ntdll!NtQueryInformationProcess` to return clean values per info class.\n\n### 2.4 Hardware Breakpoint Detection\n\n```c\nCONTEXT ctx;\nctx.ContextFlags = CONTEXT_DEBUG_REGISTERS;\nGetThreadContext(GetCurrentThread(), &ctx);\nif (ctx.Dr0 || ctx.Dr1 || ctx.Dr2 || ctx.Dr3)\n    ExitProcess(1);\n```\n\n**Bypass**: Hook `GetThreadContext` to zero DR0–DR3, or use `NtSetInformationThread(ThreadHideFromDebugger)` preemptively (ironically, the anti-debug technique itself).\n\n### 2.5 INT 2D \u002F INT 3 \u002F UD2 Exception Tricks\n\n`INT 2D` is the kernel debug service interrupt. Without a debugger, it raises `STATUS_BREAKPOINT`; with a debugger, behavior differs (byte skipping).\n\n```asm\nxor eax, eax\nint 2dh\nnop          ; debugger may skip this byte\n; ... divergent execution path ...\n```\n\n**Bypass**: Handle in VEH or patch the interrupt instruction.\n\n### 2.6 TLS Callbacks\n\nTLS callbacks execute before `main()` \u002F `WinMain()`. Anti-debug checks placed here run before the debugger's initial break.\n\n**Bypass**: In x64dbg, set \"Break on TLS Callbacks\" option. In WinDbg, use `sxe ld` to break on module load.\n\n### 2.7 NtSetInformationThread(ThreadHideFromDebugger)\n\n```c\nNtSetInformationThread(GetCurrentThread(), ThreadHideFromDebugger, NULL, 0);\n```\n\nAfter this call, the thread becomes invisible to the debugger — breakpoints and single-stepping stop working silently.\n\n**Bypass**: Hook `NtSetInformationThread` to NOP when `ThreadInfoClass == 0x11`.\n\n### 2.8 VEH-Based Detection\n\nRegisters a Vectored Exception Handler that checks `EXCEPTION_RECORD` for debugger-specific behavior (single-step flag, guard page violations with debugger semantics).\n\n**Bypass**: Understand the VEH logic and ensure the exception chain behaves identically to non-debugged execution.\n\n---\n\n## 3. ADVANCED MULTI-LAYER TECHNIQUES\n\n### 3.1 Self-Debugging (fork + ptrace)\n\nThe process forks a child that attaches to the parent via ptrace. If an external debugger is already attached, the child's ptrace fails.\n\n```c\npid_t child = fork();\nif (child == 0) {\n    if (ptrace(PTRACE_ATTACH, getppid(), 0, 0) == -1)\n        kill(getppid(), SIGKILL);\n    else\n        ptrace(PTRACE_DETACH, getppid(), 0, 0);\n    _exit(0);\n}\nwait(NULL);\n```\n\n**Bypass**: Patch the `fork()` return or kill\u002Fdetach the watchdog child.\n\n### 3.2 Multi-Process Debugging Detection\n\nParent and child cooperatively check each other's debug state, creating a mutual-watch pattern.\n\n**Bypass**: Attach to both processes (GDB `follow-fork-mode`, or two debugger instances).\n\n### 3.3 Timing-Based with Multiple Checkpoints\n\nDistributes timing checks across multiple functions, comparing cumulative drift. Single patches fail because the total still exceeds threshold.\n\n**Bypass**: Frida `Interceptor.replace` all timing sources (`rdtsc`, `clock_gettime`, `QueryPerformanceCounter`) to return controlled values.\n\n### 3.4 Nanomite \u002F INT3 Patching\n\nOriginal conditional jumps are replaced with `INT3` (0xCC). A parent debugger process handles each `INT3`, evaluates the condition, and sets the child's EIP accordingly.\n\n**Bypass**: Reconstruct the original jump table by tracing all `INT3` handlers, then patch the binary.\n\n---\n\n## 4. COUNTERMEASURE TOOLS\n\n| Tool | Platform | Capability |\n|---|---|---|\n| **ScyllaHide** | Windows (x64dbg\u002FIDA\u002FOllyDbg) | Auto-patches PEB, hooks NtQuery*, hides threads, fixes timing |\n| **TitanHide** | Windows (kernel driver) | Kernel-level hiding for all user-mode checks |\n| **Frida** | Cross-platform | Script-based hooking of any function, timing spoofing |\n| **LD_PRELOAD shims** | Linux | Replace ptrace, getenv, fopen at load time |\n| **GDB scripts** | Linux | `catch syscall`, conditional BP, register fixup |\n| **Qiling** | Cross-platform | Full-system emulation, bypass all hardware checks |\n\n---\n\n## 5. SYSTEMATIC BYPASS METHODOLOGY\n\n```\nStep 1: Static analysis — identify anti-debug calls\n  └─ Search for: ptrace, IsDebuggerPresent, NtQuery, rdtsc,\n     GetTickCount, SIGTRAP, INT 2D, TLS directory entries\n\nStep 2: Classify each check\n  ├─ API-based → hook or patch the call\n  ├─ Flag-based → patch PEB\u002Fproc fields\n  ├─ Timing-based → spoof time source\n  ├─ Exception-based → forward\u002Fhandle exception correctly\n  └─ Multi-process → handle both processes\n\nStep 3: Apply bypass (order matters)\n  1. Load ScyllaHide \u002F set LD_PRELOAD (covers 80% of checks)\n  2. Handle TLS callbacks (break before main)\n  3. Patch remaining custom checks (Frida or binary patch)\n  4. Verify: run with breakpoints, confirm no premature exit\n\nStep 4: Validate bypass completeness\n  └─ Set BP on ExitProcess\u002Fexit\u002F_exit — if hit unexpectedly,\n     a check was missed → trace back from exit call\n```\n\n---\n\n## 6. DECISION TREE\n\n```\nBinary exits\u002Fcrashes under debugger?\n│\n├─ Crashes immediately before main?\n│  └─ TLS callback anti-debug\n│     └─ Enable TLS callback breaking in debugger\n│\n├─ Crashes at startup?\n│  ├─ Linux: check for ptrace(TRACEME)\n│  │  └─ LD_PRELOAD hook or NOP patch\n│  └─ Windows: check IsDebuggerPresent \u002F PEB\n│     └─ ScyllaHide or manual PEB patch\n│\n├─ Crashes after some execution?\n│  ├─ Consistent crash point → API-based check\n│  │  ├─ NtQueryInformationProcess → hook return values\n│  │  ├─ \u002Fproc\u002Fself\u002Fstatus → filter TracerPid\n│  │  └─ Hardware BP detection → hook GetThreadContext\n│  │\n│  ├─ Variable crash point → timing-based check\n│  │  └─ Hook rdtsc \u002F QueryPerformanceCounter\n│  │\n│  └─ Crash on breakpoint hit → exception-based check\n│     ├─ INT 2D \u002F INT 3 trick → handle in VEH\n│     └─ SIGTRAP handler → GDB: handle SIGTRAP pass\n│\n├─ Debugger loses control silently?\n│  └─ ThreadHideFromDebugger\n│     └─ Hook NtSetInformationThread\n│\n├─ Child process detects and kills parent?\n│  └─ Self-debugging (fork+ptrace)\n│     └─ Patch fork() or handle both processes\n│\n└─ All basic bypasses applied but still detected?\n   └─ Multi-layer \u002F custom checks\n      ├─ Use Frida for comprehensive API hooking\n      ├─ Full emulation with Qiling\n      └─ Trace all calls to exit\u002Fabort to find remaining checks\n```\n\n---\n\n## 7. CTF & REAL-WORLD PATTERNS\n\n### Common CTF Anti-Debug Patterns\n\n| Pattern | Frequency | Quick Bypass |\n|---|---|---|\n| Single `ptrace(TRACEME)` | Very common | `LD_PRELOAD` one-liner |\n| `IsDebuggerPresent` + `NtGlobalFlag` | Common | ScyllaHide |\n| rdtsc timing in loop | Moderate | Patch comparison threshold |\n| signal(SIGTRAP) + raise | Moderate | GDB signal forwarding |\n| fork + ptrace watchdog | Rare but tricky | Kill child or patch fork |\n| Nanomite INT3 replacement | Rare (advanced) | Reconstruct jump table |\n\n### Real-World Protections\n\n| Protector | Primary Anti-Debug | Recommended Tool |\n|---|---|---|\n| VMProtect | PEB + timing + driver-level | TitanHide + ScyllaHide |\n| Themida | Multi-layer PEB + SEH + timing | ScyllaHide + manual patches |\n| Enigma Protector | IsDebuggerPresent + CRC checks | x64dbg + ScyllaHide |\n| UPX (custom) | Usually none (just packing) | Standard unpack |\n| Custom (malware) | Varies widely | Frida + Qiling for analysis |\n\n---\n\n## 8. QUICK REFERENCE — BYPASS CHEAT SHEET\n\n### Linux One-Liners\n\n```bash\n# LD_PRELOAD anti-ptrace\necho 'long ptrace(int r, ...) { return 0; }' > \u002Ftmp\u002Fap.c\ngcc -shared -o \u002Ftmp\u002Fap.so \u002Ftmp\u002Fap.c\nLD_PRELOAD=\u002Ftmp\u002Fap.so .\u002Ftarget\n\n# GDB: catch and bypass ptrace\n(gdb) catch syscall ptrace\n(gdb) commands\n> set $rax = 0\n> continue\n> end\n```\n\n### Frida Anti-Debug Bypass (Cross-Platform)\n\n```javascript\n\u002F\u002F Hook IsDebuggerPresent (Windows)\nInterceptor.replace(\n  Module.getExportByName('kernel32.dll', 'IsDebuggerPresent'),\n  new NativeCallback(() => 0, 'int', [])\n);\n\n\u002F\u002F Hook ptrace (Linux)\nInterceptor.replace(\n  Module.getExportByName(null, 'ptrace'),\n  new NativeCallback(() => 0, 'long', ['int', 'int', 'pointer', 'pointer'])\n);\n\n\u002F\u002F Timing spoof\nInterceptor.attach(Module.getExportByName(null, 'clock_gettime'), {\n  onLeave(retval) {\n    \u002F\u002F manipulate timespec to hide debugger delay\n  }\n});\n```\n\n### x64dbg ScyllaHide Quick Setup\n\n1. Plugins → ScyllaHide → Options\n2. Check: PEB BeingDebugged, NtGlobalFlag, HeapFlags\n3. Check: NtQueryInformationProcess (all classes)\n4. Check: NtSetInformationThread (HideFromDebugger)\n5. Check: GetTickCount, QueryPerformanceCounter\n6. Apply → restart debugging session\n","# SKILL: Anti-Debugging Techniques — Detection & Bypass Playbook\n\n> **AI LOAD INSTRUCTION**: Expert anti-debug techniques across Linux and Windows. Covers ptrace, PEB flags, NtQueryInformationProcess, timing attacks, signal-based detection, TLS callbacks, VEH tricks, and all corresponding bypass methods. Base models often miss the distinction between user-mode and kernel-mode detection and the correct patching strategy for each.\n\n## 0. RELATED ROUTING\n\n- [code-obfuscation-deobfuscation](..\u002Fcode-obfuscation-deobfuscation\u002FSKILL.md) when the binary also uses control flow flattening, VM protection, or string encryption\n- [vm-and-bytecode-reverse](..\u002Fvm-and-bytecode-reverse\u002FSKILL.md) when the anti-debug sits inside a custom VM dispatcher\n- [symbolic-execution-tools](..\u002Fsymbolic-execution-tools\u002FSKILL.md) when you want to symbolically skip anti-debug checks entirely\n\n### Advanced Reference\n\nAlso load [ANTI_DEBUG_MATRIX.md](.\u002FANTI_DEBUG_MATRIX.md) when you need:\n- Complete cross-reference matrix of technique × OS × detection method × bypass method\n- Per-technique reliability ratings and false-positive notes\n- Tool compatibility chart (GDB, x64dbg, WinDbg, Frida, ScyllaHide)\n\n### Quick bypass picks\n\n| Detection Class | First Bypass | Backup |\n|---|---|---|\n| ptrace-based (Linux) | `LD_PRELOAD` hook `ptrace()` → return 0 | Kernel module to hide tracer |\n| PEB.BeingDebugged (Windows) | Patch PEB byte at `fs:[0x30]+0x2` | ScyllaHide auto-patch |\n| Timing check (rdtsc) | Conditional BP after rdtsc, fix registers | Frida hook `rdtsc` return |\n| IsDebuggerPresent | NOP the call \u002F hook return 0 | x64dbg built-in hide |\n| INT 2D \u002F UD2 exception | Set VEH to handle gracefully | TitanHide driver |\n\n---\n\n## 1. LINUX ANTI-DEBUG TECHNIQUES\n\n### 1.1 ptrace(PTRACE_TRACEME)\n\nThe classic self-attach: a process calls `ptrace(PTRACE_TRACEME, 0, 0, 0)`. If a debugger is already attached, the call fails (returns -1).\n\n```c\nif (ptrace(PTRACE_TRACEME, 0, 0, 0) == -1) {\n    exit(1); \u002F\u002F debugger detected\n}\n```\n\n**Bypass methods**:\n\n| Method | How |\n|---|---|\n| `LD_PRELOAD` shim | Compile shared lib: `long ptrace(int r, ...) { return 0; }` and set `LD_PRELOAD` |\n| Binary patch | NOP the `ptrace` call or patch return value check |\n| GDB catch | `catch syscall ptrace` → modify `$rax` to 0 on return |\n| Kernel module | Hook `sys_ptrace` to allow multiple tracers |\n\n### 1.2 \u002Fproc\u002Fself\u002Fstatus — TracerPid\n\n```c\nFILE *f = fopen(\"\u002Fproc\u002Fself\u002Fstatus\", \"r\");\n\u002F\u002F parse TracerPid: if non-zero → debugger attached\n```\n\n**Bypass**: Mount a FUSE filesystem over `\u002Fproc\u002Fself`, or `LD_PRELOAD` hook `fopen`\u002F`fread` to filter `TracerPid` to 0.\n\n### 1.3 Timing Checks (rdtsc \u002F clock_gettime)\n\nMeasures elapsed time between two points; debugger single-stepping causes noticeable delay.\n\n```asm\nrdtsc\nmov ebx, eax       ; save low 32 bits\n; ... protected code ...\nrdtsc\nsub eax, ebx\ncmp eax, 0x1000    ; threshold\nja  debugger_detected\n```\n\n**Bypass**: Set hardware breakpoint after second `rdtsc`, modify `eax` to pass the comparison. Or use Frida to replace the timing function.\n\n### 1.4 Signal-Based Detection (SIGTRAP)\n\n```c\nvolatile int caught = 0;\nvoid handler(int sig) { caught = 1; }\nsignal(SIGTRAP, handler);\nraise(SIGTRAP);\nif (!caught) exit(1); \u002F\u002F debugger swallowed the signal\n```\n\nWhen a debugger is attached, `SIGTRAP` is consumed by the debugger rather than delivered to the handler. **Bypass**: In GDB, use `handle SIGTRAP nostop pass` to forward the signal.\n\n### 1.5 \u002Fproc\u002Fself\u002Fmaps & LD_PRELOAD Detection\n\nChecks for injected libraries or memory regions characteristic of debuggers\u002Finstrumentation.\n\n```c\nFILE *f = fopen(\"\u002Fproc\u002Fself\u002Fmaps\", \"r\");\nwhile (fgets(buf, sizeof(buf), f)) {\n    if (strstr(buf, \"frida\") || strstr(buf, \"LD_PRELOAD\"))\n        exit(1);\n}\n```\n\n**Bypass**: Hook `fopen(\"\u002Fproc\u002Fself\u002Fmaps\")` to return a filtered version, or rename Frida's agent library.\n\n### 1.6 Environment Variable Checks\n\nSome protections check for `LD_PRELOAD`, `LINES`, `COLUMNS` (set by GDB's terminal), or debugger-specific env vars.\n\n**Bypass**: Unset suspicious env vars before launch, or hook `getenv()`.\n\n---\n\n## 2. WINDOWS ANTI-DEBUG TECHNIQUES\n\n### 2.1 IsDebuggerPresent \u002F CheckRemoteDebuggerPresent\n\n```c\nif (IsDebuggerPresent()) ExitProcess(1);\n\nBOOL debugged = FALSE;\nCheckRemoteDebuggerPresent(GetCurrentProcess(), &debugged);\nif (debugged) ExitProcess(1);\n```\n\n**Bypass**: Hook `kernel32!IsDebuggerPresent` to return 0, or patch PEB directly.\n\n### 2.2 PEB Flags\n\n| Field | Offset (x64) | Debugged Value | Normal Value |\n|---|---|---|---|\n| `BeingDebugged` | `PEB+0x02` | 1 | 0 |\n| `NtGlobalFlag` | `PEB+0xBC` | `0x70` (FLG_HEAP_*) | 0 |\n| `ProcessHeap.Flags` | Heap+0x40 | `0x40000062` | `0x00000002` |\n| `ProcessHeap.ForceFlags` | Heap+0x44 | `0x40000060` | 0 |\n\n```asm\nmov rax, gs:[0x60]    ; PEB\nmovzx eax, byte [rax+0x02]  ; BeingDebugged\ntest eax, eax\njnz debugger_detected\n```\n\n**Bypass**: Zero all four fields. ScyllaHide does this automatically.\n\n### 2.3 NtQueryInformationProcess\n\n| InfoClass | Value | Debugged Return |\n|---|---|---|\n| `ProcessDebugPort` | 0x07 | Non-zero port |\n| `ProcessDebugObjectHandle` | 0x1E | Valid handle |\n| `ProcessDebugFlags` | 0x1F | 0 (inverted!) |\n\n**Bypass**: Hook `ntdll!NtQueryInformationProcess` to return clean values per info class.\n\n### 2.4 Hardware Breakpoint Detection\n\n```c\nCONTEXT ctx;\nctx.ContextFlags = CONTEXT_DEBUG_REGISTERS;\nGetThreadContext(GetCurrentThread(), &ctx);\nif (ctx.Dr0 || ctx.Dr1 || ctx.Dr2 || ctx.Dr3)\n    ExitProcess(1);\n```\n\n**Bypass**: Hook `GetThreadContext` to zero DR0–DR3, or use `NtSetInformationThread(ThreadHideFromDebugger)` preemptively (ironically, the anti-debug technique itself).\n\n### 2.5 INT 2D \u002F INT 3 \u002F UD2 Exception Tricks\n\n`INT 2D` is the kernel debug service interrupt. Without a debugger, it raises `STATUS_BREAKPOINT`; with a debugger, behavior differs (byte skipping).\n\n```asm\nxor eax, eax\nint 2dh\nnop          ; debugger may skip this byte\n; ... divergent execution path ...\n```\n\n**Bypass**: Handle in VEH or patch the interrupt instruction.\n\n### 2.6 TLS Callbacks\n\nTLS callbacks execute before `main()` \u002F `WinMain()`. Anti-debug checks placed here run before the debugger's initial break.\n\n**Bypass**: In x64dbg, set \"Break on TLS Callbacks\" option. In WinDbg, use `sxe ld` to break on module load.\n\n### 2.7 NtSetInformationThread(ThreadHideFromDebugger)\n\n```c\nNtSetInformationThread(GetCurrentThread(), ThreadHideFromDebugger, NULL, 0);\n```\n\nAfter this call, the thread becomes invisible to the debugger — breakpoints and single-stepping stop working silently.\n\n**Bypass**: Hook `NtSetInformationThread` to NOP when `ThreadInfoClass == 0x11`.\n\n### 2.8 VEH-Based Detection\n\nRegisters a Vectored Exception Handler that checks `EXCEPTION_RECORD` for debugger-specific behavior (single-step flag, guard page violations with debugger semantics).\n\n**Bypass**: Understand the VEH logic and ensure the exception chain behaves identically to non-debugged execution.\n\n---\n\n## 3. ADVANCED MULTI-LAYER TECHNIQUES\n\n### 3.1 Self-Debugging (fork + ptrace)\n\nThe process forks a child that attaches to the parent via ptrace. If an external debugger is already attached, the child's ptrace fails.\n\n```c\npid_t child = fork();\nif (child == 0) {\n    if (ptrace(PTRACE_ATTACH, getppid(), 0, 0) == -1)\n        kill(getppid(), SIGKILL);\n    else\n        ptrace(PTRACE_DETACH, getppid(), 0, 0);\n    _exit(0);\n}\nwait(NULL);\n```\n\n**Bypass**: Patch the `fork()` return or kill\u002Fdetach the watchdog child.\n\n### 3.2 Multi-Process Debugging Detection\n\nParent and child cooperatively check each other's debug state, creating a mutual-watch pattern.\n\n**Bypass**: Attach to both processes (GDB `follow-fork-mode`, or two debugger instances).\n\n### 3.3 Timing-Based with Multiple Checkpoints\n\nDistributes timing checks across multiple functions, comparing cumulative drift. Single patches fail because the total still exceeds threshold.\n\n**Bypass**: Frida `Interceptor.replace` all timing sources (`rdtsc`, `clock_gettime`, `QueryPerformanceCounter`) to return controlled values.\n\n### 3.4 Nanomite \u002F INT3 Patching\n\nOriginal conditional jumps are replaced with `INT3` (0xCC). A parent debugger process handles each `INT3`, evaluates the condition, and sets the child's EIP accordingly.\n\n**Bypass**: Reconstruct the original jump table by tracing all `INT3` handlers, then patch the binary.\n\n---\n\n## 4. COUNTERMEASURE TOOLS\n\n| Tool | Platform | Capability |\n|---|---|---|\n| **ScyllaHide** | Windows (x64dbg\u002FIDA\u002FOllyDbg) | Auto-patches PEB, hooks NtQuery*, hides threads, fixes timing |\n| **TitanHide** | Windows (kernel driver) | Kernel-level hiding for all user-mode checks |\n| **Frida** | Cross-platform | Script-based hooking of any function, timing spoofing |\n| **LD_PRELOAD shims** | Linux | Replace ptrace, getenv, fopen at load time |\n| **GDB scripts** | Linux | `catch syscall`, conditional BP, register fixup |\n| **Qiling** | Cross-platform | Full-system emulation, bypass all hardware checks |\n\n---\n\n## 5. SYSTEMATIC BYPASS METHODOLOGY\n\n```\nStep 1: Static analysis — identify anti-debug calls\n  └─ Search for: ptrace, IsDebuggerPresent, NtQuery, rdtsc,\n     GetTickCount, SIGTRAP, INT 2D, TLS directory entries\n\nStep 2: Classify each check\n  ├─ API-based → hook or patch the call\n  ├─ Flag-based → patch PEB\u002Fproc fields\n  ├─ Timing-based → spoof time source\n  ├─ Exception-based → forward\u002Fhandle exception correctly\n  └─ Multi-process → handle both processes\n\nStep 3: Apply bypass (order matters)\n  1. Load ScyllaHide \u002F set LD_PRELOAD (covers 80% of checks)\n  2. Handle TLS callbacks (break before main)\n  3. Patch remaining custom checks (Frida or binary patch)\n  4. Verify: run with breakpoints, confirm no premature exit\n\nStep 4: Validate bypass completeness\n  └─ Set BP on ExitProcess\u002Fexit\u002F_exit — if hit unexpectedly,\n     a check was missed → trace back from exit call\n```\n\n---\n\n## 6. DECISION TREE\n\n```\nBinary exits\u002Fcrashes under debugger?\n│\n├─ Crashes immediately before main?\n│  └─ TLS callback anti-debug\n│     └─ Enable TLS callback breaking in debugger\n│\n├─ Crashes at startup?\n│  ├─ Linux: check for ptrace(TRACEME)\n│  │  └─ LD_PRELOAD hook or NOP patch\n│  └─ Windows: check IsDebuggerPresent \u002F PEB\n│     └─ ScyllaHide or manual PEB patch\n│\n├─ Crashes after some execution?\n│  ├─ Consistent crash point → API-based check\n│  │  ├─ NtQueryInformationProcess → hook return values\n│  │  ├─ \u002Fproc\u002Fself\u002Fstatus → filter TracerPid\n│  │  └─ Hardware BP detection → hook GetThreadContext\n│  │\n│  ├─ Variable crash point → timing-based check\n│  │  └─ Hook rdtsc \u002F QueryPerformanceCounter\n│  │\n│  └─ Crash on breakpoint hit → exception-based check\n│     ├─ INT 2D \u002F INT 3 trick → handle in VEH\n│     └─ SIGTRAP handler → GDB: handle SIGTRAP pass\n│\n├─ Debugger loses control silently?\n│  └─ ThreadHideFromDebugger\n│     └─ Hook NtSetInformationThread\n│\n├─ Child process detects and kills parent?\n│  └─ Self-debugging (fork+ptrace)\n│     └─ Patch fork() or handle both processes\n│\n└─ All basic bypasses applied but still detected?\n   └─ Multi-layer \u002F custom checks\n      ├─ Use Frida for comprehensive API hooking\n      ├─ Full emulation with Qiling\n      └─ Trace all calls to exit\u002Fabort to find remaining checks\n```\n\n---\n\n## 7. CTF & REAL-WORLD PATTERNS\n\n### Common CTF Anti-Debug Patterns\n\n| Pattern | Frequency | Quick Bypass |\n|---|---|---|\n| Single `ptrace(TRACEME)` | Very common | `LD_PRELOAD` one-liner |\n| `IsDebuggerPresent` + `NtGlobalFlag` | Common | ScyllaHide |\n| rdtsc timing in loop | Moderate | Patch comparison threshold |\n| signal(SIGTRAP) + raise | Moderate | GDB signal forwarding |\n| fork + ptrace watchdog | Rare but tricky | Kill child or patch fork |\n| Nanomite INT3 replacement | Rare (advanced) | Reconstruct jump table |\n\n### Real-World Protections\n\n| Protector | Primary Anti-Debug | Recommended Tool |\n|---|---|---|\n| VMProtect | PEB + timing + driver-level | TitanHide + ScyllaHide |\n| Themida | Multi-layer PEB + SEH + timing | ScyllaHide + manual patches |\n| Enigma Protector | IsDebuggerPresent + CRC checks | x64dbg + ScyllaHide |\n| UPX (custom) | Usually none (just packing) | Standard unpack |\n| Custom (malware) | Varies widely | Frida + Qiling for analysis |\n\n---\n\n## 8. QUICK REFERENCE — BYPASS CHEAT SHEET\n\n### Linux One-Liners\n\n```bash\n# LD_PRELOAD anti-ptrace\necho 'long ptrace(int r, ...) { return 0; }' > \u002Ftmp\u002Fap.c\ngcc -shared -o \u002Ftmp\u002Fap.so \u002Ftmp\u002Fap.c\nLD_PRELOAD=\u002Ftmp\u002Fap.so .\u002Ftarget\n\n# GDB: catch and bypass ptrace\n(gdb) catch syscall ptrace\n(gdb) commands\n> set $rax = 0\n> continue\n> end\n```\n\n### Frida Anti-Debug Bypass (Cross-Platform)\n\n```javascript\n\u002F\u002F Hook IsDebuggerPresent (Windows)\nInterceptor.replace(\n  Module.getExportByName('kernel32.dll', 'IsDebuggerPresent'),\n  new NativeCallback(() => 0, 'int', [])\n);\n\n\u002F\u002F Hook ptrace (Linux)\nInterceptor.replace(\n  Module.getExportByName(null, 'ptrace'),\n  new NativeCallback(() => 0, 'long', ['int', 'int', 'pointer', 'pointer'])\n);\n\n\u002F\u002F Timing spoof\nInterceptor.attach(Module.getExportByName(null, 'clock_gettime'), {\n  onLeave(retval) {\n    \u002F\u002F manipulate timespec to hide debugger delay\n  }\n});\n```\n\n### x64dbg ScyllaHide Quick Setup\n\n1. Plugins → ScyllaHide → Options\n2. Check: PEB BeingDebugged, NtGlobalFlag, HeapFlags\n3. Check: NtQueryInformationProcess (all classes)\n4. Check: NtSetInformationThread (HideFromDebugger)\n5. Check: GetTickCount, QueryPerformanceCounter\n6. Apply → restart debugging session\n",{"name":5,"description":7},"master","4aa004da461d820f4ea5499e58eb8d196cf99016","community\u002Fskills_sh\u002Fs\u002Fskills-sh_yaklang_hack-skills_anti-debugging-techniques",0,"https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge","https:\u002F\u002Fskill-explorer-rho.vercel.app","https:\u002F\u002Fgithub.com\u002FLord1Egypt","Unbreakable. Unstoppable. Unmatched⚡.\r\n Speaker of machine tongues 🤖  | World-builder of decentralized dreams 🌐 | Defender of the digital realm🛡️.","2026-06-10 08:21:01",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add Lord1Egypt\u002Fawesome-skill-forge --skill anti-debugging-techniques",{"tool":39,"command":40},"bunx","bunx skills add Lord1Egypt\u002Fawesome-skill-forge --skill anti-debugging-techniques",{"tool":42,"command":43},"pnpm","pnpm dlx skills add Lord1Egypt\u002Fawesome-skill-forge --skill anti-debugging-techniques","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fcommunity\u002Fskills_sh\u002Fs\u002Fskills-sh_yaklang_hack-skills_anti-debugging-techniques\u002FSKILL.md",true,[],[48,55,62,69,76,83],{"skillNo":49,"name":50,"nameZh":6,"description":51,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":52,"categories":53,"keywords":54,"publishedAt":19},"01M785WKJB99G3STR1NF9NRTJW","youtube-content","YouTube transcripts to summaries, threads, blogs.","https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fskills\u002Fyoutube-content\u002FSKILL.md",[],[],{"skillNo":56,"name":57,"nameZh":6,"description":58,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":19},"01M785WEFHB0G2S9YA6EPR3H0E","xurl","X\u002FTwitter via xurl CLI: post, search, DM, media, v2 API.","https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fskills\u002Fxurl\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M785W98EDN4EFJXJPMQEHCRC","touchdesigner-mcp","Control a running TouchDesigner instance via twozero MCP — create operators, set parameters, wire connections, execute Python, build real-time visuals. 36 native tools.","https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fskills\u002Ftouchdesigner-mcp\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M785W5S9FP3QBH2V191E025P","test-driven-development","TDD: enforce RED-GREEN-REFACTOR, tests before code.","https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fskills\u002Ftest-driven-development\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M785W2AS08NSSH9YATCV6FJB","teams-meeting-pipeline","Operate the Teams meeting summary pipeline via Hermes CLI — summarize meetings, inspect pipeline status, replay jobs, manage Microsoft Graph subscriptions.","https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fskills\u002Fteams-meeting-pipeline\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M785VXKW4T34BTP1SCHW1R7F","systematic-debugging","4-phase root cause debugging: understand bugs before fixing.","https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fskills\u002Fsystematic-debugging\u002FSKILL.md",[],[]]