Skip to content
Pwnversity
REV-ANTIDEBUGadvanced · 5 min · upd. 2026-10

Anti-debugging and Anti-analysis

T1622T1497

Software that doesn’t want to be analyzed —malware, license protections, DRM, anti-cheat— incorporates techniques to detect and obstruct the analyst: check whether a debugger is attached, whether it runs in a virtual machine or sandbox, whether it’s being instrumented, or whether the binary itself has been modified. On detection, it changes behavior, exits, or runs decoy logic. For the reverser it’s a cat-and-mouse game: recognize these defenses and bypass them.

Anti-analysis is a set of checks the program runs on itself and its environment to decide whether it’s under observation. They don’t change what the program “could” do, only whether it does it: the same binary behaves normally on a real machine and aborts (or deceives) in an analysis environment. The defender’s goal is to raise the cost of reversing; the analyst’s, to locate the check and neutralize it.

flowchart TD
    A["protected binary runs"] --> B{"debugger attached?"}
    B -->|"Yes"| X["abort / decoy logic"]
    B -->|"No"| C{"VM / sandbox?"}
    C -->|"Yes"| X
    C -->|"No"| D{"binary modified? (checksum)"}
    D -->|"Yes"| X
    D -->|"No"| E["run the real logic"]
    X -.->|"the analyst patches the check"| E
  • Linux: ptrace(PTRACE_TRACEME) —a process can only be traced once, so if it traces itself, a debugger can’t attach—; reading /proc/self/status and checking TracerPid != 0.
  • Windows: IsDebuggerPresent(), CheckRemoteDebuggerPresent(), the PEB->BeingDebugged flag, NtQueryInformationProcess (ProcessDebugPort).
  • Generic: timing checks (code under a debugger is much slower: rdtsc, GetTickCount); breakpoint detection by searching for 0xCC (int3) bytes in its own code; handling SIGTRAP in a way that betrays the debugger.

Anti-VM / anti-sandbox (detect the analysis environment)

Section titled “Anti-VM / anti-sandbox (detect the analysis environment)”
  • Virtualization artifacts: hypervisor bit in cpuid, VMware/VirtualBox MAC addresses, characteristic files/processes/registry keys.
  • Sandbox detection: little user activity, low uptime, few cores/little RAM, absence of human interaction (no mouse movement).
  • Long sleeps: sandboxes cap analysis time, so malware “sleeps” to run out the clock and execute its logic outside the observed window.
  • Checksums/hashes of its own code: if someone patches the binary, the hash doesn’t match.
  • Runtime integrity checks (sometimes of specific sections).
  • Self-modifying or encrypted code: static doesn’t see the real code (see Static Analysis).
  • Control flow flattening — flatten the flow so the graph is unreadable.
  • Opaque predicates — always-true/false conditions that confuse the decompiler.
  • String encryption — strings decrypted only at runtime.
  • Dead code / junk — junk instructions with no effect.
  • Code virtualization — a custom interpreter runs custom bytecode (VMProtect, Themida); the hardest to reverse.

Exploitation (lab): bypassing the protections

Section titled “Exploitation (lab): bypassing the protections”

The principle is that nearly all reduce to a check that, once located, can be patched or forced.

Ventana de terminal
# anti-debug (Linux): neutralize ptrace with an LD_PRELOAD that always returns 0
cat > fakeptrace.c <<'EOF'
long ptrace(int r, int p, void *a, void *d) { return 0; }
EOF
gcc -shared -fPIC fakeptrace.c -o fakeptrace.so
LD_PRELOAD=./fakeptrace.so gdb -q ./binary
Ventana de terminal
# in GDB: force the result of the check
(gdb) b *0x401250 # right after the IsDebuggerPresent/ptrace call
(gdb) run
(gdb) set $rax = 0 # fake "no debugger"
(gdb) continue

Summary by category:

  • Anti-debug: patch the if (NOP), force the value in GDB, LD_PRELOAD of a fake ptrace (Linux), ScyllaHide (Windows).
  • Anti-VM: more realistic VMs (hide artifacts), bare-metal for very evasive samples, or patch the checks.
  • Anti-sandbox (sleeps): speed up/patch the sleep calls, hook GetTickCount.
  • Obfuscation: dynamic (see Dynamic Analysis) to dump the decrypted content; deobfuscators; angr.
  • Anti-tampering: patch the integrity check too (before the rest).

For whoever wants to protect their own software or delay the pirate:

  • Combine several layers (a single one is easily patched): anti-debug + anti-VM + integrity + obfuscation.
  • Commercial protectors (VMProtect/Themida) to raise the cost a lot.
  • Remember that none fully protects against a determined analyst: for malware, the answer is detection (EDR/sandbox); for intellectual property, delay.
  • Detect anti-debug (ptrace/IsDebuggerPresent/timing)
  • Bypass it (patch/force/LD_PRELOAD/ScyllaHide)
  • Detect anti-VM/anti-sandbox (artifacts, sleeps)
  • Evade (realistic VM / patch / speed up time)
  • Detect anti-tampering (checksums) and patch it
  • Identify obfuscation/packing and fight it (dynamic/angr)
  • Combine static + dynamic on protected code
  • Document the protections found