TExcelTAD
Home › Security Foundations: Concepts, Law, Ethics & Your Lab › Brute Force and Password Spraying

Brute Force and Password Spraying

A login form answers one question: "is this the right password for this account?" It answers it for anyone who asks, as often as they ask. Every guessing attack is a way of asking that question many times, and every defence is a way of making the answers cost more than they are worth. This lesson takes the four guessing patterns apart, finds each of them in a log, and lists the controls that stop them. How passwords should be stored is covered in the on-ramp lesson Password Storage; here the attacker sits outside, at the login page.

Four ways to guess

Pattern What the attacker varies Typical shape in the log Why it works
Brute force every possible password for one account one account, one source, hundreds of failures short or simple passwords
Dictionary attack likely passwords (leaked lists, Summer2025!) for one account same shape, far fewer attempts needed people choose predictable passwords
Password spraying one or two common passwords across many accounts one source, many accounts, one failure each per-account lockouts never trigger
Credential stuffing username/password pairs leaked from another site many sources, many accounts, few attempts, a suspicious share of successes people reuse passwords

Pure brute force is mostly a threat offline, against a stolen hash file, where nothing slows the guesser down. Online, against a live login page, the server decides how fast guessing can go. The lab below makes the difference concrete: start with the online attack, then switch attack to an offline GPU and hash to a slow password hash.

8 random characters from 26 a–zentropy H = L · log2 C = 8 · 4.700 = 37.6 bitssearch space C^L = 26^8 = 2.09 × 10¹¹ guessesguess rate R ≈ 1 /s (online login, rate-limited: the hash does not matter)expected time C^L / (2R) ≈ 3,309 yearsrates: illustrativeorders of magnitude,not benchmarkssecondhourdayyearcenturyuniverse age10⁻³ s10³ s10⁹ s10¹⁵ s10²¹ s14812162024expected time (log scale)L = 8: 3,309 yearslength L →

Eight random lower-case letters give 268≈2.1×101126^8 \approx 2.1 \times 10^{11} candidates. At about one guess per second against a rate-limited login, searching half of them takes thousands of years; on one GPU against an unsalted fast hash it takes seconds. The rates in the lab are illustrative orders of magnitude, and they assume a random password. Human passwords fall to dictionaries in a few thousand guesses, which is why attackers prefer dictionaries and spraying to blind brute force.

Definitions

  • Online attack: guesses go through the real login, so the defender sees every attempt and can slow or block it.
  • Offline attack: the attacker has the password hashes (from a breach) and guesses on their own hardware. Only the hash function's cost and the password's strength protect the account.
  • Lockout: blocking an account after nn failures. Throttling (rate limiting) slows attempts instead of blocking.
  • Breached-password list: passwords known from earlier leaks. NIST SP 800-63B (Revision 4, 2025) requires verifiers to compare every new password against a blocklist of commonly used, expected or compromised passwords.

The four patterns in a log

The program below builds a synthetic authentication log for a lab login page and looks at the failures of one ten-minute window in three ways: per (source, account) pair, per source, and per account. Addresses are lab and documentation ranges.

python · try it yourself
from collections import Counter, defaultdict

# Synthetic auth log for a lab login page: (second, source, user, result)
events = [(5, "10.10.0.21", "alice", "ok"), (40, "10.10.0.22", "bob", "fail"),
          (52, "10.10.0.22", "bob", "ok"), (610, "10.10.0.23", "carol", "ok")]
# 1) brute force: one source, one account, many passwords
events += [(100 + 4 * i, "203.0.113.7", "admin", "fail") for i in range(25)]
# 2) spraying: one source, many accounts, one password each
staff = ["alice", "bob", "carol", "dave", "erin", "frank",
         "grace", "heidi", "ivan", "judy", "oscar", "peggy"]
events += [(300 + 15 * i, "198.51.100.9", u, "fail") for i, u in enumerate(staff)]
events.sort()

WINDOW = 600            # look at ten minutes at a time
fails = [e for e in events if e[3] == "fail" and e[0] < WINDOW]

per_pair = Counter((src, user) for _, src, user, _ in fails)
users_per_src = defaultdict(set)
for _, src, user, _ in fails:
    users_per_src[src].add(user)
per_user = Counter(user for _, _, user, _ in fails)

