Next up, we have Mark Mager on Stop and Step Away from the Data, Rapid Anomaly Detection, via Random Note File Classification. We'd like to thank our sponsors, Endgame, Silance, Tinder, and Sophos. And reminder, if you could, please sit down in the seats. We don't want to have a fire code violation. With that, enjoy the talk. All right. Morning, everybody. So just getting things a little bit about me. I'm not a data scientist, so take whatever I say up here on stage with a very big grain of salt, and please feel to ridicule and embarrass me after the talk about the things that I get wrong. But anyways, a little bit about me. I'm a senior malware researcher at Endgame, typically do reverse engineering and sensor development. And the past two and a half years, pretty much since I've been at Endgame, I've been doing ransomware protection research. Just again. To the agenda, I'm going to provide a brief overview of ransomware, what your current detection methodology looks like, ransom notes. And then I'm going to delve into some exploratory research about the detection research that I did, and then discuss in depth the proof of concept framework that I came up with, and then wrap things up in conclusion. Hopefully, I have a little bit of time for questions. So if you don't know about ransomware... Ransomware, basically, it's a software that's written to deny users access to data on their host. The most typical approach is through encrypting individual files on a file system. And the file extensions are what's going to be targeted. So think of high-value documents like PDFs, text files, Word document, Excel spreadsheets, things of that nature. And so there's... There's two typical types of output from ransomware, the encrypted files that I was just alluding to, and the actual ransom notes. So detection methodology can be broken down pretty simply into two areas right now. You have static detections, which are either going to be signature-based, signature or heuristics-based, or machine-learning-based. The main benefit to this approach is that all data is preserved. If the detection is successful. But the drawback is that you essentially have one chance to detect whether a binary is ransomware or malware or not. And if we miss that, then all data is going to be compromised on the host. And for dynamic detections, basically, the way those work is it's a process that's going to be running in the background. That's going to monitor for any sort of anomalous behavior on the host. There can be a focus on detecting encrypted files. In certain cases, some approaches leverage canary files, which are files that are written to disk and, you know, kind of spread out in different locations. And if they're modified in particular ways, then that can be a trigger for an alert. So the main benefit for dynamic detections is that, you know, hypothetically, as a process is executing, there will always be a trigger for an alert. There will always be an ongoing chance that it will be detected. So it's not just there's one initial chance to detect and then, you know, your host is after that. But, you know, so should still be able to detect it later on. The drawback to dynamic approaches is that essentially you're sacrificing a large amount of files in order to determine whether or not there's ransomware executing on the host. Maybe in certain cases, it's easier to detect the anomalous behavior. In some cases, it might, you know, either be impossible or take a very long time. So how can we improve what the current saving art is right now? Probably the best approach is to combine benefits of static and dynamic detections. In the ideal case, yes, you would detect everything with machine learning immediately. Nothing would ever, you know, be able to detect anything. You would never execute on the host. But that's not always the case. You know, there is definitely false negatives. So you need a robust dynamic detection to serve as a fallback. So leveraging a layered security approach is probably, you know, the most recommended way to make sure you're covered for ransomware. Optimizing your machine learning models to specifically classify ransomware as opposed to just malware specifically. That can prove very beneficial. For this problem. And then to go back to dynamic detections, perhaps there might be a way to boost the time or reduce the amount of time that's required for detecting anomalous behavior. So getting into ransom notes. A little bit of background on this. Since I've been doing ransomware research for about two years or so, I've executed indebted ransomware. I've designated, you know, probably almost thousands of files manually in a virtualized environment. And kind of studied how the output typically looks. And then, you know, as sort of an aside, I was seeing ransom notes being written to disk in multiple ways, multiple directories, multiple formats. So what kind of got the gears turning for research that I'm presenting today is that I started kind of seeing a pattern in how the ransom notes looked. And so I wanted to explore that to see if there was a way that we could kind of classify those. And see if there was something there that kind of unites all of them and makes them easy to detect using AI. So just to go back a little bit. Ransom notes. Files that are written to solicit a ransom payment. They come across in multiple file types. The most typical format is TXT files, plain text files. But you also see ones that are in more formatted text formats such as HTML, RTF. And there's also images or even like GUI based like little .NET programs. Ransom notes are going to be one of the first files that are written to disk. And sometimes they're even written to every directory. Essentially, the adversary is trying to be as noisy as possible. In the hopes that they frustrate the users enough. And get the point across that their data has been totally compromised. And they have to provide the ransom to getting their data back. So we'll go back through here and look at a few ransom notes to kind of get a general idea of what I'm talking about. So this one is from CryptoLocker. And they kind of lead off with just saying your files are encrypted. And then they talk about you don't have access to your data. This is a description piece. So you can't recover your files. They want you to email them. And they're providing a specific time window for how long the ransom will be valid essentially. And then they even get into talking about the AES encryption that they're hypothetically using. Going on to the next sample. It pretty much starts out with the exact same way. All your files have been encrypted. And then they say something similar about all your documents are encrypted. Can't recover. Please pay us .01 bitcoin to a specific wallet ID. And then they also provide email address. And finally, here's an actual image based ransom note. And if you'll pay particular attention, they were requesting 100 bitcoin. Which is approximately $750,000 right now. So not exactly sure how successful they were with this ransomware campaign. But they were at least pretty pricey. So as we saw from even just looking at three very disparate samples of ransom notes. You can kind of see a template kind of form. They typically lead off with saying something about your files have been encrypted. Sometimes they provide a family name. And then they'll sometimes get into talking about the actual encryption that was implemented as part of the ransomware. They get a point across that. That files can't be recovered without a decrypter that they'll provide. Only if the ransom is provided. And then potentially provide email address. And then a time window for when their ransom essentially will be invalid. So as I previously said in my intro, I'm not a data scientist. So exploratory research for me in this case. Was just developing a better familiarity with data science concepts. And different tools I'd use. And then moving on from there. I need to collect a big enough corpus of ransom notes. In order to do some training. And on the flip side of that. We need to put together a nice base representative benign data set. To go with the ransom notes. And the overarching goal of the exploratory research. Is to determine if this approach can possibly work for classification. So tools I'm using here. Pretty much just use Anaconda for everything. Which came bundled with Python 3. Jupyter Notebook. And also use scikit-learn. So delving into the data sets a little bit. Benign data. I just ended up using the 20 news groups data set. Which probably most of you are familiar. That's a list of the actual 20 news groups that are part of that. And then for the ransom notes. It's definitely a little tougher to put together a large collection of ransom notes. Not every ransomware family writes them out to disk. So going through and kind of manually doing the research. And figuring out which families actually drop notes. Can be a little tedious. So a lot of this involved manually detonating ransomware samples. Over a period of years. Collecting the ransom notes. You know. Storing them off. And then kind of digging them out for this project. But also. Searching through blog posts. Twitter. And a lot of things like that. I was able to collect enough samples. To feel confident. I had something that was representative. Of ransomware in general. So the actual approach. That I was taking. For the explored herd research. Is we're just going to go with unlabeled data. We're going to take the 20 news groups data set. And then we'll combine that with the ransom notes. And so we'll take a clustering approach. Using kmeans. And set it to 21 clusters. And the way we write with that. Is we'll use the 20 news groups data set. And ransom notes. And we're going to hope that. With the 21 clusters. The way they kind of. Settle down. You know. That they'll be distinctly. Each of the news groups will be in their own cluster. And the ransom notes will stick together in their own cluster. In order to. Analyze the data a little closely. We'll take a look at the data. Using an account vectorizer. And a tfidf vectorizer. So getting started. Just to do some very basic. Data prep. For tokenization. We're just going to strip out newline characters. Convert to lowercase. Strip out null bytes. Just things like that. To just get the data starting to. Make a little bit more sense. And then when we do the actual tokenization. We're going to limit it to alphanumeric characters. Only. We're going to strip out any stop words. That are in the default spaCy stop words list. And we'll do limitization. So in a. Very quick example here. We can actually. Turn it into a crypt. So here's just a. Very quick overview of how. The tokenization. Worked. And for this. Example actually took. A very small blurb for a ransom note. And passed it in. And you can see how it actually breaks down. Two very. Very core. Set of words there. File encrypts and bitcoin gets a payment. Which is. Very descriptive of exactly. What they're going for. So now. Not sure how well you can see up there. Breaking down the most common features. That we're seeing in the. 173 ransom notes. We see a lot of. The same sort of words. We see things describing. You know files. With data being encrypted. Bitcoin course encrypt decrypt. You know. Things along that sort of nature. Like even just looking through those words. You might be able to. Construct what the purpose of. A ransom is. Without having any sort of context. And then when we break it out to. Bigrams. Things make a little more sense. Because you're working with. Phrasing so. It's not just files in a vacuum. It's files being encrypted. Files being decrypted. Private keys. To give you a little bit of an idea. Of what the data looks like. Then when we apply. TFID VEF. Looks pretty similar to. What we're getting from the count vectorizer. So yeah. Just gives you another view. Of what the data looks like. Now. Not sure how well you can see this here. But essentially with the 21 clusters. They broke out. Like quite nicely for us actually. And in cluster 3. Despite the ransom notes. Only consisting of 173. Unique samples. Versus the 11,000. Messages that were in. The 20 news groups data set. The ransom notes. All clustered together extremely well. That cluster. I believe that's. The top 10 features. That are in that cluster. Matches extremely well with what we've just seen. In the previous two slides. And that actually is a. A good. Test for the data set. Because if you'll see. The top. Entry for the news group. In the image to the right. Is cy.crypt. Which is the. Encryption news group. At the time. But yeah. If you see cluster 6. It might be a little tough to tell. But you can get an idea. Of how old the data is. Like that was. Around the mid 90's or so. But either way. Distinguishing between. News group discussions around encryption. Versus ransom notes. That do discuss encryption. At a more high level. That's a good initial test. Of how strong the data correlates. And so delving into. How. How the cluster actually worked. We want to kind of get. Through the hood. And pass in some sample data. So I took another ransom note. And passed it into the k-means predictor. And if you break out. The results for that. Using the square root. Of the sum of the squares. We can calculate the distance. From the centroid. For each of the clusters. Here. So in our case. With that ransom note. It did end up in cluster 3. Which worked out very well for us. For a second example. We kind of used. Something that's more generically. Just talking about encryption. But not specifically a ransom note. In this case. It actually ended up. Being closer matched to. Cluster 4. Which is actually entries from. Computer dot graphics. So. What did we learn from doing our. Well as I mentioned before. All set of data. But the ransom notes. Do cluster together very well. The second sample. Demonstrated that there is nuance. In how the data was clustered together. And from all that. We learned that it appears. That the data is going to be appropriate. For classification. So we can actually go forward. With an actual proof of concept. So for a POC framework. We have a few requirements. First and foremost. We need to. Take the file paths that are. Being created. And pass them to a model that we develop. From there. We're going to read in the actual text data. From the file paths that have been created. We're going to read in the file contents. And then pass that along. To the classifier. To determine whether or not. The data consists of a ransom note. And then if it is a ransom note. We need a way to mitigate the process. So to reduce the problem space. For this. We're going to put up a few restrictions here. We're going to stick to English only. And .txt files only. As I mentioned. They're the most common ransom notes. But that doesn't cover. The entire world of ransom notes. But yeah. Formatted text. It's going to require parsing. And images. We'd have to use OCR to extract the data. And it's probably. At least for this research. I figured that was out of scope. For what I was trying to accomplish. And then. We're going to stick to files. That are only less than 20 kilobytes. The reasoning for this is. Ransom notes are generally pretty small. Kind of going back to the template. I was discussing earlier. They're not really trying to get across. Too much. They're very utilitarian. Just saying hey file's encrypted. Please send us a ransom. Reducing the problem space there. Keeping it to less than 20 kilobytes. Helps out with performance as well. So we can break down. The framework. Into a couple of components. And just two. Pretty distinct processes. So we'll have a file change event listener. And that's going to read in the events. And place it into a queue. For a second process. Which will do the text extraction. And the actual classification of notes. And then if we determine. That there's a ransom note. There will be a process mitigation handler. That will operate. So here's kind of a high level. Diagram of. How a typical sort of. Infection scenario would play out. With the framework on disk. So you'd have ransomware executing. They drop a ransom note to the Ruby C drive. The event listener is going to be. Polling for events. At that time. They'll see a file creation event. For the ransom note. And then it'll pass along that file path. To text extractor and classifier. Which will read in the contents. Of the ransom note. And then. Do the actual classification. Hopefully return yes. And then that will result in the. Ransomware process being suspended. So for the POC framework. We wanted to build out. A more representative data set. So for the. Ransomware side. We'll still stick with the 20 news groups. But we'll take a smaller slice of it. Instead of the overarching 11,000. And then to supplement that. We'll. Leverage some of the. Windows text files. That I was kind of able to scoop up. So typically talking about log files. Reading files. Any sort of like installer logs. Things along those lines. And then for the ransom notes. Did my best to collect as many. Many more ransom notes. As I could. Ended up finding a bunch on pastebin. And a few other sources. So that was a great source. But still. We're left with only 350. Ransom notes compared to. 11,000. Benign messages. So. For the classification approach here. We want to address a data set imbalance. Which is very. Quite large. So we can use SMOTE. To generate synthetic data for us. And see hopefully if that can bridge the gap for us. And make up for that. Pretty big imbalance. So the approach for the classifier here. We're going to use. Do feature selection via TFIDF. And essentially what we have. Is a. Supervised learning problem. We're going to label the data this time. As either benign. Or a ransom note. And then yeah. We're breaking down. All of this into a binary classification problem. Does the text consist of a ransom note. Or is it benign data. And for us. A naive based classifier. Is simple and straightforward. And that's the approach that we. You know. Went for immediately. And we'll delve into the. The results that we ended up getting. So. High level overview of. Data processing pipeline here. We start with our. Label data set. And we pass that along to the pre-tokenization. Where we're stripping out characters. Converting lowercase things along those lines. We do the actual tokenization. And then we. Get into sanitizing the data a little bit. By stripping out stop words. Anything that's not alphanumeric. And then do lemmatization as I mentioned before. We pass that along. To the TFIDF vectorizer. To vectorize the data. We'll use SMOTE to balance out the data sets. And then we'll do the actual training. With our naive based classifier. So for testing here. We're splitting the. The data. Into a 80-20 split. 80% of the data will be used for training. While 20% will be used for testing. We used train test split. From scikit-learn. To handle that. And just to get into a brief overview. Of the terminology involved. Probably extremely common. And known to most of you guys. But the accuracy score. That I'm going to be referring to here. Is the actual accuracy classification score. F1 score is going to be. Average of the precision and recall. Confusion matrix. Just a great way to represent. True and false positive. And negative rates. And for our cross validation. We're going to use. We're going to use. A Monte Carlo approach. Essentially where we're running. Multiple runs. You know. Through building. And let's see. Training and test data sets. Each sign. In this case. We're just. We're testing out the model's ability. To predict the data. Testing to see. How this approach is going to be flexible. And not try to. Overfit to the data that we're passing. So for our single. One single test here. We actually ended up doing extremely well. Accuracy over 99%. F1 score 91. And you can see from the confusion matrix. Zero false negatives. Which is great. A few false positives. But nothing too crazy. So. You know. That's encouraging. But how does that scale? If that was just an outlier. Or if it's a. You know. Predictor of things to come. And so we ran through cross validation. 10 separate runs. Very good training and test data. And ended up with actually. Very similar results. Accuracy was over 99. And F1 score was over 90. The confusion matrix. Looked about the same. So I think that. You know. The approach to the problem. That we're taking. Just some graph data here. To provide you a better representation. Of what we're looking at. As I said. Not a data scientist. But it's good. So breaking things out. Into the other components. And the framework. With the event listener. We do need to monitor file change events. We're looking at all processes. That are active on a host. In a specific process. And focus specifically. On file creates in our case. There's a few approaches. That you can take. To getting this data. Including. Using Python watcher. But as I said before. The most important thing that we need here. Is we need a. We need the type of file event. We need the type of. Sorry. The process. For the particular event. And we need the file path. So Python watcher in this case. Is based off of the read directory changes API. Windows API that I believe. Doesn't actually return. Any sort of source process data. So in our case. That's not going to help. So alternative approaches to that. You could go through event logs. Or you could write your own file. When you filter your driver. Both of those. Would work. It would take way too much work. That you would want to do for this project. So. For our case here. What I ended up wanting to do. Was leverage something that's going to be prebuilt. And see if I can kind of sift through. Event log data for that. To get our file events. In real time. And so for my case. I was able to leverage Sysmon. If you're not familiar with Sysmon. It's just a tool that's. Used for monitoring. Event data on. On Windows. And so there's a specific. File create event actually. Event ID 11. That's perfect for our purposes. So we don't have to worry about. Distinguishing between different types. Of file change events. We only have one type of event. For us here. It's just create. Very simple configuration file. That I came up with. And then I posted. To the git repository for this project. We're limiting things. Just to .txt files. As I previously mentioned. And just trying to. Sift out other data. So we're not trying to. Crowd the event logs. There's a registry key. That you have to add. In order to properly allow. The event log to be queried. In real time. So that's there. And so basically. What we're trying to do in this case. Is we're going to pull. The event log. And we're going to use. The WMI query language. And we're essentially just going to be. Pulling every 10 milliseconds. In order to try to get updates. Of new file change events. That are coming in. In real time. So we need to limit the size. Of the result set that we're getting. And we're parsing. So that's what the query. Essentially looks like. Pretty self explanatory there. And for the actual. Approach for process mitigation. Very straight forward here. All we need to determine. Is that process. Currently active. With that ID and process name. If it is active. We'll suspend it. And we need to alert the user. That there was this activity on their host. And give them a choice. To close the process. Alright. So we're going to try a live demo here. So let's see what happens. Okay. So I have the framework here. Running in a single Python file. I have process monitors set up. With a couple filters. We're looking at volcano.exe. Volcano is a common ransomware family. And I renamed the executable. To volcano.exe. To make this more simple. And we're going to use. We're just going to. Look strictly at write file events. For a process with that name. So as you can see. No events at the moment. And here is my volcano.exe. And I will execute that. And we get our popup. So it provides us with a specific file path. To the text file. That it determined to be a ransom note. And it went ahead and suspended. Volcano.exe. With that specific PID. And if we go back to here. In process explorer. We can verify. That that process has been suspended. And if we go through here. We can kind of look through. How. You know the progression. Of the ransomware. As it's writing files to disk. Looks like at 540.22. That was the first activity. And. Let's see around 540.25. Is when it was. When the process suspended. And there was no further events. So detection time within. Three seconds or so. But we have to like for our purposes. Actually since we're not keying off. Of any other files. What we're only keying off of. Is the text files. So we can go through the process monitor. And. Sift through the data. And the text files. To get a better idea. Of how long it took for us to. Detect the ransomware. That actually ends with. The file. And so here. What we can see is that. There are multiple ransom notes. That are written to disk. As I mentioned before. Ransomware is typically pretty noisy. With how they're distributing. Ransom notes on disk. So in this case. We actually have. 22 of the same file. That's going to be written out. Well. Actually I think we're only looking. For the ransomware. But that gives you an idea of. Just how noisy the ransomware was. So we still have that process suspended. And we can go ahead. And click terminate. And as we'll see here. The process is done. Okay so getting into. You know some more testing. That I did at the framework. I was able to test. Against nine samples. That were essentially holdouts. Because the ransom notes. Weren't part of our training or test data set. So we were able to. Detect those nine specific samples. From those families. And as well as. Three samples I tested. That already had notes in the training set. From earlier. So in order to get some. You know a better idea. Of how successful this approach is. You know what's currently out there. And so. For our cases. For our case for this. We just wanted to do testing against. Anything that was free or trial based. You know I didn't want to show out any money. For testing here. And we wanted to break it out. For two different tests. Does it detect the sample. And if it does. Can we run it side by side. With the classifier framework. That we just came up with. Or is it just an estimate. Of what the detection speed looks like. There's definitely potential complicating factors. In that. For that particular test case. Because things like driver altitude. Can definitely affect. How the two products. Are running side by side. But you know. Just a way to get a rough idea. Of how the performance. Compares to actual. Stuff that's currently available for download. And so. We did it extremely well. Kept things very generic. I don't want to call out any specific vendors. Or anything like that. But in our case. There was one specific product. That did perform very well. And was typically faster in detection. Than the classifier framework that I developed. And. That being said. The detections. Where product P. Did perform better. The framework was. Still close in performance. And lagged behind. By a couple of seconds or so. But surprisingly. There were two products. That were very easily outperformed. By the classifier framework. And I mean. If you even look at the. A1 and A2. The. While it detects. Pretty much all of the time. For the U12 samples. That we saw. I think this unable to run a test. For one of the samples. But it was outperformed. Nearly all the time. By our framework. And that's actually pretty amazing. Considering the sort of. Ad hoc approach that we took. With sifting through event logs. For data. And then doing all this classification. At run time. And doing it all in Python. Essentially going head to head. With something that's running. Native code. And probably leveraging minifilter driver. To obtain their input. So definitely. Validates the approach that we took. So that being said. Those results are great. But there are definitely limitations. With this approach. There are plenty of ransomware samples. That don't drop .txt ransom notes. Some. Don't even drop notes at all. Some try to convey their ransom message. Just in a. Custom file extension. That they apply to every single file. Some samples. Drop ransom notes. Much later in the game. After all the files have been encrypted. And then there's also samples that. Leverage some sort of persistence. And typically respond. Even if you suspend the process. Terminate it. Whatever. Yeah we might be able to detect it. But it's going to just keep going. Over and over. To deny users. Access to their data. NPR modifications. Anything for raw disk. Or just simple screen markers. And of course as we mentioned. Going in. Or sticking only to English. So future work. We'd like to improve the data sets. Definitely more ransom notes. Less synthetic data. Would be nice as well. As well as new ransom notes. As new ransomware families. That are made aware of. And we'd also like to build out. A more representative 9-text data set. More log files. More installer files. Things of that nature. If we could port our code base. To a lower level language. That would be great. And lead to very significant performance improvements. And we'd be able to. Improve our detection time as well. It would be nice to support. Other file types. For the. As we mentioned before. As well as images. Doing OCR to extract text. Hispanic language support. Would be nice as well. As well as experimenting. With the actual. Approach to the classification. So to wrap things up. Clustering gave us a. Good idea of the data being suitable. For classification. And we saw that. Ransom notes do share enough features. For a solution to be viable. And going into this. We do realize. This isn't going to catch all ransomware. But it could be a very integral piece. Of a layer detection approach. With a static classifier as well. So yeah. The proof of concept did work. But there are definitely many improvements to be made. Alright. Thank you very much.