Tag: passkeys

  • Credential stuffing: the signals that give it away, and why CAPTCHAs are the weakest layer

    Credential stuffing: the signals that give it away, and why CAPTCHAs are the weakest layer

    Credential stuffing is the dullest attack on the internet and one of the most productive. Nobody exploits your code. Someone takes a list of email and password pairs leaked from other sites, replays them against your login endpoint, and waits for the fraction of people who reused a password. The success rate is low, commonly quoted as around one percent or less, but the lists have millions of lines and the cost per attempt is close to zero.

    The 2023 23andMe incident is the one I point people at. The company said attackers got into roughly 14,000 accounts with reused credentials, and because of the DNA Relatives sharing feature the exposed data reached around 6.9 million users. No vulnerability in 23andMe’s software was needed. The same goes for the 2024 Snowflake customer intrusions, where Mandiant tied the access to stolen credentials from infostealer logs used against accounts without MFA.

    What the traffic looks like

    A brute force attack hammers one account with many passwords. Stuffing is the opposite: many accounts, usually one or two attempts each, every password a real one that worked somewhere. That shape is the first and best signal. Your per-account failure counters never trip, because no account sees more than a couple of failures.

    The signals I actually look at, in rough order of usefulness:

    • Distinct usernames per client. A browser session that tries 40 different accounts in ten minutes is not a person with a bad memory.
    • Failure ratio across the whole login endpoint. Normal traffic has some baseline failure rate you can measure. A stuffing run pushes the global failure rate up, and the unknown-username share of failures tells you whether the list was aimed at you or sprayed generically.
    • Client fingerprint reuse. Botnets rotate IPs but the tooling underneath is often one library with one TLS fingerprint (JA3 or the newer JA4) and one header ordering. Thousands of “different” users sharing a fingerprint no real browser emits is a strong tell.
    • Hits on old passwords. If you keep the previous hash on password change, a login that succeeds with a password the user retired months ago is almost certainly a replayed list.
    • Success from a new device and ASN straight after a burst of failures from the same pool.

    This is the first query I run. It assumes a login event table with client_id (fingerprint plus IP bucket), username, success and ts.

    SELECT client_id,
           count(*)                       AS attempts,
           count(DISTINCT username)       AS users_tried,
           avg(success::int)              AS success_rate
    FROM   login_events
    WHERE  ts > now() - interval '15 minutes'
    GROUP  BY client_id
    HAVING count(DISTINCT username) >= 10
       AND avg(success::int) < 0.2
    ORDER  BY users_tried DESC;

    The thresholds are guesses until you’ve run it against your own baseline for a week. Shared NAT and corporate proxies will show up as a client with many real users, so I tune with the success rate and the fingerprint, not the distinct-user count alone.

    Rate limits and where they stop working

    Per-IP limits are the first thing everyone builds and the first thing residential proxy networks defeat. When each request leaves from a different home IP address, a limit of five attempts per minute per IP does nothing, and a tight one blocks real people behind carrier-grade NAT. I keep the per-IP limit as a cheap filter for the lazy attackers and expect nothing from it against the serious ones.

    The counters that matter are per account and per target. Slowing down the attempts on one username, and telling the real owner that someone is trying, costs the attacker nothing but it does protect the account that has the weak password. Pair that with a global circuit: when the endpoint-wide failure rate jumps, move every login that is not from a known device into a stricter path (step-up, delay, email confirmation) for the duration of the spike.

    Responses should be uniform. If “unknown user” and “wrong password” differ in text, status code or timing, you are handing the attacker a free list validator and making the next run cheaper. This is the same enumeration problem that shows up in password reset flows.

    Why the CAPTCHA is the weakest layer

    I’ve seen teams answer a stuffing incident by putting a CAPTCHA on the login form and calling it done. It stops the lazy script for a week. Then the attacker buys a solving service or pays people to solve them, and the cost per solve is small next to the value of a hijacked account. Meanwhile your legitimate users lose conversion and accessibility, and you have collected one more signal than you started with and none of the controls you needed.

    A CAPTCHA is fine as one input to a risk score, triggered when the other signals are already bad. As the main control it is a tax on your own customers.

    Stop the passwords from working

    The durable fix is making a replayed password useless. Two controls do that.

    First, refuse known-breached passwords. NIST SP 800-63B (revision 4, published in 2025) says verifiers must compare chosen passwords against a blocklist of values known to be compromised, and the Have I Been Pwned Pwned Passwords service gives you a free way to do it without sending the password anywhere. You send the first five hex characters of the SHA-1 hash and get back every suffix in that bucket, then compare locally. This is k-anonymity, and it works at login as well as at signup, which is where it pays off for stuffing: a user whose password is in the corpus gets forced through a reset instead of being let in.

    import hashlib, urllib.request
    
    def pwned_count(password: str) -> int:
        sha1 = hashlib.sha1(password.encode()).hexdigest().upper()
        prefix, suffix = sha1[:5], sha1[5:]
        req = urllib.request.Request(
            f"https://api.pwnedpasswords.com/range/{prefix}",
            headers={"Add-Padding": "true"},
        )
        body = urllib.request.urlopen(req, timeout=5).read().decode()
        for line in body.splitlines():
            h, _, n = line.partition(":")
            if h == suffix:
                return int(n)
        return 0

    The Add-Padding header makes the response size less informative to anyone watching the connection. I ran the unpadded form by hand to show what comes back:

    Terminal output: SHA-1 of the word password, the 1977-line Pwned Passwords range response for prefix 5BAA6, and the matching suffix with a count of 52372427. Text rendered into an image from a real run.

    The screenshot is a real run of those commands against the public API. The bucket for the prefix 5BAA6 holds 1,977 suffixes, and the SHA-1 of the word “password” appears in it with a count of 52,372,427. I rendered the terminal text into an image myself, so the colours are mine, the output is not.

    Second, add a factor an attacker cannot replay. A passkey or a TOTP code turns a correct password into a necessary but not sufficient credential. Passkeys are better because there is nothing to type into a phishing page or an infostealer log. If you can’t require a second factor for everyone, require it when the risk score says new device, new ASN, or the account’s password appeared in a breach corpus.

    Putting it together

    Flow diagram of five login controls from edge rate limit to second factor, with red branches showing the action taken at each

    Detection feeds the controls, and none of them is enough alone. If I had to pick the two that matter most, they are the breached-password check and a real second factor, because they work no matter how good the attacker’s proxy pool is. Everything else buys time and gives you telemetry. Start by running the query above against last week’s logs.

  • MFA that survives phishing: TOTP, push and FIDO2 passkeys compared

    MFA that survives phishing: TOTP, push and FIDO2 passkeys compared

    Part 2 of 4 in the Authentication done right series. Part 1: Password storage in 2026.

    In the first part of this series I covered how to store passwords so a database leak doesn’t hand attackers working credentials. This part assumes the password is already gone, because sooner or later it will be. Phished, reused, scraped off an infostealer log. The question is what your second factor does when someone is actively trying to get past it, and the honest answer for most deployed MFA is “less than you’d think”.

    Not all second factors are the same control

    Two sequence diagrams side by side: a phishing proxy relays a password and TOTP code to the real site and steals the session cookie, while with WebAuthn the origin-bound credential is not offered on the fake domain and the login fails

    People talk about MFA as if it were one thing. In practice the methods fall into two groups. Shared secret and approval based factors (SMS codes, TOTP apps, push notifications) prove the user has a device, but the proof can be relayed by whoever the user is talking to. Public key factors bound to an origin (FIDO2/WebAuthn security keys and passkeys) produce proof that only works for the site that asked for it. That distinction is what CISA means by phishing resistant MFA in its 2022 guidance, and it’s what OMB memo M-22-09 required US federal agencies to adopt.

    SMS is the weakest of the first group. SIM swaps and number porting fraud move the phone number to an attacker, and NIST SP 800-63B has long classed SMS and voice as a restricted authenticator. I’d still take SMS over no second factor, but I wouldn’t let it protect anything I cared about.

    TOTP and the relay problem

    TOTP (RFC 6238, built on HOTP from RFC 4226) derives a six digit code from a shared secret and the current 30 second time step. It’s offline, cheap and works everywhere. It also has nothing in it that identifies which website the user is typing it into.

    That’s the core weakness. An adversary-in-the-middle kit like Evilginx sits between the victim and the real login page as a reverse proxy. The victim sees what looks like the real site, types their password and their TOTP code, and the proxy forwards both in real time and keeps the resulting session cookie. The code was valid. It just went to the wrong party.

    The 2022 “0ktapus” campaign worked this way at scale. SMS messages pointed employees of Twilio and many other companies to lookalike Okta pages that captured credentials and one time codes as they were typed. Cloudflare was targeted by the same campaign, and some of its employees did enter their credentials. The attack still failed there, because Cloudflare required FIDO2 hardware keys and the fake domain couldn’t get a valid assertion from them. Cloudflare’s own write-up of that incident is one of the clearest arguments for WebAuthn I know of.

    If you do run TOTP, at least implement it properly. Accept a small clock skew window and reject codes that have already been used.

    from datetime import datetime, timezone
    import pyotp
    
    def check_totp(user, code):
        totp = pyotp.TOTP(user.totp_secret)
        # accept the current step and one on either side for clock drift
        if not totp.verify(code, valid_window=1):
            return False
        step = totp.timecode(datetime.now(timezone.utc))
        if user.last_totp_step is not None and step <= user.last_totp_step:
            return False  # replayed code
        user.last_totp_step = step
        user.save()
        return True

    Rate limit verification attempts too. A six digit code has a million values, which is not a lot if an endpoint lets someone try thousands of codes per account.

    Push approval and MFA fatigue

    Push MFA looked like an upgrade because the user doesn’t type anything. It created a different failure. If an attacker has the password, they can trigger approval prompts over and over until the user taps Approve to make it stop, or until someone calls pretending to be IT and asks them to accept.

    That’s what happened at Uber in September 2022. According to Uber’s own statement, the attacker had a contractor’s password, sent repeated push requests, and the contractor eventually accepted one. Cisco’s breach that year, disclosed in August, combined voice phishing with the same kind of repeated push prompts. In both cases the MFA product behaved exactly as designed.

    The fixes are real but partial. Number matching shows a code on the login screen that the user has to enter in the authenticator app, so a blind tap no longer works; Microsoft made it mandatory for Authenticator push in May 2023. Showing the location and application in the prompt helps a little. Limiting how many prompts can be sent per hour and alerting on bursts helps more. None of it stops a real-time phishing proxy, because the user is looking at a page that displays the number too.

    Why WebAuthn is different

    With WebAuthn, the browser builds a clientDataJSON structure that includes the challenge and the origin the user is actually on, and the authenticator signs it along with the relying party ID hash. Credentials are scoped to the relying party ID, so an authenticator won’t even offer a credential for example.com to a page on examp1e-login.com. There’s no code for the user to copy, so there is nothing to relay.

    The server side still has to do its part. Every serious library makes you pass the expected origin and RP ID, and you should never loosen those to make a test environment work.

    from webauthn import verify_authentication_response
    
    verification = verify_authentication_response(
        credential=assertion_from_browser,
        expected_challenge=session.pop("webauthn_challenge"),
        expected_rp_id="example.com",
        expected_origin="https://example.com",
        credential_public_key=stored.public_key,
        credential_current_sign_count=stored.sign_count,
        require_user_verification=True,
    )
    stored.sign_count = verification.new_sign_count

    The challenge must be random, single use and tied to the session that requested it. I’ve reviewed implementations that reused a static challenge, which turns a signature scheme back into something replayable.

    Passkeys, synced and device bound

    Passkeys are WebAuthn credentials, usually discoverable ones, and most are synced through a platform account such as iCloud Keychain or Google Password Manager. That’s great for adoption, because users who lose a phone don’t lose their credentials. It also means the security of the passkey now depends on the security of that cloud account and its recovery process.

    For most consumer apps, synced passkeys are a large improvement over passwords plus TOTP. For administrators and production access I still want device bound credentials on hardware keys, and I want attestation checked so I know what kind of authenticator registered.

    Recovery is part of your MFA

    Attackers go where the controls are weakest, and that’s usually account recovery. A strong factor with a “lost your key? we’ll send an SMS” fallback is an SMS factor with extra steps. Help desk resets are the same problem with a human in the loop. The MGM Resorts intrusion in 2023 was widely reported to have started with a call to the help desk.

    So register at least two strong authenticators per user, make recovery require something stronger than knowledge of public facts, and log and alert on every factor reset. Treat a new factor enrolled right after a password reset as a high priority event.

    The next part moves from authenticating a person to delegating access between systems, which means OAuth 2.0, OpenID Connect and the token mistakes that come with them.

    Other parts: Part 1: Password storage in 2026, Part 3: OAuth 2.0 vs OpenID Connect, Part 4: Session management.