print("failures per (source, account):")
for (src, user), n in per_pair.most_common(3):
    print(f"  {src:<14} {user:<6} {n}")
print("distinct accounts failed per source:")
for src, users in sorted(users_per_src.items(), key=lambda kv: -len(kv[1])):
    print(f"  {src:<14} {len(users)}")

LOCKOUT = 5             # a per-account lockout after 5 failures
locked = [u for u, n in per_user.items() if n >= LOCKOUT]
print("accounts a lockout rule would lock:", locked)

for src, users in users_per_src.items():
    if max(per_pair[(src, u)] for u in users) >= 10:
        print(f"ALERT brute force from {src}")
    if len(users) >= 8:
        print(f"ALERT password spraying from {src}: {len(users)} accounts")
failures per (source, account):
  203.0.113.7    admin  25
  10.10.0.22     bob    1
  198.51.100.9   alice  1
distinct accounts failed per source:
  198.51.100.9   12
  10.10.0.22     1
  203.0.113.7    1
accounts a lockout rule would lock: ['admin']
ALERT brute force from 203.0.113.7
ALERT password spraying from 198.51.100.9: 12 accounts

Read the output against the table. The brute force is loud: 25 failures on admin from one address, and the lockout catches it (which also locks the real administrator out: keep that in mind). The spray is quiet per account: each of the 12 staff accounts sees exactly one failure, so the lockout rule locks none of them. It is loud only per source, where one address failed on 12 different accounts in three minutes. A detection that only counts per account misses spraying entirely.

How it is detected

  • Per-account failure counts in a sliding window: brute force and dictionary attacks.
  • Distinct accounts per source (and per source network, ASN or device fingerprint): spraying. Sprayers spread over hours and many addresses to stay under thresholds, so also look at the global failure rate and at failures for accounts that do not exist.
  • Success after many failures, logins from new countries or devices, and a success rate on the login page that is suddenly higher than normal: credential stuffing (the pairs are real, so many attempts succeed).
  • Impossible travel and new-device sign-ins after a success. Detection rules of this kind are the subject of the Blue Team course; the on-ramp lesson Logging, Monitoring and Detection shows the basic log analysis.

The detection lab runs the first two rules over one synthetic hour of sign-ins for 12 accounts, with a brute force on admin at minute 20 and a spray from one address at minute 40. With the defaults (5-minute window, 10 failures per account, 5 accounts per source) it raises 4 alerts: two on the brute force (the first at 20.9 min), one on the spray at 42.0 min, and one false alarm, a burst of typos from several users behind the same VPN gateway. Raise "accounts per source" to 12 and the false alarm disappears, but so does the spray alert: the sprayer needs 5.5 minutes to try 12 accounts, longer than the window.

failed ✕ and successful ● sign-ins over one hourbrute forcesprayadminalicebobcaroldaveerinfrankgraceheidiivanjudyken0 min10 min20 min30 min40 min50 min60 minalertsSAASalert on an attack (TP)false alarm (FP)A = per account, S = per sourceattacker failureuser typo / forgotten password

How it is prevented

  1. Multi-factor authentication, preferably phishing-resistant (passkeys, security keys). A guessed password alone no longer opens the account. See Authentication and MFA.
  2. Throttling instead of hard lockout. Growing delays per account and per source slow guessing to a crawl without letting an attacker lock every employee out on purpose. NIST SP 800-63B Revision 4 limits consecutive failed attempts on one account to no more than 100 (agencies may set lower limits) and lists throttling methods.
  3. Reject breached and common passwords when a password is set, and allow long passphrases.
  4. Slow, salted password hashes (Argon2id, scrypt, bcrypt, PBKDF2) so a stolen hash file is expensive to attack offline.
  5. Bot and stuffing defences: rate limits per source network, CAPTCHAs only after suspicious signals, and identical responses for "unknown user" and "wrong password" so attackers cannot enumerate accounts.

The breached-password check can be done without sending the password, or even its full hash, to the list's owner. The client hashes the password with SHA-1 and sends only the first five hex digits; the server returns every suffix it knows with that prefix, and the client compares locally. This is the k-anonymity design used by public breached-password services. Here the "server" is a dictionary inside the example:

python · try it yourself
import hashlib

