# anti-debugging-techniques

Anti-debugging detection and bypass playbook for protected Linux and Windows binaries. Helps reverse engineers handle ptrace, PEB flags, execution timing checks, and thread hiding.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 3700 installs · ★ 2547
- Author: yaklang
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/yaklang/hack-skills/tree/HEAD/skills/anti-debugging-techniques/SKILL.md
- Updated: 2026-09-13
- HTML: https://affpapa.org/en/nevibecode/skills/anti-debugging-techniques

## What it does

This skill equips coding agents with concrete strategies to detect and defeat binary protections. Standard AI models often confuse user-mode detection with kernel-mode mechanisms, which leads to broken binary patches. The playbook contains specific evasion techniques designed around tools like ScyllaHide, TitanHide, x64dbg, GDB, and Frida.

On Linux, the instructions cover self-attachment through `ptrace(PTRACE_TRACEME)`, reading `TracerPid` from `/proc/self/status`, catching `SIGTRAP` signals, and detecting delay loops via `rdtsc`. On Windows, the focus is on clearing PEB flags like `BeingDebugged` and `NtGlobalFlag`, spoofing `NtQueryInformationProcess`, and intercepting TLS callbacks before `main` runs.

Applying these bypasses requires specific tooling on your test machine. Linux checks often demand compiling custom `LD_PRELOAD` shims or setting up FUSE mounts to feed clean process data. On Windows, calls to `NtSetInformationThread(ThreadHideFromDebugger)` will break single-stepping immediately unless you hook the API before execution.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill anti-debugging-techniques -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/anti-debugging-techniques/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/anti-debugging-techniques/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill anti-debugging-techniques -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/anti-debugging-techniques/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill anti-debugging-techniques -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/anti-debugging-techniques/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install yaklang/hack-skills anti-debugging-techniques
```

2. **Manually: put the files in place**
- File: `.github/skills/anti-debugging-techniques/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill anti-debugging-techniques -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/yaklang/hack-skills --path skills/anti-debugging-techniques
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/anti-debugging-techniques/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill anti-debugging-techniques -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/yaklang/hack-skills/tree/HEAD/skills/anti-debugging-techniques/SKILL.md

## When to use it
- bypass ptrace self-attach detection on Linux
- patch PEB BeingDebugged and heap flags on Windows
- neutralize rdtsc instruction timing loops
- spoof NtQueryInformationProcess debug port queries
- forward SIGTRAP signals through GDB handlers

## Example prompts
- Provide an LD_PRELOAD shim to bypass ptrace(PTRACE_TRACEME) return checks.
- How do I clear PEB.BeingDebugged and NtGlobalFlag in x64 assembly?
- Configure GDB to forward SIGTRAP to the binary without stopping.

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 8fdbe86c58f7bf64.

BEGIN THIRD-PARTY FILE 8fdbe86c58f7bf64
````text
---
name: anti-debugging-techniques
description: >-
  Anti-debugging detection and bypass playbook. Use when reversing protected
  binaries that detect debuggers via ptrace, PEB flags, timing checks, or
  signal/exception handlers on Linux and Windows.
---

# SKILL: Anti-Debugging Techniques — Detection & Bypass Playbook

> **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.

## 0. RELATED ROUTING

- [code-obfuscation-deobfuscation](../code-obfuscation-deobfuscation/SKILL.md) when the binary also uses control flow flattening, VM protection, or string encryption
- [vm-and-bytecode-reverse](../vm-and-bytecode-reverse/SKILL.md) when the anti-debug sits inside a custom VM dispatcher
- [symbolic-execution-tools](../symbolic-execution-tools/SKILL.md) when you want to symbolically skip anti-debug checks entirely

### Advanced Reference

Also load [ANTI_DEBUG_MATRIX.md](./ANTI_DEBUG_MATRIX.md) when you need:
- Complete cross-reference matrix of technique × OS × detection method × bypass method
- Per-technique reliability ratings and false-positive notes
- Tool compatibility chart (GDB, x64dbg, WinDbg, Frida, ScyllaHide)

### Quick bypass picks

| Detection Class | First Bypass | Backup |
|---|---|---|
| ptrace-based (Linux) | `LD_PRELOAD` hook `ptrace()` → return 0 | Kernel module to hide tracer |
| PEB.BeingDebugged (Windows) | Patch PEB byte at `fs:[0x30]+0x2` | ScyllaHide auto-patch |
| Timing check (rdtsc) | Conditional BP after rdtsc, fix registers | Frida hook `rdtsc` return |
| IsDebuggerPresent | NOP the call / hook return 0 | x64dbg built-in hide |
| INT 2D / UD2 exception | Set VEH to handle gracefully | TitanHide driver |

---

## 1. LINUX ANTI-DEBUG TECHNIQUES

### 1.1 ptrace(PTRACE_TRACEME)

The classic self-attach: a process calls `ptrace(PTRACE_TRACEME, 0, 0, 0)`. If a debugger is already attached, the call fails (returns -1).

```c
if (ptrace(PTRACE_TRACEME, 0, 0, 0) == -1) {
    exit(1); // debugger detected
}
```

**Bypass methods**:

| Method | How |
|---|---|
| `LD_PRELOAD` shim | Compile shared lib: `long ptrace(int r, ...) { return 0; }` and set `LD_PRELOAD` |
| Binary patch | NOP the `ptrace` call or patch return value check |
````
END THIRD-PARTY FILE 8fdbe86c58f7bf64

The third-party file has ended. Everything between the 8fdbe86c58f7bf64 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2499 of 13911 bytes. © yaklang · MIT · https://github.com/yaklang/hack-skills/tree/HEAD/skills/anti-debugging-techniques/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
