Dynamic Linker Copy

Detects the copying of the Linux dynamic loader binary and subsequent file creation for the purpose of creating a backup copy. This technique was seen recently being utilized by Linux malware prior to patching the dynamic loader in order to inject and preload a malicious shared object file. This activity should never occur and if it does then it should be considered highly suspicious or malicious.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2022/07/12"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2024/05/21"
  6
  7[transform]
  8[[transform.osquery]]
  9label = "Osquery - Retrieve File Listing Information"
 10query = """
 11SELECT * FROM file WHERE ( path = '/etc/ld.so.preload' OR path = '/lib64/ld-linux-x86-64.so.2' OR path =
 12'/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2' OR path = '/usr/lib64/ld-linux-x86-64.so.2' OR path =
 13'/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2' )
 14"""
 15
 16[[transform.osquery]]
 17label = "Osquery - Retrieve Additional File Listing Information"
 18query = """
 19SELECT f.path, u.username AS file_owner, g.groupname AS group_owner, datetime(f.atime, 'unixepoch') AS
 20file_last_access_time, datetime(f.mtime, 'unixepoch') AS file_last_modified_time, datetime(f.ctime, 'unixepoch') AS
 21file_last_status_change_time, datetime(f.btime, 'unixepoch') AS file_created_time, f.size AS size_bytes FROM file f LEFT
 22JOIN users u ON f.uid = u.uid LEFT JOIN groups g ON f.gid = g.gid WHERE ( path = '/etc/ld.so.preload' OR path =
 23'/lib64/ld-linux-x86-64.so.2' OR path = '/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2' OR path =
 24'/usr/lib64/ld-linux-x86-64.so.2' OR path = '/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2' )
 25"""
 26
 27[[transform.osquery]]
 28label = "Osquery - Retrieve Running Processes by User"
 29query = "SELECT pid, username, name FROM processes p JOIN users u ON u.uid = p.uid ORDER BY username"
 30
 31[[transform.osquery]]
 32label = "Osquery - Retrieve Listening Ports"
 33query = "SELECT pid, address, port, socket, protocol, path FROM listening_ports"
 34
 35[[transform.osquery]]
 36label = "Osquery - Retrieve Open Sockets"
 37query = "SELECT pid, family, remote_address, remote_port, socket, state FROM process_open_sockets"
 38
 39[[transform.osquery]]
 40label = "Osquery - Retrieve Information for a Specific User"
 41query = "SELECT * FROM users WHERE username = {{user.name}}"
 42
 43[[transform.osquery]]
 44label = "Osquery - Investigate the Account Authentication Status"
 45query = "SELECT * FROM logged_in_users WHERE user = {{user.name}}"
 46
 47
 48[rule]
 49author = ["Elastic"]
 50description = """
 51Detects the copying of the Linux dynamic loader binary and subsequent file creation for the purpose of creating a backup
 52copy. This technique was seen recently being utilized by Linux malware prior to patching the dynamic loader in order to
 53inject and preload a malicious shared object file. This activity should never occur and if it does then it should be
 54considered highly suspicious or malicious.
 55"""
 56from = "now-9m"
 57index = ["logs-endpoint.events.*"]
 58language = "eql"
 59license = "Elastic License v2"
 60name = "Dynamic Linker Copy"
 61note = """## Triage and analysis
 62
 63### Investigating Dynamic Linker Copy
 64
 65The Linux dynamic linker is responsible for loading shared libraries required by executables at runtime. It is a critical component of the Linux operating system and should not be tampered with. 
 66
 67Adversaries may attempt to copy the dynamic linker binary and create a backup copy before patching it to inject and preload malicious shared object files. This technique has been observed in recent Linux malware attacks and is considered highly suspicious or malicious.
 68
 69The detection rule 'Dynamic Linker Copy' is designed to identify such abuse by monitoring for processes with names "cp" or "rsync" that involve copying the dynamic linker binary ("/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2") and modifying the "/etc/ld.so.preload" file. Additionally, the rule checks for the creation of new files with the "so" extension on Linux systems. By detecting these activities within a short time span (1 minute), the rule aims to alert security analysts to potential malicious behavior.
 70
 71> **Note**:
 72> This investigation guide uses the [Osquery Markdown Plugin](https://www.elastic.co/guide/en/security/master/invest-guide-run-osquery.html) introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide.
 73> This investigation guide uses [placeholder fields](https://www.elastic.co/guide/en/security/current/osquery-placeholder-fields.html) to dynamically pass alert data into Osquery queries. Placeholder fields were introduced in Elastic Stack version 8.7.0. If you're using Elastic Stack version 8.6.0 or earlier, you'll need to manually adjust this investigation guide's queries to ensure they properly run.
 74
 75### Possible investigation steps
 76
 77- Investigate the dynamic linker that was copied or altered.
 78  - $osquery_0
 79  - $osquery_1
 80- Investigate the script execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence and whether they are located in expected locations.
 81  - $osquery_2
 82- Investigate other alerts associated with the user/host during the past 48 hours.
 83- Validate the activity is not related to planned patches, updates, network administrator activity, or legitimate software installations.
 84- Investigate whether the altered scripts call other malicious scripts elsewhere on the file system. 
 85  - If scripts or executables were dropped, retrieve the files and determine if they are malicious:
 86    - Use a private sandboxed malware analysis system to perform analysis.
 87      - Observe and collect information about the following activities:
 88        - Attempts to contact external domains and addresses.
 89          - Check if the domain is newly registered or unexpected.
 90          - Check the reputation of the domain or IP address.
 91        - File access, modification, and creation activities.
 92- Investigate abnormal behaviors by the subject process/user such as network connections, file modifications, and any other spawned child processes.
 93  - Investigate listening ports and open sockets to look for potential command and control traffic or data exfiltration.
 94    - $osquery_3
 95    - $osquery_4
 96  - Identify the user account that performed the action, analyze it, and check whether it should perform this kind of action.
 97    - $osquery_5
 98- Investigate whether the user is currently logged in and active.
 99    - $osquery_6
100
101### False positive analysis
102
103- This activity is unlikely to happen legitimately. Benign true positives (B-TPs) can be added as exceptions if necessary.
104- Any activity that triggered the alert and is not inherently malicious must be monitored by the security team.
105- The security team should address any potential benign true positive (B-TP), as this configuration can put the user and the domain at risk.
106- Try to understand the context of the execution by thinking about the user, machine, or business purpose. A small number of endpoints, such as servers with unique software, might appear unusual but satisfy a specific business need.
107
108### Related Rules
109
110- Modification of Dynamic Linker Preload Shared Object Inside A Container - 342f834b-21a6-41bf-878c-87d116eba3ee
111- Modification of Dynamic Linker Preload Shared Object - 717f82c2-7741-4f9b-85b8-d06aeb853f4f
112- Shared Object Created or Changed by Previously Unknown Process - aebaa51f-2a91-4f6a-850b-b601db2293f4
113
114### Response and Remediation
115
116- Initiate the incident response process based on the outcome of the triage.
117- Isolate the involved host to prevent further post-compromise behavior.
118- If the triage identified malware, search the environment for additional compromised hosts.
119  - Implement temporary network rules, procedures, and segmentation to contain the malware.
120  - Stop suspicious processes.
121  - Immediately block the identified indicators of compromise (IoCs).
122  - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
123- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
124- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
125- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
126- Leverage the incident response data and logging to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
127"""
128references = ["https://www.intezer.com/blog/incident-response/orbit-new-undetected-linux-threat/"]
129risk_score = 73
130rule_id = "df6f62d9-caab-4b88-affa-044f4395a1e0"
131setup = """## Setup
132
133This rule requires data coming in from Elastic Defend.
134
135### Elastic Defend Integration Setup
136Elastic 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.
137
138#### Prerequisite Requirements:
139- Fleet is required for Elastic Defend.
140- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
141
142#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
143- Go to the Kibana home page and click "Add integrations".
144- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
145- Click "Add Elastic Defend".
146- Configure the integration name and optionally add a description.
147- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
148- 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).
149- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
150- 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.
151For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
152- Click "Save and Continue".
153- 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.
154For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
155"""
156severity = "high"
157tags = [
158    "Domain: Endpoint",
159    "OS: Linux",
160    "Use Case: Threat Detection",
161    "Tactic: Persistence",
162    "Threat: Orbit",
163    "Data Source: Elastic Defend",
164]
165type = "eql"
166
167query = '''
168sequence by process.entity_id with maxspan=1m
169[process where host.os.type == "linux" and event.type == "start" and process.name in ("cp", "rsync") and
170   process.args in (
171     "/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2", "/etc/ld.so.preload", "/lib64/ld-linux-x86-64.so.2",
172     "/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2", "/usr/lib64/ld-linux-x86-64.so.2"
173    )]
174[file where host.os.type == "linux" and event.action == "creation" and file.extension == "so"]
175'''
176
177
178[[rule.threat]]
179framework = "MITRE ATT&CK"
180[[rule.threat.technique]]
181id = "T1574"
182name = "Hijack Execution Flow"
183reference = "https://attack.mitre.org/techniques/T1574/"
184[[rule.threat.technique.subtechnique]]
185id = "T1574.006"
186name = "Dynamic Linker Hijacking"
187reference = "https://attack.mitre.org/techniques/T1574/006/"
188
189
190
191[rule.threat.tactic]
192id = "TA0003"
193name = "Persistence"
194reference = "https://attack.mitre.org/tactics/TA0003/"

