Our speaker today, we have Brian on generating labeled data from adversary simulations with MITRE ATT&CK. Please give it up for him. Thank you very much for coming so early on Sunday morning. That's awesome. I appreciate you guys coming and listening to this for a little bit. I wanted to talk to you about a couple of things and just give you a little bit of background on how I see this problem set. So the general premise here is that whatever I'm looking at, whether it's bro logs or whatever the problem is that I'm trying to solve, I try to recognize the biases that I have, right? So I looked at this last week. I looked at this last month, that kind of idea. So if I can abstract away some of that bias and have a repeatable methodology, something that's based on math, maybe I can find some insights. And the interesting thing about what I'm talking about today is, for me, it's not theoretical at all. We have an internal red team that's really proficient. Is anyone here from the red team? We have a red team that sometimes will perform some activities based on MITRE ATT&CK. And whether that's DNS exfiltration like we're talking about today or some other technique, they'll hit a canary URL. So think about white box and overt out in the open versus black box. So if you heard of the threat hunting, the hypothesis, you know, I think that there might be DNS exfiltration and therefore you come up with a plan and look for the artifacts. We'll get into that in a minute. But for me, it's not theoretical at all. I know, based on what I saw here, that those guys, my friends that I drink beer and bourbon with. That they ripped us off. They broke in and they stole some stuff on May 18th, 2018. And that was the white box overt time where they hit the canary URL. And I know from patterns, that means that they probably broke in again in a covert black box way. So when we talk about assumed breach, completely not theoretical, whether you believe in that philosophy or not, which I do. You know, I know that these guys that bought me a beer the other night. They're probably sitting on some data that they exfilt. So that's kind of the background that we'll get into here with the threat hunting and how this ties in. But here's the quick agenda. Do a very quick intro. Believe it or not, the MITRE attack, it's going to be real quick. Love MITRE attack. Absolutely do. But I think a lot of CFPs, a lot of cons, a lot of stuff's getting saturated, right? So if anybody wants more information that I'm going to provide in the slides. Here, please come up, I'll talk about it as long as you want to afterwards, but I'm going to trim that down just a little bit because I think everyone's probably heard a lot about it recently. So harvesting labeled training data, we'll get into what I mean by that EDA exploratory data analysis, machine learning, worked example, and I'll talk about just very candidly some challenges that I've run into and a little bit about future work. So before I do that, I just wanted to get a quick sense of what the. The background is in the room. So if we could just start here and we'll go around and tell everybody what you do and name. Okay. Well, how about, could I just see a show of hands? How many people do something like threat hunting? How many people do any kind of data analytics outside of Excel? Awesome. And how many people have some sort of a program where you're doing adversary. Simulation where you've got actual purple team, both folks internal. Okay, cool. Thank you very much. That's a terrible idea. I don't know what I was thinking. All right. So real quickly about me. My name is Brian. I'm a threat hunting lead at a Fortune 100 financial services company. I also help out with the threat intelligence and now security orchestration automation response or sore. But the bottom line for me is that there's one prime directive. It's. Find evil. You know, Rob Lee from Sands talks about no normal. Find evil. I mean, I, I think about this all day, sometimes all night. I hear about that a little bit from my wife sometimes, but she's been very patient with that. It's almost an obsession. So MITRE ATT&CK framework, we're probably mostly familiar with it, but just to level set, it's tactics, techniques, common knowledge. And it's a cure. It's a curated knowledge base and model for cyber adversary behavior, reflecting the various phases of adversaries lifecycle and the platforms they're known to target. So my buddy Zach, the lead red team guy at our place in Milwaukee, we did a talk at Derby Con in 2016. It's a small world. Anybody see that talk in 2016 Derby Con? So we were just talking about very open kimono, very transparent. Here's what we were talking about. We're trying to do with limited resources and budget and everything else, because there's a lot of techniques. Here's what we tried. Here's why we're doing it. And here were the results. So I didn't put the ATT&CK timeline on here, but I know that we have pre-ATT&CK now. But at that point, we were just primarily focusing on the later stages of ATT&CK. So that's the context in which I'm talking about some of these techniques. So in particular, and. We're talking about. Exfiltration over alternative protocol. You know, I didn't blow this up because I wanted to fit everything on there. So you don't need to see what's on there. I will. I will make sure that I have my Twitter handle, which is just at Brian Gens. If anybody wants to watch that, I'll have all these slides up by Tuesday, Tuesday, midnight, Central Daylight Time. So exfiltration over alternative protocol here. I'm focused on DNS. So is anybody think of any tools that you might use for. DNS exfiltration? Go ahead and shout it out. Somebody said iodine. Yeah. Anybody else? Cobalt Strike fans or write your own. So there's a lot of different ways you can do this, right? Interestingly, I don't want to create an overfitted model. Anybody ever see that thing? There was some kind of picture I saw on Twitter from the Bay Area and it was talking about overfitting a model. I can't verify whether this is true or not, but maybe somebody in the back can tell me if you heard about this. Essentially that. A lot of the models were trained on roads. The Tesla's with the self-driving car mode in the Bay Area. And then when they were driving on roads, they were outside of that area. That didn't fit the initial kind of things that was used to. There were five salt lines that were laid down by a salt truck and that that was just messing with that. So if anybody heard about that, cool. If not, it's one example in my mind of how. If I try. To detect my buddies that are breaking in and stealing data, because if I can't detect them, I can't detect somebody else doing it, right? If I focus only on what it looks like with cobalt strike. That's too narrow, right? You use iodine. Maybe I'll catch it. Maybe I won't. So the point is that this is one of many techniques, but it's one that we focused on because we had the instrumentation and the telemetry to dig into. So really for me, all MITRE ATT&CK is, it's a true north. It's a true north where I and we can sit in front of our CISO and executive leadership and say, certainly there are compliance requirements. There are other things that we have to do and boxes that need to be checked. Well, let's focus on what the attackers are doing. They don't have to do something off the menu, on the menu, off the menu. It's up to them. But let's start with known TTPs and tighten up our monitoring and our detection engineering efforts. So I'm not going to spend a lot of time on this. If you follow this stuff, you're probably familiar with Katie Nichols and there's a couple other folks that have that. MITRE's got Caldera. Red Canary's got Atomic Red Team. Uber's got Meta. Endgame's got Red Team Automation. There are varying degrees of what they're offering. They're automating. But it's essentially helping teams. These are open source. Helping teams figure out how to do repeatable processes for adversary simulation. And then Cyber War Dog. Roberto Rodriguez, I think, is at Spectre Ops now and Devon Care, Endgame, right? Had an article that this will be linked to if you want to go to it when I send the slides out. Basically, they were using the API and hooking it in with the API. Basically, letting you dig in and do that. Hang on just a minute. Get some more vodka. Just kidding. And then that talk that we did is online if you want to look at that. So there I was, minding my own business. Red Team's sitting here. I'm sitting on the right. And Red Team is lighting things up. Probably Cobalt Strike at the time. And honestly, I can see them. They hit enter. And they're waiting for something. A callback. And then it starts popping up. I think that they're counting the milliseconds to, boom, okay, I got a callback here. And then they're kind of looking at me like, are your systems lighting up yet? Why aren't you guys hunting for this? Why aren't you guys looking at a ticket from Splunk or whatever sim you use? I look back at it and there were 300 rows that were specifically related to what my buddy Matt and Zach had done. Has anybody heard of? Low-cards exchange principle. So every contact leaves a trace. If a burglar breaks in, it might break a window, might leave some skin, might leave some hair, some kind of sample that law enforcement could use to trace back, get a DNA sample. You know, footprints outside of its muddy. This is what we're trying to do with MITRE ATT&CK. To identify, you know, Chris Sanders, who has the investigation theory course. We brought him in in December to do some training for our folks, and he talks about a triangle, a pyramid he's got of four different kinds of evidence sources, and he breaks it down like network, host, memory, and OSINT, and I want to know what are the digital artifacts that are left when my buddies or somebody else breaks in and steals stuff, and our architecture is not like yours. Your architecture probably isn't exactly like it was six months ago or a year ago, so I think there's a lot of value in seeing what this looks like, and why is everything moving on the screen? Because it's early. I know how this goes. It was slightly amusing to do that because it's parallax, and that's better than PowerPoint animation, so I think that counts. I don't think that's against the rules, but something that moves, you know. So how many people... How many people have heard of EDA, Exploratory Data Analysis? Well, let's start with, and again, don't worry about trying to read the small text here. What I wanted to show is the entirety of this rectangle, which is from Coralite's Brochi sheet, and this is all the DNS log fields, and the type, and the description of that. So in a minute, when we're trying to figure out... How do we represent the knowledge of what we're seeing on the network? How do we represent that and convert it into a feature? Or think of a column in a spreadsheet, right? How do we convert that into a feature that we can kind of hook into, and just in the same way that, you know, maybe you're training a child in some experiment, I don't know, to classify a fork versus a spoon. If none of that's labeled, if you don't know what the... If none of that's labeled, if you don't know what the ground truth is, you're dependent on somebody coming and doing that. Otherwise, all you can do is kind of cluster them based on similarities, right? But the first thing we have to do before we make those decisions is understand what AA is. You know, what does that mean in your environment? You know, protocol, proto, and then there's some other stuff we'll get into in a minute. But when I say ADA, I'm talking about starting with that. Jupyter Notebook used to be IPython Notebook. This is actually from Clarence's book that I've got here. Shameless plug. But I say that because this is from Chapter 2 of one of my new favorite books. Did anybody else buy Data-Driven Security in 2014, like the day it came out? Yeah. This is something I've been digging into, and it's very helpful. And it just reminds me that, you know, there's always something to learn. And I always... I always find it extremely valuable to get somebody else's perspective here. So this is actually from the O'Reilly GitHub. And it's just an example of, you know, we're bringing in some imports, loading the data, and just kind of standard pieces there. Pandas, DataFrame, just to oversimplify if you haven't heard of it before. But you can... I like to think of it visually as an Excel spreadsheet. I'm probably going to have pitchforks and torches after that comment. But I think it's a... It's tabular, so you can think of it right now. But it does much, much more. Has anybody heard of Kitware's Bro Analysis Tools, BAT? So there's a guy named Brian. He's one of the developers there. And I just can't say enough good things about these folks, too. Because I wasn't at BroCon last year. I saw the video that he'd done. And again, there'll be a link in this one at the bottom. And I contacted Brian because I was stuck on something, on his open source code. And I don't like to do that. I don't like to ask people to Google stuff for me to figure something out. I just, you know, a few weeks ago, I was playing around with something. I said, you know, I'll figure this out. I'm just not sure how long it's going to take. And I just sent him my question. And without getting into the details, it was essentially around, why can't I join two of these DataFrames together? And it was because of something on the back end, the way they were doing the preprocessing. With BroAnalysis tools, which they describe as a software bridge. So you can get from Bro to Pandas, and then from Pandas to Scikit-learn, which we'll talk about in a minute. But he appreciated the feedback from somebody kind of in the field, in the trenches, saying, this is what I'm trying to do. And he explained to me what the workaround was, because it was a different data type. So just another great example. People, you know, pitching in the open source community. And, I mean, I sent the dude an email at like 9 or 10 at night, and he responded that night by midnight. So it's really encouraging when you're kind of working through something and somebody else helps you out a little bit. So feature engineering, again, we're trying to figure out what are the things that we can use to categorize something. You know, this is, you could talk about height, diameter, top. So in the same way, we want to find ways to represent. The knowledge to describe what's going on on the network with DNS. And hopefully that's going to allow us to figure out what features we can hook into, and then train a model so we can catch my buddies the next time they break in. Okay. Griffin Data Science Virtual Environment. This is Charles Gibray. He does a class here with Austin Taylor and sometimes with Jay Jacobs from Data Driven Security. Awesome folks. He's got, I don't know if this is accurate, I've always thought of it as the Kali Linux for data science. So I use this. It's pretty decent. And, again, there will be a link there. So I said we're going to do a machine learning worked example. I pulled some stuff out of this. Okay. Okay. I'm going to listen to some of the other talks just because I wanted to make sure that I don't cram some kind of crazy algorithm in and try to show everything that I'm doing. Because, again, I mentioned I'm doing a little bit of orchestration automation. So I want to kind of have that cycle going where I'm getting an internal IP address, you know, going forward, and then enriching that with friendly intelligence or, okay, here's the IP address. Which host grabbed that? Let's assume 24-hour lease for a minute. Okay. Which host? Which internal host name has it? Who's the last logged in user? With that, then go collect some other stuff. The more you can find out and the faster you can find out, feed that back in, there might be a feature or a column that you can compute or some other insight. I'm going to say reputation score. I know it's a terrible example, but some other verifiable piece of information that you can create another column about. And a very fine print in the bottom. I'm being very explicit about giving credit to Charles Gevery because I literally lifted this from his slide. I just made it different colors. So thank you, Charles. There's different descriptions of how this works. I like this from his training class because it's consumable for me. You get and you clean the data. You pre-process, do the feature engineering. Now, some of this stuff, this is naive of me. When I thought bro logs, I'm like, ah, bro logs are pretty structured, right? I'm not going to have a lot of this. No. Because there's a lot of getting it from where it is to where it needs to go, a lot of the data engineering and the pipeline, that kind of stuff. And believe it or not, id.orig underscore h, that's the one I'm going to think of as the source IP. Then initiate that. Just the fact, can anybody think of a problem when you start doing stuff in Python and the label, the field or column name is called dot something? So you're going to throw an error, right? And it's just simple things like that where you'll see that in a few minutes here where we have a column that's renamed. Not a big deal. But I wouldn't have thought that I'd run into that. It's just a different use than maybe we originally thought of for it. But then with the preprocessing feature engineering, bro analysis tools, again, Kitware describes that as an open source software bridge that's going to kind of do some of the behind the scenes heavy lifting. So you can just use it kind of as a gray box and move forward with what you're trying to analyze. And then advanced feature selection. Then we have the data that we're going to split into train and test. And then we'll build the model. We'll evaluate the model. And I tried a couple of different things. So I'll show you a couple of differences. But the main thing that popped into my head when we started talking about this is if I have labeled data, if I can use labeled data when we train that model, now I can move from unsupervised, which is clustering, to supervised. Now we've got. . . I know from the 300 records that are from the DNS exfiltration, from Cobalt Strike or whatever it is. I know what they did and when they did it on May 18th. So I have another column where it's one if it's known malicious and it's zero if it's not. Does that solve everything? No, there's some issues there because what do the attackers and red team want to do? You want to be stealthy? And the better your tradecraft is. The more stealthy you are, the more stealthy you are, and the quieter you are, the fewer artifacts that I have, which leads to something we call class imbalance. And you can correct for that. You can adjust for that. But I kind of wonder sometimes, do I want to? Do I want to make that seem like it's a bigger part of the log data than it really is? So. . . . . I'm importing pandas, and then we just have a as PD. I'm importing NumPy, get in the matrix, and then from bat, bro analysis tools, which he's going to change the name after they change the name at some point. So keep in mind that this will be called something else because bro itself is changing the name of their offering, but import log to DataFrame. And then. A lot of times you'll see DF equals. I just put DNS underscore DF equals, and I'm calling log to DataFrame dot log to DataFrame path to this is one hour's worth of logs. One hour's worth of logs, and then next I see DNS DF dot rename columns. So you see what I was talking about, the ID dot origin. So if you have something dot ID dot origin. You're going to throw an error. And anything I say there's two or three ways you could probably get around that. This is the quickest for me. Filtered DNS. DF. All I'm saying there is the DataFrame. We call the DNS DF. The DataFrame is after the equal sign. So we're saying DNS underscore DF. We're referencing that pandas DataFrame. And then in the square brackets we're saying ID underscore origin. underscore h that's the host that initiated that dns request that string contains and you know i masked this but there is a there is a large subnet that wasn't relevant to this and i won't get into that for opposite reasons of course but the point is you know you might segment that through you might go through and convert the ips to integers you might you know you can do ranges you can do a lot of different stuff with that and i think that's actually covered in the data-driven security book among other places and then i did the type um filtered just to make sure you know after i talked to brian from kitware so i'm kind of leaving myself some breadcrumbs and going through i pulled all the comments out of this just to make it easier to have less on the screen so this is just a nuance but filter dns df dot is copy equals false um it's trying to make it easier to have less on the screen it's trying to be helpful if you don't do that and say hey you keep slicing these things off and you're trying to do things on a copy so i had to google that and it turns out if you just do equals false then it stops throwing those errors it sounds pretty scientific right it worked filter dns df uh query length so here what i'm doing this is the the current version of the data frame or the tabular data frame and i'm going to go ahead and do that and i'm going to go over the data structure that we're dealing with and then i say query length in quotes equals and then i'm saying add a new column and what i want in that column for each row is the data frame and then give me the length of what's in the query so again when you start talking about malicious urls when you start talking about message length and that kind of stuff this might seem a little bit too much but it's not and so i'm going to go ahead and do that like one of the go-to things however I took a bunch of the other stuff off because originally you know when I'm trying to do this in a production environment I want to know for that IP address for that time period or maybe expanded it to longer like 24 hours does that IP address and what does that look like in terms of the con dot log a lot of you I'm sure familiar with con dot log but if you're not I think of con dot log and bro as the closest I'm gonna get to a hundred percent net flow right so basically just the phone record instead of the phone conversation so I'm trying to take an entity based view of this a user 360 and a device 360 and essentially understand what behaviors are being exhibited by that host during that time frame so just real quick aside how many people have heard of Black Hills information security is Rita anybody using Rita I think I've got a link in there I'll make sure it is before I send it out but I've been using that for a while basically you pipe in the bro logs to it you import a bro log for a day and you're a directory full of bro logs for 124 hour period I should be more precise and from there you import it it creates a MongoDB collection and then you run analyze and it's going to tell you beaconing in John strand couple guys did a talk at Derby Khan a couple places they're using some kind of crazy math behind the scenes like fast for you transform and looking at the signals and what you get I just use the command line but they've got a AI Hunter product what you get is basically a table or a CSV and when I cut it out on On the command line, what I see is a score on the left. Yeah, we're 99% sure this thing's beaconing. Well, there's other stuff that looks like beaconing, right? So I don't ever want to have one view into something. I want to have a more holistic approach and enrich these things by either computing new features, add a column, perform an operation on a different column, and now I know something else about that entity in that record. So the next one, 22, in 22, I'm just, you have to put percent matplotlib inline so that you can have the plot actually display in a minute here. And the rest of this is just, in 22, just the formatting for how I want that plot to look. There's a lot of cleaner and more sophisticated looking things. I just wanted to have the basics out there. And then in 23, we're just saying import math, and we're going to look at entropy. So entropy, you might have something along the lines of base 64, base 32 encoded, or you might have some encryption. So either way, I find that to be pretty helpful. Filter DNS, again, we're creating a new column entropy. We're running lambda. So in the data frame, you don't have to do four loops, shouldn't do four loops. You want to, you know, map or apply or use a lambda function, and you're hitting it on that series, which is that column, right? So essentially, very quickly, I'm populating the value of this new column entropy with the results of that mathematical function. And now I know two more things about each of these rows. I know the message length, and I know the entropy. When I look at the length, after I filtered out that other, those segments I didn't need were at 14,000. In 27, do you remember I was talking about that canary URL? It's not actually called canary URL. I did a sophisticated find and replace, and I masked it. That's also scientific. So I'm trying to understand length of all of that inside the parentheses, which means, just to zoom back out for a minute, that my friends on the red team internally have 121 records or DNS message requests or messages that were logged during 8 to 9 a.m. Well, look at that, 121 out of 14,000. That's what I'm talking about in terms of class imbalance. So MITRE ATT&CK, here's one of the ways this fits in. I can help do the detection engineering. I can help look for those artifacts. Every contact leaves a trace. I can help. That will help me dig in and start dissecting things. And I have one goal in mind. I'm trying to protect this house. I'm trying to find how they did the X fill and then see if there's any similarities that I can come up with. And if that works out mathematically, then maybe I can run that against everything else from May 18th until yesterday and see what I find. So, you know, the point is I keyed in on that canary URL, and now I can isolate the traces that they left based on that overt white box attack. And from there, this is a little bit early. You know, I don't really need to add this column just yet, but that's where it was, and I didn't want to mess around with it. Excuse me. So essentially what I'm doing is filter DNSDF. I'm creating a new column called, is malicious. This is my label. I'm going to have essentially it's, if it contains this canary URL, is malicious is going to have a value of one. Notice I did a dot map. It's going to hit everything. The other interesting thing that I saw, has anybody ever seen bro logs with DNS, with DNS X fill, where once in a while you'll see an API dot encrypted string, 200 characters long, and then a post dot. Anybody have any ideas what that is or yeah. Yes, sir. No, I was hoping you'd tell me, man. No. So basically, again, this is a pattern. So I don't know this. That's kind of a Hail Mary when I throw that out there. Normally I'm going to look at the, make sure that these variables aren't related. I'm going to make sure that I look at the feature importance. We're not going to get into, we're not going to get into that right now because of time. Someone hurry up just a little bit. If it has post in it. Now I'm looking for a string, right? So this is the thing about the, the spy versus spy. Anybody in here in the room that sees how I'm doing this, you're going to come up with a different way around it. It's so that's why I have to keep doing this and making sure that the model doesn't degrade. And I don't get lazy in the detection. Here are, we talked about query length. So I just said for the data frame filter D and SDF. And then I want to know about the column that has the values that we computed, which is the query length. So we computed a feature populated the column for each row. And now we have a histogram. So it might be kind of hard to see in the back. I didn't blow this up. There's some different things you can do on the scale here. And that, that visualization didn't look much better, but you see a preponderance. Try to work that one, that word in on a Sunday morning, every possible chance you see a high number over, you know, 14,000, it looks like of DNS requests that are what 25, 30. And then way over there on the right, you see just a few, just a few, I'm guessing like not 120, 21, maybe like 106 or something that are 200. Can you write a signature? Can you write a rule that says, Hey, anything that's got a message length and DNS over 40 is malicious and flag it. What's going to happen when you do that? Yeah, it's going to light up, right? Cause there's, there's stuff that looks like that. Now we computed two things though. We figured out the entropy entropy. You know, what's the degree of randomness and in a moment I'll, I'll show what the ranges are for the values, but in the upper right hand corner, that's weird, right? So we've got, when we look at entropy against query length, something's definitely unique about those. So I'm going to bust through a lot of this short on time. Thank you. I'll get it. Anybody has any questions about this again? I'll have the slides up by Tuesday at Brian Gans on Twitter. I'll put out the link there. I'm going to push through the rest of this. So I said, here are the columns that I want for features. So now I made a new data frame. I said, I may have a new tabular data structure here, but only give me the data that's in these columns series. And that's my new features. Underscore DF. We imported some other things. And again, the scikit learn, we had a software bridge from, bro, the pandas to scikit learn and bro analysis tools. And bro analysis tools is doing a lot of this transformation for us. Again, without us doing adversary simulation, I'm stuck with clustering because I don't have any ground truth labels, right? So where's the evil? Where's Waldo? Where's my buddies, Zach and Matt, anybody have any idea? Which one's malicious? You shouldn't be able to tell. I mean, you might have some ideas, but this is one issue that I run into with just clustering stuff. So with MITRE ATT&CK, I've got a column. It's got one. If it's no malicious, cause my buddy just did it. And there's a zero. If I don't know, right? I don't know that it's. So, you know, what I'm doing here is creating another data frame. And I'm going to push past that. Essentially, I'm going to split that into train and test sets, train the classifier model, make predictions. I'm using logistic regression, not maybe the kind you might think about from stats. And then I'm saying, Hey, predict, you know, how well is this model going to do once we get to the results? And in this case, it was 99.85% accurate. When we look at the model evaluation or model results. But that's not the whole story. Overall, it had in the 2775, you know, we're okay with the top left and the bottom right. The four on the bottom left. That means there were four malicious ones that I told the model that those are malicious. And we, we missed those. So again, it has to do with your threshold and how it works. So again, that's the model we looked at. We need newsflash, right? More signal, less noise. And this is, you know, this is just something that I've come across. If anybody has any other perspectives on it, come see me afterwards. I'd be interested to hear your perspective. But I just think that the more stealthy attackers are, the fewer footprints, the fewer contacts are going to leave, which makes it harder for me to hook into something. Future work, I'll just push through that. But like I said, looking at other bro logs, I want to generate some features based on the presence or absence of beaconing. So take the insight that I'm getting out of Rita from Black Hills Information Security, your offensive countermeasures now, and enrich that and then do some other things. Some other enriching IP addresses. Also very excited to look at some Neo4j and some graph history stuff as well. So thank you very much for coming out on a Sunday morning. I appreciate your time. I'll be in the back and I hope you have a great rest of the conference.