TExcelTAD
Home › Windows & Active Directory Security › Password Spraying Against a Domain

Password Spraying Against a Domain

Brute-forcing one account against a domain fails fast: after a few wrong guesses the account locks and the help desk gets a call. Password spraying turns the attack sideways: one or two very common passwords (Winter2026!, Company123, the season and year) tried against every account, slowly enough that no single account reaches the lockout threshold. In a domain of a few thousand users, a handful usually have exactly that password. Spraying is one of the most frequent initial-access techniques against organisations with on-premises AD and remote access portals, and it is also one of the easiest to see, if you look at the right axis of the data.

The general pattern and a first detector are in Brute Force and Password Spraying. This lesson does the AD-specific part: which events and status codes a spray produces on domain controllers, a detection on synthetic DC logs in pandas, and the domain settings that make it fail.

The mechanism, in AD terms

A domain password policy typically has a lockout threshold (for example 10 bad attempts), an observation window (bad attempts are counted for, say, 15 minutes) and a lockout duration. A sprayer stays below the threshold per account per window: one or two guesses per account, then a pause longer than the window, then the next password. Where the guesses arrive depends on the entry point:

  • Kerberos (port 88, straight to a DC): each wrong guess is a failed pre-authentication, event 4771 with failure code 0x18. A guess for a nonexistent user returns KDC_ERR_C_PRINCIPAL_UNKNOWN (logged as a failed 4768 with result code 0x6), which sprayers use to check user names.
  • NTLM through a member server, VPN, mail or web portal: the DC validates and logs 4776 (0xC000006A wrong password, 0xC0000064 no such user), and the server logs 4625 with logon type 3 and the same status codes.
  • Lockouts show as 4740 on the PDC emulator, where bad password counts are tracked domain-wide (FSMO roles).

From one account's point of view, nothing unusual happened: one wrong password this morning. From the source's point of view, 400 accounts failed within 20 minutes.

Detecting a spray in DC logs

The synthetic log below mixes a normal working morning (users mistyping a password now and then) with a spray from 10.10.0.66 that tries Winter2026! against 40 accounts over Kerberos and succeeds on two. The detection groups failures by source over a sliding window and counts distinct accounts, which is the axis a spray can't hide on, then checks whether the same source also had successes.

python · try it yourself
import pandas as pd

rows = []
staff = [f"user{n:02d}" for n in range(1, 41)]
t0 = pd.Timestamp("2026-01-15 08:00")
# normal morning: a few users mistype once or twice from their own workstation, then succeed
for i, u in enumerate(staff[:8]):
    ws = f"10.10.0.{100 + i}"
    rows.append((t0 + pd.Timedelta(minutes=5 * i), 4771, u, ws, "0x18"))
    rows.append((t0 + pd.Timedelta(minutes=5 * i, seconds=20), 4768, u, ws, "0x0"))
# the spray: one guess per account every 25 s from one source; two accounts have that password
for i, u in enumerate(staff):
    t = t0 + pd.Timedelta(minutes=30, seconds=25 * i)
    hit = u in ("user17", "user33")
    rows.append((t, 4768 if hit else 4771, u, "10.10.0.66", "0x0" if hit else "0x18"))
rows.append((t0 + pd.Timedelta(minutes=31), 4768, "notauser", "10.10.0.66", "0x6"))

ev = pd.DataFrame(rows, columns=["time", "id", "account", "src", "code"]).sort_values("time")
fail = ev[((ev.id == 4771) & (ev.code == "0x18")) | ((ev.id == 4768) & (ev.code == "0x6"))]
ok = ev[(ev.id == 4768) & (ev.code == "0x0")]

WINDOW, THRESHOLD = "30min", 10
def max_distinct(group):           # sliding window ending at each failure
    return max(group[(group.time > t - pd.Timedelta(WINDOW)) & (group.time <= t)].account.nunique()
               for t in group.time)
per_src = pd.Series({src: max_distinct(g) for src, g in fail.groupby("src")})
print("max distinct failed accounts per source in any 30-minute window:")
print(per_src.sort_values(ascending=False).head(4).to_string())

for src in per_src[per_src >= THRESHOLD].index:
    f = fail[fail.src == src]
    s = ok[(ok.src == src) & (ok.time >= f.time.min())]
    print(f"\nALERT spray from {src}: {f.account.nunique()} accounts failed "
          f"between {f.time.min():%H:%M:%S} and {f.time.max():%H:%M:%S}, "
          f"max {f.groupby('account').size().max()} failure(s) per account")
    print("  unknown user names tried:", ", ".join(f[f.code == "0x6"].account))
    print("  SUCCESS from the same source (likely compromised):", ", ".join(s.account))
