I would like to introduce our next speaker, who is an assistant professor in the Department of Engineering at Aarhus University. Diego Arana is a professor in applied cryptography and computer security, with a special interest in efficient implementation of cryptographic algorithms and security analysis of real-world systems. His research has included coordinating two teams of independent researchers capable of detecting and exploring vulnerabilities in the software of the Brazilian voting machine, used during controlled tests organized by the National Electoral Authority. So, hi. So I'm here to talk about the horribly insecure Brazilian voting machines. An alternate title of this talk is the Return of the Insecure Brazilian Toasters because the president of the electoral authority recently claimed that the voting machines are secure because they are not connected to the internet, just like toasters. So my arguments apply to both cases. So first, a little bit of context. Yeah, I should say that this is joint work with many people. So I coordinated a team last year where we were able to full compromise the security of this machine. This is joint work with Pedro Barbosa. Caio Lourdes, who is here. Thiago Cardoso and Paulo Matias. All of them live in Brazil. A little bit of context. Brazilian elections are massive. We have 140 million voters and a high turnout because voting is mandatory. They are held every two years. We alternate between city-wise or municipal and federal elections. Elections became electronic in 1996 when the first machines were introduced. But only became fully electronic in 2000. So now, or for the last 18 years, all the polling places use voting machines. A remarkable aspect of our elections is the same authority responsible for everything. So they decide what technology is being used. They write the software. They deploy the software. They do the logistics on the election day. They collect the results. They publish the results. And since they are a branch of the judicial system, they also decide any output, any dispute in the outcome. So they are overlords of our elections. Which, of course, is a massive problem for insider attacks. Right? Because everything is centralized on the same place. So the name of this authority is the Superior Electoral Court. They are a branch of the Supreme Court. I'll just call them by SEC to save time. So this is the Brazilian voting machine. On the left, you can find the poll officer terminal where the officer types in the voter registration number or collects his or her fingerprint. The right-hand side, you can find the voter terminal. So voters type in candidate numbers on the keypad. This is not a touchscreen machine, so you vote using candidate numbers. And you can see a first design flaw in this picture. There is a cable connecting the two. So it looks, or it's apparent, that the same device collects the voter identity and the vote. So this is a threat, of course, for ballot secrecy. If the software running the machine is malicious, it can collect all the voters and their choices. So the machines were claimed to be 100% secure since 1996, but only tested for the first time in 2012. The hardware is manufactured by Diebold, which is not great, right? We have more than half a million voting machines in operation. The software was initially written by Diebold. Now it's written by the electoral authority since 2006. And the recent version has more than 24 million lines of code, which is huge. This includes the Linux kernel, user and libraries, user and applications, everything. But this is just for the voting machines. There are other software components that add up to this number. So they adopted GNU Linux in 2008 and experimented with paper records only once in 2002. And the story is really complicated. I'll just say that they deployed this in a fraction of the machines and decided to not do this in the following elections because they concluded that it was too expensive, too cumbersome, the paper jams, printers in the middle of the Amazon forest and all sorts of lame excuses. So they discontinued this in 2002. They have been rolling out fingerprint identification since 2008 and deploying them in production since 2011. Half of the population is already enrolled in. And as I said, since this is a paperless DRE voting machine, it's highly vulnerable against insider attacks from the electoral authority itself. So this is the algorithm for running an election in Brazil. The software is developed in the headquarters of the electoral authority in Brasilia. The capital of the country. And it's transmitted to the state branches of this authority through the internet, through some kind of VPN connection. On the state branches, they record the software in flashcards and these flashcards install the software since they are not connected to the internet and in the machines a few days before the election. So every install card, just like the one on the top of the slide, installs up to 50 machines. On the election day, the zero tape is printed between 7 and 8 am. The poll officer types a command in his terminal to open the voting session. Voters can authenticate, present their credentials, type their choices. And the voting session ends at 5 pm if there are no voters left in the query. At that time, the machine prints a poll tape and also records a number of files in what we call the media of results, or MR for short, which is one of the print drives at the bottom there. These files include a digital version of the poll tape, a file called DRV that I will detail later, in a moment, and a log file with all the events since the software was installed. This pen drive is detached from the machine, attached to another computer, and all the contents are transmitted to the central tabulator through, again, a VPN connection. The central tabulator tallies up everything and publishes the result. So the access to these machines is notably restricted. The only opportunity where independent experts can actually take a look at the software and try to attack the machines are what are called the public security tests. So these are restricted tests organized by the electoral authority typically one year before the elections. And the objective is clear. These experts have to provide or compromise either ballot secrecy or ballot integrity in an untraceable way. But these, as I said, are not very public despite the name. So first of all, you cannot use pen and paper to take notes when inspecting the software, the source code. You have the option to inspect the code for three days, but you cannot take notes. You have four days to mount all attacks. All the attacks need to be pre-approved by the electoral authority. All the participating members need to be pre-approved by the electoral authority. There is a whole lot of bureaucracy to participate on this. On the last year, we had to fill, during the test, eight types of different forms, and we had a form that we need to fill to fill a form. So it's a metaphor. There is no guarantees about the software that's running, the software that's being inspected, if it's correct or recent. And there are, of course, intrinsic conflicts of interest here again because it's the electoral authority evaluating the security of its own devices. So it appears not being their interest to be as deep as they can go. So still, they claim that Brazil is the only country on the planet openly evaluating its voting system. And this is a very funny quote because they were here at the voting village last year. And, well, in this picture, there is someone there that works for the electoral authority. And even though participating in this event last year, they repeated the claim that Brazil is the only one doing this type of evaluation. So it seems they have to come other times to be convinced that this is actually an open way of evaluating security of voting systems. So just to illustrate the restrictions, on the right-hand side of this slide, there is a layout of the room where we work it in. We work group one, one of the green tables there. The code is packed. The computers were in the back of the room. We could not take notes from the code on those machines and bring it back to our table. So we had to memorize sections of source code reproduced in our machines and come back if something was wrong, which is, of course, very artificial. These machines were between a distance of 10 meters. So there's no reason for doing this. So I coordinated the team in 2012. I was able to find a very serious vulnerability in the vote shuffling mechanism. And compromise ballot secrecy in that edition of the public security tests. I'll get to talk more about this in the next slides. But we also found on that edition that all the machines shared cryptographic keys. So all the media for all the machines are encrypted under the same key. And this key was directly inserted in the source code. So it was hard-coded in the software. So if it leaks one somewhere, the impact is nationwide. The voting software for integrity checks checks itself. So it knows or it stores digital signatures. It goes through those signatures, checking if they are still valid, which, of course, makes no sense in terms of computer security. It's just like trying to find out if you are crazy by not going to the doctor, right? You might be too crazy to find out that you are crazy. So software works just like this. So by analyzing these vulnerabilities, we concluded that the machines were not able to provide either ballot secrecy or ballot integrity, which, of course, implies a lack of integrity. But it also implies integrity of results as a consequence of an insecure development process, an inadequate threat model that completely disregards insider attacks, and also a result of the internal culture within the electoral authority that lacks transparency. After all, they wrote software and did this for decades without having to present the software for external inspection. So the DRV has a complicated story. It was introduced in the system by law. After the electoral authority decided that paper records were not a good idea, so they replaced the paper records with a digital version of the paper records, which, again, makes no sense. So this is a file where different races are stored in different columns. A voter votes for each of these races through the candidate numbers, and these choices are shuffled together to protect the secrecy of these votes. The gray cells there correspond to absentees. So in this case, we have seven candidates in this poll place. Four of them didn't show up to vote. And you can also vote blank, and there are other specifics of Brazilian elections here. So when we first heard about this, we figured out that trying to reverse this randomization or this shuffling would be a promising attack vector, right? So since we do computer science, we thought we need to figure out the bias of this shuffling algorithm, apply some statistical advanced cryptanalysis to reverse this shuffling. So we did exactly that by just graphing through four random stuff, quite literally in this case. And then we found a match. This was literally the first command we ran when we had access to the codebase in 2012. So this took five minutes to finish, and we found a match in a file called drv.cpp, which is very suggestive. So we took a look at the file, and then the seed was computed like this. So if you write software in C, you know that that's a timestamp, right? A 32-bit timestamp, and it's not very predictable. And this timestamp in particular was taken between 7 and 8 a.m. of the election day. So there are only 3,600 different seeds. Since the drv stores the gray cells for absentees, you can actually test if a seed is possible by storing k out of n votes and see if the holes match the polling place we're trying to break ballot secrecy. At the end, we didn't have to do this, because the seed was printed in an official document, and it's stored in a log that must be kept for five years. So you just go to the zero tape, find the timestamp there, seed into your implementation of PRNG, and then you break ballot secrecy. There is more. So to mount this against a real polling place, you need to keep track of who voted in sequence, right? But you can actually mount an interesting attack against famous voters or important voters. So this is the president of the electoral authority. We know that he voted at 11.20, in 2010, because the official picture of him voting has this timestamp in the metadata, right? So if you can take the drv file for his polling place and check out his position in the voting queue, of course, and break the shuffling of the votes, you can figure out exactly how he voted. We didn't do this at the time, because we would end up in jail, but of course it's still possible, right? All these files are public, someone can still do it for past elections, the importance of ballot secrecy, and also how dangerous it is to introduce or mandate technological components through law, because this file needs to be produced by the system because it's a law requirement, a legal requirement. So in 2012, we concluded that it was trivial to recover votes in order, trivial to recover a specific vote from the president of the electoral authority. We recommended them to eliminate this file and change the law, if possible, and do not store any metadata about the voters. Instead, they changed the random number generator implementation with a custom algorithm that no one has analyzed it, but at least which is seeded frequently with system entropy, so it should be harder to attack. Although the voting machine has two different hardware RNGs, which are much better than all these choices, and the official explanation for that is, that they give is, since not all machines have these hardware RNGs, they can't write software that selectively uses the hardware RNGs on the machines that are equipped with them. A result of this is, the security of all machines is actually determined by the worst machine in operation, right? Which doesn't have hardware RNG because it's 10 years old. So in 2017, I again participated, coordinated on a team, and we wanted to exercise a different attack, using software installation as an attack vector, just like Alex described it earlier. So software installation is performed at a public ceremony in Brazil. These are some pictures of the ceremony. The quality or security of this ceremony varies a lot, because in some places it's contracted to other companies, in some other places this is done by public servants, so it's hard to know exactly how secure it is in practice. But we found like a sample of pictures online, and in some cases it looks fairly disorganized. In some other cases, even skilled students can go there and visit, and I wouldn't say this is the most security perimeter on the planet Earth, right? For such a critical, mission-critical task. So before this event started, they published a call for participation, and they had a very explicit thing on this document saying that researchers wouldn't have access to cryptographic keys during the event. Since I'm optimistic, I thought that they actually had implemented some key management system that doesn't require storing the cryptographic keys hard-coded in the software. But actually they just erased the keys from the source code, right? It's much easier. So we figured out this again very quickly. One of the first things I ran against the new code base was this, right? So grep is surprisingly useful when you cannot use anything else. And then we found a match in a file .eueminix.c. So minix is the operating system, and we already knew that it's also the partition format for the voting machine memory, so we knew that we had something important here. When we took a look at this file, we found this. So it's a string of bytes with the exact cryptographic key for encrypting the install cards. And this is actually the first byte of that key. So the reason for that is they were migrating from kernel 2.6 to 3.16, I guess, and they forgot to delete, to erase one of the currencies of this key. So they just forgot to delete all of them. But since, well, we know they deleted some parts of code, we know also that the code base for inspection was not complete, right? This is a fairly trivial conclusion. So modern technical details. So this system, we have all of this documented in our paper. It deploys a whole bunch of cryptographic algorithms, sometimes in weird places. The install cards are encrypted with AES-256, which is nice. They tried to implement XTS mode, but they have a small difference that may make the algorithm weaker. But this doesn't matter since the keys are hard-coded in the software. Who cares about the algorithm, right? The integrity checking is done through elliptic curve-based signatures. There are signatures both in the user landing kernel mode, so multiple places check the signatures, which is good to have redundancy, but we'll see that it's not sufficient. And also the keys for assigning the results, the Paul tape, for example, are also stored in the install cards in the voting machine internal memory, encrypted under another key that was embedded in the kernel, but we didn't have access at first because it was deleted from the code base. So we could capture this encryption key and decrypt the install card, and then when we inspected the contents, we found two shared libraries missing signatures. One of them was responsible for generating the log events, so we could inject code in this library to manipulate the log, which basically makes the log useless as an audit mechanism. And we also injected code to zero a cryptographic key that encrypts the DRV. So the DRV, the vote shuffling file, is kept encrypted because if the Paul officer takes two versions of this file before or after someone's vote, he can't figure out by the difference who he voted for. So since we could choose this key by injecting code to be all zeros, we could mount this attack again during the event. We were also able to plug in a USB keyboard to issue comments to the voting machine from the outside. And on the last day, we discovered that the voting software, the application that the voters actually use, is linked against the two libraries. So we could inject code in the libraries to tamper with the voting application during the election, or a simulated election. So we illustrated this power by changing the version of the software and inserting things on the voter screen. I will illustrate in a moment. But at the end, we got arbitrary code execution during an election by forcing the voting machine to run out of the voting machine. This is our software. We also developed a payload to change votes from one candidate to the other. But the tests were interrupted at 6 p.m. on a Friday, and we were in the middle of putting this, installing this in the machine. So we never were able to find this. But it's a logical conclusion of inserting your code to run. So this is a screenshot of the simulator provided by the electoral authority. Of course, this is all in Portuguese. So you type on the right side the number of your candidate. In this case, 61. It's a fictional swimming candidate just for illustrating purposes. You can see at the top left here, there is a string called seu voto para, which basically says your vote goes for or goes to. We changed that string to tell voters to vote for candidate 99. In this case, Darth Vader, which is a much less democratic option than swimming. So in 2017, we concluded that install cards were not properly encrypted. Keys were still shared by all machines and directly inserted into the source code. Integrity checking is also insecure by having shared libraries without signatures. And at the last day, it was interesting that another team found another way to this encryption key. So this makes the whole attack fully acceptable by using what they did. They basically could run the install cards in a virtual machine and have the key in the memory layout of the virtual machine. One attacker could capture this key without access to the source code. So this makes a whole attack external without having access to the source code. So our recommendations this time were to fully automate the signing process. So when a new file comes around, you don't have to change the scripts to sign that file too. And to again deploy proper key management to have different keys in different machines to contain damage in case one of them leaks. Instead, they sort of fix it by not having the keys hard coded by computing them dynamically from a secret stored in the BIOS of the machine. So the software reads some bytes in the BIOS, runs this through some algorithm and then computes the key. But it's still the same key for all of the machines. Although you can claim that this makes the system slightly more robust against an external attacker because the key is not in the software anymore, it's still trivially vulnerable against an insider who can just run this routine once, print the key, and then leak it for malicious purposes. So again, they just mitigated this in a less than ideal way. Problems we still have. Software is for all purposes secret for over 20 years. It was already demonstrated to be insecure several times as I told to you. There is no paper record for recounts. There are no effective ways to audit the system. Everything is, you have to reconstruct history from a bunch of files, which as was argued before is fairly challenging. There are conflicts of interest everywhere and insider attacks are completely disregarded. What can we do? So we need paper records to have, what's this? Okay, I can tell by heart. So we need, oh, it's back. We need paper records for auditing that the voters can inspect. This has a fairly complicated story in Brazil. In 2015, Congress passed a law approving the reintroduction of paper records for the third time. It was, this law was considered unconstitutional by the Supreme Court, which is like really friends with the electoral authority in last June. So we won't have paper records again in the upcoming elections, which may be the most important in Brazilian history. I don't know if you've been tracking. The news. The news, but it's a whole political mess and we have eight candidates and all of them are horrible and well, one of them will become president. So we need a better way to verify that this next election is actually fair. So it would be nice to have open source software because then the community can take a look at this. It's not sufficient, but since this is public funded software, I think it's fair to claim that the public has a right to inspect it without all these restrictions. At the end, we need better social control mechanisms to decentralize the control over this system and the Brazilian technical community certainly has to be more vocal. It's really easy to shut down the few critics that live there because we are just two or three instead of having a movement like the US, for example, where the technical community is behind this. So one point I want to make, last point is the world is essentially becoming more polarized politically, which I think makes independent verification of elections even more important. Thank you for your attention. I have three references if you want to take a look at our papers and reports for the past six years, and I may have time for one question. Thank you. Questions? Yes. Hi. The next election is on the American side. Uh-huh. It's impossible to tell. So I think the important question is not, did we have fraud in the past election? But if we had fraud, can we able, are we able to detect it as independent, you know, inspectors eventually? I think this is the important question. What I can say is it was a fairly tight election and we actually did some math to understand how the impact of this attack would have on that election. If an attacker is really aggressive in the election, and the way he changes votes, he only needed to have access to 100 install cards in, not necessarily distributed even in the country, perhaps on the same place, to substitute to replace the software and impact the number of votes that separated the two candidates. So, I can't estimate how easy or expensive this is, but we got this number, 100 install cards. Thank you. Thanks. Thank you.