WEBVTT

00:00.000 --> 00:06.920
Both of these folks have a pretty extensive background, so I'm just going to cover some of it, introduce them.

00:07.060 --> 00:16.360
But before I do that, quick show of hands, how many people are doing threat hunting in memory, looking for hostile actors in memory, right?

00:16.360 --> 00:19.340
So it's a difficult problem.

00:19.860 --> 00:25.300
And so I'm really, really excited to personally to hear this talk.

00:25.300 --> 00:30.380
This is an area that needs a whole lot of work to be done in it.

00:30.380 --> 00:40.760
And it's, you know, folks like Carlos and Marcos that are, you know, on the edge of providing this kind of content for us.

00:41.140 --> 00:44.980
So Marcos is a software architect at McAfee.

00:45.140 --> 00:57.580
He's leading the development of exploit prevention technology components, which are part of the company McAfee's next generation flagship product called Endpoint Security.

00:57.580 --> 01:03.960
Marco also led the organization of the first ever B-Sides conference in Cordoba, Argentina.

01:05.220 --> 01:19.740
Carlos is an experienced InfoSec analyst who drives strategic initiatives and provides thought leadership and insight regarding the ever-changing global landscape at Claro America Mobile Offices in South America.

01:19.740 --> 01:32.080
He organized the One Hack Para Los Chicos local security conference, and is now working on organizing the first ever B-Sides conference in Cordoba, Argentina.

01:32.220 --> 01:38.600
So great, great to have these folks come and share their research with us.

01:38.600 --> 01:40.120
Give them a round of applause.

01:40.620 --> 01:41.800
Thank you.

01:46.120 --> 01:47.160
Okay.

01:48.020 --> 01:56.140
Thank you all for being here, and thank you for attending this call, this talk, and thank you Blue Team Villas for having us here.

01:56.380 --> 02:02.440
This talk is going to be about this project that we started like a year ago called Memhunter.

02:02.440 --> 02:12.000
For us it was really a way to learn and new and past code injection techniques and process manipulation in general.

02:12.000 --> 02:23.220
And also it was a way for us to explore and how to cope up with a problem that we were having on the field, which was around doing this threat hunting process in memory at scale.

02:23.280 --> 02:28.380
So we will talk about that during the slide, and we'll talk about the problem that we are trying to solve.

02:28.420 --> 02:30.580
So this is the agenda for today.

02:30.880 --> 02:37.580
So probably we will skip the first slide, and then introduction part.

02:37.580 --> 02:43.420
Then we will jump into the why, the how, and the what part of this issue.

02:43.420 --> 02:48.000
So on the why, we will dive into why hunting in memory is important.

02:48.120 --> 02:54.480
At least from our perspective, I will leave some, some, some hints on that.

02:54.500 --> 03:08.340
Then on the how part of things, we will discuss on the how someone can go and hunt for this stuff in memory by looking at specific properties of the processes.

03:08.500 --> 03:12.980
And then on the what part of the agenda, we will discuss the tools.

03:12.980 --> 03:18.280
And this tool that we have created called Memhunter, we will discuss on the characteristics of the tool.

03:18.280 --> 03:23.640
And we will also talk about the, on the, the current state of the tool and then the future.

03:24.000 --> 03:27.000
Uh, and we will wrap up everything with a, with a demo.

03:27.140 --> 03:28.820
Uh, with two demos actually.

03:29.740 --> 03:31.500
Okay, uh, about us.

03:31.500 --> 03:32.180
So, okay.

03:32.180 --> 03:32.720
Do you want to?

03:32.720 --> 03:33.080
Yeah.

03:33.140 --> 03:34.600
Uh, hello.

03:34.620 --> 03:35.720
Thank you for coming.

03:35.720 --> 03:37.260
Uh, I'm Carlos.

03:37.260 --> 03:38.160
He's Marcos.

03:38.160 --> 03:41.000
Uh, he's a Infosec lover.

03:41.260 --> 03:44.840
Uh, he, he working in McAfee.

03:44.840 --> 03:47.300
Uh, he's a software architect.

03:47.300 --> 03:48.900
Sorry for my English.

03:49.300 --> 03:51.340
Uh, we, okay.

03:51.340 --> 03:55.480
Uh, we, we are a B-site Cordova organizations.

03:55.540 --> 03:56.280
Okay.

03:56.280 --> 03:58.640
And I work in, in Arsec.

03:58.640 --> 04:00.980
It's a startup of Infosecurity.

04:00.980 --> 04:01.880
Okay.

04:01.880 --> 04:02.480
Okay.

04:02.480 --> 04:02.880
Yeah.

04:02.880 --> 04:03.540
Thank you.

04:03.540 --> 04:04.380
Thank you, Carlos.

04:04.380 --> 04:06.280
So why, why hunting in memory?

04:06.380 --> 04:09.560
So, uh, couple of things here.

04:09.560 --> 04:12.960
So memory, why hunting in memory these days?

04:13.200 --> 04:19.920
Uh, it's, it's a, I mean, hunting in memory is an important thing because of, uh, the shift that we haven't seen on the threat landscape.

04:19.920 --> 04:24.200
So the threat landscape, uh, uh, has evolved over the last few years.

04:24.200 --> 04:31.620
Mainly the, the attackers have really started to, to adopt new techniques, to, to, to adopt new things, to evade the, the current detections.

04:31.620 --> 04:43.400
So they shifted their, their, their, their attacker, attacker threat graph from, uh, a, a purely fail-based, uh, uh, approach to a file-less, uh, base approach.

04:43.520 --> 04:54.320
Um, so one, one trend or, or one aspect of, uh, this, uh, evolution is what we call the different, uh, vectors that attacker, that they are using for that.

04:54.320 --> 04:58.280
So one of these vector is, uh, what I call the process manipulation.

04:58.860 --> 05:05.980
Uh, so as part of, uh, the process manipulation, there are several things that attackers do in order to evade the current defenses.

05:06.200 --> 05:12.780
Um, one of those manipulations, uh, are what, what is called the, the call injection, right?

05:12.780 --> 05:16.980
There, there is another type of process manipulation called, uh, defense evasion.

