Potential Persistence via Login Hook
Identifies the creation or modification of the login window property list (plist). Adversaries may modify plist files to run a program during system boot or user login for persistence.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2021/01/21"
3integration = ["endpoint"]
4maturity = "production"
5updated_date = "2026/10/26"
6
7[rule]
8author = ["Elastic"]
9description = """
10Identifies the creation or modification of the login window property list (plist). Adversaries may modify plist files to
11run a program during system boot or user login for persistence.
12"""
13from = "now-9m"
14index = ["logs-endpoint.events.*"]
15language = "kuery"
16license = "Elastic License v2"
17name = "Potential Persistence via Login Hook"
18note = """## Triage and analysis
19
20> **Disclaimer**:
21> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
22
23### Investigating Potential Persistence via Login Hook
24
25The `com.apple.loginwindow` preferences domain controls login window behavior. It supports the deprecated `LoginHook` and `LogoutHook` keys, which run a script as root each time a user logs in or out. Hooks are typically set with `sudo defaults write com.apple.loginwindow LoginHook <script>`, which stores them in root's preferences at `/var/root/Library/Preferences/com.apple.loginwindow.plist`. Adversaries can abuse these keys to execute a payload every time a user logs in. This rule alerts when a file named `com.apple.loginwindow.plist` is created or modified by a process other than common system, migration, backup, and management services.
26
27### Possible investigation steps
28
29- Identify the process that modified the plist (`process.executable`, `process.code_signature.*`) and determine whether it is a recognized, signed system or management tool. Review the process's execution event for its command line, for example a `defaults write` command.
30- Review the file path (`file.path`) to determine which copy was changed: root's preferences (`/var/root/Library/Preferences`), the system-wide preferences (`/Library/Preferences`), or a user's preferences (`~/Library/Preferences`).
31- Inspect the current contents of the modified plist on the host (for example with `sudo plutil -p <file.path>`) and look for `LoginHook` or `LogoutHook` entries referencing scripts or binaries in unusual locations.
32- If a hook is present, examine the referenced script or binary: its location, code signature, creation time, and content.
33- Review the process tree and recent activity of the modifying process for signs of initial access or execution, such as downloads, script interpreters, or `defaults write` commands.
34- Check whether the same process or user created other persistence mechanisms on the host, such as LaunchAgents, LaunchDaemons, or login items.
35
36### False positive analysis
37
38- Device management solutions, configuration profiles, migration and backup tools may legitimately update login window preferences. Verify the modifying process against the tools approved in the environment.
39- Administrators or users changing login window options through System Settings or `defaults` can modify the plist. Confirm the change with the user if the modifying process is a known Apple or vendor binary.
40- When the activity is confirmed benign, add an exception for the specific signed process executable instead of excluding the plist file.
41
42### Response and remediation
43
44- Isolate the affected host if a malicious login or logout hook is identified.
45- Remove the malicious hook (for example with `sudo defaults delete com.apple.loginwindow LoginHook`), and delete the referenced script or binary after preserving a copy for analysis.
46- Terminate any running processes started by the malicious hook.
47- If root's or the system-wide plist was modified, investigate how the attacker obtained root privileges, and remediate the initial access vector.
48- Reset the credentials of affected user accounts if compromise is confirmed.
49- Escalate to the incident response team and search for the same plist modification or payload on other macOS hosts.
50"""
51references = ["https://github.com/D00MFist/PersistentJXA/blob/master/LoginScript.js"]
52risk_score = 47
53rule_id = "ac412404-57a5-476f-858f-4e8fbb4f48d8"
54setup = """## Setup
55
56This rule requires data coming in from Elastic Defend.
57
58### Elastic Defend Integration Setup
59Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows the Elastic Agent to monitor events on your host and send data to the Elastic Security app.
60
61#### Prerequisite Requirements:
62- Fleet is required for Elastic Defend.
63- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
64
65#### The following steps should be executed in order to add the Elastic Defend integration on a macOS System:
66- Go to the Kibana home page and click "Add integrations".
67- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
68- Click "Add Elastic Defend".
69- Configure the integration name and optionally add a description.
70- Select the type of environment you want to protect, for MacOS it is recommended to select "Traditional Endpoints".
71- Select a configuration preset. Each preset comes with different default settings for Elastic Agent, you can further customize these later by configuring the Elastic Defend integration policy. [Helper guide](https://www.elastic.co/guide/en/security/current/configure-endpoint-integration-policy.html).
72- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
73- Enter a name for the agent policy in "New agent policy name". If other agent policies already exist, you can click the "Existing hosts" tab and select an existing policy instead.
74For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/current/agent-policy.html).
75- Click "Save and Continue".
76- To complete the integration, select "Add Elastic Agent to your hosts" and continue to the next section to install the Elastic Agent on your hosts.
77For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
78"""
79severity = "medium"
80tags = [
81 "Domain: Endpoint",
82 "OS: macOS",
83 "Use Case: Threat Detection",
84 "Tactic: Persistence",
85 "Data Source: Elastic Defend",
86 "Resources: Investigation Guide",
87 "Noise: High",
88 "Performance: Normal",
89 "Profile: Aggressive",
90 "Rule Type: Custom Query (KQL)",
91 "Platform: macOS",
92]
93timestamp_override = "event.ingested"
94type = "query"
95
96query = '''
97event.category:file and host.os.type:macos and not event.type:"deletion" and
98 file.name:"com.apple.loginwindow.plist" and
99 not process.name: (systemmigrationd or DesktopServicesHelper or diskmanagementd or rsync or launchd or cfprefsd or xpcproxy or ManagedClient or MCXCompositor or backupd or "iMazing Profile Editor" or storagekitd or CloneKitService)
100'''
101
102
103[[rule.threat]]
104framework = "MITRE ATT&CK"
105
106[[rule.threat.technique]]
107id = "T1037"
108name = "Boot or Logon Initialization Scripts"
109reference = "https://attack.mitre.org/techniques/T1037/"
110
111[[rule.threat.technique.subtechnique]]
112id = "T1037.002"
113name = "Login Hook"
114reference = "https://attack.mitre.org/techniques/T1037/002/"
115
116[[rule.threat.technique]]
117id = "T1547"
118name = "Boot or Logon Autostart Execution"
119reference = "https://attack.mitre.org/techniques/T1547/"
120
121[rule.threat.tactic]
122id = "TA0003"
123name = "Persistence"
124reference = "https://attack.mitre.org/tactics/TA0003/"
125
126[[rule.threat]]
127framework = "MITRE ATT&CK"
128
129[[rule.threat.technique]]
130id = "T1647"
131name = "Plist File Modification"
132reference = "https://attack.mitre.org/techniques/T1647/"
133
134[rule.threat.tactic]
135id = "TA0005"
136name = "Defense Evasion"
137reference = "https://attack.mitre.org/tactics/TA0005/"
Triage and analysis
Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
Investigating Potential Persistence via Login Hook
The com.apple.loginwindow preferences domain controls login window behavior. It supports the deprecated LoginHook and LogoutHook keys, which run a script as root each time a user logs in or out. Hooks are typically set with sudo defaults write com.apple.loginwindow LoginHook <script>, which stores them in root's preferences at /var/root/Library/Preferences/com.apple.loginwindow.plist. Adversaries can abuse these keys to execute a payload every time a user logs in. This rule alerts when a file named com.apple.loginwindow.plist is created or modified by a process other than common system, migration, backup, and management services.
Possible investigation steps
- Identify the process that modified the plist (
process.executable,process.code_signature.*) and determine whether it is a recognized, signed system or management tool. Review the process's execution event for its command line, for example adefaults writecommand. - Review the file path (
file.path) to determine which copy was changed: root's preferences (/var/root/Library/Preferences), the system-wide preferences (/Library/Preferences), or a user's preferences (~/Library/Preferences). - Inspect the current contents of the modified plist on the host (for example with
sudo plutil -p <file.path>) and look forLoginHookorLogoutHookentries referencing scripts or binaries in unusual locations. - If a hook is present, examine the referenced script or binary: its location, code signature, creation time, and content.
- Review the process tree and recent activity of the modifying process for signs of initial access or execution, such as downloads, script interpreters, or
defaults writecommands. - Check whether the same process or user created other persistence mechanisms on the host, such as LaunchAgents, LaunchDaemons, or login items.
False positive analysis
- Device management solutions, configuration profiles, migration and backup tools may legitimately update login window preferences. Verify the modifying process against the tools approved in the environment.
- Administrators or users changing login window options through System Settings or
defaultscan modify the plist. Confirm the change with the user if the modifying process is a known Apple or vendor binary. - When the activity is confirmed benign, add an exception for the specific signed process executable instead of excluding the plist file.
Response and remediation
- Isolate the affected host if a malicious login or logout hook is identified.
- Remove the malicious hook (for example with
sudo defaults delete com.apple.loginwindow LoginHook), and delete the referenced script or binary after preserving a copy for analysis. - Terminate any running processes started by the malicious hook.
- If root's or the system-wide plist was modified, investigate how the attacker obtained root privileges, and remediate the initial access vector.
- Reset the credentials of affected user accounts if compromise is confirmed.
- Escalate to the incident response team and search for the same plist modification or payload on other macOS hosts.
References
Related rules
- Bash Shell Profile Modification
- AWS SSM Session Manager Child Process Execution
- Launch Service Creation and Immediate Loading
- Suspicious pbpaste High Volume Activity
- Connection to Common Large Language Model Endpoints