Skip to content
Crypto Write-up Advanced

The Curious Case of WebCrypto Diffie-Hellman on Firefox - Small Subgroups Key Recovery Attack on DH

Firefox's WebCrypto implementation allowed an attacker with XSS to modify the prime and generator parameters of an existing DH private key, enabling recovery of the private key via a small-subgroup attack. The attacker could then derive the shared secret and decrypt communications.

blog.intothesymmetry.com

Published on blog.intothesymmetry.com

January 07, 2020

The author, on blog.intothesymmetry.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the WebCrypto API allowed the prime and generator of an existing DH key to be redefined after key generation, enabling a small-subgroup attack.

Impact

An attacker with XSS could recover the private key and thus compromise the shared secret, but the attack required the victim to use Firefox's non-standard DH WebCrypto API.

What the attacker needed

Victim uses Firefox with DH WebCrypto; attacker has XSS on the victim site

How it was found

  1. Craft a malicious prime number that is smooth (p-1 has small factors).
  2. Forge a malicious generator of small order (e.g., order 5).
  3. Redefine the generator and prime associated with the existing private key.
  4. Repeat with many prime numbers/generators.
  5. Use the Chinese Remainder Theorem to recover the full private key.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Diffie-Hellman is a method for two parties to agree on a shared secret over an insecure channel. If an attacker can change the numbers (prime and generator) used in that agreement to weak ones, they can figure out the secret. Here, a website using Firefox's built-in crypto could have its keys stolen if an attacker already had a way to run scripts on the page.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.