Nothing new in this post, but I wanted to try this for myself and kept notes along the way.

In this lab, the EXE runs from PowerShell, but quits in WinDbg before doing the interesting bit.

The tl;dr: this app uses two common debugger checks, IsDebuggerPresent and CheckRemoteDebuggerPresent.

Examples from real malware: Cisco Talos found IsDebuggerPresent and CheckRemoteDebuggerPresent in an October 2026 Windows implant that exited silently on detection. Kaspersky found the same pair in GenieLocker ransomware in July 2026, along with a tricky watchdog that kept checking for debuggers and changes to its code.

In this post, we’ll use a small program built for this experiment. It makes both checks, then decodes and runs six bytes of harmless code.

Get set up

Use an x64 Windows machine with WinDbg and Visual Studio C++ Build Tools. Save GuardedStage.cpp, Build-Lab.ps1, and the README in C:\Lab\DebuggerEvasionLab.

Open PowerShell:

Set-Location C:\Lab\DebuggerEvasionLab
.\Build-Lab.ps1

The build produces bin\GuardedStage.exe and its matching private symbols (.pdb). Keep those together so WinDbg can resolve our function names as we step through. No elevation is needed. Addresses shown in your debugger will differ on your run. I recorded the output below with CDB, the console debugger from the same Windows Debugging Tools package. These commands also work in WinDbg.

WinDbg commands used below

These examples go in WinDbg’s Command window. The PowerShell commands later in the post go in PowerShell.

Command What it does here Example
g Continue until the next stop or exit g
.lastevent Show the latest debugger event, including this process exit .lastevent
.sympath+ Add the PDB folder to the symbol path .sympath+ C:\Lab\DebuggerEvasionLab\bin
.reload /f Force a symbol reload for the EXE .reload /f GuardedStage.exe
bu Set a breakpoint at a named function bu KERNELBASE!IsDebuggerPresent
k Show the call stack k 3
gu Run until the current function returns gu
r Show or change registers and temporary values r eax=1, r $t0=@rdx
u Show instructions at an address u @rip L16
dd Display 4-byte values in memory dd @$t0 L1
ed Write a 4-byte value to memory ed @$t0 0
db Display raw bytes in memory db @$t1 L6
!address Show a region’s type and current protection !address @$t1
ba e1 Break when execution reaches an address ba e1 @rcx
t Step one machine instruction t
bc Remove breakpoints; * means all of them bc *

The @ in @rip, @rcx, and @rdx means the register’s current value. $t0 and $t1 are temporary debugger registers we use to remember addresses. L limits how much a display command shows.

The ordinary run and the short exit

First, run the program without a debugger in PowerShell:

.\bin\GuardedStage.exe
$LASTEXITCODE

It printed stage_result=42 and returned 0 in my run.

Now launch the same EXE in WinDbg: File → Start debugging → Launch executable. At the initial break, enter g, then check .lastevent when it exits. The recorded debugger run ended with:

Last event: 58c8.6694: Exit process 0:58c8, code a

That’s 0xa, or 10 in decimal. There was no stage output.

The path through our lab looks like this. Red branches are the exits without edits; blue boxes show the values we’ll change in the paused run.

Sketch of the GuardedStage lab under WinDbg: the first check exits with 10, changing its result reaches a second check that exits with 20, and changing that check's output lets decoded code run from private executable memory and return 42.

The exit code tells us which path this lab took, but not what produced the decision. We already know two API names to look for, so in an x64 Developer PowerShell, let’s check the imports with dumpbin:

dumpbin /imports .\bin\GuardedStage.exe | findstr /i DebuggerPresent

Both IsDebuggerPresent and CheckRemoteDebuggerPresent appeared in the import list. Check Point’s anti-debugging reference covers both calls and related debug flags. Worth noting that an import does not show whether the call actually ran or caused the exit, so there is still value in going deeper.

Follow the first check to the exit

Launch a fresh debugger session for the EXE. Add the folder containing the PDB to the symbol path, then break on the API:

.sympath+ C:\Lab\DebuggerEvasionLab\bin
.reload /f GuardedStage.exe
bu KERNELBASE!IsDebuggerPresent
g
k 3
gu
r eax
u @rip L16
gu
r eax
u @rip L16

The k 3 stack at KERNELBASE!IsDebuggerPresent showed GuardedStage!FirstGate calling the API and main calling FirstGate:

000000c9`512ff7c8 00007ff7`0d19100a     KERNELBASE!IsDebuggerPresent
000000c9`512ff7d0 00007ff7`0d1912d9     GuardedStage!FirstGate+0xa
000000c9`512ff810 00007ff7`0d19160c     GuardedStage!main+0x9

The API lived in KERNELBASE on this build; if a breakpoint there never fires on yours, inspect the target’s import and the call from FirstGate before choosing another API address. gu runs until the current function returns. The API returned one, and FirstGate returned zero:

0:000> r eax
eax=1
0:000> gu
GuardedStage!main+0x9:
0:000> r eax
eax=0

IsDebuggerPresent returns nonzero when its calling process is being debugged. FirstGate turns that into a clear to continue result, so its zero is the answer main uses to return 10. The x64 calling convention puts scalar return values in RAX; the BOOL and C++ bool values here are visible in EAX/AL.

The disassembly in main makes the exit path visible:

00007ff7`0d1912dc 85c0            test    eax,eax
00007ff7`0d1912de 7507            jne     GuardedStage!main+0x17 (00007ff7`0d1912e7)
00007ff7`0d1912e0 b80a000000      mov     eax,0Ah
00007ff7`0d1912e5 eb1b            jmp     GuardedStage!main+0x32 (00007ff7`0d191302)
00007ff7`0d1912e7 e854fdffff      call    GuardedStage!SecondGate (00007ff7`0d191040)

Zero takes the mov eax,0Ah route, the exit code we saw. A nonzero result reaches the call to SecondGate.

At the return to main, change the gate’s result for this run and continue:

r eax=1
bu KERNELBASE!CheckRemoteDebuggerPresent
g

That edit does not change the EXE or detach WinDbg. It lets main pass the first test and reach another one. In a separate run, I made only this first change and let the program continue. It still quit silently, this time with exit code 0x14 (20 decimal).

The second answer is in memory

At KERNELBASE!CheckRemoteDebuggerPresent, inspect the first two arguments. On x64 they arrive in RCX and RDX:

r rcx,rdx
r $t0=@rdx
dd @$t0 L1
gu
r eax
dd @$t0 L1

Here RCX was ffffffffffffffff, the current-process pseudo-handle passed by SecondGate. RDX was the address of its BOOL output variable. I saved that address in $t0 because argument registers can change across the call. The output was zero before the call and one after it; EAX was one after return.

0:000> dd @$t0 L1
00000015`cdeff750  00000000
0:000> gu
GuardedStage!SecondGate+0x20:
0:000> r eax
eax=1
0:000> dd @$t0 L1
00000015`cdeff750  00000001

That matters. CheckRemoteDebuggerPresent returns nonzero in EAX when the call succeeded. It writes whether the process is being debugged through its second argument. “Remote” means the debugger is in a separate process, not necessarily on another computer. Setting EAX to zero here would report an API failure, which our sample handles as an error. The value that makes SecondGate stop is the BOOL it wrote.

The relevant part of SecondGate:

BOOL debugged = FALSE;
const BOOL ok = CheckRemoteDebuggerPresent(GetCurrentProcess(), &debugged);
if (ok == FALSE) {
    std::printf("second_gate=api_error:%lu\n", GetLastError());
    return kSecondGateErrorExit;
}
return debugged == FALSE ? 0 : kSecondGateExit;

Change that output while the program is paused, verify it, then let SecondGate return:

ed @$t0 0
dd @$t0 L1
gu
r eax

The dd showed zero after the edit, and SecondGate returned EAX=0 to main. The API had succeeded and had seen the debugger; we changed the value its caller was about to use.

Find what the gates protected

The source has a six-byte encoded stage. Once past the debugger check gates, RunStage allocates a private writable page with VirtualAlloc, decodes into it, then asks VirtualProtect for execute/read access. Stop at that protection change:

bu KERNELBASE!VirtualProtect
bu GuardedStage!InvokeStage
g
r rcx,rdx,r8
r $t1=@rcx
db @$t1 L6
!address @$t1

The VirtualProtect arguments put the buffer in RCX, its length in RDX (6), and the requested protection in R8 (0x20, PAGE_EXECUTE_READ). Selected lines from that stop show the decoded bytes and page:

000001e0`d02f0000  b8 2a 00 00 00 c3
Protect:                00000004          PAGE_READWRITE
Type:                   00020000          MEM_PRIVATE

The six bytes are mov eax, 2Ah; ret, not a PE image. !address reports the current page’s protection in Protect. The similarly named Allocation Protect field still records the protection used when the region was allocated.

Let VirtualProtect return and inspect the same address:

gu
r eax
!address @$t1

It returned EAX=1 for success. !address still reported MEM_PRIVATE, but Protect had changed to PAGE_EXECUTE_READ:

Protect:                00000020          PAGE_EXECUTE_READ
Type:                   00020000          MEM_PRIVATE

The program then calls FlushInstructionCache, as Microsoft directs for newly written executable code.

Finally, stop at the wrapper that calls the page and watch the CPU reach those bytes:

g
r rcx
u @rcx L2
ba e1 @rcx
g
r rip
t
r eax
bc *
g
.lastevent

At entry to InvokeStage, RCX was the function pointer. u showed mov eax,2Ah followed by ret at that address. ba e1 sets a one-byte execution breakpoint there. It stopped with RIP at the same private page. One instruction step left EAX=0x2a:

0:000> r rip
rip=000001e0d02f0000
0:000> t
000001e0`d02f0005 c3              ret
0:000> r eax
eax=2a

The same run finished with:

stage_result=42
Last event: 6c68.198: Exit process 0:6c68, code 0

The first gate detected a debugger and kept us from reaching the second. Passing its result reached another check that also detected a debugger. Changing that output let the program decode bytes into private memory, make the page executable, and run them. We know where it ran because the execution breakpoint stopped with RIP in that page.

Nice. I honestly think we could have stopped at the tl;dr, but it was nice to be able to poke around and use this as an example of manipulating the execution flow.

Microsoft Defender’s Dofoil investigation documents a multi-stage threat whose early anti-debugging module checked the PEB and changed code to crash under analysis. It shows another way a debugger decision can keep later behavior out of view.

Google Project Zero’s survey of in-the-wild exploit chains reports obfuscation and anti-analysis checks across Windows, Android, and iOS chains. For an offensive look at Windows debugging itself, James Forshaw’s Project Zero analysis follows debug objects, process attachment, and debug events. These provide broader context; the Check Point and Talos reports above cover the two API checks more directly.