WEBVTT

00:00.000 --> 00:05.360
So, now it is 1 o'clock, and with all that setup time, we're good?

00:05.440 --> 00:06.920
Yeah, we're good.

00:07.100 --> 00:08.480
Right, we're good.

00:08.480 --> 00:11.060
So, it's my pleasure.

00:12.380 --> 00:17.620
Jay, you presented... oh, wow, actually in this area, it seemed like yesterday, 2016.

00:17.960 --> 00:21.340
So, without much ado, it's my pleasure to introduce to you, J.D.

00:21.340 --> 00:22.720
Martino Fidelis.

00:28.680 --> 00:29.600
Thank you, guys.

00:29.600 --> 00:30.400
Thank you.

00:31.560 --> 00:42.340
So, we've all kind of been there, most of us who kind of work like either SOC work or malware analysis, or, you know, where you end up writing rules, right?

00:43.800 --> 00:51.400
I'm just going to kind of give you a methodology, or at least my methodology, of how I write rules and how I go about things.

00:52.060 --> 00:53.740
You don't have to adopt it.

00:53.740 --> 00:55.100
I don't care if you do.

00:57.160 --> 01:05.120
But hopefully, it gets better out there, and we can all rise up and start crafting good detections and whatnot.

01:05.360 --> 01:06.620
So, my name is J.D.

01:06.620 --> 01:12.600
Martino, Head of Detections and Countermeasures for the Fidelis Threat Research.

01:13.180 --> 01:15.760
That's just some fancy title my boss gave me.

01:15.760 --> 01:18.100
Really, I'm just like the rule bitch, right?

01:18.100 --> 01:21.920
So, that's pretty much how it goes.

01:22.980 --> 01:25.920
There are some prerequisites to this talk.

01:26.980 --> 01:31.400
I do a lot with regular expressions and with Yara.

01:31.400 --> 01:35.040
So, all my examples are going to kind of center around those two.

01:35.560 --> 01:48.260
If you are unfamiliar with Yara, the talk that Ming just mentioned that I did back in 2016 was to catch an APT, Yara, and I go through more of the syntax and whatnot.

01:48.260 --> 01:52.260
So, if you want to learn that, I definitely suggest going back and watching that.

01:53.640 --> 01:55.920
Regular expressions, I don't know.

01:55.920 --> 01:58.400
I have good days and bad days, either way.

01:58.400 --> 02:02.700
If you're not doing them every day, yeah, either way.

02:03.280 --> 02:16.080
So, when you're writing detections, the real problem is that you and your coworkers, you know, you're kind of building this structure, and it's very complicated, right?

02:16.080 --> 02:23.340
And sometimes, you know, like the guy in the picture, he may be looking down at what his coworker is doing.

02:23.340 --> 02:24.440
He's like, what are you doing?

02:24.440 --> 02:25.680
I'm up here.

02:25.680 --> 02:30.040
Or, hey, let's build this, and it's all disjointed and whatnot.

02:30.140 --> 02:31.940
And there's a lot of complications.

02:31.940 --> 02:34.020
It's never really easy, right?

02:34.040 --> 02:39.420
Because malware will be at all different layers upon the stack.

02:39.420 --> 02:41.980
And the attack surface is at all different layers.

02:41.980 --> 02:52.620
There's not one easy different thing over one protocol or, you know, whether it be the file or the network layer, or even metadata and whatnot.

02:53.500 --> 03:05.480
So, what happens when you two have been working alongside of each other, and all of a sudden, your colleague leaves the company, right?

03:05.560 --> 03:09.400
And everybody, you know, it's like, it's a normal thing.

03:09.400 --> 03:12.400
And it's like, hey, cheers, we're going to throw a party for you.

03:12.400 --> 03:15.340
And he's like, yeah, man, sorry for everything.

03:15.540 --> 03:17.120
We're going to be friends.

03:17.220 --> 03:26.000
And then, like, Monday comes around, and then you look at one of his detections, and you're like, holy... right?

03:27.040 --> 03:30.740
It's like, I kind of equate it to Monopoly, right?

03:30.740 --> 03:31.640
And you get the chance.

03:31.640 --> 03:36.220
Everybody wants to go and collect $200, right?

03:36.220 --> 03:37.700
Everybody wants that.

03:37.700 --> 03:41.120
But it's like, in this case, no, you've got to pay the other players.

03:41.300 --> 03:42.320
You're taking your lumps.

03:42.320 --> 03:43.780
Like I said, I'm the rule bitch, right?

03:43.780 --> 03:45.320
So, I learned this the hard way.

03:47.260 --> 03:52.360
So, that being said, how do we rise up to the occasion, right?

03:54.900 --> 03:56.520
So, I'm going to throw another one.

03:56.520 --> 03:58.040
I probably should have said this earlier.

03:59.020 --> 04:05.540
The other prerequisite for this is a little bit of, you know, set theory and whatnot that most of us probably learned in computer science.

04:05.540 --> 04:08.100
So, yes, I'm going to give you some Venn diagrams.

04:08.160 --> 04:13.520
It was the only way, or the best way, I can kind of convey it to you and whatnot.

04:14.220 --> 04:17.220
And so, you know, you have your universal set.

04:17.220 --> 04:18.100
That's the set of everything.

04:18.100 --> 04:21.040
Everything that's going on, whether it be the network, the endpoint.

04:21.400 --> 04:23.760
And then you have your detection, your target, right?

04:23.760 --> 04:25.360
What are you trying to signature?

04:25.740 --> 04:27.140
I call it a target.

04:28.160 --> 04:34.220
And so, it's, you know, you're trying to pick that needle out of the haystack.

04:35.280 --> 04:42.860
So, when you finally go for it and you write your detection, you end up getting these other set of events.

04:42.860 --> 04:45.300
I really don't have a better name for them.

04:45.300 --> 04:47.420
They're just another set of events.

04:47.540 --> 04:50.880
We all know them as mostly false positives, though, right?

04:50.940 --> 04:53.880
But they're not exactly all the others.

04:53.880 --> 04:58.480
They're just some random others that some of which happen to overlap with our target.

