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