start	end	text
0	8420	Hello, everybody. My name is Angelo. And I'm here to talk a little bit about fighting malware
8420	14640	with deep learning. So, I will show you how you can use deep learning to build a classifier,
15360	29980	binary classifier. And I'd like to thank you for coming. And thank you,
29980	40240	here. But it's been very amazing here. So, and I'd like to thank my company,
40240	50380	TOTUS, to support me to come here also. All right. So, who am I? I work as an ethical hacker
50380	58680	at TOTUS. It's the largest software company in Latin America. We build ERP. And I'm a part-time
58680	68640	data scientist. Basically, you know, self-made. And then I'm a part-time PhD student. I hope my
68640	75100	supervisor won't listen to that. And I'm interested in deep learning data science
76200	83960	for malware detection classification. Okay. So, first, I want to share
87360	97120	some experience I had. Okay. So, I was not a researcher, you know. I got a degree in mathematics,
97120	102480	but I was not a researcher. So, I went to... I started working with computers, programming,
102480	109400	and so on. So, actually, you're not researching. But then I wanted to make some research. And I
110360	117300	wanted to get into this machine learning, deep learning, AI thing.
117300	124020	And I didn't know how. So, I started studying machine learning. There's online resources
124020	133020	and books. Deep learning and malware analysis. I've already knew something about malware analysis,
133020	143260	but I kind of learned more. Okay. And then, since you want to make research, you need to start
143260	149040	studying the state-of-the-art papers. You know, to see what's going on. What's in the edge.
149660	156780	So, okay. And then I started to read these papers. And I got stuck when I tried to reproduce them.
157340	166720	Because they are very theoretical, you know. And sometimes you don't have enough information
166720	172980	to reproduce them. So, this is a very big problem in machine learning papers. And
173780	179220	for malware analysis, in particular. Because the guys, they don't want to tell you their
179220	186280	hyperparameters. They don't share data. So, it's quite hard to reproduce the papers. But also,
186280	194300	sometimes because you just don't know the basics. You haven't been through the basics. You didn't
194300	205680	code something simpler to see it working. So, you need to do that. Okay. So, here what happens
205680	212520	is because we actually... what he's saying here is that there is a difference between
213240	216880	knowing the path and walking the path. What does that mean in this context?
217480	224800	Means that I wanted to do research, but I haven't done anything yet. I want to jump, you know,
224800	233420	make a big... take a big step. So, that's quite hard to do. So, you need to step back,
233420	240780	right? And fill that gap. And how you do that? Basically, you want to build
242860	250960	that's very important for machine learning in not only in our research, but any kind of research.
251140	255340	You need to build your baseline... your own baseline models from the scratch.
255380	261460	And from the scratch, I mean that you don't need to implement backpropagation yourself.
261980	267340	You don't need. You can, but you don't need. You can use a high-level framework, deep learning
267340	273820	framework to do that for you. So, that will be your starting point for doing research.
274620	281240	And the second thing is that you want to build simple and working models using the techniques
281240	288960	you want to master in research. Because you need to learn them very well if you want to contribute
288960	292400	with something new. And the third point is...
294040	301100	this is kind of strange, but you need to not contribute first to be able to contribute later.
302160	306820	First, you need to learn the basics. Then, you know, you are not contributing. You are
306820	313420	contributing with yourself. And then, you can then try to contribute with the scientific community or
314620	320460	whatever. So, always be humble. You don't know everything.
321780	329280	Okay. So, we are data scientists. Right? Right. So, we need... in our case, we need malware.
329280	335020	A lot of malware. Meaning, we need instances. We need data to feed our models.
336220	343620	This is... that's... this one is my favorite repository. It's called VirusShare. So, there
343620	353520	you can find... I checked yesterday. Almost 34 million instances of malware to download. So,
353520	361900	you can download huge files. Six gigabytes each with 60,000 instances there. And you can play
361900	370420	with them. Okay. And then, one good thing is that they are already labeled using VirusTotal.
386690	394150	So, as you can see, I told you several layers. And the first layers are low-level features and
394150	402490	the deeper layers, high-level features. What we are interested in is getting this data from this
402490	410730	datasets. I will show you. And then, try to figure out if they are... if that... if they
410730	428610	are malicious or not. Because we're trying to detect malware. And then, we have also
428610	434310	the recurrent neural networks. They are good for sequential modeling. So, if you get sequential
434310	442070	data, varying time or space, something like that, you can use recurrent neural networks for that.
442070	447170	They're good for dynamic analysis. So, okay. So, we need to build our machine learning,
447170	455710	deep learning data science pipeline. This is actual real information that I took about one
455710	465130	month to download malware and goodware. And then, I set up an environment hypervisor with nine
465130	472530	virtual machines running for four months around the clock to run this malware and get the dynamic
472530	480250	information. And then, we need to do the basics from data science. Meaning, we need to
480750	487330	pre-process our data. We need to clean the data. We need to make some feature engineering.
488070	494550	We need to get the best features for our problem. In this case, the feature engineering
495410	506750	was minimal. Okay. I haven't done almost any. Okay. And then, we are ready to play with the models.
506750	513350	So, you use a high-level framework and you can start building the models. Okay. So, all right.
514470	521130	So, I have here three models to show you. I will share this code, the Jupyter notebooks,
521130	525590	and I will share the data set, the data sets, because there are several data sets.
527110	532270	So, don't worry if you can't get something, because I will need to be very quick.
533750	539210	Now, I just need some help here, because I will need to throw the code there, and I can't see
539210	548030	the code here, you know, because my screen is extended. Can someone help me there from AI Village,
548030	560920	please? Yes, but then I can't see the code from here, you know, when I drag.
565140	573280	Please. So, what I need is I open here the code, and I want to project there,
573280	594260	but the screen is extended. That's why I... So, I won't have time to explain step-by-step the code,
594880	601280	but basically what I'm showing here is an example of each of those models I showed before. You know,
601280	607180	this one is a multi-layer perceptron for static analysis data. So, basically,
608940	613380	what we do first is to import all the libraries.
614420	622340	Necessary libraries for Python libraries. They're amazing. So, here's our data set.
622700	626320	I'm getting data from the PE sections. So, PE sections basically
627880	635260	describes the sections in the executable file, okay? So, one information here that's
635260	643280	very important is this entropy. Usually, when the entropy is high, it means that either the code
643280	652880	is encrypted or packed. So, malware authors, they usually like packing the content of the file
652880	659880	to avoid antivirus detection. But that's not enough, okay? This can be very high, but it's not
659880	667600	malware. So, can't rely only on one feature. So, okay, and there is a column here saying
667600	673040	some malware or not, okay? So, this is how our data looks like, and this is tabular data. It's
673040	682340	in a table. Here, I do some correlation analysis, you know, to figure out correlation among the
682340	688780	features. You see that some features are very highly correlated. So, we can drop them out.
688780	696200	You don't need to duplicate data. And then, what I'm doing here is opening another data set
696200	702500	that is called imports, PE imports. PE imports basically, you know, when you
703720	707500	create a program, you need to import functions from DLLs and so on.
708820	713460	And maybe we can find, we can, the machine learning, deep learning algorithm can spot some patterns
714220	722760	that are used for malware, in malwares. So, what we're doing here is, in this data set,
722760	729400	is the most 1,000 important imported functions in reverse order. So, for example, this malware
730860	737840	imported this GetProcAddress function, and this GetProcAddress function is the most important,
737840	743720	most imported function. Okay? So, this is what it means. So, you see that there are a lot of
743720	748960	features here, and they are categorical. Categorical features are a little bit harder
749420	754960	to deal with, because you can't just play with them. You're not playing with numbers,
754960	762260	okay? We're playing with categories. All right. So, and in the end, we have said,
762260	767820	and this data set has 47,000
770000	776900	entries. Okay. So, we remove duplicates, and then we merge the files,
777460	784240	and then now we have the data set ready. Okay. I'll jump a little bit here. We convert this data
784240	793340	sets, pandas data frames to NumPy arrays to feed the models. And then there is another problem
793340	803640	here. We need to check the imbalance. And this is high imbalanced. See? 24 to 1. So, we have 24
804480	810300	malware instances for each goodware instances. So, that's a problem. Okay?
811700	819840	Then we need to make the strength test split stratified. So, meaning that after performing
819840	828620	this split, we need to keep the proportions. Okay? And basically here, I'm standardizing
829270	837100	the code. I will only standardize the code that is numeric. See? I'm not touching the
839560	847980	categorical data. Okay. So, let's jump to the model. Ah, here. There is something interesting.
848080	855140	We need to deal with imbalance. So, the data set is imbalanced. So, we can try to use some
856000	866120	algorithm to oversample, oversampling technique. So, for example, this moat won't work here,
866120	871020	because it can't deal with categorical features. And there is a variation called
871020	880120	smote nominal and continuous that was taking just too much time to run. So, I gave up for now.
880120	884900	And then we can use a random oversampler. But random oversampler is bad, because it just
885700	895340	duplicates data. But in our case, helped. So, after running that, you see, we can see here
895340	902060	that now the data set is balanced. And then I will perform some visualization using T-SNE.
902820	911780	T-SNE is a pretty awesome algorithm for visualizing high dimensional data.
913060	920040	Basically, it projects high dimensional data onto the plane or to a space. So, you can
920040	927000	have an idea how the data is in that high dimensional space. And then you can also
927000	932600	have an idea about the decision boundaries your model will need to learn. And if you see,
932600	940220	this is complicated, this one. Red is malware and green is good work. We need to separate them out.
940560	948040	So, deep learning. So, here's a model, deep learning model for multilayer perceptron. As
948040	952900	you can see, the model is quite simple. This is not research. This is just
955340	961800	that homework, you know. I said in the beginning that I need to understand how to build a simple
961800	969460	model in order to try to build something more complex or new. So, this is just a model with
969460	976680	two dense layers. And then after that, we create the model, get here the summary,
982160	990600	146,000 parameters. It's not really too much, right? Here's a model. We can get this model,
992640	997540	the architecture of the model, just with one command. And now here, there is an algorithm
997540	1005900	that I would like to explain more deep, but I can't because I don't have time.
1005900	1012980	But this is a model selection. Basically, I'm making an automation of the model selection here.
1012980	1020000	I'm getting those hyperparameters and testing each one of them, combinations, you know,
1020000	1027540	and performing a threefold cross-validation to see which combination is better.
1028520	1035680	And after that, we train the model for some time. This case didn't take too much, okay?
1035680	1041360	I trained at home, okay? I have a NVIDIA RTX 2080
1043160	1057200	Ti. So 4,300 to the cores. It's a decent card. So 10,000 seconds, roughly three hours.
1057200	1061500	And here, it's important to evaluate the model using the test set.
1062440	1069500	And okay, we have here the results from the model selection. So this is the best combination,
1069500	1077500	dropout rate, 0.6. The first model architecture here is a dropout first,
1077500	1082420	and then batch normalization. There is a holy war about that. You know, people know you should
1082420	1091080	use batch norm first and then dropout, or vice versa, and neither of them are both in any order.
1091620	1098020	But actually, it depends on the nature of your data. So that's why you need to test it.
1099500	1106100	And the lowest number of neurons won. So after that, we perform an evaluation. And with the
1106100	1113180	evaluation, we have a thing called confusion matrix to show the true negatives, false positives,
1113180	1121080	false negatives, and true positives. First, what we do is to create a benchmark.
1122200	1129140	So suppose that you have a model that predicts that every example is a malware. So what happens?
1129140	1133660	These are the numbers you get. And you see, since the data set is imbalanced,
1133660	1138520	you get pretty good numbers here for accuracy, precision, recall, F1 score.
1138960	1146220	This is misleading. So you need to use a better metric for unbalanced data set. The best metric,
1146220	1152400	as far as I know, is a balanced accuracy. And balanced accuracy is showing here that, basically,
1152920	1158320	you have chosen... you have predicted every example as a malware.
1159060	1162980	So it's very bad. This is the worst case scenario. And then when we apply
1164800	1173340	on the test set, our model, we get this result. So it's much better. So as you can see,
1173340	1179840	if we were using a multi-layer perceptron, that is a very simple deep neural network,
1179840	1185400	we can already get very good results. Now you can imagine those very, very deep models
1186140	1192700	with those inception layers and so on. You can get much better.
1192700	1199760	Okay, now the next example, I'll just show you the model. This is interesting,
1199760	1204560	because what I have done here is just to treat the binary data
1206860	1214740	like an image, as if it was an image. So take a look at that. This is what we get.
1215080	1222640	So these are malware images. I get the binary, and then I treat each byte like a grayscale,
1222640	1231280	and then scale it. So we get this information. And then, basically, we feed it to a convolutional
1231280	1237260	neural network, because convolutional neural networks are specialists in dealing with images.
1237260	1243420	So the same problem, imbalanced, and so on. And then visualization looks similar to what
1243420	1248700	we have seen there. Pretty complicated decision boundary. And then deep learning.
1248700	1254620	So this is our model, convolutional model. So as you can see, it's very, very simple.
1254620	1263500	We have a convolutional layer, and then we have... there is a model selection here.
1263540	1268600	It's about, should we apply max pooling first, and then batch normalization, or
1269860	1275520	batch normalization first and max pooling. This is also a holy war, you know? Nobody knows
1276300	1284600	what's better. But what you can do is to perform model selection with cross-validation,
1284600	1291660	which is better for your kind of data. All right. So basically, we have a convolutional layer,
1291660	1297260	and then max pooling, and then another convolutional layer, and then max pooling.
1297260	1304780	And then we flatten them out to feed to a fully connected layer for classification,
1304780	1312580	or in our case, binary classification. Okay. So we train this for some time.
1315050	1317630	I think I still got some five minutes.
1319950	1324830	I want to show you how much time I needed to train.
1326070	1341340	Here. So 15,000 seconds, five hours, four hours. Not too much, really.
1342080	1350360	And the results. So cross-validations and results. Evaluation. Okay. So the bank mark,
1350360	1355140	also pretty good. Accuracy, precision, recall F1 score, because they don't deal
1355140	1361340	very well with unbalanced datasets. Balanced accuracy is the worst possible.
1361840	1368580	And then when we use our model to predict using the test set, we get this.
1369240	1375480	So also not good. But there are some explanations here. First, because
1376640	1383960	I think the main explanation here is because malware, usually nowadays, they are all packet.
1385180	1391160	So the content is encrypted or obfuscated. So what you are seeing here
1393320	1400580	is mostly random noise. So you can't expect the algorithm to do much better.
1400760	1406820	But still, it's a pretty good result. You could just, for example,
1406820	1415220	add and step in your pre-processing pipeline to unpack this. But this is quite complicated,
1415220	1421140	because each malware uses a different technique, different key. Sometimes the key,
1421140	1431800	and so on. So it's complicated. And then, finally, dynamic analysis. Dynamic analysis,
1431800	1440220	I will show you the network called long short-term memory. It's pretty good for dealing with
1441160	1448440	sequential data. And all this software you see for speech recognition, automatic translation,
1448440	1453260	use this kind of network. So here I'm getting the sequence of calls,
1453260	1462160	of API calls. See? T0, T1, T2. These are the calls the malware does to the Windows API.
1462160	1470140	So I got just 1,024. And then, basically, I do the job here of cleaning and then
1470880	1476480	balancing the dataset. And take a look at this. Even more simpler network.
1477380	1486520	There is a version. If you are running TensorFlow and Keras, you can use the Qt version
1486520	1494790	that runs much faster than the LSTM version. And then, basically,
1497740	1503340	this takes much more time to train, okay? Your GPU will be burning there for some hours.
1503340	1515200	Really burning 90%, 100% usage for several hours. And in this case, it took about
1517100	1526240	29,000 seconds, nine hours, okay? And the results here of the model selection.
1526660	1530960	And, basically, you get our confusion matrix and then get the results here.
1530960	1540320	You see? We got 91% balanced accuracy. This is a little bit impressive. Because our
1541200	1548120	dataset is small, you know? And the number of features, I don't know if you have noticed there,
1548120	1556380	but the dataset has 1,024 features. And we used only, I think, 300. Because my computer didn't
1556380	1562200	have enough memory. Because we need to make a conversion of these features from categorical
1562200	1569060	to one hot encoders. Encoding, sorry. Before feeding the model. But my computer didn't have
1569060	1576220	enough memory for that. So, all right. Now we can have an idea how you can
1576860	1582400	apply deep learning for model detection and classification. That was the idea of this talk.
1582400	1598700	So, let me just close here. Can you see there? The slides? Okay. So, okay. And my research,
1598700	1604040	basically, is about malware behavior. And I'm researching specialized data augmentation
1604040	1610180	methods. Because the current ones, they just don't work very well with this kind of data.
1610180	1616060	And also specialized representation learning techniques from our detection classification.
1616060	1621160	And this will lead to improvements in detection and classification of zero days
1621160	1630760	and polymorphic and metamorphic malware. And that's it. Thank you very much for attending.