04:58.480 --> 05:00.900
And those are the ones that are the false positives.

05:02.800 --> 05:06.260
And so, you know, you have your red set.

05:06.260 --> 05:08.560
Your red set on the left-hand side is the target.

05:08.740 --> 05:09.600
That's your detection.

05:09.600 --> 05:10.980
The blue set is your other.

05:15.430 --> 05:20.130
It may not always be large, you know, your other, your false positives.

05:20.130 --> 05:21.550
They could be a lot smaller.

05:22.350 --> 05:24.390
And then the purple area is in the middle.

05:24.390 --> 05:25.930
That's what you're trying to eliminate, right?

05:25.930 --> 05:27.890
You're trying to eliminate that purple area.

05:29.250 --> 05:30.790
So how do you do that?

05:30.790 --> 05:32.090
How do you do that?

05:32.330 --> 05:34.270
I call it shrinkage.

05:37.010 --> 05:40.450
So we want to shrink that other event set.

05:41.270 --> 05:47.670
If we could shrink that other event set, we can get the union of the two sets to be smaller, right?

05:48.610 --> 05:56.170
The typical way that people mostly do this is kind of with some sort of and not.

05:56.170 --> 05:58.110
You know, hey, I got this detection.

05:58.110 --> 06:00.810
Oh, and not my domain controller.

06:00.810 --> 06:08.610
Oh, and not this file that passes, you know, from this person to this person every day via cron job or something like that.

06:08.610 --> 06:18.350
And so you have like these kind of one off detections where like, you know, this one set is a subset of your other.

06:18.430 --> 06:22.670
And then you have another and it's a subset of that other.

06:22.670 --> 06:27.530
And you have a third other, which is all still a subset of that other.

06:29.150 --> 06:37.310
And so you end up with these long kind of daisy chains of and not situations where you're just kind of filtering out.

06:37.770 --> 06:45.470
And, you know, those are those are somewhat maintainable, but those aren't really maintainable either.

06:45.470 --> 06:48.530
At least they can get out of hand and whatnot, if not done properly.

06:51.590 --> 06:53.430
So how do you do that?

06:53.430 --> 06:57.570
So how do you how do you shrink, you know, your false positives?

06:59.790 --> 07:02.570
There's like I said, there's the and not method.

07:02.570 --> 07:07.530
But once you do that enough, your other set gets really, really small.

07:08.210 --> 07:14.510
And it just like I said, it gets hard to maintain, but then your target set still stays large.

07:14.730 --> 07:26.670
So is there anything and there's not so much of an overlap, but it's enough that it creates in your workflow where it takes time out of your workflow to be going through some of these false positives.

07:26.850 --> 07:29.730
And you just don't want to be dealing with them anymore.

07:29.730 --> 07:33.370
So we've manipulated the other set, right?

07:33.370 --> 07:37.730
So what about maybe taking a look at the targeting set?

07:37.770 --> 07:48.290
You know, and then so back to shrinkage, we're going to try and shrink that targeted set, your detection.

07:48.290 --> 07:51.290
How do we shrink that profile, right?

07:51.290 --> 07:54.590
That that that attack profile of that detection and whatnot.

07:54.590 --> 07:57.090
And yes, you can do it.

08:00.520 --> 08:09.100
One of the situations that the target set grows over time is because of false negative situations.

08:09.400 --> 08:19.340
You get you find new activity all the time and your target set just you end up taking on more of these sets, your target one.

08:19.340 --> 08:23.140
And now you have another target to some mutual exclusive set that has nothing.

08:23.140 --> 08:26.360
It's involved, but then it's kind of not involved with the other set.

08:26.360 --> 08:28.800
And then you have to merge those two together.

08:29.720 --> 08:33.060
And then, like I said, that's a growing it's literally a growing problem.

08:33.060 --> 08:38.680
You have two sets converging together and it's getting bigger in your other set.

08:38.680 --> 08:44.700
May or may not be getting smaller, but it just doesn't become maintainable.

08:45.420 --> 08:52.160
And what I like to call that is kind of the one rule to rule them all mentality.

08:52.820 --> 09:00.020
Analysts like to write these catch all rules where, you know, the Lord of the Rings effect, I guess.

09:00.020 --> 09:10.080
And so, you know, we write these really large monolithic detections that just like I said, they become unmaintainable.

09:10.080 --> 09:10.780
Right.

09:11.600 --> 09:17.640
And so you got to kind of know when to separate or chain your detections.

09:17.640 --> 09:29.420
And then you also you kind of drop or ignore some of the true positives and maybe even pick them up with another tech detection with either with a lesser confidence detection or with a lesser severity detection.

09:30.720 --> 09:35.660
And so you you can kind of shrink that that target set a little bit.

09:35.800 --> 09:38.140
Just to kind of give you an example.

09:38.440 --> 09:38.980
Right.

09:38.980 --> 09:48.580
So at one point in my career, I inherited this network network Yara rule for ghost rat.

09:48.920 --> 09:56.620
And it was literally it was it was 100 different beacon strings that we were targeting in the one rule.

09:56.900 --> 10:05.300
And you look at the condition at the bottom and then all the number of conditions, all the number of beacon strings that we were we were looking at.

10:05.300 --> 10:18.440
Notice the first for loop goes from A to Z and then there's another the second for loop from A star and then a third for loop B star and a fourth for loop C star.

10:18.440 --> 10:22.580
So we've enumerated the alphabet going on the fourth time.

10:22.580 --> 10:29.260
That's how many times we've enumerated those those those detections and whatnot.

10:29.260 --> 10:33.940
And so what if what if one of them starts going crazy?

10:33.940 --> 10:36.080
How do you how do you adjust this?

10:36.080 --> 10:38.200
How do you adjust something that's so monolithic?

10:38.200 --> 10:45.660
You literally have 100 indicators of compromise in your in your target in your target set.

10:47.320 --> 10:53.100
And we all get we all get defensive about our rules as analysts.

10:53.340 --> 10:55.700
You know, it's our babies.

10:55.700 --> 10:57.620
We curate these and whatnot.

