Ensure sshd ClientAliveInterval and ClientAliveCountMax are configured (Automated)
Profile Applicability
- Level 1 - Server
- Level 1 - Workstation
Description
Note: To clarify, the two settings described below are only meant for idle connections from a protocol perspective and are not meant to check if the user is active or not. An idle user does not mean an idle connection. SSH does not and never had, intentionally, the capability to drop idle users. In SSH versions before 8.2p1 there was a bug that caused these values to behave in such a manner that they were abused to disconnect idle users. This bug has been resolved in 8.2p1 and thus it can no longer be abused disconnect idle users.
The two options ClientAliveInterval and ClientAliveCountMax control the timeout of SSH sessions. Taken directly from man 5 sshd_config:
ClientAliveIntervalSets a timeout interval in seconds after which if no data has been received from the client, sshd(8) will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client.ClientAliveCountMaxSets the number of client alive messages which may be sent without sshd(8) receiving any messages back from the client. If this threshold is reached while client alive messages are being sent, sshd will disconnect the client, terminating the session. It is important to note that the use of client alive messages is very different from TCPKeepAlive. The client alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option en-abled by TCPKeepAlive is spoofable. The client alive mechanism is valuable when the client or server depend on knowing when a connection has become unresponsive. The default value is 3. If ClientAliveInterval is set to 15, and ClientAliveCountMax is left at the default, unresponsive SSH clients will be disconnected after approximately 45 seconds. Setting a zero ClientAliveCountMax disables connection termination.
Rationale
In order to prevent resource exhaustion, appropriate values should be set for both ClientAliveInterval and ClientAliveCountMax. Specifically, looking at the source code, ClientAliveCountMax must be greater than zero in order to utilize the ability of SSH to drop idle connections. If connections are allowed to stay open indefinitely, this can potentially be used as a DDOS attack or simple resource exhaustion could occur over unreliable networks.
The example set here is a 45 second timeout. Consult your site policy for network timeouts and apply as appropriate.
Audit Procedure
Command Line
Run the following command and verify ClientAliveInterval and ClientAliveCountMax are greater than zero:
# sshd -T | grep -Pi -- '(clientaliveinterval|clientalivecountmax)'
Example Output:
clientaliveinterval 15
clientalivecountmax 3
- IF -
Matchset statements are used in your environment, specify the connection parameters to use for the-Textended test mode and run the audit to verify the setting is not incorrectly configured in a match block. Example additional audit needed for a match block for the user sshuser:
# sshd -T -C user=sshuser | grep -Pi -- '(clientaliveinterval|clientalivecountmax)'
Expected Result
Both clientaliveinterval and clientalivecountmax should be greater than zero.
Remediation
Command Line
Edit the /etc/ssh/sshd_config file to set the ClientAliveInterval and ClientAliveCountMax parameters above any Include and Match entries according to site policy.
Example:
ClientAliveInterval 15
ClientAliveCountMax 3
Note: First occurrence of a option takes precedence, Match set statements withstanding. If Include locations are enabled, used, and order of precedence is understood in your environment, the entry may be created in a file in Include location.
Default Value
ClientAliveInterval 0
ClientAliveCountMax 3
References
- SSHD_CONFIG(5)
- SSHD(8)
- NIST SP 800-53 Rev. 5: CM-1, CM-2, CM-6, CM-7, IA-5
CIS Controls
v8 - 0.0 Explicitly Not Mapped
v7 - 0.0 Explicitly Not Mapped
Additional Information:
- https://bugzilla.redhat.com/show_bug.cgi?id=1873547
- https://github.com/openssh/openssh-portable/blob/V_8_9/serverloop.c#L137
MITRE ATT&CK Mappings: T1078, T1078.001, T1078.002, T1078.003 | TA0001 | M1026