Detecting Brute Force
Chapters and transcript
Detecting Brute Force Guessing passwords is one of the oldest attacks. An attacker tries a password. Wrong. Then another one. Wrong again. It still works when passwords are weak or reused. The good news for defenders? It is noisy. Every guess leaves a line in the logs, and in this lesson you will learn to read them.
Three password attacks There are three kinds of password attack. Brute force tries many passwords against one account. Password spraying tries one or a few common passwords against many accounts. Credential stuffing uses username and password pairs leaked from other websites. It works because many people reuse the same password.
Three password attacks Look closer at password spraying. The attacker tries one common password, like Spring twenty twenty-six, against many accounts. Only one or two tries each, often slowly. Why? To avoid account lockout, a control that locks an account after too many failed attempts. No single account gets enough failures to lock.
SSH logs On Debian and Ubuntu, SSH logins are written to slash var slash log slash auth dot log. Three lines you must know. Failed password for root: a wrong password for a real account. Failed password for invalid user admin: that username does not even exist, so the attacker is guessing names too. And Accepted password: a successful login. Each line shows the source IP. Group by IP, not by port.
Step 1: count Step one: count the failures. The first command counts every failed password line. The second pulls out each source IP, counts them, and lists the busiest first. Three hundred and twelve failures from one outside IP is a brute force attack. Two failures from an inside address is probably a staff member who mistyped.
Step 2: look for a success Step two: look for a success. I search for Accepted, to see which logins worked. Look at the result. The same IP that failed three hundred and twelve times now has an Accepted line, for the account deploy. Right before it, a failed password for deploy. The attacker very likely guessed the password.
The key signal This is the most important signal. Hundreds of failures, then a success, from the same IP. Failed attempts alone mean someone tried. A success means someone may now be inside. Treat it as a likely compromise. So check what the account did next: commands run, files changed, new users created, and connections to other systems.
Windows Windows tells the same story with Event IDs. Forty-six twenty-five is a failed logon. It also records a failure reason and the source address. Look for many of them for one account, or across many accounts. Forty-six twenty-four is a successful logon. Watch for one soon after many failures. In a SIEM, you can count these per account and per source.
Quick check Quick check. The logs show failed logins for two hundred different usernames. Each one was tried only once, always with the password Spring twenty twenty-six. Which attack is this? Take a moment, then choose.
Defences How do we defend? MFA means a guessed password alone is not enough. Key-based SSH turns off password login, so there is nothing to guess. And disable root login, so attackers cannot target the most powerful account.
Defences More defences. fail2ban blocks IPs with too many failures. Account lockout helps, but set it carefully, or attackers can lock out real users. And alerting rules warn the SOC about failures followed by a success.
Defences Here is a defence in action. A SIEM rule spots more than twenty failures from one IP in five minutes, and raises an alert for the SOC. A tool like fail2ban reads the same log and blocks that IP for a while. The attacker tries again, and the connection is denied.
Putting it together Let us put it together. Know the three attacks: brute force, spraying and credential stuffing. Count failed passwords and group them by IP. Look for a success from the same IP. That is the most important signal. On Windows, look for many forty-six twenty-fives, then a forty-six twenty-four. And defend with MFA, key-based SSH and good alerting. Now read the lesson below, and try the lab to decide if an attack succeeded.
Guessing passwords is one of the oldest attacks, and it still works when passwords are weak or reused. The good news for defenders is that it is noisy. It leaves many lines in the logs.
Three kinds of password attack
| Attack | What the attacker does | How it looks in logs |
|---|---|---|
| Brute force | Tries many passwords against one account | Many failures for the same username, often from one IP |
| Password spraying | Tries one or a few common passwords against many accounts | Failures across many usernames, a few attempts each, often slow |
| Credential stuffing | Uses username and password pairs leaked from other websites | Many different usernames, often from many IPs, with a higher success rate |
Password spraying is designed to avoid account lockout, a control that locks an account after a number of failed attempts. Credential stuffing works because many people reuse the same password on different sites.
SSH lines in /var/log/auth.log
On Debian and Ubuntu Linux, SSH logins are recorded in /var/log/auth.log. (On some other Linux systems the file is /var/log/secure.) Three lines you must know:
Mar 12 03:14:07 web01 sshd[2201]: Failed password for root from 203.0.113.45 port 52144 ssh2
Mar 12 03:14:09 web01 sshd[2203]: Failed password for invalid user admin from 203.0.113.45 port 52150 ssh2
Mar 12 03:21:40 web01 sshd[2390]: Accepted password for deploy from 203.0.113.45 port 53011 ssh2
| Line | Meaning |
|---|---|
Failed password for root |
Wrong password for a real account, here root |
Failed password for invalid user admin |
The username admin does not exist on this server. The attacker is guessing names too |
Accepted password for deploy |
A successful login to the account deploy |
Each line also shows the source IP (203.0.113.45) and the source port. The port changes with every connection, so it is not useful for grouping. Group by IP.
Step 1: count the failures
Start with simple commands:
# How many failed passwords in total?
grep "Failed password" /var/log/auth.log | wc -l
# Which IPs failed the most?
grep "Failed password" /var/log/auth.log | grep -oE "from [0-9.]+" | sort | uniq -c | sort -rn | head
The second command pulls out each from <IP> part, counts how often each IP appears, and lists the busiest first. A result like this is typical:
312 from 203.0.113.45
41 from 198.51.100.8
2 from 10.0.5.20
Hundreds of failures from one external IP is a brute force attack. Two failures from an internal address is probably a staff member who mistyped.
Step 2: look for a success
Now check which logins worked:
grep "Accepted" /var/log/auth.log
Then compare. Did any IP that failed many times also get an Accepted line?
Mar 12 03:21:38 web01 sshd[2388]: Failed password for deploy from 203.0.113.45 port 53005 ssh2
Mar 12 03:21:40 web01 sshd[2390]: Accepted password for deploy from 203.0.113.45 port 53011 ssh2
This is the most important signal. Many failures followed by a success from the same IP means the attacker very likely guessed the password. Treat it as a likely compromise, not just an attempt.
Failed attempts alone mean someone tried. A success means someone may now be inside. After finding this, check what the account did next: commands run, files changed, new users created, and connections to other systems.
Windows equivalents
On Windows, the Security event log records the same story with Event IDs:
| Event ID | Meaning | What to look for |
|---|---|---|
| 4625 | Failed logon | Many 4625 events for one account, or across many accounts |
| 4624 | Successful logon | A 4624 for the same account or source soon after many 4625s |
Event 4625 also includes a failure reason (for example, unknown user name or bad password) and the source network address. In a SIEM you can count 4625 events per account and per source address, just like the Linux commands above.
Defences
| Defence | How it helps |
|---|---|
| MFA (multi-factor authentication) | A guessed password alone is not enough to log in |
| Key-based SSH | Turn off password login (PasswordAuthentication no), so there is nothing to guess |
| Disable root login | Set PermitRootLogin no, so attackers cannot target the most powerful account directly |
| fail2ban | Reads the logs and temporarily blocks IPs with too many failures |
| Account lockout | Locks an account after several failures (set carefully, so attackers cannot lock out real users on purpose) |
| Alerting rules | A SIEM rule such as: more than 20 failures from one IP in 5 minutes, followed by a success, raises a high-priority alert |
Strong, unique passwords still matter, especially against credential stuffing.
In the lab, you will analyse an auth log, find the attacking IP, and decide whether the attack succeeded.
HANDS-ON LAB
Brute Force Detective
Hundreds of failed SSH logins. Did any of them succeed?
Check your understanding
Answer every question correctly to complete this lesson. If you miss one, try the quiz again.
1. An attacker tries one common password, such as Spring2026, against hundreds of different accounts. What is this called?
2. You see 300 failed SSH logins from 203.0.113.45, then Accepted password for deploy from 203.0.113.45. What does this most likely mean?
3. Which change stops SSH password guessing completely?
Locked: answer every quiz question above correctly to complete this lesson.
Spotted a mistake or something unclear? Report a mistake