10:57.620 --> 11:01.960
And so there is a kind of a fact that it's like, oh, precious.

11:01.960 --> 11:02.760
Oh, yeah.

11:02.760 --> 11:06.780
And so, like, we don't want nothing to happen to them.

11:06.780 --> 11:11.260
But the life cycle shows that we have to we have to do something about it.

11:12.560 --> 11:16.000
So so let me give you some some clues enough.

11:16.000 --> 11:19.540
I mean, I'll talk a little bit, but I'll give you some more kind of examples.

11:20.000 --> 11:21.180
So how do you do that?

11:21.180 --> 11:22.780
You separate multiple detections.

11:22.780 --> 11:25.780
You take the one take target set the full set.

11:25.780 --> 11:30.900
You separate it from target one and then target two.

11:30.900 --> 11:34.520
And then they have a couple of other sets in between there as well.

11:35.240 --> 11:37.500
And now your sets just got smaller.

11:37.500 --> 11:38.160
Right.

11:38.160 --> 11:43.360
So this one is a lot larger.

11:43.360 --> 11:45.320
And then we've separated it out.

11:45.420 --> 11:48.460
And now we have two smaller sets to kind of deal with.

11:48.460 --> 11:53.520
One set may not be giving you problems, but another set may be giving you problems.

11:53.520 --> 11:56.880
But at least when you do it, you've done your work up front.

11:56.880 --> 12:03.100
You've done all your analysis up front that you don't necessarily have to manage the T1 set.

12:03.100 --> 12:08.420
Or if the T1 set is giving you problems, you don't have to manage the T2 set when you go in and make your changes.

12:09.000 --> 12:14.040
And then to even further slice it, you can make it into even more further slicing.

12:14.040 --> 12:16.400
And then the sets become even smaller.

12:16.700 --> 12:21.320
And then they have a lot less kind of management and whatnot with them.

12:21.760 --> 12:27.080
So just as a kind of warning, I am including some rules.

12:27.080 --> 12:29.740
So I'm going to throw a bunch of walls of text at you.

12:30.440 --> 12:38.720
If you do want to come back and watch the... there's a lot of good tidbits in some of these next few slides.

12:38.720 --> 12:40.300
I suggest coming back.

12:40.300 --> 12:42.000
You're not going to ingest all this stuff.

12:42.000 --> 12:44.620
And especially the syntax that I've got going on with some of these.

12:44.620 --> 12:46.120
You're going to be like, whoa, what's...

12:46.120 --> 12:50.520
So you're going to need to take a second to kind of parse through it and whatnot, though.

12:50.680 --> 12:57.040
But the main things that I want you to kind of focus for the next couple slides are the constructs and the naming and whatnot.

12:57.040 --> 12:59.400
And I'll kind of walk you through the rest and whatnot.

12:59.400 --> 13:07.420
So one thing you can do with Yara, at least, is you can separate by condition.

13:08.420 --> 13:20.320
That ghost rule that I said earlier, notice that... so there was... I at least noticed that there was different lengths of our detection set, our indicators of compromise.

13:20.360 --> 13:27.100
And so I kind of separated them and kind of grouped them by conditions in that case.

13:27.120 --> 13:34.900
So I can group with the condition and it makes it easier to promote maintenance on your rules.

13:34.900 --> 13:40.980
In these three examples, I have... I just have three, actually, but I had like up to 10.

13:41.140 --> 13:44.300
I had up to 10 for all 100 different indicators.

13:44.300 --> 13:47.260
So I had 10 different rules that I was in managing.

13:47.620 --> 13:57.320
But it was a lot easier because if one was false positing, I had a different confidence value when I need to make a change and whatnot about it.

13:57.320 --> 14:05.480
And so rather than... I can then just focus on this one rule and all the other nine rules, I didn't even have to worry about.

14:05.820 --> 14:10.820
So the ghost beacons, I split them up length four, just got like one little indicator.

14:10.920 --> 14:15.800
Length five had 85 different indicators and indicators of compromise.

14:15.800 --> 14:19.840
And then length six had... excuse me, had three of them.

14:23.900 --> 14:29.020
And so how would you... how would you kind of separate just for... because not everybody knows Yara.

14:29.020 --> 14:33.980
So an example, how would you kind of separate that in regular expressions?

14:34.200 --> 14:38.500
I'll let you chew on this regular expression for a second while I take a sip and whatnot.

14:43.870 --> 14:54.730
So this guy's kind of looking for like landing pages to do like man-in-the-middle attacks for PayPal, you know, Yahoo, Hotmail.

14:55.650 --> 15:00.290
They got PowerPoint online, Word online, so like Office 365 and whatnot.

15:01.310 --> 15:05.870
These are all these kind of landing pages that they're trying to man-in-the-middle and get your credentials.

15:07.370 --> 15:13.150
And with the regular expressions, you're just grouping the IOCs with the or clause pretty much.

15:13.250 --> 15:22.910
And so that's how you would do the equivalent of this rule from Yara, similar in a regular expression.

15:23.190 --> 15:27.890
It's a totally different detection, but it's the same idea, same concept and whatnot.

15:30.940 --> 15:47.040
So another thing is that you can separate your indicators by, so I talked about the condition statement in Yara, but you can also separate them towards the indicators of compromise as well, grouping the indicators of compromise.

15:47.140 --> 15:53.520
So what I like to do, so these are four different rules for strings out of an APT3 binary.

15:53.520 --> 16:03.280
Notice the hash is all the same for all four rules, but I have four different rules for strings.

16:03.800 --> 16:07.560
What's the thing that I said earlier, the one rule to rule them all?

16:07.560 --> 16:09.080
That's what most analysts do.

16:09.100 --> 16:23.500
They all want to just jumble them up into one Yara rule and say, hey, give me this and do, you know, gives you some kind of complex expression at the end of the condition and say, hey, this grouping or this grouping or this other grouping or this other grouping.

16:23.620 --> 16:37.940
Well, you can, if you break them out into different rules and then you be very selective with your rule names, excuse me, you can bring a lot of value to your analysis.

