Persistence via Login or Logout Hook

Identifies use of the Defaults command to install a login or logoff hook in MacOS. An adversary may abuse this capability to establish persistence in an environment by inserting code to be executed at login or logout.

Elastic rule (View on GitHub)

 1[metadata]
 2creation_date = "2020/12/07"
 3integration = ["endpoint"]
 4maturity = "production"
 5min_stack_comments = "New fields added: required_fields, related_integrations, setup"
 6min_stack_version = "8.3.0"
 7updated_date = "2023/11/15"
 8
 9[rule]
10author = ["Elastic"]
11description = """
12Identifies use of the Defaults command to install a login or logoff hook in MacOS. An adversary may abuse this
13capability to establish persistence in an environment by inserting code to be executed at login or logout.
14"""
15from = "now-9m"
16index = ["logs-endpoint.events.*"]
17language = "eql"
18license = "Elastic License v2"
19name = "Persistence via Login or Logout Hook"
20references = [
21    "https://www.virusbulletin.com/uploads/pdf/conference_slides/2014/Wardle-VB2014.pdf",
22    "https://www.manpagez.com/man/1/defaults/",
23]
24risk_score = 47
25rule_id = "5d0265bf-dea9-41a9-92ad-48a8dcd05080"
26setup = """## Setup
27
28This rule requires data coming in from Elastic Defend.
29
30### Elastic Defend Integration Setup
31Elastic 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.
32
33#### Prerequisite Requirements:
34- Fleet is required for Elastic Defend.
35- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
36
37#### The following steps should be executed in order to add the Elastic Defend integration on a macOS System:
38- Go to the Kibana home page and click "Add integrations".
39- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
40- Click "Add Elastic Defend".
41- Configure the integration name and optionally add a description.
42- Select the type of environment you want to protect, for MacOS it is recommended to select "Traditional Endpoints".
43- 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).
44- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
45- 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.
46For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/current/agent-policy.html).
47- Click "Save and Continue".
48- 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.
49For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
50"""
51severity = "medium"
52tags = ["Domain: Endpoint", "OS: macOS", "Use Case: Threat Detection", "Tactic: Persistence", "Data Source: Elastic Defend"]
53timestamp_override = "event.ingested"
54type = "eql"
55
56query = '''
57process where host.os.type == "macos" and event.type == "start" and
58 process.name == "defaults" and process.args == "write" and process.args : ("LoginHook", "LogoutHook") and
59 not process.args :
60       (
61         "Support/JAMF/ManagementFrameworkScripts/logouthook.sh",
62         "Support/JAMF/ManagementFrameworkScripts/loginhook.sh",
63         "/Library/Application Support/JAMF/ManagementFrameworkScripts/logouthook.sh",
64         "/Library/Application Support/JAMF/ManagementFrameworkScripts/loginhook.sh"
65       )
66'''
67
68
69[[rule.threat]]
70framework = "MITRE ATT&CK"
71[[rule.threat.technique]]
72id = "T1037"
73name = "Boot or Logon Initialization Scripts"
74reference = "https://attack.mitre.org/techniques/T1037/"
75
76
77[rule.threat.tactic]
78id = "TA0003"
79name = "Persistence"
80reference = "https://attack.mitre.org/tactics/TA0003/"

References

Related rules

to-top