1 00:00:00,000 --> 00:00:01,380 Hello, everybody. 2 00:00:02,200 --> 00:00:04,100 My name is Angelo. 3 00:00:04,100 --> 00:00:09,380 And I'm here to talk a little bit about fighting malware with deep learning. 4 00:00:09,380 --> 00:00:17,060 So, I will show you how you can use deep learning to build a classifier, binary classifier. 5 00:00:17,700 --> 00:00:21,300 And I'd like to thank you for coming. 6 00:00:21,300 --> 00:00:30,600 And thank you, here. 7 00:00:31,360 --> 00:00:37,460 But it's been very amazing here. 8 00:00:37,460 --> 00:00:42,980 So, and I'd like to thank my company, TOTUS, to support me to come here also. 9 00:00:43,660 --> 00:00:44,580 All right. 10 00:00:45,880 --> 00:00:47,380 So, who am I? 11 00:00:48,640 --> 00:00:51,420 I work as an ethical hacker at TOTUS. 12 00:00:51,420 --> 00:00:54,400 It's the largest software company in Latin America. 13 00:00:54,440 --> 00:00:56,320 We build ERP. 14 00:00:57,120 --> 00:00:59,980 And I'm a part-time data scientist. 15 00:01:00,480 --> 00:01:03,320 Basically, you know, self-made. 16 00:01:03,820 --> 00:01:08,140 And then I'm a part-time PhD student. 17 00:01:08,140 --> 00:01:11,460 I hope my supervisor won't listen to that. 18 00:01:12,260 --> 00:01:18,900 And I'm interested in deep learning data science for malware detection classification. 19 00:01:20,400 --> 00:01:21,180 Okay. 20 00:01:21,180 --> 00:01:23,960 So, first, I want to share 21 00:01:27,360 --> 00:01:30,520 some experience I had. 22 00:01:30,700 --> 00:01:31,300 Okay. 23 00:01:31,300 --> 00:01:34,120 So, I was not a researcher, you know. 24 00:01:34,760 --> 00:01:38,820 I got a degree in mathematics, but I was not a researcher. 25 00:01:38,820 --> 00:01:43,020 So, I went to... I started working with computers, programming, and so on. 26 00:01:43,020 --> 00:01:44,660 So, actually, you're not researching. 27 00:01:44,760 --> 00:01:49,120 But then I wanted to make some research. 28 00:01:49,120 --> 00:01:57,300 And I wanted to get into this machine learning, deep learning, AI thing. 29 00:01:57,300 --> 00:02:00,540 And I didn't know how. 30 00:02:00,540 --> 00:02:02,920 So, I started studying machine learning. 31 00:02:02,920 --> 00:02:05,780 There's online resources and books. 32 00:02:05,860 --> 00:02:09,660 Deep learning and malware analysis. 33 00:02:09,920 --> 00:02:16,920 I've already knew something about malware analysis, but I kind of learned more. 34 00:02:17,440 --> 00:02:17,800 Okay. 35 00:02:17,800 --> 00:02:25,400 And then, since you want to make research, you need to start studying the state-of-the-art papers. 36 00:02:25,840 --> 00:02:27,580 You know, to see what's going on. 37 00:02:27,660 --> 00:02:29,040 What's in the edge. 38 00:02:29,660 --> 00:02:30,340 So, okay. 39 00:02:30,340 --> 00:02:32,300 And then I started to read these papers. 40 00:02:32,780 --> 00:02:36,780 And I got stuck when I tried to reproduce them. 41 00:02:37,340 --> 00:02:41,600 Because they are very theoretical, you know. 42 00:02:41,600 --> 00:02:47,940 And sometimes you don't have enough information to reproduce them. 43 00:02:47,940 --> 00:02:52,880 So, this is a very big problem in machine learning papers. 44 00:02:52,940 --> 00:02:56,040 And for malware analysis, in particular. 45 00:02:56,300 --> 00:03:00,580 Because the guys, they don't want to tell you their hyperparameters. 46 00:03:00,580 --> 00:03:02,240 They don't share data. 47 00:03:02,620 --> 00:03:05,580 So, it's quite hard to reproduce the papers. 48 00:03:05,580 --> 00:03:10,320 But also, sometimes because you just don't know the basics. 49 00:03:10,320 --> 00:03:13,980 You haven't been through the basics. 50 00:03:13,980 --> 00:03:18,620 You didn't code something simpler to see it working. 51 00:03:18,620 --> 00:03:20,660 So, you need to do that. 52 00:03:21,960 --> 00:03:22,360 Okay. 53 00:03:22,360 --> 00:03:34,980 So, here what happens is because we actually... what he's saying here is that there is a difference between knowing the path and walking the path. 54 00:03:34,980 --> 00:03:36,880 What does that mean in this context? 55 00:03:37,480 --> 00:03:42,440 Means that I wanted to do research, but I haven't done anything yet. 56 00:03:42,440 --> 00:03:47,560 I want to jump, you know, make a big... take a big step. 57 00:03:47,560 --> 00:03:50,520 So, that's quite hard to do. 58 00:03:50,840 --> 00:03:54,240 So, you need to step back, right? 59 00:03:54,240 --> 00:03:56,180 And fill that gap. 60 00:03:56,180 --> 00:03:57,740 And how you do that? 61 00:03:58,120 --> 00:04:10,960 Basically, you want to build that's very important for machine learning in not only in our research, but any kind of research. 62 00:04:11,140 --> 00:04:15,340 You need to build your baseline... your own baseline models from the scratch. 63 00:04:15,380 --> 00:04:21,460 And from the scratch, I mean that you don't need to implement backpropagation yourself. 64 00:04:21,980 --> 00:04:23,160 You don't need. 65 00:04:23,160 --> 00:04:24,500 You can, but you don't need. 66 00:04:24,500 --> 00:04:30,160 You can use a high-level framework, deep learning framework to do that for you. 67 00:04:30,620 --> 00:04:33,820 So, that will be your starting point for doing research. 68 00:04:34,620 --> 00:04:43,760 And the second thing is that you want to build simple and working models using the techniques you want to master in research. 69 00:04:43,760 --> 00:04:50,560 Because you need to learn them very well if you want to contribute with something new. 70 00:04:51,140 --> 00:04:52,400 And the third point is... 71 00:04:54,040 --> 00:05:01,100 this is kind of strange, but you need to not contribute first to be able to contribute later. 72 00:05:02,160 --> 00:05:03,780 First, you need to learn the basics. 73 00:05:03,780 --> 00:05:06,680 Then, you know, you are not contributing. 74 00:05:06,680 --> 00:05:08,580 You are contributing with yourself. 75 00:05:08,580 --> 00:05:15,660 And then, you can then try to contribute with the scientific community or whatever. 76 00:05:16,360 --> 00:05:18,240 So, always be humble. 77 00:05:18,440 --> 00:05:20,460 You don't know everything. 78 00:05:21,780 --> 00:05:22,400 Okay. 79 00:05:22,400 --> 00:05:24,720 So, we are data scientists. 80 00:05:24,900 --> 00:05:25,480 Right? 81 00:05:25,480 --> 00:05:26,280 Right. 82 00:05:26,280 --> 00:05:29,280 So, we need... in our case, we need malware. 83 00:05:29,280 --> 00:05:30,520 A lot of malware. 84 00:05:30,520 --> 00:05:32,420 Meaning, we need instances. 85 00:05:32,420 --> 00:05:35,020 We need data to feed our models. 86 00:05:36,220 --> 00:05:40,920 This is... that's... this one is my favorite repository. 87 00:05:40,920 --> 00:05:43,100 It's called VirusShare. 88 00:05:43,100 --> 00:05:46,860 So, there you can find... I checked yesterday. 89 00:05:46,860 --> 00:05:53,360 Almost 34 million instances of malware to download. 90 00:05:53,360 --> 00:05:55,440 So, you can download huge files. 91 00:05:55,440 --> 00:06:00,600 Six gigabytes each with 60,000 instances there. 92 00:06:00,600 --> 00:06:02,900 And you can play with them. 93 00:06:03,560 --> 00:06:04,240 Okay. 94 00:06:04,240 --> 00:06:10,420 And then, one good thing is that they are already labeled using VirusTotal. 95 00:06:26,690 --> 00:06:30,990 So, as you can see, I told you several layers. 96 00:06:31,070 --> 00:06:37,830 And the first layers are low-level features and the deeper layers, high-level features. 97 00:06:37,830 --> 00:06:43,530 What we are interested in is getting this data from this datasets. 98 00:06:43,770 --> 00:06:45,070 I will show you. 99 00:06:45,070 --> 00:06:52,050 And then, try to figure out if they are... if that... if they are malicious or not. 100 00:06:52,050 --> 00:06:54,210 Because we're trying to detect malware. 101 00:07:07,270 --> 00:07:10,570 And then, we have also the recurrent neural networks. 102 00:07:10,570 --> 00:07:13,390 They are good for sequential modeling. 103 00:07:13,390 --> 00:07:22,070 So, if you get sequential data, varying time or space, something like that, you can use recurrent neural networks for that. 104 00:07:22,070 --> 00:07:24,510 They're good for dynamic analysis. 105 00:07:24,710 --> 00:07:25,270 So, okay. 106 00:07:25,270 --> 00:07:29,150 So, we need to build our machine learning, deep learning data science pipeline. 107 00:07:29,170 --> 00:07:38,310 This is actual real information that I took about one month to download malware and goodware. 108 00:07:38,330 --> 00:07:53,910 And then, I set up an environment hypervisor with nine virtual machines running for four months around the clock to run this malware and get the dynamic information. 109 00:07:54,190 --> 00:07:59,310 And then, we need to do the basics from data science. 110 00:07:59,310 --> 00:08:02,290 Meaning, we need to pre-process our data. 111 00:08:02,290 --> 00:08:04,150 We need to clean the data. 112 00:08:04,570 --> 00:08:07,330 We need to make some feature engineering. 113 00:08:08,070 --> 00:08:11,610 We need to get the best features for our problem. 114 00:08:11,670 --> 00:08:16,850 In this case, the feature engineering was minimal. 115 00:08:16,990 --> 00:08:17,210 Okay. 116 00:08:17,210 --> 00:08:20,170 I haven't done almost any. 117 00:08:20,910 --> 00:08:21,870 Okay. 118 00:08:21,910 --> 00:08:26,750 And then, we are ready to play with the models. 119 00:08:26,750 --> 00:08:31,370 So, you use a high-level framework and you can start building the models. 120 00:08:31,370 --> 00:08:32,110 Okay. 121 00:08:32,110 --> 00:08:33,350 So, all right. 122 00:08:34,470 --> 00:08:37,750 So, I have here three models to show you. 123 00:08:37,810 --> 00:08:45,590 I will share this code, the Jupyter notebooks, and I will share the data set, the data sets, because there are several data sets. 124 00:08:47,110 --> 00:08:52,270 So, don't worry if you can't get something, because I will need to be very quick. 125 00:08:53,750 --> 00:09:03,230 Now, I just need some help here, because I will need to throw the code there, and I can't see the code here, you know, because my screen is extended. 126 00:09:04,750 --> 00:09:08,770 Can someone help me there from AI Village, please? 127 00:09:16,080 --> 00:09:20,920 Yes, but then I can't see the code from here, you know, when I drag. 128 00:09:25,140 --> 00:09:26,200 Please. 129 00:09:27,120 --> 00:09:35,520 So, what I need is I open here the code, and I want to project there, but the screen is extended. 130 00:09:36,000 --> 00:09:37,700 That's why I... 131 00:09:50,580 --> 00:10:00,760 So, I won't have time to explain step-by-step the code, but basically what I'm showing here is an example of each of those models I showed before. 132 00:10:00,760 --> 00:10:06,160 You know, this one is a multi-layer perceptron for static analysis data. 133 00:10:06,160 --> 00:10:13,380 So, basically, what we do first is to import all the libraries. 134 00:10:14,420 --> 00:10:17,160 Necessary libraries for Python libraries. 135 00:10:17,440 --> 00:10:19,740 They're amazing. 136 00:10:19,740 --> 00:10:22,340 So, here's our data set. 137 00:10:22,700 --> 00:10:25,160 I'm getting data from the PE sections. 138 00:10:25,160 --> 00:10:32,260 So, PE sections basically describes the sections in the executable file, okay? 139 00:10:32,260 --> 00:10:37,120 So, one information here that's very important is this entropy. 140 00:10:37,300 --> 00:10:45,280 Usually, when the entropy is high, it means that either the code is encrypted or packed. 141 00:10:46,460 --> 00:10:55,260 So, malware authors, they usually like packing the content of the file to avoid antivirus detection. 142 00:10:55,920 --> 00:10:57,520 But that's not enough, okay? 143 00:10:57,520 --> 00:11:00,640 This can be very high, but it's not malware. 144 00:11:00,660 --> 00:11:04,620 So, can't rely only on one feature. 145 00:11:05,040 --> 00:11:09,480 So, okay, and there is a column here saying some malware or not, okay? 146 00:11:09,480 --> 00:11:12,540 So, this is how our data looks like, and this is tabular data. 147 00:11:12,560 --> 00:11:14,000 It's in a table. 148 00:11:15,240 --> 00:11:23,280 Here, I do some correlation analysis, you know, to figure out correlation among the features. 149 00:11:23,280 --> 00:11:27,100 You see that some features are very highly correlated. 150 00:11:27,100 --> 00:11:28,780 So, we can drop them out. 151 00:11:28,780 --> 00:11:31,440 You don't need to duplicate data. 152 00:11:31,960 --> 00:11:40,440 And then, what I'm doing here is opening another data set that is called imports, PE imports. 153 00:11:40,660 --> 00:11:47,500 PE imports basically, you know, when you create a program, you need to import functions from DLLs and so on. 154 00:11:48,820 --> 00:11:57,920 And maybe we can find, we can, the machine learning, deep learning algorithm can spot some patterns that are used for malware, in malwares. 155 00:11:58,080 --> 00:12:08,100 So, what we're doing here is, in this data set, is the most 1,000 important imported functions in reverse order. 156 00:12:08,100 --> 00:12:19,540 So, for example, this malware imported this GetProcAddress function, and this GetProcAddress function is the most important, most imported function. 157 00:12:20,220 --> 00:12:20,480 Okay? 158 00:12:20,480 --> 00:12:22,720 So, this is what it means. 159 00:12:22,720 --> 00:12:26,120 So, you see that there are a lot of features here, and they are categorical. 160 00:12:26,140 --> 00:12:33,440 Categorical features are a little bit harder to deal with, because you can't just play with them. 161 00:12:33,440 --> 00:12:35,360 You're not playing with numbers, okay? 162 00:12:35,360 --> 00:12:37,300 We're playing with categories. 163 00:12:38,420 --> 00:12:39,180 All right. 164 00:12:40,400 --> 00:12:51,040 So, and in the end, we have said, and this data set has 47,000 entries. 165 00:12:51,320 --> 00:12:51,620 Okay. 166 00:12:51,620 --> 00:13:01,200 So, we remove duplicates, and then we merge the files, and then now we have the data set ready. 167 00:13:01,200 --> 00:13:01,760 Okay. 168 00:13:01,760 --> 00:13:03,020 I'll jump a little bit here. 169 00:13:03,020 --> 00:13:11,380 We convert this data sets, pandas data frames to NumPy arrays to feed the models. 170 00:13:11,720 --> 00:13:13,740 And then there is another problem here. 171 00:13:13,740 --> 00:13:15,580 We need to check the imbalance. 172 00:13:16,060 --> 00:13:18,500 And this is high imbalanced. 173 00:13:19,160 --> 00:13:19,820 See? 174 00:13:19,820 --> 00:13:22,400 24 to 1. 175 00:13:22,400 --> 00:13:28,380 So, we have 24 malware instances for each goodware instances. 176 00:13:28,580 --> 00:13:29,840 So, that's a problem. 177 00:13:29,840 --> 00:13:30,300 Okay? 178 00:13:31,700 --> 00:13:37,240 Then we need to make the strength test split stratified. 179 00:13:37,240 --> 00:13:44,200 So, meaning that after performing this split, we need to keep the proportions. 180 00:13:44,980 --> 00:13:45,840 Okay? 181 00:13:46,000 --> 00:13:50,400 And basically here, I'm standardizing the code. 182 00:13:50,460 --> 00:13:54,460 I will only standardize the code that is numeric. 183 00:13:54,460 --> 00:13:54,940 See? 184 00:13:54,940 --> 00:14:01,040 I'm not touching the categorical data. 185 00:14:02,620 --> 00:14:03,440 Okay. 186 00:14:03,440 --> 00:14:05,320 So, let's jump to the model. 187 00:14:05,640 --> 00:14:06,400 Ah, here. 188 00:14:06,400 --> 00:14:07,980 There is something interesting. 189 00:14:08,080 --> 00:14:11,260 We need to deal with imbalance. 190 00:14:11,720 --> 00:14:13,540 So, the data set is imbalanced. 191 00:14:13,540 --> 00:14:22,660 So, we can try to use some algorithm to oversample, oversampling technique. 192 00:14:22,960 --> 00:14:29,580 So, for example, this moat won't work here, because it can't deal with categorical features. 193 00:14:29,580 --> 00:14:37,760 And there is a variation called smote nominal and continuous that was taking just too much time to run. 194 00:14:37,800 --> 00:14:40,120 So, I gave up for now. 195 00:14:40,120 --> 00:14:42,820 And then we can use a random oversampler. 196 00:14:42,820 --> 00:14:47,180 But random oversampler is bad, because it just duplicates data. 197 00:14:48,040 --> 00:14:50,220 But in our case, helped. 198 00:14:50,920 --> 00:14:57,520 So, after running that, you see, we can see here that now the data set is balanced. 199 00:14:57,640 --> 00:15:02,060 And then I will perform some visualization using T-SNE. 200 00:15:02,820 --> 00:15:11,780 T-SNE is a pretty awesome algorithm for visualizing high dimensional data. 201 00:15:13,060 --> 00:15:19,000 Basically, it projects high dimensional data onto the plane or to a space. 202 00:15:19,400 --> 00:15:25,900 So, you can have an idea how the data is in that high dimensional space. 203 00:15:25,900 --> 00:15:31,960 And then you can also have an idea about the decision boundaries your model will need to learn. 204 00:15:31,960 --> 00:15:34,980 And if you see, this is complicated, this one. 205 00:15:35,660 --> 00:15:38,480 Red is malware and green is good work. 206 00:15:38,480 --> 00:15:40,220 We need to separate them out. 207 00:15:40,560 --> 00:15:41,960 So, deep learning. 208 00:15:42,200 --> 00:15:47,860 So, here's a model, deep learning model for multilayer perceptron. 209 00:15:47,860 --> 00:15:50,340 As you can see, the model is quite simple. 210 00:15:50,540 --> 00:15:51,960 This is not research. 211 00:15:51,960 --> 00:15:57,220 This is just that homework, you know. 212 00:15:57,220 --> 00:16:06,560 I said in the beginning that I need to understand how to build a simple model in order to try to build something more complex or new. 213 00:16:06,740 --> 00:16:11,080 So, this is just a model with two dense layers. 214 00:16:11,520 --> 00:16:16,680 And then after that, we create the model, get here the summary, 215 00:16:22,160 --> 00:16:24,100 146,000 parameters. 216 00:16:24,380 --> 00:16:26,840 It's not really too much, right? 217 00:16:27,260 --> 00:16:28,740 Here's a model. 218 00:16:29,200 --> 00:16:35,760 We can get this model, the architecture of the model, just with one command. 219 00:16:35,880 --> 00:16:45,900 And now here, there is an algorithm that I would like to explain more deep, but I can't because I don't have time. 220 00:16:45,900 --> 00:16:47,620 But this is a model selection. 221 00:16:47,760 --> 00:16:52,980 Basically, I'm making an automation of the model selection here. 222 00:16:52,980 --> 00:17:07,540 I'm getting those hyperparameters and testing each one of them, combinations, you know, and performing a threefold cross-validation to see which combination is better. 223 00:17:08,520 --> 00:17:12,400 And after that, we train the model for some time. 224 00:17:12,400 --> 00:17:15,680 This case didn't take too much, okay? 225 00:17:15,680 --> 00:17:17,140 I trained at home, okay? 226 00:17:17,140 --> 00:17:24,520 I have a NVIDIA RTX 2080 Ti. 227 00:17:24,560 --> 00:17:29,020 So 4,300 to the cores. 228 00:17:30,140 --> 00:17:33,320 It's a decent card. 229 00:17:33,320 --> 00:17:37,200 So 10,000 seconds, roughly three hours. 230 00:17:37,200 --> 00:17:41,500 And here, it's important to evaluate the model using the test set. 231 00:17:42,440 --> 00:17:47,540 And okay, we have here the results from the model selection. 232 00:17:47,540 --> 00:17:53,140 So this is the best combination, dropout rate, 0.6. 233 00:17:53,140 --> 00:17:58,820 The first model architecture here is a dropout first, and then batch normalization. 234 00:17:58,820 --> 00:18:01,040 There is a holy war about that. 235 00:18:01,040 --> 00:18:11,080 You know, people know you should use batch norm first and then dropout, or vice versa, and neither of them are both in any order. 236 00:18:11,620 --> 00:18:16,160 But actually, it depends on the nature of your data. 237 00:18:16,180 --> 00:18:18,020 So that's why you need to test it. 238 00:18:19,500 --> 00:18:21,940 And the lowest number of neurons won. 239 00:18:22,840 --> 00:18:25,660 So after that, we perform an evaluation. 240 00:18:25,660 --> 00:18:35,420 And with the evaluation, we have a thing called confusion matrix to show the true negatives, false positives, false negatives, and true positives. 241 00:18:35,420 --> 00:18:41,080 First, what we do is to create a benchmark. 242 00:18:42,200 --> 00:18:48,140 So suppose that you have a model that predicts that every example is a malware. 243 00:18:48,140 --> 00:18:49,140 So what happens? 244 00:18:49,140 --> 00:18:50,980 These are the numbers you get. 245 00:18:51,060 --> 00:18:58,520 And you see, since the data set is imbalanced, you get pretty good numbers here for accuracy, precision, recall, F1 score. 246 00:18:58,960 --> 00:19:00,580 This is misleading. 247 00:19:00,580 --> 00:19:04,820 So you need to use a better metric for unbalanced data set. 248 00:19:04,820 --> 00:19:09,080 The best metric, as far as I know, is a balanced accuracy. 249 00:19:09,280 --> 00:19:18,320 And balanced accuracy is showing here that, basically, you have chosen... you have predicted every example as a malware. 250 00:19:19,060 --> 00:19:19,920 So it's very bad. 251 00:19:19,920 --> 00:19:21,840 This is the worst case scenario. 252 00:19:21,900 --> 00:19:29,680 And then when we apply on the test set, our model, we get this result. 253 00:19:29,680 --> 00:19:31,340 So it's much better. 254 00:19:31,460 --> 00:19:42,880 So as you can see, if we were using a multi-layer perceptron, that is a very simple deep neural network, we can already get very good results. 255 00:19:43,100 --> 00:19:50,200 Now you can imagine those very, very deep models with those inception layers and so on. 256 00:19:50,580 --> 00:19:52,700 You can get much better. 257 00:19:52,700 --> 00:19:57,660 Okay, now the next example, I'll just show you the model. 258 00:19:57,820 --> 00:20:10,580 This is interesting, because what I have done here is just to treat the binary data like an image, as if it was an image. 259 00:20:10,580 --> 00:20:12,640 So take a look at that. 260 00:20:13,040 --> 00:20:14,740 This is what we get. 261 00:20:15,080 --> 00:20:16,700 So these are malware images. 262 00:20:16,700 --> 00:20:24,520 I get the binary, and then I treat each byte like a grayscale, and then scale it. 263 00:20:24,520 --> 00:20:26,160 So we get this information. 264 00:20:26,160 --> 00:20:37,260 And then, basically, we feed it to a convolutional neural network, because convolutional neural networks are specialists in dealing with images. 265 00:20:37,260 --> 00:20:41,040 So the same problem, imbalanced, and so on. 266 00:20:41,040 --> 00:20:44,740 And then visualization looks similar to what we have seen there. 267 00:20:45,020 --> 00:20:47,560 Pretty complicated decision boundary. 268 00:20:47,620 --> 00:20:48,700 And then deep learning. 269 00:20:48,700 --> 00:20:52,280 So this is our model, convolutional model. 270 00:20:52,280 --> 00:20:54,620 So as you can see, it's very, very simple. 271 00:20:54,620 --> 00:21:03,500 We have a convolutional layer, and then we have... there is a model selection here. 272 00:21:03,540 --> 00:21:11,920 It's about, should we apply max pooling first, and then batch normalization, or batch normalization first and max pooling. 273 00:21:11,920 --> 00:21:14,620 This is also a holy war, you know? 274 00:21:14,620 --> 00:21:17,560 Nobody knows what's better. 275 00:21:17,700 --> 00:21:27,820 But what you can do is to perform model selection with cross-validation, which is better for your kind of data. 276 00:21:28,040 --> 00:21:28,580 All right. 277 00:21:29,020 --> 00:21:37,260 So basically, we have a convolutional layer, and then max pooling, and then another convolutional layer, and then max pooling. 278 00:21:37,260 --> 00:21:48,520 And then we flatten them out to feed to a fully connected layer for classification, or in our case, binary classification. 279 00:21:48,880 --> 00:21:49,760 Okay. 280 00:21:49,960 --> 00:21:52,580 So we train this for some time. 281 00:21:55,050 --> 00:21:57,630 I think I still got some five minutes. 282 00:21:59,950 --> 00:22:04,830 I want to show you how much time I needed to train. 283 00:22:06,070 --> 00:22:07,430 Here. 284 00:22:13,060 --> 00:22:19,040 So 15,000 seconds, five hours, four hours. 285 00:22:19,220 --> 00:22:21,340 Not too much, really. 286 00:22:22,080 --> 00:22:23,620 And the results. 287 00:22:23,920 --> 00:22:27,660 So cross-validations and results. 288 00:22:27,720 --> 00:22:28,640 Evaluation. 289 00:22:28,640 --> 00:22:29,420 Okay. 290 00:22:29,420 --> 00:22:31,880 So the bank mark, also pretty good. 291 00:22:31,960 --> 00:22:37,480 Accuracy, precision, recall F1 score, because they don't deal very well with unbalanced datasets. 292 00:22:37,480 --> 00:22:41,340 Balanced accuracy is the worst possible. 293 00:22:41,840 --> 00:22:48,580 And then when we use our model to predict using the test set, we get this. 294 00:22:49,240 --> 00:22:50,980 So also not good. 295 00:22:50,980 --> 00:22:54,780 But there are some explanations here. 296 00:22:54,780 --> 00:23:03,960 First, because I think the main explanation here is because malware, usually nowadays, they are all packet. 297 00:23:05,180 --> 00:23:09,700 So the content is encrypted or obfuscated. 298 00:23:09,700 --> 00:23:16,400 So what you are seeing here is mostly random noise. 299 00:23:16,780 --> 00:23:20,580 So you can't expect the algorithm to do much better. 300 00:23:20,760 --> 00:23:23,040 But still, it's a pretty good result. 301 00:23:23,220 --> 00:23:33,780 You could just, for example, add and step in your pre-processing pipeline to unpack this. 302 00:23:33,780 --> 00:23:38,720 But this is quite complicated, because each malware uses a different technique, different key. 303 00:23:38,720 --> 00:23:42,540 Sometimes the key, and so on. 304 00:23:43,160 --> 00:23:44,900 So it's complicated. 305 00:23:46,460 --> 00:23:50,640 And then, finally, dynamic analysis. 306 00:23:50,640 --> 00:23:56,740 Dynamic analysis, I will show you the network called long short-term memory. 307 00:23:57,060 --> 00:24:02,860 It's pretty good for dealing with sequential data. 308 00:24:02,860 --> 00:24:10,620 And all this software you see for speech recognition, automatic translation, use this kind of network. 309 00:24:10,720 --> 00:24:14,320 So here I'm getting the sequence of calls, of API calls. 310 00:24:14,320 --> 00:24:14,860 See? 311 00:24:14,860 --> 00:24:16,300 T0, T1, T2. 312 00:24:16,300 --> 00:24:22,160 These are the calls the malware does to the Windows API. 313 00:24:22,160 --> 00:24:25,500 So I got just 1,024. 314 00:24:26,940 --> 00:24:32,320 And then, basically, I do the job here of cleaning and then balancing the dataset. 315 00:24:32,320 --> 00:24:33,560 And take a look at this. 316 00:24:33,560 --> 00:24:36,480 Even more simpler network. 317 00:24:37,380 --> 00:24:38,800 There is a version. 318 00:24:39,000 --> 00:24:53,780 If you are running TensorFlow and Keras, you can use the Qt version that runs much faster than the LSTM version. 319 00:24:53,960 --> 00:25:00,100 And then, basically, this takes much more time to train, okay? 320 00:25:00,100 --> 00:25:03,340 Your GPU will be burning there for some hours. 321 00:25:03,340 --> 00:25:10,340 Really burning 90%, 100% usage for several hours. 322 00:25:10,380 --> 00:25:22,540 And in this case, it took about 29,000 seconds, nine hours, okay? 323 00:25:22,540 --> 00:25:26,240 And the results here of the model selection. 324 00:25:26,660 --> 00:25:30,960 And, basically, you get our confusion matrix and then get the results here. 325 00:25:30,960 --> 00:25:31,740 You see? 326 00:25:31,740 --> 00:25:36,180 We got 91% balanced accuracy. 327 00:25:36,500 --> 00:25:39,700 This is a little bit impressive. 328 00:25:39,700 --> 00:25:44,320 Because our dataset is small, you know? 329 00:25:44,320 --> 00:25:51,320 And the number of features, I don't know if you have noticed there, but the dataset has 1,024 features. 330 00:25:51,320 --> 00:25:54,780 And we used only, I think, 300. 331 00:25:54,780 --> 00:25:57,640 Because my computer didn't have enough memory. 332 00:25:57,940 --> 00:26:04,160 Because we need to make a conversion of these features from categorical to one hot encoders. 333 00:26:04,240 --> 00:26:05,600 Encoding, sorry. 334 00:26:05,780 --> 00:26:07,420 Before feeding the model. 335 00:26:08,040 --> 00:26:11,280 But my computer didn't have enough memory for that. 336 00:26:11,280 --> 00:26:12,240 So, all right. 337 00:26:14,420 --> 00:26:19,720 Now we can have an idea how you can apply deep learning for model detection and classification. 338 00:26:20,120 --> 00:26:22,400 That was the idea of this talk. 339 00:26:22,400 --> 00:26:25,260 So, let me just close here. 340 00:26:33,700 --> 00:26:34,600 Can you see there? 341 00:26:34,600 --> 00:26:35,540 The slides? 342 00:26:35,640 --> 00:26:36,420 Okay. 343 00:26:36,760 --> 00:26:37,760 So, okay. 344 00:26:37,760 --> 00:26:41,360 And my research, basically, is about malware behavior. 345 00:26:41,360 --> 00:26:44,740 And I'm researching specialized data augmentation methods. 346 00:26:44,740 --> 00:26:50,180 Because the current ones, they just don't work very well with this kind of data. 347 00:26:50,180 --> 00:26:56,060 And also specialized representation learning techniques from our detection classification. 348 00:26:56,060 --> 00:27:05,600 And this will lead to improvements in detection and classification of zero days and polymorphic and metamorphic malware. 349 00:27:06,480 --> 00:27:08,180 And that's it. 350 00:27:08,180 --> 00:27:10,760 Thank you very much for attending.