Skip to content
WETNav

PersistenceMedium

Registry Run key persistence

Also known as Run key, Autorun persistence

Adding an autorun value so code launches at logon or boot. Sysmon 13 and, with a SACL, Security 4657 record the value set.

Signals in the logs

  1. 01Sysmon13Registry Event (Value Set)Any host

    A value was set under a Run/RunOnce or Winlogon key.

    TargetObject
    ...\CurrentVersion\Run\<value> or ...\Winlogon\Userinit
    Details
    the command or path written as the value data
    Image
    process that wrote the value
  2. 02Security4657A registry value was modifiedAny host

    A registry value was modified on a key with auditing enabled.

    ObjectName
    the Run or Winlogon key
    ObjectValueName
    the value name added or changed
    NewValue
    the command or path written

What happens

Registry Run and RunOnce keys launch their referenced program every time a user logs on (HKCU) or the system starts (HKLM), which makes them a simple and very common persistence location. The usual targets are HKLM and HKCU \SOFTWARE\Microsoft\Windows\CurrentVersion\Run and RunOnce, with Winlogon's Userinit and Shell values a stealthier variant. The operator writes a value whose data is the path to their payload, often a script host with an encoded command or a binary in a user-writable folder. Setting the value is visible to Sysmon as event 13 (registry value set) when the config covers these keys, and to the Security log as 4657 when a SACL has been placed on the key. The value name and data reveal exactly what will run and from where.

Logging you need

  • Sysmon 13 requires a configuration that includes RegistryEvent rules for the autorun keys.
  • Security 4657 requires both the Audit Registry subcategory and a SACL on the specific key; neither is present by default.
  • HKCU keys are per-user, so coverage must include the right user hive.

Hunt queries

Starting points. Tune thresholds and exclusions to your environment before alerting on them.

Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-Sysmon/Operational'; Id=13} |
  Where-Object { $_.Message -match 'CurrentVersion\\Run|Winlogon\\(Userinit|Shell)' }

Benign look-alikes

  • Applications that legitimately add a Run value to start at logon (updaters, sync clients, chat apps).
  • Driver and peripheral software that registers autoruns.
  • User-initiated installs adding startup entries.

Notes

  • Autorun data pointing at powershell.exe with an encoded command, mshta, rundll32, or a path under %APPDATA%/%TEMP% is a strong indicator.
  • Winlogon Userinit and Shell values should rarely change; a modification there deserves immediate review.

References