Overview
Thepersist module implements multiple persistence mechanisms to maintain access across reboots. Methods range from simple registry keys to stealthy WMI event subscriptions.
Persistence Methods
PersistMethod Enum
persist/persist.go:27-34
- Registry
- Startup Folder
- Scheduled Task
- WMI Subscription
- Privilege: User-level
- Stealth: Low (easily detected)
- Reliability: High
- Location:
HKCU\Software\Microsoft\Windows\CurrentVersion\Run
Main Installation Function
Install()
Establishes persistence using the specified method:persist/persist.go:38-56
Persistence method to use (Registry is default and most reliable)
Method 1: Registry Run Key
installRegistry()
Adds executable to registry Run key (most common method):persist/persist.go:59-67
Registry Persistence Details
Registry Persistence Details
Location:Value name:
WindowsUpdate (masquerades as Windows Update)Value data: Full path to executableTrigger: User logonDetection:- Autoruns (Sysinternals)
- Registry monitoring tools
- Most AV/EDR solutions
- No admin required
- Survives reboots
- Highly reliable
- Easily detected
- Can be removed by user
- Logged by Windows Event Log
The value name “WindowsUpdate” is used to masquerade as a legitimate Windows component. Consider randomizing this for better stealth.
Method 2: Startup Folder
installStartupFolder()
Copies executable to Windows Startup folder:persist/persist.go:70-89
hideFile()
Sets file attributes to hidden and system:persist/persist.go:157-165
Startup Folder Persistence
Startup Folder Persistence
Location:Filename:
svchost.exe (mimics Windows Service Host)Attributes: Hidden + SystemDetection:- Visible in Task Manager Startup tab
- Easily found by users
- File hash scanning
- Simple implementation
- No registry modification
- Reliable execution
- Very easy to detect
- Visible in Startup folder
- Filename must be believable
Method 3: Scheduled Task
installScheduledTask()
Creates scheduled task that runs at user logon:persist/persist.go:92-111
Scheduled Task Parameters
Scheduled Task Parameters
Task name: View tasks:Delete task:
WindowsSecurityUpdateschtasks flags:/tn- Task name/tr- Task to run (executable path)/sc- Schedule type (onlogon)/rl- Run level (highest- requires admin)/f- Force create (overwrites existing)
Method 4: WMI Event Subscription
installWMI()
Creates WMI event subscription (most stealthy method):persist/persist.go:114-154
WMI Persistence Components
WMI Persistence Components
1. Event Filter (
__EventFilter)- Defines what events to monitor
- Uses WQL (WMI Query Language)
- Example: Performance counter modifications every 60 seconds
CommandLineEventConsumer)- Defines action to take when event occurs
- Executes command line template
- Contains path to malicious executable
__FilterToConsumerBinding)- Links filter to consumer
- Activates the subscription
- Triggers every 60 seconds when performance data updates
- Extremely common event (low suspicion)
WMI persistence is powerful but rarely used by legitimate software, making it a red flag for advanced detection.
Persistence Removal
Remove()
Removes all persistence mechanisms:persist/persist.go:168-193
Self-Destruct
SelfDelete()
Deletes the executable after execution:persist/persist.go:196-219
Self-Delete Mechanism
Self-Delete Mechanism
How it works:Limitations:
- Create batch file in temp directory
- Batch file waits 3 seconds (
pingdelay trick) - Deletes the original executable
- Deletes itself (
%%~f0refers to batch file path)
- File may still be locked if handles are open
- AV may block deletion
- Event logs will show process termination
File Operations
CopyToTemp()
Copies executable to temp directory:persist/persist.go:222-243
RunFromTemp()
Runs a copy from temp directory:persist/persist.go:246-256
Usage Examples
Basic Persistence
Multiple Methods
Self-Delete After Execution
Detection and Mitigation
Defense Evasion Tips
Defense Evasion Tips
- Randomize names - Don’t use predictable names like “WindowsUpdate”
- Legitimate paths - Place executables in common locations
- Digital signatures - Sign executables (if possible)
- Timing - Install persistence during system updates
- Multiple methods - Use redundancy for persistence
- Fileless - Consider memory-only persistence
Security Considerations
Operational Security:
- Registry Run keys are logged in Event ID 4688 (process creation)
- Scheduled tasks generate Event ID 4698 (task created)
- WMI subscriptions are rarely monitored but visible to WMI queries
- Startup folder modifications are visible to users