Search

Helping developers and enterprises secure their code is what we do. Got a project, an RFP, or just some questions? Let us know!

info(at)matasano.com
1-888-677-0666 x0

Playbook is our product. It does firewall sync. To learn more about Playbook, check out the site, or get in touch with us via the web, e-mail, or phone.

playbook(at)matasano.com
1-888-677-0666 x7529 (PLAY)

« What do you get when you mix NYSec... | Main | Enough With The Rainbow Tables: What You Need To Know About Secure Password Schemes »
Tuesday
Sep252007

Adam Bozanich Did Not Uncover An NSA IPsec Conspiracy: Diffie Hellman Parameter Validation Explained

introduction

Alice and Bob want to arrange a tryst. Bob’s wife Eve is sniffing their Instant Messenger traffic.

No problem! Alice and Bob will encrypt their messages with AES-256-CBC. Eve won’t be able to decode the traffic before the heat death of the universe.

One small problem: what AES key to use? Actually: not a small problem. No matter what key Alice comes up with, she can’t send it to Bob without exposing it. She can’t encrypt the key; chicken and egg.

number theory f.t.w.

There’s a solution to this problem. Alice and Bob will run the Diffie-Hellman protocol (DH) to securely exchange a key.

Alice and Bob agree on a prime number p, and a smaller number g with a special relationship with p ([1]). These are parameters to Diffie Hellman. “23” and “7” are valid p and g parameters. So are “37” and “5”. They aren’t secret. Think of them like a “version” of DH that Alice and Bob agree to use.

For the sake of argument, Alice and Bob agree on “37, 5” DH.

Bust out your calculator. I’ll be Bob.

Generate a random number a, modulo 37 (divide your number by 37 and a is the remainder).

I’ll do the same thing to generate a different b.

