Hi everyone, my name is Nils. I'm from Switzerland. I came today with my colleague Yolan. We are in the research team at Kudelsky Security. I like to fish and I'm really into video games. And we are going to talk about collecting public keys and breaking them at scale. So, who has a public key on GitHub, GitLab, or has pushed a PGP key on a key server? Raise your hand. SSH key, PGP key, everything. Okay, so a lot of people. So, what if I told you, those who raised your hand, we have your key. So far, so good. Nothing to worry about, right? So, now, what if I told you we could actually break those keys and retrieve the private key out of your public key? Sounds more fun, right? And so, if we can do it, guess who can do it too? Like NSA. That's easy peasy for them, right? So, one question remains. How do you retrieve the private key out of the public key, Yolan? Well, that's a really good question, Niels. So, I'm a math guy. So, I'll do a little, you know, crypto recap first. So, most keys out there are using the RSA crypto systems. So, RSA is really simple. You just need to take two large prime numbers. Okay, that slide is a bit dry. It won't do it. Two large prime numbers. Much easier. So, you take P and Q prime, really large, 2000 or more. So, you take two large prime numbers. You multiply them together. Awesome. You get N. That is your public monolith. It's your public key. And the security of RSA is all based on the fact that you cannot easily factor N into P and Q. It's really hard to factor large numbers. And so far, so good. So, you get your private key P and Q and you publish the N outside. On GitHub, PGP, whatever. But what happens if somebody else generated another public key M using the same prime Q as you did? So, let's say he has a key Q times R equal to M. You can actually really easily find the greatest common divisor of both N and M. That's everybody learned. That's called Euclid's algorithm and that's easy peasy. So, that's really bad for everybody. So, let's talk about RSA. Now, you will tell me, ah, RSA is no good. There are other fun cryptosystems out there like, you know, elliptic curve cryptography. And elliptic curve cryptography does not rely on the hardness of the factoring of large integers. It relies instead on the hardness of solving the discrete logarithm problem. And it is not impacted by having a lot of keys. Unlike for RSA where you can just try to batch factor all the public keys out there. And so, elliptic curve cryptography are more secure outside than RSA against large scale attacks like these we tried. But we'll also be talking a bit about ECC at the end of our talk. So, what kind of attacks can we actually do against public keys? We want to remain silent. You know, we don't want to... If you take a branch and go hit the guy to ask him for his password, he will not type. He will remark. You know, he will, ah, why do you hit me? So, we can try to use the return of the Copper-Smith attack, which was like, last year, smart curves were generating bad primes. And you could easily, well, too easily factor the produced integers. So, another problem you can have is invalid parameters in DSA. For example, or if you take a too small key size for your ECC or DSA or even for RSA, if you take 100 bits prime, it's no good. You can easily factor those invalid curves attack or also sing, but we'll see later. It's not a thing, actually. So, in the end, the one we're really talking about today is RSA model factorization at scale. So, it means we are doing batch GCD. Batch GCD has actually already been done in the past. It was done in the past by academics, but it was done at academic scale. So, on data sets of maybe 10 million keys, 20 million keys, 80 million keys, we did it at scale, at a much larger scale. These are all known attacks. Anybody can do it. And they are completely perceived. You won't even know if you are vulnerable to these. So, Niels, how do we collect these keys? So, so, keys are, public keys are everywhere. And we have focused on the three most common key container types and namely certificates. So, X509 certificates you can find in HTTPS, for instance, SSH keys and PGP keys. And we have found quite a few interesting results and also a few crazy things that we will talk about later in this talk. And for example, as you know, certificates have, a validity period. So, it's supposed to start being valid at some point and expire at a later date. And some certificates actually have a negative validity period. I mean, why would you do that? Most keys we have come from certs. About 70% of our data sets came from certificates. So, that's about 240 million keys. We also have 90 million SSH keys. And about 10 million PGP keys in our database. Those certs mostly come from HTTPS scans that we perform using a custom tool that I will talk about later. And SSH keys mostly came from a study that was made by Crocs. Those guys generated a lot of SSH keys with multiple software libraries and smart cards. And, um, they tried to see if there were any vulnerabilities in those LIBs. We were able to validate their results. Namely, we found, just as they did, that one of the smart card model was generating keys with common factors. So, that was really bad. And also PGP keys, so most of those keys came from the pool of SKS key servers. So, why is it interesting to actually have as many public keys as we can? So, when you run batch GCD and RSA keys, you are looking for common factors, right? So, the more keys you have, the more chances there are of having two keys with a common factor in the data set. So, this is why it's good to have as many as possible. And we currently have over 340 million keys. This is still growing. We are still ingesting keys from certs. Certificate transparency. So, this is a project that was initiated by Google and it's basically a pool of log servers where you can get certificates. So, we can grab the keys from there. And also, from those log servers, we were able to collect a list of 270 million domain names and subdomains. You can do a lot of stuff with that. Yeah, it's way more than Annex Satop 1 million. Oh, yeah. So, we found that today RSA is still the most common key type. 95% of keys are still RSA. So, ROCA attack and batch GCD is targeting that. So, be careful. EC keys are getting more popular and this is basically what I guess you should start using today. And then we still have some DSA keys. I mean, who uses that anyway today? And a few other less well-known. A few words about tools. So, we've been using a tool that was developed by one of our colleagues. It's called Scanner. So, it's not just a network scanner. It's also a fingerprinting engine. It's written in Erlang. It's open source. It's on GitHub. You can download it today. Our parsers are mostly written in Python. We also have some golden code and some bash scripts in there. The code will be open source on GitHub. It is available today. We have the link at the end of this presentation. And we also have been using Apache NiFi to define some data pipelines that we use to ingest the keys in our database. That database is stored in HDFS and we use Presto to run SQL queries on the dataset. Then for breaking keys. So, now that we have them in our database, we actually wrote a tool that is written in Chappell to compute the batch GCD of all of those keys. So, basically computing the GCD between every pair of RSA modelers in there. And this is a distributed implementation. So, it basically scales. You can throw more machines at it. It's constant in memory. If you just need it to be faster, you just add more machines. We also check for the ROCA attack, the ROCA phone. And we run some checks on EC keys like invalid parameters, key lengths, and so on. So, we have a short demo for you. So, here we have two SSH public keys. AK1.pub. AK2.pub. We run a script that extracts the RSA models from the keys, compute the GCD. And since the GCD is larger than one, we can retrieve the private key. Then we just copy paste that key to a file. Push the original public key to a test machine just for testing if we can log in via SSH to it. Now that the key is on there, we can try to log in via SSH using the private key we just reconstructed. And guess what? We're in. Boom. That machine has been prone. So, here what we did is we just computed the GCD between two keys for the example. But what we actually did is... The GCD between all key pairs. And we have made a website that you can go today. It's on keylookup.kudeskisecurity.com. You can upload your key and get it tested against our own data sets. We promise we'll tell you if we find your private key. Yeah, do not push the private key. We will find it. So, basically it looks like this. You just have a forum where you can copy and paste. You can copy and paste an SSH key, a cert or a PGP key. You hit submit. And what you may see is that either the key is already in our database so we can give you an answer immediately or we will add it to the processing queue. And you can just recheck later and it will tell you whether it is vulnerable or not within about an hour. So how does that work behind the scenes? Yeah. Yeah. You know, we have a corporate policy saying no Bitcoin mining so we have to find something to do. Yeah. So we had to use that 280 vCPU cluster and make it to good use. So we also have about two terabytes of storage required because we have to have some intermediate computations for the batch GCD so that we can reuse the calculations. And do not recompute everything when we just want to test new keys against the full data set. So we just recompute whatever changes and we don't have to recompute everything. And if we test just like one more key, it would take maybe 10 to 20 minutes. 30 keys at once is about an hour. And if you want to check a large batch of keys, like five million keys, it can take up to 24 hours. Yeah. So the data is stored in HDFS. We have a 10-data node cluster. We use partitioned Presto tables to have fast lookups. And the scanner is deployed on 50 machines so we scan from 50 different IP addresses at once. That's a really nice scanning infrastructure. So Yolan, what good results and cool stuff have we found? Well, we've broken a few keys, like, you know, 210,000 keys. Most of them were certificates, but some of them are actually in use today. So we could perform man-in-the-middle attacks against these websites really easily and passively. 3,000 SSH keys, most of them host keys, so it will mean it's allowing for man-in-the-middle attacks again. Yeah. It's not that if you are using an SSH key on your GitHub page and we broke it, maybe you're using the same SSH key on your box, you know? You shouldn't do that. PGP keys, that's bad because it means we can decrypt what you wrote. We can sign message instead of you and so on. So that's really bad. What's fun with PGP keys is that a lot of the keys we've broke were actually having more than two factors. So that's actually saving your day if your key is not just using one. It's using two primes, but three primes. And it's really strange because it's not something that common in implementations today to have three prime numbers. So Rokka attack, we actually found PGP keys vulnerable to Rokka attack on Keybase, GitHub, GitLab, everywhere. So double check your keys. You can check them using Python scripts offline on your computer or using our Keylookup website. Rokka is not that bad. Because if your key is in the two-thirds that take 4,000 bits, you're still safe. It will take way too long to actually compute the primes out of the public key. But if you are on the weak side, like, you know, 2,000 bits, it's feasible. You know, routers, they have bad randomness, we say. Well, they still do. A lot of routers. We've seen. Since 2017, they've common factors. So some of them have even broken, you know, common things or certificates, like who is using .com R. In 2015, according to our historical scan data, a lot of data link routers were having problems. And that's fun because the previous study done in 2016 about batch CCD found that the problem and they got it patched. That's nice. A few certificates are not valid before 2040. What? Wait. I'll maybe have a quantum computer by then. Why will you do that? Bad idea. ECT keys, on the other hand, are getting more and more used in practice, which is good. Certificates on PGP mostly are using it more and more. And SSH. The most used curve is still a SEC, yeah, a NIST curve, which is not bad per se. But curve 255.19 is growing. It's in third position right now, but maybe next year it will be second. It still has a bit to go, you know, before being first. So more and more ECT keys, I said. So when we scan RSA keys, new keys were always, you know, in the same. Amount. We found always the same amount of new keys. But for ECC, we are finding more and more ECT keys. And that's really good. And actually, Let's Encrypt will soon be able to issue a full ECC-based certificate chain. So it's cool. Now what if I told you that some people are using their SSH key to send encrypted PGP mails? That sounds strange. Not bad. People do. We've found keys that are reused as both PGP and SSH or as both SSH and X.509 certificates, which is completely insane. It doesn't make sense. You should just generate new keys, you know. Most people using PGP have only one subkey. Why? Just multiple, you know. So if one of the subkey is broken, you can still have another one to save your ass. Some of the keys we found were at more than two factors. Most of them were PGP, I already told you, and DSA is dead. OpenSSL de-bracketed it in 2015, three years ago. And nowadays, only like 3,000 certificates were still using DSA as a signature algorithm. And less than 1% of SSH key were DSA-based. So that's really good. And if you're still using DSA, stop. So. DSA, some people were using 256-bit keys, which doesn't make sense. So yeah, just stop using DSA. So in the end, mind your keys, because anybody can do the same kind of silent attacks. And maybe they already do. Thank you for your attention today. If you have questions, we'll be outside, or you can hit on Twitter or so. And thank you. And I'll see you guys next time.