Remote access
Password strength and rate limiting
Why guessable passwords fall to repeated tries, and the defences that stop them.
A password policy sets how strong passwords must be and how many tries a login allows. Attackers work through lists of common passwords, so weak passwords fall as fast as tries are allowed. Defences: long random passwords, a limit on tries (fail2ban reads the log and blocks the address), a second factor and, for [[ssh]], keys only. A burst of failures from one address in the log is the sign.
How weak passwords fall, step by step
In the weak password lab the appServer (10.0.2.11) takes SSH password logins, and
its admin account uses a common password. The attacker, kali (10.0.2.5), sits on the same server network.
- The service is reachable. SSH on TCP 22 answers anyone who can reach it, and asks for a password.
- Guesses are cheap. Each try is one SSH connection. People pick from a small set of passwords, so a short list of the most common ones (a dictionary) covers a large share of real accounts.
- Nothing slows the guesser. Each refused try costs a second or so, and the server never blocks the address. A weak password is found within a few tries.
- The login is ordinary. Once a guess works, the attacker is a normal user, with that account's rights.
That is online guessing: every try goes through the live service, so the service can count and limit tries.
Offline cracking is worse: an attacker who steals the stored hashes (from /etc/shadow, a database dump)
tests guesses on their own hardware, with no limit at all. Only the hash's cost and the password's length slow it
down, which is why systems store salted, deliberately slow hashes
(hashing and salting).
NIST SP 800-63B sets the modern rules. Require at least 8 characters (15 where a password is the only factor), allow at least 64, and accept spaces and any characters. Check new passwords against a blocklist of breached and common ones. Do not force composition rules (one digit, one symbol) or periodic changes; change a password when there is evidence it leaked. And rate-limit failed attempts at the service.
What it looks like on a Linux machine
A single wrong password is refused. sshpass exits 5 for a wrong password, and ssh prints:
$ sshpass -p hunter2 ssh admin@10.0.2.11 true
Permission denied, please try again.
The defender's view is the SSH log. sshd writes one line per failed try and one for the success, each with the source address and port:
$ grep -c 'Failed password' /var/log/netlab-sshd.log
6
$ grep -E 'Failed password|Accepted password' /var/log/netlab-sshd.log | tail -6
Failed password for admin from 10.0.2.5 port 44882 ssh2
Failed password for admin from 10.0.2.5 port 44890 ssh2
Failed password for admin from 10.0.2.5 port 44902 ssh2
Failed password for admin from 10.0.2.5 port 44906 ssh2
Failed password for admin from 10.0.2.5 port 44914 ssh2
Accepted password for admin from 10.0.2.5 port 44920 ssh2
A burst of failures from one address, then an Accepted, is the shape of a guessing attack. On systemd machines
the same lines are in journalctl -u ssh, or /var/log/auth.log.
The fixes, on the server. Give the accounts long random passwords:
printf 'admin:<long-random>\nroot:<long-random>\n' | chpasswd
Or turn passwords off and require keys, in /etc/ssh/sshd_config:
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password
Then limit tries: MaxAuthTries 3 per connection, and fail2ban, which reads the same log and adds a firewall rule
for an address after, say, 5 failures in 10 minutes.
What goes wrong, and how you see it
A guessable password on a reachable service. The log shows many Failed password lines from one address,
then Accepted password from the same one. Change the password at once, check what the account did, and move to
keys or a second factor (multi-factor authentication, shown in the
two-factor SSH lab).
Lockout used as a weapon. Locking an account after a few failures lets anyone lock out a real user by guessing on purpose. Rate-limit by source address and slow down per account instead of a hard, permanent lock.
Slow, spread-out guessing. A botnet tries one password per account per hour from many addresses, under every
per-address limit. You see Failed password for invalid user lines from many sources for many names. Keys only,
or a bastion host that is the only machine exposed, removes the target.
Fast hashes after a leak. Unsalted MD5 or SHA-1 hashes fall to offline cracking at billions of guesses a
second. Store yescrypt, bcrypt or Argon2 (/etc/shadow entries starting $y$ or $2b$), never fast hashes.
Questions people ask
How long should a password be? Length beats complexity. NIST asks for at least 8 characters, 15 when it is the only factor; a passphrase of four or more random words is long and easy to type. What matters most is that it is not on a list of common or breached passwords.
Should passwords expire every 90 days? No. NIST SP 800-63B says not to force periodic changes, because people then pick predictable variants. Change a password when there is a sign it leaked.
Is a strong password enough for SSH? It stops guessing, but not a stolen or reused password. Key-only login or a second factor closes that too, and a short log check shows whether anyone is trying.
Read next
- SSH Encrypted remote login and commands, on TCP port 22, with passwords or keys.
- Bastion host One hardened machine that is the only way into a private network.
- WPS A shortcut for joining a WPA network by button or PIN, whose PIN mode is easily guessed.
- Hashing, salting and key exchange The building blocks under TLS and passwords: one-way hashes, salts, key pairs and agreeing a key in public.
- Multi-factor authentication Requiring more than one kind of proof to log in, such as a password plus a time-based code from a device.
- Password cracking Recovering a password offline by hashing guesses from a wordlist (optionally mangled by rules) until one matches.
- Wordlist profiling Building a wordlist from the target's own words and facts, instead of a generic list, so it contains the base word a real passphrase was coined from.
- Online credential guessing Trying username/password pairs against a live service, as fast as it allows — and why it fails against hardened logins.
- Password spraying Trying one likely password once against every account, so no account passes a lockout threshold and anyone who reused a weak shared secret is found.
- Privilege escalation Turning a limited login on a host into full control, by abusing one thing the system was left doing wrong.
- Default credentials The username and password a device or appliance ships with — a confirmed way in whenever nobody changes it before the box goes live.