Now take your a and make A. Raise 5 to the a‘th power, modulo 37 (in Ruby, do “(5 ** a) % 37”. I’ll do the same with b to make B.

A is your public key. a is your private key. Send me A. I’ll send you B. It’s 29.

Take 29 and raise it to the a‘th power mod 37 (I don’t know what a is; it’s your private key, so I can’t tell you what you’ll get.) That’s “(B ** a) % 37” in Ruby. I’ll do the same with B.

We just arrived at the same number. Was your private key 7? We came up with 8. Was your private key 26? We came up with 27. 27 is our session key.

Funny thing about our session key: you know it, and I know it, but Eve can’t know it. Even though we did this computation out in the open. This is the deep magic, yo.

quick aside:

Well OK, Eve totally knows what number we came up with, because we used a ridiculously small p. Instead of 37, 5, try this:

FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1
29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD
EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245
E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED
EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D
C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F
83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D
670C354E 4ABC9804 F1746C08 CA237327 FFFFFFFF FFFFFFFF

Just use 2 as g. Remember now that your private key a is a random number modulo this huge p. It will also be huge.

Raising a number to a power modulo another number is modular exponentiation (modexp). A modexp is straightforward to compute.

The opposite of exponentiation is a logarithm. Taking a log mod another number is a discrete logarithm. Discrete logs are extremely hard to solve. With large enough numbers, “racing heat death of the universe” hard; “every atom in the Solar System is a computer trying to solve it, still unsolvable” hard.

So you have two closely related operations, exponentiation and logarithm mod p, one of which is easy to compute and one of which is hard. This is a cryptographic building block and the foundation of DH.

back to alice and bob

We got 26 for our session key. Let’s say we MD5 the text value of “26”, to get “4e732ced3463d06de0ca9a15b6153677”. Tack a “0x” at the front of that value, and we now have a 128 bit number we can use as an AES key. Eve can’t know we came up with 26, and so can’t know what the MD5 of the session key is, and so doesn’t know what our AES key is.

Problem solved! Cue arbitrary foreshadowing device. We’ll come back to this.

what adam bozanich found

Adam works for Mu Security. Mu is writing an IKE fuzzer. IKE is a key exchange protocol for IPSec. IKE is probably one of the worst protocols ever to come out of the IETF, and I’m not going to explain it.

What you need to know is that IKE generates the keys that secure dynamically-keyed IPSec tunnels (layer-3 VPNs), and that IKE uses DH to do that.

Adam remembers a DH gotcha. When Alice and Bob run DH, they have to be careful not to allow any of the parameters —- p, g, A, or B —- be zero or one mod p.

Why’s that? Bust out your 37, 5 DH math again. Alice’s session key computation is “(B ** a) % 37”. Bob sends B. If B is 1, the session key is… wait for it… 1. If B is 0, it’s 0. No matter what Alice’s private key is.

If Eve sees a public key that works out to 0 or 1 mod p, Eve knows what the session key was; it’s zero or one. Remember that there are infinitely many values that work out to 0 or 1 mod p. 0 is 0 mod 37. So is 37. So is 74. And so on. Bob could have sent any one of those bad public key values.

Alice and Bob are supposed to check for this. Adam looked at a bunch of IKE implementations. None of them did.

context

This is a well-known problem. It’s in Eric Rescorla’s DH RFC. It’s in an ANSI standard. You can’t use p - 1 mod p either. You also have to be careful with g; broken values will generate subgroups, not the entire group. And real DH implementations have optimizations that can be attacked mathematically if you’re not careful.

Just because it’s well known doesn’t mean people won’t make the mistake. That’s why Nate and I pointed the problem out last year (almost to the day!).

The general class of problems we’re talking about is parameter validation. You attack them by looking at the messages a protocol exchanges, and sending malicious bad values that will break the computation.

Are you a security researcher? Go look for some of these bugs. They rock. More in a sec.

but back to adam

So it’s interesting that IKE implementations don’t validate parameters, but it’s not particularly meaningful.

IKE Bob can send IKE Alice a bad public key. This key will cause Eve to know the session key Bob and Alice use. But why would Bob do this? He’s negating his own security!

Eve can try to inject a bad public key into the session. But so what? If Bob and Alice don’t agree on A and B, the public keys, they can’t run DH. Maybe a different attacker, Mallory, can get between Alice and Bob and proxy the messages. She’ll be a “man in the middle”.

In this case, Mallory wins. No matter what parameters you use and what bugs your code has, Mallory beats DH. This is a basic challenge with DH. The solution involves more crypto.

DH is a useful building block, but protocols that use DH usually depend on some other operation to ensure security. For instance, DH SSL uses RSA certificates to beat Mallory. DH is useful to SSL; it gives you perfect forward secrecy by not tying your SSL session key to a fixed RSA key that can be compromised. But DH SSL depends on RSA for security.

So it’s not a good sign that IKE implementations aren’t smart enough to do parameter validation. But it doesn’t make much of a difference. The “vulnerability” allows an IKE participant to elect an insecure session.

accident? or… murder!

Adam wants to take this somewhere. So he writes a blog post suggesting that the uniform weakness of IKE implementations could be evidence of a conspiracy.

I don’t think he’s being entirely serious, but here’s his argument: the NSA —- no wait, it’s 2007, let’s make it the RIAA —- demands the ability to snoop on everyone’s IPSec sessions. They get all the IKE vendors to ship backdoored IKE agents. On some secret signal, the IKE agent will send public keys that work out to 0 mod p, and the RIAA can break these sessions with the sniffers they’ve installed at every exchange point on the Internet.

There’s a reason this is silly besides the fact that it involves backdooring one of the least important security mechanisms on the Internet: it’s a dumb attack.

Mallory knows p and g. So does Seth, the secops guy. Mallory can watch for A and B values that are 0 mod p. So can Seth. Why would the RIAA install a secret backdoor you could write an IDS signature for?

There are much more subtle things you can do to backdoor DH. Start with, IKE implementations can just be backdoored with a known private key value, or a root backdoor private key and an algorithm for generating variants of it. Move on from there.

This isn’t a conspiracy. This is just ignorance.

and I know that because…?

Because this vulnerability happens all over the place.

Take SRP for example. SRP is a derivative of DH. Alice is a client, Bob is a server. Alice and Bob know Alice’s password. Alice generates a public key that is related to the SHA-1 hash of the password. Alice and Bob do a DH exchange to prove Alice knows the password, and if the exchange works, Alice wins.

Mallory sends Bob a public key of 0 mod p. Mallory wins. She can log in as Alice without knowing Alice’s password.

This vulnerability is well known. It’s in the RFC for SRP. But I’ve tested SRP implementations written by smart security people, and they’ve had this vulnerability. (Due credit: I got this trick from Trevor Perrin, via Nate Lawson).

Compare the SRP vulnerability to the DH vulnerability. The SRP parameter validation problem is really, really bad. It’s auth bypass. The DH vulnerability is just a dumb way to backdoor an IKE agent.

well played, adam

IKE is a mess of a protocol. Crypto parameter validation attacks are totally underappreciated. Adam’s blog post is cool. It was smart of him to check for this, and interesting that he found it.

and what have we learned?

Not much about IKE. It’s as secure as you thought it was before you heard about Adam’s finding.

Hopefully a lot about crypto, though. Like I said, we wrote a post last year talking about parameter validation tricks for DH, SRP, Elliptic Curve, and RSA.

Forget about algorithmic attacks and advances in factorization and quantum computers. Parameter validation attacks are a systems flaw; systems depend on code, and code is riddled with bugs. All bugs are vulnerabilities. Most… any? cryptosystems will be beaten by stupid bugs like this.

Go look for them!


[1]: g is a primitive root modulo p. For values of x from 0 to p - 1, raise g to x modulo p. If g is a primitive root modulo p, you’ll end up with every number between 1 and p - 1, in some order. For instance, the following Ruby snippet asks if 3 is a primitive root mod 37.

lst = [] ; 0.upto(36) {|d| lst << ((3 \*\* d) % 37)} ; lst.sort

elicits the following output:

[1, 1, 1, 3, 3, 4, 4, 7, 7, 9, 9, 10, 10, 11, 11, 
 12, 12, 16, 16, 21, 21, 25, 25, 26, 26, 27, 27, 28, 
 28, 30, 30, 33, 33, 34, 34, 36, 36]

2’s missing. So’s 5 and 6, etc. 3 is not a primitive root mod 37. Now try 5:

lst = [] ; 0.upto(36) {|d| lst << ((3 ** d) % 37)} ; lst.sort

[1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 
 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 
 29, 30, 31, 32, 33, 34, 35, 36]

All the numbers between 1 and 36 are there. 5 is primitive root mod 37.

Why is this important? Because if you’re working with a 1024 bit prime, you want session key values to possibly be any one of those 1024 bit values. Another word for “primitive root” is generator. Generators generate the entire group of values mod p. Bad values of g generate subgroups, with fewer than 1024 bits of possible values. The worst g values generate only two possible values!

Reader Comments (13)

Are you sure that second expression is going to test whether 5 is a generator? :-).

