Modification of OpenSSH Binaries

Adversaries may modify SSH related binaries for persistence or credential access by patching sensitive functions to enable unauthorized access or by logging SSH credentials for exfiltration.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2020/12/21"
  3integration = ["endpoint"]
  4maturity = "production"
  5min_stack_comments = "New fields added: required_fields, related_integrations, setup"
  6min_stack_version = "8.3.0"
  7updated_date = "2024/02/21"
  8
  9[transform]
 10[[transform.osquery]]
 11label = "Osquery - Retrieve Running Processes by User"
 12query = "SELECT pid, username, name FROM processes p JOIN users u ON u.uid = p.uid ORDER BY username"
 13
 14[[transform.osquery]]
 15label = "Osquery - Retrieve Crontab Information"
 16query = "SELECT * FROM crontab"
 17
 18[[transform.osquery]]
 19label = "Osquery - Retrieve Listening Ports"
 20query = "SELECT pid, address, port, socket, protocol, path FROM listening_ports"
 21
 22[[transform.osquery]]
 23label = "Osquery - Retrieve Open Sockets"
 24query = "SELECT pid, family, remote_address, remote_port, socket, state FROM process_open_sockets"
 25
 26[[transform.osquery]]
 27label = "Osquery - Retrieve Information for a Specific User"
 28query = "SELECT * FROM users WHERE username = {{user.name}}"
 29
 30[[transform.osquery]]
 31label = "Osquery - Investigate the Account Authentication Status"
 32query = "SELECT * FROM logged_in_users WHERE user = {{user.name}}"
 33
 34[rule]
 35author = ["Elastic"]
 36description = """
 37Adversaries may modify SSH related binaries for persistence or credential access by patching sensitive functions to
 38enable unauthorized access or by logging SSH credentials for exfiltration.
 39"""
 40false_positives = [
 41    "Trusted OpenSSH executable updates. It's recommended to verify the integrity of OpenSSH binary changes.",
 42]
 43from = "now-9m"
 44index = ["logs-endpoint.events.*", "endgame-*"]
 45language = "kuery"
 46license = "Elastic License v2"
 47name = "Modification of OpenSSH Binaries"
 48note = """## Triage and analysis
 49
 50### Investigating Modification of OpenSSH Binaries
 51
 52OpenSSH is a widely used suite of secure networking utilities based on the Secure Shell (SSH) protocol, which provides encrypted communication sessions over a computer network.
 53
 54Adversaries may exploit OpenSSH by modifying its binaries, such as `/usr/bin/scp`, `/usr/bin/sftp`, `/usr/bin/ssh`, `/usr/sbin/sshd`, or `libkeyutils.so`, to gain unauthorized access or exfiltrate SSH credentials.
 55
 56The detection rule 'Modification of OpenSSH Binaries' is designed to identify such abuse by monitoring file changes in the Linux environment. It triggers an alert when a process, modifies any of the specified OpenSSH binaries or libraries. This helps security analysts detect potential malicious activities and take appropriate action.
 57
 58> **Note**:
 59> 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.
 60> 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.
 61
 62### Possible investigation steps
 63
 64- 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.
 65  - $osquery_0
 66- Investigate other alerts associated with the user/host during the past 48 hours.
 67- Validate the activity is not related to planned patches, updates, network administrator activity, or legitimate software installations.
 68- Investigate whether the altered scripts call other malicious scripts elsewhere on the file system. 
 69  - If scripts or executables were dropped, retrieve the files and determine if they are malicious:
 70    - Use a private sandboxed malware analysis system to perform analysis.
 71      - Observe and collect information about the following activities:
 72        - Attempts to contact external domains and addresses.
 73          - Check if the domain is newly registered or unexpected.
 74          - Check the reputation of the domain or IP address.
 75        - File access, modification, and creation activities.
 76        - Cron jobs, services and other persistence mechanisms.
 77            - $osquery_1
 78- Investigate abnormal behaviors by the subject process/user such as network connections, file modifications, and any other spawned child processes.
 79  - Investigate listening ports and open sockets to look for potential command and control traffic or data exfiltration.
 80    - $osquery_2
 81    - $osquery_3
 82  - Identify the user account that performed the action, analyze it, and check whether it should perform this kind of action.
 83    - $osquery_4
 84- Investigate whether the user is currently logged in and active.
 85    - $osquery_5
 86
 87### False positive analysis
 88
 89- Regular users should not need to modify OpenSSH binaries, which makes false positives unlikely. In the case of authorized benign true positives (B-TPs), exceptions can be added.
 90- If this activity is related to new benign software installation activity, consider adding exceptions — preferably with a combination of user and command line conditions.
 91- If this activity is related to a system administrator that performed these actions for administrative purposes, consider adding exceptions for this specific administrator user account. 
 92- 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.
 93
 94### Response and Remediation
 95
 96- Initiate the incident response process based on the outcome of the triage.
 97- Isolate the involved host to prevent further post-compromise behavior.
 98- If the triage identified malware, search the environment for additional compromised hosts.
 99  - Implement temporary network rules, procedures, and segmentation to contain the malware.
100  - Stop suspicious processes.
101  - Immediately block the identified indicators of compromise (IoCs).
102  - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
103- 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.
104- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
105- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
106- Leverage the incident response data and logging to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
107"""
108references = ["https://blog.angelalonso.es/2016/09/anatomy-of-real-linux-intrusion-part-ii.html"]
109risk_score = 47
110rule_id = "0415f22a-2336-45fa-ba07-618a5942e22c"
111setup = """## Setup
112
113This rule requires data coming in from one of the following integrations:
114- Elastic Defend
115- Auditbeat
116
117### Elastic Defend Integration Setup
118Elastic 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.
119
120#### Prerequisite Requirements:
121- Fleet is required for Elastic Defend.
122- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
123
124#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
125- Go to the Kibana home page and click "Add integrations".
126- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
127- Click "Add Elastic Defend".
128- Configure the integration name and optionally add a description.
129- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
130- 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).
131- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
132- 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.
133For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
134- Click "Save and Continue".
135- 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.
136For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
137
138### Auditbeat Setup
139Auditbeat is a lightweight shipper that you can install on your servers to audit the activities of users and processes on your systems. For example, you can use Auditbeat to collect and centralize audit events from the Linux Audit Framework. You can also use Auditbeat to detect changes to critical files, like binaries and configuration files, and identify potential security policy violations.
140
141#### The following steps should be executed in order to add the Auditbeat on a Linux System:
142- Elastic provides repositories available for APT and YUM-based distributions. Note that we provide binary packages, but no source packages.
143- To install the APT and YUM repositories follow the setup instructions in this [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/setup-repositories.html).
144- To run Auditbeat on Docker follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/running-on-docker.html).
145- To run Auditbeat on Kubernetes follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/running-on-kubernetes.html).
146- For complete “Setup and Run Auditbeat” information refer to the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/setting-up-and-running.html).
147"""
148severity = "medium"
149tags = [
150        "Domain: Endpoint",
151        "OS: Linux",
152        "Use Case: Threat Detection",
153        "Tactic: Credential Access",
154        "Tactic: Persistence",
155        "Tactic: Lateral Movement",
156        "Data Source: Elastic Endgame",
157        "Data Source: Elastic Defend"
158        ]
159timestamp_override = "event.ingested"
160type = "query"
161query = '''
162event.category:file and host.os.type:linux and event.type:change and 
163  process.name:(* and not (dnf or dnf-automatic or dpkg or yum or rpm or yum-cron or anacron or platform-python)) and 
164  (file.path:(/usr/bin/scp or 
165                /usr/bin/sftp or 
166                /usr/bin/ssh or 
167                /usr/sbin/sshd) or 
168  file.name:libkeyutils.so) and
169  not process.executable:/usr/share/elasticsearch/*
170'''
171
172[[rule.threat]]
173framework = "MITRE ATT&CK"
174
175[[rule.threat.technique]]
176id = "T1543"
177name = "Create or Modify System Process"
178reference = "https://attack.mitre.org/techniques/T1543/"
179
180[rule.threat.tactic]
181id = "TA0003"
182name = "Persistence"
183reference = "https://attack.mitre.org/tactics/TA0003/"
184
185[[rule.threat]]
186framework = "MITRE ATT&CK"
187
188[[rule.threat.technique]]
189id = "T1556"
190name = "Modify Authentication Process"
191reference = "https://attack.mitre.org/techniques/T1556/"
192
193[rule.threat.tactic]
194id = "TA0006"
195name = "Credential Access"
196reference = "https://attack.mitre.org/tactics/TA0006/"
197
198[[rule.threat]]
199framework = "MITRE ATT&CK"
200
201[[rule.threat.technique]]
202id = "T1021"
203name = "Remote Services"
204reference = "https://attack.mitre.org/techniques/T1021/"
205
206[[rule.threat.technique.subtechnique]]
207id = "T1021.004"
208name = "SSH"
209reference = "https://attack.mitre.org/techniques/T1021/004/"
210
211[[rule.threat.technique]]
212id = "T1563"
213name = "Remote Service Session Hijacking"
214reference = "https://attack.mitre.org/techniques/T1563/"
215
216[[rule.threat.technique.subtechnique]]
217id = "T1563.001"
218name = "SSH Hijacking"
219reference = "https://attack.mitre.org/techniques/T1563/001/"
220
221[rule.threat.tactic]
222id = "TA0008"
223name = "Lateral Movement"
224reference = "https://attack.mitre.org/tactics/TA0008/"

