1 00:00:00,000 --> 00:00:04,700 Welcome to AI Village. The next talk is It's a Beautiful Day in the Malware Neighborhood by 2 00:00:04,700 --> 00:00:09,960 Matt. And basically we'd like to thank our sponsors, Endgame, Silence, Sophos, and Tinder. 3 00:00:10,480 --> 00:00:14,480 And of course, Silence Your Cell Phones. And if you have an open seat next to you, please raise 4 00:00:14,480 --> 00:00:18,420 your hand so the people next to you or people coming in can know there's a seat. Thanks. 5 00:00:19,840 --> 00:00:23,700 Hey, good afternoon, everyone. Even though Silence is a sponsor, don't worry, this isn't a 6 00:00:23,700 --> 00:00:29,380 sponsored talk. This tool is completely open source. So again, my name is Matt Maisel. I'm 7 00:00:29,380 --> 00:00:34,860 the manager of security data science at Silence. And specifically today, I'm going to be 8 00:00:34,860 --> 00:00:39,520 talking about the use of nearest neighbor search techniques applied to malware similarity, 9 00:00:39,640 --> 00:00:45,020 specifically in a tool called Rogers. That's open source on GitHub right now. I have a feature 10 00:00:45,020 --> 00:00:48,760 branch that I'm working on some updates from the content today that I'll present. But this tool 11 00:00:48,760 --> 00:00:53,100 is designed for malware analysts and security data scientists to perform malware similarity 12 00:00:53,100 --> 00:00:59,360 research. So just some motivation. So building databases of our malware is one of the 13 00:00:59,380 --> 00:01:03,320 things that is interesting for analysts and for data scientists. So search and retrieval of 14 00:01:03,320 --> 00:01:09,500 similar samples, you know, can provide valuable context to analysts and systems. The objective in 15 00:01:10,140 --> 00:01:14,620 this case is to basically build a database, index our malware by some attribute or some set of 16 00:01:14,620 --> 00:01:19,680 attributes. And when we have some unknown sample, query that database. And hopefully if we've 17 00:01:19,680 --> 00:01:24,600 ever seen a similar sample, we get back valuable context, you know, maybe other labeled samples, 18 00:01:24,900 --> 00:01:29,300 maybe samples that have been reversed and we have, you know, a lot of details on. So that's a 19 00:01:29,380 --> 00:01:33,220 use case kind of number one for these systems. Use case number two is, you know, if a sample 20 00:01:33,220 --> 00:01:38,080 we've never seen before and it also doesn't match anything in our corpus, you know, we can 21 00:01:38,080 --> 00:01:44,860 prioritize that for manual analysis or maybe more advanced reverse engineering. Finally, kind of 22 00:01:44,860 --> 00:01:51,160 the final use case of search and retrieval systems for malware similarity is to augment larger 23 00:01:51,160 --> 00:01:55,620 systems, maybe doing clustering or maybe doing classification. So we can use nearest neighbor 24 00:01:55,620 --> 00:01:59,360 search techniques to basically process incoming alerts and leverage all of the information from ouremebrace 25 00:01:59,380 --> 00:02:04,180 that we get back with the context to determine if we want to route that sample to other 26 00:02:04,180 --> 00:02:09,360 workflows in our environment. Historically this of course has been done in big databases of 27 00:02:09,360 --> 00:02:14,600 cryptographic hashes. Fuzzy hashing, notably SS deep is also kind of a standard approach 28 00:02:14,600 --> 00:02:20,040 still and still a good factor I'd argue. So how does this relate to nearest neighbor search? 29 00:02:20,220 --> 00:02:25,180 So if we consider malware similarity as being performed through comparison of raw bytes or 30 00:02:25,180 --> 00:02:30,060 extracted static and dynamic features that distill the semantic characteristics we can take 31 00:02:30,060 --> 00:02:34,180 these features and represent them in this end dimensional feature space and with that we can 32 00:02:34,180 --> 00:02:38,440 feed that into a lot of nearest neighbor search algorithms as well as other machine learning 33 00:02:38,440 --> 00:02:43,620 algorithms as well too. So nearest neighbor search simply put is the task of being given a 34 00:02:43,620 --> 00:02:50,400 set of samples X or corpus, basically take a query sample or unknown sample XQ and query the 35 00:02:50,400 --> 00:02:54,820 index and basically get back the K nearest neighbors according to some distance function. And 36 00:02:54,820 --> 00:02:55,160 there's you know there's a lot of things that can be done with that. So if you look at the 37 00:02:55,180 --> 00:02:58,640 you know many different distance functions that can be used here, a gentleman earlier today 38 00:02:58,640 --> 00:03:03,160 mentioned Euclidean, you know we can use cosine, we can even use other metrics like string 39 00:03:03,160 --> 00:03:08,780 metrics that operate on edit distance or Levenstein distance. And ultimately nearest neighbor 40 00:03:08,780 --> 00:03:14,260 search of course is hard at scale you know with high dimensional space so we have to look at 41 00:03:14,260 --> 00:03:19,840 approximate variance of this that allows some error threshold epsilon and basically kind of 42 00:03:19,840 --> 00:03:24,560 bounds our true distance whenever we query our index. And just again as a really simple example here 43 00:03:24,560 --> 00:03:30,820 if this kind of two dimensional space here is if we query this red dot here, the K nearest neighbor 44 00:03:30,820 --> 00:03:35,400 for three would be these three samples in the inner circle. If there is maybe, if this is maybe an 45 00:03:35,400 --> 00:03:40,380 approximate variance you know there might be a chance that we could accidentally return some of 46 00:03:40,380 --> 00:03:47,140 these samples in the larger kind of radius here. So don't worry I don't have any algorithms but I 47 00:03:47,140 --> 00:03:52,120 actually cut out a lot of this but there's a lot of interesting theory and literature around 48 00:03:52,120 --> 00:03:54,540 nearest neighbor search. You know over the past few years I've been working with a lot of these 49 00:03:54,540 --> 00:03:58,160 data centers for several decades. I kind of categorized them specifically in three different 50 00:03:58,160 --> 00:04:02,860 areas. So there's tree based methods you know where we're basically partitioning our data set 51 00:04:02,860 --> 00:04:08,760 into you know these cells in our feature space. So we use tree data structures to exploit that 52 00:04:08,760 --> 00:04:14,340 nature and basically rapidly look up and identify the cell. Kind of shown here in this case here 53 00:04:14,340 --> 00:04:19,080 still in a two dimensional space. We use a tree data structure to quickly look up and identify 54 00:04:19,080 --> 00:04:24,440 nearest neighbors in this particular cell. There's also hashing nearest neighbor methods as well 55 00:04:24,540 --> 00:04:28,720 too. You know where we're typically in this case applying a non cryptographic hash that kind of 56 00:04:28,720 --> 00:04:33,540 has this property of you know ensuring that any small input or any small change in the input space 57 00:04:34,000 --> 00:04:38,020 only results in a small change in the output space. So the idea is here we're actually looking 58 00:04:38,020 --> 00:04:42,980 for collisions between similar objects. In this case we can come up with different hashing 59 00:04:42,980 --> 00:04:48,400 algorithms. Locality sensitive hashing is one kind of popular one where the whole idea is to find 60 00:04:48,400 --> 00:04:52,520 hashing functions that take some input. So some input sample in this case represented by our 61 00:04:52,520 --> 00:04:54,520 feature vector. And if we hash it we can actually find the hash function that takes some input. So 62 00:04:54,540 --> 00:04:58,140 if we hash it we ultimately want to end up in the same bucket or end up with the same hash code if 63 00:04:58,140 --> 00:05:02,660 it's similar. And then again ultimately this determines it reduces the number of candidates in 64 00:05:02,660 --> 00:05:06,900 this case that end up in the same bucket ultimately to actually do distance comparisons on. 65 00:05:07,380 --> 00:05:11,660 Because doing you know again doing like pairwise distance is super expensive and no one wants to do 66 00:05:11,660 --> 00:05:17,980 that. Finally a kind of more recent really more recent approach for nearest neighbor search is 67 00:05:17,980 --> 00:05:22,640 graph based methods. So the general idea here is that we're going to build these proximity graphs. 68 00:05:22,840 --> 00:05:24,520 Maybe several layers of these proximity graphs. So we're going to build these proximity graphs. 69 00:05:24,540 --> 00:05:30,180 of graphs that we kind of stack together. And we have algorithms that basically do a initial kind of 70 00:05:30,180 --> 00:05:35,520 offline phase of building our graph and connect to the neighbors and with these edges based off of 71 00:05:35,520 --> 00:05:40,820 their similarity. And then ultimately query time we kind of end up in one part of the graph and 72 00:05:40,820 --> 00:05:45,660 navigate around basically traverse our graph potentially traverse multiple layers and build up 73 00:05:45,660 --> 00:05:50,260 our candidate set for comparison. The downside here is that a lot of the graphing algorithms are 74 00:05:50,260 --> 00:05:54,520 extremely expensive. You know we have to basically find specific types of graphs. We're going to 75 00:05:54,540 --> 00:05:58,940 do this when we do our build our offline build phase. That make them easy to search through and 76 00:05:58,940 --> 00:06:06,240 traverse through in a short amount of time. So there's a crap ton of methods out there. I highly 77 00:06:06,240 --> 00:06:12,160 recommend checking out this ANN benchmarks page. It's on GitHub. There's a paper associated with 78 00:06:12,160 --> 00:06:19,180 all two. Every so often this developer reruns all the latest and greatest implementations of 79 00:06:19,180 --> 00:06:24,200 these various nearest neighbor search methods across a wide variety of data sets for benchmarking. 80 00:06:24,540 --> 00:06:29,740 Kind of the typical benchmark that's used here is this trade off between queries per second so how 81 00:06:29,740 --> 00:06:35,560 fast can we look up items to the recall. In this case the recall is the fraction of the true 82 00:06:35,560 --> 00:06:39,600 nearest neighbors returned in our search. So the kind of general idea here is that you know up and 83 00:06:39,600 --> 00:06:43,920 to the right is better but you can kind of see usually there's this trade off of hey we can query 84 00:06:43,920 --> 00:06:48,740 our index for nearest neighbors very quickly. Again if this is like in a large production system 85 00:06:49,180 --> 00:06:54,440 but we get that at the expense of having really low recall. Conversely if we you know really want a 86 00:06:54,540 --> 00:06:58,680 high recall basically we want our approximate methods to bring back the exact results and we 87 00:06:58,680 --> 00:07:04,080 typically trade that off at the cost of queries per second. Now one algorithm to kind of point out 88 00:07:04,080 --> 00:07:09,580 here and I'll get into it in a bit is this HNSW or hierarchical navigable small world. So 89 00:07:09,580 --> 00:07:14,760 that's this line right here. So it does fairly well and again this is just one example of this 90 00:07:14,760 --> 00:07:20,340 New York Times data set for K equals 100. If you go back to their site you'll see that it 91 00:07:20,340 --> 00:07:24,520 actually does fairly well across a large a wide variety of data sets. And also you can see that 92 00:07:24,540 --> 00:07:30,460 it does well at varying levels of K. So hence kind of why that's one of the algorithms that I 93 00:07:30,460 --> 00:07:34,900 specifically picked to look at and you know use the implementation in Rogers for our 94 00:07:34,900 --> 00:07:40,340 similarity. So this method was recently created in 2017 against based on a lot of different 95 00:07:40,340 --> 00:07:46,200 algorithms in graph nearest neighbor search. But the basic idea at a high level is basically 96 00:07:46,200 --> 00:07:52,240 construct this multilayer graph and use it to greedily identify candidates for comparison. So as 97 00:07:52,240 --> 00:07:54,040 I kind of alluded to in my overview slide. 98 00:07:54,540 --> 00:07:58,520 You know there's this phase where we construct this graph. We query the candidates through this 99 00:07:58,520 --> 00:08:03,160 traversal mechanism and then iteratively search neighboring nodes until some stopping criteria is 100 00:08:03,160 --> 00:08:08,420 met. So HNSW defines all that all the kind of methods there for the stopping criteria for the 101 00:08:08,420 --> 00:08:13,260 way that we build the graph. And ultimately kind of just to sketch this out here after we built 102 00:08:13,260 --> 00:08:17,620 this graph consisting of multiple layers. So it's really multiple layers of graphs. You know we 103 00:08:17,620 --> 00:08:22,500 set different parameters for this algorithm to determine how frequently basically how deep a 104 00:08:22,500 --> 00:08:24,220 sample ends up in one of these layers. 105 00:08:24,540 --> 00:08:29,960 I should say how shallow. So we basically start from the top layer here going down to the bottom 106 00:08:29,960 --> 00:08:35,480 layer. But the idea at query time is once we've constructed these layers of graphs we start at 107 00:08:35,480 --> 00:08:39,780 some point here and navigate. In this case there's only one sample. So it basically searches the 108 00:08:39,780 --> 00:08:44,000 neighborhood goes right to the sample. Eventually reaches a local minimum here because there's no 109 00:08:44,000 --> 00:08:47,940 other neighbors to look for. And then drops down to the next layer. And it kind of this process 110 00:08:47,940 --> 00:08:52,780 continues until eventually we get to the final layer. And this is also can be tuned as well to a 111 00:08:52,780 --> 00:08:54,460 query time to determine how deep into the. 112 00:08:54,540 --> 00:09:00,160 Layers of graphs we'd like to go. But ultimately this results and again the kind of this paper 113 00:09:00,160 --> 00:09:05,820 based. Bases this approach and basically ensures that any samples that we visit across all the 114 00:09:05,820 --> 00:09:10,240 layers are likely to be nearest neighbors. And that's ultimately what we use to determine the 115 00:09:10,240 --> 00:09:14,980 number of candidates that we end up querying. Or sorry end up doing a comparison against with our 116 00:09:14,980 --> 00:09:21,980 query. So that's a graph based method. So there's also another really recent method too that I 117 00:09:21,980 --> 00:09:24,520 actually caught at the NIPS workshop. And it's called the graph based method. And it's kind of a 118 00:09:25,120 --> 00:09:29,500 little bit different. It's basically a machine learning research conference back last fall. It's 119 00:09:29,500 --> 00:09:35,340 really interesting. So it's called prioritized dynamic continuous indexing or PDCI. And there's an 120 00:09:35,340 --> 00:09:40,000 earlier iteration of this just called dynamic continuous indexing as well too. So the authors 121 00:09:40,000 --> 00:09:44,860 here actually design an exact randomized algorithm. And it's built around this idea that we're 122 00:09:44,860 --> 00:09:49,560 going to avoid partitioning samples by vector space. So kind of going back to this example with 123 00:09:49,560 --> 00:09:54,040 the tree based methods where we're kind of splitting up our feature space along the each feature. 124 00:09:54,540 --> 00:10:01,020 That gets, that basically has a lot of issues. And PDCI, the authors notice that, you know, what we 125 00:10:01,020 --> 00:10:06,700 can do is just build these indices and basically take our samples and project them along a random 126 00:10:06,700 --> 00:10:10,560 direction. And we do this so we can control the number of indices we want to build to basically 127 00:10:10,560 --> 00:10:16,620 determine how well this method actually works. And the idea is we construct multiple indices and 128 00:10:16,620 --> 00:10:23,160 the kind of, the main gist is that as you visit the indices and you query the index, you end up at a 129 00:10:23,160 --> 00:10:24,520 place where you're, you're basically going to get a number of indexes. And that's kind of the 130 00:10:24,540 --> 00:10:29,680 way basically your query is projected to. Any of the samples that are nearby, either in this case 131 00:10:29,680 --> 00:10:34,820 that are larger or smaller, you kind of pop those samples off. And if they end up appearing in all 132 00:10:34,820 --> 00:10:40,060 indices, again this paper kind of shows that that's highly likely to be the exact nearest 133 00:10:40,060 --> 00:10:45,060 neighbors. So you add that to the candidate set for comparison. And again this, this is 134 00:10:45,060 --> 00:10:50,140 particularly interesting because in this, specifically within this exact nearest neighbor 135 00:10:50,140 --> 00:10:54,520 search method, some of the guarantees in this paper are, are pretty, pretty compelling. And 136 00:10:54,540 --> 00:10:59,640 unfortunately though because it's an academic paper, I mean the author is a pretty well, a very 137 00:10:59,640 --> 00:11:05,160 well respected PhD student I think at Berkeley. But there's no open source implementation yet. So I 138 00:11:05,160 --> 00:11:11,440 went ahead and tried to do a naive implementation in Rogers specifically. So that's PDCI. Again 139 00:11:11,440 --> 00:11:18,600 these two algorithms are the ones that kind of I focus on right now for this talk. So other, other 140 00:11:18,600 --> 00:11:22,540 malware similarity systems, you know, there's quite a few that have different approaches to doing 141 00:11:22,540 --> 00:11:24,520 this for nearest neighbor search or just similarity systems. So I'm going to go ahead and show you 142 00:11:24,540 --> 00:11:28,220 the, the probability of similarity in general. So of course FiresTotal has different ways to 143 00:11:28,220 --> 00:11:35,480 index data, also using SS deep. But also a, a clustering, basically clustering API that is based 144 00:11:35,480 --> 00:11:39,940 off of feature hashing of the static from my understanding from the, the docs, from the 145 00:11:39,940 --> 00:11:44,180 structural data pulled out from static feature extraction. And this is actually where I source 146 00:11:44,180 --> 00:11:49,200 some of my, my datasets for evaluation of these methods, which you'll soon see to the, to my 147 00:11:49,200 --> 00:11:54,520 detriment unfortunately. Our very own Brian Wallace, one of the, one of the first 148 00:11:54,540 --> 00:11:59,520 the AI Village core team members actually came up with a blog, wrote a blog post in 149 00:11:59,520 --> 00:12:05,340 Virus Bulletin a few years back that basically exploited the way that the SSDeep message 150 00:12:05,340 --> 00:12:10,600 digest is built to eliminate the number of comparisons needed. And then more recently, 151 00:12:10,800 --> 00:12:15,500 you know, again, you can take this idea and basically apply it to Elasticsearch as well 152 00:12:15,500 --> 00:12:20,380 too. So you can just use an off-the-shelf database to actually use the same kind of 153 00:12:20,380 --> 00:12:24,800 method here for indexed SSDeep. So again, that's using one of the similarity digest 154 00:12:24,800 --> 00:12:29,260 methods that's kind of in the bigger, larger group, I should say, of hashing-based nearest 155 00:12:29,260 --> 00:12:34,300 neighbor methods. And then, of course, there's kind of the popular academic implementations 156 00:12:34,300 --> 00:12:41,080 of malware similarity systems. So BitShred is highly cited back in 2011. So it uses pairwise 157 00:12:41,080 --> 00:12:45,420 Jacquard similarity, and it uses Hadoop to do that. So it gets, again, fully pairwise, 158 00:12:45,460 --> 00:12:50,160 so that's very expensive, hence the need for Hadoop. There's also the malware provenance 159 00:12:50,160 --> 00:12:50,360 system. 160 00:12:50,380 --> 00:12:56,260 Which is a little bit more recent, that uses minhash, a type of the, basically an LSH family, 161 00:12:56,460 --> 00:13:02,460 a locality-sensitive hashing family that approximates Jacquard similarity. So that's used 162 00:13:03,040 --> 00:13:08,040 across the sliding window of Ngram features on disassembled samples. And yeah, those are 163 00:13:08,040 --> 00:13:15,140 the two final ones here. There's also Malheur, which focuses more on the behavioral feature 164 00:13:15,140 --> 00:13:20,280 similarity comparison, specifically for Cuckoo. It's a, there's a lot of different 165 00:13:20,380 --> 00:13:24,340 capabilities built in there for clustering and also classification. But underneath the 166 00:13:24,340 --> 00:13:29,920 hood, there's this kind of use of looking at behavior features for doing prototype identification 167 00:13:30,260 --> 00:13:35,420 and prototype selection. So you can basically identify prototypes that are in a large cluster, 168 00:13:35,600 --> 00:13:39,360 pretty much like the Centroid around these points, and use that for a way to quickly 169 00:13:39,360 --> 00:13:44,500 do comparison. And then, there's also the Brothers Wurzburg, which kind of takes some 170 00:13:45,100 --> 00:13:50,360 computer vision ideas from, basically, indexing images, and takes a binary role, but even 171 00:13:50,360 --> 00:13:54,220 basically converts it into a gray scale image and then indexes 172 00:13:54,220 --> 00:13:57,980 that. So there's a handful of systems out there. There's a lot 173 00:13:57,980 --> 00:14:01,160 of algorithms to kind of choose from again that have a lot of 174 00:14:01,160 --> 00:14:04,920 different properties. Again going back to the performance 175 00:14:04,920 --> 00:14:09,560 metric there of query by recall. So when we're approaching the 176 00:14:09,560 --> 00:14:12,120 design of the system to do malware similarity and 177 00:14:12,120 --> 00:14:15,220 specifically use that system to evaluate different nearest name 178 00:14:15,220 --> 00:14:18,340 research techniques. You know I kind of define these four key 179 00:14:18,340 --> 00:14:22,580 design ideas. So number one of course we have to extract and 180 00:14:22,580 --> 00:14:26,260 store sample metadata from our raw features. We have to then 181 00:14:26,260 --> 00:14:31,820 transform that raw data into some feature representation again 182 00:14:31,820 --> 00:14:34,320 in this end dimensional feature space. And we might have a 183 00:14:34,320 --> 00:14:36,340 variety of different vectorization pipelines that we 184 00:14:36,340 --> 00:14:39,580 want to experiment with. Talks earlier today mentioned a few 185 00:14:39,580 --> 00:14:44,100 TFIDF. I use feature hashing specifically in my more recent 186 00:14:44,100 --> 00:14:46,520 approach. So we might want to kind of change out that 187 00:14:46,520 --> 00:14:48,060 vectorization pipeline depending on 188 00:14:48,340 --> 00:14:50,180 you know what we want to evaluate and what features we 189 00:14:50,180 --> 00:14:54,640 want to include. And also how large our data set might be. So 190 00:14:54,640 --> 00:14:57,360 after we transform our features with one of these pipelines we 191 00:14:57,360 --> 00:15:00,980 then fit you know the different nearest neighbor methods and you 192 00:15:00,980 --> 00:15:04,280 know do some bookkeeping maybe have to save some basically save 193 00:15:04,280 --> 00:15:07,600 some of the database structures that are required. And that's 194 00:15:07,600 --> 00:15:10,260 kind of the fit stage. And finally once we fit all these 195 00:15:10,260 --> 00:15:13,180 indices you know we want to actually query samples and then 196 00:15:13,180 --> 00:15:16,760 basically again kind of pick the parameter K to determine how 197 00:15:16,760 --> 00:15:18,320 many nearest neighbors we're going to pull back. And then we 198 00:15:18,340 --> 00:15:21,740 possibly if we have this database of sample metadata we 199 00:15:21,740 --> 00:15:25,020 also might want to display the contextual features. Maybe again 200 00:15:25,020 --> 00:15:28,520 we have some case database of previous incidences in our 201 00:15:28,520 --> 00:15:30,940 environment and we want to annotate our samples that we 202 00:15:30,940 --> 00:15:33,380 pull back with some of that. And it might help for more of the 203 00:15:33,380 --> 00:15:39,140 analyst context kind of thing. So that really gives us or really 204 00:15:39,140 --> 00:15:42,040 what I kind of came up with is this design then for Rogers. 205 00:15:42,260 --> 00:15:47,260 Rogers is a Python 3 application that you know pretty much has a 206 00:15:47,800 --> 00:15:48,320 sample cluster. And then we want to have a sample cluster 207 00:15:48,340 --> 00:15:51,840 class. In this case it's really only a sample class consisting of 208 00:15:51,840 --> 00:15:56,520 the PE class. That really only focuses on really basic static 209 00:15:56,520 --> 00:16:00,420 feature extraction using PE file. But it's built in a way that you 210 00:16:00,420 --> 00:16:03,360 could expand the number of sample classes if you again bring 211 00:16:03,360 --> 00:16:05,820 in you know other things other than just portable executables. 212 00:16:07,160 --> 00:16:10,320 Vectorizer so there's a basically a scikit-learn pipeline 213 00:16:10,320 --> 00:16:13,520 APIs that are pretty much used extensively. And in this case 214 00:16:13,520 --> 00:16:16,420 right now I have latent semantic analysis which again earlier 215 00:16:16,420 --> 00:16:18,320 talk kind of uses some of those ideas with the TDA. And then we 216 00:16:18,320 --> 00:16:20,000 would have a lot of other things like PIDF-IDF and then projecting 217 00:16:20,000 --> 00:16:23,220 down. And then more recently just because I started getting into 218 00:16:23,220 --> 00:16:26,240 data sets that were a little bit larger to handle I started 219 00:16:26,240 --> 00:16:29,480 looking at feature hashing approaches you know and this 220 00:16:29,480 --> 00:16:32,200 basically can be extended with anything supported by scikit-learn 221 00:16:32,200 --> 00:16:36,420 or other vectorizers as well too. And then finally the kind of 222 00:16:36,420 --> 00:16:39,620 final component here is this index class you know which in 223 00:16:39,620 --> 00:16:44,900 this case I have implementations or I use libraries for like HNSW 224 00:16:44,900 --> 00:16:48,300 or I use the LSH force in scikit-learn which you know I 225 00:16:48,320 --> 00:16:51,020 was going to be deprecated anyway here soon. But then I have 226 00:16:51,020 --> 00:16:54,880 an implementation for index SS deep and PDCI and it pretty much 227 00:16:54,880 --> 00:16:58,580 at this point uses SQLite you know as the store for at least 228 00:16:58,580 --> 00:17:04,160 the index SS deep and the PDCI methods. All of the feature data 229 00:17:04,160 --> 00:17:07,900 too is I forgot to mention is stored in protobuf a message 230 00:17:07,900 --> 00:17:11,480 definition that has basically kind of a structure that allows 231 00:17:11,480 --> 00:17:14,820 you to add different modalities of features. So you can add 232 00:17:14,820 --> 00:17:18,200 static features, dynamic features, contextual features and then give 233 00:17:18,320 --> 00:17:22,100 them if you want to you can give that a variable type if you'd 234 00:17:22,100 --> 00:17:24,580 like to actually automatically build like feature vectorizers 235 00:17:24,580 --> 00:17:27,580 later on but again that's not really not really supported yet 236 00:17:27,580 --> 00:17:32,120 in the vectorizer class. Cool so now unfortunately to the sad 237 00:17:32,120 --> 00:17:36,920 panda part of my talk. So yeah doing these types of experiments 238 00:17:36,920 --> 00:17:39,840 and getting data sets you know for doing malware similarity is 239 00:17:39,840 --> 00:17:42,760 difficult. Unfortunately I didn't really get as much time 240 00:17:42,760 --> 00:17:45,940 on doing this experiment as I wanted to. What we're looking at 241 00:17:45,940 --> 00:17:48,300 here again is we have two charts. So we have two charts 242 00:17:48,320 --> 00:17:51,600 so this chart right here is this recall at K for exact nearest 243 00:17:51,600 --> 00:17:56,120 neighbor. So at the on the X axis we have the number of K's that 244 00:17:56,120 --> 00:17:59,460 we picked for each of the experiments and then on the left 245 00:17:59,460 --> 00:18:02,140 on the Y axis here is the recall. Again this is the fraction 246 00:18:02,140 --> 00:18:08,240 of the true nearest neighbors returned for the query. On this 247 00:18:08,240 --> 00:18:11,440 side right here we have precision at K for neighborhood class. So 248 00:18:11,440 --> 00:18:14,020 this is actually more of a same kind of metric where we're 249 00:18:14,020 --> 00:18:18,140 looking at the relevant documents over the K or the total relevant 250 00:18:18,320 --> 00:18:21,600 sorry relevant over the total number of relevant documents in 251 00:18:21,600 --> 00:18:26,200 our data set. In this case I'm actually just using the class for 252 00:18:26,200 --> 00:18:29,540 the samples to basically say hey if I query the sample and I get 253 00:18:29,540 --> 00:18:33,220 back all my results in my query are all the same class you know 254 00:18:33,220 --> 00:18:35,900 because I have labels for them. You know that indicates to me we 255 00:18:35,900 --> 00:18:39,860 have high precision at K. So if you look at this it does very 256 00:18:39,860 --> 00:18:42,820 well for these samples and I kind of I'll illustrate this in a 257 00:18:42,820 --> 00:18:46,520 sec you'll kind of see why. But the actual exact nearest neighbor 258 00:18:46,520 --> 00:18:48,120 results are pretty bad. 259 00:18:48,740 --> 00:18:54,640 You know we have .3 for PDCI and then HNSW kind of is you know 260 00:18:54,640 --> 00:18:57,620 pretty low. And again I did parameter selection or I did some 261 00:18:57,620 --> 00:18:59,880 grid search you know for parameters for each of these 262 00:18:59,880 --> 00:19:01,920 methods and tried to come up with things but I really 263 00:19:01,920 --> 00:19:03,860 couldn't get anywhere and you know just to kind of highlight 264 00:19:03,860 --> 00:19:06,460 this again this is this data set is coming from the VT clustering 265 00:19:06,460 --> 00:19:12,700 data set with 27,000 samples and 15 classes. So cool. So a quick 266 00:19:12,700 --> 00:19:15,400 demo time to kind of illustrate you know at least the interface. 267 00:19:15,640 --> 00:19:18,160 So Rogers is exposed as a command line application 268 00:19:18,320 --> 00:19:22,200 so if you want to use it on the CLI you can. But I also have 269 00:19:22,200 --> 00:19:27,760 APIs exposed to basically make it so that you can import Rogers 270 00:19:27,760 --> 00:19:31,080 and then build an index. And then I use Plotly in this case 271 00:19:31,080 --> 00:19:34,720 just to visualize some of the results. So I'll blow this up a 272 00:19:34,720 --> 00:19:40,560 little bit real quick. Like I said it's still probably hard to 273 00:19:40,560 --> 00:19:43,560 see in the back but the idea here is that I've previously fit 274 00:19:43,560 --> 00:19:48,300 an index. This one specifically HNSW and again I have the 275 00:19:48,320 --> 00:19:52,360 standard APIs here for passing in a sample, setting the number of 276 00:19:52,360 --> 00:19:57,300 K, getting back the neighbors. And in this case if we clear this 277 00:19:57,820 --> 00:20:00,580 and we can see we get back the sample. Here's the query sample 278 00:20:00,580 --> 00:20:02,840 just kind of again doing some print statements here just to 279 00:20:02,840 --> 00:20:05,360 make it easy to see what we're getting back. Then here's the 280 00:20:05,360 --> 00:20:07,980 nearest neighbors and you know again look how similar these are 281 00:20:07,980 --> 00:20:11,960 this is cosine similarity. The graph here just kind of displays 282 00:20:11,960 --> 00:20:15,000 them and if we look at some of the kind of features here. So 283 00:20:15,000 --> 00:20:17,880 here's the query sample. You know we can see that this is with 284 00:20:17,880 --> 00:20:18,300 the Lamer. This is the Lamer. This is the Lamer. This is the 285 00:20:18,300 --> 00:20:21,420 Lamer label. And we look at some of these other samples. It's 286 00:20:21,420 --> 00:20:27,120 reg run. There's another one too. And yeah totally different. 287 00:20:27,240 --> 00:20:30,260 So the labels themselves are different. And what I kind of 288 00:20:30,260 --> 00:20:32,880 realized after getting into this is that given the fact that my 289 00:20:32,880 --> 00:20:35,540 feature space is limited to the static feature extraction 290 00:20:35,540 --> 00:20:38,460 methods. You know and given that you know we're really only 291 00:20:38,960 --> 00:20:41,520 looking at samples that are usually I think a lot of these 292 00:20:41,520 --> 00:20:43,740 are just like packed samples. Everything really looks 293 00:20:43,740 --> 00:20:46,240 identical. So I think that kind of might explain why I had 294 00:20:46,240 --> 00:20:48,280 really bad results. And kind of I don't know if you guys have 295 00:20:48,280 --> 00:20:49,180 anything to add to that but I think it illustrates the need for 296 00:20:49,180 --> 00:20:53,420 me to get better data sets for evaluation here. So just for a 297 00:20:53,420 --> 00:20:57,380 little bit bonus. So Zory was released at Black Hat. And 298 00:20:57,380 --> 00:20:59,280 because of the frustration I had with some of the feature 299 00:20:59,280 --> 00:21:02,000 extraction around the basic static stuff. I went ahead and 300 00:21:02,000 --> 00:21:06,880 implemented a Zory feature extraction class for PE. And you 301 00:21:06,880 --> 00:21:09,620 know just in this case I only got to pulling out a bag of 302 00:21:09,620 --> 00:21:12,880 words for the mnemonics. So it's just kind of an example of 303 00:21:12,880 --> 00:21:16,080 this particular sample running Zory on it. I was able to do run 304 00:21:16,080 --> 00:21:18,260 this on like five hundred samples or so and build it up to 305 00:21:18,280 --> 00:21:24,040 a vectorizer. And again now we can rerun rerun the same query 306 00:21:24,040 --> 00:21:27,140 with I'm sorry this is a different sample. We can now 307 00:21:27,140 --> 00:21:31,820 leverage the bag of word mnemonics as well in addition 308 00:21:31,820 --> 00:21:34,020 to the other kind of static features that are pulled out. 309 00:21:34,140 --> 00:21:36,260 And it gives us slightly different results. Again I 310 00:21:36,260 --> 00:21:40,080 haven't really done any formal comparison of these methods. So 311 00:21:40,080 --> 00:21:44,100 this kind of wraps up stuff I think. But the general idea here 312 00:21:44,520 --> 00:21:48,140 you know is that Rogers is a tool for one experimenting with 313 00:21:48,280 --> 00:21:51,640 your different nearest neighbor search techniques. But also is a 314 00:21:51,640 --> 00:21:55,800 tool to build out vectorizers for the different methods. Similarity 315 00:21:55,800 --> 00:21:58,800 you know doing similarity in your environment might depend you 316 00:21:58,800 --> 00:22:00,960 know you might have different use cases. You might only want to 317 00:22:00,960 --> 00:22:03,280 do static comparison. You might only want to do dynamic. You 318 00:22:03,280 --> 00:22:06,120 might want to do both. You might want to you know apply like an 319 00:22:06,120 --> 00:22:10,080 automated disassembler like Zory on it. There's clearly at least 320 00:22:10,080 --> 00:22:12,860 in the vectorizers that I published with this tool you 321 00:22:12,860 --> 00:22:16,000 know it's very limited to kind of just PE. And there's 322 00:22:16,000 --> 00:22:18,260 definitely opportunity for different modalities. You know 323 00:22:18,280 --> 00:22:20,280 there's also opportunities for doing feature selection and 324 00:22:20,280 --> 00:22:22,920 learning representations as well too. To come up with a better 325 00:22:22,920 --> 00:22:26,780 feature space that could be used for similarity comparison. For 326 00:22:26,780 --> 00:22:30,100 experiments definitely my case you know I did run some 327 00:22:30,100 --> 00:22:32,760 parameter optimization but unfortunately just need to get 328 00:22:32,760 --> 00:22:36,100 more data sets for doing benchmarks. And also I think it 329 00:22:36,100 --> 00:22:38,460 would be interesting to evaluate different distance metrics you 330 00:22:38,460 --> 00:22:40,980 know beyond just Euclidean for some of this and basically use 331 00:22:40,980 --> 00:22:43,620 that to determine again similarity for some of these 332 00:22:43,620 --> 00:22:47,360 methods. And again some of these methods like HNSW by default 333 00:22:47,360 --> 00:22:48,260 uses cosine. And then there's a lot of other things that you can 334 00:22:48,280 --> 00:22:52,800 do. But like PDCI is Euclidean. And finally more use cases. So 335 00:22:52,800 --> 00:22:55,400 potentially in this case you know we're only indexing Mauer 336 00:22:55,400 --> 00:22:58,320 samples. But you could also potentially index benign samples 337 00:22:58,320 --> 00:23:01,580 as well too. And of course like the key is being able to 338 00:23:01,580 --> 00:23:05,140 continuously update the index with new samples as they come in 339 00:23:05,140 --> 00:23:08,720 and have been classified or been analyzed. So doing like a partial 340 00:23:08,720 --> 00:23:12,040 fit or like an insert operation would be pretty easy to extend 341 00:23:12,040 --> 00:23:18,220 as well too. Cool. So this point for questions. So again this 342 00:23:18,280 --> 00:23:22,180 tool is up on GitHub. I do have a feature branch. I apologize I 343 00:23:22,180 --> 00:23:26,460 got to get it out. It's just been crazy the past week. So this 344 00:23:26,460 --> 00:23:30,220 feature branch will add feature hashing. Will add the PDCI and 345 00:23:30,220 --> 00:23:34,120 basically publish the experiment. Again I do feel that the 346 00:23:34,120 --> 00:23:36,140 experimental results were pretty weak but maybe could be 347 00:23:36,140 --> 00:23:39,020 explained just by the data set I was using. Certainly it would 348 00:23:39,020 --> 00:23:41,820 be kind of interesting to experiment more. So yeah. And 349 00:23:41,820 --> 00:23:45,000 pull requests are welcome. Any questions at all? 350 00:23:48,520 --> 00:23:55,540 Sorry go ahead. Show the vectorizers? Yeah. So I guess 351 00:23:56,420 --> 00:24:04,440 sorry because I was kind of experimenting with this. Right 352 00:24:04,440 --> 00:24:07,760 here. So this is a signature vectorizer. So this one is 353 00:24:07,760 --> 00:24:11,040 actually using the Yara rules repo. So I just used the Yara 354 00:24:11,500 --> 00:24:14,620 detections as features themselves. And kind of try to 355 00:24:14,620 --> 00:24:18,260 figure out like what in this case apply TDF. TDF. TDF. TDF. 356 00:24:18,280 --> 00:24:21,600 IDF. To determine like what signatures are more useful 357 00:24:21,980 --> 00:24:30,380 compared to others. Go ahead. Oh so yeah in this case there 358 00:24:30,380 --> 00:24:33,160 really isn't any feature selection other than applying 359 00:24:33,160 --> 00:24:45,640 like TF IDF and then projecting down. Any final questions? I'm 360 00:24:45,640 --> 00:24:47,220 sorry I can't hear you at all. 361 00:24:53,120 --> 00:24:55,280 I apologize I still can't hear you. 362 00:24:58,960 --> 00:25:02,820 Oh so the metrics on the distance calc- so yeah. As I 363 00:25:02,820 --> 00:25:08,860 mentioned HN, HNSW uses cosine. The PDCI is using Euclidean. But 364 00:25:08,860 --> 00:25:12,400 the metrics are just this, this recall at K. So basically I do 365 00:25:12,400 --> 00:25:15,860 exact nearest neighbor search on my data set just using brute 366 00:25:15,860 --> 00:25:18,260 force. And I compute that for Euclidean and then I compute that 367 00:25:18,280 --> 00:25:21,640 for cosine. And then those are like kind of the, basically the 368 00:25:21,640 --> 00:25:24,120 ground truth that I use in this case for this recall at K for 369 00:25:24,120 --> 00:25:25,620 the nearest, sorry for the exact neighbors. 370 00:25:28,860 --> 00:25:32,060 You have a chance to improve your precision recall curves by 371 00:25:32,060 --> 00:25:33,600 some metric on any features? 372 00:25:35,680 --> 00:25:39,020 Yeah so I mentioned like you know I don't, don't do any 373 00:25:39,020 --> 00:25:42,100 feature learning. Don't do any of that kind of stuff. And I also 374 00:25:42,100 --> 00:25:44,280 think that you know going beyond some of the basic static 375 00:25:44,280 --> 00:25:46,900 features would, would definitely obviously change the results 376 00:25:46,900 --> 00:25:55,220 significantly. So I hope to do that in the future. Oh sorry 377 00:25:55,220 --> 00:25:55,700 didn't see you. 378 00:26:15,120 --> 00:26:16,120 Yeah so. 379 00:26:16,900 --> 00:26:19,220 Just a little background. So the question is you know do more 380 00:26:19,220 --> 00:26:21,340 experiments pretty much. Experiments are fun. Sometimes 381 00:26:21,340 --> 00:26:23,540 they're, they're sad. But you know it's always got to push 382 00:26:23,540 --> 00:26:25,940 forward to the next one. The other question was like what, 383 00:26:25,960 --> 00:26:28,460 what did I learn kind of doing this implementation? It was 384 00:26:28,460 --> 00:26:31,140 definitely really a lot of fun to do the PDCI implementation. 385 00:26:31,660 --> 00:26:36,320 Again it's really naive in Python 3 using, using SQLite 386 00:26:36,320 --> 00:26:40,040 basically to, to store those indices. So it was great to have 387 00:26:40,040 --> 00:26:42,400 a chance to kind of go through a paper that again has no 388 00:26:42,400 --> 00:26:45,800 published source code. You know and then based, or no published 389 00:26:45,800 --> 00:26:46,880 implementation for RAP2.0. 390 00:26:46,900 --> 00:26:47,660 Yeah. 391 00:26:47,660 --> 00:26:49,820 And then try to do that. And then yeah a lot of, a lot of 392 00:26:49,820 --> 00:26:52,680 Python 3 kind of things I picked up doing this project as well. 393 00:27:01,360 --> 00:27:04,280 Yeah there's not the, so those algorithms don't do any feature 394 00:27:04,280 --> 00:27:06,260 engineering. They don't do any feature selection. You basically 395 00:27:06,260 --> 00:27:09,960 pass in your, your, your feature vector into index. So 396 00:27:09,960 --> 00:27:12,900 that's kind of a pre-processing step. In this case here which I 397 00:27:12,900 --> 00:27:14,060 did at the vectorization phase. 398 00:27:15,980 --> 00:27:16,380 Yeah. 399 00:27:16,380 --> 00:27:16,460 Yeah. 400 00:27:16,460 --> 00:27:16,500 Yeah. 401 00:27:19,060 --> 00:27:20,520 Cool. Thanks everyone.