05:16.980 --> 05:19.540
So we'll touch on that during, during the, the presentation.

05:19.540 --> 05:32.440
What I wanted to mention here is that mainly because of this trend is what, uh, uh, people working on the blue side of the house have to, uh, uh, come up with a new, new way to, to detect this, uh, this stuff.

05:32.500 --> 05:45.240
And another thing that, which is actually quite important is the fact that, uh, in the past, uh, these, uh, techniques, this, especially the call injection techniques, they used to be, uh, uh, something that was only available for, you know, these big,

05:45.240 --> 05:49.640
uh, sponsor, uh, APT groups, mostly national state groups.

05:49.640 --> 06:02.640
Uh, and they, they know, uh, how to take advantage of this just to avoid, you know, being detected and being spot, uh, spotted, uh, on, uh, you know, on their, uh, on their, uh, uh, intrusions.

06:02.800 --> 06:05.680
Um, but nowadays that, that is not actually the case.

06:05.680 --> 06:10.020
Nowadays it's, uh, call injection techniques especially are, are, are a commodity.

06:10.020 --> 06:18.320
I mean, uh, anyone can go to GitHub, for example, and grab, you know, the latest and, and greatest, uh, call injection and include it on their code.

06:18.340 --> 06:25.540
So accessing to these, uh, these techniques, uh, are, are, are available to anyone, uh, right now.

06:25.560 --> 06:32.360
Uh, so that's why we, we need to, uh, start thinking on including, uh, ways to, to detect this stuff, uh, on memory.

06:32.400 --> 06:38.880
So going, going back to the file list, uh, uh, uh, state that I, that I just mentioned.

06:38.940 --> 06:46.840
So there are, uh, I, I, I really like this, uh, diagram that was taken from, uh, uh, uh, a sans, uh, uh, uh, white paper.

06:46.840 --> 06:55.920
So the idea here is that, uh, from the diagram you can see where call injection came into the, into play, uh, on the file list, uh, attack, uh, scenario.

06:55.920 --> 07:06.840
So you see that call injection is used, uh, as part of, uh, uh, I mean it's mostly used, uh, uh, this, this series of techniques are mostly used as stages on, uh, stages of attack.

07:06.840 --> 07:20.400
So, uh, for example in the, this, uh, scenario where we got a remote code execution, uh, attack where, uh, someone is executing, uh, executing, uh, execution on our, on our, uh, uh, endpoint.

07:20.400 --> 07:34.040
An example of this is, uh, the, the WannaCry example, for example, where, where we have, uh, the SMB vulnerable driver, driver, and then, uh, uh, by exploiting, uh, that vulnerability someone can get, uh, code to execute an, an, an endpoint.

07:34.040 --> 07:52.100
And then they, they will most likely use, uh, uh, they, they will mostly, uh, uh, trigger the second stage of that attack by, um, by injecting, uh, their malicious payload into the memory, the user's main memory of, uh, running process, the system process,

07:52.100 --> 07:52.900
most likely.

07:52.900 --> 08:08.500
So in the case of WannaCry, for example, they use a technique, uh, called QueueUserAPC, which allows them to, uh, um, um, to, uh, execute code, to inject code into the context of, uh, Elsa's, uh, from, uh, kernel space.

08:08.500 --> 08:14.560
So, uh, so in that case, uh, code injection was used as a, as a second stage of an attack.

08:14.560 --> 08:25.540
And, uh, and the most, uh, common attacks that we are seeing nowadays, which are mostly driven by download, download, we see that code injection is used as a second stage of the attack.

08:25.540 --> 08:35.760
So, uh, the attacker, uh, uh, gain, uh, code execution through a Word document, for example, just by having, uh, the user to open a, a, a, a document with a macro.

08:35.760 --> 08:46.180
Then the, the macro will exercise some Win, Win32 APIs and then the, the injection will happen and the attacker will be able to, uh, run code in the context of a different process.

08:46.180 --> 08:50.600
So that's where code injection is, uh, actually, uh, a thing nowadays.

08:51.080 --> 08:55.300
So, uh, yeah, so we, we know what, what, uh, these techniques are.

08:55.380 --> 08:57.620
We know how to catch them, actually.

08:57.620 --> 09:02.160
Uh, but why, why is that difficult to, to hunt for this stuff, uh, at scale?

09:02.160 --> 09:11.980
So the, the, the, the, the problem came, uh, on the, uh, tools and tech, uh, yeah, on the tools and frameworks that we have to hunt for, for this stuff.

09:12.020 --> 09:22.100
So, uh, currently the, the, I mean, you, you have, I mean, if you want to hunt for this stuff, you only have, uh, two ways, uh, from what I, from my point of view.

09:22.200 --> 09:28.140
You either go and buy, uh, uh, uh, an expensive EDR product that supports these, uh, techniques.

09:28.140 --> 09:42.580
There are several EDR products out there that, uh, either does, uh, uh, memory inspection, which is the, the same, the, the same thing that I'm doing with this tool, or, uh, memory scanner and they, they do, uh, you know, dump, uh, pattern matching on the memory of,

09:42.580 --> 09:47.680
uh, the, the different processes to look for IOCs and see if, uh, there is an injection going on.

09:47.700 --> 10:02.920
So you either have to go and do that or you get, uh, volatility and you get a full memory dump of the machine that you want to analyze and take that full memory dump, uh, uh, uh, into the volatility framework, uh, uh, and, and, and run the different, uh,

10:02.920 --> 10:08.420
uh, scanners that volatility have in order to detect for this stuff on the, on that, on that dump.

10:08.420 --> 10:11.060
The problem with that approach is that it, it doesn't scale.

10:11.060 --> 10:22.480
I mean, if you want, if you, if you have to do that, you have to go to the machine that you, uh, think, uh, might contain some, some, some of, uh, of, uh, of, uh, something living in memory.

10:22.480 --> 10:26.560
You have to dump, uh, you have to get a full memory dump of that machine.

10:26.560 --> 10:32.880
You have to grab that memory dump into a forensic environment and then analyze the stuff in there.

