How the attack works
Every user object in Active Directory has an attribute scriptPath (Script-Path). It specifies the path of the user's logon script, which Windows starts in the user's session each time the user logs on to a domain computer. Administrators set it in the properties of the account or in bulk with scripts.
The attribute is an ordinary property of the account, so every principal with write access to the account can change it. This includes generic write permissions that were delegated to a help desk group years ago and permissions that an attacker obtained through an access control path. An attacker sets the path to a script they control and waits. At the next logon the script runs with the rights of the target, on whatever computer the target uses. If the target is an administrator, the attacker's code runs as an administrator without the password, the hash or a ticket of that account ever being touched. The value stays until someone removes it, so the code runs at every logon.
The domain controller records the change in two places. Event 4738, written for every change of a user account, has a Script Path field that holds the new value and a dash when the attribute did not change. Event 5136 is written when an auditing entry covers writes on the account and shows the attribute scriptPath with the value that was added. Neither event tells what the script does. A second way to the same end, changing the content of a script that a path already points to, leaves no directory event at all and is a matter of file permissions on the share that holds the scripts. Where Audit Detailed File Share is enabled on the domain controllers, a write to the NETLOGON share through the network is logged in event 5145, which one rule on this page reads.
What an attacker needs
- Write access to the
scriptPathattribute of the target account, for example through a write-all-properties, generic write or full control permission on the account or on its organizational unit. - A location for the script that the target's computer can read at logon and that the attacker can write to.
- The target has to log on to a domain computer after the change.
Impact
Code of the attacker's choice runs in the session of the target at every logon. For a privileged target this is the rights of that account on the computer it logs on to and in the domain. For any target it is access to the user's data and sessions and a foothold on the user's computer. The setting persists across password changes.
Detection rules
File Written in the Logon Script Share of a Domain Controller
Detects write access over the network (5145 with WriteData, %%4417, in the access list) to a file in the NETLOGON share, or in the scripts folder of the SYSVOL share that NETLOGON publishes. Logon scripts named by the scriptPath attribute are stored in the NETLOGON share, so replacing the content of a script that a path already points to runs code in the session of every account that uses it, without any change to the directory. The changed file is in RelativeTargetName, the writer in SubjectUserName and the source in IpAddress. Requires "Audit Detailed File Share" on the domain controllers. A file changed locally on a domain controller, not through a share, does not produce this event.
title: File Written in the Logon Script Share of a Domain Controller
id: 918b867e-9f45-449f-8d37-87a3a2da43db
status: experimental
description: >-
Detects write access over the network (5145 with WriteData, %%4417, in the
access list) to a file in the NETLOGON share, or in the scripts folder of the
SYSVOL share that NETLOGON publishes. Logon scripts named by the scriptPath
attribute are stored in the NETLOGON share, so replacing the content of a
script that a path already points to runs code in the session of every
account that uses it, without any change to the directory. The changed file
is in RelativeTargetName, the writer in SubjectUserName and the source in
IpAddress. Requires "Audit Detailed File Share" on the domain controllers. A
file changed locally on a domain controller, not through a share, does not
produce this event.
references:
- https://attack.mitre.org/techniques/T1037/003/
- https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/event-5145
- https://learn.microsoft.com/en-us/troubleshoot/windows-server/user-profiles-and-logon/assign-logon-script-profile-local-user
- https://learn.microsoft.com/en-us/troubleshoot/windows-server/group-policy/missing-sysvol-and-netlogon-shares
author: Forestall
date: 2026-11-18
tags:
- attack.persistence
- attack.privilege-escalation
- attack.t1037.003
logsource:
product: windows
service: security
detection:
selection_access:
EventID: 5145
AccessList|contains: '%%4417'
selection_netlogon:
ShareName|endswith: '\NETLOGON'
selection_sysvol_scripts:
ShareName|endswith: '\SYSVOL'
RelativeTargetName|contains: '\scripts\'
condition: selection_access and (selection_netlogon or selection_sysvol_scripts)
falsepositives:
- Administrators who maintain logon scripts and the tools that deploy them. Exclude their management workstations by IpAddress or the accounts by exact SubjectUserName, and review a write to a script that privileged accounts run.
level: medium
False positives
- Administrators who maintain logon scripts and the tools that deploy them. Exclude their management workstations by IpAddress or the accounts by exact SubjectUserName, and review a write to a script that privileged accounts run.
Logon Script Path Attribute Written on an Account
Detects a value written to the scriptPath attribute of an account (event 5136, Value Added). The attribute specifies the path of the user's logon script, which runs in the user's session at every logon, so a write by an account that does not administer the target is a way to run code as the target. The new path is in AttributeValue, the account in ObjectDN and the writer in SubjectUserName. The previous value, if there was one, is in a Value Deleted event with the same OpCorrelationID. Compared with event 4738 this event exists only where an auditing entry covers the account, which lets you limit it to the organizational units of privileged accounts and keep routine changes of ordinary users out. Requires Audit Directory Service Changes and a SACL that audits writes on the user objects.
title: Logon Script Path Attribute Written on an Account
id: 269ea1ae-b614-4f22-9a75-0c6d30b45d52
status: experimental
description: >-
Detects a value written to the scriptPath attribute of an account (event
5136, Value Added). The attribute specifies the path of the user's logon
script, which runs in the user's session at every logon, so a write by
an account that does not administer the target is a way to run code as
the target. The new path is in AttributeValue, the account in ObjectDN
and the writer in SubjectUserName. The previous value, if there was one,
is in a Value Deleted event with the same OpCorrelationID. Compared with
event 4738 this event exists only where an auditing entry covers the
account, which lets you limit it to the organizational units of
privileged accounts and keep routine changes of ordinary users out.
Requires Audit Directory Service Changes and a SACL that audits writes on
the user objects.
references:
- https://learn.microsoft.com/en-us/windows/win32/adschema/a-scriptpath
- https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/event-5136
- https://attack.mitre.org/techniques/T1037/003/
author: Forestall
date: 2026-11-18
tags:
- attack.persistence
- attack.privilege-escalation
- attack.t1037.003
logsource:
product: windows
service: security
detection:
selection:
EventID: 5136
AttributeLDAPDisplayName: scriptPath
OperationType:
- '%%14674'
- 'Value Added'
condition: selection
falsepositives:
- Administrators and provisioning systems that assign logon scripts. Where the auditing entry covers only privileged accounts, a write has few routine reasons. Confirm the change and read the script the path points to.
level: medium
False positives
- Administrators and provisioning systems that assign logon scripts. Where the auditing entry covers only privileged accounts, a write has few routine reasons. Confirm the change and read the script the path points to.
Logon Script Path Changed on a User Account
Detects event 4738 (a user account was changed) in which the Script Path field holds a value. The field carries the new value of the scriptPath attribute when it was changed, and a dash when it was not. The attribute specifies the path of the account's logon script, which Windows runs in the user's session at every logon. Whoever sets it gets code executed with the rights of that user, without the user's password. The rule excludes the dash, the code for "value not set" (%%1793) and an empty value, so it reports paths that were set and not paths that were cleared. For local accounts on member servers and workstations the field always shows the current value, so apply the rule to the Security logs of domain controllers. Microsoft recommends monitoring changes of this field for critical accounts. Requires Audit User Account Management. The event needs no SACL.
title: Logon Script Path Changed on a User Account
id: 2c6ca83b-0f03-41fa-91cd-943d53269a3e
status: experimental
description: >-
Detects event 4738 (a user account was changed) in which the Script Path
field holds a value. The field carries the new value of the scriptPath
attribute when it was changed, and a dash when it was not. The attribute
specifies the path of the account's logon script, which Windows runs in
the user's session at every logon. Whoever sets it gets code executed
with the rights of that user, without the user's password. The rule
excludes the dash, the code for "value not set" (%%1793) and an empty
value, so it reports paths that were set and not paths that were
cleared. For local accounts on member servers and workstations the field
always shows the current value, so apply the rule to the Security logs of
domain controllers. Microsoft recommends monitoring changes of this field
for critical accounts. Requires Audit User Account Management. The event
needs no SACL.
references:
- https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/event-4738
- https://learn.microsoft.com/en-us/windows/win32/adschema/a-scriptpath
- https://attack.mitre.org/techniques/T1037/003/
author: Forestall
date: 2026-11-18
tags:
- attack.persistence
- attack.privilege-escalation
- attack.t1037.003
logsource:
product: windows
service: security
detection:
selection:
EventID: 4738
filter_not_changed:
ScriptPath:
- '-'
- '%%1793'
- ''
condition: selection and not filter_not_changed
falsepositives:
- Administrators and provisioning systems that assign logon scripts to new or moved users, often for many accounts at once. Exclude the provisioning account by SubjectUserName, or limit the rule to the privileged accounts you list.
level: medium
False positives
- Administrators and provisioning systems that assign logon scripts to new or moved users, often for many accounts at once. Exclude the provisioning account by SubjectUserName, or limit the rule to the privileged accounts you list.
Detection logic
Patterns that need more than one event, a baseline or knowledge of your own environment. Each is a hypothesis to build and tune in your SIEM, not a ready rule.
Script path set, target logs on, and the path is changed back
An attacker who wants one execution in the session of the target sets the path, waits for the logon and restores the old value so that a later review of the account shows nothing. Two changes of the script path of one account with a logon of that account in between are not how administrators manage logon scripts.
- The script path of an account changes: event 4738 in which
ScriptPathis not a dash. KeepTargetUserName,TargetSid,SubjectUserNameand the value. - After that the target logs on: event 4624 with the same account in
TargetUserName. - Within 7 days of the first change, event 4738 for the same
TargetSidshowsScriptPathchanged again, to the earlier value or to an empty one.
Events47384624
LimitsAn administrator who corrects a wrong path produces two changes as well, normally within minutes and before the user logs on. The 7 days are a starting point. An attacker who leaves the path in place is not matched and is covered by the single-event rules.
Triage
- Read the target account (TargetUserName in event 4738, ObjectDN in event 5136), the new path (ScriptPath or AttributeValue) and the account that made the change (SubjectUserName, SubjectLogonId).
- Find out where the path leads. Read the script it names, check who can write to that location and when the file was last changed.
- Check whether the target is privileged and whether the actor normally administers that account.
- Look for logons of the target after the change (event 4624) and for what ran on those computers at logon.
- Check whether the same actor set the path on other accounts.
Response
Once the attack is confirmed:
- Clear the script path on the affected accounts or set it back to the approved value.
- Keep a copy of the script as evidence, then remove it and restrict write access to its location.
- Treat every computer the target logged on to after the change as compromised, and reset the credentials of the target and of the accounts that were used on those computers.
- Disable the account that made the change and remove the write access that allowed it.
- Search the directory for other accounts whose script path points to the same location.
Mitigation
- Review who has write access to user accounts, above all to privileged accounts, and remove generic write and full control permissions held by accounts outside the administration tier of the target.
- Keep privileged accounts in organizational units whose delegation is limited to Tier 0, so that help desk permissions do not reach them.
- Remove logon script paths that are no longer needed and keep the remaining scripts in a share that only administrators can write to.
- Report accounts with a populated
scriptPathon a schedule and compare the list with the previous one. - Enable Audit User Account Management on all domain controllers, and add an auditing entry for writes on user objects so that event 5136 is written.
Frequently asked questions
When does the script run after the path was set?
At the next logon of the account to a domain computer. The attribute specifies the path of the user's logon script, and nothing happens until the user logs on. The time between the directory change and the first logon of the target is the window in which the change can be undone without any code having run.
Which event shows the new path?
Both. Event 4738 has a Script Path field with the new value, and a dash when the attribute was not part of the change. Event 5136 names the attribute scriptPath and carries the new value in AttributeValue, with the old value in a second event of the same operation. Event 5136 needs an auditing entry on the account. Event 4738 needs only the audit policy.
Does the rule see a change to the script itself?
Not the directory rules. When the path stays the same and the file it points to is replaced, the directory does not change and neither event 4738 nor 5136 is written. That variant is controlled by the permissions on the share that holds the scripts. The share rule on this page reports writes to the NETLOGON share through the network when Audit Detailed File Share is enabled on the domain controllers, but not a file changed locally on a domain controller or a script kept on another server.
How does this differ from a logon script in a Group Policy Object?
A Group Policy logon script is part of a policy and runs for every user the policy applies to. Changing it is a change to the Group Policy Object, which the page Group Policy Object Modification covers. The scriptPath attribute belongs to one account and is changed with write access to that account alone.
References
- MITRE ATT&CK T1037.003: Boot or Logon Initialization Scripts: Network Logon Script
- Script-Path attribute (scriptPath)
- Event 4738: A user account was changed
- Event 5136: A directory service object was modified
- Event 4624: An account was successfully logged on
- Event 5145: A network share object was checked to see whether client can be granted desired access
- Assign a logon script: logon scripts are stored in the Netlogon share
- Missing SYSVOL and NETLOGON shares: the scripts folder is the NETLOGON share