Time is the cheapest anti-analysis: Sleep(600000) costs the author one
line and costs the analyst ten minutes per run. Timing checks also
detect the analyst directly: breakpoints freeze time, single-stepping
stretches it, and emulation distorts rdtsc. This sub-skill covers
recognizing each timing primitive and defeating it. Scope: bypass
timing checks only on binaries you are authorized to analyze, in an
isolated lab, during authorized DFIR, malware research, or defensive
testing.
Quick Workflow
- Note the symptom: instant exit after a delay, no behavior in short
runs, exits when stepped.
- Hunt statically: Sleep, GetTickCount, QueryPerformanceCounter,
rdtsc bytes (0F 31), NtDelayExecution.
- Classify: stall (sleep out the clock), delta check (detect the
debugger), or both.
- Bypass: extend timeout, patch the sleep, hook the clock, or avoid
stepping through the check.
- Verify: behavior appears promptly; beacon timestamps confirm.
- Document the bypass with the report.
1. Stall tactics: sleeps and delays
Sleep(600000) 10-minute stall, outlasts default sandboxes
NtDelayExecution(neg 10min) kernel-level equivalent
Loop of Sleep(1000) x 600 same effect, harder to patch in one place
WaitForSingleObject(timeout) stall disguised as synchronization
Bypasses, easiest first:
- Longer detonation: submit with a 15-minute timeout. No patching,
always valid, just slow.
- Patch the sleep: NOP the call or zero its argument in the
debugger. Immediate.
- Hook Sleep: intercept and return instantly; cleaner than
patching when sleeps are scattered.
Patch shape:
Before: 68 00 09 27 00 push 0x270900 (600000 ms)
FF 15 .. .. .. call Sleep
After: 68 00 00 00 00 push 0
FF 15 .. .. .. call Sleep
For looped sleeps, patch the loop counter or break the loop condition
rather than each Sleep call.
2. Tick-count delta checks
t0 = GetTickCount();
<operation that should be fast>
t1 = GetTickCount();
if (t1 - t0 > THRESHOLD) exit(); // a breakpoint froze time
Also seen with QueryPerformanceCounter and timeGetTime. The check
detects breakpoints and single-stepping inside the measured region.
Bypasses:
- Do not step through it: set a breakpoint after the check and run
to it; the delta stays small.
- Hook GetTickCount: return t0 + epsilon always, so deltas never
trip. ScyllaHide has a GetTickCount option.
- Patch the comparison: flip the conditional jump after the delta
check so it never exits.
Static hunt: look for two GetTickCount calls with a subtraction and
compare between them; the threshold constant tells you how sensitive
it is (small threshold = aggressive, trips on any debugger pause).
3. rdtsc checks
rdtsc ; 0F 31, reads timestamp counter
mov [t0], eax
<operation>
rdtsc
sub eax, [t0]
cmp eax, THRESHOLD
ja debugger_found
rdtsc detects single-stepping (each step costs thousands of cycles)
and emulation (emulators distort the counter). Variants use rdtscp or
compare ratios of rdtsc to GetTickCount.
Bypasses:
- x64dbg can intercept rdtsc (set options to handle it); the
returned values stay consistent.
- Run, do not step, through measured regions.
- Patch the comparison after the delta, same as tick-count checks.
- For ratio checks (rdtsc vs GetTickCount), hook both consistently
or patch the final verdict.
4. Sandbox-timeout evasion patterns
Beyond raw sleeps, samples detect short detonations indirectly:
- Delayed C2: first beacon scheduled 20+ minutes out; short runs
see nothing. Fix: long timeout or patch the schedule.
- Reboot persistence then wait: the payload only runs after
reboot; detonate with a reboot step.
- Idle detection: GetLastInputInfo waits for user inactivity
(ironically) or activity before running. Fix: simulate input in
the sandbox profile.
# Confirm delayed beaconing from a long pcap
tshark -r long.pcap -Y "dns" -T fields -e frame.time_epoch -e dns.qry.name \
| sort -n | head -5
# first C2 DNS at T+1200s -> the sample waited 20 minutes
5. Validation
- Baseline: short run shows nothing; note the exact quiet duration.
- Bypassed: behavior (beacon, drop, injection) appears within seconds
of start.
- Timestamp proof: first beacon at T+5s instead of T+600s, from the
pcap, not from memory.
- Revert: restore the sleep, confirm quiet again.
Document which primitive was bypassed and how; "patched Sleep at file
offset 0x1234" reproduces, "made it faster" does not.
Edge cases
Nested timing: a sleep, then a delta check, then another sleep.
Defeat outside-in and re-test after each.
Timing checks on the C2's schedule (beacon only at certain hours):
set the VM clock or patch the schedule comparison.
Anti-hook timing: the sample measures its own Sleep to detect
hooking (hooked Sleep returns too fast). Then patch the argument
instead of hooking, or extend the real timeout.
Kernel-mode timing: user-mode hooks do not affect
NtDelayExecution measured in kernel; patch at the call site.
Sleep calls with randomized durations: patching one constant is not enough; hook the API or extend the timeout instead.
Escalation
If timing is enforced by a remote server (C2 only responds after
a delay), lab bypasses cannot help; note it and analyze the
offline-capable parts.
If the sample combines timing with VM checks such that no lab
configuration satisfies it, escalate to bare-metal analysis.
If the sample's schedule depends on a C2 command (the server tells it when to act), lab bypasses cannot trigger it; note the gap and analyze the offline-capable parts.
If timing checks are enforced in a driver or kernel component, escalate: user-mode techniques do not reach them.
Detection and defender view
Timing behavior is detection signal: a process that sleeps 10 minutes
before its first network connection is suspicious regardless of what
follows; EDR rules on sleep-then-beacon patterns catch whole classes.
Log the timing profile per family (stall duration, beacon delay);
when a new sample shares the profile, that is a clustering signal.
For sandbox operators, the lesson is operational: default 2-minute
timeouts miss an entire class of malware, so tier timeouts by triage
priority.
Key references
1---2name: binary-anti-analysis-bypass-timing-checks3description: Use when a binary uses time to detect analysis, covering long4 sleeps to outlast sandboxes, tick-count deltas to detect breakpoints,5 rdtsc to detect single-stepping or emulation. Covers identifying each6 timing primitive statically and dynamically, bypassing via patching,7 hooking, timeout extension, and accelerated clocks, and validating8 that the sample's real behavior emerged. Use when a sample sleeps9 through detonation, when stepping triggers exits, or when beaconing10 appears only after long delays.11version: 1.0.012domain: binary13lifecycle: stable14last_verified: "2026-10-23"15requires: [binary-anti-analysis-bypass]16extends: []17parent: binary-anti-analysis-bypass18relates: [malware-sandbox-analysis, binary-patching-techniques]19tools:20 - name: x64dbg21 version: "2025.06"22 - name: ScyllaHide23 version: "1.4"24 - name: Python25 version: "3.12"26 - name: CAPE Sandbox27 version: "2.5"28metadata:29 source: https://skillmd.com/skills/mizazhaider-ceh/binary-anti-analysis-bypass-timing-checks30---3132Time is the cheapest anti-analysis: Sleep(600000) costs the author one33line and costs the analyst ten minutes per run. Timing checks also34detect the analyst directly: breakpoints freeze time, single-stepping35stretches it, and emulation distorts rdtsc. This sub-skill covers36recognizing each timing primitive and defeating it. Scope: bypass37timing checks only on binaries you are authorized to analyze, in an38isolated lab, during authorized DFIR, malware research, or defensive39testing.4041## Quick Workflow42431. Note the symptom: instant exit after a delay, no behavior in short44 runs, exits when stepped.452. Hunt statically: Sleep, GetTickCount, QueryPerformanceCounter,46 rdtsc bytes (0F 31), NtDelayExecution.473. Classify: stall (sleep out the clock), delta check (detect the48 debugger), or both.494. Bypass: extend timeout, patch the sleep, hook the clock, or avoid50 stepping through the check.515. Verify: behavior appears promptly; beacon timestamps confirm.526. Document the bypass with the report.5354## 1. Stall tactics: sleeps and delays5556```text57Sleep(600000) 10-minute stall, outlasts default sandboxes58NtDelayExecution(neg 10min) kernel-level equivalent59Loop of Sleep(1000) x 600 same effect, harder to patch in one place60WaitForSingleObject(timeout) stall disguised as synchronization61```6263Bypasses, easiest first:64651. **Longer detonation**: submit with a 15-minute timeout. No patching,66 always valid, just slow.672. **Patch the sleep**: NOP the call or zero its argument in the68 debugger. Immediate.693. **Hook Sleep**: intercept and return instantly; cleaner than70 patching when sleeps are scattered.7172```text73Patch shape:74 Before: 68 00 09 27 00 push 0x270900 (600000 ms)75 FF 15 .. .. .. call Sleep76 After: 68 00 00 00 00 push 077 FF 15 .. .. .. call Sleep78```7980For looped sleeps, patch the loop counter or break the loop condition81rather than each Sleep call.8283## 2. Tick-count delta checks8485```text86t0 = GetTickCount();87<operation that should be fast>88t1 = GetTickCount();89if (t1 - t0 > THRESHOLD) exit(); // a breakpoint froze time90```9192Also seen with QueryPerformanceCounter and timeGetTime. The check93detects breakpoints and single-stepping inside the measured region.9495Bypasses:9697- **Do not step through it**: set a breakpoint after the check and run98 to it; the delta stays small.99- **Hook GetTickCount**: return t0 + epsilon always, so deltas never100 trip. ScyllaHide has a GetTickCount option.101- **Patch the comparison**: flip the conditional jump after the delta102 check so it never exits.103104Static hunt: look for two GetTickCount calls with a subtraction and105compare between them; the threshold constant tells you how sensitive106it is (small threshold = aggressive, trips on any debugger pause).107108## 3. rdtsc checks109110```text111rdtsc ; 0F 31, reads timestamp counter112mov [t0], eax113<operation>114rdtsc115sub eax, [t0]116cmp eax, THRESHOLD117ja debugger_found118```119120rdtsc detects single-stepping (each step costs thousands of cycles)121and emulation (emulators distort the counter). Variants use rdtscp or122compare ratios of rdtsc to GetTickCount.123124Bypasses:125126- x64dbg can intercept rdtsc (set options to handle it); the127 returned values stay consistent.128- Run, do not step, through measured regions.129- Patch the comparison after the delta, same as tick-count checks.130- For ratio checks (rdtsc vs GetTickCount), hook both consistently131 or patch the final verdict.132133## 4. Sandbox-timeout evasion patterns134135Beyond raw sleeps, samples detect short detonations indirectly:136137- **Delayed C2**: first beacon scheduled 20+ minutes out; short runs138 see nothing. Fix: long timeout or patch the schedule.139- **Reboot persistence then wait**: the payload only runs after140 reboot; detonate with a reboot step.141- **Idle detection**: GetLastInputInfo waits for user inactivity142 (ironically) or activity before running. Fix: simulate input in143 the sandbox profile.144145```bash146# Confirm delayed beaconing from a long pcap147tshark -r long.pcap -Y "dns" -T fields -e frame.time_epoch -e dns.qry.name \148 | sort -n | head -5149# first C2 DNS at T+1200s -> the sample waited 20 minutes150```151152## 5. Validation1531541. Baseline: short run shows nothing; note the exact quiet duration.1552. Bypassed: behavior (beacon, drop, injection) appears within seconds156 of start.1573. Timestamp proof: first beacon at T+5s instead of T+600s, from the158 pcap, not from memory.1594. Revert: restore the sleep, confirm quiet again.160161Document which primitive was bypassed and how; "patched Sleep at file162offset 0x1234" reproduces, "made it faster" does not.163164## Edge cases165166- Nested timing: a sleep, then a delta check, then another sleep.167 Defeat outside-in and re-test after each.168- Timing checks on the C2's schedule (beacon only at certain hours):169 set the VM clock or patch the schedule comparison.170- Anti-hook timing: the sample measures its own Sleep to detect171 hooking (hooked Sleep returns too fast). Then patch the argument172 instead of hooking, or extend the real timeout.173- Kernel-mode timing: user-mode hooks do not affect174 NtDelayExecution measured in kernel; patch at the call site.175176- Sleep calls with randomized durations: patching one constant is not enough; hook the API or extend the timeout instead.177178## Escalation179180- If timing is enforced by a remote server (C2 only responds after181 a delay), lab bypasses cannot help; note it and analyze the182 offline-capable parts.183- If the sample combines timing with VM checks such that no lab184 configuration satisfies it, escalate to bare-metal analysis.185186- If the sample's schedule depends on a C2 command (the server tells it when to act), lab bypasses cannot trigger it; note the gap and analyze the offline-capable parts.187- If timing checks are enforced in a driver or kernel component, escalate: user-mode techniques do not reach them.188189## Detection and defender view190191Timing behavior is detection signal: a process that sleeps 10 minutes192before its first network connection is suspicious regardless of what193follows; EDR rules on sleep-then-beacon patterns catch whole classes.194Log the timing profile per family (stall duration, beacon delay);195when a new sample shares the profile, that is a clustering signal.196For sandbox operators, the lesson is operational: default 2-minute197timeouts miss an entire class of malware, so tier timeouts by triage198priority.199200## Key references201202- MITRE ATT&CK: T1497.003 (Time Based Evasion)203- x64dbg documentation:204 https://x64dbg.com/205- ScyllaHide:206 https://github.com/x64dbg/ScyllaHide207- CAPE Sandbox documentation (timeout configuration):208 https://capev2.readthedocs.io/209- Practical Malware Analysis (Sikorski and Honig), Chapter 17210 (anti-debugging: timing checks)