10:33.100 --> 10:37.460
The problem with that, uh, is that, um, you cannot do that scale.

10:37.460 --> 10:42.360
You cannot do that, uh, every day on, on your organization, on any machine on your organization.

10:42.420 --> 10:46.460
So mainly because of that, uh, we, we created this tool called, uh , Memhunter.

10:46.460 --> 10:54.280
So what Memhunter will do, so I'm just giving a, a, a brief spoiler because we are seeing that in, in detail in a moment.

10:54.280 --> 11:03.060
But, uh, what Memhunter will do is that it will perform what is called a memory inspection on every processes on the, uh, every process on the endpoint.

11:03.060 --> 11:13.920
And it will apply the same type of heuristics, uh, and, and, and an extra couple of more, uh, that, uh, that detects for this stuff in memory and it will report that back to you.

11:14.000 --> 11:24.860
Um, so through that you can, uh, run this, uh, periodically either as a service or on demand and get the results of, uh, your entire organization, uh, at scale.

11:25.020 --> 11:27.460
So, okay , so we just talked about the why.

11:27.460 --> 11:34.540
So now we will talk a bit, uh, about the how, uh, we can hunt for this stuff, uh, in memory.

11:34.700 --> 11:52.980
So on the how part, we will, uh, mention, uh, uh, a bit , uh, we will, we will, uh, sorry, we will, we will do a quick overview on the, on the, on what the process manipulation is, what the properties of a process are affected by a process manipulation and a code injection techniques.

11:53.080 --> 12:05.880
And then we will also describe, uh, uh, we will also give, uh, a few, uh, give you a few details on, uh, how a process is created, uh, on the, when, uh, on the, on the Windows, uh, environment.

12:06.220 --> 12:08.880
So talking about, uh, process manipulation.

12:09.060 --> 12:24.080
So process manipulation is, uh, is, uh, for me is, uh, uh, uh, an umbrella term that can be used for any type of, uh, technique used to compromise a legitimate, uh, process and have it to execute malicious code.

12:24.080 --> 12:30.140
So you can do that, uh, either by, uh, performing a code injection through memory location or memory writing.

12:30.140 --> 12:34.320
You can do that by, uh, getting, forcing the process to execute something.

12:34.320 --> 12:44.020
Or you can do that through, uh, mechanism that are available , uh, in the Windows environment to force a DLL to, to be loaded, uh, during the process start.

12:44.300 --> 13:02.140
Uh, so going into the Win32, uh, process internals, uh, the thing that I want to, that I want you to take from here, I mean we can spend hours talking about this, but, uh, the most important things for, for this talk is the fact that, uh, the Windows kernel is,

13:02.140 --> 13:18.480
is the one in charge of, uh, allocating the, I mean when a process is started, uh, uh, the, the Windows kernel is the one in charge of, uh, creating, uh, what is called a, a, a process, uh, uh, a process object that will take care of, uh, the different,

13:18.480 --> 13:21.460
uh, uh, areas that that process container will have.

13:21.460 --> 13:30.500
Uh, along, among those areas, uh, there will be, uh, memories, uh, areas, uh, designated for the different threads that will run within that process.

13:30.620 --> 13:39.900
So every thread, uh, which are, by the way, the ones that will be running code, I mean the process itself, uh, is not running any code, just the thread, the ones that are running the code.

13:40.060 --> 13:44.500
So the, the, there will be a, a, a call stack, uh, uh, designated for every thread.

13:44.540 --> 13:59.420
There will be also a, a, a, an area within the process internal called PEV, which is a process environment block that will contain information on the common line used for the process, the, some, uh, information about the, the, the, the properties of the image file,

13:59.420 --> 14:03.120
um, yeah, and a couple of other things that we'll mention in a second.

14:03.120 --> 14:15.260
Then there will be areas around, uh, that, that will, that will hold information, um, uh, regarding the, the, the dynamic, uh, uh, uh, libraries that will, that the process will load.

14:15.420 --> 14:33.360
Uh, and within those, uh, dynamic libraries, uh, I wanted to mention that every library loaded, uh, within, uh, uh, uh, Windows process will have, uh, will follow what is called a PE format, which is a format described by Microsoft to, uh, load stuff in memory.

14:33.500 --> 14:39.160
Uh, so that, that is going to be important for one of the, the, the things that we'll be discussing in a second.

14:39.300 --> 14:42.800
So, uh, just to wrap up a couple of things that I just mentioned.

14:42.800 --> 14:53.080
So the process properties, uh, the thread properties, and the memory properties are the things that define, you know, the normal or standard behavior of a, of a process.

14:53.920 --> 14:59.880
Uh, so, okay, so why, why I am mentioning this and why I put in so emphasis on, on this?

14:59.880 --> 15:16.260
It's because of the fact that we will use that as a way to, uh, detect, uh, anomalies, uh, in the, in either the process properties, the thread properties, or the memory properties to, to, uh, and we will use that, that to, to hunt, uh, for stuff in memory.

15:17.000 --> 15:21.760
So I'm giving three examples here as a bit of a spoiler.

15:21.840 --> 15:32.940
Uh, we will discuss this in, in a bit more detail in a second, but, uh, the idea is that, that, for example, uh, as I mentioned, every, uh, piece of code that you run in a process, uh, have to run in a thread.

15:33.020 --> 15:42.440
So you can, you, you will, you will run in a normal scenario that that thread will have to run from code that is actually backed by a file on disk.

15:42.520 --> 15:57.800
So usually what, what is happening is that, uh, you, you have your process, you load your process, uh, and the, uh, you create threads, uh, and that thread, those threads have to run from code that they will be, uh, uh, that will be part of the main module,

15:57.800 --> 16:04.200
the main executable, or they will be part of, uh, DLL, uh, within the, uh, that, that was loaded by the process, right?

16:04.200 --> 16:14.200
So, uh, uh, there might be scenarios, uh, where the process, uh, is not running, uh, sorry, that the thread is not running from, uh, code that is backed on disk.

