Skip to content
DoS Disclosed report Advanced

Tor onion service INTRODUCE2 invalid-MAC cells permanently grow service replay cache

The onion service adds the encrypted section of an INTRODUCE2 cell to a non-expiring replay cache before verifying its MAC. An unauthenticated attacker can send many unique MAC-invalid cells to grow the cache indefinitely, leading to memory exhaustion.

geeknik Follow

Originally disclosed on HackerOne

  • Disclosed after 4 months

Summary

A remote client can send well-formed v3 INTRODUCE1 cells whose encrypted section has an invalid MAC but a unique byte pattern. The introduction point parses and forwards these cells to the onion service as INTRODUCE2. On the service side, hs_cell_parse_introduce2() inserts the attacker-controlled encrypted section into the intro-point replay cache before verifying the INTRODUCE2 MAC.

The intro-point replay cache is created with replaycache_new(0, 0), meaning entries never expire. Since MAC-invalid INTRODUCE2 cells fail before ip->introduce2_count++, they also do not advance the normal introduction-count rotation threshold. A malicious client can therefore grow an onion service's per-introduction-point replay cache with unauthenticated data until memory pressure or OOM.

Root Cause

src/feature/hs/hs_cell.c:1015-1034 adds the encrypted section to the replay cache before key/MAC validation:

C
if (replaycache_add_test_and_elapsed(data->replay_cache, encrypted_section,
                                     encrypted_section_len, &elapsed)) {
  ...
  goto done;
}

...
intro_keys = get_introduce2_keys_and_verify_mac(data, encrypted_section,
                                                encrypted_section_len);
if (!intro_keys) {
  ...
  goto done;
}

src/feature/hs/hs_service.c:539 creates the per-introduction-point replay cache with no expiration:

C
ip->replay_cache = replaycache_new(0, 0);

src/feature/hs_common/replaycache.c:122-127 allocates a new time_t and inserts a digest for every new input. With horizon == 0, replaycache_scrub_if_needed_internal() returns without scrubbing.

src/feature/hs/hs_circuit.c:1342-1369 increments ip->introduce2_count only after hs_cell_parse_introduce2() succeeds. Invalid-MAC cells return before this point, so the count-based intro-point rotation threshold is not reached.

Reachability

  1. A client obtains a public onion-service descriptor and sends INTRODUCE1 cells to the advertised introduction point.
  2. The intro point parses the non-encrypted portion, finds the service intro circuit by auth key, and forwards the same payload as RELAY_COMMAND_INTRODUCE2 (src/feature/hs/hs_intropoint.c:653-710).
  3. One INTRODUCE1 is allowed per client circuit, but an attacker can create many introduction circuits. The default onion-service intro DoS defense is disabled (HS_CONFIG_V3_DOS_DEFENSE_DEFAULT 0 in src/feature/hs/hs_config.h:20), and the relay-side INTRODUCE2 token-bucket default is also disabled (HS_DOS_INTRODUCE_ENABLED_DEFAULT 0 in src/feature/hs/hs_dos.c:47).
  4. The onion service stores each unique encrypted section in ip->replay_cache before MAC validation. Mutating only the final MAC byte preserves trunnel framing but guarantees MAC failure.

Proof of Concept

I added an in-tree regression test:

  • File: src/test/test_hs_service.c
  • Test: hs_service/intro2_invalid_mac_replay_cache_growth

(Attachment on the original report: tor-hs-introduce2-invalid-mac-replaycache-dos-poc.patch):

  1. Builds a legitimate INTRODUCE1 payload with Tor's existing hs_circ_send_introduce1() helper.
  2. Mutates only the final byte of the MAC, preserving valid INTRODUCE1/INTRODUCE2 framing.
  3. Delivers eight unique invalid-MAC payloads through hs_circ_handle_introduce2().
  4. Asserts each payload is rejected.
  5. Asserts ip->introduce2_count remains zero.
  6. Asserts digest256map_size(ip->replay_cache->digests_seen) grows from 0 to 8.

Reproduction:

Shell
git apply h1-submissions/tor-hs-introduce2-invalid-mac-replaycache-dos-poc.patch
make -j2 src/test/test
./src/test/test hs_service/intro2_invalid_mac_replay_cache_growth

Observed output:

Text
hs_service/intro2_invalid_mac_replay_cache_growth: [forking] OK
1 tests ok.  (0 skipped)

I also reran the existing normal-path test:

Text
hs_service/intro2_handling: [forking] OK
1 tests ok.  (0 skipped)

Suggested Fix

Do not insert the INTRODUCE2 encrypted section into the non-expiring intro-point replay cache until after the MAC has been verified. If Tor wants early replay suppression for invalid cells to avoid repeated crypto work, use a separate bounded and short-lived negative cache with explicit size limits and expiration.

