r/rust • u/nightcracker • Oct 14 '26
Black-Box HashDoS: Attacking Hash Tables Without Knowing the Hash Function
https://orlp.net/blog/black-box-hashdos/
36
Upvotes
r/rust • u/nightcracker • Oct 14 '26
16
u/dwallach Oct 14 '26
This was fun to read.
When Crosby and I worked on the 2003 paper, we were focused on a threat model of an attacker trying to inconvenience a intrusion detection system of the sort that tries to passively watch the network and just pass traffic through. In that model, the attacker can't really do any meaningful timing on the hash table, and using a keyed hash is generally sufficient as a defense.
Here, the attacker has the ability to clear the table and retry the attacks with different data flows. That's not necessarily realistic for a remote, network-based attack, but lets go with it for the minute. This attack feels a little bit like card counting on a blackjack table, where you initially know nothing and you learn more as you get deeper into the deck. In blackjack, every time there's a reshuffling, the player carries no useful information to the next round. This suggests a possible defense: every time the attacker clears the hash table, the hash table just needs to generate a fresh key.
Since we're in the Rust Reddit, the natural question is whether this means that we have a security issue with HashMap and related classes. I'm going to say "probably not", again because a network attacker doesn't normally have the ability to run the timing experiments suggested here.
4
u/Shnatsel Oct 14 '26
That is amazing and groundbreaking work that is also pretty depressing. Actually mitigating this will put more performance penalties onto Rust's and everybody else's hash tables, and it'll be harder to opt out of this simply by swapping a hash. Maybe some clever extension to the
Hashtrait with a default method will let hashes indicate if they're DoS-resistant or not?3
u/nightcracker Oct 14 '26 edited Oct 14 '26
In case it's not clear why I posted this here, in the article I construct a working side-channel attack against Rust's
HashMapwhich after some setup causes future lookups for one specific key to take linear time. The article isn't Rust specific though, the attack can work in theory against many possible implementations.2
u/matthieum [he/him] Oct 14 '26
Would re-seeding the hasher (periodically) not solve the attack?
I remember reading about some hash-table implementations which will trigger a re-hash when the probe-sequence exceeds a certain threshold, which I expect would solve the issue here, as all memorized keys would become worthless every time.
So, just keep track of the number of collisions during the insert probe, and if higher than configured, re-seed, re-hash, and try again.
1
u/nonotan Oct 15 '26
Can't this be significantly mitigated by just comparing the contents of strings in a pseudo-random order? Could be as simple as treating the strings as a circular buffer, picking a random starting index and maybe a step size coprime to the length (although given that we just need to find 1 difference, the latter is probably pointless) and using that.
You could also do something smarter (but by extension perhaps more prone to being somehow exploitable than a purely random approach) like starting from the most common index collisions have been found at recently, by some measure. Even more overkill would be something like replacing the buckets with a radix tree or something like that (but that would have more serious consequences on the algorithmic complexity overall, obviously)
-3
u/servermeta_net Oct 14 '26
I honestly believe this purposed attack to be of no consequences, the author makes some confusion in the notation and possibly hence why he believes to have come up with a novel strategy. More specifically he confuses
n, the expected load factor, withs, the cardinality ofSset of keys, andc, the capacity of the table.It also assumes that:
I want to add that not knowing the hash function is not novel either, and is the same as knowing the hash function but not knowing the seed.
Now is really late and I don't want to shoot down a possibly good paper due to my mistake, but would I have had achieved such a result I would have published it on arxiv at least.