16:14.200 --> 16:27.060
And those scenarios are mostly, uh, no, not 100 percent of the cases, but are mostly caused by, uh, these, uh, by the side effects, uh, uh, on the, on the artifacts left by these, uh, code injection techniques.

16:27.060 --> 16:45.660
So whenever we found a thread whose start address is not, is running from memory that is not backed by disk, we might say, okay, you know, this heuristic, because we call that heuristic, the heuristic might, might, might be telling us that there might be something suspicious on that thread that might require further attention,

16:45.660 --> 16:48.360
and that's what the tool will actually report.

16:48.360 --> 16:56.340
So the tool will basically, uh, flag those processes with anomalies for ThreadHunter to go and look, uh, in detail.

16:56.520 --> 17:06.460
Uh, another, uh, potentially, uh, another, uh, anomaly that we might end up using is the memory permissions for the base address of, uh, the threads.

17:06.700 --> 17:20.600
So, uh, the threads are supposed to be from, uh, memory regions that are marked as, uh, read, uh, um, execute, but there might, there are code injections that left those memory regions marked as, uh, read, write, execute.

17:20.680 --> 17:27.340
So that goes, uh, uh, the, the, uh, that will cause, uh, one of our heuristics to, to, to fire, basically.

17:27.500 --> 17:37.380
Then, uh, in terms of, uh, memory properties, uh, we can also look for, uh, uh, as I mentioned, uh, memory regions, uh, with, uh, read, write, uh, execute permissions.

17:37.580 --> 17:53.080
We can also look for all allocations, so whenever you allocate a, a piece of, uh, uh, allocate and commit, uh, um, a piece of, um, virtual memory within the context of a process, there will be two, uh, meta, meta data fields within that memory regions that will indicate the,

17:53.080 --> 18:07.580
the state of, uh, those, uh, um, of, uh, of, uh, the, the, the, sorry, the, the protections, the, yeah, the, the, the state of, uh, that memory region, I mean, is that memory region is, uh, read, write, execute region or, or something else.

18:07.680 --> 18:23.980
Uh, so there, there are cases, uh, that, uh, techniques, uh, initially allocates, uh, the memory region with, uh, read, write, execute and then, uh, uh, call, uh, uh, a Win32 API called virtual protect to move those memory regions back to read, execute so it can look,

18:23.980 --> 18:24.760
uh, legit.

18:25.000 --> 18:33.880
Uh, but there, uh, there is a flag within those, uh, memory regions meta data that will still contain the initial allocation, uh, uh, value.

18:33.880 --> 18:43.840
So by looking into the, uh, mismatch between those values is, uh, is a way to, to, to determine if there have been a, a potential injection in place.

18:44.060 --> 18:49.440
Uh, then, uh, in terms of memory content, uh, there are a couple of things that we can do here.

18:49.440 --> 19:00.140
Uh, I mean, one thing is just go and do, you know, the regular DOM, uh, IOC match, which is, uh, effective, but it's, but it's very costly in terms of, uh, performance.

19:00.180 --> 19:06.420
So there, there are EDR vendors that, uh, you know, have, uh, modules that are specialized on doing this.

19:06.420 --> 19:18.760
They are mostly running, uh, drivers, uh, that scan the memory of the process and looking for specific patterns and, and flag, you know, uh, uh, a threat event whenever something, uh, malicious is found.

19:18.760 --> 19:21.780
In our case, uh, we, we were not able to do that.

19:21.780 --> 19:26.400
Again, mainly because of performance reason, Memhunter is just a user space application.

19:26.820 --> 19:34.060
So we, uh, we cannot afford, you know, just going and scanning, uh, the memory of the entire memory base of a, of a process.

19:34.200 --> 19:40.420
So, uh, mainly because of that, what we are doing is something called, uh, the virtual query walk.

19:40.420 --> 19:46.740
So what basically, uh, what we're doing is that we are walking the different memory regions of every process.

19:46.740 --> 20:00.020
And then in some cases we are looking for, you know, just a few, uh, f-f-fierce, uh, uh, bytes within those memory regions, uh, looking for, uh, you know, signs of, uh, uh, P file within that, that, that region.

20:00.020 --> 20:05.240
Like, uh, looking for the MC header, uh, within the, those, those f-f-fierce, uh, few bytes.

20:05.240 --> 20:12.460
Or we look for, uh, you know, uh, uh, associated, uh, strings, uh, left by a Tagger thread graph.

20:12.460 --> 20:22.140
Uh, but again, uh, this is, uh, uh, optimized just to look for a specific stuff and not for entire content of, uh, the memory region.

20:22.140 --> 20:36.600
Okay, so, uh, having said that, uh, we will jump into, uh, two examples of, uh, both code injection, uh, and, and, uh, uh, and, and defensivation, uh, approaches.

20:36.820 --> 20:40.400
Uh, the, these examples are actually not quite new.

20:40.400 --> 20:43.360
They have been in the, in the field for quite some time now.

20:43.460 --> 20:47.660
Uh, the, the first one is, uh, reflective DLL injection.

20:47.740 --> 20:56.020
So reflective, uh, DLL injection, uh, is, uh, is a technique that got, uh, popularized, uh, a few, a couple of years back.

20:56.020 --> 21:00.120
It was, uh, created and released by a guy from Germany called Stephen Feuer.

21:00.200 --> 21:18.360
Uh, what this technique, uh, was to, uh, I mean the, the purpose of the, this technique was to, um, allow the, the, the, the, the, yeah, mostly the, the, the people interested on this kind of approach to unload code, uh, uh, in the context of a remote process just by using a DLL.

21:18.360 --> 21:32.680
So the idea is that you get the, the reflective DLL framework , you create the DLL, you include a part of that framework within your code, uh, compile your DLL, and then, uh, the, the result of that compilation is something that you can embed into the,

21:32.680 --> 21:41.600
uh, the, your, your attacking process or, uh, something that you can read, read from, from the file system in, in, if that, that is what you, you wanted to do.

21:41.600 --> 21:53.440
But the idea is that once you get that, that, that load of, load of data into the context of, uh, the attacking process, you will write, you will write that, uh, that up into the victim process.