October 15, 2009 | Unregistered CommenterDave

Although quite some time, I consider this a complete info worth the read although it sounds too technical but the issue has been well said with matching "conversation like" explanation. The main point here is the word Security in all aspects of your dealing. valentines day gifts delivered

February 5, 2010 | Unregistered CommenterJennie

The IPsec working group had a simple and clean key exchange protocol called Photuris written by two brilliant people with a history of writing bulletproof protocols and RFCs. But the leadership of the WG had a personal issue with one of the authors, and the WG scrapped Photuris. They then put together a far less experienced team (in terms of protocol authorship, that is) that developed and rammed through the ball of warts we now call IKE.

Committee-think at its best.

March 8, 2010 | Unregistered CommenterBorderline_ADD

lv owners, please listen up. I am spotting a lot of louis vuitton out there that are being misused and mishandled. These precious Louis vuitton bags should be handled like newborn babies. With a gentle touch and lots of love. louis vuitton handbags are some of the most luxurious of all handbags. You have to appreciate the hard work and craftsmanship put into each Louis item.

July 1, 2010 | Unregistered Commenterlouis vuitton

Free download iCoolsoft PPERFECT STRANGERS
to 3GP Converter and easily enjoy PPERFECT STRANGERS DVD
movies with your mobile phone on the go. The PERFECT STRANGERS DVD COLLECTION mailing list is a good source for further information.

And if you accept a replica Chanel handbags
on your arm again you will be able-bodied accepted. Chanel is accepted for abundant Chanel handbag
, however if we were to name the face of Chanel again it would be the Chanel archetypal Chanel
.

July 4, 2010 | Unregistered Commentercollections dvd

It can also rip and convert RHODA
movies to 3G2, MPEG-4, H.264. ICoolsoft RHODA DVD
to 3GP Converter enables you to customize all video/audio encoding settings like Video Encoder.The image directory eventually will hold the completed RHODA DVD COLLECTION
.

Chanel Wallet
are fabricated actual well. China is a cogent architect of affected and Chanel handbags
. Out of all of the replica Chanel handbags that are accessible on the bazaar now.

July 4, 2010 | Unregistered Commentercollections dvd

It can also rip and convert RHODA
movies to 3G2, MPEG-4, H.264. ICoolsoft RHODA DVD
to 3GP Converter enables you to customize all video/audio encoding settings like Video Encoder.The image directory eventually will hold the completed RHODA DVD COLLECTION
.

Chanel Wallet
are fabricated actual well. China is a cogent architect of affected and Chanel handbags
. Out of all of the replica Chanel handbags that are accessible on the bazaar now.

July 4, 2010 | Unregistered Commentercollections dvd

Microsoft MCITP practice exams are just the MCSE beginning. With each exam you will see real Microsoft MCITP practice questions giving you the ultimate Microsoft MCITP MCSE Exam preparation available online anywhere. Where else can you find an Microsoft MCITP study pack with so many MCSE Exam possibilities? 70-620 Exam

July 8, 2010 | Unregistered Commenterliuhan

Just gone through your blog and found it wonderful. It was nice going through your blog. keep on posting.

July 12, 2010 | Unregistered CommenterHampers

Just gone through your blog and found it wonderful. It was nice going through your blog,