16:37.940 --> 16:48.180
When you start separating your detections like this, you start augmenting your analysis and you can say, hey, this, I got this one binary here.

16:48.180 --> 16:53.680
It hit on one of these four string rules for APT3.

16:53.980 --> 17:01.620
Maybe that's not an APT3 binary, but I got this other binary that hit on three of the four.

17:01.740 --> 17:08.160
And so when it hits on three of the four, you're like, OK, it's more than likely APT.

17:08.160 --> 17:11.780
And then, oh, wait, so we didn't have the fifth, the fourth rule.

17:11.780 --> 17:14.460
So maybe there's a shift in your detections.

17:14.460 --> 17:21.940
Maybe you're detecting, you're, you're detecting the shift in, in targeting and whatnot.

17:21.940 --> 17:24.140
And so their binaries are kind of changing.

17:24.140 --> 17:26.400
You know, they may have a different campaign going on.

17:26.400 --> 17:33.380
And so a different person on the team is compiling these or something and or they fix their incorrect spellings and whatnot.

17:33.540 --> 17:41.200
And so, like, if you look at some of these groupings, just I have some regular strings, just unique, very unique strings.

17:41.200 --> 17:44.080
Then I have network GUID strings.

17:44.640 --> 17:54.020
And so and then notice that with the with the first rule there of strings that I say any of them.

17:54.020 --> 17:54.320
Right.

17:54.320 --> 17:57.580
So that's basically the or clause with any of them.

17:57.580 --> 18:03.340
And any one of those strings would are unique enough that they could stand on their own.

18:03.340 --> 18:09.320
You don't need any other supporting strings to kind of make your detection and whatnot.

18:09.320 --> 18:10.740
Now, there's a couple where there's two rules.

18:10.740 --> 18:12.100
There's two rules with any of them.

18:12.100 --> 18:13.980
And there's two rules with all of them.

18:13.980 --> 18:20.440
And so the rules with all of them, where it says all of them in the condition, those are your lesser quality indicators.

18:20.440 --> 18:29.960
You can still group them, but you need the strength of all four indicators of compromise to say to give you that confidence layer layer on your head and whatnot.

18:30.140 --> 18:34.360
And so if you look and then there's a there's output strings, bad grammar.

18:34.360 --> 18:36.340
So I'm even calling out bad grammar.

18:36.340 --> 18:44.200
You know, when people make mistakes in spellings now, granted, there's a lot of code reuse and whatnot.

18:44.420 --> 18:53.640
So when you have all these mistakes like this, especially grammar mistakes, you can generally kind of attributed to one one person or.

18:53.640 --> 19:00.520
But if you start seeing more and more than and there's a lot of different compilations floating around, there's probably some code reuse going on as well.

19:00.520 --> 19:02.760
And that's how you would detect that stuff.

19:03.720 --> 19:06.300
And then you have more output strings.

19:06.300 --> 19:10.060
So the output of this tool was our APT remote command tool.

19:10.860 --> 19:12.920
I can't remember if I wrote these rules.

19:12.920 --> 19:13.960
I probably did.

19:13.980 --> 19:14.500
I don't know.

19:14.500 --> 19:15.340
I didn't put my name.

19:15.340 --> 19:18.100
I guess I should have put my name on it, whether I was the author or not, though.

19:18.220 --> 19:20.380
But it's a good grouping.

19:20.380 --> 19:27.860
It's a good representation of what I'm trying to convey to you guys on splitting up your detections to make them more manageable and whatnot.

19:30.720 --> 19:32.580
So let's see, one more.

19:33.300 --> 19:37.020
Yeah, one more wall of text and then we'll get back to some other stuff.

19:38.760 --> 19:41.520
So we talked about groupings by conditions.

19:41.640 --> 19:50.660
We talked about groupings by indicators of compromise, your string sections, or in with regex, you know, you're using your or statement.

19:53.320 --> 20:01.100
The next one, you still want to try and create multiple detections, but you want to use multiple detection methods.

20:01.160 --> 20:06.380
So I have three rules up here that are all looking for the same technique.

20:06.380 --> 20:10.380
They're looking for a very simple embedded executable.

20:10.540 --> 20:11.720
That's it.

20:12.580 --> 20:20.980
Well, maybe the detections are a little fancy, but nothing fancy about the technique that I'm trying to detect.

20:21.060 --> 20:29.820
And like I said, this is what I said earlier about how when you build enough of these rules, the more rules you have, the more you can augment your analysis.

20:29.820 --> 20:43.600
And so you can save this time up front on by just by running Yara or your regular expressions and let those automated scans do your triage for you.

20:43.600 --> 21:01.340
And so when you can have a large enough rule set to scanning and do triage, and then you can have, without even throwing the binary in a hex editor or IDAPRO or even a text editor or something like that, you can run it against your rule set.

21:01.820 --> 21:06.540
And you can get somewhat of a disposition, whether it be benign.

21:06.940 --> 21:08.500
You still may need to verify it.

21:08.500 --> 21:11.800
If it's benign, you can get some sort of suspect disposition.

21:11.800 --> 21:16.040
It's doing all these techniques, but then there's nothing attributable that's going on.

21:16.040 --> 21:21.540
Or you can get a malicious disposition right off the bat if you have an attributable signature.

21:21.720 --> 21:24.720
And so you can say, hey, this is definitely malicious.

21:24.720 --> 21:26.460
I can attribute it to this group.

21:27.060 --> 21:31.160
How much more do I need to spend on this so I can move on to the next binary?

21:32.580 --> 21:38.040
So, like I said, these are three different rules targeting embedded executables.

21:38.040 --> 21:41.220
One of them looks for more than one DOS stub.

21:41.220 --> 21:51.100
So the DOS, the 16-bit DOS stub that's present in the 32-bit Windows PE header, or just before it, I'm sorry, the MZ header, the 16-bit.

21:51.800 --> 21:54.180
So it looks for multiple DOS stubs.

21:54.180 --> 21:59.420
The other one, it looks for a possible PE structure in which the DOS stub may have been stripped.

21:59.420 --> 22:03.060
And then there's another one that looks for a DOS stub.

