-
Notifications
You must be signed in to change notification settings - Fork 10
Registry Persistence
The following section is sourced from this blog.
Attackers continue to abuse Windows Services for their SYSTEM-level privileges (NT AUTHORITY\SYSTEM), which grant unrestricted access to the system. While UAC bypasses were common on Windows 7/8, modern Windows 10/11 and Server 2016+ enforce stricter controls:
-
Protected Process Light (PPL): Critical services (e.g.,
LSASS.exe) are isolated from tampering. - Driver Signature Enforcement: Blocks unsigned kernel-mode drivers, reducing "Own Process" service hijacking.
- Windows Defender Application Control (WDAC): Restricts unauthorized DLL/EXE execution, complicating "Share Process" attacks.
| Technique of persistence | Risk Assessment | Usage |
|---|---|---|
| HKLM\System\CurrentControlSet\Services | Runs as SYSTEM, very stealthy, safe - High risk if attackers bypass WDAC. |
Used for long-term remote access in early stages and as backup access - APTs deploy phantom DLLs (e.g., APT28’s "GreyEnergy"). - Mitigation: Enforce code integrity policies and monitor CurrentControlSet changes (Sysmon Event ID 13). |
| HKLM\Software run keys | Runs as Administrator, less stealthy - Moderate risk (common in commodity malware). |
Used for initial compromise - Ransomware (e.g., BlackCat) uses Run keys for initial foothold. - Mitigation: Restrict registry writes via AppLocker and hunt for reg.exe anomalies (Elastic/Splunk). |
| HKCU run keys | Early stage droppers & downloaders, noisy and dangerous - Low risk (noisy, user-level). |
Initial exploit, day zero activity - Phishing payloads (e.g., QakBot) leverage HKCU for persistence. - Mitigation: Deploy UEBA to detect anomalous user activity. |
Contemporary registry persistence techniques fall into 3 operational categories:
| Type | Definition | Article Examples |
|---|---|---|
| List Appenders | Add to existing multi-item registries (e.g., multiline values, subkey lists) | LSA Authentication Packages, BootExecute |
| Ghost Key Actors | Create keys that Windows checks but don't exist by default | Office Test\Special\Perf key |
| Value Overwriters | Replace single default values in commonly monitored keys | UserInit shell replacement |
-
Detection Bypass: List appenders (e.g., adding to
BootExecute) evade tools that only alert on replacement of known values. - Low IOC Coverage: 83% of enterprise EDRs lack rules for "Ghost Key" creation (source: article's "Forgotten Techniques" section). 3
Although attackers still target Windows Services for SYSTEM-level privileges (NT AUTHORITY\SYSTEM), modern Windows 10/11 and Server 2016+ systems enforce stricter controls:
- User Account Control (UAC) bypass via service abuse is mitigated by Windows Defender Credential Guard and Protected Process Light (PPL) restrictions.
-
Driver Signature Enforcement blocks unsigned kernel-mode drivers, reducing "Own Process" service hijacking.
- Windows Defender Application Control (WDAC) and AMSI scrutinize unauthorized DLL/EXE execution, complicating "Share Process" (svchost.exe) attacks.
Service Types in Modern Context:
| Type | Contemporary Risks & Detection | Detection & Mitigation |
|---|---|---|
| Own Process | - Rare in modern attacks due to AMSI/EDR scrutiny. - Seen in ransomware (e.g., LockBit’s .exe droppers). |
- Block unsigned executables via WDAC. - Monitor CreateService API calls (Sysmon Event ID 12). |
| Share Process | - Still abused via DLL sideloading (e.g., Cobalt Strike’s execute-assembly). - Detected via anomalous svchost child processes (Sysmon Event ID 1). |
- Alert on svchost.exe spawning unusual children (e.g., powershell.exe) via EDR/Sysmon (Event ID 1). |
HKLM\System\CurrentControlSet\services
- Loaded by the Service Controller at various times during computer operation(system startup, event trigger)
- Driver Signature Enforcement: Windows 10/11 blocks unsigned drivers/services unless Secure Boot is disabled.
- Protected Services: Critical services (e.g., LSASS) now run as Protected Processes (PPL), preventing tampering
-
Detection: Modern EDRs (CrowdStrike, Microsoft Defender) flag:
- Unusual service binaries (e.g.,
svchost.exespawningpowershell.exe) - Services with mismatched hashes or unsigned DLLs (via AMSI)
- Correlates process lineage with registry changes(ex.
svchost.exespawningcmd.exe)
- Unusual service binaries (e.g.,
HKLM\Software\Microsoft\Windows NT\CurrentVersion\SvcHost
- Usually heavily monitored
- Groups services that have similar privilege needs
- Hijack deprecated services (e.g.,
IISADMIN) to load malicious DLLs- RBAC, Virtualization-Based Security (VBS), and Credential Guard
- Windows 11 auto-blocks unused
netsvcsgroups via controlled folder access. - Virtualization-Based Security (VBS): Isolates critical services to prevent credential theft.
- Windows 11 auto-blocks unused
- RBAC, Virtualization-Based Security (VBS), and Credential Guard
- Hijack deprecated services (e.g.,
- The
netsvcsgroup still exists and categorizes network-dependent services.- Windows 10/11 and Server 2022 have fewer unused
netsvcsentries due to deprecated services (e.g.,Irmon,Ntmssvc)
- Windows 10/11 and Server 2022 have fewer unused
- Sysmon (Event ID 12/13) logs registry modifications to
SvcHostkeys - Tools like Velociraptor baseline legitimate
netsvcsentries and alert on anomalies
User-Specific (HKCU)
HKCU\Software\Adobe\Acrobat\UpdaterHKCU\Software\Microsoft\Office\Common\AutoUpdateHKCU\Software\Google\Chrome\NativeMessagingHostsHKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell FoldersHKCU\Software\Microsoft\Windows NT\CurrentVersion\Fonts-
HKCU\Software\7-Zip\FM(if 7-Zip is installed) System-Wide (HKLM) HKLM\Software\Microsoft\Windows Defender\FeaturesHKLM\Software\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCacheHKLM\Software\Microsoft\Cryptography\RNGHKLM\Software\Microsoft\Windows\CurrentVersion\Setup\PersistenceComponentsHKLM\Software\Policies\Microsoft\Windows\WindowsUpdateHKLM\Software\Microsoft\Windows\CurrentVersion\Reliability
- Updaters:
AdobeUpdater- `Java Update Scheduler
FlashPlayerSecurityPatch- `MicrosoftEdgeAutoUpdate
- System Tools:
-
SecurityHealth(mimics Windows Defender) -
RuntimeBroker(real Windows process) - `Background Tasks Infrastructure Service
Windows Error Reporting
-
- Common Software:
- `TeamViewer_Service
- `ZoomPresence
- `SlackHelper
OneDriveSyncEngine
- Generic Background Tasks:
- `PowerManagement
- `NetworkConfigurator
DisplayCalibration- `AudioEndpointBuilder
- Hardware/Driver-Related:
- `NvidiaDisplayContainer
- `IntelHDAService
- `RealtekAudioService
AMDExternalEvents
- Avoid Overused Names: Don’t use
svchost,explorer, orwinlogon—these are heavily monitored. - Use Subkeys: Hide deeper in the registry (e.g.,
HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run). - Match Installed Software: Check the target’s installed programs (e.g.,
CCleanerorVLC) and mimic their naming. - Environment Variables: Use paths like
%APPDATA%\Microsoft\Windows\Themes\Cursorsfor payload storage. - Legacy Key Revival: Target deprecated-but-still-functional keys like
HKLM\...\Office Test\Special\Perf(checked by Office apps) - Multi-Stage List Injection: Append to existing lists rather than replacing entries (e.g., add to LSA's
Authentication Packagesvs overwriting) - COM Hybrid Approach: Create both HKLM and HKCU entries for App Paths/Credential Providers to ensure persistence across privilege levels
- Boot Sequence Mimicry:
- Use names like
BootVerification.exein `%SystemRoot%\System32** - Match Microsoft's timestamping on registry keys
- Use names like
-
Ghost Key Creation:
- Target registry paths checked by apps but non-existent by default
- Example:
HKLM\Software\Microsoft\Office Test\Special\Perf(triggers on Office launch) - Find via Procmon: Filter
Result=NAME NOT FOUNDon high-value processes (winword.exe, etc.)
-
Cloud-Hybrid Attacks:
- Attackers pivot from on-prem registry persistence to Azure Arc-enabled servers for cross-cloud access.
- Mitigation: Use Azure Sentinel to correlate registry changes with cloud identity anomalies.
-
Zero-Trust Strategies:
- Enforce conditional access policies for service accounts.
- Implement just-in-time (JIT) privilege escalation for administrators.
-
List Appender Defense:
- Use Canary Values: Insert fake entries in multiline registries (e.g.,
BootExecute) to detect additions - Enable Registry Filtering Driver logging (Microsoft-Windows-FilterManager/0x803)
- Use Canary Values: Insert fake entries in multiline registries (e.g.,
Microsoft.Win32.RegistryKey key;
key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("My_Key"); key.SetValue("My_Key", "Test");
key.Close();Registry keys can be added from the terminal to the run keys to achieve persistence. These keys will contain a reference to the actual payload that will executed when a user logs in. The following registry locations is known to be used by threat actors and red teams that use this method of persistence.
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /v Pentestlab /t REG_SZ /d "C:\Users\pentestlab\pentestlab.exe"
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v Pentestlab /t REG_SZ /d "C:\Users\pentestlab\pentestlab.exe"
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunServices" /v Pentestlab /t REG_SZ /d "C:\Users\pentestlab\pentestlab.exe"
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce" /v Pentestlab /t REG_SZ /d "C:\Users\pentestlab\pentestlab.exe"
If elevated credentials have been obtained it is preferred to use the Local Machine registry locations instead of the Current User as the payload will executed every time that the system boots regardless of the user who is authenticating with the system.
reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run" /v Pentestlab /t REG_SZ /d "C:\tmp\pentestlab.exe"
reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v Pentestlab /t REG_SZ /d "C:\tmp\pentestlab.exe"
reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices" /v Pentestlab /t REG_SZ /d "C:\tmp\pentestlab.exe"
reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce" /v Pentestlab /t REG_SZ /d "C:\tmp\pentestlab.exe"
Oddvar Moe discovered two more registry locations that could allow red teams to achieve persistence by executing either an arbitrary payload or a DLL. These will be executed during logon and require admin level privileges.
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\0001" /v Pentestlab /t REG_SZ /d "C:\tmp\pentestlab.exe"
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\0001\Depend" /v Pentestlab /t REG_SZ /d "C:\tmp\pentestlab.dll"
| Technique | Modern Detection Signature | Recommended Control |
|---|---|---|
| Boot Verification Hijack |
services.exe launching non-MS signed binaries post-boot |
WDAC + Protected Service policies |
| SMSS Configuration | Unexpected entries in BootExecute multiline string |
Baseline monitoring of Session Manager keys |
| RDP Startup Abuse |
termsvcs.dll anomalies in RDP sessions |
Restrict rdpwd key modifications |
| App Paths Hijacking | Non-standard EXE paths in App Paths keys | Registry access control (JEA) |
- https://r4bb1t.medium.com/windows-persistence-registry-run-keys-e9acb20c4a7d
- https://pentestlab.blog/2019/10/01/persistence-registry-run-keys/
- https://www.cyberark.com/resources/threat-research-blog/persistence-techniques-that-persist
#windows #registry #persistence