At minimum, the fix should ensure attacker-controlled MAC-invalid encrypted sections cannot create permanent entries and cannot bypass the normal intro-point rotation/resource accounting.

Impact

The attacker controls the number of permanent replay-cache entries added to the onion service for an intro point. These entries are not removed by replay-cache time expiration, and invalid cells do not count toward the 16,384 to 32,768 valid-INTRODUCE2 introduction-count rotation threshold. The time-based intro-point lifetime is 18 to 24 hours, giving a large window for sustained memory growth.

Each unique invalid encrypted section creates one digest256map entry and one separately allocated time_t. The map entry stores a 32-byte digest key, a value pointer, hash-table linkage, allocator metadata, and the time_t value allocation. A reasonable 64-bit estimate is about 64 to 96 bytes per unique invalid INTRODUCE2, before hash-table resizing overhead. At 100, 500, and 1000 fresh introduction circuits per minute, that is roughly 0.4 to 0.6 MB/hour, 1.9 to 2.9 MB/hour, and 3.8 to 5.8 MB/hour per targeted intro point. Across the 18 to 24 hour intro-point lifetime window, a sustained attacker can accumulate tens to low hundreds of MB of service RSS, and more with parallel clients or higher circuit creation rates.

This is an availability issue. I am not claiming code execution, information disclosure, or integrity impact.

CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L Justification:

  • AV:N: the attack is delivered over normal Tor onion-service introduction circuits.
  • AC:L: no race or heap shaping is required; each malformed INTRODUCE1 only needs valid public framing and a unique invalid MAC byte pattern.
  • PR:N: public onion services expose introduction points to unauthenticated clients.
  • UI:N: no user interaction is needed.
  • S:U: the affected component is the onion service process that receives INTRODUCE2.
  • C:N/I:N: no confidentiality or integrity impact is claimed.
  • A:L: the demonstrated impact is unbounded memory growth, but the PoC does not show immediate service loss or a one-shot crash.

Escalation note: CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H is defensible if you classify sustained, unauthenticated memory growth until OOM as high availability impact, especially for onion services running near a memory ceiling.

The original report as published on HackerOne, by geeknik. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

Tor onion services of the v3 generation are reached through introduction points. A client that wants to contact a service fetches the service's public descriptor, which advertises one or more introduction points, and sends an INTRODUCE1 cell to one of them. The introduction point parses the non-encrypted part of the cell, locates the service's introduction circuit by auth key, and forwards the payload to the service as a RELAY_COMMAND_INTRODUCE2 cell. On the service side, hs_cell_parse_introduce2() handles the cell: it checks the encrypted section against a replay cache and then verifies the MAC with the introduction-point keys.

The replay cache in question is the per-introduction-point cache created in src/feature/hs/hs_service.c. Its purpose is to stop the same encrypted section being accepted twice. The report shows that this cache is populated before the MAC is checked, and that it is created without any expiry, so unauthenticated data can be stored in it permanently.

Setup

The work was done against the Tor source tree. The researcher added an in-tree regression test rather than using a live network deployment:

  • File: src/test/test_hs_service.c
  • Test: hs_service/[redacted]

The proof of concept is attached to the report as tor-hs-introduce2-invalid-mac-replaycache-dos-poc.patch. No specific Tor version is given in the report. The relevant defaults cited are [redacted] 0 in src/feature/hs/hs_config.h:20 and HS_DOS_INTRODUCE_ENABLED_DEFAULT 0 in src/feature/hs/hs_dos.c:47, meaning the onion-service introduction DoS defence and the relay-side INTRODUCE2 token bucket are both disabled by default.

Finding it

The report shows that hs_cell_parse_introduce2() inserts the attacker-controlled encrypted section into the intro-point replay cache before verifying the INTRODUCE2 MAC. Because the cache is created with replaycache_new(0, 0), entries never expire. A cell with an invalid MAC is rejected, but only after its encrypted section has already been recorded. Since the rejection happens before ip->introduce2_count++, such cells also never advance the normal introduction-count rotation threshold.

The combination is the problem: an unauthenticated remote client can add unique, permanent entries to a service's per-introduction-point cache, and the usual accounting that would rotate the introduction point away does not move.

Exploitation

Step 1: Obtain a descriptor and send INTRODUCE1 cells

A client obtains a public onion-service descriptor and sends INTRODUCE1 cells to the advertised introduction point. The cells are well-formed v3 INTRODUCE1 cells whose encrypted section has an invalid MAC but a unique byte pattern.

Step 2: The introduction point forwards the payload

The introduction point parses the non-encrypted portion, finds the service introduction circuit by auth key, and forwards the same payload as RELAY_COMMAND_INTRODUCE2 (src/feature/hs/hs_intropoint.c:653-710).

