1 00:00:04,200 --> 00:00:13,660 hello everyone thank you for sticking with us that late in the day so my name is Niels I'm a 2 00:00:13,660 --> 00:00:21,360 security researcher at Kudelsky security I focus on privacy and I like to process large data sets 3 00:00:21,360 --> 00:00:31,260 and I'm a huge Linux fan and today I'm also here with my colleague Marco hello Marco Macchetti I 4 00:00:31,260 --> 00:00:38,320 work as a cryptographer for Kudelsky security and my background is other design cryptanalysis and 5 00:00:38,320 --> 00:00:44,620 applied cryptography in general so what are we going to talk about today this is a new attack 6 00:00:44,620 --> 00:00:51,020 that we devised against an algorithm to generate digital signatures which is called ecdsa and 7 00:00:51,020 --> 00:00:58,420 it's well known for being the digital signature argued beyond the Bitcoin blockchain this attack 8 00:00:58,420 --> 00:01:02,440 is called polynons and we will give you some details of the attack and the things we tried 9 00:01:02,440 --> 00:01:07,680 to put it in practice how we did it and what we learned in the process and there will be a brief 10 00:01:07,680 --> 00:01:15,180 demo and then we will give also some results and takeaways let's add over to the introduction what 11 00:01:15,180 --> 00:01:20,800 is a digital signature well basically a digital signature is just a proof of knowledge of a private 12 00:01:21,020 --> 00:01:27,320 key right everyone can verify your signatures with your public key but only you can generate 13 00:01:27,320 --> 00:01:33,100 signatures with the private key so in a real world your signature on a piece of paper is a 14 00:01:33,100 --> 00:01:37,480 proof of identity in the digital world the knowledge of your private key is a proof of 15 00:01:37,480 --> 00:01:44,260 identity and on blockchains the private key means ownership of the coins so everyone will try to 16 00:01:44,260 --> 00:01:50,360 steal your key uh if it's on backups paper notes brain wallets and sometimes it's it's a strong key 17 00:01:51,020 --> 00:01:59,460 to protect it with a weak password uh digital signatures are mildly complex objects uh signature 18 00:01:59,460 --> 00:02:05,440 argument is is actually a set of three arguments you have key generation signature generation and 19 00:02:05,440 --> 00:02:12,940 verification is there randomness inside all of this well yes essentially key generation is uh 20 00:02:12,940 --> 00:02:19,440 throwing the dice to obtain your keeper and randomness is also present in the signature 21 00:02:19,440 --> 00:02:20,380 generation process 22 00:02:21,020 --> 00:02:25,540 your private key and the message you throw the dice again and you obtain a signature and verification 23 00:02:25,540 --> 00:02:31,800 is just a deterministic algorithm well if everyone wants your private key is it possible to obtain 24 00:02:31,800 --> 00:02:37,440 your private key just by looking at the signatures well in general no but under some assumption yes 25 00:02:37,440 --> 00:02:43,200 for example if you generated the key with low entropy or with short seeds or using a brain 26 00:02:43,200 --> 00:02:49,000 wallet maybe it's easy to guess but provided that the key is properly generated is it possible to 27 00:02:49,000 --> 00:02:50,800 obtain it uh from 28 00:02:51,020 --> 00:02:55,580 your signatures well remember there is randomness in the signature generation so there is more attack 29 00:02:55,580 --> 00:03:01,880 surface that we can explore in this paper we we target the ecdsa algorithm this is probably the 30 00:03:01,880 --> 00:03:07,640 mostly deployed algorithm for digital signatures ec is for elliptic curve and elliptic curves is 31 00:03:07,640 --> 00:03:12,820 just a curve on a finite field with some parameters you all know the Bitcoin curve 32 00:03:13,500 --> 00:03:18,900 and the curve is also a set of points you can perform operation with the points you can add the 33 00:03:21,020 --> 00:03:25,740 numbers as a scalar this is called scalar point multiplication and why it is so useful because 34 00:03:25,740 --> 00:03:30,900 scalar point multiplication it's easy to do in one direction but it's hard to invert and this 35 00:03:30,900 --> 00:03:35,980 is called the discrete logarithmic problem and this is the basis of the security for ecdsa 36 00:03:37,220 --> 00:03:44,340 so what is in detail the the set of algorithms for ecdsa well key generation is quite simple 37 00:03:44,340 --> 00:03:49,840 you just pick an integer D in a certain range and this is your private key and the public key you 38 00:03:49,840 --> 00:03:50,840 just obtain it through 39 00:03:51,020 --> 00:03:56,860 scalar point multiplication to generate a signature you hash the message first and then again you have 40 00:03:56,860 --> 00:04:02,580 to pick an integer in uh in the same range again uniformly at random and this is called the nonce 41 00:04:02,580 --> 00:04:08,620 and you have to to have a different noise nonce for each signature then the the signature is just 42 00:04:08,620 --> 00:04:14,780 two numbers R and S and R is just the X coordinate of the point which correspond to your nonce and 43 00:04:14,780 --> 00:04:20,620 S is obtained with the expression that is in the slide and verification is just deterministic 44 00:04:21,020 --> 00:04:26,340 so we are not very interested so the takeaway is that you also performing key generation for 45 00:04:26,340 --> 00:04:34,520 every signature basically and if the nonces can be predicted or or some beats are known then you 46 00:04:34,520 --> 00:04:40,440 can use lattice attacks and you can also use side channel attacks in combination with lattice 47 00:04:40,440 --> 00:04:46,560 attacks to retrieve the key so what you have to choose to to generate this the randomness is to 48 00:04:46,560 --> 00:04:50,680 choose your dice there are good dice like those uh 49 00:04:51,020 --> 00:04:57,140 RNGs based on cryptographic algorithms like HMAC and AES these are the good ones and then you have 50 00:04:57,140 --> 00:05:04,960 bad ones like algebraic generators LFSRs and then they are the awful ones like fixed secret constant 51 00:05:04,960 --> 00:05:10,320 the round functions and these kind of things and once you choose the dice you also have to seed it 52 00:05:10,320 --> 00:05:17,380 with entropy let's pick one of these bad RNGs the linear congruential generator this is has been 53 00:05:17,380 --> 00:05:20,520 known for decades I mean it's a it's a generator that is implemented 54 00:05:21,020 --> 00:05:27,180 basically everywhere it's in GMP other libraries and it was also referenced from the NIST 55 00:05:27,180 --> 00:05:34,360 documentation basically an LCG works in this way you generate a random number and then you apply a 56 00:05:34,360 --> 00:05:40,900 linear relation to obtain new numbers with known coefficients A and B there is no bias in this so 57 00:05:40,900 --> 00:05:46,660 it's good but in fact it has been shown by by previous projects that you can use lattice attacks 58 00:05:47,400 --> 00:05:50,640 to retrieve the private key so if your LCG is 59 00:05:51,020 --> 00:05:58,140 in full state but it's 128 bit for example for the Bitcoin curve then with as low as 22 signatures 60 00:05:58,140 --> 00:06:05,020 you can get the private key but here we want to go beyond what if you use a full state LCG 61 00:06:05,560 --> 00:06:10,960 there are no results published so far on this and what if you increase the degree to quadratic or 62 00:06:10,960 --> 00:06:15,460 even cubic then lattice attacks are not possible and what if you keep the coefficients unknown 63 00:06:15,460 --> 00:06:20,540 secret then you you may think you are safe right but in fact no we show that we've 64 00:06:21,020 --> 00:06:25,300 announced we can retrieve the private key in a fraction of a second so how does it work 65 00:06:25,300 --> 00:06:31,380 basically we don't care about the air part of the signature but we just look at the S part of 66 00:06:31,380 --> 00:06:37,800 the signature and we rewrite the expression of S to be a linear relationship between the 67 00:06:37,800 --> 00:06:44,160 nonce and the private key what does it mean it means that there is only one secret behind all 68 00:06:44,160 --> 00:06:50,140 your signatures you can think that it's the private key or you can think that is one of the nonces or 69 00:06:51,020 --> 00:06:58,520 partial information on more nonces and so we want to exploit this additional information that 70 00:06:58,520 --> 00:07:06,440 is in the S part of the signatures how can we do it basically suppose that you are you are generating 71 00:07:06,440 --> 00:07:13,720 your nonces with an LCG so you generate a first nonce K0 and then you generate K1 K2 K3 in this 72 00:07:13,720 --> 00:07:20,000 way and suppose that the attacker doesn't know A1 and A0 these are the secret coefficients 73 00:07:21,020 --> 00:07:26,120 but basically what we can do you can subtract the second equation from the first and the third from 74 00:07:26,120 --> 00:07:32,200 the second and we get this pair of equations here and then we can solve for A1 in both and 75 00:07:32,200 --> 00:07:37,860 we can just equate the results and we get this expression here and we got a completely rid of 76 00:07:37,860 --> 00:07:46,440 the unknown secret coefficients and then this is the trick we can replace every nonce in this 77 00:07:51,020 --> 00:07:55,520 way we get a polynomial which where the only unknown is D we find the roots of the polynomial 78 00:07:55,520 --> 00:08:02,780 it's easy to do and we get the private key and we extended this to all n degree polynomial 79 00:08:03,230 --> 00:08:07,940 relationships so we we are able to attack quadratic and cubic and higher degrees and 80 00:08:07,940 --> 00:08:13,020 this is a recursive algorithm it's a fast generic it's not using lattice and if you want to take a 81 00:08:13,020 --> 00:08:20,220 look there is an e-print paper on this and then I add over to nice we'll explain how we put this into practice 82 00:08:26,240 --> 00:08:34,080 thank you Marco so with all of that how can we actually attack things in practice 83 00:08:36,540 --> 00:08:43,900 well to to run the polynons attack what you will need is at least four signatures but that's for 84 00:08:43,900 --> 00:08:49,620 the linear case if you want to target a higher degree relation then you need more than four 85 00:08:49,620 --> 00:08:50,120 signatures 86 00:08:51,020 --> 00:08:57,560 in any case you'll need to make sure that these signatures are sorted by the time in 87 00:08:57,560 --> 00:09:04,740 which they have been generated on top of that you'll need to also have associated with each 88 00:09:04,740 --> 00:09:13,140 signature the message and the public key if you have all of that and the nonces were indeed 89 00:09:13,140 --> 00:09:20,680 generated in a biased way then you can retrieve the private key so where can we find 90 00:09:21,020 --> 00:09:30,480 eCDS signatures in practice well one good source of that is Bitcoin in Bitcoin you have blocks and 91 00:09:30,480 --> 00:09:36,860 inside blocks you have transactions and these transactions they contain inputs and outputs 92 00:09:36,860 --> 00:09:47,120 and good for us these inputs are signed with ecdsa so how do we get what we need well the public key 93 00:09:51,020 --> 00:09:57,400 in that input. The message, however, you have to compute it. And computing that message 94 00:09:57,400 --> 00:10:08,040 is a very error prone and under documented process. You will need to use fields from 95 00:10:08,040 --> 00:10:13,560 the current transaction but also fields from previous transactions. So you will need to 96 00:10:13,560 --> 00:10:16,300 keep track of all of that to compute the message. 97 00:10:19,620 --> 00:10:26,160 So to actually get the data, what you will need is to let your Bitcoin client sync and 98 00:10:26,160 --> 00:10:32,200 download the whole chain. And we did that. It took about a day. And we got all of the 99 00:10:32,200 --> 00:10:38,280 blocks until September last year. And when it was synced, we dumped all of the signatures, 100 00:10:38,560 --> 00:10:45,220 the pop keys, the messages by just reading the block files from disk. And we 101 00:10:45,220 --> 00:10:54,040 with that, we dumped about 700 million signatures. We only covered the most common type of Bitcoin 102 00:10:54,040 --> 00:10:59,460 signature, which is pay to public key hash signatures. But that covers more than half 103 00:10:59,460 --> 00:11:08,980 of the Bitcoin transactions. Another good source is Ethereum because transactions in 104 00:11:08,980 --> 00:11:15,200 Ethereum are also signed with ECDSA. And in that case, the signature is directed to 105 00:11:15,220 --> 00:11:23,480 directly in the transaction. The public key, not directly. But there is actually a lesser known 106 00:11:23,480 --> 00:11:32,500 feature of ECDSA called ECDSA recover that you can use to compute the public key based on the 107 00:11:32,500 --> 00:11:38,960 signature and the message plus a third value that I won't discuss but which is in the 108 00:11:38,960 --> 00:11:42,900 transaction. The message also must be computed. 109 00:11:45,220 --> 00:11:50,920 To compute the message, the main challenge here is that Ethereum has multiple protocol 110 00:11:50,920 --> 00:11:59,040 versions. And these versions change based on the block number. Meaning if you want to compute 111 00:11:59,040 --> 00:12:04,840 the message for a specific transaction, depending on what block this is, the way you compute the 112 00:12:04,840 --> 00:12:10,920 message changes. So if you want to dump all of the signatures for the whole chain, you basically 113 00:12:10,920 --> 00:12:14,400 have to implement all of these Ethereum versions of the protocol. 114 00:12:15,220 --> 00:12:20,760 So we did that. If you want to have a look at the details, please check out our code. It's on 115 00:12:20,760 --> 00:12:29,740 GitHub. To actually get the data, you'll need two things. An execution client first, such as 116 00:12:29,740 --> 00:12:36,160 GIF, and a consensus client such as Lighthouse. You let these two sync so that it downloads the 117 00:12:36,160 --> 00:12:42,680 whole chain. For us, that took about three weeks and a ton of disk space. But then we got all of 118 00:12:42,680 --> 00:12:45,200 the blocks until October last year when we did that. 119 00:12:45,220 --> 00:12:55,140 We used the JSON RPC API of the execution client to get the blocks directly parsed in JSON and 120 00:12:55,140 --> 00:13:04,120 dumped the signatures, pub keys, and messages to a file. And we dumped 1.7 billion signatures 121 00:13:04,120 --> 00:13:13,160 that way. We also had a look at two more signature ‑‑ sorry, two more sources that are not 122 00:13:13,160 --> 00:13:14,260 blockchain related. 123 00:13:16,100 --> 00:13:23,640 The first is a sample of TLS servers. So why TLS servers? Well, if you make a TLS handshake with a 124 00:13:23,640 --> 00:13:30,080 server, it's going to send you a signature. And if the key is an ACDS key, you get an ACDS 125 00:13:30,080 --> 00:13:37,000 signature. So that's what we collected. The second one is actually a set of data sets from the 126 00:13:37,000 --> 00:13:43,080 Minerva attack. These are publicly available, and these are ACDS signatures that were generated 127 00:13:43,080 --> 00:13:45,080 from TPMs. 128 00:13:45,220 --> 00:13:48,280 So you can use them to get a lot of data and a bunch of software libraries. 129 00:13:50,220 --> 00:14:00,880 So a few stats. Here at the top, you see that about 97% of Bitcoin wallets only generated three 130 00:14:00,880 --> 00:14:09,240 signatures or less. And at the bottom, for Ethereum, this is a bit less extreme, but only 77% of 131 00:14:09,240 --> 00:14:15,200 wallets generated ‑‑ well, 77% of wallets generated only a fraction of the signatures. So 132 00:14:15,220 --> 00:14:21,880 generated less than four signatures. The rest, however, so those that have at least four 133 00:14:21,880 --> 00:14:28,580 signatures, we can try to attack. And that means there's at least a few million wallets we 134 00:14:28,580 --> 00:14:35,180 can try to break with that attack. So we implemented the attack in Sage and it's a 135 00:14:35,180 --> 00:14:44,260 multi-threaded implementation. The code is out there on GitHub. So just a quick demo. So 136 00:14:44,260 --> 00:14:54,280 here, we start a TLS server, which is vulnerable. It's going to generate biased 137 00:14:55,220 --> 00:15:05,620 nonces. We capture the network traffic, dump it to a PCAP file, then we make TLS handshakes to 138 00:15:05,620 --> 00:15:14,240 that vulnerable server. We stop the capture, stop the server, and then we start the 139 00:15:14,260 --> 00:15:22,940 attack. Then we read the traffic from that PCAP file and dump the signatures, messages, and 140 00:15:22,940 --> 00:15:32,220 public keys to a CSV file. And finally, we run the attack against the signatures in that file. 141 00:15:34,640 --> 00:15:40,160 And that's it. We got the private key here. . 142 00:15:46,020 --> 00:16:00,360 So how did it go? Well, no, we didn't drive in in a new Ferrari today. Well, for Bitcoin and 143 00:16:00,360 --> 00:16:07,120 Ethereum, we used a big machine with lots of cores. And for Bitcoin, the attack ran for about 144 00:16:07,120 --> 00:16:14,240 two days. And we were able to get the private key of about 700 wallets. But for Bitcoin, the attack was 145 00:16:14,260 --> 00:16:20,280 really bad. None of these had any money on them. So it looks like someone else had drained them 146 00:16:20,280 --> 00:16:29,200 before us. For Ethereum, we processed about 20% of the input file in two days, and we only got two 147 00:16:29,200 --> 00:16:36,840 private keys. So we stopped it because we thought the cost time ratio was not really worth it. 148 00:16:37,720 --> 00:16:44,240 These two also had a zero balance here. It turns out that all of the signatures that we had in the 149 00:16:44,260 --> 00:16:50,380 last three years that we used, that were generated by these vulnerable wallets, actually had 150 00:16:50,380 --> 00:16:58,400 repeated nonces. And, of course, the poly nonce attack is also going to find repeated nonces, 151 00:16:58,500 --> 00:17:07,180 because that's just a particular case of an LCG where the last unknown coefficient is the only 152 00:17:07,180 --> 00:17:13,740 one which is non-zero, and it's equal to that repeated nonce value. But this could also have been 153 00:17:13,740 --> 00:17:22,060 found with a simpler attack. For the two others, TLS and Minerva, this was actually pretty 154 00:17:22,060 --> 00:17:29,700 quick. So just a few seconds for the TLS set we had. And for Minerva, a few hours. So you could just 155 00:17:29,700 --> 00:17:36,020 run this on a laptop. We did N equals 4, 5, and 6 signatures because it was quick. But we got no 156 00:17:36,020 --> 00:17:43,720 successful attacks there. So we wanted to see what happened in the last three years. So we 157 00:17:43,740 --> 00:17:51,500 went back to those stolen Bitcoin. And we tracked that, and we found that about 140 Bitcoins were 158 00:17:51,500 --> 00:18:01,080 stolen in total. So that's about 10 million USD at Bitcoin's peak price. We also saw that some of 159 00:18:01,080 --> 00:18:09,480 the addresses that received that stolen money had readable names in them, like one hack, one gift, 160 00:18:09,760 --> 00:18:10,720 something like this. 161 00:18:10,720 --> 00:18:20,620 And there is one idiot address that sent the money it stole to another address called 1andreas. 162 00:18:21,080 --> 00:18:26,980 And this address is owned by a guy who made significant contributions to the Bitcoin ecosystem. 163 00:18:27,500 --> 00:18:34,200 And when people found out about this in 2017, they decided to make a ton of donations to that guy. 164 00:18:34,400 --> 00:18:40,640 So it looks like the one idiot guy stole Bitcoin to give it back to this guy as a donation. 165 00:18:40,720 --> 00:18:41,740 So this is a donation for charity. 166 00:18:43,220 --> 00:18:50,980 And we also saw on some public forums that people had been saying like how many Bitcoin they stole due to 167 00:18:50,980 --> 00:18:57,180 repeated attacks, repeated nonsense attacks just publicly on the forum. Like, oh, I have collected 168 00:18:57,180 --> 00:18:58,400 seven Bitcoins so far. 169 00:19:01,540 --> 00:19:02,980 So a few takeaways. 170 00:19:04,840 --> 00:19:10,040 Make sure you don't generate signatures with a biased nonce. 171 00:19:10,720 --> 00:19:16,720 And to make sure you don't do that, you should use something that does deterministic nonce generation, 172 00:19:17,040 --> 00:19:20,440 such as deterministic ECDSA or EDDSA. 173 00:19:21,660 --> 00:19:24,920 We just barely scratched the surface here. 174 00:19:25,020 --> 00:19:30,580 So there's plenty of other areas that we didn't touch and that you could apply this attack on. 175 00:19:31,280 --> 00:19:34,000 And it's very easy for you to check your own wallet. 176 00:19:34,660 --> 00:19:36,600 You don't need to have the whole chain. 177 00:19:36,680 --> 00:19:39,540 If you just have the signatures for your wallet, 178 00:19:39,540 --> 00:19:43,560 the pub key and the message, you can run this on your laptop, basically. 179 00:19:45,460 --> 00:19:49,040 So for more research from our team, please visit our blog. 180 00:19:49,400 --> 00:19:52,240 We have more exciting research on this topic. 181 00:19:52,660 --> 00:19:57,180 And we hope that people get more secure by releasing our code. 182 00:19:57,460 --> 00:20:00,180 It's public. It's on GitHub. Please check it out. 183 00:20:01,280 --> 00:20:03,040 And thank you. Do you have any questions?