QA Interview Hub · Knowledge base · Quizzes · Українська

Penetration Testing

Authentication: passwords, MFA, sessions, JWT

Passwords, brute force and credential stuffing: how login is attacked and defended

Brute force tries many passwords on one account, spraying tries common passwords across many accounts, stuffing uses pairs from breaches. Defence is layered: limits per account, per IP and global, anomaly detection, MFA, breach-list checks and identical responses to any login error. A full account lockout lets an attacker lock other people's accounts.

Pentest · Authentication

A thousand failed logins a minute from different IPs. Is it an attack, and will the login hold?

The log shows a burst of POST /login requests answered with 401. Did somebody forget a password? No: 4000 different accounts and only a few attempts on each. The login form is the first target of any service, and there are three typical attack scenarios. This lesson covers how they differ, why one lockout of failed attempts does not save you and what QA checks.

How it works and why. All three attacks automate login attempts but differ in what they substitute:

  • Brute force — many passwords for one account (from a dictionary to full enumeration);
  • Password spraying — one or two very common passwords for many accounts so as not to exceed the per-account limit;
  • Credential stuffing — login and password pairs from other breaches: it works because people reuse passwords across sites.

What each attack substitutes

Brute forceone accountSprayingone passwordStuffingleaked pairs
Figure 1. Rows are accounts, columns are passwords, attempts are highlighted. A limit per account stops only the first attack.

This gives the logic of defence. Rate limiting of logins is set on several levels: per account, per IP address and overall, and anomalies (many different accounts tried with the same password) are detected separately. A full lockout of an account after N attempts has a downside: an attacker can deliberately lock other people’s accounts (denial of service), so progressive delays or a temporary lockout together with a challenge are used more often. Against stuffing, multi-factor authentication, checking passwords against lists of known breaches and bot protection help.

Password policy. NIST SP 800-63B-4 (revision 4) drops the usual requirements. For a password as the only factor the minimum is 15 characters (8 if the password is only part of MFA); the verifier should allow a length of at least 64; must not impose composition rules such as “a capital letter, a digit, a symbol”; must not require periodic changes without signs of compromise; must compare a new password against a list of common and compromised ones. The limit of failed attempts on one authenticator must not exceed 100. The reason: complex rules produce predictable passwords (Winter2026!) and forced rotation produces “Winter2027!”.

Example: what the login gives away. QA sends a login with a non-existent account and with an existing one but a wrong password. The defective responses differ:

POST /login   {"email":"nobody@shop.example","password":"x"}
HTTP/1.1 401  {"error":"user not found"}

POST /login   {"email":"anna@shop.example","password":"x"}
HTTP/1.1 401  {"error":"wrong password"}

Now an attacker can check whether an account exists (user enumeration) and work only on real ones. The fix is the same message, the same code and about the same response time (a difference of milliseconds also gives away whether the server computed a password hash):

HTTP/1.1 401 Unauthorized
{"error":"Invalid email or password"}

The limit can also be seen from the client side: after a series of failed attempts a refusal is expected with a hint when to retry:

HTTP/1.1 429 Too Many Requests
Retry-After: 60

Such checks are done only on a test account on a test system or in labs (PortSwigger Web Security Academy, the Authentication section, OWASP Juice Shop). Brute force against someone else’s production service without written permission is a crime, and on your own it can lock out real users.

A real case. In October 2023 23andMe reported account takeovers through credential stuffing, and in December, after its investigation, stated that the attacker had accessed about 14,000 accounts (less than 0.1% of 14 million customers): logins and passwords matched those customers used on other sites that had been compromised earlier. According to the company, its own systems were not breached. Through the DNA Relatives feature about 5.5 million relatives’ profiles and 1.4 million family tree profiles were viewed. The company made everyone reset passwords and introduced mandatory two-step verification. The lesson: the weak link is password reuse, and the defence on the service side is MFA, checking against breach lists and detecting mass logins.

Limits. CAPTCHA slows bots down, but services for solving it exist. A per-IP limit is bypassed by a distributed attack from thousands of addresses, so it is complemented by a per-account limit. A password manager and unique passwords are protection on the user’s side that the service does not control. Passkeys remove the password and with it the whole class of attacks on it.

Common mistakes.

  • Different messages for “no such user” and “wrong password”, and the same in the password recovery form.
  • A limit by IP only: spraying from a botnet does not notice it.
  • A full account lockout with no way out: an attacker locks the director out before a decisive day.
  • The “one capital, one digit, one symbol” requirement instead of length and a breach list check.

Check yourself

A limit of “5 failed attempts per account, then a 15-minute lockout”. Which attack does it not stop?

Answer

Password spraying: one or two attempts per account never reach the limit. Limits per IP and overall, anomaly detection and MFA are needed. Credential stuffing with correct pairs also passes on the first attempt.

A login with a non-existent email answers in 12 ms and with an existing one and a wrong password in 180 ms. Why is it a defect even though the messages are the same?

Answer

The different time gives away that for an existing account the server computed the password hash: this is user enumeration by timing. A hash is computed for a non-existent account as well (a dummy one) so that the time matches.

In an interview. Junior: “Brute force tries passwords on one account, spraying tries one password on many accounts, stuffing uses pairs from other breaches. Defence: limits, identical error responses, MFA, long passwords and a breach list check”. Middle/Senior: I add: multi-level limits (account, IP, global), the trade-off between lockout and denial of service, enumeration by message and by time, NIST SP 800-63B-4 on length and rotation, and the 23andMe 2023 case.

MFA and password reset: weak points beyond the password

MFA is broken through the process around it, not the maths of the code. The server issues a session before the second step, does not limit code attempts or accepts a weaker fallback. Password reset must be no weaker than login: the token is random, single-use and short-lived, and the link is not built from the Host header. Against notification fatigue, number matching and passkeys help.

Pentest · Authentication

The login is protected by MFA and the account is still taken over. Through which back door?

A team enabled two-factor authentication and thinks the accounts are protected. But there are several doors to an account: the login form itself, the second step, the “forgot password” button, support. An attacker picks the weakest. This lesson covers typical mistakes of the second factor and of password reset: the places where authentication is broken most often without touching the password.

How it works and why. MFA combines at least two different kinds of factor: knowledge (a password), possession (a phone, a key), inherence (biometrics). The weakness is almost never in the mathematics of the one-time code but in how the server runs the process. Typical defects of the second step:

  • Skipping the step: after the password the server has already issued a session and merely shows the MFA page; a direct request to /dashboard works;
  • No attempt limit: a six-digit code has a million variants and without a limit it is enumerated;
  • The code is not bound to a session or time: the same code is accepted twice or for another account;
  • A weaker fallback: SMS or an e-mail “if you have no app” or “remember this device” bypasses the strong factor;
  • Trusting the client: a flag mfa=true in the request or cookie.

A separate attack is MFA fatigue: an attacker who already knows the password sends dozens of push requests until the user taps “Approve”. Defence: number matching, a request limit, turning push off in favour of codes and best of all passkeys (FIDO2/WebAuthn) bound to the real domain.

Example: skipping the MFA step. After the correct password the application redirects to the code page:

POST /login
HTTP/1.1 302 Found
Location: /mfa
Set-Cookie: sid=A1; HttpOnly

The tester does not enter the code and requests a protected page with the received cookie:

GET /dashboard HTTP/1.1
Cookie: sid=A1

If the answer is 200 with data, the session was issued before the second step and MFA works only on the screen. The right design: until the code is entered the session is only “partially authenticated” and the server refuses (302 to /mfa or 401) on any protected address.

Password reset. This is another path to the account, so it must be no weaker than login. The diagram shows where the checks sit.

Password reset and where it gets broken

1. Request by e-mail2. Letter with token3. Following the link4. New passwordsame responserandom, one-timeshort lifetimeother sessions ended
Figure 1. On the right are the requirements for each step; if one is broken, an account can be taken over without the password.

Typical defects: the token is predictable (depends on time, a number or the user id), has no expiry, works many times or is stored in clear; the response to the request gives away whether the e-mail exists; the link in the e-mail is built from the Host header (host header poisoning); a token in the URL leaks in Referer to third-party sites; old sessions remain after the password change; the code is short with no attempt limit.