22:03.340 --> 22:08.780
It just looks for an additional DOS stub past the initial DOS header.

22:08.860 --> 22:17.160
And so, well, what happens if the outer binary doesn't have a DOS stub and then the embedded binary does?

22:17.160 --> 22:23.400
And so these are three different techniques to kind of catch embedded executables using these rules.

22:26.240 --> 22:31.620
So next I want to talk to you about some detection targeting approaches and whatnot.

22:31.760 --> 22:33.480
But first, let me take a step.

22:37.980 --> 22:39.840
So we're all on the hunt, right?

22:40.220 --> 22:41.560
We're all on the hunt.

22:43.500 --> 22:46.280
What was the Black Hat talk?

22:47.400 --> 22:48.700
2015, big game hunting.

22:48.700 --> 22:52.140
We're all on the hunt for big game, big game malware and whatnot.

22:53.200 --> 22:56.240
The original big game was JAWS, right?

22:58.980 --> 23:04.400
So as, you know, as I go through all my data, I realize some things.

23:06.920 --> 23:11.640
And that I'm hunting, but as a malware analyst, right?

23:11.800 --> 23:14.120
So I'm always on the hunt for that big game.

23:14.120 --> 23:21.480
So I can make an argument of this is bad, you know, and it could be just some random file.

23:21.480 --> 23:25.280
This is bad any day of the week, blah, blah, blah, because of the context you give it to me in.

23:27.600 --> 23:30.400
And I can do that a couple different ways.

23:30.400 --> 23:35.940
I can do that with kind of unique code DNA.

23:36.220 --> 23:43.100
You can either do it with the strings, with the very unique strings, or you can do it with unique byte sequences, right?

23:43.100 --> 23:48.520
So that unique DNA allows you to track the families and go hunt.

23:50.020 --> 24:03.300
But I noticed when hunting that the data that I was looking, or the rules that I was producing, based on the data that I was looking at, I had a bias.

24:03.500 --> 24:07.920
Like I said, I can make an argument for anything to be malicious, right?

24:08.020 --> 24:12.580
And given a limited scope of the view.

24:12.580 --> 24:19.120
And so my, I didn't realize, but my detections also were becoming biased.

24:21.180 --> 24:26.460
And so, you know, we're hunting for that shark, we're hunting for jaws, right?

24:26.460 --> 24:28.680
And we see the fin come out the water.

24:28.680 --> 24:37.420
But then we look under the water, we look and we see the whole scope, and it's just some guy wearing a shark fin, right?

24:39.240 --> 24:40.780
And you're confused.

24:40.780 --> 24:43.180
You're like, wait, I thought this guy was bad.

24:43.360 --> 24:45.200
You know, why is he not bad?

24:45.200 --> 24:48.900
But it's just some guy with a shark fin strapped to his back, right?

24:48.900 --> 24:51.200
Now, once you've seen the whole picture.

24:51.560 --> 24:59.200
And I got that way actually, or at least I noticed that because just enough customers are like, no, this is good.

24:59.200 --> 25:00.460
I'm like, no, this is bad.

25:00.460 --> 25:01.820
And they're like, no, this is good.

25:01.860 --> 25:05.700
And so I would argue with people and whatnot.

25:05.700 --> 25:08.780
And so I noticed the bias in the detections.

25:08.820 --> 25:12.040
And so I noticed that a lot of my detections were as a malware analyst.

25:12.040 --> 25:17.500
And so I got to thinking, well, what would a network admin's detection be like?

25:17.680 --> 25:23.040
You know, how would they write a detection and whatnot?

25:23.040 --> 25:32.040
With malware authors, we're looking in a sea of bad or a sea of... let's see, what's...

25:32.040 --> 25:36.620
Yeah, we're looking from a sea of bad that ignore the good.

25:36.940 --> 25:40.800
And then the network admins are writing their detections.

25:40.800 --> 25:47.680
They're writing detections from a sea of good to detect or highlight the anomalous bad.

25:47.680 --> 25:55.160
So they're almost seeing this kind of inverse view of what we're looking at as a malware author.

25:59.830 --> 26:04.530
So how do you write a malware analyst detection in Regex?

26:04.530 --> 26:12.710
I showed you the one prior with the kind of the DNA, the unique sequences.

26:12.710 --> 26:14.830
But how do you write that in Regex?

26:15.350 --> 26:18.290
So I had a customer that was like, hey, I want to see these.

26:18.290 --> 26:24.310
They had these custom mail headers and they were getting mail from all over the world.

26:24.630 --> 26:27.710
And they were like, look, I know I know this is bad.

26:27.710 --> 26:30.410
It's coming from this country or it's coming from that country.

26:30.410 --> 26:32.310
And how do I detect this stuff?

26:32.310 --> 26:37.350
So I started writing these regular expressions and then it quickly got out of hand for him.

26:37.350 --> 26:41.050
He's like, look now, you know, he's like, you showed me how to do this.

26:41.050 --> 26:48.370
But now, look, we've got 1, 2, 3, 4, 5, 6, 7 different countries and I'm getting new ones popping up every other day or so.

26:48.510 --> 26:53.550
And so we can't really take that approach in our detections.

26:53.550 --> 26:53.790
Right.

26:53.790 --> 26:57.290
Or at least the network admins can't take that approach in our detections.

26:57.290 --> 26:58.690
So I had to kind of think of it.

26:58.690 --> 27:00.570
I had to flip and I had to go inverse.

27:00.570 --> 27:01.970
How would I do this?

27:01.970 --> 27:07.550
And he's like, you know, really, we only do business with these three companies.

27:07.550 --> 27:08.870
I mean, three countries.

27:08.890 --> 27:15.990
And he's like, if you can write me a signature that, you know, if it's not these three countries.

27:15.990 --> 27:20.250
And I know like the DoD, they got Five Eyes and stuff like that.

27:20.250 --> 27:31.030
Like there's smaller companies that, you know, they're only doing they know they don't have an office in Madagascar or something like that or Nigeria.

27:31.050 --> 27:37.110
And I mean, they may have a Nigerian maybe related to a Nigerian prince, but they don't have an office office in Nigeria.

