Detection of Potential Persistence via Logon Script Registry Modification
Detection of adversaries modifying the UserInitMprLogonScript registry value to establish persistence via logon scripts.
Adversaries often attempt to achieve persistence on Windows systems by modifying registry keys that execute code automatically during user logon. One such mechanism involves the "UserInitMprLogonScript" registry value. By adding a malicious executable or script path to this value, an attacker ensures their code runs with the privileges of the user who logs on to the system. While this technique is traditionally associated with registry modifications, command-line tools like "reg.exe" are frequently used to perform these modifications stealthily or during post-exploitation activities. Defenders should monitor for command-line arguments that attempt to write to or modify this specific registry path, as such actions are rarely required for routine administrative tasks and often signal unauthorized persistence efforts.
Attack Chain
- Attacker gains initial access to the target host (e.g., via spearphishing or exploit).
- Attacker executes a shell or drops a payload to the disk.
- Attacker identifies the need for persistent access to survive system reboots.
- Attacker uses "reg.exe" or similar tools to interact with the Windows Registry.
- Attacker executes "reg add" to set or append a value to "HKCU\Environment\UserInitMprLogonScript" pointing to a malicious binary or script.
- Victim user logs into the system.
- Windows automatically executes the path specified in "UserInitMprLogonScript" during the login process.
- Attacker code executes with the user's privileges, establishing persistent access.
Impact
Successful exploitation results in unauthorized persistence, allowing attackers to maintain access across user sessions and system reboots. This technique effectively grants the attacker the ability to execute arbitrary code with the privileges of any user who logs into the compromised machine, increasing the risk of data exfiltration and credential theft.
Recommendation
- Deploy the Sigma rule below to detect instances of "UserInitMprLogonScript" being referenced in command-line arguments.
- Monitor logs for unauthorized use of "reg.exe" or "reg add" involving environment-related registry keys.
- Audit existing "UserInitMprLogonScript" registry values across the fleet for unexpected file paths.
Immediate actions
Deploy the Sigma rule to detect suspicious modifications of UserInitMprLogonScript
Threat Hunt
Search for existing UserInitMprLogonScript entries in the registry that reference files in non-standard paths
Data: Registry auditing logs
Detection coverage 1
Potential Persistence Via Logon Scripts - CommandLine
highDetects the addition of a new LogonScript to the registry value UserInitMprLogonScript for potential persistence
Detection queries are available on the platform. Get full rules →