max distinct failed accounts per source in any 30-minute window:
10.10.0.66     39
10.10.0.100     1
10.10.0.101     1
10.10.0.102     1

ALERT spray from 10.10.0.66: 39 accounts failed between 08:30:00 and 08:46:15, max 1 failure(s) per account
  unknown user names tried: notauser
  SUCCESS from the same source (likely compromised): user17, user33

The workstations never exceed one distinct failing account each; the spray source reaches the threshold within minutes, never fails more than once per account (so lockout never triggers), and two accounts then succeed from the same address. Those two are the incident: reset their passwords, revoke their sessions and tickets, and look at what they did next.

Making the rule robust

  • Distributed sprays come from many addresses (a botnet, a cloud range, or the VPN's own address because the VPN does the authentication). Add a second view: failures per password-guess time slot across all sources, and for portals behind a proxy, the client address from the portal's own logs rather than the DC's view.
  • Slow sprays (one password per day) need longer windows and a daily "distinct accounts with one failure" count compared with its baseline.
  • Source = the server, not the attacker: for NTLM through a member server, 4776 on the DC shows the server as the workstation. Use the member server's 4625 (with the network source address) or the portal's log.

How it is fixed or prevented

  • Ban the guessable passwords. Length helps less than refusing the passwords sprayers try: Microsoft Entra Password Protection can enforce a banned-password list (global plus your own: company name, products, city, seasons) on on-premises DCs; third-party password filters do the same. Check NTDS hashes against breach corpora (the shared-hash audit of LSASS and Stored Credentials).
  • MFA on every externally reachable authentication (VPN, mail, remote desktop gateways, web portals), so a correct password alone isn't enough.
  • A sensible lockout policy (NIST SP 800-63B suggests limiting failed attempts per account; Microsoft's baseline uses a threshold of 10 over 15 minutes) plus Fine-Grained Password Policies for admins and service accounts with longer passwords.
  • Reduce the exposed surface: no direct Kerberos or NTLM authentication from the Internet; portals that use modern authentication with smart lockout and IP reputation.
  • Detection plus response: an automatic ticket for "spray from X with successes" and a playbook to reset and investigate.

Pitfalls

  • Alerting on per-account failure counts only. That is the brute-force rule; sprays are designed to stay under it.
  • Lockout as the only defence. It also hands attackers a denial-of-service lever: spraying wrong passwords up to the threshold (10 attempts per account under the baseline) locks everyone out.
  • Ignoring service accounts in the policy: spraying finds Summer2019! on an account with PasswordNeverExpires set years ago.
  • Missing the success. A spray alert without the "and who succeeded" query sends you to block an IP while the compromised account is already in use.

Practice

1. A domain has a lockout threshold of 5 within 30 minutes. How many passwords per account per hour can a careful sprayer try without causing lockouts?

At most 4 per 30-minute window, so 8 per hour, if spaced evenly; in practice sprayers try 1 or 2 per window to stay well clear. That's why lockout alone doesn't stop spraying.

2. Change the spray in the program to come from 40 different addresses (f"10.10.0.{150 + i}"). Does the alert still fire? What would you add?

No: each source fails only once. Add a view across sources: count distinct accounts with exactly one 0x18 failure per 10-minute slot, compared with the morning baseline (here about 1 per 5 minutes); a jump to 38 single-failure accounts in about 16 minutes is the signal.

3. Why does the program also look at result code 0x6?

0x6 (KDC_ERR_C_PRINCIPAL_UNKNOWN) means the user name doesn't exist. Sprayers validate guessed user names this way; a source that tries non-existent names is enumerating.

Test yourself

Which DC event and code show a wrong password during Kerberos pre-authentication?

  1. 4768 with 0x0
  2. 4771 with failure code 0x18
  3. 4740
  4. 4624 type 2

Which axis reveals a password spray best?

  1. Failures per account
  2. Distinct accounts failing per source (or per time slot) in a window
  3. Successful logons per day
  4. Number of DCs

On which DC are account lockouts processed and logged as 4740?

  1. The schema master
  2. The PDC emulator
  3. Every RODC
  4. The infrastructure master

Which defence most directly makes the passwords sprayers try unusable?

  1. A longer lockout duration
  2. A banned-password list enforced on the DCs (e.g. Entra Password Protection)
  3. Renaming the Administrator account
  4. Disabling DNS