At logon
Logon Scripts: UserInitMprLogonScript and GPO Scripts
How UserInitMprLogonScript and Group Policy startup and logon scripts run code at every boot or logon, how attackers set them, and how to find and remove them.
- Tactics
- Persistence, Privilege escalation
- Runs
- At logon
- Set up by
- Users and administrators
- Locations
- HKCU\Environment
- HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Startup
- HKCU\Software\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Logon
- C:\Windows\System32\GroupPolicy\Machine\Scripts\scripts.ini
- C:\Windows\System32\GroupPolicy\User\Scripts\scripts.ini
- C:\Windows\System32\GroupPolicy\Machine\Scripts\psscripts.ini
How it works
Windows has several ways to run a script when a user logs on or the machine starts. ATT&CK splits them in two: a logon script set in the user's own registry (T1037.001), and scripts assigned from the network, through Active Directory or Group Policy (T1037.003).
UserInitMprLogonScript. A string value in HKCU\Environment. At logon, Userinit (see Winlogon) runs the command it holds, in the user's session and as that user. HKCU\Environment is also where the user's environment variables live, so the value shows up as a variable of the same name in every process of the session. Any user can set it for themselves, without administrator rights; the only place Windows shows it is the user's environment variables.
Group Policy scripts. A Group Policy Object can assign four kinds of script:
| Kind | Policy | Runs | As |
|---|---|---|---|
| Startup | Computer Configuration > Windows Settings > Scripts | At boot | SYSTEM |
| Shutdown | Computer Configuration > Windows Settings > Scripts | At shutdown | SYSTEM |
| Logon | User Configuration > Windows Settings > Scripts | At logon | The user |
| Logoff | User Configuration > Windows Settings > Scripts | At logoff | The user |
The local policy keeps its scripts in C:\Windows\System32\GroupPolicy\Machine\Scripts and ...\User\Scripts, each kind in its own folder, listed in scripts.ini (any script or program) and psscripts.ini (PowerShell) as numbered CmdLine and Parameters lines. A domain GPO keeps the same layout in SYSVOL, under \\<domain>\SYSVOL\<domain>\Policies\{GUID}. When the Group Policy client applies the policies, it writes the resulting list to the registry, under ...\CurrentVersion\Group Policy\Scripts in HKLM (startup and shutdown) and HKCU (logon and logoff): one numbered subkey per GPO, with GPO-ID (LocalGPO for the local policy), DisplayName and FileSysPath, and one numbered subkey per script, with Script and Parameters.
Since Windows 8.1, Group Policy logon scripts start five minutes after logon by default (the "Configure Logon Script Delay" setting).
Active Directory logon script. A domain user's scriptPath attribute (the "Logon script" field of the account's Profile tab) names a script relative to the NETLOGON share of the domain controllers. Local accounts have the same field, set with net user <name> /scriptpath:<path>.
Where it lives
| Location | Who can write it | On a stock standalone Windows 10 or 11 |
|---|---|---|
HKCU\Environment, value UserInitMprLogonScript | The user | Absent |
C:\Windows\System32\GroupPolicy\Machine\Scripts\scripts.ini, psscripts.ini | Administrators | Absent |
C:\Windows\System32\GroupPolicy\User\Scripts\scripts.ini, psscripts.ini | Administrators | Absent |
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Startup, Shutdown | The Group Policy client | Empty or absent |
HKCU\Software\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Logon, Logoff | The Group Policy client | Empty or absent |
\\<domain>\SYSVOL\<domain>\Policies\{GUID}\...\Scripts, \\<domain>\NETLOGON | Domain administrators and GPO editors | Not applicable |
The GroupPolicy folder is hidden. On a domain member, logon and startup scripts from domain GPOs are normal, and the registry copy lists them.
How attackers use it
The per-user value is a one-line, no-privilege persistence:
reg add "HKCU\Environment" /v UserInitMprLogonScript /t REG_SZ /d "C:\Users\alice\AppData\Roaming\Microsoft\Windows\logon.bat" /f
[Environment]::SetEnvironmentVariable('UserInitMprLogonScript', 'C:\Users\alice\AppData\Roaming\Microsoft\Windows\logon.bat', 'User')
MITRE ATT&CK records a loader used by APT28 setting HKCU\Environment\UserInitMprLogonScript to persist. The script is usually a short batch or VBScript file that starts the real payload, so the value itself looks harmless.
With administrator rights on one machine, the local policy gives a startup script that runs as SYSTEM at every boot. gpedit.msc adds it through the interface; an attacker can also write the script into Machine\Scripts\Startup and a line into scripts.ini directly. The registry copy reflects such a change only once Group Policy has processed it.
With rights over a domain GPO, or write access to the NETLOGON share, the same change reaches every computer or user the policy applies to: a new script in the GPO, one line appended to an existing domain logon script, or a changed scriptPath on chosen accounts. ATT&CK files the GPO change itself under Group Policy Modification (T1484.001).
How to check a host
On a live machine:
reg query "HKCU\Environment" /v UserInitMprLogonScript
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts" /s
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Group Policy\Scripts" /s
type C:\Windows\System32\GroupPolicy\Machine\Scripts\scripts.ini
gpresult /h gpresult.html
Get-ItemProperty 'Registry::HKEY_USERS\*\Environment' -Name UserInitMprLogonScript -ErrorAction SilentlyContinue
Get-ChildItem -Force C:\Windows\System32\GroupPolicy\Machine\Scripts, C:\Windows\System32\GroupPolicy\User\Scripts -Recurse
Get-ADUser -Filter "ScriptPath -like '*'" -Properties ScriptPath | Select-Object SamAccountName, ScriptPath
gpresult (run as the user, then elevated for the computer part) shows which GPOs apply and their scripts. The last command needs the ActiveDirectory module and lists domain accounts with a logon script.
Offline, read Environment in each NTUSER.DAT, Microsoft\Windows\CurrentVersion\Group Policy\Scripts in the SOFTWARE hive and Software\Microsoft\Windows\CurrentVersion\Group Policy\Scripts in each NTUSER.DAT, and the GroupPolicy folder with its file times. For domain scripts, the evidence is on the domain controllers: the SYSVOL folder of the GPO and its version history. The Environment key also holds the user's TEMP, TMP and Path, so its last-write time can move for other reasons. Process creation events (4688 with command lines, or Sysmon event 1) show the script's interpreter starting at logon or boot, and Sysmon event 13 records the registry value being set.
What stands out: any UserInitMprLogonScript at all, a local startup script on a workstation, a script in a user-writable folder, and a domain script changed recently or by an unexpected account.
What Windows Persistence flags
The tool reads three sources:
UserInitMprLogonScriptin each collectedNTUSER.DAT: Logon script in the user's environment (high).- The registry copy of applied Group Policy scripts:
StartupandShutdownin the SOFTWARE hive (trigger: boot),LogonandLogoffin eachNTUSER.DAT(trigger: logon). Each script is an entry named after its kind and file, with the GPO's display name and folder. A script recorded by file name alone is resolved against that folder, as<FileSysPath>\Scripts\<kind>\<file>. Group Policy script is medium when the GPO is the local one (GPO-IDisLocalGPO) and informational for domain GPOs, which are normal on domain members. scripts.iniandpsscripts.iniof the local policy, when theGroupPolicyfolder is in the collection: one entry per script, with its section, Computer or User, and script or PowerShell. Group Policy script is always medium here.
The command-line rules run on every command: Runs from a temporary or public folder, Runs from a network share (which domain scripts, kept on SYSVOL, raise as well), Encoded PowerShell command, Downloads and runs code, Windows program used to run outside code, Script run by the Windows script host and the others, plus System-wide autostart from a writable folder for startup and shutdown scripts. Across mechanisms: Written date, Inside a Defender exclusion (exclusion) and program also runs from mechanisms.
Hide Windows entries hides an entry only when its program is in Windows' folders and every flag is informational.
Limits: the tool reads the command, not the script file, so an innocent-looking logon.bat that starts the payload is only as visible as its path. Script names in scripts.ini are shown as written, not resolved to their folder. It does not see the scriptPath of accounts (in Active Directory, or in the SAM for local accounts), the contents of SYSVOL or NETLOGON, or GPOs that apply only after the collection.
Cleaning up
- Preserve the value or the ini files and the scripts they name, with their times, before changing anything:
reg export HKCU\Environment environment.reg, and a copy of theGroupPolicyfolder. - Remove the per-user value:
reg delete "HKCU\Environment" /v UserInitMprLogonScript /f. Processes already running keep the variable until the user logs off. - Remove a local policy script in
gpedit.msc(Computer or User Configuration > Windows Settings > Scripts), not by editingscripts.inialone, then rungpupdate /forceand check that the registry copy is gone. - For a domain script, fix the GPO or the
NETLOGONscript on the domain controllers, review who changed it, and check every machine the policy reached. Removing it from one host's registry achieves nothing: the next refresh writes it back. - A startup or shutdown script ran as SYSTEM: treat the host as fully compromised and rotate its local administrator and service credentials. A logon script ran as the user: rotate that user's passwords and sessions.
See also
Related techniques
On Windows Forensics
The artifacts behind this technique, in the Windows Forensics reference: