Replay Attacks, Explained
If you are reading this, you have probably seen "replay attack" on a list of network attacks and wondered how repeating an old message could break anything, especially if the message is encrypted.
By the end you will be able to define a replay attack, explain why it works without breaking any encryption, recognise where it shows up, tell it apart from relay, man-in-the-middle and session-hijacking attacks, and explain the standard defences and how real protocols (IPsec, Kerberos, TLS, Wi-Fi) apply them. It builds on MITM and Handshakes.
1. What a replay attack is
NIST's glossary gives the definition used in its authentication guidance (SP 800-63-4 and SP 800-53 Rev. 5) (source):
"An attack in which the attacker is able to replay previously captured messages (between a legitimate claimant and a verifier) to masquerade as that claimant to the verifier or vice versa."
NIST's WLAN security guide describes it in a similar way: "The attacker monitors transmissions (passive attack) and retransmits messages posing as the legitimate user."
The idea is simple. The attacker does not need to understand, decrypt or change the message. They only need to record one that worked and send it again.
A picture: a security guard opens a door for anyone who says the day's password. You overhear a guest say it. You do not need to know why the password works. You walk up and repeat it, and the guard, who only checks whether the words are right, lets you in. The words were correct, but they were old, and the guard had no way to know.
Why encryption alone does not help
Suppose the message is encrypted and signed. When the attacker replays it, the signature is still valid and the decryption still works, because it is the genuine message. Encryption protects secrecy and signatures protect integrity. Neither one says anything about freshness: "is this message new, or is this the one I saw yesterday?"
So every replay defence works by adding freshness to the message or to the receiver's checks.
2. Where replay attacks appear
| Setting | What is replayed | Example of the risk |
|---|---|---|
| Logins and tokens | A captured authentication message, a password hash or a one-time code | Reusing it to log in again. NIST SP 800-63B separates replay-resistant authenticators from those that are not |
| Web sessions | A stolen session cookie | MITRE ATT&CK (T1550.004): "Adversaries can use stolen session cookies to authenticate to web applications and services. This technique bypasses some multi-factor authentication protocols since the session is already authenticated." |
| Car and garage remotes | A recorded radio code | Replaying it to unlock. Rolling codes were invented to prevent it (section 3) |
| Network protocols | Packets captured from an IPsec, Wi-Fi or Kerberos exchange | Re-sending old packets or tickets. Protocols include built-in counters and timestamps |
| TLS early data (0-RTT) | The first request, sent before the handshake completes | RFC 8446 warns that 0-RTT data has weaker replay protection (section 5) |
| APIs and payments | A valid request with a signature | Re-sending "transfer funds" if the server does not reject duplicates. Applications must design for duplicates |
3. A famous example: rolling codes and RollJam
A fixed code remote sends the same code every time you press the button. Recording it once is enough to replay it forever. Wikipedia's description of the fix: "A rolling code (or sometimes called a hopping code) is used in keyless entry systems to prevent a simple form of replay attack, where an eavesdropper records the transmission and replays it at a later time." The code changes with every press, and the receiver accepts only codes it has not seen before. The receiver tolerates some missed presses; Wikipedia gives, as a typical implementation, a comparison within the next 256 codes.
In 2015 the researcher Samy Kamkar presented RollJam at DEF CON 23. According to Wikipedia's description, his device jams the vehicle's receiver while recording two consecutive unlock attempts, then replays the first code (so the owner's second press still works) and keeps the second for later use. The weakness it exploits is that a code is valid until used, so a code captured before the receiver sees it has not been "spent".
The lesson is the key one in this topic: the defence must fit the way the attacker can interfere, including by jamming, delaying or capturing messages before they arrive.
4. The standard defences
| Defence | How it adds freshness | Where you meet it |
|---|---|---|
| Nonce / challenge-response | The verifier sends a fresh random value (a nonce) that the sender must include in the response, so an old response does not fit a new challenge | Modern cryptographic authentication. NIST SP 800-63B: cryptographic authenticators use challenge-nonce protocols to ensure uniqueness |
| Timestamps | The message includes the time, and the receiver rejects messages that are too old | Kerberos (below) |
| Sequence numbers | Each message carries a counter. The receiver rejects numbers it has seen or that are too old | IPsec ESP (below), Wi-Fi management frames |
| Single-use secrets | A code or token is accepted only once | One-time passwords. NIST: "Verifiers SHALL accept a given OTP only once while it is valid to provide replay resistance" |
| Short lifetimes | A captured secret stops working soon | Out-of-band codes (NIST: limited validity, ten minutes at most), session expiry |
| Session hygiene | New session ID after login, invalidation on logout, idle and absolute timeouts | OWASP Session Management Cheat Sheet |
| Channel protection (TLS) | Each connection uses fresh keys and random values, so a recording from another connection is useless | TLS 1.3: "Protection against replay for ordinary TLS 1.3 1-RTT data is provided via the server's Random value" |
NIST SP 800-63B: replay resistance in authentication
NIST's digital identity guidelines set requirements by assurance level: at AAL2, "at least one authenticator used at AAL2 SHALL be replay-resistant"; at AAL3 "the cryptographic authentication protocol SHALL be replay-resistant". Passwords and look-up secrets, on their own, are not replay-resistant: if an attacker captures a password, they can reuse it. This is one reason the guidelines push toward cryptographic, phishing-resistant authenticators (see Authentication vs. Authorization).
IPsec: sequence numbers and a sliding window
RFC 4303 (IPsec ESP) gives every packet on a security association a sequence number. The receiver keeps a sliding window and rejects duplicates: "a minimum window size of 32 packets MUST be supported when 32-bit sequence numbers are employed; a window size of 64 is preferred." The sequence number must never be allowed to cycle, so a new key must be negotiated before the 2<sup>32</sup>nd packet, or 64-bit extended sequence numbers can be used for fast links. All implementations must support the service, but the receiver can switch it on or off per security association.
Kerberos: timestamps and a replay cache
In Kerberos (RFC 4120), a client proves itself to a service with an authenticator that contains a timestamp. "The timestamp proves that the message was recently generated and is not a replay." The server rejects an authenticator whose time differs from its own by more than the allowed clock skew (for example five minutes), and must keep a replay cache of authenticators it has seen within that window. If a server loses its cache, it "MUST reject all requests until the clock skew interval has passed." This also shows why accurate clocks matter in a Kerberos domain.
Wi-Fi: protected management frames
IEEE 802.11w (protected management frames) protects certain management frames, such as deauthentication, and, per Wikipedia, gets its replay protection from counters already present in the 802.11 encryption. So protected management frames resist replays of old frames. See Deauthentication Attacks.
TLS 1.3 and 0-RTT
TLS 1.3 lets a returning client send data in its first message ("0-RTT"). RFC 8446 states: "There are no guarantees of non-replay between connections. Protection against replay for ordinary TLS 1.3 1-RTT data is provided via the server's Random value, but 0-RTT data does not depend on the ServerHello and therefore has weaker guarantees." Servers can limit the risk with single-use tickets, by recording ClientHellos, or with freshness checks, and applications that use 0-RTT should expect that a message may be delivered more than once. In practice that means only allowing 0-RTT for requests that are safe to repeat (see Handshakes).
Web sessions
A stolen session cookie is a replayable credential. MITRE notes the technique can bypass some MFA because the session has already been authenticated, and recommends configuring browsers to delete persistent cookies regularly. OWASP's session guidance supports shorter exposure: renew the session ID after login or any privilege change, invalidate sessions on logout, use both idle and absolute timeouts, and set the Secure, HttpOnly and SameSite cookie attributes (see XSS for how cookies are stolen).
5. Replay compared with look-alike attacks
| Attack | What the attacker does | Needs to understand or change the message? |
|---|---|---|
| Replay | Records a valid message and sends it later | No |
| Relay | Forwards messages live between two parties who are really far apart. A 2010 ETH Zurich paper on relay attacks against car keys explains that the attacker places one device near the key and one near the car and relays messages between them. Its abstract says the relays are "completely independent of the modulation, protocol, or presence of strong authentication and encryption", so encryption does not stop them. The paper discusses distance bounding as a countermeasure | No |
| Man-in-the-middle | Sits in the path and may read and change messages | Can do both |
| Session hijacking | Takes over a live session, often by stealing the token | Needs the token |
| Spoofing | Fakes an identifier | Not necessarily |
| Brute force | Guesses secrets (see Brute Force vs Password Spraying) | N/A |
Replay is often listed next to man-in-the-middle attacks, because the attacker has to capture the message somewhere on the path. It is useful to keep them separate because the defence against replay, freshness, differs from the defence against reading or tampering, encryption and authentication.
6. How defenders notice replays
| Signal | Where |
|---|---|
| The same message, ticket or code arriving twice | Application and authentication logs. Kerberos servers return an error when they see a repeated authenticator |
| Packets rejected for repeated or out-of-window sequence numbers | IPsec and Wi-Fi counters |
| A session cookie used from two places or two devices | Web application logs |
| Authentication that succeeds from an unexpected place right after a legitimate login | Identity provider logs |
| Remote that works for the owner, then fails once for them | A rolling-code sign that a code was captured |
7. A short design checklist
For anyone building a login, API or device protocol:
- Make every message depend on something fresh: a server-chosen nonce, a counter or a timestamp inside the signed data.
- Make secrets single-use or short-lived, and have the verifier actually enforce it.
- Keep state where it matters: remember used nonces or tickets for the length of the validity window (Kerberos's replay cache is the model).
- Handle clocks carefully if you rely on timestamps. Allow a small, fixed skew and no more.
- Use proven protocols (TLS, IPsec, Kerberos, WebAuthn) instead of designing your own.
- Design operations to be safe to repeat (idempotent) or require a unique request ID, because RFC 8446's guidance for 0-RTT is that applications must cope with duplicated messages.
- Protect and expire sessions as OWASP describes.
- Add phishing-resistant, replay-resistant authentication for high-value accounts.
8. Common mistakes
| Myth | The facts |
|---|---|
| "Encrypted means safe from replay" | A replayed message is a genuine encrypted message. Encryption does not prove it is new |
| "Replay attacks are old and solved" | Protocols solve it, but incorrect or disabled checks, shared clocks, 0-RTT without safeguards and jamming attacks like RollJam keep it relevant |
| "A replay needs the attacker to be in the middle" | They need to hear or capture the message once. Later they can send it from anywhere |
| "Replay and relay are the same" | Replay re-sends a recording later. Relay forwards live to extend distance. Their defences differ (freshness versus distance bounding) |
| "Timestamps alone stop replay" | A replay inside the allowed window can still succeed, so servers (like Kerberos) also keep a replay cache |
| "MFA stops all replay" | Not if the attacker replays an already-authenticated session cookie (MITRE T1550.004) |
| "One-time passwords can be used twice if they are still valid" | The verifier must accept a given OTP only once (NIST SP 800-63B) |
| "Turn off the anti-replay window to avoid dropped packets" | IPsec makes the service optional on the receiver, but turning it off removes the protection |
Closing
A replay attack records a legitimate message and sends it again later. It works without breaking encryption because a replayed message is genuine; what is missing is freshness. Defences add freshness with nonces, timestamps, sequence numbers, single-use and short-lived secrets, and well-managed sessions. Real protocols build these in: IPsec's sliding window, Kerberos's timestamps and replay cache, TLS 1.3's per-connection random values (and its warnings about 0-RTT), and Wi-Fi's protected management frames. Attacks such as RollJam show that attackers will try to capture messages before the receiver counts them.
Keep these points:
- Replay = record a valid message, send it again later.
- Encryption and signatures do not give freshness. Nonces, timestamps and counters do.
- Single-use and short-lived secrets make a captured one useless (NIST SP 800-63B).
- IPsec uses sequence numbers with a window; Kerberos uses timestamps and a replay cache.
- TLS 1.3 0-RTT has weaker replay protection, so use it only for requests that are safe to repeat.
- Stolen session cookies are replayable credentials. Expire and renew sessions.
- Replay is not relay. Relay forwards live, and needs distance-based defences.