Step 3: The service stores the encrypted section before MAC validation

On the service side, hs_cell_parse_introduce2() adds the encrypted section to the replay cache before key/MAC validation. The relevant code from src/feature/hs/hs_cell.c:1015-1034 is:

C
if (replaycache_add_test_and_elapsed(data->replay_cache, encrypted_section,
                                     encrypted_section_len, &elapsed)) {
  ...
  goto done;
}

...
intro_keys = [redacted](data, encrypted_section,
                                                encrypted_section_len);
if (!intro_keys) {
  ...
  goto done;
}

The cache insertion happens first; the MAC verification happens afterwards. A MAC failure jumps to done with the entry already in the cache.

Step 4: Repeat with unique invalid payloads

One INTRODUCE1 is allowed per client circuit, but an attacker can create many introduction circuits. Mutating only the final MAC byte preserves trunnel framing but guarantees MAC failure, so each circuit can deliver a fresh, unique encrypted section that is stored and then rejected.

Step 5: Confirm with the regression test

The proof of concept is an in-tree regression test that:

  1. Builds a legitimate INTRODUCE1 payload with Tor's existing hs_circ_send_introduce1() helper.
  2. Mutates only the final byte of the MAC, preserving valid INTRODUCE1/INTRODUCE2 framing.
  3. Delivers eight unique invalid-MAC payloads through hs_circ_handle_introduce2().
  4. Asserts each payload is rejected.
  5. Asserts ip->introduce2_count remains zero.
  6. Asserts digest256map_size(ip->replay_cache->digests_seen) grows from 0 to 8.

Reproduction:

Shell
git apply h1-submissions/tor-hs-introduce2-invalid-mac-replaycache-dos-poc.patch
make -j2 src/test/test
./src/test/test hs_service/[redacted]

Observed output:

Text
hs_service/[redacted]: [forking] OK
1 tests ok.  (0 skipped)

The existing normal-path test was rerun as well:

Text
hs_service/intro2_handling: [forking] OK
1 tests ok.  (0 skipped)

Root cause

The mistake is ordering: the encrypted section is added to the replay cache before the MAC is verified, and the cache is created without expiry. The encrypted section is added to the replay cache before the MAC is verified, and the cache is created without expiry.

src/feature/hs/hs_service.c:539 creates the per-introduction-point replay cache with no expiration:

C
ip->replay_cache = replaycache_new(0, 0);

src/feature/hs_common/replaycache.c:122-127 allocates a new time_t and inserts a digest for every new input. With horizon == 0, replaycache_scrub_if_needed_internal() returns without scrubbing, so nothing is ever removed by time.

src/feature/hs/hs_circuit.c:1342-1369 increments ip->introduce2_count only after hs_cell_parse_introduce2() succeeds. Invalid-MAC cells return before this point, so the count-based intro-point rotation threshold is not reached.

The default defences are disabled. The default onion-service intro DoS defence is disabled ([redacted] 0 in src/feature/hs/hs_config.h:20), and the relay-side INTRODUCE2 token-bucket default is also disabled (HS_DOS_INTRODUCE_ENABLED_DEFAULT 0 in src/feature/hs/hs_dos.c:47). The per-circuit limit of one INTRODUCE1 is not a barrier because an attacker can create many introduction circuits.

Impact

The attacker controls the number of permanent replay-cache entries added to the onion service for an intro point. These entries are not removed by replay-cache time expiration, and invalid cells do not count toward the 16,384 to 32,768 valid-INTRODUCE2 introduction-count rotation threshold. The time-based intro-point lifetime is 18 to 24 hours, giving a large window for sustained memory growth.

Each unique invalid encrypted section creates one digest256map entry and one separately allocated time_t. The map entry stores a 32-byte digest key, a value pointer, hash-table linkage, allocator metadata, and the time_t value allocation. A reasonable 64-bit estimate is about 64 to 96 bytes per unique invalid INTRODUCE2, before hash-table resizing overhead. At 100, 500, and 1000 fresh introduction circuits per minute, that is roughly 0.4 to 0.6 MB/hour, 1.9 to 2.9 MB/hour, and 3.8 to 5.8 MB/hour per targeted intro point. Across the 18 to 24 hour intro-point lifetime window, a sustained attacker can accumulate tens to low hundreds of MB of service RSS, and more with parallel clients or higher circuit creation rates.

This is an availability issue. The researcher explicitly does not claim code execution, information disclosure, or integrity impact.

The CVSS vector given is:

Text
CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L