Checking host header poisoning on a test system:

POST /forgot-password HTTP/1.1
Host: evil.example
Content-Type: application/json

{"email":"test-user@shop.example"}

If the test user’s e-mail contains a link to https://evil.example/reset?token=…, then a victim who clicks it hands the token to the attacker. The link is built from fixed configuration (the application’s own domain), not from the incoming request.

Real cases. In September 2022 Uber suffered an MFA fatigue attack: according to the company, the attacker likely bought the contractor’s password on the dark web and then tried to log in again and again, so the contractor kept receiving login approval requests; eventually the contractor accepted one and the attacker reached the company’s internal systems. In 2016 researcher Anand Prakash showed that on Facebook’s beta sites (beta.facebook.com) the password reset page had no limit of failed attempts, so the six-digit code (a million variants) could be enumerated; Facebook fixed the bug and paid him 15,000 dollars. Both cases are not about a weak password but about a weak process around it.

Limits and alternatives. Every factor has a price: SMS can be intercepted (SIM swap, phishing), TOTP (a code from an app) is stolen by phishing in real time, passkeys resist phishing but require a recovery plan that does not become the weak spot. The stronger the MFA, the more attractive account recovery and support become to an attacker: human procedures are checked too. Reset requirements are aligned with login requirements.

Common mistakes.

  • Checking MFA only in the interface and not on the server for every protected request.
  • Not limiting attempts to enter the MFA code and the reset code.
  • Giving different response text in the “forgot password” form for an existing and a non-existent e-mail.
  • Not ending active sessions after a password change.

Check yourself

After the password the application shows the MFA page, but GET /dashboard with the issued cookie returns 200. What is the mistake?

Answer

A full session was issued before the second factor and MFA is checked only on the screen. The server must treat the session as incomplete until the code is confirmed and refuse every protected address.

Why is “long” not enough for a password reset token: what else must it be?

Answer

Random from a cryptographic generator, one-time, with a short lifetime and bound to the user; the server stores its hash. Otherwise a long but predictable or eternal token remains vulnerable.

In an interview. Junior: “MFA adds a second factor, but it must be checked on the server, with limited attempts and no bypass routes. A reset token must be random, one-time and short-lived”. Middle/Senior: I add: step skipping, enumeration of a short code, weaker fallbacks, MFA fatigue (Uber 2022) and a reset with no limit (Facebook 2016), host header poisoning, session revocation and passkeys as a more resistant option.

Sessions and JWT: fixation, signature, expiry

Session fixation and JWT mistakes give access without a password. In the first the session id stays the same after login, in the second the server trusts an unchecked token. After login or a privilege change a new id is issued. A typical JWT (JWS) is signed but not encrypted. The server verifies the signature with a fixed algorithm and exp; defects: alg none, RS256 to HS256 confusion, a weak secret.

Pentest · Authentication

The token is signed, so it cannot be forged. Why is that confidence sometimes wrong?

A user has logged in and from then on the server recognizes them by a session identifier or a token. If an attacker made a victim use an id the attacker already knows, or if the server trusts the data in a token without a proper signature check, the password is no longer needed. This lesson covers two related weaknesses: session fixation and typical JWT mistakes.

Session fixation. An attacker gets a not yet authenticated session id from the site (say A1), slips it to the victim (via a link with a parameter or a cookie from a subdomain) and waits for the victim to log in. If after login the server does not change the id, A1 becomes authenticated and the attacker already holds the key. The fix is simple: after any change of privilege level (login, MFA, privilege elevation) issue a new id and destroy the old one.

GET /login HTTP/1.1
HTTP/1.1 200 OK
Set-Cookie: sid=A1; HttpOnly

POST /login   Cookie: sid=A1
HTTP/1.1 302 Found
Set-Cookie: sid=A1

The test is simple: compare the id before and after login. If it is the same, it is a defect (ideally Set-Cookie after login returns a different value).

JWT. A JSON Web Token has three parts in base64url encoding separated by dots: a header (the algorithm), a payload (claims: sub, exp, a role) and a signature. The signature guarantees the data was not changed but does not encrypt it: anyone decodes the header and payload without a key. So secrets and excess personal data are not put in the payload.