21:53.640 --> 22:01.480
Uh, actually, sorry, uh, you, you will allocate first, you know, the, uh, read, write, execute, uh, uh, big chunk of memory in the context of, uh, remote process.

22:01.480 --> 22:12.300
Then you will write that down into the context of, uh, remote process and then you will spawn a thread, a new thread, uh, that will run out of, uh, that, uh, that floating read, write, execute, uh, code.

22:13.700 --> 22:26.900
Uh, one of the biggest, uh, biggest or then most well-known, uh, consumers of, uh, these techniques was, uh, Metasploit on, with this, uh, Meta interpreter, uh, payload.

22:26.960 --> 22:34.660
So initially they, they used this to move, uh, their, their, their payload around, you know, processes using this technique to go in a pure file-less way.

22:34.860 --> 22:38.500
Uh, nowadays, uh, I think that they are using it as a kind of a fallback.

22:38.500 --> 22:45.500
They, they, I think that they start with a different technique, the Q-user APC one, and then use this as a fallback in case the previous one fails.

22:45.900 --> 23:02.380
Um, but, uh, yeah, but, uh, yeah, but, but the thing, uh, the important thing here is that the anomalies that this technique will introduce, uh, within the context of the process is that, that after the technique is executed, you will run, uh, a new thread running from,

23:02.380 --> 23:04.020
uh, floating code, right?

23:04.020 --> 23:18.140
So there will be a big, uh, a new thread that was not there before and the base address of that thread will be, uh, uh, uh, uh, uh, code, uh, memory region marked as read, write, execute, which, which is not, uh, backed, uh, by a model on disk.

23:18.180 --> 23:29.620
Then if you look into the code stack of that thread, there will be a stock frames that will, again, will be not, um, uh, backed by a symbol, uh, uh, uh, by, uh, on, uh, one of the models on disk.

23:29.620 --> 23:46.420
And that basically means that, uh, uh, I mean for this particular technique, that basically means that, that thread, uh, uh, was created out of, uh, shellcode that, uh, in, in the case of, uh, this technique was used to bootstrap the, the malicious payload that you are,

23:46.420 --> 23:47.440
you are using.

23:47.440 --> 24:03.100
So basically the techniques, uh, simplifies that, uh, bootstrapping, uh, for you so you are putting your regular DLL code, uh, uh, and the bootstrapping code, shellcode will take care of, uh, uh, mapping sections, resolving import, uh, fixing up relocations,

24:03.100 --> 24:04.620
uh, yeah, couple of extra things.

24:04.620 --> 24:17.400
But the idea is that after, after the execution, uh, happens, uh, these three anomalies, uh, can be, will, can be seen, uh, will, I mean we will be able to see these three anomalies in the process.

24:17.840 --> 24:25.680
Okay, so, now, uh, jumping into, uh, defense, uh, evasion example, the process following one.

24:26.020 --> 24:35.820
So the idea here is that, uh, uh, you want to run, uh, you want to evade, uh, you know, the, the, the, the available, uh, endpoint protection stack.

24:35.820 --> 24:40.800
So you want to evade the, the AVs and the EDR, uh, most likely on the, on the endpoint.

24:40.800 --> 24:46.640
You want to, your, your malicious, uh, process to look as legit for, uh, these solutions.

24:46.900 --> 24:54.640
Uh, and, uh, yeah, and you want to use, uh, uh, uh, a legit process as a container for your malicious code.

24:54.720 --> 25:02.460
Uh, and this technique works by, uh, by again using, uh, legal, uh, Win32 APIs.

25:02.460 --> 25:05.760
So the idea is that you create a process in suspended state.

25:06.420 --> 25:18.440
Uh, then you get the, I mean, when, when a process is created in suspended state, uh, the, that process will not be assigned with, uh, any , you know, uh, time, uh, in the, uh, scaling time in the kernel.

25:18.460 --> 25:27.360
It will be just, uh, you know , freeze, uh, will, uh, with, uh, just, uh, uh, one, uh, single thread that will be also freeze.

25:27.360 --> 25:29.340
So nothing, uh, will, will happen.

25:29.340 --> 25:37.660
Then, uh, once you, the process is created in suspended state, you can get the, the, the execution context of that thread.

25:37.740 --> 25:46.060
Uh, from the execution context and by also wa- and, and by also working, you know, the memory of, uh, uh, of, uh, that, that process.

25:46.060 --> 25:52.960
Uh, you can, uh, with those two inputs, you can determine which is the main module of, uh, of, uh, for that thread.

25:53.180 --> 26:04.780
Uh, and then you can, uh, call this API called NT unmap view of section, which will end up, uh, unmapping, you know, the, the main module from, uh, from the, from the process.

26:04.900 --> 26:10.060
Uh, and then you, the, there are a couple of things, uh, that you can do, uh, that, at that point in time.

26:10.300 --> 26:18.300
Um, um, there are more basic ways of, uh, uh, uh, or, or writing the, the, your malicious payload into that process.

26:18.300 --> 26:31.880
In this case, and just for simplification, uh, I, I just, uh, mentioned that, uh, uh, one of the, uh, uh, one of the, uh, possibilities that the attacker can do, can follow, is that they can call virtual lock.

26:31.880 --> 26:35.500
Again, allocating a big chunk of, uh, read write execute memory.

26:35.640 --> 26:39.700
They can, they can, uh, write, uh, you know, the payload into that memory.

26:39.700 --> 26:52.740
And then they can, uh, redirect, uh, the, the, uh, the, the execution context of, uh, the, uh, the, the thread that is posed to this new, uh, memory region.

26:52.740 --> 26:55.000
And then they can resume, uh, the thread.

26:55.000 --> 27:02.340
So that will force the, your, uh, uh, the, the, the malicious, uh, the host, the host process to run your code.

27:02.340 --> 27:14.340
But at the same time as, uh, no other thing has been modified in the process, just the, uh, the, we, we just forced the, the, the victim process to run a different, uh, uh, module.

27:14.640 --> 27:22.940
Uh, the process will, for, for a basic system, um, for AR solutions, uh, they will, process will look like, uh, will look as, will look as legit.

