SSH brute-force attack
| Class | Authentication |
|---|---|
| Also known as | SSH password guessing |
| CWE | CWE-307: Improper Restriction of Excessive Authentication Attempts |
| OWASP Top 10 | A07:2025 Authentication Failures |
| MITRE ATT&CK | T1110.001 Brute Force: Password Guessing |
| Typical severity | High |
| Affects | Linux servers that run OpenSSH with password login allowed on a port reachable from the internet |
An SSH brute-force attack tries many passwords, usually from a list of common ones, against common account names to sign in to a server through SSH.1 It is the form of Brute-force attack that reaches a server's command line, and SSH on TCP port 22 heads the list of services that password guessing commonly targets.1 The guessing can go on for as long as the server does not limit repeated failed sign-ins in a short time,2 a weakness counted among authentication failures.3
Description
Most Linux servers run OpenSSH, whose server program is sshd. Its settings file, sshd_config, allows password login unless told otherwise: PasswordAuthentication and KbdInteractiveAuthentication both default to yes.4 The root account is treated differently. Its default, PermitRootLogin prohibit-password, turns off password and keyboard-interactive login for root only, so ordinary accounts with passwords remain open to guessing.4
The attacks are automated. The malware Xbash fetches a list of weak passwords from its control server, and P.A.S. Webshell tries passwords against SSH as well as FTP, MySQL and PostgreSQL.1 A server that has been broken into is then often used to attack others, as part of a botnet.
Mechanism
The attacker opens a TCP connection to port 22 and offers a user name and password. OpenSSH allows six attempts per connection by default (MaxAuthTries 6) and closes a connection that has not signed in after 120 seconds (LoginGraceTime).4 Those limits apply to one connection at a time, so a tool opens a new connection when one closes. MaxStartups, default 10:30:100, caps connections that have not yet signed in: at 10, sshd refuses 30% of new ones, and the share rises until it refuses all of them at 100.4
OpenSSH 9.8, released on 1 July 2024, added PerSourcePenalties, enabled by default, which refuses connections from an address that keeps failing, with password guessing named as one of the cases it targets.5 A connection that ends after failed attempts, or that tries an unknown user name, adds 5 seconds of penalty; refusal starts once 15 seconds have built up and lasts at most 10 minutes.4 Guessing still works on such a server, only slower.
Impact
A correct guess gives the attacker a shell with that account's rights. Attackers then add their own public key to ~/.ssh/authorized_keys to keep access after the password is changed (SSH authorized key persistence), and use the machine's processor for Cryptojacking or to attack further servers.6
Notable incidents
Guardicore Labs, now part of Akamai, first recorded the FritzFrog botnet on 9 January 2020. Its malware, written in Go, ran only in memory and had no central control server: infected machines passed lists of targets among themselves and divided them so that no two nodes attacked the same address.6 It tried passwords from a large dictionary against tens of millions of addresses, including government offices, banks, medical centres and telecom companies, and broke into more than 500 SSH servers, among them universities in the United States and Europe and a railway company.6
On each server it added one fixed SSH-RSA public key to authorized_keys, which let the operators back in without a password, and it ran a Monero miner based on XMRig. Akamai's report calls weak passwords "the immediate enabler" of these attacks and recommends public key authentication.6
Detection
sshd writes failed attempts to the system log, in files such as /var/log/auth.log.7 Lines that contain Invalid user record guesses at account names the server does not have. Two patterns are worth an alert: many failures from one address followed by a successful login from the same address, and failures that cycle through many user names.1 The first means a guess worked.
Prevention
Sign in with keys only
A login with an SSH key has no password to guess.6 Create one on your own computer and copy the public half to the server:8
ssh-keygen -t ed25519
ssh-copy-id deploy@203.0.113.10After confirming that a key login works, add a file such as /etc/ssh/sshd_config.d/10-keys.conf on the server:8
PasswordAuthentication no
KbdInteractiveAuthentication no
AllowUsers deployAllowUsers limits SSH login to the listed names.4 Check the settings with sudo sshd -t before running sudo systemctl restart ssh.service; a wrong setting can lock you out of a server reached only over SSH.8 Where a password is still wanted as a second step, AuthenticationMethods publickey,password requires the key first and offers the password prompt only after it.4
Ban repeat offenders
Fail2Ban reads the log and adds firewall rules that block an address after too many failures. Its defaults ban an address for 10 minutes after 5 failures within 10 minutes.9 Its own documentation says it reduces the rate of guesses but "cannot eliminate the risk presented by weak authentication".7 Lockouts have a cost of their own: set too strict, they shut out real users.1
Limit who can reach port 22
A firewall rule that accepts port 22 only from your own addresses stops the attempts before they reach sshd. Securing a Docker application on a self-managed server covers the provider firewall and the other server settings.
Prompt for a coding agent
On this Linux server, check the OpenSSH settings in /etc/ssh/sshd_config and every file in /etc/ssh/sshd_config.d/. Report the values of PasswordAuthentication, KbdInteractiveAuthentication, PermitRootLogin, AllowUsers and MaxAuthTries, and which file sets each one. Then list every key in each user's ~/.ssh/authorized_keys with its comment. Do not change anything or restart sshd; I will confirm a key login works first.
In SecFlash
On the Server page, SecFlash reports a server that offers password login over SSH as SF-SRV-201 and accounts with no password at all as SF-SRV-302. On the Detections page, many failed SSH logins from one address appear as SF-DET-401, attempts across many user names as SF-DET-402, a successful login after many failures as SF-DET-405, and a key newly added to authorized_keys as SF-DET-101.
See also
- Brute-force attack
- Credential stuffing
- SSH authorized key persistence
- Multi-factor authentication
- Securing a Docker application on a self-managed server
- Responding to an unrecognised server login
- Category: Self-managed servers
References
- a b c d e "Brute Force: Password Guessing, T1110.001". MITRE ATT&CK. MITRE.
- back "CWE-307: Improper Restriction of Excessive Authentication Attempts". Common Weakness Enumeration. MITRE.
- back "A07:2025 Authentication Failures". OWASP Top 10:2025. OWASP Foundation.
- a b c d e f g OpenSSH (n.d.). "sshd_config(5)". OpenBSD manual pages.
- back OpenSSH (1 July 2024). "OpenSSH 9.8 release notes". OpenSSH.
- a b c d e Harpaz, Ophir (21 September 2022). "FritzFrog: A New Generation of Peer-to-Peer Botnets". Akamai Blog. Akamai (Guardicore Labs research).
- a b Fail2Ban project (n.d.). "Fail2Ban: ban hosts that cause multiple authentication errors". GitHub.
- a b c Canonical (n.d.). "OpenSSH server". Ubuntu Server documentation.
- back Fail2Ban project (n.d.). "jail.conf". GitHub.
External links
- sshd_config(5), OpenBSD manual pages
- FritzFrog detection script and indicators, Guardicore Labs on GitHub