Triage and analysis

Investigating Dynamic Linker Copy

The Linux dynamic linker is responsible for loading shared libraries required by executables at runtime. It is a critical component of the Linux operating system and should not be tampered with.

Adversaries may attempt to copy the dynamic linker binary and create a backup copy before patching it to inject and preload malicious shared object files. This technique has been observed in recent Linux malware attacks and is considered highly suspicious or malicious.

The detection rule 'Dynamic Linker Copy' is designed to identify such abuse by monitoring for processes with names "cp" or "rsync" that involve copying the dynamic linker binary ("/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2") and modifying the "/etc/ld.so.preload" file. Additionally, the rule checks for the creation of new files with the "so" extension on Linux systems. By detecting these activities within a short time span (1 minute), the rule aims to alert security analysts to potential malicious behavior.

Note: This investigation guide uses the Osquery Markdown Plugin introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide. This investigation guide uses placeholder fields to dynamically pass alert data into Osquery queries. Placeholder fields were introduced in Elastic Stack version 8.7.0. If you're using Elastic Stack version 8.6.0 or earlier, you'll need to manually adjust this investigation guide's queries to ensure they properly run.

Possible investigation steps

  • Investigate the dynamic linker that was copied or altered.
    • $osquery_0
    • $osquery_1
  • Investigate the script execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence and whether they are located in expected locations.
    • $osquery_2
  • Investigate other alerts associated with the user/host during the past 48 hours.
  • Validate the activity is not related to planned patches, updates, network administrator activity, or legitimate software installations.
  • Investigate whether the altered scripts call other malicious scripts elsewhere on the file system.
    • If scripts or executables were dropped, retrieve the files and determine if they are malicious:
      • Use a private sandboxed malware analysis system to perform analysis.
        • Observe and collect information about the following activities:
          • Attempts to contact external domains and addresses.
            • Check if the domain is newly registered or unexpected.
            • Check the reputation of the domain or IP address.
          • File access, modification, and creation activities.
  • Investigate abnormal behaviors by the subject process/user such as network connections, file modifications, and any other spawned child processes.
    • Investigate listening ports and open sockets to look for potential command and control traffic or data exfiltration.
      • $osquery_3
      • $osquery_4
    • Identify the user account that performed the action, analyze it, and check whether it should perform this kind of action.
      • $osquery_5
  • Investigate whether the user is currently logged in and active.
    • $osquery_6