27:23.000 --> 27:30.500
So the, the P, the PB, uh, uh, yeah, most of the, the stuff on the process will not be touched.

27:31.000 --> 27:33.940
Uh, yeah, so we will see that, uh, in a moment too.

27:34.460 --> 27:40.660
Uh, uh, so in, in terms of anomalies and, uh, and in terms of, uh, ways to detect this, uh, this stuff.

27:40.660 --> 27:59.120
So the, the most likely, the most, uh, uh, the, the, the best heuristic to detect, uh, something like this will be to, uh, uh, check, uh, uh, for the, uh, P header fields of the main module on memory versus the P header fields of the counterpart on disk.

27:59.120 --> 28:07.340
So by, by checking that, you can detect if, uh, uh, there is a mismatch with, uh, which, uh, should never happen.

28:07.340 --> 28:11.480
And if there is a mismatch, we can, uh, report that as something, uh, suspicious.

28:11.680 --> 28:12.720
So, yeah.

28:13.260 --> 28:16.200
Okay, so we just talk about those two examples.

28:16.200 --> 28:20.860
We will, we will just talk about the process properties and how we can detect stuff.

28:20.860 --> 28:32.920
We will now jump into the what part of, uh, the talk, which is around, uh, how to perform this as, uh, uh, at scale, uh, as part of our threat hunting process.

28:33.240 --> 28:36.560
Uh, and this is where we are introducing Memhunter.

28:36.560 --> 28:46.260
So, um, so this is a tool, uh, that we, I probably mentioned this already, but anyways, uh, uh, this is a tool that we, we, we started some, some time ago.

28:46.260 --> 28:54.620
And again, it was a, a, a way for us to, to explore on these, uh, techniques and ways, and ways to, uh, ways to explore these, uh, uh, capabilities .

28:54.700 --> 28:56.980
So, uh, so Memhunter.

28:56.980 --> 29:00.520
Memhunter is a tool that, uh, deploys itself as a standalone binary.

29:00.820 --> 29:09.980
Uh, it will, once, uh, the tool is running, it will, uh, perform a series of inspection heuristics, which are the anomalies thing that I was just mentioning.

29:10.320 --> 29:16.940
So, uh, and then whenever there is a find, finding, the tool will report that to the, to the user.

29:17.000 --> 29:20.520
So the idea is that you have all these, uh, this is the architecture of the tool.

29:20.520 --> 29:29.580
The idea is that you have, uh, uh, all these different heuristics in, in, uh, in the, in the, abstracted in this concept, uh, called, uh, Hunter Modules.

29:29.580 --> 29:33.440
So every hunter is specialized in one of, uh, one specific heuristics.

29:33.540 --> 29:42.140
And then, uh, there is, uh, uh, along with the, the hunters, there is a, a part of a company in the tool in charge of, uh, doing the, the process context enumeration.

29:42.180 --> 29:46.660
There is a part of the tool, uh, doing, in charge of doing the, the orchestration of the hunters .

29:46.700 --> 29:50.620
And there is a part of the tool in charge of getting the, the forensic data.

29:50.860 --> 30:05.940
Uh, something that I didn't quite mention is the fact that the tool can run, uh, either as, uh, as, uh, a standalone service, uh, which, uh, is mainly a way for, to, for the tool to get the, uh, the, the, the hunters to be driven by events.

30:05.940 --> 30:11.200
So we are using ETW to determine when the hunters will be triggered.

30:11.220 --> 30:24.660
So, for example, we are listening for, uh, uh, kernel providers, uh, from, uh, ETW kernel providers to, to determine if there is a process, uh, if a process got created, if a thread got created, if an image was load.

30:24.660 --> 30:30.720
So those, those kind of things will draw, will draw, uh, you know, some hunters to run on the context of a process.

30:30.880 --> 30:33.480
So that's, uh, the real time eventing way.

30:33.480 --> 30:39.960
And then you also have the point in time or standalone execution, execution analysis, which is the thing that we are going to demo.

30:40.040 --> 30:54.820
So the idea here is that you get the tool, uh, you, you get the binary of the tool, uh, uh, you run it without being privileged and the tool will perform the process enumeration and it will, uh, perform, uh, it will apply the heuristics over every, uh,

30:54.820 --> 30:57.060
process, uh, on the endpoint.

30:57.640 --> 30:59.740
Uh, okay.

30:59.740 --> 31:03.820
So, uh, currently, uh, the tool support nine hunter heuristics.

31:03.820 --> 31:06.760
So we will see that, uh, uh, in the next slide.

31:06.860 --> 31:13.800
Along with the tool, uh, I have also created as a way to exercise, uh, uh, the different hunter heuristics.

31:13.800 --> 31:21.520
I created, uh, this tool, uh, separate tool called M Injector, which is basically a test tool, which, uh, 15 code injection techniques.

31:21.880 --> 31:29.640
Uh, I'm probably going to include, uh, um, I need the new injection framework to add a couple of, uh, extra techniques.

31:29.640 --> 31:41.000
So there was a great talk yesterday on code injection, uh, in general, uh, which, uh, uh, they, they released a framework, um, which I cannot remember the name to be honest, sorry.

31:41.040 --> 31:45.200
But, uh, yeah, but, uh, anyways, uh, that framework is, is great.

31:45.200 --> 31:47.420
Uh, I will, I will, uh, I will start to use it.

31:47.420 --> 31:55.480
And then the, the tool will also, um, generate some even logs, uh, and it also support the, the, some, uh, baseline, uh, some exclusion.

31:55.480 --> 32:05.380
Because, uh, uh, as I mentioned that the tool will not give you data on which malware, which, uh, attacker, tradecraft is running on the endpoint.

32:05.380 --> 32:10.080
It will just give you a hint that there is something, uh, suspicious on the endpoint.

32:10.180 --> 32:13.540
So you have to go and, and, and find yourself, you know, what, what is going on.

32:13.560 --> 32:17.500
And that, uh, also means that the tool might end up reporting fault positives.

32:17.560 --> 32:23.200
So for both, for, for, sorry, for the fault positive scenario, you have to have a way to exclude some processes.

