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"]
  4maturity = "production"
  5updated_date = "2025/07/07"
  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*"]
 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]
 91timestamp_override = "event.ingested"
 92type = "new_terms"
 93query = '''
 94host.os.type:linux and event.category:process and event.type:start and event.action:exec and
 95process.parent.name:(* and not (
 96  awk or bwrap or cylancesvc or dbus-run-session or java or julia or make or matlab_helper or ninja or noproc_sandbox or
 97  nxrunner or nxserver or perl or rear or sapcontrol or setsid or spoold or sshd or steam or su or sudo or titanagent or
 98  vls_agent or zabbix_agentd
 99)) and
100process.name:(bash or csh or dash or fish or ksh or sh or tcsh or zsh) and
101process.args:-c and process.command_line:(*LD_LIBRARY_PATH=* or *LD_PRELOAD=*)
102'''
103[[rule.threat]]
104framework = "MITRE ATT&CK"
105
106  [rule.threat.tactic]
107  name = "Defense Evasion"
108  id = "TA0005"
109  reference = "https://attack.mitre.org/tactics/TA0005/"
110
111  [[rule.threat.technique]]
112  name = "Hijack Execution Flow"
113  id = "T1574"
114  reference = "https://attack.mitre.org/techniques/T1574/"
115
116  [[rule.threat.technique.subtechnique]]
117  name = "Dynamic Linker Hijacking"
118  id = "T1574.006"
119  reference = "https://attack.mitre.org/techniques/T1574/006/"
120
121[[rule.threat]]
122framework = "MITRE ATT&CK"
123
124  [rule.threat.tactic]
125  name = "Persistence"
126  id = "TA0003"
127  reference = "https://attack.mitre.org/tactics/TA0003/"
128
129  [[rule.threat.technique]]
130  name = "Hijack Execution Flow"
131  id = "T1574"
132  reference = "https://attack.mitre.org/techniques/T1574/"
133
134  [[rule.threat.technique.subtechnique]]
135  name = "Dynamic Linker Hijacking"
136  id = "T1574.006"
137  reference = "https://attack.mitre.org/techniques/T1574/006/"
138
139[[rule.threat]]
140framework = "MITRE ATT&CK"
141
142  [rule.threat.tactic]
143  name = "Privilege Escalation"
144  id = "TA0004"
145  reference = "https://attack.mitre.org/tactics/TA0004/"
146
147  [[rule.threat.technique]]
148  name = "Hijack Execution Flow"
149  id = "T1574"
150  reference = "https://attack.mitre.org/techniques/T1574/"
151
152  [[rule.threat.technique.subtechnique]]
153  name = "Dynamic Linker Hijacking"
154  id = "T1574.006"
155  reference = "https://attack.mitre.org/techniques/T1574/006/"
156
157[rule.new_terms]
158field = "new_terms_fields"
159value = ["process.parent.name", "process.command_line", "host.id"]
160
161[[rule.new_terms.history_window_start]]
162field = "history_window_start"
163value = "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

to-top