1 00:00:00,000 --> 00:00:05,220 Thanks so much for coming out this morning. I want to be true to my Scots heritage, I never 2 00:00:05,220 --> 00:00:12,040 turn down whiskey. I'm David McGrew. I'm going to be presenting some joint work I did with 3 00:00:12,040 --> 00:00:20,100 Andrew Chee and Brandon Enright here. And we're going to be assessing the security of 4 00:00:20,100 --> 00:00:23,860 certificates at scale and the exciting thing of course is we're going to show an exploit 5 00:00:23,860 --> 00:00:30,860 against keys we got off the internet. So, for the last decade or so, people have been aware 6 00:00:30,860 --> 00:00:37,460 that there's a problem that commercial and small business and consumer grade devices often 7 00:00:37,460 --> 00:00:43,120 have really poor entropy and when they use this to generate keys, they can generate keys that 8 00:00:43,120 --> 00:00:49,180 are exploitably weak. And so, Dan Bernstein and Nadia Henninger and their teams, you know, 9 00:00:49,800 --> 00:00:53,840 convincingly showed this a long time ago and there's, there's other, there's other 10 00:00:53,860 --> 00:00:59,300 teams that more recently showed that it's still a problem. In 2023, we are talking about 11 00:01:00,000 --> 00:01:05,020 migrating to quantum safe cryptography. We have a, another problem to solve which is this weak 12 00:01:05,020 --> 00:01:09,340 entropy problem, right, because otherwise we're going to have quantum safe algorithms with 13 00:01:09,340 --> 00:01:20,460 weak keys, which is maybe an oxymoron. So, what is the, the weak key problem? So, here 14 00:01:20,460 --> 00:01:23,840 we've got a big set of devices. So, we've got, we've got, we've got, we've got, we've got, we've 15 00:01:23,840 --> 00:01:24,180 got, we've got, we've got, we've got, we've got, we've got, we've got, we've got, we've got, we've got, 16 00:01:24,180 --> 00:01:25,520 we've got, we've got, we've got, we've got, we've got, we've got, and in this diagram there are 17 00:01:25,520 --> 00:01:30,260 wireless access points, right? Could it be, but it could be any device that generates a, a 18 00:01:30,260 --> 00:01:37,760 public-private key pair. And so, each device has an entropy source in it and the entropy source is 19 00:01:37,760 --> 00:01:43,220 going to provide an output into a key generator. Very often these devices generate a key when 20 00:01:43,220 --> 00:01:48,820 they first boot, which is often a problem because if you have a software based entropy source, 21 00:01:49,480 --> 00:01:53,700 when you first boot, you're probably don't have a lot of entropy. Probably it's fairly deterministic 22 00:01:53,840 --> 00:02:00,920 process by which you boot. And so the, if you use that entropy, put it into a key generator and 23 00:02:00,920 --> 00:02:07,180 generate a key from it, then, uh, that could potentially be a problem as we show. But, our 24 00:02:07,180 --> 00:02:11,000 model is, you know, we've got a lot of devices, they each have an entropy source, they each 25 00:02:11,000 --> 00:02:16,320 generate, uh, a public-private key pair. And then we, we're able to access the public keys and 26 00:02:16,320 --> 00:02:23,180 then analyze them. So, if you have cryptographically strong entropy generators, then if 27 00:02:23,180 --> 00:02:27,880 you want to generate an n-bit key, all two to the n possible keys are equally probable, right? 28 00:02:27,980 --> 00:02:32,520 And that's what you want to be unpredictable to your adversary. But with weak key generation, you 29 00:02:32,520 --> 00:02:38,320 just have a really small typical set that's like a tiny fraction of the original size of, you 30 00:02:38,320 --> 00:02:43,380 know, the, the size you wanted, right? And this can make it predictable. And so, we're gonna be 31 00:02:43,380 --> 00:02:50,500 detecting and exploiting some of these weak keys. Going back to our original picture, we have a 32 00:02:50,500 --> 00:02:53,160 bunch of wireless access points and they, they, they, they, they, they, they, they, they, they, 33 00:02:53,180 --> 00:02:58,520 they are, they're, they're entropy sources, except device one and device three happen to have 34 00:02:58,520 --> 00:03:06,100 entropy that's similar, right? And so, the similar entropy is fed into the, uh, key generation 35 00:03:06,100 --> 00:03:11,220 algorithm and then the, the keys are gonna be weak, right? So, red on these diagrams 36 00:03:11,220 --> 00:03:18,040 indicates weak. And the, you know, there's a key thing here is, which is, there's a lot of 37 00:03:18,040 --> 00:03:23,160 devices that we want to assess the security of and we're gonna, we're gonna, we're gonna be 38 00:03:23,180 --> 00:03:27,220 gonna use batch processing on this. And it actually, it's kind of a birthday paradox thing. 39 00:03:27,340 --> 00:03:36,100 The more things we're analyzing, the more chance of success we're gonna have. So, there are 40 00:03:36,100 --> 00:03:41,040 different public key crypto-algorithms, and they each have their own failure modes. And the, 41 00:03:41,060 --> 00:03:47,540 the two really important ones, are common keys and common factors. So, common keys can be 42 00:03:47,540 --> 00:03:53,160 generated uh, for any algorithm, right? It, it just means that the, th-the entropy, the favournica, 43 00:03:53,180 --> 00:03:58,120 input to the key generation was identical in two cases, so you get identical keys out, right? 44 00:03:58,280 --> 00:04:03,380 So this can happen for any algorithm, elliptic curve cryptography, RSA, or any of the quantum 45 00:04:03,380 --> 00:04:10,100 safe things. And so detection is fairly easy in the sense that you're just doing an equality match, 46 00:04:10,320 --> 00:04:19,240 but it also is difficult to go from that match to strong evidence of failure, right, of exploitable 47 00:04:19,240 --> 00:04:25,240 weakness, because there are, you know, the same public key might be enrolled in multiple 48 00:04:25,240 --> 00:04:30,240 certificates, and sometimes people actually take the same private key and they put it in multiple 49 00:04:30,240 --> 00:04:34,040 servers, and they think they're being clever, even though it's a poor security practice. 50 00:04:34,600 --> 00:04:39,400 But the common keys can be generated by weak entropy, but it can be difficult to distinguish it 51 00:04:39,400 --> 00:04:44,000 from that, like, poor security practice. The other thing that we're going to focus more of our 52 00:04:44,000 --> 00:04:48,880 time on today is common factors, right? So in the RSA cryptosystem, 53 00:04:49,640 --> 00:04:58,460 there are two factors. I'll show you how the math works. And it can happen that two distinct 54 00:04:58,460 --> 00:05:03,540 private keys have the same common factor. We can detect that using the batch GCD algorithm, and 55 00:05:03,540 --> 00:05:09,340 this is very strong evidence of weak entropy, and a serious problem with the entropy in the 56 00:05:09,340 --> 00:05:16,220 system. And then also it's exploitable, which is kind of fun to watch. So here's how the RSA 57 00:05:16,220 --> 00:05:18,320 cryptosystem works, right? The public key, 58 00:05:19,240 --> 00:05:25,560 is the product of two large primes, and those large primes are the private key, right? So the 59 00:05:25,560 --> 00:05:32,220 private key would be, you know, P comma Q, and then the public key is their product, M. And M is 60 00:05:32,220 --> 00:05:39,680 also called the modulus, right? Within the context of RSA. So multiplication is easy to do, in a 61 00:05:39,680 --> 00:05:45,060 computational sense, but factoring is very hard, right? So which is what makes the RSA cryptosystem 62 00:05:45,060 --> 00:05:46,320 secure when it's done properly. 63 00:05:49,240 --> 00:05:54,840 So when I talk about common factors, what I mean is, like, two distinct devices will generate the 64 00:05:55,880 --> 00:06:01,900 identical factors, right? You can see here, you know, continuing our previous example, device 1 65 00:06:01,900 --> 00:06:08,400 and device 3 have their Q factor in common, right? They happen to be equal, because the entropy 66 00:06:08,400 --> 00:06:19,220 input was so similar. So we can find common factors, right? So in this situation where device 1 67 00:06:19,240 --> 00:06:25,120 and device 3 happen to, you know, have this weak entropy problem, we can just perform the 68 00:06:25,120 --> 00:06:32,780 greatest common divisor algorithm, and use that to find Q, and then we can divide M by Q, and we can 69 00:06:32,780 --> 00:06:39,980 find the other factor, and then we've broken the key. So the GCD algorithm is easy. It's not hard 70 00:06:39,980 --> 00:06:45,420 in a cryptographic sense. And there's this algorithm that Dan Bernstein came up with for doing 71 00:06:45,420 --> 00:06:49,220 batch GCD, right? So you can get a very large set of keys, and then you can find all of the other 72 00:06:49,220 --> 00:06:55,120 find any common factors that those keys might have, right? Which is the real key to efficiency in 73 00:06:55,120 --> 00:07:01,180 this situation. To actually use this approach, your first step is you need to obtain 74 00:07:01,180 --> 00:07:09,640 certificates, right? That have RSA public keys in them. And so, you could obtain these through 75 00:07:09,640 --> 00:07:16,760 active scans of the internet or through passive monitoring that, you know, for TLS 1.2 and 76 00:07:16,760 --> 00:07:22,620 earlier, you can just observe the certificates on the wire. And then, if you have a friend 77 00:07:22,620 --> 00:07:27,240 that works at a certificate authority, then you can get the CA logs, right? And that's 78 00:07:27,240 --> 00:07:34,740 another really good thing. So, we have some tools that we published. TLS scanner for active 79 00:07:34,740 --> 00:07:40,620 scanning. Mercury for passive monitoring. And cert analyze for analyzing stand alone 80 00:07:40,620 --> 00:07:46,220 certificates. As well as the batch GCD program, which isn't written on this slide. But these 81 00:07:46,220 --> 00:07:54,160 are all BSD licensed, um, Linux oriented tools, uh, implemented in C++17 with a lot of, 82 00:07:54,280 --> 00:08:07,220 heh, with native ASN1 code. And so, the TLS scanner tool can, you know, scan a list of hosts you 83 00:08:07,220 --> 00:08:14,400 provide in a, in a file and it can write out the certificates as a, a PEM file. And so, you can 84 00:08:14,400 --> 00:08:18,240 use this to obtain certificates from a set of hosts. So, if you have, like, a, a set of hosts, 85 00:08:18,300 --> 00:08:24,160 like, say you're, you want to do a security audit for some, you know, bunch of stuff on the 86 00:08:24,160 --> 00:08:29,160 internet that you're, you've deployed or, you know, somebody who's, who's contracting with you 87 00:08:29,160 --> 00:08:36,800 has deployed, you can use this to grab all those certificates. So, our certificate tool, you 88 00:08:36,800 --> 00:08:43,800 can use this to filter, uh, against a regular expression or an exact string match in the text fields of a 89 00:08:43,800 --> 00:08:48,380 certificate, which is really useful. If you have a giant batch of certificates, like you got it 90 00:08:48,380 --> 00:08:54,920 from Shodan or Census or someplace like that, Rapid7, then you, you can use it to filter out things 91 00:08:54,920 --> 00:08:59,660 like there's a particular vendor you want to focus on for a security audit. Uh, filtering the 92 00:08:59,660 --> 00:09:04,920 giant set of certificates down to a very large but manageable set of certificates can really help 93 00:09:04,920 --> 00:09:13,080 you, uh, by, you know, making the analysis go faster. So, our tool can, if you're gonna filter, 94 00:09:13,080 --> 00:09:20,220 you need to provide the PEM output format. And it, you know, outputs the manageably small set of 95 00:09:20,220 --> 00:09:26,980 certificates. So, in, in, in our work, so we, we wrote these tools so that we could assess 96 00:09:26,980 --> 00:09:34,460 certificates at, um, you know, that, that we were, uh, you know, for devices that we were 97 00:09:34,460 --> 00:09:41,840 analyzing. And we, we applied this to a number of things, including internet scan data. And we 98 00:09:41,840 --> 00:09:49,420 found there's a lot of common strings in issuers that reveal, uh, different vendor names, 99 00:09:49,540 --> 00:09:56,100 right? So, today we're gonna be picking on DrayTek. And we kind of picked them at random. Um, 100 00:09:56,320 --> 00:10:01,380 but just to admit, right, so my employer is Cisco and, and Cisco small business routers did 101 00:10:01,380 --> 00:10:11,360 appear here. And, uh, you know, fortunately we no longer sell that thing. So, the batch GCD tool, 102 00:10:11,840 --> 00:10:19,960 is where the, most of the interesting work gets done for RSA. So, in this tool, um, which, you 103 00:10:19,960 --> 00:10:24,020 know, I have to give credit to Brandon and Andrew, are the, the people that wrote this. I only 104 00:10:24,020 --> 00:10:32,080 wrote the ASN1 export functionality. Uh, batch GCD, you provide it some giant set of certificates 105 00:10:32,480 --> 00:10:40,060 in a single file that has the, the PEM certificate format. And, and then you have to provide it with 106 00:10:40,060 --> 00:10:41,820 the right keys option. If you actually want to use the right keys, you can use the right keys. 107 00:10:41,820 --> 00:10:45,500 You could also want it to generate some output data that you could use to demonstrate an 108 00:10:45,500 --> 00:10:51,820 exploit. So, for each factored RSA key, it is going to write out the private key in a 109 00:10:51,820 --> 00:10:58,440 separate RSA private key format. It's another PEM format. And the, it's also gonna write out the 110 00:10:58,440 --> 00:11:02,160 corresponding certificate, right? So, if, if you're analyzing, you know, millions of 111 00:11:02,160 --> 00:11:06,940 certificates, you don't wanna have to wade through that file in order to, to find the 112 00:11:06,940 --> 00:11:11,300 certificate file corresponding to your private key file. This tool does two, two different 113 00:11:11,300 --> 00:11:17,840 passes over the input data because we want to carefully manage our random access memory 114 00:11:17,840 --> 00:11:22,900 usage because RAM is a scarce resource when you're trying to do something like batch GCD. 115 00:11:24,820 --> 00:11:36,120 So I want to show a demonstration of this attack. And let me explain the setup here. So we 116 00:11:36,120 --> 00:11:45,120 have a victim that owns a wireless access point that has an exploitable key in it. And he has 117 00:11:45,120 --> 00:11:53,240 chosen to trust the self-signed certificate associated with this device. And the victim is at 118 00:11:53,240 --> 00:11:58,260 a browser and he's going to visit the manufacturer of this device and we're going to perform 119 00:11:58,260 --> 00:12:06,000 a machine in the middle attack against his traffic. So I want to acknowledge the MITM 120 00:12:06,000 --> 00:12:23,460 proxy tool which we used in this attack. Okay. So we're going to start out. This is the 121 00:12:23,460 --> 00:12:35,980 attacker's machine. So we've previously obtained a bunch of certificates that are based on the 122 00:12:36,000 --> 00:12:39,800 GCD. And they all have a bunch of certificates that are all have this, you know, DrayTek string in 123 00:12:39,800 --> 00:12:46,300 their issuer. And we're going to run the batch GCD program with that file as input. And we're 124 00:12:46,300 --> 00:12:52,100 going to ask it to write out the private keys. And you can see we've got about 158,000 distinct 125 00:12:53,260 --> 00:13:00,960 RSA keys here. A modulus is a key in this situation. And so I wish I had the laptop here today. 126 00:13:01,080 --> 00:13:05,420 This is running on my framework laptop which has eight cores. And you can see in this system 127 00:13:05,420 --> 00:13:14,300 utilization. We're keeping all of the 8 cores pretty busy at this point. And so this tool can 128 00:13:15,080 --> 00:13:21,700 analyze a batch of about 67 million RSA keys all together. That's assuming an average size of 129 00:13:22,560 --> 00:13:27,940 2048 bits each, which is common place. And that's going to require about half a terabyte of RAM 130 00:13:27,940 --> 00:13:35,400 if you actually go up to that limit. You can rent that on GCP for not too much money. And 131 00:13:35,420 --> 00:13:41,000 so at this point it's a boring demo, but we're about to get to the point where we find 55 weak 132 00:13:41,000 --> 00:13:47,560 keys out of the initial set, right? So our tool writes out the lines corresponding to all of 133 00:13:47,560 --> 00:13:53,900 those weak keys. And we're going to pick one of these things at random to use in a demo. The 134 00:13:53,900 --> 00:13:59,180 tool outputs, you'll see the line number is the, you know, the number of the certificate in the 135 00:13:59,180 --> 00:14:05,400 input file. And we have to use the line number so you can correspond the, you know, the 136 00:14:05,420 --> 00:14:10,860 private key file with the certificate file. And that's the sort of thing you'd use. Here we're 137 00:14:10,860 --> 00:14:16,000 piping the certificate through our tool so you can see that the subject alt name in the 138 00:14:16,000 --> 00:14:22,960 certificate includes www.draytech.com. And this is a terrible idea to do, right? To say that 139 00:14:22,960 --> 00:14:35,400 the subject alt name for this device is on the, here I'm showing that we are setting up the 140 00:14:35,420 --> 00:14:47,500 substituting. The here I want to replay that. I think I have time to do this. Sorry, my 141 00:14:47,500 --> 00:14:51,500 explanation is a little slow. So you can see we're going to replace words like manage, 142 00:14:51,580 --> 00:14:56,940 management, VPN with the word hacked, right? That's what MITM proxy is going to do for us. So 143 00:14:56,940 --> 00:15:04,380 we're running MITM proxy here. And so this victim is visiting draytech.com and first he's going 144 00:15:04,380 --> 00:15:05,160 to bring up his favorite. 145 00:15:05,420 --> 00:15:09,980 Search engine DuckDuckGo and look up draytech and then we're going to visit it. This is the 146 00:15:09,980 --> 00:15:18,860 victim's view at this point. And so, you know, we'll visit draytech and we're surprised to see 147 00:15:18,860 --> 00:15:25,740 that our man in the middle proxy is working and the, we are intercepting the traffic and 148 00:15:26,560 --> 00:15:33,700 replacing the, you know, we're revealing hacked routers and hacked switches and whatnot, right? 149 00:15:33,820 --> 00:15:34,000 So. 150 00:15:35,420 --> 00:15:47,380 So don't ever put the, your, your vendor URI in the subject alt name if you're going to have a 151 00:15:47,380 --> 00:15:51,840 cheap device generate the certificate. That's one of the things that you shouldn't do. The other 152 00:15:51,840 --> 00:16:01,800 thing you shouldn't do is have weak entropy, right? So, hopefully that attack made sense. And I 153 00:16:01,800 --> 00:16:04,560 want to conclude the presentation. 154 00:16:05,640 --> 00:16:14,660 With a few thoughts here. Batch testing is practical and effective. And, you know, Dan Bernstein and 155 00:16:14,660 --> 00:16:20,000 Nadia Henninger showed that this stuff was a problem ten years ago, but we wanted to democratize this a 156 00:16:20,000 --> 00:16:27,280 little bit by making a full set of tools available. And we found in our work that showing 157 00:16:27,280 --> 00:16:34,160 somebody an exploit is, you know, often necessary to get them to understand that yes, an exploit is 158 00:16:34,160 --> 00:16:34,520 possible. 159 00:16:37,260 --> 00:16:43,020 So, for future work, you know, we'd like to detect more failure modes. There's, you know, the, the two 160 00:16:43,020 --> 00:16:51,920 major ones we found now, but there's other failure modes, weak keys, especially with RSA. And we're 161 00:16:51,920 --> 00:16:56,560 working on analyzing a large batch of manufacturing certificates and we hope to share that 162 00:16:56,560 --> 00:17:04,980 information soon when we can. And I want to mention that you can download the, the software tools and 163 00:17:04,980 --> 00:17:11,640 documentation at a bit.com. That's great. So, on GitHub.com slash Cisco slash Mercury, please look 164 00:17:11,640 --> 00:17:18,700 in the, in the documentation directory for the batch GCD file, which has the, the instructions about 165 00:17:18,700 --> 00:17:26,600 the, the main tool here. And, you know, if I could, you know, make a shout out for people who like to do 166 00:17:26,600 --> 00:17:34,960 crypto attacks. As the industry evolves away from RSA towards a, other potential, maybe a better 167 00:17:34,980 --> 00:17:40,140 crypto algorithms, it's gonna make it harder to detect weak entropy problems, but it is not 168 00:17:40,140 --> 00:17:45,060 gonna make the weak entropy problem go away, right? So, this is a very real thing, right? We 169 00:17:45,060 --> 00:17:51,740 should be looking for other ways that we can convict devices that have weak entropy. So, that 170 00:17:51,740 --> 00:17:54,820 concludes our presentation for today. Thank you so much for your attention.