Triage and analysis

Investigating Modification of OpenSSH Binaries

OpenSSH is a widely used suite of secure networking utilities based on the Secure Shell (SSH) protocol, which provides encrypted communication sessions over a computer network.

Adversaries may exploit OpenSSH by modifying its binaries, such as /usr/bin/scp, /usr/bin/sftp, /usr/bin/ssh, /usr/sbin/sshd, or libkeyutils.so, to gain unauthorized access or exfiltrate SSH credentials.

The detection rule 'Modification of OpenSSH Binaries' is designed to identify such abuse by monitoring file changes in the Linux environment. It triggers an alert when a process, modifies any of the specified OpenSSH binaries or libraries. This helps security analysts detect potential malicious activities and take appropriate action.

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 script execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence and whether they are located in expected locations.
    • $osquery_0
  • 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.
          • Cron jobs, services and other persistence mechanisms.
            • $osquery_1
  • 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_2
      • $osquery_3
    • Identify the user account that performed the action, analyze it, and check whether it should perform this kind of action.
      • $osquery_4
  • Investigate whether the user is currently logged in and active.
    • $osquery_5

False positive analysis

  • Regular users should not need to modify OpenSSH binaries, which makes false positives unlikely. In the case of authorized benign true positives (B-TPs), exceptions can be added.
  • If this activity is related to new benign software installation activity, consider adding exceptions — preferably with a combination of user and command line conditions.
  • If this activity is related to a system administrator that performed these actions for administrative purposes, consider adding exceptions for this specific administrator user account.
  • 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.

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