Registry Run Keys / Startup Folder
Adversaries may achieve persistence by adding a program to a startup folder or referencing it with a Registry run key. Adding an entry to the 'run keys' in the Registry or startup folder will cause the program referenced to be executed when a user logs in. These programs will be executed under the context of the user and will have the account's associated permissions level. The following run keys are created by default on Windows systems: HKCU\Software\Microsoft\Windows\CurrentVersion\Run, HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce, HKLM\Software\Microsoft\Windows\CurrentVersion\Run, and HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce. Additional persistence can be achieved through the Startup folder at C:\Users\[Username]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup and the system-wide C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp. The BootExecute value under Session Manager and the load value under HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows are also abusable.
let RunKeyPaths = dynamic([
"\\CurrentVersion\\Run",
"\\CurrentVersion\\RunOnce",
"\\CurrentVersion\\RunOnceEx",
"\\CurrentVersion\\RunServices",
"\\CurrentVersion\\RunServicesOnce",
"\\CurrentVersion\\Policies\\Explorer\\Run",
"\\Windows NT\\CurrentVersion\\Windows",
"\\Control\\Session Manager"
]);
let TrustedProcesses = dynamic(["msiexec.exe", "TrustedInstaller.exe", "TiWorker.exe", "ccmexec.exe", "MpSigStub.exe"]);
DeviceRegistryEvents
| where Timestamp > ago(24h)
| where ActionType in ("RegistryValueSet", "RegistryKeyCreated")
| where RegistryKey has_any (RunKeyPaths)
| where InitiatingProcessFileName !in~ (TrustedProcesses)
| extend SuspiciousPath = RegistryValueData has_any ("\\Temp\\", "\\AppData\\Local\\Temp", "\\Downloads\\", "\\Public\\", "$Recycle.Bin", "\\ProgramData\\")
| extend SuspiciousExt = RegistryValueData has_any (".vbs", ".js", ".bat", ".cmd", ".ps1", ".hta", ".wsh", ".wsf")
| project Timestamp, DeviceName, ActionType, RegistryKey, RegistryValueName, RegistryValueData,
InitiatingProcessFileName, InitiatingProcessCommandLine, InitiatingProcessAccountName,
SuspiciousPath, SuspiciousExt
| sort by Timestamp desc Data Sources
Required Tables
False Positives
- Legitimate software installations that add Run key entries (antivirus, VPN clients, cloud sync tools like OneDrive, Dropbox)
- Enterprise deployment tools (SCCM, Intune, PDQ Deploy) adding startup entries for managed software
- User-installed utilities that register themselves for auto-start (Discord, Spotify, Steam)
- IT automation scripts that configure startup programs as part of endpoint provisioning
References (8)
- https://attack.mitre.org/techniques/T1547/001/
- https://learn.microsoft.com/en-us/windows/win32/setupapi/run-and-runonce-registry-keys
- https://oddvar.moe/2018/03/21/persistence-using-runonceex-hidden-from-autoruns-exe/
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1547.001/T1547.001.md
- https://github.com/SigmaHQ/sigma/tree/master/rules/windows/registry_set
- https://web.archive.org/web/20160214140250/http://blog.cylance.com/windows-registry-persistence-part-2-the-run-keys-and-search-order
- https://docs.microsoft.com/en-us/windows/win32/sysinfo/32-bit-and-64-bit-application-data-in-the-registry
- https://blog.malwarebytes.com/cybercrime/2013/10/hiding-in-plain-sight/
Unlock Pro Content
Get the full detection package for T1547.001 including response playbook, investigation guide, and atomic red team tests.