Has anyone of you heard about the OpenSSL Debian bug? What? Sorry about our English. We know it's pretty poor. It's pathetic. The word is pathetic. According to the dictionary, it's pathetic, the word. Let's go again. Has anyone of you heard about the Debian OpenSSL package bug? How many of you? How many? Well, a lot. This will be easy. So, I start with a brief introduction and some history about how the bug was introduced in OpenSSL and how it affected this package and cryptography. And then, Luciano will show the most funny part, the live demo, and maybe even how to conquer the universe. So, let's go. Which he became a master of the universe. So, this bug was caused by a Debian-specific patch introduced almost two years ago and remained unseen until this year, a couple of months ago, when our friend Luciano discovered this problem. This problem that affected the random number generator in OpenSSL in Debian. This bug affected not only OpenSSL, but the underlying library, liveSSL, and every packages that linked against this library. Not only did it affect Debian distro, but any other distributions that are based on Debian, Debian such as Ubuntu. It also affected other, or may have affected other operating systems which are, although not based on Debian, may have imported wikis into them. So how did it affect the random number generation? Well, in fact, the entropy got reduced to just 15 bits. So the key space, any random number generated had to be inside this very little key space of just 15 bits. Other aspects, other features we should bear in mind that limit the key space are the platform, that is the architecture, and the endianness, little endianness. Big endian, big endian, 32 or 64 bits. And the length of the keys, for example, if they are 1024 or 2048. And well, these are just some examples of cryptographic schemes that got affected by this bug. As you may know, cryptography is heavily based on random, secure random numbers, so this bug affects all of them. These are some of the affected packages, which are linked against libSSL, either dynamically or statically. And some of them were showed off in some other presentations, such as OpenSSH and Tor. So they all relied on the security and unpredictability of the random numbers. So, how did this start? It began, as I said, two years ago, when a Debian user submitted a wishlist severity bug to the Debian backtracking system about some uninitialized variable warning that was being printed by Bidegreen. Bidegreen is an online debugger that checks for memory leaks and something like that. So, we show a brief demo. . Sorry. . . . . . . . We have here a program that just requests some random bytes into a from OpenSSL and prints them. It's just that. So, can you hear? Yeah. We compile it and link a variance libSSL to SSL. We see it's linked. And let's try it. It prints just random numbers. So let's see what this user was complaining about. We'll just link with the original version of OpenSSL, that of two years ago. And we're running with Valkyrie, just to check for any problems. So we can see here many warnings about initialized variables. Quite a lot of errors. So this is what the user was complaining about. In fact, it affected every package that linked against libSSL. So the Debian maintainer analyzed the source code. And just find out that it was due to just two lines of the OpenSSL source code, which are these two lines, which are identical. They are syntactically identical, but they're in two different functions in different contexts. We should notice that the second line is surrounded by... Ryan? We should Ryan? Ryan? Okay, so... Maybe we should Ryan. I'm not sure. Who puts the fight alarm? Okay. Do you look calm? That's good. I am not calm. That's fine. You look calm. No, I'm not calm. That's fine. Okay. Okay. They hacked our presentation. Should we continue? What did he say? He's checking. Be careful. Sorry? Okay, I try to continue. It's pretty hard. Oh my God. There's people clamping, so... The exit is over there. Stupid. Epic fail. It smells like sabotage. Oh, it's good. This is not the light button. This is the alarm button. Please don't touch it. Gosh. What should we do? We can't speak over there. We can continue. It's quite confusing. Stop it. Okay. If it happens again, should we do something? We have water here. We can use it. Okay. Okay. Let's go. Mom, I'm okay. Are you looking at me? I'm okay. So, where were we? Okay. So, these two lines. These two lines are the ones to blame for these uninitialized variable warnings. But we should notice that the second line is surrounded by this macro. It's about other debugging tool, very like Vibrant, that's called Purify. And this is just the original source code from OpenSSL, so that this line may get into the... binary program or not, depending of the compilation options. So, let's continue. There were several proposals or solutions to this problem, but the most... the most... the one that looked most suitable, thanks, was the... the... the option, just to comment out these lines, because... oh, sorry. They're adding just... what these lines are doing. They're... er... in some cases, they're er... taking this parameter, the buffer, both as input, and as output. They take the input from the buffer, add it to the entropy pool. So, when the buffer was. uninitialized, the... the. and the warning was being printed. So, in fact, this entropy added by some initialized variable is almost negligible, so it looked like a good idea just to comment out these two lines. So, the package maintainer asked to the OpenSSL mailing list about these two lines and the answer from an OpenSSL developer was that it was okay just to comment out those two lines for the buying purposes, because they didn't add any significant entropy to the entropy pool. So, okay, this is the most famous patch lately. It just commented out those two lines. But, how did this affect the random number generator? You remember the function we just saw a few minutes ago? It was runbytes. When a user wants to get a random string, it calls this function, runbytes, with a buffer, which is both input and output. So, this function takes some entropy, almost negligible from this buffer, and when the state of the random number generator hasn't been initialized, it calls the runpol function, which takes care of this, taking or adding entropy from several sources, such as the system random device, the user ID, and the buffer. The process ID, the process ID, and the current time. This is all through the runadd function. Finally, we got the process ID again, just in cases for multiprocess, and forking, just to avoid the collisions in the random number generator. So, here is the result of the, it's commenting out, but, the second line, that which was surrounded by the macro, we saw it doesn't add any significant entropy, so it's not a big deal. The problem relies on the first commented outline, which affected the runadd function, so in such a way that, okay, in such a way that none of this entropy is affected, the entropy sources, or randomness sources, were read into the entropy pool, and as a result, the only source of entropy remaining is the current process ID. This is what limits the entropy to just 15 bits, which is the maximum process ID of the system. So, we may wonder why this, the second line was commented, which has this effect. Well, in fact, with the Debian developer, tested the OpenSSL with Bygreen, just running the OpenSSL regression tests, and in many cases, the runadd function is called directly, that is, not from runbyte function, for example. So, in this function, which is OpenSSL API, which loads some entropy, or some randomness from a file, as the comment says, there may be the case, when the buffer, we're using more bytes from the buffer than those read from the file, and in this case, Bygreen will print the warning, too. So, okay, so, this is time to get to the funny part. Do you get this part? The third parameter of the runadd function is how much entropy is adding to the PRNG statement. And as you can see, the number is only i, which means only the part have you read. So, the initial values are not taken as entropy, in that case. I mean, they are valuable as zero. So, that's mean that the entropy by initialization memory is negligible, that's why. So, let's see. Let's see how can we take advantage of these problems. Well, as Maxi says, random numbers are everywhere in cryptography, so we will see few scenarios when we can exploit this flow. The first one is authentication by challenge, also known as powers-less authentication. How many of you are familiar with this concept? Okay, we will be quickly in this part, yeah? The client generates a pair of key, randomly. When the client wants to create, when it wants to log in with a powers-less authentication, the server creates a random number, they cipher with the public key, they send the challenge, the clients decipher the challenge, get, again, the random number, and sends to the server the challenge response. And if it's okay, access granted. Yeah, fixed with your concept? Cool. So, let's introduce another character. It's a hacker. You know, the hackers use common lines, so that's why. And this hacker uses really big fonts. I don't know why. Okay, this hacker, notice that the client generates this pair of key, these ones. I'm not sure if you can see the arrow. This one pair of key was generated by random, and was generated in an unsecured Debian system. So, there's a limited space for this key pair. So, the attacker creates all of the possible keys, which is two, which is two to power 15. And try with the first one, try with the second one, trying to challenge, to respond to the challenge. Sooner or later, the servers will grant the challenge because one of that pairs will be exactly the clone that use it by the client, yeah? So, this is really, really easy to get. I mean, it's not rocket science, but any of you didn't see this problem? Okay, let's see an example. Let's see. Let's see. Okay, hdmoor provide us a lot of the complete space for all SSH keys. It's available in his website, for example. In this case, we have the spaces for the 124, 1000 keys. We are going to have 124 and 2048 length, for example, for the two... As you can see, it's a really small space. I mean, you can get many of these ones. Let's see how we can try it. We have made a little script called exploiter, which is a rhetorical script. really simple script. As you can see, the script tries to, with each pair of key, tries to get login to the server. So let's try to see how it's working. Of course, you should know the user. For example, and let's try to, a random server, I don't know. What, w-o-p-r? Okay, let's go. And the port, probably is 22, so let's run. Well, let's see if it's, this works. As you can see, all the, all the, all the keys are the fingerprint, and the number, which is the PID, use it for create that pair. Oh, how nice. So, you know what, what an alarm is, you heard it. So, should we run this script? I mean, push red button, it sounds. No. Yeah. Okay. Oh, gosh. Where's the alarm? Yes? Yes? We shouldn't. We shouldn't. Well, it's, the script is not working well, but you can die with a bash script, I mean. Okay. Let's continue with this silly thing. Okay. Well, this is the first attack. It's a really simple attack. I mean, you, you, you can literally be in a script key, because it's a script, so you can use it. So, let's continue with the other one, but this one is really simple. I mean, let's, let's see how to attack Diffie-Hellman. How many of you are familiar with Diffie-Hellman key exchange? Okay. Good. So, Diffie-Hellman, you know about that. Yeah? Too, too many math for you? Okay. Both parts selects random number, and after some math magic, they get a shared secret. It's something simple. I mean, let's see. How many of you are familiar with Diffie-Hell, ephemeral Diffie-Hellman? Okay. I, I can teach you something new. No. It, the ephemeral Diffie-Hellman is just like Diffie-Hellman, but you should discard the private exponent. Yeah? So, after the key exchange, you discard the private exponent. If an attacker take control of one of the parties, they can't, he can't recalculate the shared secret. Yeah? Well, let's begin. No, no, no, no, no. Oh, come on. Okay. So, So if you want to decipher the communication, you should go against k, which of course is a really big number, so you need to brute force it. But in this case, probably you see the problem. In this case, the x, the private exponent, are random. So if those keys were generated in a vulnerable Debian system, we can look for all of them. So let's see how this works. So we just generate a list with all the possible x, and we try to get the private part of one of the parties. So if we get the private part of the client, that means that we get the x for the client. And if we can get the private part of the server, that means that we get the x of the server. Notice that even if one of the... If one of the parties are vulnerable, you are able to recalculate the share secret. That's something interesting. So we have a demo here. Okay. This is a Wireshark. Probably you are familiar with it. Maxi, me, and Paolo. Paolo is that guy who's looking for a show. If you have a show for him, please contact me. So we made a modification to the Wireshark in order to decipher... ...a SSL and TLS connection with a Diffie-Hellman. With a Diffie-Hellman. So, for example, in this case, the cipher suite was used with Diffie-Hellman ephemeral. That means D-H-E. Diffie-Hellman ephemeral. So as you can see, the connection is ciphered. I didn't notice. Okay. The... And, of course, you can decipher it because it's ciphered, of course. But if one of the parts is vulnerable, you can look for all the possibilities. So we go to Preference, Protocols, SSL. And this box, this is a new box, was created for us. Let's see if I have the... Nope. Nope. Nope. Nope. Nope. Nope. This file contains all the possible X. Yeah? The all possible X can be in two lengths. Can be 64 lengths or 128. 128 bits. Yeah, of course. We are talking about the length. Yeah. Bits. Bits. So that's why the... That's... These kind of lines. It's true. Two power 16. So that's why it is. So we... We put this here. And this here. Yep. And press OK. In this moment, we are trying to brute force the connection looking for one of the public keys. That's why it's taking a while. In fact, it looks like hanging, but it's not. It's working. Believe me. Oh, there it is. So, okay. And... There is the connection deciphered. Thank you. Thank you. Thank you. Don't thanks me. Thanks, Kurt. Kurt is the... Okay. It's okay. It's the guy who comments the line. Fuck. He's gonna kill me. Okay. Well, that's... As you can see, this is a really big problem. I mean... You can... You can do the same thing for SSH. So if you transfer secrets with SSH connections in the last two years, you should note it that you are compromised a lot. For example, if you copy your private PCP over SCP and no passphrase there was not ciphered symmetrically, in that case, your PCP is compromised, too. Sorry. So, as you can see, it's a really big problem, yeah? Continue. And another scenario, and this one is really, really, really... I don't know. Really strange scenario, but it's really funny, too. It's DSA. How many of you are familiar with DSA? Digital Signature Algorithms, I think. Again, sorry? Oh, many. Many of you. Cool. Well, that's good. More math. Sorry. Okay, there are as many as you know. There are as many valuables, public valuables. There's P, G, which are primes. G is a generator. Y is the public part. X is the private part. And if Alice wants to sign a message M, she needs to calculate two numbers, R and S. As you can see, in this part, the only purpose of R is to obfuscate the X, which is the private part, yeah? And R only depends on K, which is a random number. Of course, you are seeing the problem now. If a message is signed in an unsecure environment, in a weak environment, in a vulnerable deviant, in that case, you can recover the X. You just make some math workout, and it's magic, and you can isolate the X. I'm not sure if the correct word, but you can put the X alone in one part of the equation. And of course, as you can see, S, it's a public value. K, it's a value which, what we're enforcing. The hash of M, of course, you should know it. And R is the public value, of course, Q2. So you can calculate the X, which is the private part. That means, even if, if DSA key pair was generating in a secure and safe system, if that pair had been using in an unsecure system, then your pair is compromised, too. Sorry, again. So, can you see this? No? Somebody said no? Say it slower. No? Okay. Yes. Yes, yes. Yeah, go, yeah, let's go, let's go, finish it. Okay. So, we have a really, really good scenario here. I mean, Debian is the universal operating system, so we can conquer the universe. Yeah, as Maxi says. We can do it in five single steps. Of course, we should choose an application. Can be SSH, SSL, whatever. You should see what algorithm is using. For example, if an SSL connection, if you had a pickup of the last two years, maybe you work for the NSA, and you have all the pickups in the world. That would be great, in that case. It's not great. The way it's not great, but. You see, you need to see which algorithm is using when you decide in the cipher suite. Then you should generate all the possible key. That means two to the 15th key. 15th, minus one, because open SSL cannot run as init, so you can save one of the keys. Times three. Why times three? Because there's three combination with Indianness and bits. I mean, Debian runs in 32 bits, little Indian, 32 bits bigger Indian, 64, little Indian. I'm not sure if I said it in the correct way, but that's three combinations. Combinations, so you should generate all the keys. Of course, if we are going to conquer the universe, you should conquer all the platforms, so that's why you should multiply by three. All this space can be something really easy to generate. In a few hours, you can generate all the possible keys. And then you should brute force. There are many options here. You can authenticate yourself using asymmetric keys. As we see, you can contact the whitehouse.globe and try to brute force him. In this case, you need a quick public key on a server. So it's a possible situation. You can do a man-in-the-middle attack in the same way that we generate. You can generate all the clones of the pairs. You can generate many clones for RSA certificate. So you can create a phishing situation or something like that. Of course, in this case, you need to create a man-in-the-middle scenario. You know, that is really hard. You need a multi-vendor DNS bugger. You need to poison in caches. It's really hard. You didn't go to the damn talk? Okay. It's tomorrow. It's tomorrow? Tomorrow. Oh, tomorrow is the damn talk. So that's why you are not laughing. Okay. He was in Black Hat, too. I have news for you. Internet is going to be exploding these days. Because I'm going to be talking to you. Because this little problem with DNS, where are you living, in a tupperware? You should know this one. Okay, let's continue. Yeah, if you, probably Dams wants to give you the surprise tomorrow. I am so stupid, but okay. Don't tell him. Don't tell him, don't tell him. Yeah, another scenario, possible scenario is the cipher connection, made it with one of the parts vulnerable, just as we did with Wireshark. There's many other tools you can attack SSH to. In that case, you need one of the parts outdated, which runs a Debian vulnerable in this moment. At least, you captured traffic in the last two years. Maybe don't. That's actually... There's an agency that made these kind of things. I don't know. Maybe if you didn't know the Dan problem, maybe you don't know about these things, so I am noticing you. Another problem, another scenario, possible scenario is attack cipher symmetric encryptions, storage or connections. You know, in many cases, when, for example, in a storage, if you want to cipher in a storage, you create a random key, which is symmetric, in that case, you should need to create all the possible keys and just decipher it, something like that. Many, many backup systems are vulnerable to this flaw in that way. And, of course, as we see, you can attack the DSA private part, there are tools made in this. We want to give you the URL in the... Next slide, I think. In that case, you need a message signet in a weak system. That means that the non-reputable... I don't think it's... Reputable means something for you? Non-reputability. Reputable. Okay, that's a strange word. Non-reputable? The property of non-reputable? Non-reputable was losing in DSA. Reputable? Repudiability. Repudiability? Oh! Thank you, James Bond. And, of course, the last step, ensure your power. Okay, that is the related work. The first one is the open... The HD Moore tools, which has the... All the key spaces for SSH. You can download there. There is many left, so you don't need to calculate them. The second link is our patch for Wyshack. The third link is a Ben Snort plugin to detect communications using weak... Weak Diffie-Hellman exponent in SSH. So you can get an alert. You can get an alert if one of the parties are running weak, okay, weak, weak keys. So, Ben, are you here? No. He ran with the final alarm, I think. Or maybe with the rocket issue. The third one is SSH tools. That's... In that link, you can find ways to decipher SSH connection when one of the parties are vulnerable. And in that link, you can find a tool for get DSA parts with a sign-in message in a weak environment. The other, the Firefox SSL blacklist add-on, it's a plugin for Firefox in order to detect if you... When you are connected with an SSH server, if there's a certificate, it's blacklisted. You need to install two extensions there. One is the... The extension for check itself. And the other one, it's the database with all the blacklisted certificates. The other, the open ID devian PRNG DNS cache poisoning advisory, it's from yesterday. I mean, tomorrow we... I think we get pranked. But we found this, and we decide to put it anyway. Nowadays, since yesterday, you can't trust in open ID anymore. Sorry. If you combine the problem with the PRNG, that means clone certificates, with the DNS cache poisoning, with the Kaminsky problem, open ID can be fakeable. That's why... That's because open ID is fake. Open ID doesn't use CRL, certificate location list, CRL. So, when... In fact, nobody uses CRL. When... Not nobody. How many of you are Windows Vista user? So, you are the only one who use it by default. Sorry. Yeah. Yes, please, please. Yes. You're safe. Yeah. The other ones should install by hand, but the only people who have CRL by default are the Vista users. You have other problems, but you are safe in this case. And the last link is the devian wiki where you can find all the packages affected and how you should regenerate the keys for each package. So, let's continue. So, some countermeasures. Countermeasures. Of course, you should read the devian wiki for more details, but one of the countermeasures is update libsl. Of course, if you are a devian user, how many of you are devian user or derivates? Ubuntu, Kubuntu, or something like that. Okay. But probably most of you do an upgrade daily. I see some faces like... Okay. In that case, you should upgrade it. The other problem, the other countermeasure is look for compromises keys. Devian provides you a nice tool to do that. I can... Maybe I can show you. It's called ssh-boolkey. I don't know if you are familiar with this tool. The devian users. Are you... You are not familiar with this tool? Okay. Well... Dump up. Okay. Okay. That's good because you are learning something. So... Let's see. For example, in this case, there are some compromises keys here. For example, this one, which is host compromises, as you can see. There are some ones that are not blacklisted, so it's safe. This checks for your... Of course, this is on purpose. I'm not using compromises keys. Cool. In one of the case, it's unknown. I can't find it. Okay. But let's go on. So, you know this tool now. You can write like this. And you can check all the keys on your system. Of course, you need to be rude because you need to read it. Okay. Let's continue. Well, you should look for weak keys even if you are not a devian user. Maybe one of your devian users export to your system weak public keys. So, in that case, you have a hole in your system. I mean, a really big hole. You can put some... A little elephant in that hole. You should regenerate all these keys if you use it in an affected devian system. Of course, you can mitigate the problem with Firefox, with the blacklist add-on. This is... It doesn't work in all the issues, but let's leave the details. And if you are a devian user, if you are running a Sage server in the devian user, you can check this option in order to avoid that users with weak keys connect to your systems. Of course, all the traffic affected in the last two years, you can do nothing for it. I mean, the milk is already split. So, let's see some repercussions. Okay. These numbers are from our friend Jeren. Oh, my God. Okay. Our friend. He is German. He works in Haysec. And he... They make a survey with 100,000 web servers. They are looking for man-in-the-middle situations. So, they detect 3% of the servers of the people who have a SANE-ed CA are running weak certificates. This is a number from two weeks ago... Two weeks after publications of the advisory. So, if we extrapolate this number to the global numbers, maybe 24,000 weak certificates are running these days. Combine this with the DNS problem, and you will get a perfect phishing situation. So, another repercussions on devian, of course. I am the devian developer. This problem touched my deep feelings. We get the pony award there. We won the pony award to the most epic fail. We have it here. Say hello to the pony. There are some things that you should know before criticize us. One of these is that devian needs to patch the systems. I mean, all the distribution patch software. That's because in most of the case, upstream has not the same goals than the distributions. In this case, for example, for open-cell, it's not something big to have by green problems. In devian, this is something really huge. So, that's why the problem starts. In some case, upstream is hostile. Hostile? I think the word is hostile. I mean, they are bad guys. No, not bad. Bad. Not friendly. Not friendly. Yeah. Well, open as I said. Guys are from the BSD school, and they are not friendly guys. So, of course, we can audit all the code because it's a lot of Linux code. So, let's see. Devian is working on visibility. Do you know about the Linux law? How many of you know the Linux law? The Linux law says, given enough eyeballs, all the bugs are shallow. So, we are working on create many eyeballs. So, we are working on visibility. So, many eyeballs will see the code. In that case, we are trying to get public the version control systems for all the sources. Okay. Working on patches.devian.org. Which will be a place where the patches will be there. The issue here is maybe it's not a technical problem. I mean, maybe the upstream has not an easy way to see the patches. Maybe it's a policy problem. The developers are not obliged to public the patches. Maybe it's a social problem. Maybe we should be more friendly with our co-developers. And we should ask in better ways. And that's... Maybe the problem is in the conjugation of all that sets. So, let's see some conclusions. We are hurrying, as you notice. The first problem here is review twice, patch once. If the devian developer follow the data flow problem, he will notice that the only part where buff is touching, it's there in the line in comment. So, the problem is... If you notice that run add don't add nothing, that's a problem. So, another issue is don't write fancy code. I mean, if unaccelerated memory doesn't contribute with something substantial, so don't do that. Of course, make a lot of comments on your code. That will be good. Ask with details. The devian developer... The devian developer just asked with few lines. You should put the context of the line. You should put what are you trying to do. If many people complains about something, maybe it's something huge. A lot of people complains about binary problems in OpenSSL in many... from many years ago. In fact, one year ago, a frequency-hacking question is why OpenSSL has a lot of warning problems. In the background. Of course, another... Another first... Another big issue here is... Open source... And I'm... And I'm an activist of OpenSource. But OpenSource doesn't complain the Linux law conditions per se. That means OpenSource doesn't mean a lot of eyeballs. How many of you are activists of OpenSource? Well, many of you. Okay. So, it's not enough with OpenSource. You should see the code. So, that's... That's what that line means. That... Here is the thanks. And, of course, we are answering question in room number... 105, down this corridor, straight across the hallway. 105. Okay. We will listen your insults there.