[00:00.000 --> 00:07.860] All right. Good afternoon, everyone. And it is 1.30 Pacific time in beautiful Las Vegas, [00:07.860 --> 00:17.320] Nevada. Thank you so much for joining us today. And this next talk is sponsored by the Packet [00:17.320 --> 00:23.300] Hacking Village. And it is my absolute pleasure to introduce to you Josh Piore. [00:23.900 --> 00:33.980] Thank you. All right. So that's me. I work with Cisco Talos. Previously I worked with Zscaler, [00:33.980 --> 00:40.160] Umbrella, OpenDNS, NASA, and Mandiant and some other places and nonprofits and whatnot. So I do [00:40.160 --> 00:47.760] security research and I make music and do a bunch of other stuff. So before I get into all the [00:47.760 --> 00:53.180] details, I'm going to talk about what I want to focus on when I'm doing this kind of thing. I'm [00:53.180 --> 00:57.260] going to talk about the infection chain real quick. And it's probably very familiar to you. So [00:57.260 --> 01:01.940] hopefully I'm not going to bore everyone, but I'll just continue on. So looking at attribution, [01:01.940 --> 01:05.120] when you're looking for something, I spent most of my time as a threat hunter. When you're [01:05.120 --> 01:12.200] looking for something, you're following one thing that you see. So maybe I found a domain or a [01:12.200 --> 01:18.240] URL. In this case, I found this one at urlhouse.abuse.ch. And then I can see as part of [01:18.240 --> 01:21.200] Emotet, a lot of the samples I'm using are kind of some old samples for the moment. I have some [01:21.200 --> 01:26.600] newer stuff later on. But this is part of Emotet, part of the Epoch 4. There are various epochs, [01:26.600 --> 01:34.520] various evolutions. If I look at that in like VirusTotal, I can find a hash that's associated [01:34.520 --> 01:42.520] with this URL. And then I can follow that trail, looking for more hashes. VirusTotal makes this [01:42.520 --> 01:48.020] very easy. I can then keep on going and getting more and more attribution, finding more of this [01:49.080 --> 01:54.920] particular variation of Emotet. Maybe it's today's variant or this week's variant. I can copy [01:54.920 --> 01:59.120] the hash for that file and I can go in multiple different directions, take that to another [01:59.740 --> 02:08.040] interface and find additional things. Keep on looking, basically ending up at finding a whole [02:08.040 --> 02:12.020] bunch of different URLs. So as a threat hunter, I would do this to like find additional [02:12.020 --> 02:18.340] compromised URLs. In this case, a bunch of WordPress URLs that are dropping this specific [02:18.820 --> 02:25.020] version of Emotet at the time. Maybe I have another example, just to give you another example. [02:25.160 --> 02:31.980] I go to any.run, which is a malware sandbox that you can go to, and I grab something. I see a [02:31.980 --> 02:36.240] URL that's at this IP address. And I grab that IP address, go look for it in another place and [02:36.240 --> 02:42.480] get some hashes and get more information. Keep building up my thing. You have to know when to [02:42.480 --> 02:47.260] quit, of course, but keep building. And eventually you can do something like you can map it [02:47.260 --> 02:54.220] all together, following host infrastructure, finding what these specific threat actors are using [02:54.220 --> 02:59.720] to make their malware do what it does. But there's always patterns, as we all know, like when [02:59.720 --> 03:04.400] you look at binary analysis or anything like that, there's certain variable names that are the [03:04.400 --> 03:11.560] same because it's difficult to change your habits as anything in the world. There's a framework [03:11.560 --> 03:16.240] for this, you probably all know about it, minor attack framework to attribute various tools, [03:16.240 --> 03:22.400] tactics, procedures to things and to groups like APT29, which is a threat group and it's, you [03:22.400 --> 03:27.300] know if something belongs to them because it follows these certain procedures. They use certain [03:27.300 --> 03:31.620] techniques, you can track everything with this. It's nice, it's a little hard to automate, but [03:31.620 --> 03:36.440] it's nice. There's books about this kind of thing, this is a great book about this, I actually [03:36.440 --> 03:42.180] bought it at Defcon a few years ago. But there are levels of attribution. When I worked in the [03:42.180 --> 03:46.340] government, we were very interested in threat actors, like what threat actor is responsible for [03:46.340 --> 03:51.120] this thing and APT was the word of the day every single day, so. We were interested in [03:51.120 --> 03:56.460] individuals, other governments, the state sponsored stuff. In some cases, many places, I'm [03:56.460 --> 04:01.800] interested in campaigns, so what is the malware campaign that I'm looking at, is it Emotet or is [04:01.800 --> 04:08.760] it something like a remote access Trojan or is it ransomware or whatever. And then in most [04:08.760 --> 04:11.940] cases, like small environments, you just want to know what's inside your network, if that's your [04:11.940 --> 04:18.120] attribution level. So I'm going to talk briefly about the infection chain because it doesn't [04:18.120 --> 04:23.140] change much, just like the behaviors of all these things don't change much, making it possible to [04:23.140 --> 04:28.400] track them. Using Emotet again, it's just so easy to use and I like to make fun of it. It usually [04:28.400 --> 04:33.560] comes in via an email and then you get a link to something or an attachment to something, leads to [04:33.560 --> 04:39.500] OfficeDock with macros, PowerShell, more macros, it'll install additional components, then the C2 [04:39.500 --> 04:45.240] stuff, back then, I mean, it would lead to Cobalt Strike, but maybe it leads to remote access [04:45.240 --> 04:50.820] Trojan. This is just Emotet, but this is kind of a pattern with most things. The easiest way to [04:50.820 --> 04:55.440] compromise is, you know, get the user via some kind of email dropper or link to something or [04:55.440 --> 05:04.400] drive-by download. Usually, oh, let's see, I forgot that I made this segmented, but I just went [05:04.400 --> 05:10.080] over that. So another one, QuackBot, same kind of thing, but a little bit more complex, maybe to [05:10.080 --> 05:14.760] make it seem more authentic. Usually they get an email, which has a link, which leads to a [05:14.760 --> 05:20.840] password-protected zip file, they possibly open that file, and then they have an ISO, and they're [05:20.840 --> 05:24.580] like, what do I do with this? They open that, there's a Windows shortcut, downloads things, and [05:24.580 --> 05:32.000] then it does what it does after that. And typically you see that get request in over HTTP, maybe you [05:32.000 --> 05:37.140] see it more these days over SSL, but often you'll see it over HTTP, and then SSL traffic starts [05:37.140 --> 05:42.380] after that. When you're detecting this kind of stuff, it's harder where you get to the SSL, but [05:42.380 --> 05:47.460] I'm going to talk about that too. The problem that I'm addressing here is how do we find bad [05:47.460 --> 05:51.820] things in the network? How do we get the attribution of what's inside our environment without [05:51.820 --> 06:01.520] knowing too much? So this is just my home network, I'm just capturing stuff on a capture device. It's [06:01.520 --> 06:04.800] not very busy, but I mean, of course, networks are way busier than this, but how do you find [06:04.800 --> 06:10.240] something like this? This is just a super simple example of like a post over clear text of someone [06:10.240 --> 06:14.960] putting a username and password into a compromised WordPress site. How do you find that inside [06:14.960 --> 06:20.920] that? There are ways, obviously, we know about this, I'm sure. Intrusion detection and Yara, I'm [06:20.920 --> 06:26.340] going to talk about these. So IDS rules, this is kind of a crazy slide, but at the very top, if [06:26.340 --> 06:31.700] you're familiar with this, is an IDS rule, I'm using Emotet, it would capture what you see in [06:31.700 --> 06:35.940] this PCAP, it's going to look for things like the content being the post, it's going to look for a [06:35.940 --> 06:42.880] specific kind of post content, maybe it's looking for the user agent or some other data. And when I [06:42.880 --> 06:46.660] run this, like if I run a PCAP or I run that malware in my, when I ran it in my home [06:46.660 --> 06:52.780] environment, I triggered six alert fires through Suricata reading this rule. So there's really [06:52.780 --> 06:58.180] easy detection mechanisms for certain things. Of course, as with most things, you have to know [06:58.180 --> 07:02.800] what you're looking for. You have to have already seen it in many cases. Yara rules are typically [07:02.800 --> 07:08.360] not thought of as a streaming detection mechanism. I mean, they can be used in such a way. We use [07:08.360 --> 07:15.600] them at my work like that. But they're typically for finding strings or data in binary analysis, [07:15.600 --> 07:21.020] you can look for stuff in HTTP text and JavaScript. So it's not really thought of as a thing you can [07:21.020 --> 07:26.780] use for PCAPs or net streaming network traffic. But I did find that someone wrote a tool called [07:26.780 --> 07:31.360] Yara PCAP, I took that and I modified it, my code is going to be at the very end of this, I have a [07:31.360 --> 07:36.280] link to it. But I modified that to include it as a proof of concept if you want to play with it. So [07:36.280 --> 07:44.820] you can upload a PCAP and test it. How it works with the Yara PCAP thing is you write a Yara rule, [07:44.820 --> 07:49.760] like based off this IDS rule that I had before, it becomes really simple, much easier to read. I'm [07:49.760 --> 07:56.140] looking for a post for the user agent, certain kind of content, the refer information, and then [07:56.140 --> 08:00.780] I want to get all those things when it sees them, it triggers. So if you look at my web app that I [08:00.780 --> 08:08.680] built, you browse to something, I pull up like a test Yara, I can see that I get these two alerts, [08:08.680 --> 08:17.280] basically. So it's possible to capture stuff over network with Yara as a detection mechanism. [08:18.220 --> 08:25.160] There's just a view of it. There are some obstacles here. I'm going to talk about a lot of [08:25.160 --> 08:33.320] obstacles. Visibility, SSL, I briefly touched on this. Going back to that infection chain, [08:33.320 --> 08:37.060] usually you get an email, and that's going to be one endpoint detection, you're looking at your [08:37.060 --> 08:42.300] email detection, so hopefully you have something that's watching your email. You maybe have a [08:42.300 --> 08:48.360] going to get that link over HTTP, or you have an attachment already in the email, so, I mean, [08:48.360 --> 08:52.620] you hopefully detected it in the email. And then your endpoint detection is hopefully catching [08:52.620 --> 08:57.820] that office doc with all the macros and seeing PowerShell running and stopping it. [08:58.580 --> 09:02.880] Then installing additional components is probably going to be over SSL, you're probably not going to [09:02.880 --> 09:08.720] know that's something weird is happening, except for the endpoint that it's connecting to, if [09:08.720 --> 09:12.440] you're monitoring that, or if you're looking at DNS, you can also get some information from that, [09:12.440 --> 09:18.580] too. And the C2 is usually going to be SSL as well, and beyond. Remote access Trojan traffic, [09:18.580 --> 09:23.980] and when they drop ransomware on there, you don't have visibility into the whole [09:23.980 --> 09:30.980] thing like you did maybe 15 years ago. And here's an example, like iced ID dropper, [09:30.980 --> 09:38.160] you get it over HTTP, and then traffic starts right afterwards with SSL. So you can capture [09:38.160 --> 09:44.700] that HTTP and maybe the SSL with some kind of magical behavioral analysis, or in some cases, [09:44.700 --> 09:49.800] stuff I'm showing you kind of catches it sometimes. There are solutions for this. When I [09:49.800 --> 09:55.220] give talks, I don't do vendor talks usually, so I try to talk about free things. I think Proxifier [09:55.220 --> 10:01.680] has a fee, but enterprises like my company and other companies offer solutions to man the middle [10:01.680 --> 10:06.820] of your SSL traffic, you have to install something on the clients, so you can intercept that stuff [10:06.820 --> 10:12.300] for better detection. But you can also do it for free. So is this possible, this thing I'm talking [10:12.300 --> 10:17.920] about here? Well, let's find out. I had this idea from a talk I gave a long, long time ago, [10:17.920 --> 10:23.940] I was looking at, these are really old samples. These are, okay, I'm not a data scientist, so [10:23.940 --> 10:29.720] ignore the numbers on the left. I was plotting the time, plotting when things were happening [10:29.720 --> 10:34.540] with a sample, like over the network. When does it make a GET or a PORT request, or when's the SYN, [10:34.540 --> 10:38.960] SYNACK, et cetera. And it's a whole bunch of samples. And I've seen there's a relationship [10:39.420 --> 10:44.860] between these samples, but I don't know, maybe not. Then I looked at Emotet samples, [10:44.860 --> 10:52.320] it's different than Hansitor, it's different. And they're related, by the way, but they're, [10:52.320 --> 10:56.440] the traffic stuff is different. And then we look at TrickBot, same kind of thing, they're related [10:56.440 --> 11:00.160] to each other, very different from Hansitor and Emotet. I'm not going to show you more examples [11:00.160 --> 11:04.460] of malware, but I was like, maybe there's an idea here of something I could explore. [11:05.100 --> 11:10.580] So let's talk about finding some patterns and show, like, some examples. I'll use dropper [11:10.580 --> 11:15.100] downloads, so when you first get that dropper, beaconing out, and we'll have a little bit of SSL [11:15.100 --> 11:18.980] in there, and then benign versus malicious, because in many cases I'm wondering, is this [11:18.980 --> 11:23.500] just how networking works, the way that I'm doing this? Or is it bandwidth that's causing issues, [11:23.500 --> 11:28.980] or not causing issues? Looking at dropper downloads first, I'll take two separatized [11:28.980 --> 11:34.440] ID downloads, I'm getting these requests, I've got almost double the transactions on the top one [11:34.440 --> 11:41.860] than the bottom one, and the download is basically the same. So these, they look different, but in [11:41.860 --> 11:48.620] terms of how many transactions happen. I'll look at the timing in between these, like, so when a [11:48.620 --> 11:52.020] transaction happens, then the next transaction, and what's the timing between that? And that's [11:52.020 --> 11:56.940] what I'm going to be focusing on mostly in this talk. And despite the difference in transactions, [11:56.940 --> 12:02.020] I'm seeing that there's a sort of a pattern, just, you know, just using my meat brain. I've [12:02.020 --> 12:09.260] got a big time, and a small one, larger, small, really big, smaller, etc. So I'm seeing a pattern, [12:09.260 --> 12:15.580] I'm wondering, is this something I can work with? Let's look at beaconing. This is over SSL, [12:15.580 --> 12:22.900] cobalt strike, beaconing, two samples. Is this even, am I going to see the kind of same results, [12:22.900 --> 12:25.840] or is this just how networking works? This is what I'm always asking myself, is this [12:26.420 --> 12:31.580] stuff I don't know about? I look at it, I'm kind of seeing the same patterns where I get that big [12:31.580 --> 12:36.980] one and the small one, so it's still maybe, maybe it's just how it works. I do Emotet and Trickbot [12:36.980 --> 12:43.820] beacons, same kind of thing. So I need to find something to show me a difference. I need two [12:43.820 --> 12:49.180] samples that are alike, and I want to know if they behave differently. So benign versus malicious. [12:49.620 --> 12:54.320] I downloaded this thing called existential.exe, I found it when I was looking for a benign exe [12:54.320 --> 13:00.500] file. Someone wrote it to look like a malicious dropper download, which is usually pretty small. [13:00.840 --> 13:04.880] You can see I get it, and I'm getting it from some site, a domain that I own. [13:05.560 --> 13:10.280] And then I compared it with a malicious dropper download. I don't remember the malicious dropper, [13:10.280 --> 13:15.060] but I'm seeing there are some similarities, but it's starting to be different enough that [13:15.060 --> 13:19.720] I decided to explore further. So let's talk about the processes that I'm going to play with [13:19.720 --> 13:25.780] and use in this. I'm going to talk about averages, Levenstein distance, and some fuzziness. [13:26.360 --> 13:33.600] There's some challenges. Again, finding the parts that I'm interested in. If you have [13:34.300 --> 13:39.800] network traffic, how do you find the bad stuff? I have malware analysis sandboxes at home, [13:39.800 --> 13:45.300] we have them at work, we have them all available to us for free. So you can find this stuff. But [13:45.300 --> 13:51.520] if you have a PCAP full of stuff, how do you find it? And there's always flows in a huge PCAP [13:51.520 --> 13:54.980] file. These are the connections between all the different servers, or maybe you just do one [13:54.980 --> 13:59.900] machine in all the places it connects to. So how do you separate all these flows in an efficient [13:59.900 --> 14:05.860] manner and then operate on them? There are, as I mentioned, there are places we can go get stuff. [14:05.860 --> 14:09.580] I'm going to use a lot of examples from malware traffic analysis for the Austin site. You can [14:09.580 --> 14:15.560] download an exact, like almost a carved PCAP, sometimes there's extra data in there, but of [14:15.560 --> 14:19.520] malicious stuff. And I'm going to use that for what I'm going to build signatures out of. [14:20.460 --> 14:24.060] So once I have a viable PCAP, like I downloaded from malware traffic analysis, [14:26.440 --> 14:30.940] like I'm going to use this ICED ID with Cobalt Strike, it's old, but... [14:30.940 --> 14:35.560] Oh wait, I figured something out. Oh yeah, once I have a viable PCAP, I can use that. So [14:36.020 --> 14:39.900] I'll play with the detection ideas. I'll play with the averages and I'm going to look at [14:39.900 --> 14:44.620] co-integration. And once again, I'm not a data scientist. I'm going to talk about co-integration [14:44.620 --> 14:48.820] and I might mess it up a little bit, but I know how to make it work in the thing, sort of. So [14:49.820 --> 14:56.100] averages first. When I look at an isolated trick bot post from that viable PCAP that I download, [14:56.100 --> 15:02.780] I've got 840 queries. I'll take the queries in between the transactions and I'll put them in a [15:02.780 --> 15:07.160] big list. And this is basically the entire PCAP in terms of time from the very beginning to the [15:07.160 --> 15:12.600] end from when it runs. And then I'll find the average. So I'll add them together and I'll [15:12.600 --> 15:19.160] divide them and get the average number. So average time between is 12,748 for this one PCAP. [15:19.320 --> 15:25.340] And then take another one. I've got a different set of queries. Do the same thing. And I've got [15:25.340 --> 15:32.520] these averages that on their own don't look that similar. The number is 14,748 and 16,125 [15:33.000 --> 15:37.220] different. But I need to compare it to other stuff to see how related they might be to each other. [15:37.480 --> 15:43.620] So I'll compare this against some random traffic. I take a random PCAP just with stuff in it. And [15:43.620 --> 15:48.600] it's got 779 queries and I'm also taking one flow from that random traffic just to [15:48.600 --> 15:54.160] add another thing. Just 32 queries. So it's not that much data. And when I look at it in [15:54.160 --> 15:57.900] this context, I'm seeing that there's a little bit more of a relationship between them. And if [15:57.900 --> 16:01.800] I scale this, I'm seeing even more of a relationship between them. I don't have that as an [16:01.800 --> 16:08.880] example. So I'm feeling like I can continue on and explore this further. [16:09.300 --> 16:14.260] I'm going to talk about cointegration as another method. So cointegration as described is usually [16:14.760 --> 16:18.480] a drunk guy and a dog are walking. They're walking together. So they're co-occurring [16:18.480 --> 16:23.840] with each other. But are they actually together? So there's this model to run it against them. [16:23.840 --> 16:28.740] They start to move in a different direction. You can see that they co-occur, but they didn't [16:28.740 --> 16:32.680] co-integrate. They're not actually together. They're just doing their own thing. Basically [16:32.680 --> 16:40.500] like that. And some little parts to describe it when I show some graphs. P-value is the [16:40.500 --> 16:46.020] probability that the relationship between those series is due to chance. And then there's a [16:46.020 --> 16:51.300] spread, which is the difference between the two actually co-integrated time series to show how [16:51.300 --> 16:56.960] far they deviate from their long-term relationship with each other. Just some examples like Russia, [16:56.960 --> 17:05.600] Ukraine searches on Google. On the spread, they were together and they separated away from the [17:05.600 --> 17:09.860] spread, but they did it at the same time. So they're co-integrated and they stay together [17:09.860 --> 17:14.740] basically. These are co-integrated, co-occurring things happen at the same time. Twitter and Elon [17:14.740 --> 17:20.260] Musk around that time, I think that's around when he took it over. So they don't really... [17:20.800 --> 17:24.980] they're way off the spread. The timelines don't match up, but they come together right at the [17:24.980 --> 17:29.440] same time to zero on the spread right there. So there was a relationship because everyone's like, [17:29.440 --> 17:34.360] oh, what's going on with this? And they're Googling it or whatever. And then 5G and COVID, I just had [17:34.360 --> 17:38.540] to put this in here because people were searching it. They matched, stayed on the spread all the [17:38.540 --> 17:47.220] time, and then they both searched at the same time. Annoying. The people... whatever. So two [17:47.220 --> 17:51.720] identical PCAP files. If I take the same exact ones, they're going to definitely co-integrate. [17:53.200 --> 17:57.820] Just as a test to see if I could do it, I guess you don't. And you've got... I put a scatterplot [17:57.820 --> 18:02.320] here. The little numbers on the bottom are the times, the milliseconds. And they're on top of [18:02.320 --> 18:05.560] each other. There's a blue value underneath the orange value. Of course, they're identical. And [18:05.560 --> 18:10.860] the P value, which you want to be between zero and one, it's the probability value. They match [18:10.860 --> 18:15.100] exactly. So I want to try two different PCAP files. Doesn't matter what they are, if they're [18:15.100 --> 18:20.940] malware or not. They won't co-integrate, though. And they don't. The P value for file one is [18:21.620 --> 18:27.620] way off. And the scatterplot is just a mess. And I'm starting to think there may be some [18:27.620 --> 18:32.200] problems with co-integration. But there's maybe also a method to start finding similarities. [18:32.680 --> 18:39.660] I'll try two different PCAP files with similar traffic. So these are benign. One to [18:40.260 --> 18:46.620] DigiCert and one to Windows Update. Just some get requests. When I map them, I've got a seconds [18:46.620 --> 18:50.400] marker. I'm using seconds here. And most of this stuff, I'm going to use microseconds. And I'll [18:50.400 --> 18:56.860] mention this in a second. But at 48 seconds, then 50 seconds, then 53 seconds, then zero. And that [18:56.860 --> 19:01.980] other one, at 38 seconds, at 46, rolling through time as we go forward. And the number of [19:01.980 --> 19:07.140] transactions at those seconds. When I map them, I get similar P values, because they're kind of [19:07.140 --> 19:12.560] similar. The timing difference is a little bit off, because one started later, one started earlier. [19:13.420 --> 19:19.300] There are some problems, as I mentioned, with co-integration. Like the time value. I've got [19:19.300 --> 19:23.400] this one and I've got this other one that has a huge one. I'm going to get a scatterplot or data [19:23.400 --> 19:27.780] that the second one is going to far exceed the other one. They aren't going to match up the way [19:27.780 --> 19:34.340] I want them to. Even if I'm doing individual flows compared against each other. As you can see, [19:34.340 --> 19:39.160] that's what I did here. I forgot that I put the slide here. But the orange one keeps on going. [19:39.180 --> 19:46.280] The P values are different. So short sample size. In many cases, a flow will be very minimal. So [19:46.280 --> 19:52.380] I'm going to get something where I can't do anything with it. So let me talk about time [19:52.380 --> 19:59.260] resolution. I just briefly mentioned I talk about this. You have to decide how much time you want [19:59.260 --> 20:02.940] to work with. At the minutes resolution, you're not going to get much data. It's going to be [20:02.940 --> 20:08.960] spread out one per minute. Or all your transactions in a minute. The seconds, you're going to get [20:08.960 --> 20:12.620] some data, but it's not going to be useful. Microseconds, you get a lot more data. So I'm [20:12.620 --> 20:18.260] going to work with microseconds. Also normalization. Because things aren't starting at the same time, [20:18.260 --> 20:23.560] I want them to start at the same time. So I decided to make all PCAPs or any network transactions, [20:23.560 --> 20:28.800] I throw through this to start at January 1st, 2000, just to get them to line up. [20:30.520 --> 20:34.680] And this just sort of shows that. I don't have to really describe it, but they show [20:34.680 --> 20:38.460] how they all start at the same time. Now, talking about signatures and [20:38.460 --> 20:41.040] detection, where it's getting a little more interesting, where I'm starting to play with [20:41.040 --> 20:45.180] actually building the signatures. I want to separate the flows first. I'm going to calculate [20:45.560 --> 20:48.440] percentages. I'm going to do distance, and I'm going to do fuzziness. And I'll involve [20:48.440 --> 20:52.780] Levenstein distance and other things. So first step to separate these flows, [20:52.780 --> 20:56.660] as I showed before, it's a lot of flows inside network data. And if you're running this [20:56.660 --> 21:06.200] with Daemon logger or TCP dump, writing a packet capture to file on your logging systems, [21:06.200 --> 21:09.980] and then you're going to have tons of data, and then you have to separate those flows. [21:10.000 --> 21:13.540] So I'm going to operate against each flow individually. This is computationally [21:14.720 --> 21:18.980] intense. So in my code, I've made it so it's multiprocessing. At least there's that. [21:19.140 --> 21:23.860] So when I run it, it'll just use whatever processing power you have. I'm using it on [21:23.860 --> 21:31.200] this laptop, and it's pretty fast for a fairly large file. And so once I operate that, I get [21:31.200 --> 21:34.880] the average time between queries and the total queries, and I also get some other data. I added [21:34.880 --> 21:38.880] more after this point. And then I'm going to calculate percentages, because I'm ending up [21:38.880 --> 21:46.400] with these times and these averages, and it's kind of messy. I want it to be smaller. I'm [21:46.400 --> 21:50.760] ultimately working towards a goal of building a small list of numbers that I can make into a [21:51.360 --> 22:00.640] So when I take those frequencies, those numbers and the times in between, and I say this time is [22:00.640 --> 22:05.880] what percentage of the entire PCAP, I do that for the whole thing. There's a lot of zeros, [22:05.880 --> 22:10.920] and then there's a lot of times where it doesn't. Theoretically, this whole list should equal 100. [22:11.080 --> 22:15.820] I do some stuff to it, and it doesn't quite equal 100 after I deal with it. [22:15.820 --> 22:20.600] But if I look at just a quick look at just this raw percentage data, I'm kind of seeing the same [22:21.460 --> 22:26.640] traffic patterns between PCAPs. I add a little chaos. Like I said, I do some stuff to it. [22:26.700 --> 22:32.680] I take away those zeros. I round things. This, you add it up, it won't equal 100, [22:32.680 --> 22:36.780] but it's because I did stuff to it. But it's all in my code, which you can see. [22:38.480 --> 22:42.000] Basically, what I'm ending up with is something like this, where I have this list of numbers, [22:42.000 --> 22:46.880] and I'm thinking, well, this is... okay, this is something. It represents the time of a transaction. [22:47.420 --> 22:52.160] So we can find exact matches, like the exact same thing in other PCAP data. And that's [22:52.820 --> 22:58.500] nice, but I'm looking for variations of malware. Like when the new variant of [22:59.040 --> 23:04.580] today's hot malware drops because the last one was burned, how do we find it? [23:06.300 --> 23:11.140] So I look at percentages and distances. I talked about Levenstein distance, and let me go into [23:11.140 --> 23:16.120] that a little bit more. Levenstein distance, if you don't know, it's usually used on string data. [23:17.820 --> 23:22.960] And if you want to know how far away the word kitten is from sitting, you place that K with an [23:22.960 --> 23:27.260] S, that's one distance. You place the E with an I, that's a second distance. You add a G, [23:27.260 --> 23:33.500] that's a third distance. So it's three distance from each other. And I was thinking maybe I could [23:33.500 --> 23:39.620] use this even on small bits of data and treat those numbers not like integers, but like strings. [23:41.000 --> 23:48.160] So if we remember, I want to find this behavior, this little bad thing in this whatever thing. [23:48.940 --> 23:54.140] So I'll create my signature, which looks like this. And it doesn't look that valuable. It's [23:54.240 --> 24:03.560] a bunch of ones and twos and that one. And when I run it on something using Levenstein distance, [24:03.560 --> 24:08.320] I get a number at the very end. That number going up to 100 equals the probability that I'm finding [24:08.320 --> 24:16.140] inside a flow something that matches. But I can see there's a lot of like 58, 67. There's one [24:16.140 --> 24:20.040] that's 100. That's the one I made my signature from. So of course it matches because it's exactly [24:20.040 --> 24:26.520] identical. So I'm starting to get somewhere where I can maybe be a little looser in my searching. [24:27.660 --> 24:31.760] I'm just looking at that PCAP and seeing that's the thing I made a signature from. [24:32.160 --> 24:35.160] But I need to be fuzzier with it. I need to get a little bit looser. [24:36.440 --> 24:40.740] There was something that was called Fuzzy Wuzzy, which is so cool, but it's the fuzz now. [24:40.800 --> 24:47.080] So I'm using this to apply a different threshold based on the Levenstein distance. [24:47.260 --> 24:52.140] When I run this, I'm going to get another number that's been modified. It still has the 100 for [24:52.140 --> 24:58.940] the signature match, but it has other numbers that I'm interested in, like the 75, 67. [24:59.820 --> 25:05.500] What are these numbers and what do they represent? So I can't remember if I opened the PCAP in this [25:05.500 --> 25:13.190] one. Let's see. I did not. So the signature made from this flow, as pointed out before, [25:13.190 --> 25:17.810] got these two other ones I'm interested in. If I look at one of them, I get an exact match. [25:18.310 --> 25:24.650] If I look at another one, it's an exact match. So that's interesting. I have no match on 67, [25:24.650 --> 25:28.830] so maybe there's a number I can pick that is my magical number that's going to find this [25:28.830 --> 25:33.670] all of the time. There's some tuning involved, because different malware campaigns are different [25:33.670 --> 25:37.890] with each other. I'll talk about this in the future work I'm going to work on, but [25:37.890 --> 25:44.110] just showing tuning. I'm sorry to show you code, but basically I'm looking, as kind of described [25:44.110 --> 25:50.330] already, the partial ratio is greater than my threshold. That partial ratio is from the fuzz [25:50.330 --> 25:54.070] thing, and Levenstein distance is less than my Levenstein threshold. So I'm working with these [25:54.070 --> 25:58.330] two variables, and I just have to tune them depending on what I'm working with. [25:59.750 --> 26:04.490] And I can set that, you know, at the very top of my code. This is all in the README on the GitHub. [26:06.050 --> 26:15.250] So if I go get two things, Darkgate activity, I downloaded one from 11-30-2023 and 12-7-2023. [26:15.250 --> 26:20.910] I don't think I could find... I wasn't able to find newer stuff than that, just like last week. But [26:24.590 --> 26:30.190] what I'm going to do is I'm going to carve out the bit I'm interested in from the 11-30 one [26:30.190 --> 26:42.150] first. Let me scroll down here to post. So I'm finding this information here, this post that's [26:42.150 --> 26:48.210] suspicious, and we know it's bad. And I'm going to save this to create a signature out of it. [26:48.210 --> 26:54.630] So I'm just exporting just the displayed packets, saving it as Darkgate post, and then [26:57.330 --> 26:59.850] just showing you what it looks like. It has no other flows in it, [26:59.850 --> 27:04.970] just this one flow between these two servers. And then I'm going to upload this to create a [27:04.970 --> 27:12.470] signature. And when I upload it, it creates a really simple... like, there's three numbers. [27:12.470 --> 27:15.750] It doesn't seem like I can do much with that. But I'll show you. [27:16.770 --> 27:25.290] And then when I go and I upload the same file, I want to see... I'm tuning it right now. So [27:25.290 --> 27:33.720] I'm getting a match, of course, on my exact match. But if I look at some of the other ones [27:33.720 --> 27:39.120] below it, I'm going to see some other additional matches here. So it's not quite tuned yet. I've [27:39.120 --> 27:44.000] got 11 sign distance of four, my ratio is 75%. I click on the very top one, which is the most [27:44.000 --> 27:51.520] matchy that didn't match. It's the same one. I continue down the list and maybe go to 67% [27:54.100 --> 28:00.020] distance of four on 11 sign. And I've got another match here. So I've obviously got to fix [28:00.020 --> 28:04.640] the thresholds I'm working with. I look at 64%. Let's see what this is. [28:08.100 --> 28:12.860] And in this case, I'm not getting a match. So I'm starting to find the numbers I can work with. [28:17.800 --> 28:25.960] Now, I look at this one, 67%. It's a match. And so between 67 and 64 is where I want to be. 11 [28:25.960 --> 28:31.140] sign, five or four, somewhere on there. And so I just want to adjust those values and play with [28:31.140 --> 28:36.480] it. Then we'll try this again. So I've unfortunately got to see me carve out that part again. I'm going [28:36.480 --> 28:39.280] to carve out a little bit different part. So it's going to create a slightly different signature. [28:41.040 --> 28:50.120] And I think I ran it on... I think I ran it on the same one. Sorry. And I'm seeing my don't [28:50.120 --> 28:54.600] matches don't match and my matches match. So I've got this tuned and I can start applying [28:54.600 --> 29:00.120] it to other things. So now I'm going to upload the newest signature from 12.7. This is a later [29:00.120 --> 29:06.680] PCAP different version, basically. And I'm looking at my matches. I'm getting similar, [29:06.680 --> 29:11.380] different things happening in there. Same kind of post to a different server, [29:12.920 --> 29:22.560] basically. And the... I'll show you two of them. And then the ones that are in the not matching [29:23.120 --> 29:28.780] will show that they don't match. So I'm feeling a lot more confident about what I'm seeing here. [29:29.420 --> 29:33.380] And I can apply it to other things. So I want to try an older signature, newer variant. This [29:33.380 --> 29:37.300] is what I was saying. You have to watch me carve out the same thing again. But I'm going to carve [29:37.300 --> 29:44.880] it out from the 11.30 and make a signature out of it. And then I'm going to... I'll stalk you [29:44.880 --> 29:52.880] through it. So I open that up. I'll isolate the flow that I'm interested in. I keep on selecting [29:52.880 --> 30:02.460] that same get request. But basically I want to follow this post here. And I'll save this. [30:09.170 --> 30:14.430] And then upload that to create my signature. And this is where I'm going to have some different [30:14.430 --> 30:19.990] numbers from the last one, because it's a slightly different transaction. And I want to analyze, [30:19.990 --> 30:25.590] I guess, one from six months later, Darkgate. So I was actually able to find a newer one. [30:26.190 --> 30:30.910] And I'm getting a whole bunch of matches. So I can review those. And I can go to the very bottom, [30:30.910 --> 30:37.490] which is the least matchy of the matches. And... oh, actually, I guess I'm going to look at the [30:37.490 --> 30:43.630] top one first. No matter how many times I build these videos, I always forget what I did. [30:43.930 --> 30:47.990] But the very top one matches, of course. And I can put this... throw this in the last search [30:47.990 --> 30:54.510] if I want to. I'll get all those matches. 169 hits. When I look at the signature, [30:54.510 --> 31:00.150] the signature is based off this visit to TranslateGoogle.com, misspelled, [31:00.150 --> 31:04.730] typosquatting. And the bottom one is the same kind of post to a different place. [31:05.410 --> 31:10.030] And I'm getting 169 matches. So that's pretty cool. I thought it'd be cool to add a map, [31:10.030 --> 31:15.550] because we all love maps. Our management loves maps. And so it's thought it'd be cool. The [31:16.950 --> 31:23.490] red skulls are the bad locations. The unmapped things are black, because you can't... I couldn't [31:23.490 --> 31:28.910] put an internal IP address on a map. But I try to put them in the middle of the Pacific Ocean [31:28.910 --> 31:33.330] when they're unmapped, but there are some other ones that actually get unmapped. So I'm working [31:33.330 --> 31:38.790] on that. Production use. This is cool that you can use... you have a web app. If you're... I've [31:38.790 --> 31:43.190] been a SOC analyst, and I've pulled PCAPs down, and I'm like... I open it up, and I see what [31:43.190 --> 31:48.310] actually happened once the IDS rule fired. But it'd be cool to have something like this, where [31:48.310 --> 31:52.970] I could upload it, see what's happening, see if it compares with anything in my database of [31:52.970 --> 31:57.890] signatures. But there's other ways to do it. For example, I was talking about the daemon logger, [31:57.890 --> 32:05.150] or TCP dump, if you're writing packets to your disk. How do you run this on a rolling basis? [32:07.210 --> 32:16.010] So I wrote this as a fast API thing with Flask running on top of it. So if I start this over [32:16.010 --> 32:21.270] on the left, I'm running my fast API app. And then on the right, I have a Python script [32:21.910 --> 32:28.590] sending a PCAP. And it sends it and gets back JSON data, and then I can refresh whatever my [32:28.590 --> 32:32.710] sim is. It can be Elasticsearch, or anything else that you use, or want to use, and get those [32:32.710 --> 32:39.250] matches. So that's nice, at least for a rolling PCAP. Of course, as mentioned before, the [32:39.250 --> 32:43.250] multiprocessing happens when the flows are separated. So you want to do it on a fast machine. [32:43.250 --> 32:48.630] But generally, machines that are doing packet capture are going to be fast. [32:49.850 --> 32:55.330] Additionally, just because I thought it would be fun, you can use notify, which is N-T-F-I, [32:55.330 --> 33:01.550] to notify you. So when I run this again, I can get a notification on my phone, which is kind [33:01.550 --> 33:08.650] of cool. Kind of cool. It could also be kind of terrible. For example, you can get analyst fatigue [33:09.190 --> 33:16.430] when I did this and got a whole bunch of stuff. So I have that on my system. But you can run it [33:16.430 --> 33:24.470] if you want to. I'm going to talk about something completely impractical. I love doing research [33:24.470 --> 33:31.430] because it opens my mind to new things. I get to create and build things. I feel like security [33:31.430 --> 33:38.070] research is a creative process, and it fuels my other creative passions, like music. So I just [33:38.070 --> 33:43.810] wanted to play around with this and see if I could do something with audio. It's not practical. But [33:43.810 --> 33:48.890] let's just see what happens. So I like this quote a lot. Art is how we decorate space. Music is how [33:48.890 --> 33:54.830] we decorate time. And I painted before I made things, built things to fill up the space we [33:54.830 --> 33:59.390] live in. I also make music. And music is all based on time. You change the beat, it's completely [33:59.390 --> 34:05.410] different. You change a note, and the length of the note is different. So they're powerful things [34:05.410 --> 34:10.810] in their own areas. And I was thinking, while I'm playing with time, let's see if I can make [34:10.810 --> 34:16.490] something musical with this. So you all know about Shazam, I'm sure. I use it. If I'm at a club, [34:16.490 --> 34:24.270] I'm in the corner, like, Shazamming. So basically, if you don't know how it works, [34:24.270 --> 34:32.340] this is what it looks like. Oh, that's not what it looks like. So you press Shazam, you hear a [34:32.340 --> 34:36.960] song you want to hear, and then it tells you what it is, adds it to your Spotify playlist, [34:36.960 --> 34:42.580] you can listen to it over and over again. It's great. Sorry to rickroll here. So I was researching [34:42.580 --> 34:49.260] this. I was like, could I do this with Python and NumPy? So I found this article. I also found [34:49.260 --> 34:54.220] something called DejaVu that someone wrote, that they wanted to make their own personal Shazam [34:54.220 --> 34:58.920] server where they could store their music, and if they heard a sample of something, [34:58.920 --> 35:05.160] it would play that, it would listen for the sample, or you send it to DejaVu, and it would go, [35:05.160 --> 35:11.640] oh, yeah, that's this song. I thought, oh, I can probably do this. So I'm back to my transactions, [35:11.640 --> 35:16.880] not the percentages, but the actual times in between, the microseconds or milliseconds or [35:16.880 --> 35:23.660] whatever time I was using or want to use. And I'm looking at this, I'm thinking about pitch. [35:23.720 --> 35:30.320] Frequency is the number. So zero would be a low, like a low sound, and up high would be a [35:30.320 --> 35:34.840] high number is a high sound. So I can make audio out of this. It's not going to be beautiful. I [35:34.840 --> 35:40.880] mean, you're going to hear it right now, what it sounds like when you listen to a PCAP file. [35:41.640 --> 35:48.280] But there's patterns in there. Like I said, this is not practical. But let's play with this. Let's [35:48.280 --> 35:53.840] go same malware sample, different environments. I'm going to grab my malware. I grabbed from [35:54.380 --> 36:01.540] Malware Bazaar, agent Tesla, kind of old. I ran it in any run, downloaded the sample, [36:01.540 --> 36:07.360] just I don't know why I downloaded the sample. I always do. And I get the PCAP. And then I can [36:07.360 --> 36:11.500] see that it's doing a post. And in this case, I'm not going to be applying my Levenshtein stuff. [36:11.500 --> 36:18.100] I'm just playing with audio. But I see there's a post here. And I also want to address the idea of [36:18.100 --> 36:21.280] bandwidth. That's why I'm running this any run. And I'm also going to run it in my own very busy [36:21.280 --> 36:27.620] network environment at home. I run it on my system. This is just a picture of one of my malware VMs. [36:27.640 --> 36:32.140] And I've got the same kind of post happening. I'm going to have different transaction times [36:32.140 --> 36:38.700] because of bandwidth. And I'm going to just end it. So there's a little bit of stuff here. I have [36:38.700 --> 36:43.880] to reverse it. I'm instead going to be making a signature out of the entire PCAP, not the little [36:43.880 --> 36:50.040] bit. So like I said, not practical. And then I'm going to play my little bit and see if it finds it. [36:52.020 --> 36:57.840] If I open up this PCAP, let's see here. And we're looking at that post. [37:00.320 --> 37:05.340] I've got to create an audio file from it. So I have a little Python script I wrote to [37:05.340 --> 37:11.600] convert those frequencies into different pitches using Fourier transform and some other stuff. [37:12.380 --> 37:15.520] And in the back, you can see there's a bunch of MP3s being made. And they all disappear. Those [37:15.520 --> 37:19.820] are all the flows individually. And then they get combined into one big PCAP, MP3. [37:21.540 --> 37:27.820] And then I'm left with that thing. And then I've got a carved one. This is the little tiny bit [37:27.820 --> 37:33.060] that I want to identify in my Shazam. I'm going to do the same thing with that. [37:34.780 --> 37:39.120] I've got that MP3 file, which is huge, by the way, compared to the PCAP, which is like 500k [37:39.120 --> 37:45.160] or something. It's not that huge. But I've got others that are huger. I've got my carved one [37:45.160 --> 37:51.880] here. I'm going to make the signature from this one. And you see a bunch of... it's carved, [37:51.880 --> 37:57.640] but there's flows in there. Because I didn't carve it all the way. And I've got these two MP3 files. [37:59.220 --> 38:07.660] Let's see. So now I'm going to try to identify it. Initially, when I try to identify, it's not [38:07.660 --> 38:13.220] going to see it because I have to add it to a database. It's not like a clean app like Shazam. [38:13.220 --> 38:17.040] It's just a program you can run. So I try to recognize it. It's not going to recognize my [38:17.040 --> 38:20.880] file yet. But that's because I haven't added it. So what I'm going to do is I'm about to add it. [38:20.900 --> 38:25.560] I've got to drop it into the signatures folder, which I'm going to do right now. [38:29.620 --> 38:37.600] Slowly. Drop it in there. I'm going to run a script to help it identify that. So it sees it. [38:37.600 --> 38:44.740] It's like now there's a signature for this audio file, this song of yours. And then I want to [38:44.740 --> 38:55.040] recognize the file, just my part. And it's seeing there's a song ID recognized this traffic pattern [38:55.040 --> 38:58.220] that I was seeing. And if I apply Levenshtein to it, which I didn't do in this example because I [38:58.220 --> 39:05.800] don't want to bore you with more of this running commands. But it gets even more interesting. [39:05.800 --> 39:10.180] But of course, like I said many times, it's not practical because those pcap files can grow to [39:10.180 --> 39:16.980] huge sizes when they're mp3s. And who wants to run their network in mp3 mode? So maybe I do. [39:18.180 --> 39:21.820] I guess I kind of talked fast. I'm kind of getting towards the end here. Supposed to go [39:21.820 --> 39:26.820] for 50 minutes or 55 minutes. But you can go get some coffee. [39:26.820 --> 39:30.820] So going further, I'm going to work on some third-party APIs. Like I said, I like to, [39:30.820 --> 39:35.540] when I release stuff personally, whether that's not a work talk, I want people to be able to try [39:35.540 --> 39:40.940] it and play with it if you want to. So you can add stuff if you want integrations with VirusTotal, [39:40.940 --> 39:46.540] with my company's product, Investigate, or other things like that. I didn't add it. It's very easy [39:46.540 --> 39:52.020] to add. Then you can look at things like domain, IP, reputation, relationships. If you have a [39:52.020 --> 39:55.760] sinkhole in your environment, you can pull that data in. You can play with anything you have. [39:56.680 --> 40:02.460] To add more things for conviction. And I'll analyze various components of the PCAPs, [40:02.460 --> 40:06.140] so I can add that in the future. And I should probably learn Rust. I should learn something [40:06.140 --> 40:10.380] so it's fast. Like, you know how Snort is a C binary, or I think it's a C binary, [40:10.380 --> 40:13.760] and it uses its rules. It runs very fast streaming. I'd love to do that. [40:14.560 --> 40:20.400] The code is available. It's a long name, but if you want, I just uploaded it about two days ago. [40:20.400 --> 40:24.380] So hopefully it's okay. There's a couple things you have to do if you want to play with it. [40:24.380 --> 40:32.360] But I was very, very verbose in my documentation on the README. And there's a couple utilities, [40:32.360 --> 40:37.360] too. I added a malware traffic analysis unzipper file, because there's a password scheme. So if [40:37.360 --> 40:42.200] you want to unzip malware traffic analysis PCAPs, you can do that. You can reach me at my website, [40:42.200 --> 40:47.900] my personal site, which is pyrosec.com. Not a Twitter, because I just don't post. [40:47.900 --> 40:52.940] Don't even really look at it anymore. And I'll probably rewrite all my posts with nonsense. [40:53.440 --> 40:57.200] And Bastodon, I don't even have the app installed, but I should, because it's kind of cool. [40:57.200 --> 41:00.280] But anyways, that's my talk. And thank you for coming. [41:09.280 --> 41:11.620] There's time for questions, if you have questions. [41:27.710 --> 41:33.410] Well, a lot of the time I was working in a clean environment, for the most part. [41:34.950 --> 41:40.450] But I did run stuff over my network at home, which I know that's crazy, but I do it. And [41:40.900 --> 41:46.840] I didn't see negative results. But my network is busy. It's not a corporate environment. I have [41:47.750 --> 41:57.090] like 20 VMs and three or four servers. So it's busy. But I have a family, Spotify, Netflix, [41:57.090 --> 42:08.690] YouTube. What's that? Yeah, yeah. It shows promise. I want to keep exploring it. Yeah. [42:13.660 --> 42:23.170] Sorry, say again? No, but that's what I mentioned. I want to explore future stuff. And that's easy [42:23.170 --> 42:28.830] enough to do. Direction, that's also good to play with. I started to play with it with a mapping, [42:28.830 --> 42:32.870] like making the source changes constantly. So... [42:33.790 --> 42:41.350] Oh, yeah? That's really cool. I love to talk. Yeah. All right. Thank you very much.