The three parts of a token

Headeralg, typPayloadsub, exp, roleSignaturesealthe signature covers these twobase64url: readable without a key
Figure 1. The signature protects against changes but does not hide the content.

Typical implementation and configuration defects:

  • alg: none — the library accepts a token without a signature and the attacker writes any payload;
  • Algorithm confusion (RS256 to HS256) — the server expects an RSA signature but accepts HMAC and uses the public key as the HMAC secret, and everyone knows the public key;
  • A weak HMAC secret — it is guessed offline from a single captured token;
  • No exp or it is not checked — a stolen token works forever;
  • No revocation — a self-contained token works until it expires, even after logout or a password change;
  • Trusting token data without checking — the role from the payload is taken as is although the signature was not verified.

Example: a token that was changed. A genuine user’s token split into parts (shortened, without the signature):

eyJhbGciOiJIUzI1NiJ9
.eyJzdWIiOiI3Iiwicm9sZSI6InVzZXIifQ
.(signature)

After decoding these are the header {"alg":"HS256"} and the payload {"sub":"7","role":"user"}. A tester on a test system assembles a token with the role and the algorithm changed:

eyJhbGciOiJub25lIn0
.eyJzdWIiOiI3Iiwicm9sZSI6ImFkbWluIn0
.
GET /api/admin/users HTTP/1.1
Authorization: Bearer eyJhbGciOiJub25lIn0.eyJzdWIiOiI3Iiwicm9sZSI6ImFkbWluIn0.

The right answer is 401: the server verifies the signature with the expected algorithm and rejects any other. An answer of 200 means the token was forged without a key. The recommendations are collected in RFC 8725 (JWT Best Current Practices): set allowed algorithms explicitly, check iss and aud, do not trust data from the token header; exp is checked per the base RFC 7519. To protect tokens they are stored in an HttpOnly cookie instead of localStorage, and a short lifetime is combined with a refresh token that can be revoked.

A real case. In March 2015 researcher Tim McLean described critical vulnerabilities in JWT libraries on the Auth0 blog. Some of them treated a token with the algorithm none as having a verified signature, so an attacker could compose a token with any payload and access other people’s accounts. Another problem was RS256 to HS256 confusion: a server that expected RSA accepted an HMAC token and used the public key as the secret, so a forged token passed verification. Popular libraries for Node.js, Python and PHP were at risk; the fix was updates and an explicit algorithm parameter during verification. A lesson for QA: every authorization test suite has a “token with another alg” case and an “expired exp” case.

Limits and alternatives. A JWT is not better than a server-side session: a session is easy to revoke and small, while a JWT is convenient when different services verify the token without a shared store. But it is harder to revoke (a short lifetime, a revocation list, key rotation). A cookie token still needs CSRF protection and a token in localStorage is readable by any XSS script. The choice depends on architecture, and both options can be made safe.

Common mistakes.

  • Not changing the session id after login.
  • Treating the JWT payload as secret: everyone can read it and it has no place for passwords and sensitive data.
  • Not checking exp, aud and iss.
  • Taking the verification algorithm from the token’s own header.
  • A short HMAC secret like secret or the project name.

Check yourself

The login page issues the cookie sid=A1 and after login the server keeps sid=A1. How can an attacker use it and what to change?

Answer

The attacker slips the victim a known A1; the victim logs in and A1 becomes authenticated. A new id has to be issued after login (and after MFA or privilege elevation) and the old one destroyed.

A JWT is signed with HMAC and the secret secret. Why does the signature not protect here?

Answer

A weak secret is guessed offline from one captured token and then any payload is signed. The secret must be long and random and keys rotated.

In an interview. Junior: “A JWT is signed but not encrypted: everyone can read its content. The server must verify the signature, the algorithm and the expiry. After login a new session id must be issued to avoid fixation”. Middle/Senior: I add: alg none and RS256/HS256 confusion (the 2015 library example), a weak HMAC secret, revocation and refresh tokens, the choice between a session and a JWT, and RFC 8725.