Justification:

  • AV:N: the attack is delivered over normal Tor onion-service introduction circuits.
  • AC:L: no race or heap shaping is required; each malformed INTRODUCE1 only needs valid public framing and a unique invalid MAC byte pattern.
  • PR:N: public onion services expose introduction points to unauthenticated clients.
  • UI:N: no user interaction is needed.
  • S:U: the affected component is the onion service process that receives INTRODUCE2.
  • C:N/I:N: no confidentiality or integrity impact is claimed.
  • A:L: the demonstrated impact is unbounded memory growth, but the PoC does not show immediate service loss or a one-shot crash.

An escalation note states that CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H is defensible if sustained, unauthenticated memory growth until OOM is classified as high availability impact, especially for onion services running near a memory ceiling.

Fix

The suggested fix is to not insert the INTRODUCE2 encrypted section into the non-expiring intro-point replay cache until after the MAC has been verified. If Tor wants early replay suppression for invalid cells to avoid repeated crypto work, the report suggests a separate bounded and short-lived negative cache with explicit size limits and expiration.

At minimum, the fix should ensure attacker-controlled MAC-invalid encrypted sections cannot create permanent entries and cannot bypass the normal intro-point rotation/resource accounting. The report does not state that a patch was merged.

Variants to test

  • Other replay caches created with replaycache_new(0, 0). Search the tree for zero-horizon caches and check whether any are fed with unauthenticated input before validation. A positive result is a cache whose size grows from attacker-controlled data that is later rejected.
  • Other parse paths that insert before authenticating. Look for functions that call a replay-cache add before a MAC or signature check. A positive result is a rejected cell or message that still leaves a permanent entry.
  • Counters incremented only on success. Check whether other rotation or rate-limit counters are advanced only after full validation, so that invalid input bypasses them. A positive result is a counter that stays at zero while the underlying state grows.
  • Disabled-by-default DoS defences. Check other components where the DoS defence or token bucket defaults to off. A positive result is a documented default of 0 on a defence that would otherwise bound the resource.
  • Single-byte mutation of trailing MAC fields. Try mutating only the final MAC byte in other protocols with framed encrypted sections. A positive result is a payload that passes framing checks, fails authentication, and still causes state to be stored.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 19 min read.

What happened, in plain words

Tor is a network that lets people browse and communicate with more privacy than the ordinary internet gives them. One of its best-known features is the onion service: a website or other service that runs inside the Tor network and is reached through a special .onion address instead of a normal domain name. The service does not have one fixed door on the internet. Instead it publishes a small public file, called a descriptor, that lists a handful of volunteer relays, called introduction points, which are willing to pass visitors through to it.

When you want to visit an onion service, your Tor software downloads that descriptor, picks one of the listed introduction points, and asks it to pass a message to the service. The message is called an INTRODUCE1 cell. The introduction point cannot read the private part of the message; it only reads the outer label, works out which service the message is for, and forwards the private part on to the service as a second kind of message, RELAY_COMMAND_INTRODUCE2.

The service then has to decide whether the message is genuine. It does this with a MAC, short for message authentication code: a short cryptographic stamp that only someone who holds the right secret key can produce correctly. If the stamp is wrong, the message is a forgery or a corrupted copy and should be thrown away.

What this report found is an ordering mistake with an availability consequence. Before the service checks the stamp, it writes a fingerprint of the message into a memory list called the replay cache. The replay cache exists so that the same message cannot be accepted twice: if a fingerprint is already in the list, the message is a replay and is refused. The problem is that this list is created with no expiry at all, so entries stay in it for as long as the service process runs. A stranger on the network can therefore send a stream of messages that are all guaranteed to fail the stamp check, each with a slightly different fingerprint, and every one of them leaves a permanent entry in the list before being rejected. Nothing removes those entries, and the usual safety counter that would eventually rotate the introduction point away is never advanced, because it only moves on successful messages. Memory use grows and grows, which can lead to memory pressure or the service running out of it.

The researcher rated this as a low-severity availability problem: it does not let anyone read data or change data, but it can slowly exhaust a service's memory. The report is written against the Tor source code, and the proof of concept is a test added to Tor's own test suite rather than an attack against a live service.

Context

To follow the rest of this, you need four ideas.

Onion services and introduction points. Think of an onion service as a shop that does not want its street address published. Instead it gives out the addresses of a few trusted couriers, the introduction points. A visitor hands a sealed envelope to a courier, the courier recognises from the outside of the envelope which shop it is for, and delivers it. The courier never opens the envelope. In Tor terms, the visitor's Tor client fetches the service's public descriptor (the list of couriers), builds a circuit (a chain of relays) to one of the introduction points, and sends an INTRODUCE1 cell. A cell is Tor's fixed-size unit of data travelling through the network, roughly the equivalent of a packet.

The introduction point reads only the non-encrypted part of the cell, finds the service's own circuit by an auth key (a public key that identifies which service the message belongs to), and forwards the payload to the service as a RELAY_COMMAND_INTRODUCE2 cell. On the service side, a function called hs_cell_parse_introduce2() handles it: it checks the encrypted section against a replay cache and then verifies the MAC using the introduction point's keys.

