At logon
Registry Run Keys: Windows Persistence at Logon
How the Run and RunOnce registry keys start programs at every Windows logon, how attackers plant and disguise values there, and how to find and remove them.
- MITRE ATT&CK
- T1547.001
- Tactics
- Persistence, Privilege escalation
- Runs
- At logon
- Set up by
- Users and administrators
- Locations
- HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
- HKCU\Software\Microsoft\Windows\CurrentVersion\Run
- HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce
- HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce
- HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run
- HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run
- HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run
How it works
When a user logs on, Explorer, the Windows shell, reads the Run keys and starts the command line held in each of their values. The value name is a free label; the data is a command line, stored as REG_SZ or REG_EXPAND_SZ. The key under HKLM applies to every user who logs on, the key under HKCU to one user. Either way the program runs in the user's session, with that user's token, and its parent process is explorer.exe. A value in HKLM needs administrator rights to write, but it does not run as SYSTEM: it buys code in every account's session, including other administrators'.
The keys sit under Software\Microsoft\Windows\CurrentVersion in both hives:
| Key | Behaviour |
|---|---|
Run | Runs at every logon |
RunOnce | Runs at the next logon; Windows deletes the value before it starts the command |
RunOnce, value name starting with ! | Deletion is deferred until the command has run, so a failed run is tried again |
RunOnce, value name starting with * | Also runs in Safe Mode, where Run keys are otherwise ignored |
RunOnceEx | Numbered subkeys of commands, used by setup programs, run once |
Policies\Explorer\Run | Written by the Group Policy setting "Run these programs at user logon"; runs at every logon |
RunServices, RunServicesOnce | Windows 9x keys; ATT&CK still lists them, and a value there is odd in itself |
Since Windows 8, the Startup tab of Task Manager (and, on Windows 10 and 11, Settings > Apps > Startup) can switch an entry off without touching the Run value. Explorer records that choice in ...\Explorer\StartupApproved\Run (Run32 for 32-bit entries, StartupFolder for Startup folder items): a binary value with the same name, whose first byte is even when the entry is enabled and odd when it is disabled, followed by the time it was disabled.
On 64-bit Windows, a 32-bit program that writes HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run lands in HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run. Explorer runs both. HKCU\Software is not redirected, so per-user entries have a single key.
Where it lives
| Key | Who can write it | On a stock Windows 10 or 11 |
|---|---|---|
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run | Administrators, SYSTEM | SecurityHealth = %windir%\system32\SecurityHealthSystray.exe (the Windows Security icon), plus OEM and vendor tray programs |
HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run | Administrators, SYSTEM | 32-bit vendor entries |
HKLM\...\RunOnce, HKLM\...\RunOnceEx | Administrators, SYSTEM | Usually empty |
HKLM\...\Policies\Explorer\Run | Administrators, Group Policy | Absent |
HKCU\Software\Microsoft\Windows\CurrentVersion\Run | The user | Often OneDrive, pointing at OneDrive.exe /background in the profile |
HKCU\...\RunOnce, HKCU\...\Policies\Explorer\Run | The user | Usually empty |
HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows, values Load and Run | The user | Empty or absent; Windows 3.x compatibility values |
Each user's keys live in that user's NTUSER.DAT. C:\Users\Default\NTUSER.DAT is the template Windows copies into every new profile, so a value planted there reaches every account created afterwards.
How attackers use it
A per-user Run value needs no privileges and a single command, which is why commodity malware relies on it so much. MITRE ATT&CK records Emotet, for example, adding its payload to HKCU\...\Run.
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v OneDriveUpdate /t REG_SZ /d "\"C:\Users\alice\AppData\Roaming\Microsoft\OneDrive\odupdate.exe\" /background" /f
New-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Run' -Name 'SecurityHealthUpdate' -Value 'C:\ProgramData\Microsoft\svchost.exe' -PropertyType String -Force
The usual disguises:
- A value name copied from a real entry (OneDrive, SecurityHealth, an audio or graphics tray) with a program somewhere else.
- A Windows program name in a user folder (
svchost.exein%APPDATA%), or a name one letter away (scvhost.exe). - A built-in program that runs the payload for it:
rundll32.exe C:\Users\Public\lib.dll,Start,wscript.exe //B C:\ProgramData\u.vbs,mshta.exewith avbscript:orjavascript:argument, or PowerShell with-w hidden -enc. Poweliks (2014) kept its payload in the registry and started it from a Run value throughrundll32.exe javascript:andmshtml,RunHTMLApplication, with no file on disk. - A
RunOncevalue that the payload writes back each time it starts: the key is empty while the program runs, so a live check at that moment finds nothing. - The quieter locations:
Policies\Explorer\Run, theWOW6432Nodecopy, and theLoadvalue, which fewer tools and analysts check.
How to check a host
On a live machine, from an elevated prompt:
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
reg query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run"
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx" /s
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Run"
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce"
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run"
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run"
autorunsc.exe -accepteula -a l -s -h -c * > logon.csv
HKCU is only the account running the prompt. Users who are logged on have their hive under HKU\<SID>, and Get-ItemProperty 'Registry::HKEY_USERS\*\Software\Microsoft\Windows\CurrentVersion\Run' lists them all. For a user who is not logged on, load the hive: reg load HKU\Case C:\Users\bob\NTUSER.DAT, query HKU\Case\Software\..., then reg unload HKU\Case.
Offline, read Microsoft\Windows\CurrentVersion\Run and its siblings in the SOFTWARE hive, and Software\Microsoft\Windows\CurrentVersion\Run in each NTUSER.DAT, including the Default profile's. Values have no time of their own: the key's last-write time is when any value in it was last added, changed or removed. Line it up with process creation (event 4688 with command lines, or Sysmon event 1, parent explorer.exe shortly after a logon), Sysmon event 13 (registry value set) on a path ending in \CurrentVersion\Run, and event 4657 if auditing was set on the key.
What stands out: a program in a temporary, public or profile folder (and, for an HKLM value, any user-writable folder), an interpreter or built-in program running a file outside Windows' folders, encoded or hidden PowerShell, a Windows name outside System32, a value name that imitates a vendor while its path does not, and a key written around the time of the incident.
What Windows Persistence flags
The tool reads, in the SOFTWARE hive and in every user hive of the collection, the Run, RunOnce, RunServices, RunServicesOnce and Policies\Explorer\Run keys under Microsoft\Windows\CurrentVersion, the WOW6432Node copies of Run, RunOnce and Policies\Explorer\Run, the numbered subkeys of RunOnceEx and the Depend subkeys under them (skipping their Flags and Title values), and, per user, the Load and Run values of Windows NT\CurrentVersion\Windows. In the SOFTWARE hive it also reads the Run and RunOnce keys under Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows\CurrentVersion, Remote Desktop's install-mode copy. The user hives include the Default profile's, shown as the user "Default profile", and those of SYSTEM (.DEFAULT), LOCAL SERVICE and NETWORK SERVICE when they were collected.
Each non-empty value becomes an entry that names its key. RunOnce entries say whether they run once, are deleted only after they succeed (!) or also run in Safe Mode (*). For the Run key and its 32-bit copy, the keys Task Manager's switch covers, a matching StartupApproved\Run or Run32 value marks the entry enabled or disabled, with the date under "Switched off in Task Manager".
Flags of its own:
- Run key set by policy (medium): any value in
Policies\Explorer\Run. - Legacy Load/Run value (medium): a non-empty
LoadorRunvalue.
The command-line rules run on every value: Downloads and runs code, Encoded PowerShell command (with the decoded script), Obfuscated command, Runs with a hidden window, Bypasses the PowerShell execution policy, Runs from a temporary or public folder, Runs from a network share, Windows program used to run outside code, Script run by the Windows script host, Windows program name in the wrong place, Name one letter away from a Windows program, Machine-made name, and the rules for defences, backups, accounts and logs (Changes Defender settings, Deletes backups or recovery, Creates an account or grants admin, Clears event logs). System-wide autostart from a writable folder applies to HKLM values only: a per-user entry running from AppData is normal.
Across mechanisms: Written date when the key changed in the 7 days before the newest time collected from that host, Inside a Defender exclusion (exclusion), and program also runs from mechanisms.
With Hide Windows entries on, values whose program sits in Windows' folders and that raise no flag, such as SecurityHealth, are hidden.
Limits: per-user keys are only as complete as the NTUSER.DAT files collected. A RunOnce value that already ran is gone. The tool reads the command, not the program: it does not check signatures or file contents.
Cleaning up
- Preserve:
reg export "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" run-hkcu.reg(or theHKU\<SID>path of another user), then copy the program and recordGet-FileHashfor it. - Stop the running process, for example
Get-Process | Where-Object Path -eq 'C:\Users\alice\AppData\Roaming\Microsoft\OneDrive\odupdate.exe' | Stop-Process. - Delete only the value:
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v OneDriveUpdate /f. Never delete the key itself or stock values such asSecurityHealth. Disabling the entry in Task Manager is not removal: the value stays and anyone can switch it back on. - Delete the payload and its folder, and the matching
StartupApprovedvalue if there is one. - Look for the same program in every other profile, the Default profile, and the other mechanisms (services, scheduled tasks, Winlogon). An empty
RunOncekey proves nothing: the value deletes itself. - Rotate what the user's session exposed: passwords, browser sessions and tokens.
See also
Related techniques
On Windows Forensics
The artifacts behind this technique, in the Windows Forensics reference: