Skip to content
Crypto Write-up Advanced

Exploiting the Diffie-Hellman bug in socat

The socat tool used a hard-coded 1024-bit Diffie-Hellman parameter that was not prime, making the key exchange weaker than expected. An attacker who could factor the composite number could recover the shared secret by passively eavesdropping on the traffic.

vnhacker.blogspot.com

Published on vnhacker.blogspot.com

February 03, 2016

The author, on vnhacker.blogspot.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 hard-coded Diffie-Hellman parameter was not a prime number, which weakens the discrete logarithm problem enough that the shared secret can be recovered by factoring the composite modulus.

Impact

An attacker who can factor the composite parameter could recover the shared secret by passively eavesdropping, but the text notes that if the largest factor is large enough (e.g., two 500-bit primes), factoring may be infeasible.

What the attacker needed

Ability to factor the composite parameter; ability to sniff network traffic

The fix

The parameter should be replaced with a properly generated prime, as implied by the patch showing a new prime value.

How it was found

  1. Factor the composite parameter p completely using Lenstra elliptic curve factorization and the general number field sieve.
  2. Use the Pohlig-Hellman algorithm and the Chinese Remainder Theorem to reduce the discrete logarithm problem to a smaller subgroup.
  3. Solve the discrete logarithm in the largest subgroup using Pollard's rho or index calculus.
  4. Sniff socat traffic and recover the Diffie-Hellman shared secret.

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 secret key over an insecure channel. It relies on a large prime number; if that number is not actually prime, the secret can be recovered more easily. Here, socat used a non-prime number, so someone listening could potentially work out the secret key and decrypt the traffic.

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.