1 00:00:00,000 --> 00:00:03,480 Our next talk is by Robert Brandon on JumpGate, 2 00:00:03,480 --> 00:00:06,760 Accelerating Reverse Engineering into Hyperspace Using AI. 3 00:00:07,100 --> 00:00:11,860 We'd like to thank our sponsors, Endgame, Silence, Sophos, and Tinder. 4 00:00:12,180 --> 00:00:16,040 And we'd also ask if you could raise your hand if you have an open seat next to you 5 00:00:16,040 --> 00:00:20,060 so that basically people in the back know that there's a seat available. 6 00:00:20,400 --> 00:00:24,300 And then finally, please silence your cell phones, and here's Rob. 7 00:00:26,500 --> 00:00:27,660 All right, how are you doing, folks? 8 00:00:28,420 --> 00:00:32,220 So I'm going to talk a little bit about something that's been kind of an obsession of mine 9 00:00:32,220 --> 00:00:33,200 for the last couple of years. 10 00:00:35,420 --> 00:00:36,900 So, like Tori, who am I? 11 00:00:37,080 --> 00:00:38,800 Been working in tech for a while. 12 00:00:39,780 --> 00:00:43,880 Finished my Ph.D. in Computer Science at the University of Maryland, Baltimore County last year, 13 00:00:43,960 --> 00:00:46,240 largely on the research that I'm going to be talking about today. 14 00:00:46,880 --> 00:00:50,100 And I'm currently a threat hunter with Bruce Allen Hamilton's Stark Labs. 15 00:00:53,420 --> 00:00:55,900 So when you're doing research, in a lot of cases, 16 00:00:55,900 --> 00:00:57,640 it's a good idea to kind of figure out, 17 00:00:57,640 --> 00:00:59,440 what's the big question you're trying to answer? 18 00:00:59,820 --> 00:01:02,740 Otherwise, it's really easy to find rabbit holes that you're going to go down 19 00:01:02,740 --> 00:01:06,320 and waste a lot of time without solving kind of what you initially set to solve out. 20 00:01:08,040 --> 00:01:11,260 So the big question that I've been trying to figure out is, 21 00:01:11,840 --> 00:01:16,220 is there a good way to represent machine code in a way that computers can understand? 22 00:01:17,520 --> 00:01:19,380 You can kind of sit back and say, 23 00:01:19,420 --> 00:01:22,880 well, you know, of course, computers understand machine code because they execute it. 24 00:01:23,700 --> 00:01:27,460 But that's like saying, you know, a line chef at McDonald's understands, 25 00:01:27,460 --> 00:01:30,160 all of cuisine, because they can follow a set of instructions. 26 00:01:31,160 --> 00:01:32,980 You know, what I mean by understand is, 27 00:01:33,080 --> 00:01:39,240 can they take that particular bit of code and in some way place it in the context of all the other code that exists? 28 00:01:41,040 --> 00:01:42,820 You know, so it's kind of the question of, 29 00:01:42,900 --> 00:01:48,340 is there a representation of machine code that captures the semantic meaning of that code in a way that 30 00:01:51,180 --> 00:01:57,160 both computers and humans can kind of make easy comparisons between different types of different pieces of code? 31 00:02:00,120 --> 00:02:01,620 And this has a lot of applications. 32 00:02:02,640 --> 00:02:08,680 You know, one of the big problems or tasks in reverse engineering is the problem of binary similarity. 33 00:02:09,840 --> 00:02:15,260 You know, so given a piece of, or given a program, you don't just want to know, is this thing malware? 34 00:02:16,240 --> 00:02:18,280 You want to know, what kind of malware is it? 35 00:02:18,780 --> 00:02:22,660 You know, does it have some kind of encryption component that could mean that it's ransomware? 36 00:02:22,980 --> 00:02:26,020 You know, is this similar to other rats that we've seen? 37 00:02:27,460 --> 00:02:30,220 This also has a lot of applications in vulnerability discovery. 38 00:02:30,620 --> 00:02:35,400 You know, if you have a program and you decide, hey, is there, are there any vulnerabilities in this program? 39 00:02:36,300 --> 00:02:41,880 You're going to be asking questions like, does it have a library that we already have, that has known vulnerabilities? 40 00:02:43,080 --> 00:02:45,620 You know, and in a lot of cases, you can do that with signatures, 41 00:02:46,120 --> 00:02:49,040 but then those signatures tend to break if the library gets recompiled. 42 00:02:51,220 --> 00:02:56,160 So there are definitely ways to approach the problem right now, and BIM BIF is awesome, 43 00:02:56,160 --> 00:02:58,340 but it doesn't really scale well. 44 00:02:59,620 --> 00:03:03,380 You know, BIM BIF works great if you've got three or four binaries you want to compare. 45 00:03:03,600 --> 00:03:07,520 If you've got three or four thousand, though, it very quickly becomes computationally infeasible. 46 00:03:09,040 --> 00:03:15,440 Then we also have similarity hashes like SSDs and SDHash, and those are great, once again, if your only question is similarity. 47 00:03:16,380 --> 00:03:23,520 But those hashes don't really do, don't really help you as far as being able to encode any of these semantic meanings of a function or a program. 48 00:03:27,960 --> 00:03:33,980 And so kind of the other problem I'm trying to tackle with this is, how do you model binaries for machine learning? 49 00:03:35,080 --> 00:03:38,280 So most machine learning algorithms, you need some kind of fixed length input. 50 00:03:40,080 --> 00:03:48,060 In a lot of cases, when you're working with a program, those fixed length feature vectors are going to be constructed by domain experts. 51 00:03:48,260 --> 00:03:53,420 You know, they'll look at things and say, like, okay, there's important things like, how many sections are in the PE header? 52 00:03:53,960 --> 00:03:56,140 You know, how long is the text section? 53 00:03:56,600 --> 00:03:58,740 You know, how many bytes is the binary? 54 00:03:58,860 --> 00:03:59,760 How much data is there? 55 00:03:59,820 --> 00:04:00,400 What's the entropy? 56 00:04:02,880 --> 00:04:06,880 But those features aren't always comprehensive. 57 00:04:07,320 --> 00:04:13,180 One domain expert might pick a different set of features than another domain expert. 58 00:04:13,320 --> 00:04:17,980 There's no real good way to decide what's the right way to do it. 59 00:04:19,620 --> 00:04:26,140 And in a lot of cases, some things, like an N-gram computation, that can be pretty computationally intensive once you get into it. 60 00:04:26,160 --> 00:04:28,800 There's all this sort of layered number of N's. 61 00:04:30,880 --> 00:04:36,480 When you're looking at machine code, machine code doesn't easily fit into a fixed length feature vector. 62 00:04:36,900 --> 00:04:40,540 Machine code can be incredibly variable in length. 63 00:04:40,960 --> 00:04:47,400 You know, if you're looking at functions, the length of the functions kind of just don't fit on the verbosity of the program. 64 00:04:47,980 --> 00:04:52,140 Some people like writing really long functions and putting everything in long functions. 65 00:04:52,420 --> 00:04:54,700 Other programmers will have very short functions. 66 00:04:56,540 --> 00:05:00,140 And, of course, label data is really hard to obtain. 67 00:05:00,400 --> 00:05:04,180 You know, nobody's going to sit down and look at all the programs out there, 68 00:05:04,300 --> 00:05:07,060 and exhaustively, you know, categorize them by, 69 00:05:07,080 --> 00:05:11,420 okay, this one has some network connectivity, this one has description, this one has text. 70 00:05:13,100 --> 00:05:19,680 The other real significant challenge in this field is there aren't a lot, compared to fields like vision and language, 71 00:05:20,200 --> 00:05:24,000 there really aren't a lot of machine learning researchers working in the security field. 72 00:05:24,580 --> 00:05:26,940 And even the ones that are working in the security field, 73 00:05:27,680 --> 00:05:33,280 the ones working on, you know, binary analysis in reverse engineering are a very small subset of that. 74 00:05:36,840 --> 00:05:43,720 So because of that, I like to try and find approaches from other domains where other people have been successful 75 00:05:44,380 --> 00:05:46,840 that I can apply to the domain I'm working in. 76 00:05:48,100 --> 00:05:53,020 So for binary analysis, I found the field of natural language processing to be 77 00:05:55,080 --> 00:05:55,960 extremely useful. 78 00:05:57,060 --> 00:06:02,300 Because, really, there are a lot of structural similarities between computer languages and human languages. 79 00:06:03,060 --> 00:06:06,060 You know, I mean, they're both created by kind of the same webware. 80 00:06:07,260 --> 00:06:09,820 So both consist of some kind of arbitrary length sequence. 81 00:06:10,840 --> 00:06:17,920 You know, both have a very rich semantic and conceptual information content, 82 00:06:18,120 --> 00:06:21,420 you know, on top of just what you both are composed of. 83 00:06:21,420 --> 00:06:28,300 You know, functions have meaning to humans at a level that's higher than the actual code, 84 00:06:28,480 --> 00:06:31,520 you know, or the actual sequence of instructions. 85 00:06:33,200 --> 00:06:38,840 And fortunately enough, there's been a lot of research done on how you process and represent language. 86 00:06:39,140 --> 00:06:43,680 You know, it's been ongoing since before computers were a machine. 87 00:06:45,280 --> 00:06:48,180 And I always like to try and avoid reinventing the wheel when I'm working. 88 00:06:52,520 --> 00:06:59,120 So a lot of natural language models kind of rely on converting the text 89 00:06:59,120 --> 00:07:02,220 into some kind of pi-dimensional space, you know, a hyperspace. 90 00:07:03,080 --> 00:07:08,780 So a hyperspace is basically any Euclidean space with more than three dimensions. 91 00:07:09,180 --> 00:07:12,600 So, you know, it's a space where you can do things like add vectors. 92 00:07:13,340 --> 00:07:19,560 And more importantly for data science and machine learning, you can compute distance between the vectors. 93 00:07:21,420 --> 00:07:25,040 So in data science, you know, it's very common to model similarity 94 00:07:25,040 --> 00:07:31,520 by taking the distance between two vectors in some high-dimensional feature space. 95 00:07:33,740 --> 00:07:37,280 And in machine learning, you know, machine learning, fundamentally, 96 00:07:37,600 --> 00:07:41,640 the vast majority of machine learnings are just trying to figure out how do you take these data points 97 00:07:41,640 --> 00:07:42,940 and draw a line between them. 98 00:07:43,480 --> 00:07:49,680 So kind of as an example up there, you have a data set in one dimension of x's and y's. 99 00:07:50,160 --> 00:07:53,440 You want to figure out how can you draw a line between the x's and y's. 100 00:07:53,540 --> 00:07:58,660 You know, if you're just working in that one dimension, there's no way that you can do that. 101 00:07:58,860 --> 00:08:02,980 But if you can do something like, say, take the square of each value and move it up into a higher dimension, 102 00:08:03,700 --> 00:08:06,700 in that higher dimension, you can then draw a line between the two classes. 103 00:08:11,500 --> 00:08:15,880 So the ways that you can take language and you can move it into higher spaces, 104 00:08:17,000 --> 00:08:19,460 you know, there's been a lot of techniques invented to do this sort of thing. 105 00:08:19,680 --> 00:08:23,820 One of the most common techniques is a bag-of-words model, 106 00:08:24,060 --> 00:08:30,140 where you just take a straight count of each of the words that are present in the document 107 00:08:30,140 --> 00:08:32,220 that induce that constructive effort. 108 00:08:33,020 --> 00:08:36,460 That also translates fairly well to a machine code. 109 00:08:36,580 --> 00:08:40,220 You know, you can do a bag of opcodes and just take a count of the opcodes. 110 00:08:40,860 --> 00:08:48,020 You can also do engrams, which are basically where you take, say, the sentence, 111 00:08:48,080 --> 00:08:49,660 the cat ran past the cat. 112 00:08:49,680 --> 00:08:53,320 You know, the two grams would be the cat, cat ran, and ran past. 113 00:08:55,200 --> 00:08:57,120 That works reasonably well. 114 00:08:57,220 --> 00:09:01,020 I mean, the problem with engrams is when you're looking at machine code, 115 00:09:01,240 --> 00:09:03,300 and once you get over about five grams, 116 00:09:04,080 --> 00:09:07,300 you start looking at processing power on the order of ones 117 00:09:07,300 --> 00:09:12,560 to try and compute all of the five grams that are present in a set of binaries. 118 00:09:15,020 --> 00:09:16,320 So most of the... 119 00:09:17,740 --> 00:09:20,440 But most of the really awesome natural language approaches 120 00:09:20,440 --> 00:09:23,240 have kind of moved away from just basic law counts 121 00:09:23,240 --> 00:09:25,020 and they've moved to a concept called embeddings. 122 00:09:26,580 --> 00:09:31,060 And what embeddings are trying to do is take those word counts, 123 00:09:31,180 --> 00:09:34,880 or take a document and convert it into a dense vector 124 00:09:34,880 --> 00:09:38,200 within some higher dimensional state. 125 00:09:38,780 --> 00:09:41,560 And what I mean by dense is there aren't a lot of zeros in it. 126 00:09:42,400 --> 00:09:44,520 It's going to be made up of real numbers. 127 00:09:44,700 --> 00:09:46,240 That just makes complications easier. 128 00:09:46,920 --> 00:09:49,540 So in general, most documents are kind of sparse. 129 00:09:49,640 --> 00:09:51,560 You know, your typical document does not have 130 00:09:52,200 --> 00:09:54,420 all of the words in the English language that are in it. 131 00:09:55,020 --> 00:09:58,420 So a vector of that document is going to have a whole lot of zeros in it. 132 00:10:00,700 --> 00:10:05,040 But the other really cool thing about word embeddings as well 133 00:10:06,300 --> 00:10:12,080 is the vectors within the states, within the five dimensional states, 134 00:10:12,180 --> 00:10:15,400 just kind of naturally cluster into areas where 135 00:10:16,320 --> 00:10:20,620 high level meaning for humans kind of resides within that area. 136 00:10:21,380 --> 00:10:27,060 So for example, if you train a vector space model on 137 00:10:27,060 --> 00:10:29,220 a whole lot of English language documents, 138 00:10:30,140 --> 00:10:34,300 you're going to end up with a space or a hyperplane 139 00:10:34,300 --> 00:10:36,340 or a space within that high dimensional space 140 00:10:37,300 --> 00:10:40,260 where the concept of capital cities is. 141 00:10:41,240 --> 00:10:46,160 You'll have another space where the concept of countries is. 142 00:10:46,640 --> 00:10:49,200 So you can do things like say the vector for London 143 00:10:49,200 --> 00:10:51,700 plus the vector for Britain minus the vector for France 144 00:10:52,200 --> 00:10:54,380 will land you somewhere in the region of the vector for Paris. 145 00:10:57,360 --> 00:11:02,140 So one problem with figuring out how you apply this to machine code though 146 00:11:02,960 --> 00:11:07,900 is that for most of the natural language vector models, 147 00:11:10,220 --> 00:11:14,220 the vector is constructed by examining the co-location of words. 148 00:11:14,360 --> 00:11:15,760 You know, what words are used together? 149 00:11:16,460 --> 00:11:19,420 The meaning of a word, you can kind of infer that by its name. 150 00:11:24,740 --> 00:11:28,440 So when you try to apply these concepts to machine code, 151 00:11:28,540 --> 00:11:30,520 you run into the problem of first off, 152 00:11:30,620 --> 00:11:33,200 what is the equivalent to words in machine code? 153 00:11:34,860 --> 00:11:37,120 You know, you're looking for something that has a fairly 154 00:11:37,120 --> 00:11:39,740 high level semantic meaning to a human. 155 00:11:40,360 --> 00:11:43,640 You know, something that encodes a lot of very dense information. 156 00:11:45,700 --> 00:11:48,240 But isn't too generalizable. 157 00:11:48,420 --> 00:11:50,460 You know, it's not so general that it has no meaning. 158 00:11:52,440 --> 00:11:54,920 So you could use, say, opcodes. 159 00:11:55,120 --> 00:11:57,760 But an opcode like push, move, that, you know, 160 00:11:57,760 --> 00:12:02,000 it really doesn't say much about what the program does on its own. 161 00:12:03,600 --> 00:12:09,680 You know, something like a basic block is another intuitive structure that you could use. 162 00:12:09,760 --> 00:12:10,720 And those are easy to use. 163 00:12:10,720 --> 00:12:14,040 You know, a basic block is basically just continuous execution of code 164 00:12:14,040 --> 00:12:15,940 in the assembly without being granted. 165 00:12:16,720 --> 00:12:21,420 So in the assembly, it would be a sequence of things until you run into a jump or a call 166 00:12:21,420 --> 00:12:26,960 or some other point where the code has to make a decision about what to do. 167 00:12:28,620 --> 00:12:29,940 But at least from my thoughts, 168 00:12:30,680 --> 00:12:35,600 when trying to figure out, you know, kind of what is the basic view of a program 169 00:12:35,600 --> 00:12:38,240 that you'd want to apply some kind of semantic meaning to, 170 00:12:38,240 --> 00:12:41,980 functions seem like the natural choice. 171 00:12:43,080 --> 00:12:47,280 I mean, programmers, when they're coding, they commonly break things up into functions. 172 00:12:47,920 --> 00:12:50,120 Reverse engineers, when they're looking at a binary, 173 00:12:50,260 --> 00:12:54,160 they usually try and break it up into functions and then figure out what each function does. 174 00:12:56,680 --> 00:12:59,980 So the problem now, you know, now that we've decided to use functions is 175 00:13:01,600 --> 00:13:06,300 functions don't exhibit the same kind of temporal properties that language does. 176 00:13:07,140 --> 00:13:07,740 You know, 177 00:13:08,240 --> 00:13:10,440 if you're looking at a document of English language, 178 00:13:11,160 --> 00:13:13,140 you know, the words that are right next to each other, 179 00:13:13,180 --> 00:13:15,520 you can say that these words have something to do with each other. 180 00:13:16,440 --> 00:13:19,600 If you're looking at a static binary, you really can't make that a function. 181 00:13:20,220 --> 00:13:23,380 You know, you're going to have function definitions right next to each other 182 00:13:23,380 --> 00:13:25,020 that really have nothing to do with each other. 183 00:13:25,060 --> 00:13:29,260 You might have printf defined here right next to, you know, open socket, 184 00:13:29,880 --> 00:13:35,000 which is right next to, you know, encrypt all the things in the ransomware. 185 00:13:35,160 --> 00:13:36,880 And each of those functions, you know, 186 00:13:36,880 --> 00:13:38,540 sequentially in the binary really, 187 00:13:39,720 --> 00:13:43,740 their location in the binary really doesn't say anything about what function they perform. 188 00:13:44,700 --> 00:13:46,380 So when you're looking at machine code, 189 00:13:46,900 --> 00:13:49,940 you can't take a co-occurrence type of approach. 190 00:13:51,080 --> 00:13:53,520 You really have to look at the composition of the function. 191 00:13:53,700 --> 00:13:55,660 You know, what instructions comprise this function? 192 00:13:56,080 --> 00:13:58,480 You know, not so much what's next to it. 193 00:14:03,480 --> 00:14:04,900 So from there, you know, 194 00:14:04,900 --> 00:14:06,860 if you're going to be working with a binary, 195 00:14:07,380 --> 00:14:08,680 you have to look at a compositional approach. 196 00:14:08,820 --> 00:14:12,120 You have to figure out, okay, how do we represent the compositional function? 197 00:14:13,920 --> 00:14:17,160 So just looking at, you know, 198 00:14:17,160 --> 00:14:21,760 average length of x86 instructions in a wide variety of machine code, 199 00:14:21,880 --> 00:14:25,280 you know, the common length of most instructions is probably around seven bytes. 200 00:14:25,580 --> 00:14:28,320 You know, to include this instruction as well as the operands. 201 00:14:30,040 --> 00:14:33,560 That's really computationally infeasible if you're just trying to do n-grams. 202 00:14:33,780 --> 00:14:35,980 And you can do, you know, two or three grams, 203 00:14:36,860 --> 00:14:39,660 and each of the n-grams is just going to be a subsection of a instruction. 204 00:14:40,840 --> 00:14:46,120 And, you know, half an instruction really doesn't give you a lot of usefulness. 205 00:14:48,380 --> 00:14:53,440 You know, you could sit down and have a human who really knows assembly really well 206 00:14:53,440 --> 00:14:55,380 figure out, okay, how, you know, 207 00:14:55,380 --> 00:14:59,360 what are the things that are significant when I'm looking at assembly? 208 00:15:00,000 --> 00:15:02,120 So you could, you know, you might find things like, 209 00:15:02,120 --> 00:15:05,780 okay, if I see a bunch of pushes followed by, you know, the pop, 210 00:15:06,860 --> 00:15:08,760 followed by, you know, a bunch of xors, 211 00:15:08,760 --> 00:15:10,500 you know, followed by a bunch of xors, 212 00:15:11,400 --> 00:15:16,920 that might, that's probably some type of a encoding encryption routine 213 00:15:16,920 --> 00:15:18,780 that's, you know, a significant pattern. 214 00:15:19,740 --> 00:15:21,620 But there's a lot of patterns like that. 215 00:15:21,760 --> 00:15:23,320 They're extremely variable length. 216 00:15:24,240 --> 00:15:26,540 And figuring out, you know, which patterns are significant 217 00:15:26,540 --> 00:15:30,420 and how do you encode them is not really a tractable problem. 218 00:15:32,340 --> 00:15:34,380 You know, if you step back and think about it intuitively, 219 00:15:35,460 --> 00:15:36,840 you know, if you really want to think about it intuitively, 220 00:15:36,860 --> 00:15:38,080 and you want to figure out how do you build something, 221 00:15:41,460 --> 00:15:44,000 then you need to, you know, if you want to know 222 00:15:44,000 --> 00:15:46,280 what features are significant to represent something, 223 00:15:46,960 --> 00:15:48,600 then kind of knowing how to build it, 224 00:15:48,680 --> 00:15:50,360 figuring out how do you build it, you know, 225 00:15:50,400 --> 00:15:52,720 which features are important to construct those things, 226 00:15:53,340 --> 00:15:54,860 is a useful way to go about it. 227 00:15:56,940 --> 00:15:58,740 But to test the approach, you know, 228 00:15:58,740 --> 00:16:01,400 and it's a really hard problem for humans to do, 229 00:16:02,060 --> 00:16:05,780 why not let a neural network figure out how to compose functions? 230 00:16:06,960 --> 00:16:08,760 And then just take what the neural, you know, 231 00:16:08,760 --> 00:16:10,220 take what the neural network's going to do. 232 00:16:11,200 --> 00:16:12,040 Save all the work. 233 00:16:14,460 --> 00:16:18,180 So fortunately, there is a type of neural network that does that, 234 00:16:18,320 --> 00:16:21,160 which is a character RNN. 235 00:16:22,340 --> 00:16:24,440 Character RNN is a generative neural network 236 00:16:24,440 --> 00:16:26,160 that generates test sequences, you know. 237 00:16:26,800 --> 00:16:30,360 The great thing about a generative neural network is 238 00:16:30,360 --> 00:16:32,200 you don't need label data to train it. 239 00:16:32,400 --> 00:16:34,140 You know, the data is its own label. 240 00:16:36,860 --> 00:16:39,500 And the other really awesome thing about this particular architecture 241 00:16:39,500 --> 00:16:43,920 is all of the popular deep learning frameworks out there 242 00:16:43,920 --> 00:16:46,320 have examples of code for doing this, 243 00:16:46,340 --> 00:16:48,200 you know, just in their reference libraries. 244 00:16:48,600 --> 00:16:50,980 It's a fairly common part of this type of thing. 245 00:16:52,940 --> 00:16:54,700 So training a generative RNN, 246 00:16:55,440 --> 00:16:57,760 you basically are going to show it a sequence of bytes, 247 00:16:57,820 --> 00:16:58,820 one byte at a time. 248 00:16:59,140 --> 00:17:01,480 It's going to try and predict the next byte in the sequence. 249 00:17:02,320 --> 00:17:03,900 You know, if it gets it wrong, you know, 250 00:17:03,900 --> 00:17:06,060 after you go through and let it predict everything, 251 00:17:06,860 --> 00:17:10,220 you can go back and let it correct the weights 252 00:17:10,220 --> 00:17:12,760 and just the network training. 253 00:17:13,400 --> 00:17:15,300 So like in this example, you know, 254 00:17:15,320 --> 00:17:18,020 you have a neural network that at each time stamp 255 00:17:18,020 --> 00:17:19,460 is trying to predict the output 256 00:17:19,460 --> 00:17:21,900 based on all the sequence of letters it's seen so far. 257 00:17:22,300 --> 00:17:24,960 You show up a letter C, it's going to predict the letter A, 258 00:17:25,020 --> 00:17:27,120 you know, good job neural network, you know, that's right. 259 00:17:27,660 --> 00:17:29,900 You know, as it says, okay, I've seen C and A, 260 00:17:29,980 --> 00:17:31,320 I'm going to predict the next letter C. 261 00:17:32,200 --> 00:17:32,560 Great. 262 00:17:33,140 --> 00:17:34,840 It says, okay, now I've seen C and A, C. 263 00:17:35,280 --> 00:17:36,520 Maybe the next letter is Q. 264 00:17:37,820 --> 00:17:38,860 You know, at that point, 265 00:17:38,900 --> 00:17:40,800 the training is going to go back to C or D. 266 00:17:42,400 --> 00:17:43,900 That's not a valid word. 267 00:17:44,080 --> 00:17:46,080 Let's go ahead and correct the weights at that point 268 00:17:47,080 --> 00:17:50,620 in a way to hopefully get it working right. 269 00:17:55,560 --> 00:17:56,980 So this is an example. 270 00:17:57,060 --> 00:17:58,780 This is just a bit of assembly that a, 271 00:17:59,280 --> 00:18:00,620 I trained a generative neural, 272 00:18:00,780 --> 00:18:03,440 or a generative RNN on lots of assembly. 273 00:18:04,840 --> 00:18:05,980 You can kind of see that 274 00:18:05,980 --> 00:18:09,120 it's reasonable looking assembly, 275 00:18:09,300 --> 00:18:10,720 except all the registers, right? 276 00:18:10,800 --> 00:18:13,760 You know, there's no registers that you wouldn't expect to see. 277 00:18:14,560 --> 00:18:16,680 And it even learned to clean up the stack when it's done. 278 00:18:20,700 --> 00:18:23,500 So what you end up with after you train one of these networks 279 00:18:24,360 --> 00:18:28,040 is you basically have a method for embedding your functions 280 00:18:29,360 --> 00:18:31,120 into a higher dimensional state. 281 00:18:31,940 --> 00:18:35,320 You know, the final set of activations in your general, 282 00:18:35,320 --> 00:18:36,820 generative neural networks, 283 00:18:37,520 --> 00:18:41,120 you can basically treat as a high dimensional vector. 284 00:18:41,280 --> 00:18:43,240 You know, if you have 100 neurons in your network, 285 00:18:43,880 --> 00:18:45,920 then each of them is going to have an activation, 286 00:18:46,020 --> 00:18:46,800 which is a number. 287 00:18:47,140 --> 00:18:49,800 So you've got a 100 dimensional vector within vector space. 288 00:18:52,120 --> 00:18:54,840 And just given the way the training process works, 289 00:18:55,460 --> 00:18:57,280 similar sequences of code 290 00:18:57,280 --> 00:19:00,400 are going to quality similar activations 291 00:19:00,400 --> 00:19:01,320 within the neural network. 292 00:19:03,700 --> 00:19:05,640 So you can kind of say that 293 00:19:06,320 --> 00:19:08,220 if you've got two pieces of code, 294 00:19:09,300 --> 00:19:10,220 each of the vectors, 295 00:19:10,400 --> 00:19:11,200 you can say they're similar 296 00:19:11,900 --> 00:19:15,060 based on the fact that they activate a neural network 297 00:19:15,060 --> 00:19:17,520 that's looked at a whole lot of F86 code the same way. 298 00:19:23,100 --> 00:19:24,160 So of course, you know, 299 00:19:24,200 --> 00:19:25,980 being a data scientist, 300 00:19:26,560 --> 00:19:28,220 there's no science without testing. 301 00:19:28,380 --> 00:19:30,500 You can say, hey, this is great, 302 00:19:30,500 --> 00:19:32,960 but how do you know all these numbers that you're generating 303 00:19:33,460 --> 00:19:36,280 actually do what you want them to do 304 00:19:36,280 --> 00:19:39,260 and you're not just generating a bunch of neural network garbage? 305 00:19:40,420 --> 00:19:41,760 So in order to test this, 306 00:19:41,840 --> 00:19:43,960 I trained three generative LSTMs 307 00:19:43,960 --> 00:19:45,580 on a data set consisting of functions 308 00:19:45,580 --> 00:19:48,080 from React OS, Arch Linux, and Windows 10. 309 00:19:48,360 --> 00:19:51,340 They were compiled with both GPPT and Visual Studio. 310 00:19:52,480 --> 00:19:55,140 The overall data set was about 23 million functions. 311 00:19:56,900 --> 00:19:58,140 LSTMs were all single layered. 312 00:19:58,300 --> 00:20:00,160 I trained one with 100 nodes, 313 00:20:00,500 --> 00:20:01,280 one with 500 nodes, 314 00:20:01,340 --> 00:20:03,060 and one with 1,000 nodes, 315 00:20:03,140 --> 00:20:06,020 just to kind of get a broad understanding 316 00:20:06,020 --> 00:20:10,420 of how much representation can you get 317 00:20:10,420 --> 00:20:12,080 within a particular neural network architecture. 318 00:20:14,040 --> 00:20:17,900 And just given that the LSTMs take regular training, 319 00:20:18,080 --> 00:20:19,380 the only training we should be using 320 00:20:19,380 --> 00:20:20,720 is retraining that as we thought. 321 00:20:21,160 --> 00:20:22,020 And with React OS, 322 00:20:22,220 --> 00:20:24,420 we should be trying to calculate that 500 times less. 323 00:20:24,660 --> 00:20:26,680 And all the statistics, if anybody cares, 324 00:20:26,720 --> 00:20:27,500 probably can chat later. 325 00:20:30,980 --> 00:20:33,220 So the next big decision is 326 00:20:33,220 --> 00:20:35,640 do you want to work with assembly versus the raw binary? 327 00:20:36,800 --> 00:20:38,140 There's been some prior research, 328 00:20:38,280 --> 00:20:39,220 but in a lot of cases, 329 00:20:39,300 --> 00:20:41,980 people want to disassemble the code first, 330 00:20:42,160 --> 00:20:43,320 which, you know, that's reasonable. 331 00:20:43,660 --> 00:20:45,160 I mean, if you're trying to look at things, 332 00:20:45,220 --> 00:20:46,820 a lot of people like looking at assembly 333 00:20:46,820 --> 00:20:47,800 a lot better than binary. 334 00:20:48,860 --> 00:20:50,520 There are some downsides to that though. 335 00:20:50,580 --> 00:20:51,600 The first problem is 336 00:20:52,400 --> 00:20:54,180 what is the correct disassembly? 337 00:20:54,660 --> 00:20:56,120 You know, every disassembler 338 00:20:56,120 --> 00:20:58,540 can disassemble things slightly different. 339 00:20:58,660 --> 00:20:59,880 You might have one disassembler 340 00:20:59,880 --> 00:21:01,320 that wants to use AT&T syntax, 341 00:21:01,660 --> 00:21:02,500 another one that wants to use 342 00:21:02,500 --> 00:21:02,780 syntax. 343 00:21:04,380 --> 00:21:06,900 And kind of figuring out which one is correct 344 00:21:06,900 --> 00:21:08,300 is a hard problem. 345 00:21:09,500 --> 00:21:12,080 And really, I prefer to try and keep things 346 00:21:12,080 --> 00:21:13,640 as close to the level as possible 347 00:21:13,640 --> 00:21:15,220 and as close to the original data set 348 00:21:15,740 --> 00:21:18,680 without introducing more in the other data sets. 349 00:21:20,640 --> 00:21:23,660 One problem I did try to find a workaround for, though, 350 00:21:23,680 --> 00:21:25,240 is that raw binary code 351 00:21:25,740 --> 00:21:28,140 misses some valuable semantic information. 352 00:21:28,740 --> 00:21:31,900 So the x86 instruction set is a, 353 00:21:32,940 --> 00:21:35,380 for example, any function calls 354 00:21:35,380 --> 00:21:38,160 are done relative to the current address. 355 00:21:38,960 --> 00:21:40,880 So if you have a, let's say, 356 00:21:41,080 --> 00:21:44,100 if you have a printf sitting at address 20 in memory, 357 00:21:44,380 --> 00:21:49,700 if it's called from a function at address 5, 358 00:21:50,440 --> 00:21:53,540 it'll say actually call me plus 15. 359 00:21:53,920 --> 00:21:55,580 You know, if you call it at address 10, 360 00:21:55,600 --> 00:21:57,640 it'll say call the function at me plus 10. 361 00:21:58,700 --> 00:22:00,760 So that, you know, that introduces some problems 362 00:22:00,760 --> 00:22:02,440 because there's no way to tell 363 00:22:03,420 --> 00:22:05,640 that the same function is being called multiple times. 364 00:22:06,100 --> 00:22:07,580 So in order to work around this, 365 00:22:07,660 --> 00:22:10,900 I do some basic normalization of the data. 366 00:22:10,920 --> 00:22:12,560 You know, if there's a function that's being imported 367 00:22:12,560 --> 00:22:13,940 somewhere in the binary, 368 00:22:14,680 --> 00:22:15,960 then I'll just take, you know, 369 00:22:16,020 --> 00:22:18,180 before I send it over to be vectorized, 370 00:22:18,300 --> 00:22:20,600 I'll just compute a 32-bit hash of the function name 371 00:22:21,080 --> 00:22:22,820 and substitute that into the address. 372 00:22:23,300 --> 00:22:26,340 So that every time you, let's say, call printf, 373 00:22:26,340 --> 00:22:29,380 the neural network sees that this is a call for the same hash. 374 00:22:35,320 --> 00:22:38,540 So how do we evaluate these embeddings after we use them? 375 00:22:39,640 --> 00:22:42,600 In a lot of cases, the criteria for deciding, you know, 376 00:22:42,600 --> 00:22:44,160 are embeddings any good is kind of like, 377 00:22:44,200 --> 00:22:46,540 well, do they work for the problem I'm trying to solve? 378 00:22:47,980 --> 00:22:50,740 That's, you know, that's great from an engineering perspective, 379 00:22:50,860 --> 00:22:53,620 not so great from a scientific rigor perspective. 380 00:22:55,380 --> 00:22:57,920 So one of the ways you can kind of evaluate embeddings 381 00:22:57,920 --> 00:23:00,980 are you can kind of plot them out and look to see, you know, 382 00:23:01,020 --> 00:23:03,600 do they kind of have some kind of structure that's interesting. 383 00:23:04,480 --> 00:23:07,960 You know, you can do random sampling 384 00:23:07,960 --> 00:23:09,620 or just have somebody kind of eyeball 385 00:23:09,620 --> 00:23:10,880 whether they look good or not. 386 00:23:12,180 --> 00:23:14,900 Now that's okay, but I mean, 387 00:23:14,920 --> 00:23:16,720 having a human kind of eyeball them, 388 00:23:17,820 --> 00:23:19,240 that's, A, it doesn't scale, 389 00:23:19,420 --> 00:23:20,980 and then you're also kind of prone to bias. 390 00:23:21,080 --> 00:23:23,340 You know, if you really want your algorithm to work, 391 00:23:23,340 --> 00:23:25,820 you might be tempted to ignore some of the stuff 392 00:23:26,300 --> 00:23:28,520 that you can't quite explain 393 00:23:28,520 --> 00:23:29,880 and focus on the stuff that you can. 394 00:23:32,080 --> 00:23:34,060 So in order to evaluate these embeddings, 395 00:23:34,340 --> 00:23:36,440 I'm going to kind of borrow some similar things 396 00:23:36,440 --> 00:23:40,280 that one or two researchers in the natural language space 397 00:23:40,280 --> 00:23:42,540 have been doing to figure out some standard tests 398 00:23:42,540 --> 00:23:44,600 for an embedding model. 399 00:23:45,580 --> 00:23:47,480 So in the natural language realm, 400 00:23:49,780 --> 00:23:53,140 you have things like standard lists 401 00:23:53,340 --> 00:23:54,120 of synonyms. 402 00:23:54,280 --> 00:23:56,640 You can evaluate, okay, do the embeddings say 403 00:23:56,640 --> 00:23:58,780 that all of these words are synonyms to each other? 404 00:24:00,040 --> 00:24:02,560 We don't really have that for machine code. 405 00:24:03,140 --> 00:24:07,960 So the criteria I'm proposing are consistencies. 406 00:24:08,240 --> 00:24:10,900 You know, are these embeddings consistent with 407 00:24:10,900 --> 00:24:13,380 embeddings generated with other algorithms 408 00:24:13,380 --> 00:24:14,620 or with other models? 409 00:24:15,900 --> 00:24:17,960 As well as, you know, 410 00:24:17,960 --> 00:24:20,440 the ultimate job of an embedding model 411 00:24:20,440 --> 00:24:22,700 is to try and extract some semantic content 412 00:24:23,340 --> 00:24:25,740 of something into a fixed dimensional space. 413 00:24:26,860 --> 00:24:29,520 So can we come up with some standardized tests 414 00:24:29,520 --> 00:24:33,160 to kind of measure how much semantic meaning 415 00:24:33,160 --> 00:24:33,940 is being extracted? 416 00:24:37,880 --> 00:24:44,280 This is just a scatterplot of some of the embeddings, 417 00:24:44,520 --> 00:24:48,840 you know, plotted by operating system and compiler. 418 00:24:49,380 --> 00:24:50,980 So you can kind of tell, well, 419 00:24:50,980 --> 00:24:52,960 it's not quite as obvious with the colors, 420 00:24:53,340 --> 00:24:54,960 but you can kind of see that, you know, 421 00:24:54,960 --> 00:24:56,200 even just eyeballing it, 422 00:24:57,280 --> 00:24:59,300 the stuff that was compiled with GCC, 423 00:24:59,460 --> 00:25:00,760 which would have been the Arch Linux, 424 00:25:01,060 --> 00:25:03,140 you know, is sitting in a very different 425 00:25:03,820 --> 00:25:05,560 area of the space compared to the stuff 426 00:25:05,560 --> 00:25:06,780 that was compiled with Visual Studio. 427 00:25:08,360 --> 00:25:10,000 And as a human analyst, you know, 428 00:25:10,080 --> 00:25:11,640 I would say, okay, you know, 429 00:25:11,640 --> 00:25:16,020 yeah, so, you know, Visual Studio and GCC 430 00:25:16,020 --> 00:25:18,200 use completely different function prologues 431 00:25:18,200 --> 00:25:19,080 in the book than in the text. 432 00:25:19,580 --> 00:25:20,300 Totally different. 433 00:25:20,440 --> 00:25:21,320 So when I'm looking at it, 434 00:25:21,360 --> 00:25:22,740 it's totally obvious that they're different. 435 00:25:23,740 --> 00:25:25,440 But, you know, when we were training the embeddings, 436 00:25:25,500 --> 00:25:27,140 we didn't try to optimize them. 437 00:25:27,200 --> 00:25:29,000 We didn't say, we didn't tell the model, 438 00:25:29,100 --> 00:25:30,460 hey, these things are separate, 439 00:25:30,600 --> 00:25:31,420 so you should learn that. 440 00:25:32,860 --> 00:25:34,620 That's just something that is picked up on its own. 441 00:25:37,080 --> 00:25:38,480 And for evaluating consistency, 442 00:25:38,880 --> 00:25:40,580 I'm going to define two types of consistency. 443 00:25:41,280 --> 00:25:42,500 I'm going to say heart consistency, 444 00:25:44,100 --> 00:25:47,440 which is, you know, using bottle one, 445 00:25:48,320 --> 00:25:51,180 the nearest neighbor for function A in set one. 446 00:25:52,280 --> 00:25:54,560 If we do the same nearest neighbor measurement 447 00:25:54,560 --> 00:25:56,360 on set two, they have to have 448 00:25:56,360 --> 00:25:57,600 the exact same nearest neighbor. 449 00:25:58,980 --> 00:26:04,520 And that's a fairly rigorous criteria there. 450 00:26:05,360 --> 00:26:06,840 That's something you definitely, 451 00:26:07,340 --> 00:26:09,900 by random chance, it's not going to happen. 452 00:26:09,980 --> 00:26:12,480 And even two reasonable models, you know, 453 00:26:13,180 --> 00:26:16,660 like, for example, is the word fluffy, 454 00:26:17,840 --> 00:26:20,360 you know, a closer synonym to salt 455 00:26:20,360 --> 00:26:21,400 than the word dose. 456 00:26:22,600 --> 00:26:24,540 They both kind of have the same meaning, 457 00:26:24,560 --> 00:26:26,400 but which of those is, should be, 458 00:26:26,520 --> 00:26:28,200 you know, the closest neighbor to salt? 459 00:26:29,980 --> 00:26:31,960 So to kind of relax you a little bit, 460 00:26:32,000 --> 00:26:34,200 I also have a measure of salt consistency, 461 00:26:35,100 --> 00:26:36,700 which is that, you know, 462 00:26:36,700 --> 00:26:39,360 if you take function A in set one, 463 00:26:41,260 --> 00:26:43,240 then its nearest neighbor in set two 464 00:26:43,240 --> 00:26:45,060 is going to be within the 10 nearest neighbors. 465 00:26:46,180 --> 00:26:47,620 That way you're saying, you know, 466 00:26:47,620 --> 00:26:49,500 it may not be exactly the closest one, 467 00:26:49,560 --> 00:26:50,120 but it's still, 468 00:26:50,360 --> 00:26:51,180 you know, in the same area. 469 00:26:54,920 --> 00:26:56,540 So evaluating the models, 470 00:26:56,660 --> 00:26:59,280 I think I actually got some pretty good results 471 00:26:59,280 --> 00:27:00,740 for consistency here. 472 00:27:01,580 --> 00:27:03,380 So for the consistency measurement, 473 00:27:03,560 --> 00:27:05,820 I took a random sample of 10,000 functions, 474 00:27:06,780 --> 00:27:10,300 just because doing a full end-by-end measurement 475 00:27:10,300 --> 00:27:12,300 of 23 million takes forever. 476 00:27:13,960 --> 00:27:15,920 And out of those 10,000 functions, 477 00:27:16,960 --> 00:27:19,400 around a quarter of them met the criteria 478 00:27:19,400 --> 00:27:21,680 for hard consistency between models. 479 00:27:22,240 --> 00:27:26,220 So that's basically both the 100-node neural network 480 00:27:26,220 --> 00:27:27,960 and the 500-node neural network. 481 00:27:28,860 --> 00:27:30,420 Twenty-five percent of the time, 482 00:27:30,560 --> 00:27:32,720 they said, okay, these two functions 483 00:27:32,720 --> 00:27:34,180 have the exact same nearest neighbor. 484 00:27:35,960 --> 00:27:38,140 And when I relax that to the salt consistency 485 00:27:38,840 --> 00:27:40,260 of 10 nearest neighbors, 486 00:27:42,020 --> 00:27:47,260 then we are still getting around 50 plus percent, 487 00:27:47,260 --> 00:27:49,160 which is a really good result. 488 00:27:49,300 --> 00:27:51,560 If you try and look at what you'd expect 489 00:27:51,560 --> 00:27:52,420 from random chance, 490 00:27:52,640 --> 00:27:54,260 you wouldn't expect that in your year 491 00:27:54,260 --> 00:27:58,420 this kind of consistency. 492 00:27:58,940 --> 00:28:02,040 This really kind of gives you some kind of a confidence 493 00:28:02,040 --> 00:28:05,260 that the neural networks are learning consistent, 494 00:28:05,980 --> 00:28:09,700 useful stuff about the data that they're being shown. 495 00:28:13,220 --> 00:28:15,160 So for the problem of standardized tests, 496 00:28:16,860 --> 00:28:18,780 standardized tests, not just for your kids anymore, 497 00:28:20,700 --> 00:28:22,600 some of the tests I came up with are, 498 00:28:23,520 --> 00:28:25,980 given the embedding, can we tell what, 499 00:28:26,020 --> 00:28:29,960 given just embedding, can we train a model 500 00:28:29,960 --> 00:28:31,960 or tell what compiler was used to build that, 501 00:28:32,040 --> 00:28:32,980 to compile that function? 502 00:28:34,920 --> 00:28:36,180 Going a little further, 503 00:28:37,480 --> 00:28:39,540 can we tell what optimization settings 504 00:28:39,540 --> 00:28:40,780 were used with that compiler? 505 00:28:42,300 --> 00:28:43,520 And on top of that, 506 00:28:44,680 --> 00:28:47,160 can we determine whether a particular, 507 00:28:47,440 --> 00:28:49,360 functions from a particular library, 508 00:28:49,600 --> 00:28:51,740 for example, WS232.dll, 509 00:28:51,980 --> 00:28:53,480 can we tell whether those were used 510 00:28:53,480 --> 00:28:55,400 in this function from the embedding? 511 00:28:59,140 --> 00:29:00,340 So to do that, 512 00:29:00,400 --> 00:29:02,380 given that I had labeled data 513 00:29:02,380 --> 00:29:03,660 because I compiled all these things myself, 514 00:29:04,760 --> 00:29:06,600 I trained several classifiers. 515 00:29:06,860 --> 00:29:09,280 So I trained the logistic progression classifier 516 00:29:09,280 --> 00:29:11,900 to tell what compiler was used. 517 00:29:11,900 --> 00:29:13,980 And no surprise, 518 00:29:14,180 --> 00:29:16,020 that actually got 100% accuracy. 519 00:29:17,340 --> 00:29:18,860 Which, looking at the 520 00:29:18,860 --> 00:29:20,580 PC plot from earlier, 521 00:29:20,700 --> 00:29:22,380 you can kind of tell that the two classes 522 00:29:22,380 --> 00:29:25,840 are basically linearly separable in this space. 523 00:29:27,120 --> 00:29:29,140 What I was actually even more impressed with 524 00:29:29,140 --> 00:29:32,660 was the softmax classifier that I built for 525 00:29:33,720 --> 00:29:35,340 detecting the compiler optimization 526 00:29:36,300 --> 00:29:39,320 actually got between 72 and 85% accuracy 527 00:29:39,320 --> 00:29:41,600 depending on which embedding type, 528 00:29:41,620 --> 00:29:41,840 you know, 529 00:29:41,900 --> 00:29:42,960 we've got a little better 530 00:29:42,960 --> 00:29:44,680 with the higher dimensional embedding. 531 00:29:45,900 --> 00:29:46,780 That's really impressive 532 00:29:46,780 --> 00:29:47,820 when you consider that 533 00:29:47,820 --> 00:29:49,920 in a lot of cases, 534 00:29:50,040 --> 00:29:51,300 especially for small functions, 535 00:29:52,060 --> 00:29:54,700 a compiler may not generate different code. 536 00:29:54,900 --> 00:29:55,660 You know, if you have a code, 537 00:29:55,720 --> 00:29:56,560 if you have a function 538 00:29:56,560 --> 00:29:57,640 that just takes two numbers, 539 00:29:57,700 --> 00:29:58,860 adds them, and returns the result, 540 00:29:59,380 --> 00:30:00,380 it doesn't really matter 541 00:30:00,380 --> 00:30:01,600 if you're using 01 or 03. 542 00:30:01,800 --> 00:30:03,420 There's really not much you can do 543 00:30:03,420 --> 00:30:04,840 to change that and make it better. 544 00:30:05,860 --> 00:30:07,160 And even in the cases 545 00:30:07,160 --> 00:30:09,220 where the softmax classifier 546 00:30:09,220 --> 00:30:10,920 didn't get the correct 547 00:30:11,960 --> 00:30:12,800 optimization setting, 548 00:30:13,700 --> 00:30:15,920 it still determined that it was 549 00:30:15,920 --> 00:30:16,840 the correct compiler. 550 00:30:16,980 --> 00:30:17,400 You wouldn't just say, 551 00:30:17,460 --> 00:30:18,720 well, I know this is GCC, 552 00:30:18,980 --> 00:30:20,860 but I'm not, you know, 553 00:30:20,900 --> 00:30:22,620 I'm going to say maybe it's 51% 554 00:30:22,620 --> 00:30:24,880 that it's compiled with dash 01 555 00:30:24,880 --> 00:30:28,900 and 49.5% that it's compiled with dash 03. 556 00:30:29,220 --> 00:30:30,420 That's definitely not the case. 557 00:30:33,180 --> 00:30:34,380 In addition to that, 558 00:30:34,420 --> 00:30:36,040 I trained a random port classifier 559 00:30:36,920 --> 00:30:40,460 on functions that had WF232 560 00:30:40,460 --> 00:30:43,360 or imports from WF232.dll 561 00:30:43,920 --> 00:30:45,420 and functions that didn't. 562 00:30:46,060 --> 00:30:47,360 That was able to get about 563 00:30:47,360 --> 00:30:49,160 a 78 to 91% accuracy, 564 00:30:49,280 --> 00:30:50,680 with the accuracy increasing 565 00:30:50,680 --> 00:30:52,660 with the dimensionality of embeddings, 566 00:30:53,640 --> 00:30:54,920 which I thought that was 567 00:30:54,920 --> 00:30:55,980 actually really cool. 568 00:30:56,180 --> 00:30:57,560 The embeddings really appear 569 00:30:57,560 --> 00:30:59,460 to be encoding things like, 570 00:30:59,560 --> 00:31:01,060 okay, this has an import 571 00:31:01,060 --> 00:31:02,900 from the Windows network library. 572 00:31:07,220 --> 00:31:08,580 You know, it looks like 573 00:31:08,580 --> 00:31:09,220 these things work. 574 00:31:09,220 --> 00:31:13,320 So how can we actually do something with it? 575 00:31:16,980 --> 00:31:20,600 So this is where the framework 576 00:31:20,600 --> 00:31:21,420 that I'm working on 577 00:31:21,420 --> 00:31:22,520 calling JumpGate comes in. 578 00:31:24,340 --> 00:31:25,980 So basically one of the challenges 579 00:31:25,980 --> 00:31:27,320 in the reverse engineering space 580 00:31:27,320 --> 00:31:28,580 is that there is definitely 581 00:31:28,580 --> 00:31:30,520 not a shortage of tools to use. 582 00:31:31,280 --> 00:31:32,320 You've got IDA Pro, 583 00:31:32,600 --> 00:31:33,640 you've got Binary Ninja, 584 00:31:33,880 --> 00:31:34,520 you've got Redare. 585 00:31:35,000 --> 00:31:36,040 All these frameworks 586 00:31:36,040 --> 00:31:37,320 do really awesome stuff. 587 00:31:38,160 --> 00:31:39,940 None of them interoperate well, 588 00:31:40,020 --> 00:31:41,380 and none of them really work 589 00:31:41,780 --> 00:31:42,660 in the same way. 590 00:31:42,780 --> 00:31:43,780 So in a lot of cases, 591 00:31:43,980 --> 00:31:46,600 you know, analysts will kind of pick 592 00:31:47,640 --> 00:31:48,680 which do they like better. 593 00:31:48,840 --> 00:31:49,880 You know, you have some people 594 00:31:49,880 --> 00:31:50,240 that are like, 595 00:31:50,300 --> 00:31:51,700 I'm an IDA Pro user, 596 00:31:51,960 --> 00:31:52,560 you know, I don't want 597 00:31:52,560 --> 00:31:53,280 to touch anything else. 598 00:31:53,320 --> 00:31:53,780 Others are like, 599 00:31:54,140 --> 00:31:55,400 oh, IDA Pro is too expensive, 600 00:31:55,560 --> 00:31:56,220 I like Redare. 601 00:31:57,900 --> 00:31:58,800 So my goal here 602 00:31:58,800 --> 00:32:00,580 is to be able to take embeddings 603 00:32:00,580 --> 00:32:02,280 and use them with whatever 604 00:32:02,280 --> 00:32:03,320 kind of front-end you want. 605 00:32:04,620 --> 00:32:06,040 If you're an IDA user, 606 00:32:06,160 --> 00:32:07,120 you should be able to use 607 00:32:07,120 --> 00:32:07,300 as many of these things 608 00:32:07,320 --> 00:32:07,840 and embedding models 609 00:32:07,840 --> 00:32:10,540 that Redare users train 610 00:32:11,120 --> 00:32:11,880 and vice versa. 611 00:32:14,540 --> 00:32:16,100 So kind of the architecture 612 00:32:16,100 --> 00:32:16,860 with JumpGate 613 00:32:16,860 --> 00:32:18,380 is you'll have your client, 614 00:32:18,540 --> 00:32:20,200 which is going to be IDA Pro, 615 00:32:20,500 --> 00:32:22,080 you know, Binary Ninja, Redare, 616 00:32:22,660 --> 00:32:23,900 whatever front-end 617 00:32:23,900 --> 00:32:24,820 you really like to use. 618 00:32:25,880 --> 00:32:28,040 The key here is the vectorizer, 619 00:32:28,240 --> 00:32:31,940 which is basically just a Python class 620 00:32:31,940 --> 00:32:33,580 that implements the... 621 00:32:33,580 --> 00:32:35,220 You can write vectorizers 622 00:32:35,220 --> 00:32:36,740 for whatever framework you want, 623 00:32:36,800 --> 00:32:36,980 you know, 624 00:32:37,320 --> 00:32:38,000 if you're a PyTorch person, 625 00:32:38,660 --> 00:32:39,820 you can write your vectorizer 626 00:32:39,820 --> 00:32:40,600 in PyTorch. 627 00:32:40,700 --> 00:32:42,940 If you're a Keras person, 628 00:32:43,060 --> 00:32:44,020 you can write it in Keras. 629 00:32:45,180 --> 00:32:46,500 If you really like just coding 630 00:32:46,500 --> 00:32:47,580 everything from the ground up, 631 00:32:47,600 --> 00:32:48,120 you can do that. 632 00:32:48,820 --> 00:32:50,480 You know, as long as you can 633 00:32:50,480 --> 00:32:51,100 send something, 634 00:32:51,140 --> 00:32:53,240 a flat-screen device, 635 00:32:53,800 --> 00:32:54,700 then you're good to go. 636 00:32:55,680 --> 00:32:56,260 From there, 637 00:32:56,320 --> 00:32:57,280 your vectorizer will, 638 00:32:57,720 --> 00:32:58,460 you know, convert, 639 00:32:58,680 --> 00:32:59,780 move it up into this 640 00:32:59,780 --> 00:33:00,200 high-dimensional, 641 00:33:00,300 --> 00:33:01,880 into your high-dimensional space, 642 00:33:02,660 --> 00:33:03,780 and you can send it on 643 00:33:03,780 --> 00:33:04,960 to modules that do 644 00:33:04,960 --> 00:33:06,880 whatever tasks you want to do, 645 00:33:06,960 --> 00:33:07,300 whatever you want to do. 646 00:33:07,300 --> 00:33:07,520 If you want to train 647 00:33:07,520 --> 00:33:08,260 a compiler software, 648 00:33:09,440 --> 00:33:10,100 go for that. 649 00:33:10,260 --> 00:33:10,420 You know, 650 00:33:10,420 --> 00:33:11,220 if you want to have it 651 00:33:12,120 --> 00:33:14,040 do find the 10 nearest neighbors 652 00:33:14,040 --> 00:33:15,440 in your collection of functions 653 00:33:15,440 --> 00:33:16,860 and send back whether you have 654 00:33:16,860 --> 00:33:18,380 something within a certain distance, 655 00:33:18,640 --> 00:33:19,200 you can do that. 656 00:33:19,340 --> 00:33:19,560 You know, 657 00:33:19,560 --> 00:33:21,460 it's really intentionally 658 00:33:21,460 --> 00:33:23,800 less very freeform, 659 00:33:23,880 --> 00:33:24,580 so that you can do 660 00:33:25,420 --> 00:33:26,360 whatever you want with it. 661 00:33:29,760 --> 00:33:30,380 Like I said, 662 00:33:30,380 --> 00:33:30,880 some of the, 663 00:33:30,880 --> 00:33:31,860 you know, 664 00:33:31,860 --> 00:33:32,860 sample applications 665 00:33:32,860 --> 00:33:35,780 that I've either tested 666 00:33:35,780 --> 00:33:36,940 or am working on right now 667 00:33:36,940 --> 00:33:37,240 are, 668 00:33:38,280 --> 00:33:38,980 you know, 669 00:33:38,980 --> 00:33:39,460 are function similarities. 670 00:33:40,220 --> 00:33:40,580 So, 671 00:33:40,580 --> 00:33:42,080 I've got this binary 672 00:33:42,080 --> 00:33:44,000 that I just found somewhere, 673 00:33:44,200 --> 00:33:44,760 I don't even know. 674 00:33:46,300 --> 00:33:46,960 In my, 675 00:33:47,080 --> 00:33:48,160 in all the other binaries 676 00:33:48,160 --> 00:33:48,500 I've seen, 677 00:33:48,580 --> 00:33:49,440 do I have similar functions? 678 00:33:51,100 --> 00:33:51,940 Compiler identification, 679 00:33:52,520 --> 00:33:53,420 is this binary, 680 00:33:53,660 --> 00:33:54,800 which functions were compiled 681 00:33:54,800 --> 00:33:55,880 with Visual Studio? 682 00:33:56,140 --> 00:33:56,440 You know, 683 00:33:56,460 --> 00:33:57,040 are they running at 684 00:33:57,040 --> 00:33:57,520 what's compiled 685 00:33:57,520 --> 00:33:58,480 with Visual Studio? 686 00:33:58,780 --> 00:33:59,860 That might be interesting. 687 00:34:01,320 --> 00:34:01,800 Crypto, 688 00:34:01,800 --> 00:34:02,420 is that, 689 00:34:02,920 --> 00:34:04,140 a little more challenging 690 00:34:04,140 --> 00:34:05,000 because that requires 691 00:34:05,000 --> 00:34:05,940 building a data set 692 00:34:05,940 --> 00:34:07,260 of known cryptos 693 00:34:07,280 --> 00:34:07,580 or functions, 694 00:34:07,680 --> 00:34:08,560 stream classifier, 695 00:34:09,110 --> 00:34:10,040 and all that stuff. 696 00:34:10,340 --> 00:34:10,380 But, 697 00:34:11,460 --> 00:34:12,420 this kind of enables 698 00:34:12,420 --> 00:34:13,160 that a little bit. 699 00:34:13,500 --> 00:34:14,460 And kind of the only 700 00:34:14,460 --> 00:34:15,360 limitation is, 701 00:34:15,400 --> 00:34:16,380 what can you think of 702 00:34:16,380 --> 00:34:17,240 to do with 703 00:34:18,180 --> 00:34:18,640 vector, 704 00:34:18,760 --> 00:34:20,040 vector space model code? 705 00:34:22,260 --> 00:34:22,720 So, 706 00:34:22,760 --> 00:34:23,440 some of the ongoing 707 00:34:23,440 --> 00:34:24,480 stuff I'm doing 708 00:34:24,480 --> 00:34:24,860 with this, 709 00:34:25,500 --> 00:34:26,400 planning on doing 710 00:34:26,400 --> 00:34:26,640 a, 711 00:34:26,680 --> 00:34:27,520 building out 712 00:34:27,520 --> 00:34:28,880 a 64-bit data set 713 00:34:28,880 --> 00:34:29,100 model. 714 00:34:29,460 --> 00:34:30,340 That should be 715 00:34:30,340 --> 00:34:31,780 a lot more interesting, 716 00:34:32,880 --> 00:34:33,800 54 bits, 717 00:34:34,700 --> 00:34:35,620 where everything's 718 00:34:35,620 --> 00:34:36,260 moving right now, 719 00:34:36,320 --> 00:34:36,820 as well as, 720 00:34:36,840 --> 00:34:37,260 you don't have 721 00:34:37,280 --> 00:34:37,840 the same, 722 00:34:39,060 --> 00:34:39,540 function, 723 00:34:40,680 --> 00:34:41,440 calling different 724 00:34:41,440 --> 00:34:42,180 complexity 725 00:34:42,180 --> 00:34:42,680 that you have 726 00:34:42,680 --> 00:34:43,260 with x86. 727 00:34:43,640 --> 00:34:43,720 So, 728 00:34:43,720 --> 00:34:44,620 you can do 729 00:34:44,620 --> 00:34:45,740 compiler problems 730 00:34:45,740 --> 00:34:46,760 on 54 bits 731 00:34:46,760 --> 00:34:47,380 with the same 732 00:34:47,380 --> 00:34:47,620 actually. 733 00:34:47,780 --> 00:34:48,860 That should be 734 00:34:48,860 --> 00:34:49,700 fairly interesting. 735 00:34:50,600 --> 00:34:51,080 Also, 736 00:34:51,160 --> 00:34:51,540 in the middle 737 00:34:51,540 --> 00:34:52,000 of transitioning 738 00:34:52,000 --> 00:34:52,960 the entire project 739 00:34:52,960 --> 00:34:53,600 from Python 2 740 00:34:53,600 --> 00:34:54,280 to Python 3. 741 00:34:54,480 --> 00:34:54,580 But, 742 00:34:55,500 --> 00:34:56,500 not up in GitHub 743 00:34:56,500 --> 00:34:57,400 right now. 744 00:34:57,520 --> 00:34:58,160 While I finish 745 00:34:58,160 --> 00:34:58,740 that transition, 746 00:34:59,280 --> 00:34:59,760 hopefully, 747 00:34:59,960 --> 00:35:01,020 I'll get it up there 748 00:35:01,020 --> 00:35:01,620 within the next 749 00:35:01,620 --> 00:35:02,100 week or so. 750 00:35:08,240 --> 00:35:08,620 And, 751 00:35:08,660 --> 00:35:09,160 other than that, 752 00:35:09,240 --> 00:35:10,460 that's my talk. 753 00:35:10,720 --> 00:35:11,350 You can message 754 00:35:11,960 --> 00:35:12,480 me on Twitter 755 00:35:12,480 --> 00:35:12,940 if you want.