32:23.260 --> 32:31.920
Uh, the processes that most likely are going to cause fault positives are the, the process that, uh, use techniques, use these techniques for legit, uh, purposes.

32:32.060 --> 32:41.520
Example of that is, uh, the, the .NET processes, the managed processes, what, which use, uh, which compile things, uh, on the fly, uh, and have, uh, JIT compilers.

32:41.520 --> 32:50.500
There are also products, uh, uh, for, from security vendors that use code injection as a way to hook into stuff, uh, to monitor behavior and so on.

32:50.500 --> 32:52.860
So there might be some positives, fault positives.

32:52.860 --> 32:56.560
You have, uh, an exclusion, a way to baseline your, your environment.

32:56.680 --> 33:06.040
Okay, talking about the, the hunters, uh, as we have, uh, nine, uh, hunters, so we are running out of time for demo, so I will go really quick on, on this one.

33:06.080 --> 33:08.300
So the, the first one is a suspicious threat.

33:08.300 --> 33:13.240
It will look for the base, uh, uh, star address and it will check for read write execution flag.

33:13.240 --> 33:17.140
Suspicious call stack will look for, uh, symbols that are not backed.

33:17.140 --> 33:29.880
Suspicious memory regions, it will check for the first few bytes, uh, to, to look for, uh, you know, signs of, uh, uh, uh, uh, P models, uh, that was loaded or that currently been loaded and used.

33:29.960 --> 33:38.080
Uh, sufficient base address is something that indicates that the main model is running from private commit, uh, markup, uh, read write execute memory regions.

33:38.080 --> 33:41.240
Suspicious pair is, uh, the thing that I just mentioned.

33:41.240 --> 33:46.040
Uh, suspicious models, uh, models, uh, associated with, uh, read write execute memory regions.

33:46.180 --> 33:54.960
Suspicious hollow mo- hollow models is, uh, the, this, uh, cross check between the, the P header, uh, field from the memory versus the counterpart on disk.

33:55.200 --> 34:06.200
Uh, register persistent is just to, to look for, uh, stuff like, uh, this, uh, uh, functionality from Windows to force, uh, DLL to load into, uh, into remote process.

34:06.240 --> 34:16.240
Uh, and the last one, suspicious shellcode, uh, is, uh, mainly to look for, uh, the well-known products from 886 and 864, uh, you know, shellcodes.

34:16.240 --> 34:22.660
So, uh, there are, uh, good amount of shellcodes that start with the same set of, uh, opcodes.

34:22.680 --> 34:25.560
Uh, and this is something that I am develop- developing right now.

34:25.560 --> 34:35.040
So this is a, uh, you know, some evasions that have started to appear, uh, a couple of, uh, I think it was the last year, between last year and the, uh, the year before the last one.

34:35.040 --> 34:42.700
So ways to evade the EDR solutions like, uh, uh, parent PID spoofing, uh, and the, uh, and, uh, common line spoofing.

34:42.700 --> 34:48.720
So the way to do that is to, again, to cross check information from the OS with the current things, uh, on the PID.

34:49.180 --> 34:54.700
Okay, uh, this is, uh, the, the eventing information and this will be later available for reference.

34:54.880 --> 34:58.540
Uh, the set of information, forensic information that the tool reports.

34:58.560 --> 35:00.680
And after that, we will jump into the demo.

35:13.870 --> 35:16.830
Okay, so Carlos here will help me with the demo.

35:16.830 --> 35:17.770
Thank you, Carlos.

35:19.130 --> 35:32.090
Uh, okay, so the, the idea, uh, the idea, yeah, the idea is that we will look first at the, you know, the, uh, the expected behavior of a process.

35:32.210 --> 35:35.570
So Carlos will, will open, uh, uh, Notepad.

35:35.930 --> 35:40.070
Um, are you able to see?

35:40.070 --> 35:50.710
Yeah, so he, he will open Notepad with, uh, Process Hacker, which is, uh, really convenient tool to, to look for, you know, uh, the details on the property of, uh, of a process.

35:50.710 --> 35:58.550
Uh, and within, uh, um, Notepad, he will check for the running threads of the processes, uh, of, uh, that process.

35:58.550 --> 36:01.810
He will check for the call stack of those threads.

36:01.830 --> 36:13.330
And he will also, he, he will also check for the memory regions currently located just to, just allow you to see that there are no memory regions with, uh, read, write, execute, uh, permissions.

36:13.410 --> 36:22.430
And after that, uh, we will, uh, exercise the reflective DLL injection, uh, the technique that we, that we just mentioned.

36:22.710 --> 36:27.630
Uh, and we will come back again to the tool, to the Process Hacker tool.

36:27.670 --> 36:34.030
We will, we will look for the anomalies and then we will run Memhunter to see the, the thing that, that, uh, reports.

36:41.960 --> 36:43.920
Okay, just a second guys.

36:55.100 --> 36:57.220
Okay, we'll switch, uh, computers.

37:07.920 --> 37:08.800
Okay.

37:16.000 --> 37:17.240
Just a second.

37:17.240 --> 37:18.640
Okay.

37:18.640 --> 37:25.400
So we will use, uh, Win10 RS4 machine for, for this, uh, testing.

37:25.980 --> 37:28.700
Uh, yeah.

37:34.650 --> 37:36.170
Okay.

37:37.190 --> 37:39.270
Just one more second.

37:40.630 --> 37:45.390
Uh, there you go.

37:48.820 --> 37:54.080
Okay, so we have, uh, we have, uh, our environment over here.

37:54.740 --> 38:00.300
Uh, we will, as I mentioned, we will run, uh, Notepad first.

38:02.000 --> 38:05.600
Uh, then, uh, we will go and, uh, Process Hacker.

38:05.600 --> 38:07.720
We will check for the properties of Notepad.

38:07.840 --> 38:12.780
We, we see that, uh, there are a bunch of, uh, threads running because of, uh, Windows.

38:12.980 --> 38:20.460
Uh, but, uh, the important thing is that , that there is, uh, this thread running, uh, out of, uh, the main executable image from Notepad.

