Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Credential stuffing and how to stop it

After this lesson: I can recognise credential stuffing in a sign-in log and choose defences that stop it.

60 min lesson10 commandsPassword lab: John the Ripper, MFA and passkeys

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

A shop's leak becomes a college's problem

An online shop is breached and its customers' emails and passwords are posted on a forum. A week later, a college's sign-in page gets thousands of attempts, each a different account, each tried once.

Nobody guessed anything. The attacker is betting that people used the same password at the shop and at college.

By the end of this lesson

Note

I can recognise credential stuffing in a sign-in log and choose defences that stop it.

Key words

WordWhat it means
Combo listleaked pairs of email and password
Reuseone password on more than one site
Throttlingrefusing sign-ins after too many failures
Lockoutblocking one account after failures
Breached-password checkrefusing a password seen in a leak
Failure ratiofailed sign-ins out of all sign-ins

The cells students fill in are left blank in this preview.

Starter

Have a go

Starter

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

The rule for this lesson

Warning

Attack only your own lab's site. Its accounts, addresses and leaked list are made up, and your copy has no way out to the internet. Replaying leaked passwords against a real site without written permission is a crime under the Computer Misuse Act 1990.

Stuffing replays pairs leaked elsewhere

A combo list holds pairs leaked from other sites. A stuffing tool tries each pair once, spread over many addresses, often through hired proxies. Most fail, because most people's accounts are elsewhere or use a different password.

The few that work are reuse. Neither the password's length nor the site's hash helps, because the attacker already has the password.

Look at the leaked list

Command
docker exec john head -3 combos.txt

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Replay the list against your site

Command
docker exec john python3 steps/stuff.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Worked example: the first replay

What stuff.py printedWhat it means
pairs tried: 30Every pair once
wrong 28Most pairs fail
ok 1, [email protected]ben reused Liverpool1: the account is taken
need-code 1, [email protected]amira reused sunshine, but her second factor held

The cells students fill in are left blank in this preview.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

The log shows the pattern

Every attempt is a line in the site's log. One person who forgot a password fails a few times on one account. A stuffing run fails on many different accounts, from each address, nearly every time.

So count, per address, the attempts, the failures and the distinct accounts tried. A high failure ratio across many accounts is the signature.

Summarise the log by address

Command
docker exec site python3 report.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Read the last three log lines

Command
docker exec site tail -3 site.log

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Try it: failures per address

Code: python
# Failed sign-ins per address, and how many accounts each tried.
tried = {"10.9.0.11": [4, 4], "10.0.0.5": [3, 1]}
for address in tried:
    failed = tried[address][0]
    accounts = tried[address][1]
    print(address, failed, "failed across", accounts, "accounts")
# Add a third address that failed 1 time on 1 account, then press Run.

Make a free account to save your work and track your progress.

Throttling alone does not stop it

Throttling refuses an address or an account after 5 failures. Stuffing tries each account once from 8 addresses, so neither limit is reached and ben is still taken. Sent from one address, the same run is throttled after 5 failures.

The breached check works differently: a correct password that is on a leaked list is refused until it is changed.

Switch throttling on

Command
docker exec site python3 policy.py throttle on

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Replay over 8 addresses again

Command
docker exec john python3 steps/stuff.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Start the failure counts again

Command
docker exec site python3 policy.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Replay from one address

Command
docker exec john python3 steps/stuff.py one

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Switch the breached check on

Command
docker exec site python3 policy.py breached on

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Replay with the breached check on

Command
docker exec john python3 steps/stuff.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

A common mistake

Warning

Many people think locking an account after five failures stops credential stuffing. Stuffing tries each account once, so a lockout never fires; it mostly locks out real people. Use breached-password checks and MFA, and throttle by address as one layer.

The fix, and how to detect it

Fix: check passwords against breached lists at sign-up and sign-in, ask for MFA, and throttle by address with a bot check when failures climb. Tell users who reused a leaked password to change it.

Detect: alert when one address fails across many accounts, or when the site-wide failure ratio jumps. Watch for many accounts signing in from new places.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Assignment: find the stuffing

The lab site's log has one line per attempt, such as #4 10.0.0.5 [email protected] wrong: a number, the address, the account and the result. Write three functions. parse(line) returns [address, account, result]. by_source(lines) returns a dictionary from each address to {"attempts": ..., "failed": ..., "accounts": [...]}, where a result of "wrong" or "throttled" is a failure and accounts lists each account once, in the order first seen. suspects(lines, accounts_at_least, failed_share) returns, in sorted order, the addresses that tried at least that many accounts and whose failures divided by attempts are at least failed_share.

Code: python
def parse(line):
    return []


def by_source(lines):
    return {}


def suspects(lines, accounts_at_least, failed_share):
    return []

Make a free account to save your work and track your progress.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.