1 00:00:00,000 --> 00:00:04,660 Chris Gardner and this is chatting with your programs to find vulnerabilities where we are 2 00:00:04,660 --> 00:00:10,440 going to learn how to become therapists for our programs. So to start off, introduce myself. I 3 00:00:10,440 --> 00:00:14,700 recently graduated from UMBC which is where I did this research and while I was there I took a 4 00:00:14,700 --> 00:00:19,800 couple classes on machine learning which in some organizations makes me a data science expert. I 5 00:00:19,800 --> 00:00:23,360 also have done a lot of reverse engineering over the years and competed in many capsule fly 6 00:00:23,360 --> 00:00:28,320 competitions so I know a little bit about vulnerability research. And speaking of 7 00:00:28,320 --> 00:00:32,620 vulnerability research, it's pretty expensive to do these days. Experts in the field are in high 8 00:00:32,620 --> 00:00:37,040 demand and cost a lot and plus they take a lot of time to do their jobs. I think it's high time to 9 00:00:37,040 --> 00:00:41,680 replace people like me with a computer program and DARPA agrees with me. So a couple years ago 10 00:00:41,680 --> 00:00:46,820 DARPA ran the cyber grand challenge here at DEF CON or CGC which challenged eight teams from 11 00:00:46,820 --> 00:00:52,460 industry and academia to create fully autonomous cyber reasoning systems to find, exploit and 12 00:00:52,460 --> 00:00:58,140 patch bugs in computer programs. As part of this DARPA created DECREE, a special OS designed 13 00:00:58,140 --> 00:01:03,000 to be easy to model and analyze. In DECREE you don't have to worry about networking, file IO, 14 00:01:03,200 --> 00:01:06,680 thread scheduling or many of the other hard problems in computer science and software 15 00:01:06,680 --> 00:01:10,840 engineering. Since there are no environmental factors, each program written for DECREE is 16 00:01:10,840 --> 00:01:15,960 deterministic which makes DECREE a good target for research projects. So DARPA ran the cyber 17 00:01:15,960 --> 00:01:20,120 grand challenge but we're not out of a job yet. The winning cyber reasoning system went on to play 18 00:01:20,120 --> 00:01:24,960 against the humans and the DEF CON CTF and it didn't crash and burn horribly but it did get last 19 00:01:24,960 --> 00:01:28,120 place. And additionally during the competition only a five-year-old student was able to get a 20 00:01:28,140 --> 00:01:32,900 fraction of the programs actually had exploits written for them. So we can do a little bit 21 00:01:32,900 --> 00:01:37,400 better. There's space for new research in the field. So if you want to build an automated 22 00:01:37,400 --> 00:01:41,660 vulnerability finding machine, you basically have one option in terms of overall architecture. 23 00:01:42,040 --> 00:01:46,620 We use a tool called a fuzzer to find crashes in a program and then use a technique known as 24 00:01:46,620 --> 00:01:51,580 symbolic execution to solve for an exploit. Symbolic execution is somewhat of a solved problem 25 00:01:51,580 --> 00:01:55,860 from a research perspective but there's a lot of space in the fuzzer level to apply cool AI 26 00:01:55,860 --> 00:01:57,780 tricks. So let's talk about fuzzing. 27 00:01:58,140 --> 00:02:02,840 Basically if you're not familiar, what fuzzing is, is fuzzing takes an initial corpus of test cases 28 00:02:02,840 --> 00:02:08,620 which are inputs that cause some program to do something and randomly mutates them in the hopes of 29 00:02:08,620 --> 00:02:13,640 finding a bug. Many fuzzers called coverage guided fuzzers measure the code coverage of each 30 00:02:13,640 --> 00:02:18,060 mutation to try and make sure that different parts of the code are tested and take a little bit of 31 00:02:18,060 --> 00:02:24,520 the variance out of the process. One popular fuzzer called American Fuzzy Lop or AFL actually 32 00:02:24,520 --> 00:02:27,920 uses some AI to do this. It implements genetic algorithms to 33 00:02:28,140 --> 00:02:33,400 evolve the inputs using code coverage as the fitness function. And fuzzers in AFL in particular 34 00:02:33,400 --> 00:02:37,760 work really, really well. In fact they work so well that combining AFL with more advanced 35 00:02:37,760 --> 00:02:43,040 techniques such as involving symbolic execution in the fuzzing process only marginally increases 36 00:02:43,040 --> 00:02:48,640 the number of crashes found. But unfortunately fuzzers aren't quite perfect. Coverage guided 37 00:02:48,640 --> 00:02:53,340 fuzzers only measure how much of the code is tested. They cannot reason at all about what the 38 00:02:53,340 --> 00:02:58,040 code actually is. They rely on random chance and heuristics to boost the amount of 39 00:02:58,140 --> 00:03:03,740 code tested. In a case like this program where it asks you to enter 1, 2, 3, 4, 5, 6 to trigger 40 00:03:03,740 --> 00:03:09,560 buggy code, the fuzzer breaks down. Even though the correct value is in the program, it's even 41 00:03:09,560 --> 00:03:13,920 outputted to whoever is using the program, the fuzzer cannot make use of this information and in 42 00:03:13,920 --> 00:03:18,640 order to trigger the buggy path, the fuzzer has to basically just guess 48 bits of information 43 00:03:19,190 --> 00:03:24,480 which is not really going to happen on any reasonable time scale. And this brings us to 44 00:03:24,480 --> 00:03:28,040 limitations of fuzzers. Fuzzers are good at making small changes to find 45 00:03:28,140 --> 00:03:32,940 interesting execution paths but tend to be bad at making big coherent changes. And the way you 46 00:03:32,940 --> 00:03:37,800 get around this is by providing the initial test case corpus. If you're fuzzing a PDF reader, the 47 00:03:37,800 --> 00:03:42,620 fuzzer isn't going to be able to create a valid PDF file from nothing most of the time so you 48 00:03:42,620 --> 00:03:47,860 should give the fuzzer some valid PDF files to work with just to start it off. And so in a sense 49 00:03:47,860 --> 00:03:52,960 the effectiveness of a fuzzer is a function of the quality of the test case corpus. And a good 50 00:03:52,960 --> 00:03:56,860 quality test case corpus should include inputs that exercise the different parts of the program. 51 00:03:58,140 --> 00:04:02,680 If you have a huge processing library, good test cases would be a PNG file and a JPEG file and 52 00:04:02,680 --> 00:04:08,460 maybe like a TIF or other weird formats. Generally, test cases are easy for unskilled humans to 53 00:04:08,460 --> 00:04:13,020 create but hard for machines to create automatically. But we can do something about that. 54 00:04:14,040 --> 00:04:18,240 So to generate test cases automatically, there's a few different solutions people have thought 55 00:04:18,240 --> 00:04:24,700 of. And here are the three. So the first method is to use symbolic execution which I mentioned a 56 00:04:24,700 --> 00:04:28,120 little bit earlier to aid in the fuzzing process. So the first method is to use symbolic execution 57 00:04:28,140 --> 00:04:29,620 which I mentioned a little bit earlier to aid in the fuzzing process. If the fuzzer ends up at a 58 00:04:29,620 --> 00:04:35,960 junction in a program so there's two paths and the fuzzer can't get the mutation engine in the 59 00:04:35,960 --> 00:04:40,420 fuzzer can't get the program to go down one specific path, it can invoke a symbolic execution 60 00:04:40,420 --> 00:04:45,620 engine to solve for the input required for the program to take that path. This has the advantage 61 00:04:45,620 --> 00:04:50,640 that it always works. However, it's very, very slow. We're talking execution times in the order 62 00:04:50,640 --> 00:04:55,740 of seconds whereas AFL mutations run in microseconds. And this needs to happen thousands 63 00:04:58,140 --> 00:05:03,000 of times. And one example of this kind of fuzzer is Driller by the team Shellfish which competed in 64 00:05:03,000 --> 00:05:09,360 the CGC. But many of the other teams in the CGC also use this technique. So another option is we 65 00:05:09,360 --> 00:05:13,880 can cheat and just add humans into the equation. And a bunch of the Shellfish guys developed a 66 00:05:13,880 --> 00:05:18,040 system where they would have random people on Amazon Mechanical Turk interact with the programs 67 00:05:18,040 --> 00:05:22,680 and then use those interactions as the initial test case corpus. This actually worked really, 68 00:05:22,760 --> 00:05:28,120 really well. It almost actually worked better than just using symbolic execution in the fuzzing 69 00:05:28,140 --> 00:05:32,840 process. However, it is cheating because we're using humans even though it's like a little more 70 00:05:32,840 --> 00:05:40,400 automatic since Amazon Mechanical Turk is pretty fast at finding workers. But it's not quite 71 00:05:40,400 --> 00:05:45,320 automatic and the humans do take some time. So you're still looking at run times in the order of 72 00:05:45,320 --> 00:05:50,140 seconds or minutes. And while the humans didn't find any bugs, they were in this paper, they were 73 00:05:50,140 --> 00:05:57,540 able to create great test cases and AFL was able to take those and find bugs with those. Lastly, we 74 00:05:57,540 --> 00:06:01,900 can try to apply AI to this problem. There have been a few applications of AI to fuzzing, namely 75 00:06:01,900 --> 00:06:06,400 using genetic algorithms in AFL which I mentioned, which has been very successful. There's also a 76 00:06:06,400 --> 00:06:10,420 paper called Deep Reinforcement Fuzzing which outlines a method to use reinforcement learning 77 00:06:10,420 --> 00:06:15,400 instead of genetic algorithms in fuzzing. The method is a little young and I don't think they 78 00:06:15,400 --> 00:06:21,380 released any code from that paper but early results seemed to outperform AFL by about 10% which 79 00:06:21,380 --> 00:06:27,440 is definitely worth the effort. And lastly, there's our idea which approaches the problem in a 80 00:06:27,540 --> 00:06:31,000 different way than these two methods. So we have a bunch of 81 00:06:31,000 --> 00:06:33,400 conversations between unskilled humans and these programs. 82 00:06:33,700 --> 00:06:36,440 Sounds like we have data. Many of the programs from the 83 00:06:36,440 --> 00:06:38,640 Cyber Grand Challenge are console programs meant to be 84 00:06:38,640 --> 00:06:41,180 used by humans. Sounds like a good application for a chatbot. 85 00:06:41,640 --> 00:06:44,080 And that's what we did. We trained a chatbot on the results 86 00:06:44,080 --> 00:06:47,760 of the human assisted CRS paper that the Shellfish guys wrote 87 00:06:47,760 --> 00:06:50,820 and sampled that on the input from new programs to provide 88 00:06:50,820 --> 00:06:53,480 test cases. And also a big shout out to Zardes from 89 00:06:53,480 --> 00:06:55,760 Shellfish for giving us the data and making this research 90 00:06:55,760 --> 00:07:01,400 possible. So despite the opinions of my machine learning 91 00:07:01,400 --> 00:07:04,060 professor, I'm not actually good at machine learning. So instead 92 00:07:04,060 --> 00:07:07,180 of writing my own chatbot implementation, I kind of just 93 00:07:07,180 --> 00:07:09,940 pulled one off of GitHub. It's just kind of a standard chatbot 94 00:07:09,940 --> 00:07:12,880 uses recurrent neural networks, sequence to sequence, blah, blah, 95 00:07:12,880 --> 00:07:16,260 blah, buzzwords, buzzwords. And basically I just modified it 96 00:07:16,260 --> 00:07:18,820 to work on a byte level instead of a word level, kind of 97 00:07:18,820 --> 00:07:21,420 discarding all the optimizations that people can do with words 98 00:07:21,420 --> 00:07:24,660 and let it train. And speaking of training, since no one likes 99 00:07:24,660 --> 00:07:25,740 to fund undergrad research, I'm going to show you how to do 100 00:07:25,760 --> 00:07:27,400 that. So we did a lot of research projects. We only 101 00:07:27,400 --> 00:07:30,640 trained the network for about five hours on a CPU, although it 102 00:07:30,640 --> 00:07:35,060 wasn't a CPU. For the data we used about 3,000 test cases from 103 00:07:35,060 --> 00:07:38,680 the HA CRS paper, which corresponded to about 50,000 104 00:07:38,680 --> 00:07:43,300 question response pairs. So 50,000 samples. And for the test 105 00:07:43,300 --> 00:07:46,380 set we had 200 programs in the Cyber Grand Challenge that we had 106 00:07:46,380 --> 00:07:49,960 data for. So we excluded six of those from the training set and 107 00:07:49,960 --> 00:07:54,760 that was our test set. And so the way we tested it is we 108 00:07:54,760 --> 00:07:55,740 measured the code coverage. So we measured the code coverage 109 00:07:55,760 --> 00:07:58,700 of the generated test cases and then compared that with the code 110 00:07:58,700 --> 00:08:03,800 coverage of the HA CRS test cases. Code coverage, the way you 111 00:08:03,800 --> 00:08:07,420 calculate it is the number of basic blocks in each program. The 112 00:08:07,420 --> 00:08:12,060 basic block is one uninterrupted sequence of assembly instructions 113 00:08:12,060 --> 00:08:16,820 with no jumps. And you take the number of basic blocks you hit, 114 00:08:16,920 --> 00:08:19,780 you measure using instrumentation and divide that by the total 115 00:08:19,780 --> 00:08:24,980 number. And basically we, or I decided if a test case has higher 116 00:08:24,980 --> 00:08:27,440 code coverage, it's a higher quality test case. That's not the 117 00:08:27,440 --> 00:08:29,960 best way to measure these things but it was a quick and dirty 118 00:08:29,960 --> 00:08:33,080 method and it worked really fast. So I did it. And 119 00:08:33,080 --> 00:08:35,780 specifically we generated 10 different test cases for each 120 00:08:35,780 --> 00:08:38,160 program and then we took the average code coverage of every 121 00:08:38,160 --> 00:08:42,200 test case and then also took the union code coverage of those 10 122 00:08:42,200 --> 00:08:45,700 test cases and then compared those with the HA CRS test cases. 123 00:08:45,860 --> 00:08:53,200 And we had about 30 test cases per binary to train on. So the 124 00:08:53,200 --> 00:08:54,960 results. As expected, we didn't really do a lot of testing. We 125 00:08:54,980 --> 00:08:57,980 do quite as well as the humans but we only underperformed them by a 126 00:08:57,980 --> 00:09:00,760 single percentage point in some cases. And the worst we ever did 127 00:09:00,760 --> 00:09:03,580 was only 10% under the humans, which is pretty great. And we 128 00:09:03,580 --> 00:09:07,280 way outperformed restoring random data or using the word 129 00:09:07,280 --> 00:09:10,180 fuzz as your initial seed for everything, which some teams did 130 00:09:10,180 --> 00:09:13,480 during CGC. And thankfully this system is also really, really 131 00:09:13,480 --> 00:09:16,500 fast. Even though it's not quite as good as humans or using 132 00:09:16,500 --> 00:09:19,940 symbolic execution, it runs in milliseconds compared to seconds 133 00:09:19,940 --> 00:09:22,880 for symbolic execution in humans. And actually the big 134 00:09:22,880 --> 00:09:24,960 bottleneck for that is not even the number of tests that we do. 135 00:09:24,980 --> 00:09:27,420 In the neural network it's just communicating with the target 136 00:09:27,420 --> 00:09:31,280 program. And also the network wasn't just like throwing garbage 137 00:09:31,280 --> 00:09:33,840 and like hitting error cases and doing stuff. It was actually 138 00:09:33,840 --> 00:09:36,920 navigating the menus of these applications and responding with 139 00:09:37,500 --> 00:09:41,940 sometimes invalid but a lot of times mostly valid data. It 140 00:09:41,940 --> 00:09:45,280 wasn't perfect and so sometimes we only got halfway there. So for 141 00:09:45,280 --> 00:09:48,340 example, here's one of the programs tested. The program 142 00:09:48,340 --> 00:09:52,040 prompts, it asks for a number between 100 and 1,000. And it 143 00:09:52,040 --> 00:09:54,960 responded with a number. But not in that range. It responded with 144 00:09:54,980 --> 00:09:59,600 40 with a leading zero. But it's important to note that that is 145 00:09:59,600 --> 00:10:02,720 actually only one bit away from the correct response. It can just 146 00:10:02,720 --> 00:10:06,060 flip a bit to turn the leading zero into a 1 or a 2 or 147 00:10:06,060 --> 00:10:09,940 whatever. And then the fuzzler should be able to easily make 148 00:10:09,940 --> 00:10:13,320 that change and take it from there. And then it's presented 149 00:10:13,320 --> 00:10:16,280 with a menu and it actually does pick a valid option from those 150 00:10:16,280 --> 00:10:19,360 choices. Showing that this approach is capable of 151 00:10:19,360 --> 00:10:22,600 recognizing and navigating the basic menus that are in many of 152 00:10:22,600 --> 00:10:24,960 the CGC programs. The approach to this is a little bit more 153 00:10:24,980 --> 00:10:27,020 complex. It does have some limitations though. And the big 154 00:10:27,020 --> 00:10:31,100 one is that it only works on CGC programs or and most of the CGC 155 00:10:31,100 --> 00:10:34,580 programs are toys. This doesn't quite work as well in the real 156 00:10:34,580 --> 00:10:39,040 world because the CGC programs are a little contrived compared 157 00:10:39,040 --> 00:10:42,960 to the real world programs. However, it might be possible to 158 00:10:42,960 --> 00:10:48,340 apply this to other like human interactable programs such as 159 00:10:48,340 --> 00:10:51,700 like GUI programs or web forms or other like simple console 160 00:10:51,700 --> 00:10:54,960 programs or stuff like that. And it's a little bit more 161 00:10:54,980 --> 00:10:56,560 complex. And lastly, this research isn't going to make 162 00:10:56,560 --> 00:10:59,140 many waves in file format fuzzing which is what a lot of 163 00:10:59,140 --> 00:11:02,440 the new research is focused on. AFL is mainly a file format 164 00:11:02,440 --> 00:11:05,240 fuzzer. And since this kind of relies on output from the 165 00:11:05,240 --> 00:11:10,420 program before the program does like really any major parsing, 166 00:11:10,460 --> 00:11:13,300 in most like file format fuzzing situations it doesn't 167 00:11:13,300 --> 00:11:16,220 work. There are a few ways this research could be extended 168 00:11:16,220 --> 00:11:21,040 though. Mainly we can train for longer, add more data. Like I 169 00:11:21,040 --> 00:11:24,480 said, we trained for 5 hours on a CPU which is barely nothing in 170 00:11:24,480 --> 00:11:24,960 machine learning. And then we can train for more data. We can 171 00:11:26,720 --> 00:11:29,180 train for more data. And we were only able to acquire a small 172 00:11:29,180 --> 00:11:33,420 subset of the data in the HICRS paper so it might be helpful to 173 00:11:33,420 --> 00:11:36,400 get more data. But also try training on different data. It 174 00:11:36,400 --> 00:11:39,420 might be possible to train on exploits or crashes instead of 175 00:11:39,420 --> 00:11:42,960 just test cases and then get crashes from those. And the 176 00:11:42,960 --> 00:11:46,860 biggest area to combine this, to move this research forward would 177 00:11:46,860 --> 00:11:49,840 be to combine this technique with symbolic fuzzer like 178 00:11:49,840 --> 00:11:52,880 driller giving it another fast option to try when the mutator 179 00:11:52,880 --> 00:11:54,960 engine gets stuck. Instead of just diving through the data, 180 00:11:54,960 --> 00:11:57,840 driving into a long symbolic execution operation, the fuzzer 181 00:11:57,840 --> 00:12:00,840 can try to approximate it first using machine learning. This 182 00:12:00,840 --> 00:12:03,480 would allow driller to focus on solving the hard constraints like 183 00:12:03,480 --> 00:12:06,440 a hard coded password rather than wasting time on navigating 184 00:12:06,440 --> 00:12:09,980 simple menus. So to wrap this up, here's a quick summary, 185 00:12:10,060 --> 00:12:12,220 here's what I told you. Vulnerability research is 186 00:12:12,220 --> 00:12:15,040 expensive, takes a really long time and it's high time we work 187 00:12:15,040 --> 00:12:18,000 on automating it. Cyber reasoning systems are one approach to 188 00:12:18,000 --> 00:12:21,300 that and they work by, or they automatically find exploit and 189 00:12:21,300 --> 00:12:24,100 patch bugs generally using a combination of fuzzing and 190 00:12:24,100 --> 00:12:27,500 symbolic execution. Fuzzer effectiveness is often limited 191 00:12:27,500 --> 00:12:30,180 by the quality of the initial test case corpus which machines 192 00:12:30,180 --> 00:12:33,220 are currently bad at making automatically. We can use 193 00:12:33,220 --> 00:12:36,300 symbolic execution to make test cases slowly or we can do it 194 00:12:36,300 --> 00:12:39,080 really fast with a recurrent neural network chat bot which was 195 00:12:39,080 --> 00:12:41,940 trained on human interactions. And the chat bot works pretty 196 00:12:41,940 --> 00:12:46,080 well, way better than just the word fuzz. And finally, we did 197 00:12:46,080 --> 00:12:48,340 really well with just a few hours on a CPU, it would probably 198 00:12:48,340 --> 00:12:52,760 work a lot better with a GPU, more time or more data. Alright, 199 00:12:52,840 --> 00:12:54,080 thank you guys so much for listening to me, I'll see you in 200 00:12:54,100 --> 00:12:57,560 my talk. My contact info is listed, if you don't have time 201 00:12:57,560 --> 00:12:59,960 for questions now, please feel free to reach out to me on 202 00:12:59,960 --> 00:13:02,860 either of those, I'm very responsive. Yeah, please, 203 00:13:03,260 --> 00:13:06,620 questions, comments, complaints, private party invites, you know 204 00:13:06,620 --> 00:13:09,460 what to do. Alright, do I have time for questions? Alright, any 205 00:13:09,460 --> 00:13:15,100 questions? No, okay. Alright, thank you guys so much for 206 00:13:15,100 --> 00:13:15,320 listening.