27:37.110 --> 27:37.830
Right.

27:38.430 --> 27:44.530
And so and then they had these other kind of headers that were coming in through through one of their things upstream.

27:45.190 --> 27:47.610
And they were marking all this mail stuff for us.

27:47.610 --> 27:49.090
I'm like, man, this is a gold mine here.

27:49.090 --> 27:49.390
Right.

27:49.390 --> 27:58.970
And he's like, look, I want to find all these different these different detections based on these or the non presence of these strings and whatnot.

27:58.970 --> 28:05.150
So I I kind of took the I went to the red the regular expression route.

28:06.550 --> 28:16.330
And and when I inversed it, I I came up with negative look aheads.

28:16.350 --> 28:16.970
Right.

28:17.130 --> 28:20.610
And so they're a little complex.

28:20.610 --> 28:25.310
Like I said, if you want to read into them, go back to the talk afterwards and kind of see it.

28:25.310 --> 28:31.130
It's all about creating a set and then you have a match to non match on and then another matching set.

28:31.130 --> 28:38.130
It gets a little hairy, but I definitely suggest going on like regex 101 to help you build your regular expressions and whatnot, though.

28:38.370 --> 28:44.270
And I came up with three these three detections for these three different X headers for the situations that he wanted me to do.

28:44.330 --> 28:45.770
And it worked out great.

28:45.770 --> 28:47.450
He's like, man, this is awesome.

28:47.450 --> 28:48.350
I don't have to do it.

28:48.350 --> 28:51.970
I don't have to do any maintenance anymore for these these detections.

28:52.110 --> 28:56.370
And and it did everything that he wanted to accomplish.

28:58.630 --> 29:03.090
So, you know, and that was kind of looking at that that inverse view.

29:03.090 --> 29:03.650
Right.

29:05.010 --> 29:10.150
So we talked about kind of the malware analyst detections.

29:10.150 --> 29:20.110
We talked about the bias that it kind of creates and how a network admin has a different view to it and whatnot.

29:20.910 --> 29:23.910
But how do you get longevity out of your stuff?

29:24.830 --> 29:33.030
And I have a technique that I call, I don't know how else to describe them, just circular detections.

29:33.030 --> 29:35.930
I'll write a couple of rules based on a few things.

29:35.930 --> 29:40.310
And and those two those two target rule sets are mutually exclusive.

29:40.310 --> 29:40.670
Right.

29:40.670 --> 29:41.470
They have nothing.

29:41.470 --> 29:46.930
They share the sample, but they don't share any same indicators of compromise.

29:46.990 --> 29:47.470
Right.

29:47.470 --> 29:52.810
And so so I'll create these these circular detections.

29:52.810 --> 29:57.670
I'll have rule one and it's and it detects a piece of malware.

29:57.990 --> 30:02.830
But then I have another rule that I built off of my original source.

30:03.450 --> 30:06.410
But rule one detected this malware.

30:06.570 --> 30:09.490
But rule two didn't trigger.

30:10.230 --> 30:11.210
Analyze it.

30:11.210 --> 30:12.810
We know it's malware.

30:13.110 --> 30:17.750
But when I analyze it, I get an update to rule two.

30:19.750 --> 30:21.930
So I got that rule.

30:21.930 --> 30:29.370
I got a new indicator of compromise for rule two that I didn't already have from my first original sample.

30:29.370 --> 30:29.710
Right.

30:29.710 --> 30:35.430
And most people who do a lot of virus total or reversing labs hunting do a lot of retro hunts.

30:35.490 --> 30:41.470
You guys are used to this stuff kind of panning out and finding the broader campaign.

30:42.490 --> 30:53.070
This is a kind of common thing, but I want everybody else who's not a malware analyst or not a malware hunter to kind of, you know, learn this stuff.

30:53.070 --> 30:54.850
So that's why I'm telling you about it.

30:55.070 --> 30:57.950
And so how do you do these circular detections?

30:57.950 --> 30:58.550
Right.

31:01.570 --> 31:07.350
So my first round, this is actually a throwback to my old talk.

31:07.350 --> 31:09.170
The payload names.

31:09.170 --> 31:14.530
I found these weird little payload names and these small DLLs that were getting loaded up.

31:15.150 --> 31:17.850
And they kind of had some of these unique names.

31:17.890 --> 31:24.430
Now, it's set up that MSI may not be unique, but it's kind of unique in the context of it's a DLL and it's only 11k, right?

31:25.510 --> 31:29.770
And then I came up with a string deobfuscation routine.

31:29.770 --> 31:51.290
And that routine, so I had the payload name that was embedded into the loader and I had a string deobfuscation routine that was also embedded in the loader, but it deobfuscated the payload, not the strings for the file.

31:51.290 --> 32:00.810
And so I run it, I do a retro hunt, find a bunch of other files, and then I go on to round two.

32:00.810 --> 32:10.170
And I found some new payload names, so my set of indicators of compromise just got larger, right?

32:10.170 --> 32:15.390
And they all stand apart from each other, so they can all be a detection on their own.

32:16.330 --> 32:21.270
But I went from having two payload names to I now have eight payload names.

32:22.690 --> 32:31.970
And then, instead of having just one byte sequence for the payload deobfuscation, I now have three.

32:31.970 --> 32:36.290
I only got two rules up there, plus the previous one.

32:36.290 --> 32:37.910
And so I ended up getting three.

32:37.910 --> 32:46.830
And I keep doing these iterations and I keep finding more rules, I mean, more Intel and I keep finding more malware.

32:46.830 --> 32:57.330
And in the end, I end up with like 27 payload names, some of which may not have even been PlugX for the payload.

32:57.330 --> 33:04.710
So they were using a similar delivery method, or at least I suspect they were using a similar delivery method for a couple different pieces of malware.

33:04.710 --> 33:14.990
And then, for as far as the strings, and then the byte sequences, I came up with 11 different byte sequence rules.

33:16.490 --> 33:31.790
And so I would have a subset at any one time, if a file was scanned, I'd have a subset of maybe 5 out of 10 of these byte sequence rules would trigger on one of those things.

