Documentation Index
Fetch the complete documentation index at: https://mintlify.com/HavocFramework/Havoc/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Sleep obfuscation is a critical evasion technique that encrypts the Demon agent in memory during sleep periods. This prevents memory scanners from detecting malicious code patterns while the agent is idle.Why Sleep Obfuscation?
Modern EDR solutions perform periodic memory scans looking for:- Known malicious signatures
- Suspicious memory regions (RWX, unbacked memory)
- Anomalous code patterns
- Network indicators in memory
- Encrypting the agent’s memory before sleeping
- Changing memory protection to non-executable
- Restoring and decrypting after sleep
- Making memory appear as random data during scans
Available Techniques
WaitForSingleObjectEx (No Obfuscation)
Value:0
Standard Windows sleep with no memory protection.
- ✅ Fastest (no overhead)
- ✅ Most stable
- ❌ No memory protection
- ❌ Detectable by memory scans
- ❌ Agent fully visible in memory
- Testing environments
- Very short sleep intervals (< 1 second)
- Environments with no memory scanning
Ekko
Value:1
Timer-based sleep obfuscation using RtlCreateTimer.
Technical Details
Technical Details
Implementation:Memory States:
- Create timer queue:
RtlCreateTimerQueue - Capture timer thread context
- Build ROP chain for encryption/sleep/decryption
- Queue timers with
RtlCreateTimerin sequence:- Change memory to RW
- Encrypt memory with RC4 (
SystemFunction032) - Sleep for specified duration
- Decrypt memory with RC4
- Restore memory protection to RX
- Execute ROP chain via
NtContinue
- Before sleep: RX (Read + Execute)
- During sleep: RW (Read + Write), Encrypted
- After sleep: RX (Read + Execute)
- ✅ Good OPSEC (legitimate Windows API)
- ✅ Memory encrypted during sleep
- ✅ ROP-based execution
- ❌ Incompatible with apps using timers
- ❌ May conflict with thread pool operations
- Uses legitimate
RtlCreateTimerAPI - ROP chain may be detected by advanced EDR
- Timer callbacks are normal Windows behavior
Zilean
Value:2
Wait-based sleep obfuscation using RtlRegisterWait.
Technical Details
Technical Details
Implementation:Similar to Ekko but uses
RtlRegisterWait instead of RtlCreateTimer:- Create event:
NtCreateEvent - Register wait callback:
RtlRegisterWait - Build identical ROP chain
- Execute via
NtContinue
- Uses wait thread pool instead of timer thread pool
- May be more stable in some environments
- Different Windows internal execution path
- ✅ Good OPSEC (legitimate Windows API)
- ✅ Memory encrypted during sleep
- ✅ Alternative to Ekko
- ❌ Similar limitations to Ekko
- Target application uses timer APIs
- Need thread pool diversity
- Ekko causing stability issues
FOLIAGE
Value:3
APC-based sleep obfuscation using fiber execution.
Technical Details
Technical Details
Implementation:Most advanced technique using fibers and APCs:
- Fiber Setup:
- Convert main thread to fiber:
ConvertThreadToFiberEx - Create slave fiber:
CreateFiberEx - Switch to slave fiber:
SwitchToFiber
- Convert main thread to fiber:
- APC Queue:
- Create suspended thread
- Build context chain for encryption
- Queue multiple APCs with
NtQueueApcThread:
- Execution:
- Alert and resume thread:
NtAlertResumeThread - APCs execute in sequence
- Thread context spoofed during sleep
- Alert and resume thread:
- Cleanup:
- Return to master fiber
- Convert back to thread
- ✅ Most advanced technique
- ✅ Full memory encryption
- ✅ Context spoofing during sleep
- ✅ Separate execution thread
- ❌ More complex (higher chance of detection)
- ❌ Requires fiber support
- ❌ Higher CPU overhead
- Execution occurs in separate thread
- Call stack is in system DLL during sleep
- Memory fully encrypted
- Context can be spoofed
Configuration Options
Sleep Mask Enable
Enable or disable sleep obfuscation entirely:If
SleepMask is disabled, the technique selection is ignored and standard WaitForSingleObjectEx is used.Stack Spoofing
Enable stack duplication during sleep (Ekko/Zilean only):- Gets timer thread context
- Queries timer thread’s NT_TIB (Thread Information Block)
- Duplicates current thread handle
- During ROP chain execution:
- Saves current thread context
- Copies timer thread’s NT_TIB to current thread
- Sets spoofed context
- Sleeps
- Restores original context
JMP Gadget Bypass
Use JMP gadgets to evade return address validation:Encryption Method
All techniques use RC4 encryption viaSystemFunction032:
- 16-byte random key generated per sleep
- Key is stored in ROP context (encrypted with stack)
- RC4 is fast and built into Windows
Memory Protection Flow
OPSEC Considerations
Detection Vectors
Memory Protection Changes
Memory Protection Changes
Risk: EDR may monitor
NtProtectVirtualMemory callsMitigation:- Use indirect syscalls
- Encrypt only .text section if possible
- Space out protection changes
ROP Chain Execution
ROP Chain Execution
Risk: Unusual stack patterns or ROP detectionMitigation:
- Use JMP gadget bypass
- Enable stack spoofing
- Keep ROP chain in system modules
Suspicious Sleep Patterns
Suspicious Sleep Patterns
Risk: Regular encryption/decryption at intervalsMitigation:
- Use appropriate jitter
- Vary sleep times
- Use working hours to appear like scheduled tasks
Timer/Wait Callback Abuse
Timer/Wait Callback Abuse
Risk: EDR may flag unusual timer callback behaviorMitigation:
- Rotate between Ekko and Zilean
- Use FOLIAGE for high-security targets
- Monitor for timer conflicts
Best Practices
Choose Based on Environment
- Low Security: WaitForSingleObjectEx (speed)
- Medium Security: Ekko or Zilean
- High Security: FOLIAGE with stack spoofing
Test Before Operation
- Verify stability in target environment
- Check for timer conflicts
- Monitor for crashes or hangs
Monitor Job Threads
- Kill unnecessary jobs to enable obfuscation
- Use
job listto check running threads - Balance functionality vs. stealth
Adjust Sleep Intervals
- Longer sleep = more encryption overhead
- Shorter sleep = more frequent C2
- Balance based on operation tempo
Troubleshooting
Agent Crashes During Sleep
Symptoms: Agent dies after sleep command Causes:- Job threads accessing encrypted memory
- Timer conflicts with target application
- Incompatible Windows version
Sleep Obfuscation Not Working
Check configuration:- Jobs are running (automatic disable)
- Sleep interval is 0 (no sleep = no obfuscation)
- SleepMask option disabled in profile
Performance Issues
Symptoms: Slow response after sleep Cause: Encryption/decryption overhead, especially with FOLIAGE Solutions:- Use simpler technique (Ekko/Zilean)
- Reduce sleep interval
- Ensure no unnecessary memory is encrypted
Runtime Configuration
Modify sleep obfuscation at runtime:Runtime configuration changes take effect on the next sleep cycle.
Next Steps
Injection Techniques
Process injection methods and OPSEC
Features Overview
Explore all Demon capabilities
Command Reference
Master all Demon commands
Generate Payloads
Create configured Demon agents