August 3, 2010 | Unregistered CommenterHampers

Nike Rifts
Nike Rift
nike air max
nike air rift
nike air rifts
nike rifts men
nike air max skyline
nike air max classic
nike shox rivalry
air max 90
nike air max 90
Air Max Skyline
Nike Dunk Sb
Nike Free Run+ Men
Nike Air Rift Women
Nike Shox
Nike Kid Shoes
Nike Air Max 1
Nike Air Max 87
Nike Air Max 180
Nike Air Max 2003
Nike Air Max 2009
Nike Air Max 93
Nike Air Max 95
Nike Air Max 97
Nike Air Max Classic Bw
Nike Air Max Light
Nike Air Max 88
Nike Air Max Ltd
Nike Air Max Tn
Nike Air Rift Men
Nike Air Max 90 Kids
Nike Air Max TN Kid
Nike Air Rift Kid
Nike Shox R4 Kid
Nike Shox NZ
Nike Shox OZ
Nike Shox R4
Nike Shox Rivalry R3
Nike Shox TL
Nike Shox TL3


nike rifts
nike rift
nike air max
nike air rift
nike air rifts
nike air force
nike air jordan
nike shox
nike shox rivalry
air max 90
nike air max 90
Nike Air Rejuven8
Nike pas cher
Rift Nike
Nike Air Max Skyline
Air Max Skyline
Nike Rifts Men


Nike Rifts
Nike Rift
Nike Air Max
Nike Air Rift
Nike Air Rifts
Nike Air Force
Nike Shox OZ
Nike Shox R4
Nike Shox Rivalry
Air Max 90
Nike Air Max 90
Nike Air Rejuven8
Nike pas cher
Nike Air Rift Femme
Nike Air Max Skyline
Air Max Skyline
Nike Air Rift Homme


ED Hardy
ED Hardy Clothing
Christian Audigier
ED Hardy Accessories
ED Hardy Bags
ED Hardy Handbags
ED Hardy Belts
ED Hardy Sunglasses
ED Hardy Kid's T-shirt
ED Hardy Kid Shirt
ED Hardy Kid
ED Hardy Man
ED Hardy Active Wear
ED Hardy Man Wear
ED Hardy Hoodies
ED Hardy Outerwear
ED Hhardy Man's Hoodies
ED Hardy Long Sleeves
ED Hardy Man's Sleeves
ED Hardy Shoes
ED Hardy Man's Shoes
ED Hardy T-shirts
ED Hardy Man's T-shirts
ED Hardy Swim Trunks
ED Hardy Man's Trunks
ED Hardy Women
ED Hardy Bottoms
ED Hardy Women's Bottoms
ED Hardy Women's Hoodies
ED Hardy Women's Outerwear
ED Hardy Intimates
ED Hardy Lingerie
ED Hardy Women's Sleeves
ED Hardy Sandals
ED Hardy Women's Sandals
ED Hardy Women's T-shirts
ED Hardy Swimwear
ED Hardy Bikini
ED Hardy Tanks
ED Hardy Women's Tanks
ED Hardy Knits Tops
C A Women
C A Man

August 12, 2010 | Unregistered CommenterED Hardy Belts

Christian Louboutin On Sale Market sales Christian Louboutin has boutiques in Paris, United States, London, England, Australia. In Asia, the first Christian Louboutin Boots boutique was opened in October 2007 on On Lan Street in Central, Hong Kong.The red outsole is the distinctive features of?Christian Louboutin Flats , also is the female of gentle, lovely, beautiful and sexy logo.And you've found the world's most comfortable Christian Louboutin Sandals,just from here.In the 1980s,Moncler Kid's become unprecedentedly popular all over the world.Yes, that isMoncler.In fact, after 50 years development,Moncler has already become an international brand together with LV, Channel, Gucci and other famous brand.Today, owning aMoncler Jackets Vest is numerous Youngman's dream. Imaging one person wears a Moncler Accessories,he or she will become the focus of attention.No matter what kind of dress you like, you can have a look atHerve Leger bandage dress.Ladies who love beauty may choose Herve Leger bandage dress, you will find what you are looking for is in 2010 new style Herve Leger Strapless. There have a chance for you to shop on 2010 new styleHerve Leger Strapless sale online store, to catch the fashion wind.Hermes handbags is one of the best handbag brands in the world. For more than 100 years,Hermes birkin makes its handbag by the traditional European technology of handicraft, which is also a platform for many craftsmen to realize their dream.Hermes Kelly knows the principle that less is more, so although HERMES Kelly 22CM Bags is a century for mass production,HERMES PURSE keeps on its traditional manufacturing system, which helpsHermes Purse and Other rank high among the worldwide famous brands.?

August 28, 2010 | Unregistered CommenterChristian Louboutin

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>