Replay cache. A replay cache is a memory of things already seen, used to refuse exact copies. If someone records a valid message and sends it again later, the cache spots the repeat. The cache in question here is kept per introduction point, created in src/feature/hs/hs_service.c. Its purpose is to stop the same encrypted section being accepted twice.

MAC. A message authentication code is like a wax seal on an envelope. Anyone can see the envelope, but only the holder of the secret stamp can make the seal correctly. A receiver checks the seal before trusting the contents. Checking a seal costs a little work, so the order in which you check the seal and do other bookkeeping matters.

The finding. The report shows that this replay cache is filled before the MAC is checked, and that it is created without any expiry. Unauthenticated data, meaning data from someone who has proved nothing, can therefore be stored in it permanently.

Setup

The work was done against the Tor source tree, that is, the collection of source code files that make up Tor. The researcher did not attack a live network deployment. Instead they added a regression test: a test that lives inside the project's own test suite and checks that a particular behaviour stays correct (or, here, demonstrates that it is wrong).

  • File: src/test/test_hs_service.c
  • Test: hs_service/[redacted]

The proof of concept is attached to the report as tor-hs-introduce2-invalid-mac-replaycache-dos-poc.patch. A patch is a text file describing changes to source code, which a tool can apply automatically. No specific Tor version is given in the report.

Two defaults matter for reachability. [redacted] 0 in src/feature/hs/hs_config.h:20 means the onion service's built-in defence against introduction flooding is switched off unless an operator turns it on. HS_DOS_INTRODUCE_ENABLED_DEFAULT 0 in src/feature/hs/hs_dos.c:47 means the relay-side INTRODUCE2 token bucket is also off by default. A token bucket is a simple rate limiter: a bucket holds a number of tokens, each request spends one, and tokens refill at a fixed rate, so a client that sends too fast runs out. With both defaults at zero, neither limiter stands in the way.

Finding it

The report shows that hs_cell_parse_introduce2() inserts the attacker-controlled encrypted section into the intro-point replay cache before verifying the INTRODUCE2 MAC. Because the cache is created with replaycache_new(0, 0), entries never expire. A cell with an invalid MAC is rejected, but only after its encrypted section has already been recorded. Since the rejection happens before ip->introduce2_count++, such cells also never advance the normal introduction-count rotation threshold.

The combination is the problem: an unauthenticated remote client can add unique, permanent entries to a service's per-introduction-point cache, and the usual accounting that would rotate the introduction point away does not move. In plain terms, the shop keeps a filing card for every sealed envelope it receives, files the card before checking the seal, never throws cards away, and never counts the bad envelopes towards the limit that would make it change courier.

Exploitation

Step 1: Obtain a descriptor and send INTRODUCE1 cells

A client obtains a public onion-service descriptor and sends INTRODUCE1 cells to the advertised introduction point. The cells are well-formed v3 INTRODUCE1 cells whose encrypted section has an invalid MAC but a unique byte pattern.

Why this step: the descriptor is public, so anyone can fetch it, and the introduction points it lists accept connections from anyone. "Well-formed" matters because the outer framing must be valid for the introduction point to parse and forward the cell at all. "Unique byte pattern" matters because the replay cache stores a fingerprint of the encrypted section; if two cells had identical encrypted sections, the second would be recognised as a repeat and would not add a new entry. The MAC is deliberately wrong so the service will reject the cell, which is exactly what the attacker wants: rejection after storage.

Step 2: The introduction point forwards the payload

The introduction point parses the non-encrypted portion, finds the service introduction circuit by auth key, and forwards the same payload as RELAY_COMMAND_INTRODUCE2 (src/feature/hs/hs_intropoint.c:653-710).

Why this step: the introduction point is not the target and does not need to be fooled. It behaves exactly as designed, reading the outer label and passing the sealed contents to the service. The attacker never needs to compromise the courier; the courier is doing its job.

Step 3: The service stores the encrypted section before MAC validation

On the service side, hs_cell_parse_introduce2() adds the encrypted section to the replay cache before key/MAC validation. The relevant code from src/feature/hs/hs_cell.c:1015-1034 is:

C
if (replaycache_add_test_and_elapsed(data->replay_cache, encrypted_section,
                                     encrypted_section_len, &elapsed)) {
  ...
  goto done;
}

...
intro_keys = [redacted](data, encrypted_section,
                                                encrypted_section_len);
if (!intro_keys) {
  ...
  goto done;
}