33:31.790 --> 33:36.670
But if it got like 2 out of 10, then maybe I'd take a look at it.

33:36.770 --> 33:45.410
But if I got a high number of matches, detections, then I would just kind of roll with it, right?

33:45.790 --> 33:47.950
And kind of update it as I go along.

33:49.610 --> 33:53.630
So, I'm all about stories.

33:55.130 --> 33:59.830
My next one is a story, because we're all in the trenches, right?

34:00.470 --> 34:04.830
And so I had a buddy of mine, Fish is his name.

34:05.050 --> 34:10.150
And he calls me up one day and he's like, dude, we got hacked by the Russians.

34:10.210 --> 34:11.210
I'm like, what?

34:12.430 --> 34:13.150
Yeah.

34:14.030 --> 34:17.010
And so I'm like, he's like, we got hacked by the Russians.

34:17.010 --> 34:18.050
I'm like, no we didn't, dude.

34:18.050 --> 34:20.650
I'm like, alright, we'll take a look at it, right?

34:20.990 --> 34:23.190
And it's this, this, and this.

34:23.190 --> 34:24.850
And he's all excited.

34:24.970 --> 34:26.950
And it was the day before Thanksgiving, right?

34:26.950 --> 34:28.250
And I'm on vacation.

34:29.830 --> 34:31.510
It's Sunday at four o'clock, right?

34:31.510 --> 34:34.270
It always happens on the weekend, right?

34:34.270 --> 34:37.070
Or it always happens when you're on vacation, right?

34:37.990 --> 34:43.270
And so we called it Operation Turkey Eve, because it was the day before Thanksgiving.

34:43.490 --> 34:45.270
And he's calling me up.

34:45.270 --> 34:47.530
And we're getting on the phone, we're talking back and forth.

34:47.530 --> 34:55.150
And I'm like, walk me down the path that you arrived to, however it is, right?

34:55.350 --> 34:58.310
And so he walks me down this path.

34:58.310 --> 35:01.450
But I'm a guy that, I gotta look at the data, right?

35:01.450 --> 35:05.150
I can't just take somebody else's word off the phone.

35:06.290 --> 35:17.550
And so one of the big things that he pointed me out to was the file in question had a hit in VirusTotal.

35:17.550 --> 35:21.490
And it was tagged by Thor APT scanner.

35:21.490 --> 35:29.010
And it was tagged FancyBear, which is supposedly Russia, right?

35:29.350 --> 35:32.010
Whether it is, whether it isn't, I don't know, but either way.

35:32.050 --> 35:38.730
So that's what he, and we'll just say that it is just for the matter of fact, because he's like, yeah, we got it, we're Russian, blah, blah, blah.

35:38.790 --> 35:40.470
So it says it's tagged by FancyBear.

35:40.470 --> 35:42.970
And it says it's MAL, MAL FancyBear.

35:43.090 --> 35:49.410
And it says CompuTrace agent, or computer, yeah, CompuTrace agent.

35:49.410 --> 35:55.110
And so I'm looking at these files, and they look like malware.

35:55.110 --> 35:57.170
They really look like malware.

35:57.170 --> 36:00.250
The loaders are doing this crazy stuff.

36:00.250 --> 36:03.590
They're using an undocumented API.

36:03.590 --> 36:06.970
It's an arbitrary binary loader.

36:07.590 --> 36:12.870
And it really looked like malware.

36:12.870 --> 36:15.750
Just something that you wouldn't normally do, right?

36:15.870 --> 36:18.450
And so I'm tearing through it, I'm tearing through it.

36:19.310 --> 36:23.750
And for a good like three hours, I'm like, maybe we did get hacked, right?

36:23.750 --> 36:24.890
Maybe we did.

36:25.010 --> 36:28.890
But I was like, I got to see this through the end, right?

36:29.190 --> 36:33.610
And by this time, I think it was like 12 o'clock at night, day before Thanksgiving.

36:33.750 --> 36:35.850
Got to get the family up the next morning, right?

36:35.850 --> 36:37.150
I'm not giving up.

36:37.550 --> 36:47.310
And good thing that the person who wrote the rule, or at least I traced it back to where the source came for the rule.

36:47.310 --> 36:54.070
Good thing, he actually uses a lot of things that I kind of preach, which is a good naming convention.

36:54.770 --> 36:59.770
And also having good complete descriptions and whatnot.

36:59.770 --> 37:03.250
And then also sourcing where your information came from.

37:03.330 --> 37:07.890
So I noticed that this author, I'm not going to say his name, because I actually do respect him a lot.

37:07.890 --> 37:10.350
But we're all human, we all make mistakes.

37:11.030 --> 37:15.370
And it came from a report from Arbor Networks.

37:15.370 --> 37:20.270
And so I was like, let me go back to this report that Arbor has.

37:20.270 --> 37:21.950
And let me read their report.

37:22.450 --> 37:27.390
And I probably read that report like four times.

37:27.410 --> 37:28.830
Really, like four times.

37:28.830 --> 37:30.150
I'm like, what is going on here?

37:30.150 --> 37:31.690
What is going on here?

37:31.890 --> 37:37.210
And at the end of the report, they give a YARA rule.

37:37.210 --> 37:52.650
And I'm looking, and I'm looking, and I'm like, this YARA rule looks similar to the YARA rule that Thor APT scanner used to kind of make this attribution.

37:52.710 --> 37:59.610
And the name of the rule, and hats off to Arbor as well, they're doing good naming conventions.

37:59.990 --> 38:01.850
They're doing descriptions.

38:01.850 --> 38:04.470
Now, they didn't source anything, but that's fine, though.

38:06.810 --> 38:11.770
And the name of the rule just says CompuTrace agent.

38:11.770 --> 38:13.330
And I'm like, well, wait a second.

38:13.330 --> 38:15.890
So I had to kind of dig more and dig more.

38:15.890 --> 38:29.550
And turns out that what was going on was Fancy Bear was taking this CompuTrace agent, and they were patching the beacon, the domain beacon.

38:29.550 --> 38:31.170
That's all they were doing.

