Good afternoon. It's a wonderful honor to be here today. Tonight, or this afternoon, I'm going to be talking about Capture the Flag. Capture the Flag is a contest we like to run at DEF CON. DEF CON, you're here. We've run Capture the Flag at DEF CON in Las Vegas for several years now. In 1996, the first Capture the Flag game at DEF CON was held. And in the year 2000, so after four years, they formalized how it was run. So for the first few years, how Capture the Flag worked at DEF CON was players would either bring software that they wanted somebody to hack for them, or they would hack somebody else's software. And the human judges that were authenticating and running the contest had to make the these decisions every time something got hacked, whether it was easy, whether it was hard, who got the points, and it was very, very confusing. So starting in the year 2000, the DEF CON goons running Capture the Flag created rules, and they created services. So starting in 2002 and running through 2004, a group called Ghetto Hackers took over Capture the Flag. And this is kind of how Capture the Flag became a name brand event, where the Ghetto Hackers had a different brand name, slightly different from DEF CON. They had continuity from year to year. Starting in 2005, a new team called Kenshoto took over. And this is also when I started playing Capture the Flag. Kenshoto had a much more difficult game that made a lot more people more interested in Capture the Flag. Starting in 2009, the next team called DD Tech and started running Capture the Flag themselves. And then, starting in 2013 and running up until last year, my team, the legitimate business syndicate, took over. And starting literally tomorrow, the new team, Order of the Overflow, is taking over running DEF CON Capture the Flag. So the way we think about Capture the Flag and how Capture the Flag works with DEF CON is that there are two distinct formats. This format is Jeopardy format, named after the U.S. game show. And how this works is teams pick a question or a challenge from this grid. They receive a prompt and solve the challenge for some points. The main part of this game is the scoreboard that we just saw. On the scoreboard, you find a prompt. In this case, the prompt is giving us a network address, including a port number and a file to download. From there, we solve the challenge. In a lot of cases, these challenges involve a lot of assembly programming or reading assembly. And they involve Python. Once the challenge has been solved, you return the answer to the question to the scoreboard for points. And then you go on to the next challenge. Right here, we see a handful of challenges that have been solved by somebody with different point amounts. And one challenge that has not been solved yet and that will give the person who solves it scoreboard control. So Defcon Capture the Flag qualifiers is one of the most famous Jeopardy-style CTFs in the world. But I'm going to talk about a challenge from a different event, the Shaw 2017 Capture the Flag contest. So Shaw 2017 was an outdoor computer festival held in the Netherlands last August, the week after Defcon. And I went there and had a wonderful time. And part of the wonderful time was a contest that the Dutch team Eindhoven ran at this event. I'm going to talk about a challenge called Asby. With Asby, we get a file. This is the prompt that has a little bit of backstory where their team member named Asby got a reputation for solving challenges the wrong way. So once I downloaded this file, I discovered it was a Windows executable. And because I just, like, downloaded this executable randomly from the internet, I decided to run it and figure out what I had to do. So the goal with this is we need to enter in the flag, and the executable will tell us if it's correct or not, and starting from here, how many characters are correct. So I need to guess the correct input. So I have three ways that I can do this. I can either reverse engineer a Windows binary, and I'm not very good at reverse engineering and I don't usually use Windows, so that was kind of out. I could guess each character by hand, which looked like it would take a long time, or I could write a program, which I foolishly believed would go really, really quickly. So I chose to write the program. And this is the program. It's a little Ruby script, and mostly what it does is it opens the wine emulator with the Asby executable. I hand guessed a bunch of the flag before I tried writing the program, so I have that part of the flag at the top. And then we just loop over and over, guessing which of our flag characters goes into the executable and tells us it's correct. If we get to a point where something weird happens, we print out what we have so far and exit. In theory, after a long time writing this program and switching back and forth between, oh, I can't program computers anymore, I'm just going to do this by hand, I eventually got the solution. The solution is right here, right above the stack trace, which is cool. I solved it, I got some points, the organizers gave me some beverages while I was sitting there, and I had a lot of fun. So that's Jeopardy style. You get a challenge, you solve it, and you get some points. This is the visualization from our finals game, which is an attack-defense format capture the flag. It's very, very different. Here we see teams shooting successful attacks at each other in a soundboard-themed, or like audio mixer-themed event. So how this works is all these steps happen at the same time. Teams are reverse engineering the challenges or the services. They're patching the flaws in the services at the same time they're trying to exploit other teams' services. And in all of this, they're trying to not break their own services to lose points. So here's a small example of how attack-defense works. At the top, we have the score bot, or the scoring system of the capture the flag game. On the left, we have PPP's service called AppMail, and on the right, we have a team called Shellfish. So, every round, the score bot deposits a new flag or a new piece of random data in PPP's AppMail service, and everybody else's services as well. Sometime during the round, Shellfish manages to send some network traffic to AppMail that causes it to disclose this flag, or as we call it, Shellfish has stolen the flag. Then, they take that flag, submit it to the score bot, or they redeem it to the score bot, and get some points. In the meantime, score bot is checking PPP's AppMail service to make sure it's working okay. Can it send messages? Can it receive messages? Is it happy? And, if PPP has broken their AppMail, if they've, you know, turned it off or deleted it, or just written a bad patch that makes it do things wrong, that's a failed availability check. And we assume that if there's a failed availability check, that Shellfish is also not able to steal from it, so we make a failed availability check lose a whole lot of points. And, again, this is the format we used for Defcon Capture the Flag finals. Here's an example. It's a service called Rubix. This is a service we put in place last year. How it works is teams connect to the Rubix service on another team, and it simulates this Rubix puzzle cube where you rotate the cube and try and get all the colours on the same side. But it's a virtual version of that. Teams submit instructions to rotate the cube into a valid configuration, and once the Rubix cube is happy, it executes the instructions as if they were CPU instructions. Which is kind of clever. So we're going to follow along with a write-up from a team called Lab Rats. They publish this write-up and we can follow along. So the first steps to solve this, the computers we used for Defcon CTF finals last year was one we made up, and it used 9-bit bytes instead of 8-bit bytes to make it miserable for teams. So they first had to write software that could deal with 9-bit traffic, which nobody has normally. Then they had to figure out what parts of these binaries were part of the standard C library, and what parts of these binaries were which functions in the C library. After that, they can figure out how the main gets called and what the part of the program that they care about actually is. Once they've done all that work, which took several hours, they could actually start analyzing what the service does. So what are they analyzing? How is it supposed to work? What is the benign traffic supposed to do? Once they figure that out, how can they attack it? How can they make the service release its secrets? And after they figure that out, they can try and figure out how to defend it. How can we prevent the service from revealing its secrets to other teams? So all this is in support of the game goals. You get points by capturing flags, you lose points by having flags captured, and you lose lots of points by failing availability checks. It's extremely complicated, it's extremely frustrating, but it's a lot of fun. For both organizers and most importantly, it's fun for players. But I should go back. Every kind of Capture the Flag game is extremely ambitious. Jeopardy style, they're extremely ambitious to run, they're difficult to play on purpose. Attack defense, also difficult. So some of our goals for Capture the Flag games are making them run smoothly, making them a fair contest, and having fun challenges. If the game doesn't run smoothly, players are going to get frustrated and find something else to do. If it's not fair, players aren't going to put in a legit effort. You know, if the same team is always going to win because they're friends with the organizers, why play? And if the challenges aren't fun, then the challenges aren't fun. So let's talk about running the game smoothly. And just like any big ambitious project, running a Capture the Flag game project starts early. And the most important part of it is who you're running it with, who is on the organizing team. So legitimate business syndicate is about half of us are friends from university that competed together then, and about half were people that worked together in 2012. So here's my friend Gino, kind of the team captain and I. Twelve years ago, we were participating in a college level contest, and we just solved a difficult problem. And we were very, very happy about it. And also a little bit weird from being in a windowless room all day. So how did we start to run DEF CON CTF? We found out during closing ceremonies at DEF CON 2012, that the previous organizers, DD Tech, were stepping down. In December, Gino realized that, hey, I should make a team that runs CTF because that's my dream. So he started talking to us, and I remember at a chicken wing restaurant, the day after Christmas is when he told me about this, and I was in. So in February 2013, we all got together in the same room, wrote down a proposal for how we wanted the game to work, and found out in March that the proposal got accepted. And then the real work began. So what is our group made out of? So about three quarters of the group are people that I would normally call reverse engineers. But people, you know, people aren't just their skills. And all these people have different specialties. So we have a radio specialist who did a lot of work on our 2014 Challenge Badger. We have several people who were good just with computer hardware in general, which was really useful for 2015, the year we brought, I think, 40 different computers to Las Vegas. And in 2017, the game ran on the work of our esoteric computing expert for the Clemency system. But besides reverse engineers, my friend Salir is just a genius when it comes to computer infrastructure of any kind. Networking. He can type commands into routers faster than I could just mash my fingers on a keyboard. I don't understand it. I worked on the database-backed web application because that's something I really enjoy. But the most important part is that people grow and change. I'm not the same person I was five years ago. None of us are. So whenever somebody, you know, grows into a new skill set or gets excited about something, don't say you're the web app person. Just deal with that. Like, if they're excited about something, that's a big benefit for everybody. And that means that players' role or team members' roles also grow and change over time. So if you are putting together a capture-the-flag team, either for playing or for organizing, think about who you know and who you know that you trust and who do you like? Who do you want to hang out with a lot? So once you've figured out who's on the team, you need to be able to talk to your team. And that's what communication is for. We, after the first year, we ended up using Slack or the chat program Slack for asynchronous chat basically all the time. It's great because you don't have to, you know, talk to somebody immediately. They'll just see the message later. We did eventually settle on having meetings every week, which is really, really useful to, you know, have these little iterations where you commit to something and get it done. But whenever we have an actual contest to run, we like to be all in the same place. So this is the rental house we had for our 2017 qualifiers. And this is right before the game starts where we're figuring out what order challenges get unlocked. Once we get to Vegas, we find it really nice to have a shared hotel room where we set up all the noisy computers and stash all the snacks and stash all the drinks, including lots of water because it's important to stay hydrated. And, you know, that's kind of our home base when we're in Vegas. And the snacks and the drinks are really, really important because your team is a team made out of people. And people, you know, people require food and snacks. So in 2014, we were having computer problems. One of the team's instances, their actual physical hardware was acting really flaky and it needed to get unplugged and plugged back in a lot, like more than any other team should. And it was causing a delay of the game because processes would be trying to talk to that machine and it was just not on. So I was on stage trying to figure out why the scoreboard was going slow. And Salir was walking back and forth between his computer on stage to read logs and the rack of hardware off the stage to unplug and plug it back in to power cycle the machine. And I was kind of like getting impatient with how things were going. And I just kind of asked him, how much longer is this going to take? And whenever he walked off stage, he didn't go to the hardware. He just kind of left the room. And Salir is normally like the most stable, level-headed, friendliest person. And that's not something that ever happens. And that really, really scared the rest of us running this game. And eventually after about half an hour, he came back with a drink. He came back with a sandwich and he solved the problem basically instantly. And what I'd kind of neglected was to think about what he needed, you know, both in emotional terms and also it was lunchtime and that's why we were both kind of crabby. So supporting the CTF players means supporting the organizing team and making sure everybody's well fed. The final point I need to talk about with smooth operation is that Capture the Flag software is still software. And just like any kind of software or any other computer system, the way to make this software work reliably is really screwed up. By the end, we could have another machine spun up in about five minutes and we usually had hot spares ready to go anyways, which was great. So next up, I'm going to talk about running a fair contest. And a fair contest is really challenging because Capture the Flag is a game about computer hacking, but DEF CON CTF is also a computer system, which means that we have to be really, really paranoid. And we have to worry about teams trying to hack the right service the wrong way. We also want to make sure that teams don't hack the wrong thing. We want them to hack a vulnerable service. We don't want them to attack the scoreboard. And for attack defense games, we have another problem where teams may want to fix a broken software the wrong way. And the way we eventually, you know, solve this is by restricting what players can do more. So for qualifiers, we tend to run services on separate hosts. And we eventually got to running multiple hosts in multiple locations. So for the different challenges we have in qualifiers, each one would get at least one machine per data center. So teams in the U.S. would connect to a data center in North Virginia or something. Teams in Europe would go to Ireland, Asia Pacific, wherever Amazon's Asia Pacific hub is, which was great. Teams got lower ping times and we didn't have to worry about the entire service getting screwed up globally. Next, each connection to a vulnerable service would get a separate container using the run C container run time and xinitd to actually manage the connections. Using xinitd also has a really nice benefit where instead of writing each service having to have its own, like, network handling code, we could write all these services as just standard in and out executables. And then finally, in 2015, what we started doing was limiting what system calls each service would be able to make using the set comp tools in Linux. Finals is a much more complex game with much more complex problems. And one of the problems that we had was we kept trying to keep the game about reverse engineering and not a game about operating system administration. Starting in 2013, what we did was each team, whenever they connected to their machine, instead of getting root or super user access, they'd get an unprivileged team account that all it could really do is overwrite the service binaries that then ran under their own accounts. So we had a problem starting that year, and it got really bad in 2014, and it was a phenomenon we called the Superman defense. After the comic book character who just, like, one of his special powers is, oh, he just doesn't get hurt ever. So some of the Superman defenses would be like a firewall rule that says this traffic coming from the scoring system is okay, let it through, but this traffic coming from an opponent team is not okay, so just block it. And we never let teams have firewalls that way. However, a Superman defense that was very successful was preventing the flag being read from disk. So teams would run the service in an emulator, and the emulator wouldn't have flag access, and that was that. And we tried to solve that with making legitimate pollers read the flag, but it didn't always fit into a service nicely. So what we learned was that the U.S. Defense Advanced Research Projects Agency, or DARPA, started this project called Cyber Grand Challenge in 2014. And one of their goals was to, or their one goal, was to build a capture the flag game for autonomous computers with extremely formal rules. So for their thing, instead of having, you know, just services on a disk that would run, they came up with new jargon for it called challenge binaries, or CBs. These CBs were all 32-bit x86 binaries, but they used a special executable format that had limited system calls and couldn't store state. So what this meant was that teams couldn't just break out of the jail, or they couldn't wrap it in an emulator. They had to solve these things the, quote, right way. Similar to that, instead of just launching exploits over a network, CGC gave us this idea of a proof of vulnerability, which was the same kind of executable, but it had a few extra functions it could do. It could declare that it was going to demonstrate that it could control registers of a target program, or leak memory from the target program, and the scoring system instead of the teams managed how they ran. So these were put in place to support this goal of offline evaluation, where teams connect to a website and they get the binaries, the challenge binaries that other teams are using. And whenever they go to patch it, they upload it to the team interface website again. Whenever they have an attack, they write a proof of vulnerability and submit it. So the scoring system then runs the availability checks and proofs of vulnerability and isolation. And the value there is that we can run those offline, or we can run them later in a way that's designed to be reproducible and auditable. So once we learned about that, in finals, we could bring some of that technology to our game. Starting in 2015, we would restrict what system calls vulnerable services could make. And in 2016, the day after the Cyber Grand Challenge, we ran our game using their same format, with challenge binaries with proofs of vulnerability. And then finally, for our last year, we ran the entire game in a limited emulator that didn't have a lot of hooks into the messy real world of Linux. Another part of our fair contest is releasing the scoring information after the game's over. For qualifiers, we release the, you know, scoring information and a little bit of that. For finals, we release just, here's the database dump from Postgres, here's all the binaries teams uploaded, here's packet captures for the entire game. And that meant that a lot of teams could spend time after the game analyzing what was being used against them. Third parties could audit the scores and figure out how the actual scoring system in the game worked. An important part of running a fair contest is thinking about accessibility. And accessibility can mean a lot of things, and all these things are important. Our first year, we had a challenge called Die Hard, which required sensitive timing. This was a problem because the name of the challenge was supposed to be a clue, based on a popular movie in the US, about what players had to do. And the timing was difficult if you were on a, you know, internet connection that wasn't super close to where the game was being run. And what we had to do in future years, well, that year we, you know, had a really bad solution. We told teams to rent space near our servers and play from there and write a program, which is like, I don't want to be in the middle of a CTF game renting new servers. Long term, what we had to do was we had to rethink how a lot of our challenges were being built. We had to remove this idea that, you know, teams should be familiar in, you know, United States online, you know, hacker culture from our game. We had to eliminate the whole idea of precise timing for our game. And I think our game improved for that. Some of the other accessibility issues are just the languages we use online in our official communication. Because not everybody's a, you know, the same language as you are. And a lot of people are going to use machine translation because it works. But you have to, you know, use shorter sentences, use smaller words. And it's difficult to get in that frame of mind. And I don't know if we did a great job, but we thought about it at least. So, the last aspect of Capture the Flag and what I've learned running it is this idea of fun challenges. And the fun challenges that we spent a lot of time on, that we think were the most successful, we went and broke expectations. One of the ones from 2015 was a challenge called DOS Fun For You. And there's one writeup for this online. And the writeup starts with discover this challenge is a DOS binary, the disk operating system from the 80s. And they discovered that the IDA Pro disassembly tool was doing it wrong. So, they ended up debugging their disassembler and patching it before they could actually start the reverse engineering. And some teams found out that they had to use the emulator we told them to use because if they used something else, if they used DOS box, it would get some of the subtle timing wrong and they'd have a bad time. Another fun one was our Badger challenge from 2015 finals. And what it was, was a service running on MSP430 microcontroller on physical hardware that communicated with other teams with the game network using a custom CDMA radio network. So, this is it right here. We had two versions, I think three different versions of this badge. We had the one for competing teams. We had the one for organizers and VIPs that showed game scores. We had the base station which was hung up on a string over the game area and had a bunch of wires hanging out of it. So, one thing that we learned from Cyber Grand Challenge was this idea of consensus evaluation. So, with most with a traditional attack defense game, whenever you patch a binary on your machine, your opponents don't get to see how the binary has been patched, they just notice that their attacks don't work anymore. And what CGC did was they introduced this idea called consensus evaluation, where whenever you patch or you replace a binary with a fixed one, everybody else gets to see that. Which means that if your patch isn't complete, other teams, you know, can still attack it. And it also means that if your patch is really good, other teams will start using it. But the important part of that is that now, instead of us releasing eight services over an entire weekend and only getting eight binaries, every time somebody patches it, there's a new binary that needs reversing. So, what I wanted to do with these quals challenges was I wanted to push teams into this idea that automated program analysis is important. You can't just, you know, open up IDA Pro, solve a binary, and then, you know, you're done. You need to start thinking about programs, not just as software that runs, but as input for other programs. So, I worked on this thousand cuts category in 2015, 16, and on a category called Crack Me 2000 in 2017. Each of these challenges had hundreds of binaries that required automated analysis. And I feel they were successful. I saw a lot of blog posts and a lot of write-ups about how to solve these that mentioned they'd never done automated program analysis before. Consensus evaluation and finals gave us some really funny moments. So, a player from a team that I'm going to refrain from naming walked up to the organizer's table and asked why they were losing points. You know, their service was being attacked. We looked at the scoreboard. It's like, yeah, your service is being attacked. That's why you're losing points. It's called capture the flag. But they claimed they were using the same binaries as the winning team and that it couldn't be that. And we just kind of, like, looked at them. And then they just kind of did this and walked away. Because what they realized was that the winning team had put a secret code in their, or a backdoor in their binary to allow them to attack anybody that didn't, that just used their binary without thinking about it. That was really funny. You know, we still laugh about just the expression on that guy's face all the time. So, the Rubik's service from 2017. A few minutes ago I mentioned how it worked. You upload the instructions to rotate a Rubik's cube and then if you've done it successfully, those instructions get evaluated as just CPU byte code. So, how this worked in practice was teams would start to write code to block the evil, whenever shellcode would come in, the scoring system would submit some that didn't steal the flag, but attacking players would submit shellcode that did try and steal the flag. So, defenders would start using the extra space in this binary and they'd patch it by saying this shellcode let it through, this shellcode block it, this code let it through, this code block it. So, what that meant was whenever a team would patch Rubik's, somebody that was already successfully attacking them would disassemble the binary, see their previous attack reflected in it, and have to build a new attack, which felt like the comments we got after the game were that this felt like a multiplayer game against other people. We were having, I was having a back and forth with somebody on this other team. They'd patch it, I'd write a new exploit. They'd patch it, I'd write a new exploit. And we also had to update the scoring system to, you know, create new good shellcode. But it was a lot of fun for the players and it just fascinates me. So, we've talked about running smoothly, we've talked about running a fair contest, and we've talked about fun challenges. This is not everything that we know about Capture the Flag, and this is not everything that there is to know about Capture the Flag. There's still a lot more to learn, and there's a lot more work ahead of us building new Capture the Flag games that create new opportunities for new players. CTF is not a huge community yet. How many people in here have never played a Capture the Flag game? Okay, that's actually really impressive. But I think in a lot of the world, there's still a lot more work that we can do to make Capture the Flag for new players. The best way to learn how to do Capture the Flag is to do it. Either play a Capture the Flag game, or once you're happy with that, build your own Capture the Flag game for your friends and for people that you like to play. Capture the Flag has given me five years with the best group of people I've ever worked with, and it's given me an amazing five years building a contest for the CTF community around the world, the friendliest and smartest community I know. Thank you for making it amazing. And if you're curious about DEF CON Capture the Flag, order The Overflow, the new DEF CON CTF organizers. They're starting their game tomorrow morning at 8am Beijing time. You can learn more about it at oooverflow.io