# A tiny stand-in for a breached-password corpus (all well-known weak passwords).
breached = {"123456": 9000, "password": 7000, "Summer2025!": 40, "qwerty123": 900, "letmein": 600}

def sha1(pw):
    return hashlib.sha1(pw.encode()).hexdigest().upper()

# The "server" publishes hash suffixes grouped by their first 5 hex digits (k-anonymity).
ranges = {}
for pw, count in breached.items():
    h = sha1(pw)
    ranges.setdefault(h[:5], {})[h[5:]] = count

def times_breached(candidate):
    h = sha1(candidate)
    bucket = ranges.get(h[:5], {})      # only the 5-character prefix leaves the client
    return h[:5], bucket.get(h[5:], 0)

for pw in ["Summer2025!", "correct horse battery staple", "letmein"]:
    prefix, n = times_breached(pw)
    verdict = "REJECT (seen in breaches)" if n else "allow"
    print(f"{pw!r:32} prefix sent {prefix}  seen {n:>4}  {verdict}")
'Summer2025!'                    prefix sent 1103B  seen   40  REJECT (seen in breaches)
'correct horse battery staple'   prefix sent ABF7A  seen    0  allow
'letmein'                        prefix sent B7A87  seen  600  REJECT (seen in breaches)

SHA-1 is acceptable here because the hash is only a lookup key, not password storage. A real list holds hundreds of millions of entries, so each five-digit prefix matches hundreds of suffixes and the server cannot tell which one you checked.

Pitfalls

  • Hard lockouts as the only control. They turn brute force into a denial of service against your own users and do nothing against spraying.
  • Different error messages ("no such user" versus "wrong password") hand the attacker a list of valid accounts to spray.
  • Counting only by IP address. Sprayers and stuffers rotate through thousands of addresses; count per account and globally as well.
  • Forgetting the other doors. Legacy protocols (IMAP, SMTP AUTH, old VPN portals) often accept passwords without MFA. Attackers spray where MFA is missing.
  • Composition rules instead of length. "One capital, one digit, one symbol" produces Summer2025!, which is in every spraying list.

Practice

1. A sprayer tries one password against 400 accounts every 30 minutes from 50 rotating addresses. Which counter catches it, and which do not?

Per-account counters see one failure per account per half hour and never fire. Per-source counters see eight attempts per address per half hour, probably under a threshold. A global counter of failures (and of failures for accounts that do not exist) shows 400 failures per half hour against a normal background of a few, and catches it. Grouping the 50 addresses by network or by client fingerprint helps too.

2. Change the example so the sprayer uses three source addresses, four accounts each. Does the spraying alert still fire? What would you change?

No: each source now fails on 4 accounts, under the threshold of 8. Lower the threshold (more false positives), count distinct accounts per /24 network, or add a global rule such as "more than 10 accounts failed within 10 minutes across all sources".

3. Why does credential stuffing often produce *successful* logins in the log, and why does MFA still help?

The pairs come from another site's breach, so wherever a user reused the password the first attempt is correct. MFA stops the login at the second factor; the success of the password step is then itself a signal that this user's password is known and must be reset.

Practice problem in 21 languages: Brute-Force Login Alerts.

Test yourself

One source address fails exactly once on each of 12 accounts within three minutes. What is it most likely?

  1. Brute force
  2. Password spraying
  3. A user who forgot a password
  4. A denial-of-service attack

Why does a per-account lockout after 5 failures not stop password spraying?

  1. Sprayers use MFA
  2. Each account receives fewer failures than the threshold
  3. Lockouts only work offline
  4. Sprayers guess hashes

Which attack uses username and password pairs leaked from a different website?

  1. Dictionary attack
  2. Password spraying
  3. Credential stuffing
  4. Brute force

In the k-anonymity breached-password check, what does the client send?

  1. The password
  2. The full SHA-1 hash
  3. The first five hex digits of the SHA-1 hash
  4. Nothing; it downloads the whole list

In the detection lab, why does raising "accounts per source" to 12 lose the spray alert, although the sprayer tries all 12 accounts?

  1. The spray uses 12 different sources
  2. The sprayer needs 5.5 minutes for 12 accounts, so a 5-minute window never holds all 12
  3. Spray failures are ignored by the rule
  4. The per-account rule fires first