38:31.170 --> 38:39.850
And a normal CompuTrace agent, DLL, different from a Fancy Bear was only 28 bytes.

38:39.970 --> 38:42.590
And then it was XORed, so it was obfuscated.

38:42.590 --> 38:48.710
And so since it was obfuscated, you can't pre-predict what those domains are going to be.

38:48.710 --> 38:53.470
So how do you signature the unsignatureable, right?

38:53.470 --> 38:58.130
There is no real code in there that's attributable to Fancy Bear.

38:58.130 --> 39:01.410
So this was a CompuTrace binary.

39:03.790 --> 39:10.650
And so it took me a while to kind of tear it down and to kind of come to this discovery, did a byte-by-byte comparison.

39:10.650 --> 39:13.950
And finally, I was like, no, we didn't get hacked by the Russians.

39:14.190 --> 39:19.570
It's just whoever we have, like one box in the network that has this CompuTrace software running.

39:19.630 --> 39:22.510
Let's go get the IT department, let's clean it up and whatnot.

39:22.510 --> 39:29.410
And so, and to Thor APT Scanner's kind of credit, he...

39:29.410 --> 39:33.330
So this was the day before Thanksgiving, so that's November 2018.

39:33.690 --> 39:39.990
And then on March 2019, he actually renamed the rule.

39:40.330 --> 39:43.190
He changed it instead of MAL for the first three.

39:43.190 --> 39:47.950
He changed it to PUP, which is Potentially Unwanted Program.

39:48.090 --> 39:50.910
Thanks to a colleague of mine, I was like, what is PUP, right?

39:50.910 --> 39:53.990
And even I was like, I'm a seasoned guy.

39:53.990 --> 39:55.190
I was like, what is PUP?

39:55.190 --> 39:59.570
And I was like, what does that make any difference?

39:59.570 --> 40:03.950
Well, it... but he still got the fancy bear attribution in there.

40:04.030 --> 40:11.670
And that rule, once you look at it, it's hitting on all these CompuTrace binaries in VirusTotal.

40:11.670 --> 40:13.810
Maybe it's running in reversing labs as well.

40:13.810 --> 40:22.750
So anybody who goes and looks up a CompuTrace binary in VirusTotal, they're going to get false attribution of fancy bear for this binary.

40:22.750 --> 40:26.990
And then they themselves will be think they got hacked by fancy bear.

40:26.990 --> 40:32.030
And so you see that domino effect of, you know, the just prop...

40:32.530 --> 40:49.910
doing things kind of proper, taking your time, you know, making multiple detections and, you know, doing proper naming conventions and whatnot, and just kind of slowing it up a bit and not having that one rule to kind of rule them all mentality.

40:50.070 --> 40:52.730
And so that's kind of my story.

40:53.110 --> 40:57.990
Does anybody kind of have any questions or anything or what?

41:22.670 --> 41:29.410
I would say, yeah, maybe you can do some automation into it and look at ratios and whatnot.

41:30.210 --> 41:35.090
I kind of, when I do my circular detections, I do a lot of bytecode optimizations.

41:35.450 --> 41:38.950
And I'll look back at the assembly table.

41:39.030 --> 41:42.530
Take a look back at my previous talk and I talked a little bit about it.

41:42.530 --> 41:43.850
But where do you stop?

41:43.850 --> 41:49.130
Yeah, it's most of the time it's kind of by the analyst because most of us, I mean, we're all pretty bad.

41:49.170 --> 41:52.010
We're doing things, we're hand jamming things.

41:52.270 --> 41:59.050
Most of us probably should be, you know, because we all, a lot of the SOC people, they're just getting things on a whim.

41:59.390 --> 42:07.790
And, you know, if they write a script, take an hour out of their time and write a script, they may never use that script again and do any kind of automation with it.

42:07.790 --> 42:11.830
But with the rules that you're doing, you can do some triage up front.

42:11.830 --> 42:13.090
But yeah, where do you kind of stop?

42:13.090 --> 42:14.950
It is kind of up to the analyst.

42:14.950 --> 42:18.590
You just got to find that line within your workflow, I'd say.

42:18.650 --> 42:37.470
If you do have it in a malware shop and you got a big, a much bigger automated workflow, then I'd say, then you got to need to see, you know, give it some thresholds or something like that and say, Hey, you know, I got some malware that in my eyes is pretty rare and whatever the source that may came from.

42:37.530 --> 42:44.630
And let's say if I get a hundred hits on it, I'll, I'll just stop right there, right?

42:44.630 --> 42:52.410
If I get a hundred hits, because probably more than it's a high confidence, very targeted sample.

42:53.250 --> 42:58.770
Why are there going to be a hundred hits out there, you know, or you get a thousand, you can bump that up to a thousand maybe.

42:58.770 --> 43:05.250
And so once you kind of get to that, that level, you can kind of say, okay, yeah, this is a lot of noise.

43:05.250 --> 43:14.810
But then once your rule set gets more mature, you can leverage more of your rule set to kind of give you that other feeling.

43:14.810 --> 43:17.530
So you don't, you're not really always relying on the numbers.

43:17.530 --> 43:18.570
Does that kind of make sense?

43:19.530 --> 43:22.390
So at least in my, that's my point of view.

43:22.450 --> 43:23.430
So, yeah.

43:24.390 --> 43:25.930
Any other questions?

43:31.660 --> 43:33.040
I know it was a lot, guys.

43:33.040 --> 43:36.140
And I thank you and thank you for, for all the people that have stayed.

43:36.340 --> 43:38.480
A lot of technical stuff.

43:38.480 --> 43:39.940
Go back and watch it.

43:39.980 --> 43:42.280
A lot of text on there.

43:42.480 --> 43:44.440
Chew on some of those YARA rules and whatnot.

43:44.440 --> 43:46.340
If you haven't played with it, play with it.

43:46.340 --> 43:47.500
It's a great thing.

43:47.600 --> 43:49.680
Regular expressions too and whatnot.

43:49.680 --> 43:50.860
So, yeah.

43:51.280 --> 43:52.320
Thank you, guys.

