Modification of Environment Variable via Launchctl

Identifies modifications to an environment variable using the built-in launchctl command. Adversaries may execute their own malicious payloads by hijacking certain environment variables to load arbitrary libraries or bypass certain restrictions.

Elastic rule (View on GitHub)

 1[metadata]
 2creation_date = "2021/01/14"
 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 modifications to an environment variable using the built-in launchctl command. Adversaries may execute their
13own malicious payloads by hijacking certain environment variables to load arbitrary libraries or bypass certain
14restrictions.
15"""
16from = "now-9m"
17index = ["logs-endpoint.events.*"]
18language = "kuery"
19license = "Elastic License v2"
20name = "Modification of Environment Variable via Launchctl"
21references = [
22    "https://github.com/rapid7/metasploit-framework/blob/master//modules/post/osx/escalate/tccbypass.rb",
23]
24risk_score = 47
25rule_id = "7453e19e-3dbf-4e4e-9ae0-33d6c6ed15e1"
26setup = """
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
51"""
52severity = "medium"
53tags = ["Domain: Endpoint", "OS: macOS", "Use Case: Threat Detection", "Tactic: Defense Evasion", "Data Source: Elastic Defend"]
54timestamp_override = "event.ingested"
55type = "query"
56
57query = '''
58event.category:process and host.os.type:macos and event.type:start and 
59  process.name:launchctl and 
60  process.args:(setenv and not (ANT_HOME or 
61                                DBUS_LAUNCHD_SESSION_BUS_SOCKET or 
62                                EDEN_ENV or 
63                                LG_WEBOS_TV_SDK_HOME or 
64                                RUNTIME_JAVA_HOME or 
65                                WEBOS_CLI_TV or 
66                                JAVA*_HOME) and 
67                not *.vmoptions) and 
68  not process.parent.executable:("/Applications/IntelliJ IDEA CE.app/Contents/jbr/Contents/Home/lib/jspawnhelper" or 
69                                  /Applications/NoMachine.app/Contents/Frameworks/bin/nxserver.bin or 
70                                  /Applications/NoMachine.app/Contents/Frameworks/bin/nxserver.bin or 
71                                  /usr/local/bin/kr)
72'''
73
74
75[[rule.threat]]
76framework = "MITRE ATT&CK"
77[[rule.threat.technique]]
78id = "T1574"
79name = "Hijack Execution Flow"
80reference = "https://attack.mitre.org/techniques/T1574/"
81[[rule.threat.technique.subtechnique]]
82id = "T1574.007"
83name = "Path Interception by PATH Environment Variable"
84reference = "https://attack.mitre.org/techniques/T1574/007/"
85
86
87
88[rule.threat.tactic]
89id = "TA0005"
90name = "Defense Evasion"
91reference = "https://attack.mitre.org/tactics/TA0005/"

References

Related rules

to-top