00:00:00.000-->00:00:06.406 >>Hi everyone, my name is Nils. Uh I’m from Switzerland uh I came today with my colleague 00:00:06.406-->00:00:11.411 Yolan, uh, we are in the research team at Kudelski Security. Uh I like to fish and 00:00:13.513-->00:00:18.518 I’m really into video games. Um. And we are going to talk about collecting public keys and uh 00:00:24.324-->00:00:29.329 breaking them at scale. So who has a public key on GitHub, GitLab or uh has pushed a PGP 00:00:34.668-->00:00:39.673 key on a key server. Raise your hands. >>Yeah, SSH key, PGP key, everything. Ok, so a lot of 00:00:43.076-->00:00:49.850 people. So what if I told you uh those who raised your hands, we have your key? So far, so good. 00:00:49.850-->00:00:54.855 Uh nothing to worry about, right? Um so now what if I told you we could actually break 00:00:58.692-->00:01:03.630 those keys and retrieve the private key out of your public key? Sounds more fun right? And 00:01:05.832-->00:01:10.837 uh so if we can do it, guess who can do it too? Like NSA, uh that’s easy peasy for them 00:01:14.875-->00:01:22.616 right? So one question remains, uh, how do you retrieve the private key out of the public 00:01:22.616-->00:01:30.891 key? Yolan. >>Well that’s a really good question Nils. So I’m a math guy, so I’ll do a 00:01:30.891-->00:01:37.130 little you know Crypto recap first. So most keys out there are using the RSA crypto 00:01:37.130-->00:01:44.938 systems. So RSA is really simple. You just need to take two large prime numbers. Ok. 00:01:44.938-->00:01:51.445 That slide is a bit dry. It won’t do it. Two large prime numbers. Much easier. So you 00:01:51.445-->00:01:58.986 take P and Q, prime. Really large. 2-->000 or more bits, you tally it. You multiply them 00:01:58.986-->00:02:05.759 together. Awesome. You get N. That is your public models. It’s your public key. And the 00:02:05.759-->00:02:14.001 security of RSA is all based on the fact that you cannot easily factor N into P and Q, it’s 00:02:14.001-->00:02:23.744 really hard to factor large um numbers. And so first uh you get your private key P and Q and you 00:02:23.744-->00:02:31.418 publish the N outside on GitHug, PGP, whatever. But what happens if somebody else generated 00:02:31.418-->00:02:40.961 another public key M. Using the same prime prime Q as you did? So let’s do as a key Q times R 00:02:40.961-->00:02:49.736 equal to M. You can actually really easily find the greatest common divisor of both N and M. 00:02:49.736-->00:02:55.575 That everybody learned at school that logarithm that’s easy peasy. So that’s really bad for 00:02:55.575-->00:03:03.383 RSA. Now you’re all done, yeah, everybody says no good. There are other fun crypto system out 00:03:03.383-->00:03:08.855 there like you know elliptic curve cryptography. An elliptic curve cryptography does not rely 00:03:08.855-->00:03:18.065 on the hardness of the factoring um of large integers. It relies instead of the hardness of 00:03:18.065-->00:03:23.970 solving solving the discrete logarithm problem, um it is not impacted by having a lot of 00:03:23.970-->00:03:30.744 keys. Unlike for RSA where you can just try to batch factor all the public keys out there. And 00:03:30.744-->00:03:37.884 uh so elliptic curve cryptography are more secure outside than RSA against large 00:03:37.884-->00:03:44.858 scale attacks like these we tried, but we’ll also be talking about a bit about ECC at the end 00:03:44.858-->00:03:53.133 of our talk. So what kind of attacks can we include against public keys? We want to remind 00:03:53.133-->00:03:57.804 silence you know we don’t want to take a branch and go hit the guy to ask him for his password. 00:03:57.804-->00:04:03.910 You will not ti-, he will remark, you know you will ha- why do you hit me. So we try we 00:04:03.910-->00:04:08.148 can try to use a copper- the Return of the Coppersmith’s Attack. Which was like last 00:04:08.148-->00:04:16.523 year, smartcurves were generating uh bad primes and you could easily, what, too easily 00:04:16.523-->00:04:25.132 factor the produce um integers. So another problem you can have is invalid parameters in DSA for 00:04:25.132-->00:04:32.272 example or if you take a too small key size for your ECC or DSA or even for RSA if you take 00:04:32.272-->00:04:38.712 a hundred bits. Um prime, it’s no good. You can easily factor those. Invalid curve attack is a 00:04:38.712-->00:04:44.818 thing, but we’ll see later it’s not a thing. So in the end, the one we really talking about 00:04:44.818-->00:04:50.457 today is RSA modulus factorization at scale, so it means we do it, we’re doing 00:04:50.457-->00:04:56.129 batch GCD. Batch GCD as actually being done in the past by academics. And it was done at 00:04:56.129-->00:05:04.037 academic scale, so on- se- that stuff maybe 10 million keys, 20 million keys, 18 million keys, 00:05:04.037-->00:05:09.843 we did it at scale a much larger scale. These are all known attacks. Anybody can do it and 00:05:09.843-->00:05:18.485 they are completely passive. You won’t even know if you are vulnerable to these. So Nils how 00:05:18.485-->00:05:31.464 do we collect these keys? >>So, hmm. Keys are public keys are everywhere and we have focused 00:05:31.464-->00:05:37.070 on the three most common key container types and namely uh certificates. So X 509 00:05:37.070-->00:05:43.543 certificates to confining https for instance uh SSH keys and PGP keys and we have found quite a 00:05:43.543-->00:05:49.416 few interesting results and also a few crazy things. Uh that we will talk about later in this 00:05:49.416-->00:05:56.189 talk and for example uh as you know certificates have uh validity period. So it’s 00:05:56.189-->00:06:02.162 supposed to start being validated at some point and expire at later dates. And some 00:06:02.162-->00:06:11.171 certificates actually have uh negative validity period, I mean, why would you do that? Um 00:06:11.171-->00:06:19.145 most keys we have come from certs, um, about 70 percent of data assets came from 00:06:19.145-->00:06:24.718 certificates so that’s about 240 million keys. You also have 90 million SSH keys and about 10 00:06:24.718-->00:06:35.729 million PGP keys uh in our database. Those certs most come from https scans that we perform 00:06:35.729-->00:06:43.737 using a custom tool that we’ll talk about later and um SSH keys mostly came from a study that 00:06:43.737-->00:06:51.378 was made by CroCS. Uh those guys generated a lot of SSH keys with multiple, softer libraries and 00:06:51.378-->00:06:58.585 smart cards and um they tried to see if there were any vulnerabilities in those libs. 00:06:58.585-->00:07:05.859 We were able to validate their results. Namely we found uh just as they did that one of the 00:07:05.859-->00:07:13.500 smart card model was generating uh keys with common factors so that was to really bad. Um and 00:07:13.500-->00:07:24.577 also PGP keys for most of those keys came from the pool of SKS key servers. Um. so why it is 00:07:24.577-->00:07:30.650 interesting to actually have as many public keys as we can. So when you run batch TC and RSA 00:07:30.650-->00:07:38.658 keys, you you’re looking for um common factors right? So the more keys you have, the more 00:07:38.658-->00:07:44.631 chances there are of having two keys with a common factor in the data sets so at this is why it’s 00:07:44.631-->00:07:50.203 good to have as many as possible. And we currently have over 340 million keys. This is 00:07:50.203-->00:07:56.276 still growing. We’re still adjusting keys from uh certi- uh certificate transparency. So 00:07:56.276-->00:08:01.915 this is a project that was initiated by Google. And it’s basically a pool of lock servers 00:08:01.915-->00:08:07.120 where you can get certificates. So we can grab the keys from there. And also uh from those uh 00:08:07.120-->00:08:15.729 lock servers were were able to collect uh a list of 270 million domain names and sub-domains. Uh 00:08:15.729-->00:08:23.336 you can do a lot of stuff with that. >>Yeah it’s way more dynamics at the quantium. >>Oh 00:08:23.336-->00:08:34.314 yeah. Um so we found that today RSA is still the most common key type. 95 percent of keys are 00:08:34.314-->00:08:42.055 still RSA. So roca attack, and bach GCD is targeting that so be careful. Um EC keys are getting 00:08:42.055-->00:08:48.628 more popular and this is basically what I guess you should start using today. And um 00:08:48.628-->00:08:55.468 then we still have some DSA keys I mean, who uses that anyway today? And a few other lessfull 00:08:55.468-->00:09:05.612 known. A few words about tools. Uh so we’ve been using a tool that was developed by one of our 00:09:05.612-->00:09:12.685 colleagues. It’s called Scannerl. So it’s not just um network scanner. It’s also a 00:09:12.685-->00:09:18.858 fingerprinting engine. It’s written in erlang. It’s open source, it’s on GitHub, you can 00:09:18.858-->00:09:24.264 download it today. Uh our parsers are mostly written in Python. Uh we also have some go 00:09:24.264-->00:09:30.403 and get code and uh some batch scripts in there. Uh the code will be open open source on 00:09:30.403-->00:09:36.376 GitHub. It is available today. We have the link at the end of this presentation. And we also 00:09:36.376-->00:09:45.218 have been using apache nifi to define some um data pipelines that we use to ingest the keys 00:09:45.218-->00:09:50.690 in our database. Um that database is stored in HDFS and we use Presto to run it’s 00:09:50.690-->00:10:00.600 queries on the datasets. Uh then for breaking keys so we now that we have them in our database, um 00:10:00.600-->00:10:09.542 we actually wrote a tool that is written in chapel to um compute the batch GCD of all of those 00:10:09.542-->00:10:17.951 keys so basically computing the GCD between every pair of RSA models in there. And this is a 00:10:17.951-->00:10:22.689 distributed implementation so it basically scales, you can throw more machines at it. It’s 00:10:22.689-->00:10:31.164 constant in memory, uh you can you if you just need to be faster, just add more machines. 00:10:31.164-->00:10:36.336 We also check for the roca attack through the rocaton and uh we run some checks in EC keys 00:10:36.336-->00:10:49.482 like invalid primaries uh key lengths and so on. So we have a short demo for you. So here we 00:10:49.482-->00:10:57.790 have two SSH public keys. AK1 dot pub, AK2 dot pub. We run a script that extracts the RSA 00:10:57.790-->00:11:04.230 models from that keys, computer the GCD and since the GCD is larger than one, we can retrieve 00:11:04.230-->00:11:13.506 the private key. Um then we just copy paste that key to a file. Push the original public key to 00:11:13.506-->00:11:24.717 a test machine, just for testing if we can login with via SSH tuit.. Now the the keys on 00:11:24.717-->00:11:33.593 there, we can try to login via SSH using the private key we just reconstructed. >>And guess 00:11:33.593-->00:11:47.740 what, we’re in. >>Boom. That machine has been prone. [applause] So here what we did 00:11:47.740-->00:11:53.479 is we just computed the GCD between two keys for the example, but we actually did is 00:11:53.479-->00:12:01.187 the GCD between old key pairs and we have made a website that you can go today. It’s on key 00:12:01.187-->00:12:05.525 look up kudelski security dot com. You can upload your key and get it uh stood against our own 00:12:05.525-->00:12:13.233 data assets. [laughter] >>We promise we’ll tell you you if we find your private key. >>Yeah, 00:12:13.233-->00:12:21.274 don’t uh do not push the private key. We will find it. [laughter] So basically it looks like this 00:12:21.274-->00:12:27.046 you just have a forum where you can copy paste an SSH key, a cert or a PGP key. You hit 00:12:27.046-->00:12:33.853 submit and um what you may see is that either the keys already in our database, so we can give 00:12:33.853-->00:12:39.559 you an answer immediately or we will add it to processing queue. And you can just recheck later 00:12:39.559-->00:12:47.166 and it will tell you whether it is vulnerable or not. Uh within about an hour. So how does that 00:12:47.166-->00:12:55.308 work behind the scenes? [laughter] >>Yeah, you know, we have a corporate policy saying 00:12:55.308-->00:13:03.249 no bit code mining. So we had to find something to do. [laughter] >>Yeah so we had to use that uh 00:13:03.249-->00:13:12.825 280 vCPU cluster and um uh make it to good use. So uh we also have about 2 terabytes of 00:13:12.825-->00:13:19.766 storage required because we have to uh have some intermediate computations for the batch GDC 00:13:19.766-->00:13:25.338 so that we can reuse the the calculations and do not recompute everything when we 00:13:25.338-->00:13:31.177 just want to test new keys against a full dataset. So we just recompute whatever changes 00:13:31.177-->00:13:37.417 and we don’t have to recompute everything. And if we test just like one more key, it would take 00:13:37.417-->00:13:42.355 maybe 10 to 20 minutes. 30 keys at once is about an hour and if you want to check a large um 00:13:42.355-->00:13:52.198 batch of keys like 5 million keys it can it can take up to 24 hours. Um that data is stored on 00:13:52.198-->00:13:58.471 HDFS we have a 10 data node cluster a we used to partitioned Presto tables to have fast 00:13:58.471-->00:14:05.745 lookups. And uh Scannerl is deployed on 50 machines so we scan from 50 different IP 00:14:05.745-->00:14:15.221 addresses at once. >>That’s a really nice Kamen Infrastructure >>[laughs] So Yolan uh what good 00:14:15.221-->00:14:27.433 results and cool stuff have we found? >>Well we’ve broken a few keys like you know 210-->000 keys. 00:14:27.433-->00:14:33.339 Most of them were certificates but some of are actually used today so we could perform man in 00:14:33.339-->00:14:41.280 the middle attacks against these websites really easily and passively. And 3-->000 SSH keys 00:14:41.280-->00:14:46.385 and most of them post keys so it will mean it’s a low for man in the middle attacks again. But if 00:14:46.385-->00:14:51.858 you’re using a SSH key on your little page and we broke it, maybe your using the same SSH 00:14:51.858-->00:14:59.098 key on your back, you know? You shouldn’t do that. And PGP keys that’s bad because it means we 00:14:59.098-->00:15:05.505 can decrease what we wrote you what we can sign message instead of you and so on, so that’s 00:15:05.505-->00:15:11.744 really bad. Uh what’s fun with PGP keys is that a lot of the keys we’ve broke were actually 00:15:11.744-->00:15:17.383 more than 2 factors so that’s actually saving your day if your key is not just using 2 primes 00:15:17.383-->00:15:21.988 but 3 primes. Uh and it’s really strange because it’s not something that common in 00:15:21.988-->00:15:30.530 implementations to have 3 prime numbers. >>So roca attack, we actually found a PGP keys we 00:15:30.530-->00:15:35.902 were able to roca attack on Keybase, Github, Gitlab, everywhere. So double check your 00:15:35.902-->00:15:42.875 key, you can check them using Python scripts offline and on your computer or using your Q 00:15:42.875-->00:15:51.050 kept websites. And roca is not that bad because if your key is in the two third that have 4-->000 00:15:51.050-->00:15:58.658 bits, you’re still save. It will take way too long to actually compute primes out of the public 00:15:58.658-->00:16:09.502 key. But if you’re on the weak side, like you know 2-->000 bits. Eh, it’s feasible. And you know 00:16:09.502-->00:16:16.776 routers they add random at sites, well they still do. A lot of routers we’ve seen uh since 00:16:16.776-->00:16:26.586 2017 eh um, common factors, so some of them may be even broken, um, you know common things are 00:16:26.586-->00:16:36.062 certificates, like who is using that comr. And in 2015 after according to our historical uh 00:16:36.062-->00:16:42.535 scan data, a lot of D-Link routers were in problem and that’s fun because uh previous 00:16:42.535-->00:16:48.741 study done in 2016 about batches found a problem and they got it batched. That’s nice, um few 00:16:48.741-->00:16:59.485 certificates are not valid before 2014. What. What wait. Uh I’ll may be a quantum computer 00:16:59.485-->00:17:05.858 by then. Why will you do that? Bad idea. Um ECC keys on the other end are getting more and 00:17:05.858-->00:17:13.900 more um used in practice which is good. Uh certificates in PGP mostly are using it more and 00:17:13.900-->00:17:22.441 more and SSH most um the most use curve is still the sec- uh used curve. Which is not bad per 00:17:22.441-->00:17:29.515 say, but uh curve 200 and ug 55 19 is growing. It’s in third position right now but maybe 00:17:29.515-->00:17:36.689 next year it will be second. Uh it still has a bit to go you know before being first. So more 00:17:36.689-->00:17:43.963 and more uh ECC keys I said so when we scan EC keys and new keys were always you know in the 00:17:43.963-->00:17:51.237 same amount we found always same amount of new keys. But for ECC we are finding more and more ECC 00:17:51.237-->00:17:58.177 keys and that’s really good and actually less encrypt will soon be able to issue a full uh uh 00:17:58.177-->00:18:08.220 ECC based um um se- certificate chain so it’s called. And now what if I told you that some 00:18:08.220-->00:18:17.229 people are using their SSH to send encrypted PGP mails. That sound strange, no? But people 00:18:17.229-->00:18:26.806 do. We found keys that are reused as both PGP and SSH or as both SSH and x 509 certificates 00:18:26.806-->00:18:32.345 which is completely insane. Doesn’t make sense. You should just generate new keys no? Um 00:18:32.345-->00:18:39.051 most people using PGP only one step key. Why? Just a multiple you know so if one step key is 00:18:39.051-->00:18:45.658 broken you can still even those are one uh to save your a*s. And some of the keys we’ve found 00:18:45.658-->00:18:53.766 were add more than two factors. Most of them were PGP I already told so um DSA is dead. OpenSSL 00:18:53.766-->00:19:00.539 deprecated in 2015 three years ago. And now it is only like 3-->000 certificates we’re still 00:19:00.539-->00:19:08.481 using in a DSA as a logarithm. And less than 1 percent of SSH key were uh DSA based, so that’s 00:19:08.481-->00:19:15.354 really good. And if you’re still using still using DSA, stop. So DSA some people were using 256 00:19:15.354-->00:19:25.765 bits keys which doesn’t make sense. So we just stop DSA. So in the end mind your keys 00:19:25.765-->00:19:32.905 because anybody can do this same kind of silent attacks and maybe they already do. Thank you for 00:19:32.905-->00:19:36.909 your attention today. If you have questions we’ll be outside or you can hit on the on the 00:19:36.909-->00:00:00.000 twitter also. And um thank you. [applause]