38:20.460 --> 38:23.240
If we open that thread, we can see the call stack.

38:23.260 --> 38:29.120
Uh, and the call stack, you see that all the, all the symbols in the call stack are mapped to a byte, uh, to a file on disk.

38:29.140 --> 38:30.020
Right?

38:30.260 --> 38:41.000
Uh, and then if we go and check the memory, uh, we will see that there are, I mean, no memory, uh, region with, uh, read, write, execute.

38:41.060 --> 38:46.580
There are only read, either, uh, read, read, execute, or read, write.

38:46.720 --> 38:59.600
Uh, and there is also memory regions with, uh, copy and write, uh, um, which are the, which is the thing that, um, uh, Microsoft use for the, his, uh, uh, copy and write, uh, capabilities.

38:59.640 --> 39:05.600
Uh, okay, so, uh, yeah, so let's, uh, go ahead and, and execute an attack against, uh, Notepad.

39:05.600 --> 39:09.560
So it's, Notepad is process 6020.

39:09.920 --> 39:14.060
So we will, uh, we will run this tool.

39:14.060 --> 39:18.040
So this is an M-injector tool, uh, supports, uh, 15, uh, techniques.

39:18.040 --> 39:22.420
I'm going to, uh, add a couple more, uh, after, uh, DEFCON.

39:22.640 --> 39:39.000
So if we run the, uh, the technique number 5, which is, uh, reflective DLL injection, and then we ask the tool to run, uh, payload that is part of, uh, the M-injector project called, uh, M-reflective payload.

39:40.820 --> 39:49.020
And then we target, uh, the, the PID of Notepad, which is 60, 6020.

39:49.120 --> 40:00.580
And we run this, uh, we will get, uh, this popup coming from Notepad that indicates there is now code that was injected and is running, uh, uh, out of, uh, Notepad.

40:00.700 --> 40:19.140
Uh, and then if we go, uh, back to the project, uh, to the process, sorry, uh, and check on the threats, uh, area, we will see now that there is a new threat, uh, RTL use that I started, uh, that's supposed to start, uh, that's showing to start from RTL user threat to start.

40:19.140 --> 40:28.140
And if we check on the code stack of that threat, we will see that there is now two, uh, uh, symbols that are not backed by any, anything on disk.

40:28.160 --> 40:33.420
Uh, process hacker just run, is showing the, the memory addresses of, uh, those symbols.

40:33.760 --> 40:49.260
Uh, and then, uh, the memory area, we can check that, uh, there is, there will be a read, write, execute, uh, allocation uh, that will contain the malicious payload, which is this private commit allocation.

40:49.460 --> 40:54.840
Uh, if we open the allocation, we will see the P header signs in here.

40:54.840 --> 41:00.000
Okay, so now if we run MemHunter, so let's go ahead and run MemHunter.

41:00.020 --> 41:06.040
So MemHunter, this is the output that you get from MemHunter, so we will apply a specific heuristic to MemHunter.

41:06.040 --> 41:10.100
The one that, that we're interested in is the, the suspicious threat.

41:10.260 --> 41:13.080
Uh, you, you don't have to apply any heuristic when you run this.

41:13.080 --> 41:16.700
In this case we're, we're just doing it for, for the sake of, of time.

41:16.880 --> 41:20.960
Uh, and then we will ask MemHunter to be verbose on his output.

41:21.320 --> 41:28.940
Uh, so MemHunter will run a bit, it will, again it will enumerate the process, it will perform the beautiful query walk on all the processes.

41:29.240 --> 41:38.240
Uh, and after that it will report that there is something suspicious on nowpa.dxc on this specific threat ID.

41:38.280 --> 41:41.920
Uh, and these are the details of that memory region.

41:42.280 --> 41:46.060
Uh, okay so that's uh, demo number one.

41:49.040 --> 41:59.860
Okay, uh, demo number two, uh, again is uh, uh, the, the, the defensivation example that we just uh, mentioned.

41:59.880 --> 42:10.760
Uh, demo number two we are uh, launching, let's uh, close this notepad instance and we will use also notepad as a, as a target, as a hosting process for our attack.

42:10.760 --> 42:15.080
So we are running technique number seven, uh, which is uh , process Halloween.

42:15.080 --> 42:29.240
We are uh, pointing uh, uh, M injector to use another payload, oh, sorry , another payload uh, which is in this case is uh, uh, MSX payload.

42:30.540 --> 42:31.920
There you go.

42:31.920 --> 42:35.060
And then the target is going to be notepad again.

42:42.550 --> 42:43.710
Yeah, there you go.

42:43.710 --> 42:49.210
So the technique just executed, so we just hollow out the main memory of uh, notepad.

42:49.210 --> 42:54.470
So if we check on notepad, uh, the process uh, looks uh, pretty legit.

42:54.470 --> 42:57.130
Looks as a signed process from Microsoft.

42:57.130 --> 43:01.090
Uh, it, it contains uh, uh, some threats.

43:01.090 --> 43:07.750
The, the, the threat is con- contains a potentially valid uh, call stack.

43:07.750 --> 43:11.310
I mean there are no issues from a simple uh, site.

43:11.310 --> 43:20.390
So we'll run uh, uh, uh, uh, Memhunter, but this time uh, we will use uh, a different uh, uh, heuristic.

43:20.390 --> 43:32.930
Uh, heuristic number four that will perform the uh, the cross check between the, the, the P header uh, uh, fields from the things in memory versus something on disk on all the processes running on the, on the end point.

43:32.990 --> 43:38.310
Uh, uh, and there will be a mismatch on notepad.exe because of uh, process hollowing.

43:38.310 --> 43:40.810
Uh, so Memhunter will, will flag that out.

43:40.910 --> 43:41.910
Uh, okay.

43:41.910 --> 43:43.070
So that's it.

43:43.070 --> 43:47.170
Thank you very much for, for being here, for attending our call.

43:47.390 --> 43:51.790
There are some uh, stickers of the tool uh, on the, on the tables.

43:52.090 --> 43:53.010
Uh, yeah.

43:53.010 --> 43:53.530
Thank you very much.

