[00:00.000 --> 00:08.680] Our next speaker is Guy. I'm not gonna try to pronounce his last name. He told me not to do [00:08.680 --> 00:16.980] that. Okay. He's B-Sides Tel Aviv chairman and CTF lead. Also a public speaker and [00:16.980 --> 00:24.020] recipient of the Cisco Black Belt Security Ninja. That's nice. With nearly 20 years of [00:24.020 --> 00:31.620] experience in cyber security industry. Currently providing security services. Focusing on OS, [00:31.620 --> 00:39.100] hardening, crypto, AI and reverse engineering. And he's going to talk about crypto failures and [00:39.100 --> 00:43.120] how to avoid them. Give him a round of applause please. [00:47.370 --> 00:53.350] Thank you very much. Can you hear me in the back? Because I tend to walk about so I'll take the [00:53.350 --> 01:00.250] mic. But if not I'll just speak very loudly. Okay. So welcome to my talk about crypto failures. [01:00.250 --> 01:05.590] Before I begin I just want to say one thing. I'm not dissing anyone who's actually developing and [01:05.590 --> 01:11.490] using crypto libraries. But I do want to point out several failures that I have seen happen over and [01:11.490 --> 01:16.250] over again. And try to give you those patterns and some tools and some ideas of what to do when you [01:16.810 --> 01:22.250] encounter such issues or such things. But I also wanted to make this talk let's say entertaining [01:22.250 --> 01:28.510] and show you a couple of well at least for me and probably for others pretty funny failures. Some [01:28.510 --> 01:44.420] of them of very large extent. So said so. Okay. This should work. Okay. So as I was so kindly [01:44.420 --> 01:52.460] introduced I'm besides Tel Aviv chairman I also do the CTF. I invite you all to come to us to [01:52.460 --> 02:00.720] sunny Tel Aviv in June for a pretty nice conference. I'm here and I've been here for quite a [02:00.720 --> 02:05.280] while. I've seen a couple of different things in different areas. I've managed a cryptographer. I [02:05.280 --> 02:11.800] manage developers. I manage reverse engineers. And some patterns tend to emerge again and again. [02:11.800 --> 02:16.600] So I want to focus on that. The first thing and probably the most important thing is crypto is [02:16.600 --> 02:22.440] math and that kind of scares a lot of people. And I'll try to give you like a first introduction [02:23.060 --> 02:28.740] to what cryptography actually is without going into the math because obviously most people don't [02:28.740 --> 02:34.200] really care. But more than that I want you to give to get like a very at least fundamental [02:34.200 --> 02:40.400] understanding of what you should expect and when you don't see that it should light a red flag. So [02:40.400 --> 02:45.760] I'll give you a couple of examples. So you probably are already familiar with the CIA [02:45.760 --> 02:51.580] confidentiality integrity and availability concepts from other perspectives. This is also true for [02:51.580 --> 02:55.740] cryptography. So when we're saying confidentiality and talking about cryptography, it means we [02:55.740 --> 03:00.820] want to keep things secret. We want to have some sort of method, some sort of idea or function [03:01.340 --> 03:06.820] that if we know the secret, then we will know what this payload contains. And if no one else knows [03:06.820 --> 03:11.560] that secret, nobody else can know what this secret contains. Identity comes to the same thing. We [03:11.560 --> 03:15.420] want to make sure that if someone sends us the message, we can verify that we got the message [03:15.420 --> 03:21.140] from that person or that system and not from someone else. Phishing comes to mind. The third [03:21.140 --> 03:25.860] one is authenticity. Can we trust that nobody touched that message or modified that message? Did [03:25.860 --> 03:31.280] we actually get the same message that the sender sent us or was somebody messing around with it [03:31.280 --> 03:37.840] along the way? This is kind of a personal point for me, but I'm not ashamed to mention it. One of [03:37.840 --> 03:44.640] the teams I led when I was at Cisco was in charge of an area called supply chain security. So I [03:44.640 --> 03:50.360] was the very happy owner of that specific area of responsibility when Snowden releases [03:50.360 --> 03:56.020] documents. If you remember the nice image of NSA intercepting Cisco equipment and doing supply [03:56.020 --> 04:03.900] chain attacks, that was fun. And my point is, is that authenticity is important. When you're [04:03.900 --> 04:08.680] dealing with a product, with a vendor, with a library, you want to make sure that what you're [04:08.680 --> 04:15.320] getting is what actually the developer or the system actually intended you to receive. If you [04:15.320 --> 04:21.240] remember the NPM dependency issue, I don't remember, about a year ago more or less, [04:21.240 --> 04:26.740] somebody decided that he doesn't like the left line string to maintain that anymore, he kind of [04:26.740 --> 04:34.720] dropped that, everything broke. Somebody put some malicious code or stuff like that into the [04:34.720 --> 04:39.740] dependencies of NPM and now everybody got the same kind of libraries along the way. This is [04:39.740 --> 04:43.540] something you need to think about. It's something you need to be aware of. So it's an issue. [04:44.860 --> 04:49.340] Usually when people talk about cryptography, they kind of think that everything is the same. [04:49.340 --> 04:53.980] And it's not the same. When we're talking about hashes, for example, one of the common things [04:53.980 --> 05:00.520] that I hear is that I've encrypted with SHA-1 or encrypted with SHA-512. Well, not. You did [05:00.520 --> 05:07.660] not encrypt the SHA. A hash function has only one job. Taking lots and lots of information, [05:07.660 --> 05:11.580] boiling it down and getting a very short piece of information. But that's also true for [05:11.580 --> 05:19.460] checksums. So if you write CRC32 or something similar, you get the same concept. You process a [05:19.460 --> 05:28.080] lot of information, you get some validating code at the end. However, CRC32 and SHA and other [05:28.080 --> 05:32.920] constructs are not the same. Because cryptographic hashes, which is a specific type of hashes, [05:32.920 --> 05:38.140] try to give you a guarantee. They try to give you that if you change one bit in the input, you'll [05:38.140 --> 05:43.000] get a dramatically different output. More than 50% of it should be different. And if it's not [05:43.000 --> 05:48.140] the case, this is a very bad function to use. Because that means that an attacker can now use [05:48.140 --> 05:52.480] that to find collisions. Collisions meaning find a different message that will give him the same [05:52.480 --> 05:58.680] output. So short story. MD5, for those of you who are familiar with it, used to be a very common [05:59.220 --> 06:04.280] hashing algorithm way back when. And a couple of years ago in Black Hat, if I remember [06:04.280 --> 06:12.120] correctly, I don't remember her name, but a researcher from China, if I remember correctly, [06:12.120 --> 06:18.200] showed a way to find collisions in MD5. And what happened, immediately you can actually [06:18.200 --> 06:25.280] generate whatever you want to get the same kind of MD5 hash on it. Which means that now it's [06:25.280 --> 06:32.660] open for attackers to use MD5 to modify inputs or select their own inputs. And you will still [06:32.660 --> 06:38.360] think it's the same thing. It's paramount or analogous into some developer writing a library [06:38.840 --> 06:44.000] and giving you an affirmation that this is my library, I wrote it, here's my MD5 signature, [06:44.000 --> 06:48.640] and then someone else uses MD5 to give you some malicious piece of code and you will not be [06:48.640 --> 06:54.840] able to tell the difference. So just as an example, what does it look like in real life? So [06:54.840 --> 06:59.960] if we take a function, SHA1 in this example, the quick run forks, blah, blah, blah, will give an [06:59.960 --> 07:08.240] output, 2FD, blah, blah, ending in B12. Let's change one character. I change the D to a C. And [07:08.240 --> 07:13.540] you can see that the output is dramatically different. So that's the purpose of a [07:13.540 --> 07:18.700] cryptographic hash function. So if you change just one thing, it will be dramatically different. [07:18.700 --> 07:24.420] It will be very difficult to find two different sources that get the same output. Why is this [07:24.420 --> 07:29.340] important? It used to be very, very difficult to attack SHA1, two to the power of 80. That [07:29.340 --> 07:35.220] means it's a lot of compute. However, with recent advances, last year, or sorry, this year, [07:35.220 --> 07:40.400] early this year, this was reduced to the power of 68. Well, that sounds pretty tough yet, [07:40.400 --> 07:47.900] right? So if you go and spend like 100K in Amazon, you can crack SHA1. And that means that if [07:47.900 --> 07:54.880] you have, you're using Git and you're counting in Git to make sure that the commits have the [07:54.880 --> 07:59.200] right hashes and don't have like two people committing the same thing or a malicious person [07:59.200 --> 08:05.180] committing something and you get the same kind of commit, well, that's not true anymore for a [08:05.180 --> 08:10.640] SHA1 attacker with lots of money. But it might be even true in the future for other advances. So [08:10.640 --> 08:17.280] I'm not really worried about Git because that's like not a really viable attack surface. But Git [08:17.280 --> 08:23.320] had discussions to move away from SHA1 to SHA256 or SHA512 and that's probably the most common [08:23.320 --> 08:28.100] recommendation right now, don't use SHA1 anymore. Symmetric function, something you're probably [08:28.100 --> 08:33.860] more familiar with, which is a cryptographic function that given a key, you can use it on a [08:33.860 --> 08:38.780] piece of information and then it will be hidden. Use the same key again, you get the information [08:38.780 --> 08:48.000] right back. So example, take AS, AS is the currently known best practice to use for encrypting [08:48.000 --> 08:52.820] symmetric information. So I just like, it's pseudocode, but like Python notation, padded it [08:52.820 --> 08:59.320] with 21 zeros, get something. Change a bit, get something dramatically different. Why is this [08:59.320 --> 09:06.440] important? It's important because if the cryptographic function produces an output that has [09:06.440 --> 09:11.080] some sort of information in it, it doesn't look like random noise, it means that I can go ahead [09:11.080 --> 09:18.820] and break this algorithm. I'll give you an example. One of my friends, he's a master thesis, [09:18.820 --> 09:24.880] was to break an algorithm called WEP, might have heard of it for Wi-Fi. And the reason it was [09:24.880 --> 09:32.920] broken was because when you used the algorithmic function called RC4, RC4 wasn't stable. The [09:32.920 --> 09:39.140] first 1,000 or 2,000 bits coming out of RC4 had a bias. So you can guess with good certainty [09:39.140 --> 09:44.560] what was the key that produced that output if you recorded that output. So once you did that, [09:44.560 --> 09:49.720] you just record some information out of the air and now you know the key for that WEP encryption. [09:49.720 --> 09:55.880] But that's pretty bad. You want something to be very, very stable, very, very good. So AES is [09:55.880 --> 10:00.760] currently the standard and it's a good standard and you could be very happy using it. And there [10:00.760 --> 10:07.760] are other cryptographic algorithms out there to supplement it when the time comes. Asymmetric [10:07.760 --> 10:12.080] cryptography, I'm not going to go into a lot of length here, but that's what you probably all know [10:12.080 --> 10:17.160] from private public keys. Basically what they mean is that if you have a pair of public and [10:17.160 --> 10:24.280] private keys, you can give everybody your public key, they can encrypt the message with the public [10:24.280 --> 10:28.840] key that you gave away, but because you're the only one who has a private key, you're the only [10:28.840 --> 10:34.220] one who is able to decrypt that message. So hand wavingly, this is the way that works. And this is [10:34.220 --> 10:42.380] something that a lot of our internet, our data communication is based on. There was a [10:42.380 --> 10:45.740] presentation, I don't know if you've seen the Twitter storm about it, I think it was, I'm not [10:45.740 --> 10:52.460] sure if it was yesterday or two days ago, in Black Hat by a company called Time AI. They do 5D [10:52.860 --> 10:59.460] encryption with quasi prime numbers and lots of other, they enhance their cryptographic functions [10:59.460 --> 11:05.660] with music and emotions. And it was like, I could not believe that this was a Black Hat talk. So [11:06.340 --> 11:12.960] choosing like vetted, known, good algorithms is what you should do. You should not invent your [11:12.960 --> 11:20.060] own algorithms. And I'll come back to that message in a moment with some examples. So what is a [11:20.060 --> 11:25.720] signature? A signature is having some private key and using that in order to provide a proof to [11:25.720 --> 11:30.020] everyone that a piece of code or a piece of message is something that you actually guarantee came [11:30.020 --> 11:34.980] from you. So how does that work? So I'll take my message, could be my library or something similar, [11:34.980 --> 11:40.100] and I'll calculate or compute the hash of that message using the SHA-1 or something similar from [11:40.100 --> 11:46.760] before. Then I'll provide a signature. A signature is just taking a public private key algorithm, [11:46.760 --> 11:52.220] using my private key, I'll encrypt the hash. Now I have an encrypted hash that was encrypted with [11:52.220 --> 11:57.440] my private key. So I'm not giving anyone my private key, but I know that it's, I can assure [11:57.440 --> 12:02.800] someone that it's mine. How can I ensure someone that it's mine? I give everybody my public key and [12:02.800 --> 12:06.700] I give them the message. They will compute their own version of the hash because they do it by [12:06.700 --> 12:12.860] themselves, they don't trust me anymore. And they decrypt the message using the public key. Now if [12:12.860 --> 12:18.940] they got the same key, the same hash, that means that I am the owner of the private key, of the [12:18.940 --> 12:26.760] public key, and therefore this message came from me. Sorry. So the whole concept of signature is [12:26.760 --> 12:32.120] based on the idea that I can share something publicly, I can keep something private, not tell [12:32.120 --> 12:39.160] that to anyone. But using that information, I can also convince you of my identity as a holder of [12:39.160 --> 12:45.480] that private key. Okay. One of the things and probably the last tenets for this very short [12:45.480 --> 12:51.240] introduction is the idea of randomness. Almost everything that we do in cryptography is somehow [12:51.240 --> 12:57.740] centered about randomness. So if we don't have a very strong randomness source, everything breaks. [12:57.740 --> 13:01.640] And I'll give some examples of that. So usually when we talk about randomness, we talk about two [13:01.640 --> 13:07.120] different things. The first one is called the TRNG or true random number generator. And the other is [13:07.120 --> 13:13.060] called PRNG, absurd random number generator. The big difference between the two is that the PRNG is [13:13.160 --> 13:18.920] a function. If I'll give it a known starting point, it will always get to the same result. Change the [13:18.920 --> 13:24.280] starting point, you'll get a different result, but it's derived in deterministic fashion. TRNG, I [13:24.280 --> 13:29.220] have no idea what's not going to happen. So it's just like measuring neutrons from the air or like [13:29.220 --> 13:34.120] measuring electromagnetic interference. It might be zero, it might be one, I have no idea what's [13:34.120 --> 13:40.540] going to happen. So a good TRNG will give me bits with a probability of 50%. I don't know what it [13:40.540 --> 13:46.400] would be. If it was something like, let's say 49%, I would be able to break that random number [13:46.400 --> 13:54.080] generator. So we need something that's very, very stable. So how do you use that? You take a PRNG and [13:54.080 --> 13:59.260] you provide it with an input that's come from a real world entropy source, something that's actually [13:59.260 --> 14:07.360] truly random. So what happens when it isn't random? Sometimes people misuse random numbers. For [14:07.360 --> 14:12.320] example, when they're writing code and they need to use nonces. Everybody are familiar with what's [14:12.420 --> 14:19.160] a nonce? Okay, so a nonce should be just a random number. It shouldn't be constant, it shouldn't be [14:19.160 --> 14:25.440] hardcoded into your code, until it is. And when it is, funny things happen. So I'll give you an [14:25.440 --> 14:33.840] example. Probably heard of Bitcoin, once or twice, maybe. So Bitcoins is actually a [14:33.840 --> 14:41.660] cryptographic operation. So what are coins? Coins are actually going and trying to find inputs that [14:41.660 --> 14:48.780] given a hash function will provide a pre-known output. So that's the difficult problem, not [14:48.780 --> 14:54.360] because it's mathematically hard, but because it's very difficult to find those inputs. So what do [14:54.360 --> 15:00.180] you do? You try a lot of different attempts, found one, you earn the coin. Now you are an owner of a [15:00.180 --> 15:06.000] single Bitcoin. This is exponentially harder as time goes by, which means you have to invest more [15:06.000 --> 15:11.360] time, more resources, more CPU power in order to actually mine those Bitcoins. But the basic [15:11.360 --> 15:17.380] principle still holds. Wallets, or your Bitcoin wallets, are just identities. They are something [15:17.380 --> 15:23.040] that represent your private and public keys. And transactions are actually just saying, I'll take [15:23.040 --> 15:28.140] this piece of money and I'll give it to that private key or that holder of that private key, and this [15:28.140 --> 15:33.240] is a transaction. Just shifting money or shifting coins or pieces of coins from one source to [15:33.240 --> 15:42.120] another. And I should have clicked like 20 minutes ago. An important thing to note, if you lose your [15:42.120 --> 15:48.600] private key, you lost your money. Because your coins are held by your private key. If you don't [15:48.600 --> 15:53.400] have access to your private key anymore, you don't have access to your coins. Something to keep in [15:53.400 --> 15:58.660] mind when you're playing around with Bitcoin. So the last thing I want to talk about is called [15:58.660 --> 16:04.640] elliptic curve cryptography. If you're familiar with RSA, basically the same thing, much cheaper to [16:04.640 --> 16:12.060] execute, much less compute power, same guarantees for security. Bitcoin is using these elliptic [16:12.060 --> 16:17.840] curve cryptography operations in order to move money about. So that's the basic algorithms behind [16:17.840 --> 16:24.340] Bitcoin. So this is a screenshot from a Bitcoin transfer. So what you can actually see is that [16:24.340 --> 16:33.060] this value here, this is the address of the source, which is actually the hash of my public key. And [16:33.060 --> 16:40.320] I'm moving money, 7.179 blah blah Bitcoins, into two different addresses, and the addresses are [16:40.320 --> 16:45.400] just the hashes of the public keys of the recipients. This is everything that there is to it. [16:45.400 --> 16:55.180] This is the entire Bitcoin idea in a slide. So how would you go about attacking this? So I will not [16:55.180 --> 17:00.220] going to bore you with the mathematical details behind this, but I'll try to direct your attention [17:00.220 --> 17:08.600] to a couple of things. The transaction actually happens when I, as an owner of a Bitcoin, will sign [17:08.600 --> 17:14.600] over a portion of that coin into a new address, to a new private key, or sorry, to a new hash of a [17:14.600 --> 17:20.320] public key. In order to do that, I have to work with a couple of components. The hash of the [17:20.320 --> 17:27.240] message, K, which is random, R, which is the multiplication operation under elliptic curves, and [17:27.240 --> 17:31.740] the signature. And the way to calculate the signature is outlined in the formula in the bottom. [17:31.980 --> 17:36.780] So there's something here which should stick out like a sore thumb to everyone who looks at it, [17:36.780 --> 17:47.120] which is, maybe I can show my hair. K should be random. And sometimes when implementers are [17:47.120 --> 17:54.020] reading the spec, they say, okay, K should be random, so I'll select a random number. So what [17:54.020 --> 18:00.200] happens when K isn't random? Assume that K isn't random. If I can go over on the block, look at all [18:00.200 --> 18:06.480] the blockchain, all the Bitcoin transactions, and find two different transactions that share the [18:06.480 --> 18:12.200] same random number. Suddenly, this is a problem in sixth grade algebra. Because if I know the [18:12.200 --> 18:19.300] value for K, I can just move about the equation, isolate K, and solve for everything else. And I [18:19.300 --> 18:24.980] solve and I solve, and finally I have D. Now I have the private key. Because in elliptic curve [18:24.980 --> 18:31.940] operations, when you're not using random numbers, everything breaks. So it's a tenet of using [18:31.940 --> 18:37.840] elliptic curves. So you say, okay, this is like nonsense. Who wouldn't use random numbers in the [18:37.840 --> 18:44.080] real world? This never happens. And the answer is, well, of course it does. So this is a [18:44.080 --> 18:49.220] screenshot from many, many years ago, 2013, when somebody noticed that people are stealing money [18:49.220 --> 18:55.440] from wallets. And how did this attack happen? Because someone else was probably a bit brighter [18:55.440 --> 19:01.060] noticed that people are using bad wallets or bad wallet software, where the developers for that [19:01.060 --> 19:06.240] piece of software for that wallet didn't realize that they need to generate a new K for every [19:06.240 --> 19:12.960] transaction. So what they've done is just searched the transaction logs for two different [19:12.960 --> 19:18.140] transactions using the same random number, extracted the private key, and stole all of their [19:18.140 --> 19:24.500] bitcoins. This was in the entire attack. So, you know, that's kind of if somebody wants to mess [19:24.500 --> 19:29.900] with bitcoins, like they had it coming. I have no problems with that. But you say, this shouldn't [19:29.900 --> 19:36.700] happen in, like, real world applications, like big sized interesting stuff. So how does that [19:36.700 --> 19:42.000] look like in the real world? When you generate a random number, what you should probably be [19:42.000 --> 19:48.800] doing is something like open slash dev slash random and pull a number of bytes out of it, maybe [19:48.800 --> 19:53.840] 30, I don't know, just throw in a number there. But you should do this for every time that you [19:53.840 --> 19:59.600] need a random number. Because when you don't, you get something like this. You choose the [19:59.600 --> 20:06.680] random number very securely, once, and hard code it. Which is like analogous to saying, what's [20:06.680 --> 20:19.140] my random number? Four. It was chosen by a fair dice roll. I'll skip this. Okay. We'll come back [20:19.140 --> 20:23.580] to the point of the randomness in a moment. I want to show you a piece of code and ask [20:23.580 --> 20:29.440] everyone, can everybody see the problem with this piece of code? Any hands? It was pretty [20:29.440 --> 20:35.540] famous for a while. Okay. We have one person. Two persons. Excellent. So I'll highlight it for [20:35.540 --> 20:43.640] everyone. So this piece of code is actually the verification code for X509 certificates on [20:43.640 --> 20:51.040] iOS. Or it used to be. And what this means is when you're doing a TLS transaction, somebody [20:51.040 --> 20:55.220] needs to check the certificate. How do you check the certificate? Just the same way that we [20:55.220 --> 21:00.340] talked previously. Just check the public keys, find out the hashes, compare them, check them. And [21:00.340 --> 21:06.160] the way that the code is written is that if there's an error, some check didn't pass, go to [21:06.160 --> 21:13.280] fail. But what happens here is you have a double line. So the first line is in the scope of that [21:13.280 --> 21:19.320] if. The second line isn't in the scope of anything. So anything written after that never [21:19.320 --> 21:25.200] executes. Okay? Whenever you go into that point, you immediately go to fail. So how is that [21:25.200 --> 21:31.740] interesting for an attacker? If you specially craft your certificate that you would pass each [21:31.740 --> 21:37.320] and every check up to that point, even though your certificate is invalid, you will still pass [21:37.320 --> 21:43.060] the test. Because nobody tests for like everything, you just test up to that point. And that [21:43.060 --> 21:48.940] meant that attackers could create certificates for, I don't know, for example, iOS apps that are [21:48.940 --> 21:53.960] invalid and malicious but have like certificates which are bad but pass the verification [21:53.960 --> 22:04.420] process. So special attention needs to be given to these kinds of cases. Am I missing a slide? Let [22:04.420 --> 22:18.600] me check. Yeah. I should have said something here and I skipped it, so let me circle back for a [22:20.640 --> 22:24.720] second. So Sony, you might have heard of them, have a device or had a device called the [22:24.720 --> 22:29.280] PlayStation 3. And the PlayStation 3 was pretty awesome, everybody liked playing with it, but [22:29.280 --> 22:34.540] they couldn't really copy the games. Why? Because of the digital rights management protection [22:34.540 --> 22:39.600] on the games. But what Sony didn't really take into account or their developers didn't think [22:39.600 --> 22:44.620] about very thoroughly is that when they signed the games, they signed them with elliptic curves [22:44.620 --> 22:51.800] but they chose a single random value and it was hard-coded. So when the guys at Overflow found [22:51.800 --> 22:58.260] this out, they understood, okay, I can just take two different games, compare the signatures, [22:58.260 --> 23:03.380] find the random values that they used, derive the private key and now I can sign whatever game [23:03.380 --> 23:09.480] that I want for Sony because I have the private keys because they didn't use random values. So [23:09.480 --> 23:14.260] this was a very big thing for a while because those hard-coded numbers were hard-coded [23:14.260 --> 23:20.060] into the PlayStation 3 hardware device itself, the firmware. And they couldn't really update [23:20.060 --> 23:25.580] this, they couldn't circumvent this, they just lost a lot of money because someone made a [23:25.580 --> 23:30.660] mistake about assuming something about random numbers. Sorry, I completely missed my point [23:30.660 --> 23:39.740] here. Circling back to Bitcoin, everybody remember this screen from two and a half years ago, [23:39.740 --> 23:48.740] something like that? So attackers behind WannaCry built, I don't know, let's call it a GUI or [23:48.740 --> 23:53.720] something that will give you some information, how can you get the keys in order to get back all [23:53.720 --> 23:59.240] your files that they encrypted, just send me some money to this Bitcoin address. And they were [23:59.240 --> 24:03.860] supposed to send you back the keys and everybody would be very happy. So a couple of things [24:03.860 --> 24:08.200] happened. The first one was that obviously they never sent the keys. The second one was that the [24:08.200 --> 24:13.340] WannaCry attack was stopped pretty much in the middle because of a different operation. They [24:13.340 --> 24:19.900] had like a failsafe so they could stop the propagation of the malware from going everywhere [24:19.900 --> 24:26.500] because, that's like a different story, but the malware would check if a specific domain name [24:26.500 --> 24:33.940] was registered. If it was registered, it would stop the work. So while that domain name was not [24:33.940 --> 24:38.580] registered, it would continue to propagate. So one of the security researchers would just [24:38.580 --> 24:44.020] finish, if you're following up on the news, just finish his trial, find that out from reverse [24:44.020 --> 24:48.760] engineering the software, he registered that domain, he paid like, I don't know, $5 for it and [24:48.760 --> 24:53.880] stopped WannaCry. So that was the first thing that was really not very smart about WannaCry. The [24:53.880 --> 25:01.080] second thing was that they kind of missed the point of using Bitcoin. Bitcoin is a confidential [25:01.080 --> 25:06.700] service, but it's not an anonymous service. It means that everybody can be the owner of [25:06.700 --> 25:11.440] Bitcoins and their identity is protected. You don't have to tell anyone your identity, but [25:11.440 --> 25:17.020] everything you do is always logged, is always recorded. It's part of the very mechanism of how [25:17.020 --> 25:23.400] transactions on the blockchains work. And that means that if I'm a malicious attacker, and I'm [25:23.400 --> 25:28.180] asking people to send money over to my wallet, everything is traceable, everything is [25:28.180 --> 25:33.920] accountable, and it's part of the design of the system. And if I want to cash out, now I have a [25:33.920 --> 25:40.360] problem. Because if I try to cash out, somebody can just okay, now you linked that identity with [25:40.360 --> 25:47.220] this real world credit card. So they had money stuck there, they had about $70,000 if I [25:47.220 --> 25:52.080] remember correctly, they had it stuck there for a couple of months until they thought about a [25:52.080 --> 25:57.780] solution, which was just doing cash exchanges in Macau or something like that, to go over there, [25:57.780 --> 26:02.440] pull out the money very fast and disappear. But while they were doing this, they really couldn't [26:02.440 --> 26:09.640] touch the funds, because whatever you do with the funds, it's always traceable. Okay. So how [26:09.640 --> 26:15.800] does this look in the real world? New example. Who uses BitLocker, or at least heard of it enough [26:15.800 --> 26:22.700] to understand the term? I don't believe you. Who has Windows laptops? Really, everybody runs [26:22.700 --> 26:33.740] Linux? Wow, cool. I'm really proud of you guys. So BitLocker is, I wouldn't call it a protocol, [26:33.740 --> 26:39.420] but it's like a feature where your hard drive will self encrypt everything. So if somebody steals [26:40.100 --> 26:45.320] the hard drive and connects it to a new computer, he can't read the data that's on that device. [26:45.380 --> 26:51.080] That's a description of that feature. What really happens is that when you connect it to the [26:51.080 --> 26:58.680] operating system, the operating system is something like this. Are you a hard drive or SSD or [26:58.680 --> 27:04.580] whatever that supports hardware encryption? And the BitLocker supported device says, yes, of [27:04.580 --> 27:10.840] course I know encryption. Let's use my encryption. So if you have a hardware supported encryption [27:10.840 --> 27:16.240] on your hard drive, it will use the hardware version. If you don't have support, then Windows [27:16.240 --> 27:21.740] will simulate that support in software. What's the problem with that? The problem with that is [27:21.740 --> 27:26.220] the very premise that hardware is actually better than software. Because the way that the hardware [27:26.220 --> 27:35.140] developers did that was mumble about. What they did. They had a password that's used by your [27:35.140 --> 27:40.460] BIOS in order to encrypt or decrypt information from your hard drive, and they had a key. But [27:40.460 --> 27:44.380] there is no relationship between the password and the key. So you can type any password that you [27:44.380 --> 27:50.320] want, the key will still be fixed. It will be orthogonal to the password that you used. So [27:50.320 --> 27:56.860] they didn't tie together in any way. Second thing is, they used the same key to encrypt the entire [27:56.860 --> 28:00.900] drive. All of the different partition, all of the different blocks and sections. Which means [28:00.900 --> 28:05.820] that I have lots and lots of different blocks of encrypted data that I can compare against that are [28:05.820 --> 28:11.560] all using the same key. Which means that if you had a bad implementation, you just made my life [28:11.560 --> 28:17.940] easier as an attacker. And the last thing is, they didn't really use random keys. I'm just [28:17.940 --> 28:23.180] dissing here, but think of it as an equivalent of a 12 character password where it's all ones. [28:23.680 --> 28:28.980] Okay? So they didn't randomize the password. So you had the same password for all blocks on [28:28.980 --> 28:33.440] your hard drive, which didn't have any correspondence with a password for your BIOS or [28:33.440 --> 28:37.840] anything else. So you couldn't customize it, it didn't tie into anything from the real world. [28:37.840 --> 28:45.220] And that meant that, I'll skip that, and that meant that all of those drives were very, very [28:45.220 --> 28:51.120] weak from a cryptographic perspective. It's almost trivial to break them. However, the [28:51.120 --> 28:56.140] operating system by default will choose the hardware encryption over the software encryption. [28:56.140 --> 29:01.820] And that means that any laptop that you probably have or had for the past year or older than [29:01.820 --> 29:08.680] that, didn't really have the security guarantees that you thought it had by using the [29:08.680 --> 29:15.820] BitLocker and similar properties, similar features. Here's just, I don't know, I just found it [29:15.820 --> 29:20.940] like an extremely funny example. Somebody on Stack Exchange asked for an algorithm to encrypt [29:20.940 --> 29:25.240] your password. I know you can't read it, so I'll enlarge it. So the method that he was [29:25.240 --> 29:32.900] suggesting to do was to take a Base64 encoding of your password and then reverse it, apply [29:32.900 --> 29:37.560] Base64, and now you have an encryption. So the amount of things that are wrong with that [29:37.560 --> 29:42.700] sentence are that... I don't know, he summarized this much better than me. The first thing is [29:42.700 --> 29:49.920] that Base64 is a bad choice because it enlarges the space requirement to store the same kind [29:49.920 --> 29:53.920] of information. The second thing is obviously this has nothing to do with cryptography, it's [29:53.920 --> 29:59.860] just encoding the same information in a different way. Reversing the encoding does nothing for [29:59.860 --> 30:05.360] security, just means that I have to reverse it again. And the basic thing is that this [30:05.360 --> 30:12.420] was an entire thread on Stack Exchange, should I use MD5 to encrypt my files and encrypt [30:12.420 --> 30:17.780] my passwords, where one, MD5 is not an encryption algorithm, and two, it has nothing to do with [30:17.780 --> 30:22.740] it, it's broken, use something else. And this guy came along and suggested to use this amazing [30:22.740 --> 30:27.740] piece of code that he wrote in order to protect everybody's password. So be careful of where [30:27.740 --> 30:33.880] you get your advice. I'm not dissing Stack Exchange, I'm just saying you should vet information [30:33.880 --> 30:42.940] that you receive. I think it's my last example. I do want to explain the concept and what [30:42.940 --> 30:48.720] I find problematic with it, but the basic idea is that it is actually a good piece of [30:48.720 --> 30:53.340] software, it just had its own limitation. So what this guy, he wrote a piece of software [30:53.340 --> 30:58.320] called Crypt Hook, and the problem he was trying to solve is that you have information [30:58.320 --> 31:03.060] on server A, and you want to communicate with server B, but you don't have the facilities [31:03.060 --> 31:06.880] to encrypt the information, you can't change the software that's running on the servers. [31:07.080 --> 31:11.860] So what he said, okay, I'll hook the system calls, and every network packet that transfers [31:11.860 --> 31:18.140] from server A to server B, I will encrypt it myself. So I will, like, create an out-of-bed [31:18.140 --> 31:23.700] encrypted channel between the two servers that has nothing to do with the software running [31:23.700 --> 31:28.420] on them. It will still transparently use the network stack, and I will encrypt the network [31:28.420 --> 31:33.140] stack. Out of the box, it's not like a bad idea, this really solves a real problem where [31:33.140 --> 31:37.180] you can't touch the software. On the other hand, the choices that he's made, made it [31:37.180 --> 31:44.440] very, very weak. So he chose to use GCM, which nobody should really care what it means, to [31:44.440 --> 31:49.740] do authentication, but he encrypted everything with a fixed key. So every packet was encrypted [31:49.740 --> 31:55.120] with the same key. Not only was that every packet was encrypted with the same key, there [31:55.120 --> 31:58.380] was no difference between the packets, so everything was encrypted exactly the same [31:58.380 --> 32:04.980] way. So it was absolutely easy for an attacker to capture a packet and replay it, send it [32:04.980 --> 32:10.320] again over the network. So if you had a packet that says, transfer $1,000 to my account, [32:10.320 --> 32:14.420] you can just capture that packet and replay it again and again and again, because no [32:14.420 --> 32:19.680] one would know, because there's no such information inside the packet to stop that. Also, you [32:19.680 --> 32:24.760] can change the order of the messages. You can do whatever you want with it, like dropping [32:24.760 --> 32:29.580] some of the messages, because his encryption scheme didn't think about those kinds of edge [32:29.580 --> 32:35.500] cases or use cases. But also, it meant that if I broke the key once, because it was fixed, [32:35.500 --> 32:39.840] it was hard-coded, that meant that I now had the key to every communication that would [32:39.840 --> 32:44.560] ever happen with this piece of software, which is tentative to just reading the source [32:44.560 --> 32:51.780] code because the key was there. So the question is, is everything on fire? Is everything bad? [32:52.280 --> 32:58.080] So obviously the answer to that is no, not everything is on fire, not everything is bad. [32:58.080 --> 33:04.460] But you should really pay special consideration whenever you're touching something related [33:04.460 --> 33:11.560] to crypto. Crypto is hard. There are experts, usually PhDs, that spend years and years of [33:11.560 --> 33:17.000] their lives researching crypto problems and crypto properties in order to make sure that [33:17.000 --> 33:22.280] whatever they're doing is very, very safe. You're not going to outperform them, you're [33:22.280 --> 33:27.640] not going to outsmart them, and you probably shouldn't be trying. Never roll your own crypto. [33:27.640 --> 33:32.820] Use best practices, use what's already out there. In my next slide, I'll give some recommendation. [33:32.820 --> 33:37.680] But also, you have a special use case, you have some problem that's unique and you don't [33:37.680 --> 33:43.480] know if the current tooling is able to solve that. Well, ask around, ask an expert. I can [33:43.480 --> 33:48.740] recommend two, let's say, expert advice channels that you can use. The first one is using Reddit, [33:48.740 --> 33:53.640] the crypto subreddit, but also the crypto stack exchange. Both are wonderful resources [33:53.640 --> 33:59.120] to consult with real world experts that can help you understand your problem and the right [33:59.120 --> 34:04.920] kind of tooling, the right kind of algorithms that you can use to solve that unique problem. [34:05.100 --> 34:09.740] More than that, you can always pay consultants. I'm a consultant, I'm getting paid to give [34:09.740 --> 34:14.120] advice, that's fine. There are experts that you can talk to on Twitter, anywhere else, [34:14.120 --> 34:19.960] you will get advice. People are nice, basically, most of the time. You can also pay a crypto [34:19.960 --> 34:24.100] review firm to go and look over your crypto code to make sure you haven't done something [34:24.100 --> 34:29.060] horrible like what happened to Sony. You don't want to be in that position where you wrote [34:29.060 --> 34:32.960] your own crypto or your team wrote some crypto because you thought you would be really solving [34:32.960 --> 34:37.420] something and you just horribly broke the entire security premise of your product. [34:39.320 --> 34:44.080] So what's my advice to you? That's probably the slide you should copy or photograph or [34:44.080 --> 34:49.560] just listen very carefully. The first one is that make sure that you're using the right [34:49.560 --> 34:58.300] libraries for you. Personally, I never recommend OpenSSL. Who has experience using OpenSSL [34:58.300 --> 35:04.600] APIs or implementing OpenSSL code in their own ID or in their own product? Anyone using [35:04.600 --> 35:14.880] OpenSSL? How sorry are you? Have you tried anything else? Not really. So at least my [35:14.880 --> 35:21.820] opinion of OpenSSL, it's a big, large, bloated piece of software that tries to do everything [35:21.820 --> 35:27.900] and most of the time doesn't do them the most efficient or the most proper way and it gives [35:27.900 --> 35:32.400] you... I used to have a boss that told me that C is a wonderful language. It gives you [35:32.400 --> 35:37.860] every tool possible to slit your own throat. So in a sense, OpenSSL is the same way. They [35:37.860 --> 35:42.460] support everything. Every legacy algorithm, every parameter ever conceived for anything [35:42.460 --> 35:47.880] and if you will misuse this or configure it wrongly or use the wrong parameters, you won't [35:47.880 --> 35:52.920] even know that you broke your crypto. So my first recommendation for you is just use [35:52.920 --> 35:57.160] something simpler. And you know, the world has advanced. There are lots of very good [35:57.160 --> 36:04.760] libraries out there. Archimedecommon, BoringSSL, the Golang crypto stack is excellent. NACL [36:04.760 --> 36:12.800] is also very, very good. NSS is very good. I do want to say that all of the libraries [36:12.800 --> 36:17.440] I mentioned here are good and I recommend them myself. Sometimes they have issues. They [36:17.440 --> 36:22.180] have bugs. They have patches that you need. And this is actually a good thing. Because [36:22.180 --> 36:26.140] that means that somebody is maintaining this. Somebody is actually looking if there are [36:26.140 --> 36:30.800] any issues and somebody is trying to fix them. So whenever such a thing exists, take that [36:30.800 --> 36:34.940] into your consideration, into your dependency stack and make sure that your own code is [36:34.940 --> 36:41.020] up to date. Never trust people that roll their own crypto. There are lots of like, oh, yeah, [36:41.020 --> 36:46.160] we have a student. He's really brilliant. We ask him to write our crypto stack. That's [36:46.160 --> 36:51.060] not a good idea. Even if he is brilliant. Use best practices. Use what's already out [36:51.060 --> 36:56.160] there. Just use it correctly. You have a much easier time, much better time overall. [36:56.720 --> 37:02.940] The last thing is that... sorry. The last thing that I want to mention about that is [37:02.940 --> 37:09.020] that not every feature that exists in crypto is actually something that you need. So cryptography [37:09.020 --> 37:13.240] has a lot of building blocks that are used in many, many different ways. Some of them [37:13.240 --> 37:19.100] are very esoteric. Some of them are like the mainline use cases. 90% of the time, [37:19.100 --> 37:23.360] you need the mainline use case. It's already described. It's already known. Just use that. [37:23.360 --> 37:27.380] Don't invent anything. Don't try to like, oh, that's a nice looking piece of technology. [37:27.380 --> 37:31.420] Just like, let's use that instead. You need to think about it and you probably need some [37:31.420 --> 37:34.580] cryptographer to let you know if you did this correctly or not. [37:35.560 --> 37:41.680] So what you can do. Update your libraries. I've seen so many customers, so many people [37:41.680 --> 37:49.160] who use OpenSSL and like version 1.01 or something like that. And it's not updated at all. Because [37:51.260 --> 37:56.300] it's hard to update and they're afraid it will break something. And with OpenSSL, that's [37:56.300 --> 38:02.580] very cumbersome anyway. So make your life easier. Make sure that you have thought of [38:02.580 --> 38:06.800] how are you going to update this? How are you going to fix this when the time comes? [38:07.380 --> 38:12.440] If you want to become an expert, my recommendation to you is to start small. Go to trainings, [38:12.440 --> 38:17.960] to workshops, hear talks, go over YouTube, read a book. You can become an expert on cryptography [38:17.960 --> 38:22.580] without knowing math. You don't need a math degree in order to better understand crypto. [38:22.580 --> 38:26.920] You probably need a math degree or even a math PhD to invent crypto. But not to use [38:26.920 --> 38:32.520] it. To use it properly, study. Like everything else that we do. Study. This is a domain of [38:32.520 --> 38:36.300] knowledge that you can use, you can learn. It's not scary. It's not something that you [38:36.300 --> 38:42.600] should be afraid of. Down the line, you probably want to either outsource or hire the right [38:42.600 --> 38:48.260] people to look at cryptography very closely. But if you're not inventing cryptography, [38:48.260 --> 38:52.680] just use something that someone else already did. It will make your life easier and probably [38:52.680 --> 39:06.810] get better security out of it. With that, I would thank you very much. I'll be happy [39:06.810 --> 39:11.470] to take questions now in a moment. And if not, I'll be also outside later to take more [39:11.470 --> 39:19.810] questions. Yes, sir? That depends on what your desktop is. If you're on Linux or on [39:19.810 --> 39:26.730] your own Windows or you're on Chrome OS or differently. But I would trust with a mild [39:26.730 --> 39:32.010] degree of assault attached to it. But I would trust the operating system to hold secrets. [39:32.890 --> 39:37.310] They're usually pretty good. Depending on how much trust you need for that secret. If [39:37.310 --> 39:41.810] I have a desktop application, usually that means I have my own laptop or storing my own [39:41.810 --> 39:45.770] bank accounts or something like that, that's secure enough. If I have a production server [39:45.770 --> 39:51.290] hosting secrets for my 100,000 customers, that's a different question. There I would [39:51.290 --> 39:57.090] use an HSM or something similar. HSM is a hardware security module. That's actually a [39:57.090 --> 40:00.670] piece of hardware that holds secrets and lets you do cryptographic operations without [40:00.670 --> 40:08.800] revealing those secrets. So we can talk about that later. Yes? Yeah? [40:28.570 --> 40:35.530] I fully agree. I'll repeat that. The Capital One issue hand wavingly was not actually an [40:35.530 --> 40:40.490] encryption issue, it was a permission issue. So if you give someone permissions or you [40:40.490 --> 40:47.130] commit to GitHub your keys, then you actually give everybody permission to use your keys to [40:47.130 --> 40:51.310] do whatever they want to do. So the cryptography is still very strong but you haven't [40:51.310 --> 40:55.070] protected your keys. So in a sense that's what happened with Capital One. Both for roles [40:55.070 --> 41:15.620] and permissions for the access list they used for attacking. Well, here's where you [41:15.620 --> 41:19.720] actually need an expert to come and help you and look at your own specific use case. But if [41:19.720 --> 41:24.100] you encrypted your entire database but you kept the key in a script by that database, then [41:24.100 --> 41:27.620] you haven't really done anything. But if you encrypted your entire database and the key [41:27.620 --> 41:31.800] comes from a different component which checks your permissions and stuff like that, then you [41:31.800 --> 41:36.960] already have a different security model. So this is actually a more complex question to [41:36.960 --> 41:40.500] answer and not necessarily relevant for client side encryption depending on what you're [41:40.500 --> 41:49.700] trying to solve. Okay, more questions please. Be brave. Go on. Going to the next one. [41:49.720 --> 41:52.400] Thank you very much.