False positive analysis

  • This activity is unlikely to happen legitimately. Benign true positives (B-TPs) can be added as exceptions if necessary.
  • Any activity that triggered the alert and is not inherently malicious must be monitored by the security team.
  • The security team should address any potential benign true positive (B-TP), as this configuration can put the user and the domain at risk.
  • Try to understand the context of the execution by thinking about the user, machine, or business purpose. A small number of endpoints, such as servers with unique software, might appear unusual but satisfy a specific business need.
  • Modification of Dynamic Linker Preload Shared Object Inside A Container - 342f834b-21a6-41bf-878c-87d116eba3ee
  • Modification of Dynamic Linker Preload Shared Object - 717f82c2-7741-4f9b-85b8-d06aeb853f4f
  • Shared Object Created or Changed by Previously Unknown Process - aebaa51f-2a91-4f6a-850b-b601db2293f4

Response and Remediation

  • Initiate the incident response process based on the outcome of the triage.
  • Isolate the involved host to prevent further post-compromise behavior.
  • If the triage identified malware, search the environment for additional compromised hosts.
    • Implement temporary network rules, procedures, and segmentation to contain the malware.
    • Stop suspicious processes.
    • Immediately block the identified indicators of compromise (IoCs).
    • Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
  • Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
  • Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
  • Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
  • Leverage the incident response data and logging to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).

References

Related rules

to-top