Unusual LD_PRELOAD/LD_LIBRARY_PATH Command Line Arguments
This rule detects the use of the LD_PRELOAD and LD_LIBRARY_PATH environment variables in a command line argument. This behavior is unusual and may indicate an attempt to hijack the execution flow of a process. Threat actors may use this technique to evade defenses, escalate privileges, or maintain persistence on a system.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2025/04/30"
3integration = ["endpoint", "crowdstrike"]
4maturity = "production"
5updated_date = "2025/10/17"
6
7[rule]
8author = ["Elastic"]
9description = """
10This rule detects the use of the LD_PRELOAD and LD_LIBRARY_PATH environment variables in a command line argument.
11This behavior is unusual and may indicate an attempt to hijack the execution flow of a process. Threat actors may use
12this technique to evade defenses, escalate privileges, or maintain persistence on a system.
13"""
14from = "now-9m"
15index = ["logs-endpoint.events.process*", "logs-crowdstrike.fdr*"]
16language = "kuery"
17license = "Elastic License v2"
18name = "Unusual LD_PRELOAD/LD_LIBRARY_PATH Command Line Arguments"
19note = """ ## Triage and analysis
20
21> **Disclaimer**:
22> 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.
23
24### Investigating Unusual LD_PRELOAD/LD_LIBRARY_PATH Command Line Arguments
25
26LD_PRELOAD and LD_LIBRARY_PATH are environment variables in Linux that influence dynamic linking by specifying libraries to load before others. Adversaries exploit these to hijack execution flow, evade defenses, or escalate privileges. The detection rule identifies suspicious use of these variables in shell commands, excluding benign processes, signaling potential misuse for persistence or defense evasion.
27
28### Possible investigation steps
29
30- Review the process command line to identify the specific libraries being loaded via LD_PRELOAD or LD_LIBRARY_PATH and assess their legitimacy.
31- Examine the parent process name to determine if the process is expected to use these environment variables, considering the exclusion list provided in the query.
32- Investigate the user account associated with the process to check for any signs of compromise or unusual activity.
33- Analyze the process execution context, including the timestamp and host details, to identify any patterns or correlations with other suspicious activities.
34- Check system logs and other security tools for related alerts or events that might indicate broader malicious activity or attempts to evade defenses.
35
36### False positive analysis
37
38- Development and testing environments often use LD_PRELOAD and LD_LIBRARY_PATH for legitimate purposes such as testing new libraries or debugging. Consider excluding processes associated with these environments if they are known and trusted.
39- Some software installations or updates may temporarily use these environment variables to ensure compatibility or to load specific libraries. Monitor installation logs and exclude these processes if they are verified as part of legitimate software management.
40- System administration scripts or automation tools might use these variables to manage library paths dynamically. Review and whitelist these scripts if they are part of routine maintenance and have been vetted for security.
41- Certain applications, like custom-built software or legacy systems, may rely on these variables for normal operation. Document these applications and exclude them from the rule if they are essential and secure.
42- Security tools or monitoring agents might use these variables to hook into processes for legitimate monitoring purposes. Verify the behavior of these tools and exclude them if they are part of your security infrastructure.
43
44### Response and remediation
45
46- Immediately isolate the affected system from the network to prevent further malicious activity or lateral movement.
47- Terminate any suspicious processes identified with unusual LD_PRELOAD or LD_LIBRARY_PATH usage to halt potential exploitation.
48- Conduct a thorough review of the affected system's environment variables and remove any unauthorized or suspicious entries.
49- Restore the system from a known good backup if malicious activity is confirmed and system integrity is compromised.
50- Escalate the incident to the security operations team for further investigation and to determine if additional systems are affected.
51- Implement stricter access controls and monitoring on the affected system to prevent unauthorized changes to environment variables.
52- Update and enhance detection rules to include additional indicators of compromise related to LD_PRELOAD and LD_LIBRARY_PATH misuse, ensuring future attempts are identified promptly.
53"""
54risk_score = 21
55rule_id = "65613f5e-0d48-4b55-ad61-2fb9567cb1ad"
56setup = """## Setup
57
58This rule requires data coming in from Elastic Defend.
59
60### Elastic Defend Integration Setup
61Elastic 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.
62
63#### Prerequisite Requirements:
64- Fleet is required for Elastic Defend.
65- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
66
67#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
68- Go to the Kibana home page and click "Add integrations".
69- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
70- Click "Add Elastic Defend".
71- Configure the integration name and optionally add a description.
72- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
73- 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).
74- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
75- 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.
76For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
77- Click "Save and Continue".
78- 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.
79For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
80"""
81severity = "low"
82tags = [
83 "Domain: Endpoint",
84 "OS: Linux",
85 "Use Case: Threat Detection",
86 "Tactic: Defense Evasion",
87 "Tactic: Persistence",
88 "Data Source: Elastic Defend",
89 "Resources: Investigation Guide",
90 "Data Source: Crowdstrike",
91]
92timestamp_override = "event.ingested"
93type = "new_terms"
94query = '''
95host.os.type:linux and event.category:process and event.type:start and event.action:(exec or ProcessRollup2) and
96process.parent.name:(* and not (
97 awk or bwrap or cylancesvc or dbus-run-session or java or julia or make or matlab_helper or ninja or noproc_sandbox or
98 nxrunner or nxserver or perl or rear or sapcontrol or setsid or spoold or sshd or steam or su or sudo or titanagent or
99 vls_agent or zabbix_agentd
100)) and
101process.name:(bash or csh or dash or fish or ksh or sh or tcsh or zsh) and
102process.args:-c and process.command_line:(*LD_LIBRARY_PATH=* or *LD_PRELOAD=*)
103'''
104[[rule.threat]]
105framework = "MITRE ATT&CK"
106
107 [rule.threat.tactic]
108 name = "Defense Evasion"
109 id = "TA0005"
110 reference = "https://attack.mitre.org/tactics/TA0005/"
111
112 [[rule.threat.technique]]
113 name = "Hijack Execution Flow"
114 id = "T1574"
115 reference = "https://attack.mitre.org/techniques/T1574/"
116
117 [[rule.threat.technique.subtechnique]]
118 name = "Dynamic Linker Hijacking"
119 id = "T1574.006"
120 reference = "https://attack.mitre.org/techniques/T1574/006/"
121
122[[rule.threat]]
123framework = "MITRE ATT&CK"
124
125 [rule.threat.tactic]
126 name = "Persistence"
127 id = "TA0003"
128 reference = "https://attack.mitre.org/tactics/TA0003/"
129
130 [[rule.threat.technique]]
131 name = "Hijack Execution Flow"
132 id = "T1574"
133 reference = "https://attack.mitre.org/techniques/T1574/"
134
135 [[rule.threat.technique.subtechnique]]
136 name = "Dynamic Linker Hijacking"
137 id = "T1574.006"
138 reference = "https://attack.mitre.org/techniques/T1574/006/"
139
140[[rule.threat]]
141framework = "MITRE ATT&CK"
142
143 [rule.threat.tactic]
144 name = "Privilege Escalation"
145 id = "TA0004"
146 reference = "https://attack.mitre.org/tactics/TA0004/"
147
148 [[rule.threat.technique]]
149 name = "Hijack Execution Flow"
150 id = "T1574"
151 reference = "https://attack.mitre.org/techniques/T1574/"
152
153 [[rule.threat.technique.subtechnique]]
154 name = "Dynamic Linker Hijacking"
155 id = "T1574.006"
156 reference = "https://attack.mitre.org/techniques/T1574/006/"
157
158[rule.new_terms]
159field = "new_terms_fields"
160value = ["process.parent.name", "process.command_line", "host.id"]
161
162[[rule.new_terms.history_window_start]]
163field = "history_window_start"
164value = "now-7d"
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 Unusual LD_PRELOAD/LD_LIBRARY_PATH Command Line Arguments
LD_PRELOAD and LD_LIBRARY_PATH are environment variables in Linux that influence dynamic linking by specifying libraries to load before others. Adversaries exploit these to hijack execution flow, evade defenses, or escalate privileges. The detection rule identifies suspicious use of these variables in shell commands, excluding benign processes, signaling potential misuse for persistence or defense evasion.
Possible investigation steps
- Review the process command line to identify the specific libraries being loaded via LD_PRELOAD or LD_LIBRARY_PATH and assess their legitimacy.
- Examine the parent process name to determine if the process is expected to use these environment variables, considering the exclusion list provided in the query.
- Investigate the user account associated with the process to check for any signs of compromise or unusual activity.
- Analyze the process execution context, including the timestamp and host details, to identify any patterns or correlations with other suspicious activities.
- Check system logs and other security tools for related alerts or events that might indicate broader malicious activity or attempts to evade defenses.
False positive analysis
- Development and testing environments often use LD_PRELOAD and LD_LIBRARY_PATH for legitimate purposes such as testing new libraries or debugging. Consider excluding processes associated with these environments if they are known and trusted.
- Some software installations or updates may temporarily use these environment variables to ensure compatibility or to load specific libraries. Monitor installation logs and exclude these processes if they are verified as part of legitimate software management.
- System administration scripts or automation tools might use these variables to manage library paths dynamically. Review and whitelist these scripts if they are part of routine maintenance and have been vetted for security.
- Certain applications, like custom-built software or legacy systems, may rely on these variables for normal operation. Document these applications and exclude them from the rule if they are essential and secure.
- Security tools or monitoring agents might use these variables to hook into processes for legitimate monitoring purposes. Verify the behavior of these tools and exclude them if they are part of your security infrastructure.
Response and remediation
- Immediately isolate the affected system from the network to prevent further malicious activity or lateral movement.
- Terminate any suspicious processes identified with unusual LD_PRELOAD or LD_LIBRARY_PATH usage to halt potential exploitation.
- Conduct a thorough review of the affected system's environment variables and remove any unauthorized or suspicious entries.
- Restore the system from a known good backup if malicious activity is confirmed and system integrity is compromised.
- Escalate the incident to the security operations team for further investigation and to determine if additional systems are affected.
- Implement stricter access controls and monitoring on the affected system to prevent unauthorized changes to environment variables.
- Update and enhance detection rules to include additional indicators of compromise related to LD_PRELOAD and LD_LIBRARY_PATH misuse, ensuring future attempts are identified promptly.
Related rules
- Git Hook Command Execution
- Node.js Pre or Post-Install Script Execution
- Suspicious APT Package Manager Execution
- Directory Creation in /bin directory
- Git Hook Child Process