Line by line:

  • if (replaycache_add_test_and_elapsed(data->replay_cache, encrypted_section, starts a call to a function whose name says what it does: add the encrypted section to the replay cache, test whether it was already there, and report how much time has elapsed. data->replay_cache is the cache belonging to this introduction point. encrypted_section is the attacker-supplied bytes.
  • encrypted_section_len, &elapsed)) { passes the length of those bytes and a place to store the elapsed time. The if is true when the function reports that the entry was already present, that is, a replay.
  • ... stands for code the report elides.
  • goto done; jumps to the end of the function, so a detected replay is refused.
  • The blank line and ... separate the two halves of the function.
  • intro_keys = [redacted](data, encrypted_section, calls the function that looks up the introduction point's keys and checks the MAC over the encrypted section. Its result is stored in intro_keys.
  • encrypted_section_len); passes the length again.
  • if (!intro_keys) { tests whether the verification failed. A null result means the MAC did not check out.
  • ... again stands for elided code.
  • goto done; jumps to the end, refusing the cell.

The cache insertion happens first; the MAC verification happens afterwards. A MAC failure jumps to done with the entry already in the cache. That is the whole bug in two lines of ordering: file the card, then check the seal.

Step 4: Repeat with unique invalid payloads

One INTRODUCE1 is allowed per client circuit, but an attacker can create many introduction circuits. Mutating only the final MAC byte preserves trunnel framing but guarantees MAC failure, so each circuit can deliver a fresh, unique encrypted section that is stored and then rejected.

Two terms here. A circuit is a path through several Tor relays that a client builds before sending traffic; building many circuits is normal and cheap for an attacker. Trunnel is Tor's own tool for generating code that packs and unpacks structured messages; it enforces the layout of fields, so if you change a byte in the wrong place the message may no longer parse. Changing only the last byte of the MAC is the surgical option: the message still parses, the fingerprint is different, and the MAC is certain to fail. Each circuit gives one fresh attempt, and the attacker can make as many circuits as they like.

Step 5: Confirm with the regression test

The proof of concept is an in-tree regression test that:

  1. Builds a legitimate INTRODUCE1 payload with Tor's existing hs_circ_send_introduce1() helper.
  2. Mutates only the final byte of the MAC, preserving valid INTRODUCE1/INTRODUCE2 framing.
  3. Delivers eight unique invalid-MAC payloads through hs_circ_handle_introduce2().
  4. Asserts each payload is rejected.
  5. Asserts ip->introduce2_count remains zero.
  6. Asserts digest256map_size(ip->replay_cache->digests_seen) grows from 0 to 8.

Why each step: starting from a legitimate payload means the only difference from real traffic is the one byte the test changes, so the test cannot be dismissed as sending malformed junk. Delivering eight payloads gives a small but clear sample. Asserting rejection confirms the service is doing its job. Asserting the counter stays at zero confirms the rotation safety net never engages. Asserting the map size grows from 0 to 8 confirms that all eight rejected messages left permanent entries behind. digest256map_size is a function that reports how many entries a hash map keyed by 256-bit digests currently holds; digests_seen is the field inside the replay cache that stores those digests.

Reproduction:

Shell
git apply h1-submissions/tor-hs-introduce2-invalid-mac-replaycache-dos-poc.patch
make -j2 src/test/test
./src/test/test hs_service/[redacted]

Line by line:

  • git apply h1-submissions/tor-hs-introduce2-invalid-mac-replaycache-dos-poc.patch applies the patch file to the source tree, adding the test. git apply is a command from the Git version control tool that reads a patch and changes files accordingly.
  • make -j2 src/test/test builds the test binary. make is the standard build tool; -j2 tells it to run two compile jobs in parallel; src/test/test is the target, the test program.
  • ./src/test/test hs_service/[redacted] runs that test program and asks it to execute only the named test.

Observed output:

Text
hs_service/[redacted]: [forking] OK
1 tests ok.  (0 skipped)

Line by line: the first line names the test and says it ran in a forked child process ([forking]) and passed (OK). The second line summarises: one test passed, none were skipped. In other words, the test's assertions all held, including the one that says the cache grew from 0 to 8 while every payload was rejected.

The existing normal-path test was rerun as well:

Text
hs_service/intro2_handling: [forking] OK
1 tests ok.  (0 skipped)

Line by line: the ordinary introduction-handling test still passes, which shows the new test did not break normal behaviour and that the code path under test still works for legitimate traffic.

Root cause

The mistake is ordering: the encrypted section is added to the replay cache before the MAC is verified, and the cache is created without expiry. The encrypted section is added to the replay cache before the MAC is verified, and the cache is created without expiry.

src/feature/hs/hs_service.c:539 creates the per-introduction-point replay cache with no expiration:

C
ip->replay_cache = replaycache_new(0, 0);

Line by line: ip is the introduction point structure. ip->replay_cache is its replay cache field. replaycache_new(0, 0) creates a new cache; the two zeros are the parameters that would set how long entries live and how often the cache is cleaned. Zero means no expiry and no cleaning. The cache is born immortal.

src/feature/hs_common/replaycache.c:122-127 allocates a new time_t and inserts a digest for every new input. With horizon == 0, replaycache_scrub_if_needed_internal() returns without scrubbing, so nothing is ever removed by time. A digest is a fixed-length fingerprint computed from data; here it is 256 bits, or 32 bytes. time_t is the C type used to store a point in time. Scrubbing means walking the cache and deleting stale entries; with a horizon of zero the scrub function decides there is nothing to do and returns immediately.

src/feature/hs/hs_circuit.c:1342-1369 increments ip->introduce2_count only after hs_cell_parse_introduce2() succeeds. Invalid-MAC cells return before this point, so the count-based intro-point rotation threshold is not reached. The counter is the safety net: after enough valid introductions, the service rotates to a different introduction point, which would also discard the old cache. Bad cells never touch the counter, so the net never springs.

The default defences are disabled. The default onion-service intro DoS defence is disabled ([redacted] 0 in src/feature/hs/hs_config.h:20), and the relay-side INTRODUCE2 token-bucket default is also disabled (HS_DOS_INTRODUCE_ENABLED_DEFAULT 0 in src/feature/hs/hs_dos.c:47). The per-circuit limit of one INTRODUCE1 is not a barrier because an attacker can create many introduction circuits. Think of a nightclub with a strict one-drink-per-person rule but no limit on how many people can queue: the rule is real, and it achieves nothing.

Impact

The attacker controls the number of permanent replay-cache entries added to the onion service for an intro point. These entries are not removed by replay-cache time expiration, and invalid cells do not count toward the 16,384 to 32,768 valid-INTRODUCE2 introduction-count rotation threshold. The time-based intro-point lifetime is 18 to 24 hours, giving a large window for sustained memory growth.

Each unique invalid encrypted section creates one digest256map entry and one separately allocated time_t. A hash map is a data structure that stores key-value pairs and finds them quickly by key; here the key is the 32-byte digest. The map entry stores a 32-byte digest key, a value pointer, hash-table linkage, allocator metadata, and the time_t value allocation. A reasonable 64-bit estimate is about 64 to 96 bytes per unique invalid INTRODUCE2, before hash-table resizing overhead.

At 100, 500, and 1000 fresh introduction circuits per minute, that is roughly 0.4 to 0.6 MB/hour, 1.9 to 2.9 MB/hour, and 3.8 to 5.8 MB/hour per targeted intro point. Across the 18 to 24 hour intro-point lifetime window, a sustained attacker can accumulate tens to low hundreds of MB of service RSS, and more with parallel clients or higher circuit creation rates. RSS is resident set size, the amount of physical memory a running process is currently using. The arithmetic is simple: entries per hour times bytes per entry, with the report's own ranges.

This is an availability issue. The researcher explicitly does not claim code execution, information disclosure, or integrity impact. In plain words: nobody gets to run their own code on the service, nobody gets to read secrets, and nobody gets to alter data. The service just gets fatter, which can lead to memory pressure or running out of memory.

The CVSS vector given is:

Text
CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L

CVSS is the Common Vulnerability Scoring System, a standard way of writing a severity score as a short string of letters. Each pair of letters describes one property of the attack. Line by line, the vector says:

  • AV:N: attack vector is network, meaning the attacker reaches the target over a network rather than needing to sit at the keyboard.
  • AC:L: attack complexity is low, meaning no special conditions or lucky timing are needed.
  • PR:N: privileges required is none, meaning the attacker needs no account or permission.
  • UI:N: user interaction is none, meaning no victim has to click anything.
  • S:U: scope is unchanged, meaning the impact stays within the vulnerable component.
  • C:N/I:N: confidentiality and integrity impact are none.
  • A:L: availability impact is low.

Justification:

  • AV:N: the attack is delivered over normal Tor onion-service introduction circuits.
  • AC:L: no race or heap shaping is required; each malformed INTRODUCE1 only needs valid public framing and a unique invalid MAC byte pattern. Heap shaping means carefully arranging memory allocations so that a bug lands in a useful place; this attack does not need that trick.
  • PR:N: public onion services expose introduction points to unauthenticated clients.
  • UI:N: no user interaction is needed.
  • S:U: the affected component is the onion service process that receives INTRODUCE2.
  • C:N/I:N: no confidentiality or integrity impact is claimed.
  • A:L: the demonstrated impact is unbounded memory growth, but the PoC does not show immediate service loss or a one-shot crash.

An escalation note states that CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H is defensible if sustained, unauthenticated memory growth until OOM is classified as high availability impact, especially for onion services running near a memory ceiling. The only difference from the first vector is the final letter: A:H instead of A:L, high availability impact instead of low. OOM stands for out of memory, the point at which a process cannot get more memory and typically dies.

Fix

The suggested fix is to not insert the INTRODUCE2 encrypted section into the non-expiring intro-point replay cache until after the MAC has been verified. If Tor wants early replay suppression for invalid cells to avoid repeated crypto work, the report suggests a separate bounded and short-lived negative cache with explicit size limits and expiration. A negative cache is a memory of things known to be bad, kept deliberately small and short-lived so it cannot itself become the resource problem.

At minimum, the fix should ensure attacker-controlled MAC-invalid encrypted sections cannot create permanent entries and cannot bypass the normal intro-point rotation/resource accounting. The report does not state that a patch was merged.

Variants to test

These are follow-up ideas for anyone auditing similar code. Each one is a way of asking the same question in a different place: does unauthenticated input get remembered before it is checked?

  • Other replay caches created with replaycache_new(0, 0). Search the tree for zero-horizon caches and check whether any are fed with unauthenticated input before validation. A positive result is a cache whose size grows from attacker-controlled data that is later rejected.
  • Other parse paths that insert before authenticating. Look for functions that call a replay-cache add before a MAC or signature check. A positive result is a rejected cell or message that still leaves a permanent entry.
  • Counters incremented only on success. Check whether other rotation or rate-limit counters are advanced only after full validation, so that invalid input bypasses them. A positive result is a counter that stays at zero while the underlying state grows.
  • Disabled-by-default DoS defences. Check other components where the DoS defence or token bucket defaults to off. A positive result is a documented default of 0 on a defence that would otherwise bound the resource.
  • Single-byte mutation of trailing MAC fields. Try mutating only the final MAC byte in other protocols with framed encrypted sections. A positive result is a payload that passes framing checks, fails authentication, and still causes state to be stored.

Glossary

  • API: an agreed way for one piece of software to ask another to do something, like a menu of allowed requests.
  • Auth key: a public key that identifies which onion service a message is meant for, used by an introduction point to route it.
  • Availability: whether a service is up and able to answer requests; an availability attack tries to stop that.
  • Cell: Tor's fixed-size unit of data sent through the network, roughly a packet.
  • Circuit: a path through several Tor relays that a client builds before sending traffic.
  • Confidentiality: the property that data cannot be read by unauthorised people.
  • CVSS: Common Vulnerability Scoring System, a standard shorthand for describing the severity of a security flaw.
  • Descriptor: the public file an onion service publishes listing its introduction points and keys.
  • Digest: a fixed-length fingerprint computed from data, here 256 bits (32 bytes).
  • Digest256map: a hash map keyed by 256-bit digests, used to look up fingerprints quickly.
  • DoS (denial of service): an attack that aims to make a service unusable rather than to steal from it.
  • Hash map: a data structure storing key-value pairs that finds values quickly by key.
  • Heap shaping: deliberately arranging memory allocations so a bug lands somewhere useful; not needed here.
  • Horizon: in a replay cache, the time window after which entries are considered stale; zero means never.
  • INTRODUCE1: the message a client sends to an introduction point asking it to pass a request to an onion service.
  • INTRODUCE2 / RELAY_COMMAND_INTRODUCE2: the forwarded form of that message, delivered by the introduction point to the service.
  • Integrity: the property that data cannot be altered by unauthorised people.
  • Introduction point: a Tor relay that accepts introductions for an onion service and forwards them to it.
  • MAC (message authentication code): a short cryptographic stamp proving a message came from someone holding the right key and was not altered.
  • Negative cache: a small, short-lived memory of known-bad items, kept bounded so it cannot itself exhaust resources.
  • Onion service: a service reachable only through the Tor network, usually at a .onion address.
  • OOM (out of memory): the state in which a process cannot obtain more memory and usually dies.
  • Patch: a text file describing changes to source code, applied with a tool such as git apply.
  • Regression test: a test kept in a project's test suite to make sure a behaviour stays correct over time.
  • Replay cache: a memory of messages already seen, used to refuse exact copies sent again.
  • RSS (resident set size): the amount of physical memory a running process is currently using.
  • Scrubbing: walking a cache and deleting stale entries.
  • Source tree: the collection of source code files that make up a project.
  • time_t: the C data type used to store a point in time.
  • Token bucket: a simple rate limiter that holds tokens, spends one per request, and refills at a fixed rate.
  • Trunnel: Tor's tool for generating code that packs and unpacks structured messages, enforcing their layout.
  • Unauthenticated: coming from someone who has not proved their identity or permission.
  • v3: the third generation of Tor onion service addressing and protocol, the current one.

More by geeknik

View all

79 more disclosed reports, best first.

More from Tor

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.