00:00:00.133-->00:00:04.471 >>You know it takes a lot of effort to talk in front of a big group and this is Andrea's first 00:00:04.471-->00:00:09.476 time, so, uh, let's give him a round of applause. [applause] There you go. [applause] >>Can I 00:00:15.182-->00:00:21.455 start? Okay. [chuckle] Well, good morning and thanks for being here. It is my first time 00:00:21.455-->00:00:27.895 DefCon, it's a big pleasure to be here. My name is Andrea Marcelli and today the talk is 00:00:27.895-->00:00:32.900 "Looking for the perfect -. Signature and automatic YARA-rule generation algorithm 00:00:32.900-->00:00:37.905 in the AI-era. I am PhD student, at Politcino of Torino in Italy. I study machine learning 00:00:40.607-->00:00:46.513 semi-supervised modelling and optimization problems. But I am also Ph-, uh, security 00:00:46.513-->00:00:52.552 researcher at Hispasec Sistemas where I work on new techniques for large scale Android malware 00:00:52.552-->00:00:57.557 detection. Today we will talk about the signature generation problem about the algorithm that 00:01:00.560-->00:01:06.366 I have developed and the tool that I have, uh, developed. Then we go through a quick, uh, demo 00:01:06.366-->00:01:12.539 and some results of the algorithm. So, let's now, let's now talking, start talking about 00:01:12.539-->00:01:18.845 the signature generation problem and what is a malware signature? A malware signature is a unique 00:01:18.845-->00:01:23.850 pattern that indicates the presence of malicious code. And, since the problem is that since 00:01:27.120-->00:01:33.760 malware evolved over time, new signature, uh, should be generated very frequently. And 00:01:33.760-->00:01:38.165 historically there are 2 type of signatures: there are syntactic signatures and semantic 00:01:38.165-->00:01:44.338 signatures. Syntactic signatures are those based in text word strings and on, uh, binary 00:01:44.338-->00:01:49.176 sequences extracted from the application. And this is also the industry standard type of 00:01:49.176-->00:01:55.449 signatures and where most of the existing research focus on. Except today we will talk about 00:01:55.449-->00:02:00.287 Semantic signatures which, according to some recent research group, could lead to 00:02:00.287-->00:02:06.693 better detection. And this provide and obstruction in the program behavior. So, in today 00:02:06.693-->00:02:13.033 our talk we, we'll talk about Android malware and automatic signature generation. But all 00:02:13.033-->00:02:19.239 the concepts are very generic and should be applied and could be applied to harder targets 00:02:19.239-->00:02:25.045 too. So, which are the motivations behind the work? We-, well well, first of all we 00:02:25.045-->00:02:31.151 want to reduce the malware exposure time, second, uh, generating, writing a malware 00:02:31.151-->00:02:38.025 signature is a very repetitive task and keep in mind that with, from 20- to 50 thousand new 00:02:38.025-->00:02:44.331 applications received everyday. Malware analysis is not an option. Then we have a goal 00:02:44.331-->00:02:49.403 which-. [mic disturbance] And very high precision requirements. In other words, 00:02:49.403-->00:02:55.142 you want to lower false positives and false negatives. And lastly, in the end it's all 00:02:55.142-->00:03:00.580 about saving a lot of resources and time because writing signatures malware it's very 00:03:00.580-->00:03:05.819 time-consuming and expensive. [mic disturbance] Today we will generate signatures using their 00:03:05.819-->00:03:11.525 YARA language. YARA has been defined by Victor Alvarez, his has creator has "YARA's to files 00:03:11.525-->00:03:17.064 what's snort is to network traffic." [mic disturbance] And that of YARA is that YARA is 00:03:17.064-->00:03:23.236 fast and it's also the standard type of languages that is used in the anti-virus industry. So, 00:03:23.236-->00:03:30.243 it's very spread. And YARA naturally support, uh, syntactic signatures but it also support 00:03:30.243-->00:03:36.016 semantic signatures through custom models. So, you can write your own models. It's an example 00:03:36.016-->00:03:40.921 of YARA-rules - there are three main sections, although the most important 1 is the condition 00:03:40.921-->00:03:46.927 that is where the logic of the rule is placed and also where the semantic attributes of the 00:03:46.927-->00:03:53.500 signature can be hardened. Now, let's go through the algorithm the algorithm of the, for the 00:03:53.500-->00:03:59.406 automatic malware signature generation is placed within a pipeline that is very common to 00:03:59.406-->00:04:04.344 many anti-virus, uh, industry, antivirus software's house. And the idea is that there is a, a 00:04:06.413-->00:04:11.184 mission, some new application every day. These applications are analysed through machine 00:04:11.184-->00:04:15.188 learning techniques mostly unsupervised techniques. [mic disturbance] In order to 00:04:15.188-->00:04:21.394 automatically infer new malware families that is the clusters. And in the end for each malware 00:04:21.394-->00:04:26.399 family it want to generate, uh, a signature and that is where my algorithm comes in place. And, 00:04:28.535-->00:04:33.406 in order to generate the signature you need to start from some attribute, some features 00:04:33.406-->00:04:37.944 extracted from the applications. Through the application analysis, both statically and 00:04:37.944-->00:04:44.251 dynamically. And, just to have a graphical representation, it's feature could be a small square 00:04:44.251-->00:04:50.524 within the grey grades which you can see in the slides. And could be, for example, a URL, could be 00:04:50.524-->00:04:56.963 a permission, and intent filter or everything else. And it's very very important that the 00:04:56.963-->00:05:01.902 analysis is performed very carefully because through the analysis, uh, we extract the 00:05:03.937-->00:05:08.942 attributes. And having good attributes is the key. To have a good signature tool. So, the 00:05:12.212-->00:05:17.250 idea behind the algorithm is very simple. We have two application, we have a set of 00:05:17.250-->00:05:21.788 attributes for each applications. Probably some attributes will be of the same 00:05:21.788-->00:05:27.027 type and we'll be actually the same between the two applications. In this case we 00:05:27.027-->00:05:33.800 have some orange and some green attributes which, are, uhm, the same. And, actually, we can 00:05:33.800-->00:05:39.472 generate the signatures by combining those attributes. Although the reality is much 00:05:39.472-->00:05:44.377 more complex and as you can see most of the cases you can not find unique pattern which is, 00:05:44.377-->00:05:50.050 uh, in common with all the samples of the same malware family. And, so the problem of 00:05:50.050-->00:05:55.055 generating a signatures is the problem to find the, uh, attribute's subsets that cover 00:05:57.424-->00:06:03.129 the entire malware family - all the samples of the entire malware family. And, if, if you 00:06:03.129-->00:06:09.436 think about it it's a very, it's problem that is very similar to a very well-known problem in the 00:06:09.436-->00:06:15.609 literature which is the set coverage problem. Actually, this is a variant of the set coverage 00:06:15.609-->00:06:20.614 problem which unfortunately is very hard to solve because it's an incomplete problem. But since 00:06:22.616-->00:06:28.288 we are not interested in a global optimal solution, we just need a local optimal solution. I 00:06:28.288-->00:06:33.159 have developed a dynamic YARA algorithm to solve the, to solve the problem. And actually 00:06:33.159-->00:06:37.731 automatically generating a signature. So, as you can see, generating a signature is not 00:06:37.731-->00:06:42.736 such big issue but the main challenge is to evaluate a signatures. So, in order to 00:06:45.805-->00:06:51.177 better understand these process, I will introduce a couple of formulas. First of all is the 00:06:51.177-->00:06:56.182 DNF, the des-, Disjunctive Normal Form, where a certain clauses are illogical or an each 00:06:58.385-->00:07:02.155 clause is made by a set of clauses which are illogic or, and each clause is made by a set 00:07:02.155-->00:07:07.527 of literals which are illogic. And, and a literal is one of the attributes that we have 00:07:07.527-->00:07:12.532 extracted before through the analysis. So, we redu-, if we reduce each signature to a DNF 00:07:16.636-->00:07:21.641 we can actually wave it's clause and that way - we can say that the weight of its signature is 00:07:25.345-->00:07:30.350 actually the lowest among its clauses. And this work-in-progress is the base of 00:07:33.253-->00:07:39.693 the evaluation process of its signature, because of the signature have, have. Has a very 00:07:39.693-->00:07:45.231 high weight it means it's, it's too specific. It will not be able to generalize and we'll 00:07:45.231-->00:07:50.236 actually produce a lot of, uh, false negatives. Instead, if it's too generic it will, uh, 00:07:54.107-->00:07:59.579 uh, uhm, generate a lot of unwanted detections that is a lot of false positives. So, we 00:07:59.579-->00:08:05.485 want to generate a signature which, which states between 2 threshold "t-min" and "t-max". 00:08:05.485-->00:08:12.359 And that's where the optimal signature are. So, as you can understand, the, uhm, the key of 00:08:12.359-->00:08:18.732 the waiting process is to actually assign a good value to the attributes. And the value of 00:08:18.732-->00:08:24.104 the attributes are really tied to the value of the real threshold t-min and t-max. And 00:08:24.104-->00:08:28.575 actually I want the entire process to be automated and I didn't want to rely on the 00:08:28.575-->00:08:34.748 knowledge of the expert analysis. I just wanted to make it automated. And, one of the 00:08:34.748-->00:08:39.119 possible solution is to start form the repository of YARA-rules. there are a lot of 00:08:39.119-->00:08:44.891 public repository of YARA-rules and that you can parse them and reduce to the, uh, disjunctive 00:08:44.891-->00:08:49.896 normal form. Then you can, then it becomes, uh, a leaner problem that you can solve by means of 00:08:52.065-->00:08:57.337 linear programming algorithm like the simplex algorithm. And in the end you are able to 00:08:57.337-->00:09:02.275 satisfy. The 95 percent of rule set in order to have a weight which is between the 2 00:09:05.412-->00:09:10.417 thresholds. Why 95 percent? Well, because some rule sets are so specific to a, to a very, to 00:09:12.986-->00:09:17.891 fulfil, to a type of malware family that it's not possible to really extract some useful 00:09:17.891-->00:09:22.896 knowledge from, for them. Well, when I actually implemented these, uhm, these algorithm I 00:09:26.966-->00:09:33.139 run into a new problem that is the signature were too specific, too many attributes. Too many 00:09:33.139-->00:09:38.778 attributes - the weight was so high. It was actually impossible to use them. So, uh, in order to 00:09:38.778-->00:09:44.684 create a better signature, we have to remove some attributes. How to remove them? I have 00:09:44.684-->00:09:50.290 developed 2 strategies - 1 very simple which is the basic optimiser. Which simply, 00:09:50.290-->00:09:56.496 randomly throws away some attributes. And then the other is the basic optimiser. And when 00:09:56.496-->00:10:01.134 we use evolutionary algorithm to optimise the signature? Well, there are some non-written rules 00:10:01.134-->00:10:06.139 about how, uh, to generate a good signature and those rules can be placed within, uh, an 00:10:08.541-->00:10:13.680 algorithm, a genetic algorithm. That actually find the best combination of them to generate 00:10:13.680-->00:10:17.717 the best signature. And the good thing about, uh, all of them is that they are all very, they are 00:10:17.717-->00:10:19.719 very fast - 1 less than 1-minute and the other about 5-minutes. So, it's scalable. So, after I 00:10:19.719-->00:10:21.721 implemented the, the entire procedure that I have described into an algorithm, which is 00:10:21.721-->00:10:23.723 called "Interproblem" which is called "YaYaGen". YaYaGen is an acronym that stands for "Yet 00:10:23.723-->00:10:26.593 Another YARA-rule Generator" and if you know Spa-, if you know Spanish, you will probably know 00:10:26.593-->00:10:33.199 that yana, uh, "ya ya" in Spanish means, uh, grandmother. And the goal of YaYaGen is to 00:10:33.199-->00:10:38.204 create, uh, is to start from a set of application, application records which means uh, start 00:10:55.855-->00:10:58.391 from the result of the analysis several applications and generate for them a set of 00:10:58.391-->00:11:00.326 YARA-rules. YaYaGen includes a lot of functionalities and for sure the most important one are 00:11:00.326-->00:11:02.328 the algorithms generate the rules. There are, uh, 2 variants, there is the closed 00:11:02.328-->00:11:04.330 and the greedy. The closed is, uh, unanswered greedy because the problem with the greedy is 00:11:04.330-->00:11:09.335 that probably you will generate rules which are not homogenous in the number of, of samples 00:11:12.305-->00:11:17.310 that are covered. Instead, the closed tries to generate a rule with all of the, all the same 00:11:38.965-->00:11:45.772 coverage in order to create better rules. Then we have 2 optimiser, the basic and the 00:11:45.772-->00:11:50.843 evil one and some heuristics because in the signature generation it's all about 00:11:50.843-->00:11:57.483 heuristics. For example, we are very interested in including some URL if those are malicious 00:11:57.483-->00:12:02.522 so there are some heuristics to understand if URL is malicious. There are some heuristics to 00:12:02.522-->00:12:07.527 throw away some attributes so performing some kind of filtering in the beginning. And 00:12:09.829-->00:12:14.233 the software package also include the YARA-rule parcel for, uh, attribute weight 00:12:14.233-->00:12:19.639 optimisations. S, if you have your own set of YARA-rules you can actually apply this program 00:12:19.639-->00:12:24.644 and find out. [coughing] Which ways satisfies these rules starting from your set. Uh, then 00:12:27.614-->00:12:33.086 it also supports the false-positive exclusion and although the false-positive, 00:12:33.086-->00:12:38.891 false-positive match is something very rare with our automatic generated signature. 00:12:38.891-->00:12:43.463 Uh, we want to include this option in the rule generation so in case I wanted detection you 00:12:43.463-->00:12:48.801 just include that detection into the process of generating a signature and the, the signature 00:12:48.801-->00:12:55.708 will not match that false positive anymore. Everything is written in, uh, was written in 00:12:55.708-->00:13:02.081 Python 3, so very to, very easy to use and customize and, finally, as you may understand, 00:13:02.081-->00:13:07.487 this is just a plug-in with a much bigger infrastructure. Because you need the 00:13:07.487-->00:13:13.526 infrastructure to actually analyse, uh, the application and the infrastructure to test the 00:13:13.526-->00:13:20.266 rules to have generated. And that's the reason why YaYaGen has been written to directly 00:13:20.266-->00:13:25.571 work with Koodous. Because it's the open anti-virus from [indiscernible] and it's free 00:13:25.571-->00:13:30.576 and, uh, open to everyone. And it works with, uh, Android applications, Android malware. 00:13:33.146-->00:13:38.151 So, the great news about YaYaGen is that it's free, its on GitHub so, any, any improvement is 00:13:40.753-->00:13:45.758 really welcome. Now I'll go through short demo. [pause] Okay, in this case I'm, uh, 00:13:54.267-->00:14:00.840 using YaYaGen to generate a rule using the closed algorithm for the SkyGo free family - malware 00:14:00.840-->00:14:05.845 family. And, uh, as you can see, I gave the input some, uh, hashes of known applications 00:14:08.481-->00:14:14.587 that belong to this family. And what the tool actually is doing now, is just downloading the 00:14:14.587-->00:14:19.592 report of the, the an-, the app-, the application analysis from the internet. So, uh, I 00:14:23.262-->00:14:28.468 said it's generic and it is because if you changed this part that is if you feed into YaYaGen 00:14:28.468-->00:14:33.773 and other type of report. It's just, uh, it's all about changing which attributes are 00:14:33.773-->00:14:40.613 selected and then everything can be optimised. It's not tied to this type of report only. And 00:14:40.613-->00:14:47.453 the rule that is generated and everything is super fast because I didn't speed up anything and 00:14:47.453-->00:14:52.091 the rule is, that is generated is a valid YARA-rule so you can actually use this rule, uh, in 00:14:52.091-->00:14:57.096 your system. Be only aware that probably you will need some custom models, uh, in YARA to 00:15:00.466-->00:15:04.370 use it according to the type of the attributes that you used. In our case we are using Android 00:15:04.370-->00:15:09.242 variant and Cuckoo which are, uh, models that are available in Koodous but probably if you will 00:15:09.242-->00:15:14.247 use it, uh, on your home platform you will have to hide them. And let's, let's just go 00:15:17.450-->00:15:22.455 through the rule. This rule has 17 literals which means 17 attributes with a score, or, of 00:15:25.458-->00:15:30.463 484 which is a quite high score. And it's above the threshold the minimum threshold is set to 400. 00:15:34.834-->00:15:39.839 It has a coverage of 8 over 8 which means that all the samples that, uh, I gave an input are 00:15:41.974-->00:15:47.980 covered. Because in this case the family was very tight. If the family is loosely defined, 00:15:47.980-->00:15:52.985 it doesn't matter, simply find more rules. And, that's all for the demo. Now, let's go back to 00:15:58.491-->00:16:03.429 the result. I wanted to, to compare the efficacy, the effectiveness of the automatic 00:16:06.465-->00:16:11.470 generated rules with the human generated, the human-written rules. So, I started from some 00:16:13.673-->00:16:18.678 of the available ones and I tried to recreate an automatic version, uh, starting from some 00:16:21.514-->00:16:26.519 sample that were originally detected. Well, actually I did some tests on a 1 point 5 00:16:29.388-->00:16:34.393 million dataset of Android applications collected through 2017. And, what it comes out is 00:16:36.696-->00:16:42.034 that all the automatically generated signatures improved the number of detection. Ranging 00:16:42.034-->00:16:47.039 from the 8 percent to the 1, uh, 131 percent. With an average of 65 percent - so, it's a huge 00:16:50.309-->00:16:57.283 improvement and all of that without even generating a false-positive. So, in order to 00:16:57.283-->00:17:02.221 conclude, I developed a set of algorithms to automatically generate YARA-rules. I did it in 00:17:05.958-->00:17:10.963 the context of Android and using YARA language. But, as I said, everything can be easily ported 00:17:12.965-->00:17:19.338 to other targets and other languages. And what comes out is that automatically generated 00:17:19.338-->00:17:24.343 rule, rules perform better than human-generated ones. Then, one interesting fact is that there 00:17:27.980-->00:17:33.586 are several ways in which the expert knowledge can be included into the YARA-rule generation. 00:17:33.586-->00:17:38.324 For example, there are the heuristics, they are the way in which the, uh,attributes are, 00:17:38.324-->00:17:43.329 the attribute value is set. And there are also, also the optimisation phase. So, actually 00:17:45.364-->00:17:50.369 a malware expert can really increase the quality of the, the automatically-generated rules. 00:17:53.105-->00:17:58.110 And finally, all the approach is very scalable because generating a rule for 100 app, it takes 00:18:00.246-->00:18:05.251 less than 5 minutes. And if it grows to 1000 app. it takes around 30 minutes - less than 1 00:18:08.254-->00:18:14.360 hour. So, it's a lot but its hours less compared to manual work. We're working on a new 00:18:14.360-->00:18:19.365 version YaYaGen which will target, uh, a Windows executable. It's called "YaYaGen 00:18:24.270-->00:18:29.642 P" we are still working on that. We are still testing it but preliminary results are very 00:18:29.642-->00:18:34.647 great. So, I, I will keep posted, if you, if I have any news. And that's all. Thanks a 00:18:39.185-->00:18:43.856 lot for attending the talk and if you have any question I would really appreciate to talk with 00:18:43.856-->00:18:48.861 you off the stage. [applause]