WEBVTT

00:00.000 --> 00:00.640
All right.

00:00.660 --> 00:06.100
Aloha and welcome to my talk on mastering Apple's endpoint security.

00:06.180 --> 00:10.180
So today we're going to talk about all things related to Apple's endpoint security.

00:10.180 --> 00:20.360
We are going to start with some basics but very quickly we will then move into some more advanced topics as well as cover some nuances and pitfalls.

00:20.360 --> 00:26.760
Really shed some light into what I think are the darker corners of endpoint security.

00:27.160 --> 00:28.960
Super stoked you're all here.

00:28.960 --> 00:41.380
I imagine those of you who are defenders, malware analysts, perhaps those writing security software, the content of this talk, it's relevance should be readily apparent.

00:41.580 --> 00:50.560
But if you are a attacker, a hacker, a malware author and are targeting Mac OS, cool, it's Def Con, all are welcome.

00:50.560 --> 01:00.760
I think this talk will be very relevant to you as well because as we'll see, endpoint security really provides defenders the tools to detect even the most advanced malware.

01:00.760 --> 01:11.480
So again, if you're a hacker , this might cause you some consternation so having a in -depth understanding of what the defenders have in their arsenal I think is very relevant.

01:12.000 --> 01:13.360
My name is Patrick Wardle .

01:13.360 --> 01:17.060
I am the founder of the Objective-C Foundation.

01:17.380 --> 01:29.340
More recently in parallel, I am also the co-founder of W where we are building core Mac OS detection components to integrate into larger enterprise security products.

01:29.900 --> 01:34.180
I'm also the author of the Art of Mac Malware book series.

01:34.180 --> 01:42.200
I mention this here because in volume 2 there are 2 full chapters dedicated solely to endpoint security.

01:42.200 --> 01:49.960
So if you find this talk interesting and you want to dig more into the content of what we're covering today, I recommend reading that.

01:49.960 --> 01:54.940
And this is not a sales pitch because good news is this book is 100% free online.

01:56.800 --> 01:59.020
So let's start with some basics.

01:59.020 --> 02:09.780
Those of you who perhaps have dabbled in endpoint security, this might be a little bit of review but it's important for us to all be on the same page before we delve into more advanced topics.

02:10.300 --> 02:12.320
So what is endpoint security?

02:12.320 --> 02:14.900
Apple has a fairly succinct definition.

02:14.900 --> 02:21.540
They say it's a C API for monitoring system events for potentially malicious activity.

02:21.780 --> 02:31.800
For me, what I love about endpoint security is really for the first time it's a framework that Apple has released specifically for third party security tools.

02:31.800 --> 02:35.640
And I cannot stress the importance of this enough.

02:35.700 --> 02:44.880
Some of you I look around, you look to be perhaps my age or a little bit older so some of you might have been writing Mac security tools before endpoint security was released.

02:44.880 --> 02:49.800
And you know that sucked because there were no APIs dedicated to security tools.

02:49.800 --> 02:54.300
Something like creating a simple process monitor was very very difficult.

02:54.300 --> 02:56.400
Now though with endpoint security it is a breeze .

02:56.400 --> 02:58.920
So thank you to Apple for releasing this.

02:58.920 --> 03:02.720
Myself and other tool developers we are forever indebted to you.

03:02.720 --> 03:10.180
While I am heaping some praise on Apple, which is maybe a little bit rare for me, I also want to give a shout out to them for their documentation .

03:10.400 --> 03:14.920
Unlike some of their other frameworks, endpoint security is actually fairly well documented.

03:14.920 --> 03:19.900
If you go to their developer site, there's a whole section on that, even sample code.

03:19.900 --> 03:29.500
They also ship a neat utility, ES logger, that's built into Mac OS that allows you to explore endpoint security directly from the terminal.

03:30.220 --> 03:42.840
Now though, if you talk to anyone that really does any in-depth tool development using endpoint security, they will say, okay, ignore all the online documentation, go to the header files.

03:42.840 --> 03:46.820
And so I want to instill that wisdom upon you as well.

03:46.820 --> 03:51.740
So there's 3 main header files, these will be found in the SDK directory under endpoint security.

03:51.740 --> 03:55.740
You have ES client, ES message, and ES types.

03:56.460 --> 04:00.080
As we can see on the slide, these are not normal header files.

04:00.080 --> 04:07.000
They include, for example, ASCII flow charts describing very complicated parts of endpoint security.

04:07.080 --> 04:13.660
So again, thank you to whoever the Apple developers who poured their heart and soul into these header files, super indebted to them as well.

04:14.840 --> 04:22.680
Another takeaway or point I want to make early on is if you are developing security tools for Mac OS, you should be using endpoint security.

04:22.680 --> 04:29.100
Not only is it recommended and supported by Apple, and anytime Apple recommends and supports something, use it.

04:29.100 --> 04:34.240
I've been on the other end of that trying to do something a little different, especially before endpoint security.

04:34.240 --> 04:41.080
That always figuratively bit me in the butt when Apple would change something, for example, when a new version of Mac OS came out.

04:41.560 --> 04:47.320
Also Apple continues to invest and improve endpoint security, so it just gets better and better.

04:47.680 --> 05:00.660
And then finally, as we will see, endpoint security is insanely powerful, giving us unparalleled insight into activity on the operating system, which means even the most sophisticated malware will be observable.

05:00.660 --> 05:05.460
So again, if we use endpoint security, it really, as defenders, gives us a great leg up.

05:07.340 --> 05:10.420
Let's now talk about writing an endpoint security tool.

05:10.440 --> 05:14.340
Conceptually, it's actually pretty straightforward in two basic steps.

05:14.340 --> 05:19.960
Subsequent slides will show code how to do this, but for now let's talk about how to do it conceptually.

05:20.060 --> 05:25.300
So the first thing you're going to do is going to be to create an endpoint security client.

05:25.320 --> 05:31.160
This is important because all subsequent endpoint security API calls need this client.

05:31.160 --> 05:32.400
You basically pass it around.

05:32.400 --> 05:34.340
So step one is to create this client.

05:34.460 --> 05:44.720
We'll see that you create this client with a handler block, and I will repeat this several times, that this handler block receives the events of interest that you subscribe for.

05:44.720 --> 05:46.700
We'll get into that a little bit more.

05:47.080 --> 05:54.460
Once you have initialized, created a endpoint security client, you specify and subscribe to events of interest.

05:54.800 --> 05:59.400
So imagine we're interested in tracking process spawns .

05:59.400 --> 06:03.060
We want to get notified any time a process spawns anywhere on the system.

06:03.060 --> 06:06.120
For example, to check if it's malware, something it's trusted.

06:06.120 --> 06:09.320
We can do that with the notify exec event.

06:09.320 --> 06:11.920
We'll talk more about events very shortly.

06:12.140 --> 06:31.400
But the idea is once we've created a client and subscribed to this event, any time a new process is started, either by the system, by the user, by malware, by an exploit, doesn't matter, new process, it means we, our endpoint security client, will get a notification and an endpoint security message telling us that just happened.

06:31.400 --> 06:32.920
Super powerful stuff.

06:36.260 --> 06:40.300
Let's now talk about these endpoint security events.

06:40.300 --> 06:43.400
These are the ones that you can subscribe to.

06:43.400 --> 06:48.860
So these are declared in one of the header files, specifically estypes.h.

06:48.860 --> 06:56.680
There's a large structure that currently holds over 150 events that you can tell endpoint security you are interested in subscribing to.

06:56.680 --> 07:04.840
These range from process events that we just mentioned to file events, USB activity, all sorts of really interesting events.

07:04.840 --> 07:07.120
And Apple continues to add more.

07:07.760 --> 07:10.420
Generally these events fall into two categories.

07:10.420 --> 07:12.780
There are notification events.

07:12.780 --> 07:18.000
These are events that are delivered to you after the fact that something has occurred.

07:18.060 --> 07:22.600
So for example, on a previous slide we saw the notify exec event.

07:22.600 --> 07:26.620
This will be delivered to you any time a new process has started.

07:26.620 --> 07:29.560
But it's important to understand that it is reactive.

07:29.560 --> 07:33.380
It's after the fact and you can't really do anything about it.

07:33.380 --> 07:35.380
It's just a notification.

07:35.380 --> 07:41.760
Still, this is very powerful if you want to, for example, build a passive process monitor or file monitor.

07:41.760 --> 07:43.740
Notification events are your friend.

07:44.200 --> 07:49.260
The other category are the more powerful authorization events.

07:49.260 --> 07:59.640
These actually are delivered to you before the event occurs and the operating system actually pauses or holds the event until you explicitly approve or deny it.

07:59.640 --> 08:16.060
So we'll see for example there's another process event off exec that you can register for and if you register and subscribe to that whenever a new process is about to be started, the operating system and point security will pause that, ask you if you want to allow or deny the process,

08:16.060 --> 08:18.780
and if you allow it, it will allow the process to continue.

08:18.780 --> 08:23.680
But if you say no, it will actually prevent the process from starting in the first place.

08:27.100 --> 08:31.000
Alright, so let's talk about actually creating an endpoint security client.

08:31.000 --> 08:36.060
Don't want to go through all the code but you can see it's 15 lines, nothing too in depth.

08:36.060 --> 08:39.920
Basically first we import the endpoint security framework.

08:39.920 --> 08:42.620
We declare an endpoint security client.

08:42.840 --> 08:47.600
We define a handler block which we'll talk about more in a subsequent slide.

08:47.600 --> 08:53.960
Most important though at the bottom, line 15, we see we invoke the ES new client API.

08:53.960 --> 09:07.100
This takes a pointer to the endpoint security client that will be initialized and then the handler block that will be invoked automatically by endpoint security any time matching events occur anywhere on the system.

09:07.340 --> 09:14.500
Now, this is the first endpoint security API you're going to call so it's very important to check the return result from this.

09:14.500 --> 09:21.620
Because we'll talk briefly, shortly about some of the prerequisites that Apple leverages on us if we want to use endpoint security.

09:21.680 --> 09:28.340
But for example, this API can fail if we don't have the right entitlements, privileges, or permissions.

09:30.140 --> 09:43.660
Once we have created a endpoint security client, next we need to tell endpoint security what of those 150 or so events we are actually interested in and then subscribe to them.

09:43.660 --> 09:47.460
So this is done via the ES subscribe API call.

09:47.460 --> 09:49.540
You can see it takes 3 arguments.

09:49.540 --> 09:52.520
The first is that initialized endpoint security client.

09:52.520 --> 09:55.320
Then an array of events.

09:55.320 --> 09:59.720
Here we're only asking to subscribe to 1, the notify exec event.

09:59.720 --> 10:03.220
And then we have to pass the number of events in this array.

10:03.420 --> 10:06.520
Recall that endpoint security is a C API.

10:06.520 --> 10:07.460
It's very low level.

10:07.460 --> 10:13.160
So a lot of times you're going to see APIs that take an array, an account, a string, and a length, et cetera, et cetera.

10:13.160 --> 10:15.480
These very low level C isms.

10:16.100 --> 10:23.040
Now once we've subscribed to this event, as I mentioned, any time the matching events occur, we will get notified about them.

10:25.840 --> 10:37.080
So when an event occurs that matches one of the ones we've subscribed to, endpoint security will deliver us a lovely message indicating that a matching event has just occurred.

10:37.560 --> 10:39.800
Here is the message that is delivered.

10:39.800 --> 10:43.000
It's rather a large structure with a lot of members.

10:43.000 --> 10:47.960
We're not going to go into all of them, but I do want to mention 2 or 3 important ones here.

10:47.960 --> 10:51.620
So first we have what I like to call the responsible process.

10:51.620 --> 10:55.980
And this is the process that is responsible for triggering the event.

10:55.980 --> 11:06.600
So imagine we've registered for file IO endpoint security events and imagine we are now monitoring the file system to detect anomalous or unusual events.

11:06.760 --> 11:10.320
Say something accesses the key chain database.

11:10.320 --> 11:12.000
The question is, is that the user?

11:12.000 --> 11:18.760
Is that the trusted key chain app or is that a stealer that's trying to grab your passwords and certificates?

11:19.020 --> 11:27.560
Well the good thing is, when we get the file IO event that endpoint security delivers to us, if we examine the responsible process, it will tell us whodunit.

11:27.560 --> 11:33.020
And we can see if it's the user, something trusted, or something malicious like a stealer.

11:33.220 --> 11:35.540
We also get an event type.

11:35.540 --> 11:39.100
You can subscribe to multiple events in the same endpoint security client.

11:39.100 --> 11:42.740
So this will tell you what event this message belongs to.

11:42.740 --> 11:43.560
What type.

11:43.560 --> 11:47.740
And this is important because the event data is event type specific.

11:47.820 --> 11:56.780
If we've registered for say process and file events and this is a process event, the event structure will be related to the process .

11:56.780 --> 11:58.720
For example, a PID and a path.

11:58.720 --> 12:05.380
If it's related to a file event, it won't have a PID but it will have things like the file source and destination path.

12:07.520 --> 12:11.700
Now we talk about the all important endpoint security handler block.

12:11.700 --> 12:17.840
As I mentioned this is invoked automatically by endpoint security anytime a matching event occurs anywhere on the system.

12:17.840 --> 12:23.400
This is where you put all your logic to do whatever you want to do to process that event.

12:23.660 --> 12:31.980
If you're writing a simple process monitor or file monitor, in this case we just print out some of the information, the responsible process, etc.

12:31.980 --> 12:32.360
etc.

12:32.360 --> 12:42.740
If you're trying to detect malware, this is where you would have some heuristics for example to examine what the event is, who did it, and if it's malware or not.

12:44.200 --> 12:48.320
Now the last thing we need to talk about are those pesky prerequisites.

12:48.320 --> 12:58.320
So, endpoint security is an insanely powerful framework that gives you essentially full access, full observability of everything that's happening on the operating system.

12:58.320 --> 13:06.760
Apple understandably says hey this is super powerful and so from a privacy point of view we just don't want any process using endpoint security.

13:06.760 --> 13:13.020
So they protect it with an entitlement that you have to ask or rather beg Apple give you.

13:13.200 --> 13:18.400
And without this entitlement you can't write endpoint security tools or at least you can't deploy endpoint security tools.

13:18.860 --> 13:33.760
So once you beg for this entitlement and make a sacrifice to Cupertino if they grant it to you, you are super stoked, you can then create a program that uses endpoint security, notarize it, entitle it , and then deploy it to your users.

13:33.900 --> 13:41.760
Your users though are going to have to run it with root privileges and either grant the utility or the terminal full disk access.

13:41.760 --> 13:49.440
Again this is just to essentially protect users from inadvertently or something malicious using endpoint security.

13:49.980 --> 13:54.200
Okay so that is a wrap of an introduction to endpoint security.

13:54.200 --> 14:01.760
Hopefully if you've even never heard about endpoint security before you understand at least conceptually how to create an endpoint security tool.

14:01.980 --> 14:08.300
So now I want to talk about some of the more advanced topics and also some of the nuances and pitfalls.

14:08.300 --> 14:17.340
Many of these have bit me, figuratively speaking, in the bot and so I want to share them with you so you can avoid my blood sweat and tears.

14:17.860 --> 14:23.400
So let's start with caching which is a nuance but a very important optimization.

14:25.280 --> 14:29.020
So caching is related to authorization events.

14:29.020 --> 14:43.680
So remember we had the authorization events which are events that the operating system will essentially disallow them until your endpoint security client tells the operating system to either allow or deny it.

14:44.240 --> 14:50.620
So for example we have an auth exec event to authorize new processes or deny ones we don't want.

14:50.620 --> 14:58.460
So the way you respond back to the operating system is by invoking the ES respond auth result API.

14:58.460 --> 15:07.700
This takes your decision, a yes or no, and then a very important flag which tells endpoint security whether to cache the response or not.

15:07.700 --> 15:18.100
If you tell endpoint security to cache the response, subsequent process executions of that same process will not result in endpoint security sending you another message.

15:18.100 --> 15:22.980
It basically says yo, I got it, I'm going to cache this, I'm not going to ask you again.

15:24.240 --> 15:30.440
So let's show a specific example of a tool that should have used caching but didn't.

15:30.440 --> 15:33.160
I'm going to pick on this tool because I wrote it.

15:33.380 --> 15:35.920
So one of the tools I've written is called block block.

15:35.920 --> 15:46.080
It monitors for persistent malware but it also has a neat feature that if you turn on, notarization mode, will block any process that is not notarized.

15:46.080 --> 15:47.520
What is notarization?

15:47.520 --> 15:55.840
It's essentially an Apple security mechanism that requires developers to submit their compiled binaries to Apple.

15:55.920 --> 15:58.200
Apple then scans them for known malware.

15:58.200 --> 16:03.100
If none is found, Apple notarizes it, essentially giving it a stamp of approval.

16:03.100 --> 16:08.600
Then a run time Mac OS will check to see if a process or program is notarized or not.

16:09.020 --> 16:16.440
Now obviously the vast, vast, vast majority of legitimate software is going to be notarized whereas malware often isn't.

16:16.440 --> 16:21.500
Malware authors are not keen on giving their binaries to Apple before they deploy them.

16:22.060 --> 16:27.960
So this is a very powerful heuristic that can block most malware very simply and very generically.

16:27.960 --> 16:33.600
And yes, Mac OS does try to also prevent non-notarized code from running but there's a lot of loopholes.

16:33.600 --> 16:38.620
Mac OS is actually very lenient which is why block block takes a more draconian step.

16:38.920 --> 16:43.100
So in terms of implementation, block block uses endpoint security.

16:43.420 --> 16:47.820
Specifically it registers or subscribes to the off exec event.

16:47.840 --> 16:55.980
Then whenever a program is launched by the user, by the system, by whatever, endpoint security pauses that, asks block block.

16:55.980 --> 16:58.440
Block block checks if it's notarized or not.

16:58.440 --> 17:00.120
And if it is it says cool, you can run.

17:00.120 --> 17:02.940
If it's blocked it says no and tells the user about this fact.

17:04.120 --> 17:05.720
Here's some of the code from block block.

17:05.720 --> 17:07.080
Don't worry about reading it all.

17:07.080 --> 17:09.460
It's more for a reference if you're interested.

17:09.580 --> 17:14.620
Basically block block uses Apple's code signing APIs to check if something is notarized.

17:14.620 --> 17:22.180
And then at the bottom you can see it invokes that ES respond auth result telling endpoint security to allow or deny.

17:22.180 --> 17:23.720
I took out the allow code.

17:23.720 --> 17:26.240
It's essentially the same as the deny code.

17:26.240 --> 17:29.460
But the key is that block block did not cache the result.

17:29.600 --> 17:30.140
Why not?

17:30.140 --> 17:32.160
Patrick didn't read the header files.

17:32.260 --> 17:35.700
Also process launches are not that common.

17:35.700 --> 17:38.800
Notarization checks are not that CPU intensive.

17:38.860 --> 17:41.480
So in my testing I didn't see a problem.

17:41.580 --> 17:50.120
Well of course I deployed block block and shortly thereafter I started getting some bug reports especially from people who were compiling large programs.

17:50.120 --> 17:52.380
Large software projects.

17:52.380 --> 17:56.200
They said, hey Patrick, block block is causing the CPU to spike.

17:56.460 --> 17:58.660
And very quickly I realized what the problem was.

17:58.660 --> 18:08.620
When you compile a large software project, especially if it's like Objective C or Swift code, the compiler is invoked again and again and again and again to compile each file.

18:08.680 --> 18:17.720
Since block block wasn't caching the result, this means endpoint security would ask block block again and again and again and again if it wanted to allow the compiler.

18:17.720 --> 18:28.260
Obviously block block should have checked the compiler once, said, yeah this is a signed notarized trusted Apple process, cached that response and then endpoint security would have never asked block block again.

18:28.560 --> 18:29.960
But it didn't.

18:30.300 --> 18:34.980
Turns out there's some more nuanced problems with caching.

18:34.980 --> 18:39.900
And so block block not caching revealed a more subtle problem.

18:39.980 --> 18:52.420
So I got another bug report saying, hey Patrick, I have block block and Jamf Protect installed on my computer and I noticed that when block block is running, Jamf Protect CPU utilization goes through the roof.

18:52.500 --> 18:53.720
I was like, that's super weird.

18:53.720 --> 18:56.460
Like why is block block impacting Jamf Protect?

18:56.820 --> 19:02.040
So it turns out that block block and Jamf Protect both use endpoint security, which is fine.

19:02.280 --> 19:06.340
What Jamf does is also subscribe to the auth exec event.

19:06.340 --> 19:07.880
Also no problems there.

19:07.900 --> 19:14.460
What Jamf did though, it was for every new process launch, they would perform some very CPU intensive actions.

19:14.460 --> 19:18.040
Caching the file, running a full Yara scan, all sorts of things.

19:18.040 --> 19:19.640
But then Jamf cached that.

19:19.640 --> 19:27.880
They basically said, okay, we're okay doing a one time very CPU intensive thing, but since we cached it, we will only do it once.

19:28.060 --> 19:44.960
Well unfortunately the endpoint security cache is global and there is a nuance that if there is another endpoint security client on the same system that is not caching the results, this actually undoes the caching even for the other client, which meant that because block block was not caching,

19:44.960 --> 19:55.840
this meant that Jamf was receiving all the same endpoint security messages again and again and therefore were performing the same CPU intensive actions over and over.

19:55.980 --> 19:57.360
Who's at fault here?

19:57.460 --> 19:58.780
Kind of everybody.

19:58.780 --> 20:00.260
I will take full responsibility.

20:00.260 --> 20:02.360
Block block should have been doing caching.

20:02.360 --> 20:07.340
I would argue the fact that the endpoint security cache is global, I understand why Apple did it.

20:07.340 --> 20:12.020
It's kind of a very simple way, but does have some problems.

20:12.160 --> 20:21.440
And then I think Jamf should have taken the step of implementing an internal cache because if some other client doesn't implement caching, ultimately it would impact them.

20:21.440 --> 20:25.400
And even if a new client comes along, Apple says that the cache would be invalidated.

20:25.400 --> 20:29.920
So if you're writing your own security tool, make sure you implement your own cache as well.

20:30.680 --> 20:33.380
All right, so you're like, Patrick, I get it, I should use cache.

20:33.380 --> 20:34.800
Well, not so fast.

20:34.800 --> 20:36.240
Nuances, nuances, nuances.

20:36.240 --> 20:39.680
That's really the theme of this talk and Apple's endpoint security.

20:39.760 --> 20:43.120
This is because caching may be broader than you think.

20:43.120 --> 20:46.700
So let's look at what it means for off exec events.

20:46.700 --> 20:49.900
Turns out caching is based on the binary itself.

20:49.900 --> 20:51.480
The file inode.

20:51.480 --> 20:52.680
So let's look at the slide.

20:52.680 --> 21:00.160
Imagine a developer is installing homebrew and he does that via bash and curl, the recommended way.

21:00.160 --> 21:05.380
If there's an endpoint security client that is examining new processes, it will see bash and curl being executed.

21:05.380 --> 21:08.920
It will approve these because they are trusted, notarized processes.

21:08.920 --> 21:14.340
And if it was a person who came to Patrick's talk, it was like, okay, I'm going to cache these because caching is very important.

21:14.740 --> 21:23.660
Well, the problem is if later malware uses bash or curl, endpoint security will not deliver a new event because bash and curl have not changed.

21:23.660 --> 21:27.700
That is to say, caching does not take into account the arguments.

21:27.700 --> 21:34.420
So what you really should do is avoid caching binaries where command line arguments control the behavior.

21:34.420 --> 21:38.020
For example, curl, Python or script interpreters.

21:38.020 --> 21:40.160
So again, always some nuances.

21:41.480 --> 21:46.980
So that's caching and now let's transition to talking about scripts and their interpreters.

21:47.540 --> 21:54.400
This is important because a lot of Mac malware even today is distributed to end users as standalone scripts.

21:54.500 --> 22:00.600
For example, we have Joker Spy, a malicious Python script, SIGIN, which is a malicious bash script.

22:00.600 --> 22:01.920
There's many of these.

22:03.920 --> 22:08.580
Now, if you've been following along so far, you've heard me talk a lot about the responsible process.

22:08.580 --> 22:15.740
And this is because endpoint security events are tied to the process that essentially triggered them or created them.

22:15.880 --> 22:21.620
And this is usually all well and good, but not in the context of script interpreters.

22:21.780 --> 22:26.140
So imagine the user inadvertently executes Joker Spy.

22:26.160 --> 22:33.500
Well, endpoint security will deliver a process event if someone has subscribed to it, but it won't be for the actual script.

22:33.500 --> 22:35.600
It will be for the script interpreter.

22:35.880 --> 22:39.140
And if you think about it, we actually don't care about the script interpreter at all.

22:39.140 --> 22:40.880
We don't care about Python per se.

22:40.880 --> 22:43.320
What we really care about is the script.

22:43.320 --> 22:53.400
We want to perhaps scan that to see if it's malware, run some heuristics against it to see if it's something malicious, and if so, block, yes, Python, but because of the script.

22:56.280 --> 23:07.640
So Apple realized this after endpoint security was released, and in version 2.0 of endpoint security, they added a script member to the exec key structures.

23:07.640 --> 23:10.140
These are the structures that describe processes.

23:10.540 --> 23:11.560
And this is awesome.

23:11.560 --> 23:20.140
So now as we can see on the slide, we can write code that can extract the script from a script interpreter.

23:20.620 --> 23:21.380
Note two things, though.

23:21.380 --> 23:25.840
First, we check the version to make sure we are executing on a compatible version of endpoint security.

23:25.840 --> 23:33.480
This is very important to do any time you use these newer methods because you don't want to crash if the user runs your program on an older version of macOS.

23:34.140 --> 23:44.980
Also then we check to make sure it's null because for most processes that don't have scripts, it's going to be blank, but for script interpreters, it should be set, meaning we get the script, which then we can scan to make sure it's not malware.

23:47.200 --> 23:50.020
And this appears to be all well and good, right?

23:50.020 --> 23:52.560
Now, spoiler, more nuances.

23:53.100 --> 24:01.920
So if we execute joker spy, it's a malicious Python script named sh.py, we can see the first invocation where we execute it directly.

24:01.920 --> 24:04.280
This generates an endpoint security event.

24:04.280 --> 24:17.280
We look at the script member that Apple now sets, and indeed, it is the path to the malicious script, which we can now detect as malware and block it terminating the Python process, protecting the user from infection.

24:17.960 --> 24:32.240
Well, if we execute it again, this time via the script interpreter, so Python and then script.py, we can see that as expected, because we're not caching script interpreters, we get another process event.

24:32.380 --> 24:39.400
However, in this case, the script member is null, it's blank, and so we can't detect that and the malware is free to run.

24:39.700 --> 24:41.660
So what's going on?

24:42.660 --> 24:55.960
Well, if we go back to the header files, which recall are the source of all answers to everything related to endpoint security, we see a very short comment that says, this field is only valid if a script was executed directly and not as an argument.

24:56.000 --> 25:06.400
Which means, as we saw in the previous slide, if the script is executed directly, the script member will be set, but if it's executed via a script interpreter, it will remain blank.

25:06.400 --> 25:11.740
This is kind of a huge shortcoming and something that we really all need to be aware of.

25:11.860 --> 25:16.000
Now, if we are aware of this, we can solve this in various ways.

25:16.000 --> 25:27.460
For example, if we see a script interpreter, we can ourselves manually enumerate all of the arguments and for those that are file paths, we can treat those as scripts.

25:29.060 --> 25:31.820
So that's scripts and more nuances.

25:32.380 --> 25:37.040
The next topic I want to talk about deals with authorization deadlines.

25:37.040 --> 25:42.860
And this is arguably the most important topic because if we don't get that right, we're going to get killed.

25:42.860 --> 25:44.220
Like, for real.

25:46.380 --> 25:51.020
So, let's briefly go back and touch on auth events.

25:51.280 --> 25:55.960
So we talked about this a few times, but let's focus on the auth exec event.

25:56.100 --> 26:09.560
Recall that if we subscribe to this event, any time a new process is about to be spawned, endpoint security will first come to us and ask us if we should or we want to allow or deny the process.

26:10.080 --> 26:16.240
While we are making a decision, that process is going to be essentially suspended or not run.

26:17.080 --> 26:30.100
And so Apple says, okay, third-party developers, we're going to give you a little bit of time to make your decision, but if you take all day, like, this is going to impact the user experience, and you know Apple is not stoked about the user experience being impacted,

26:30.100 --> 26:35.140
and so what macOS does is eventually, if you don't respond quick enough, it will nuke you.

26:35.140 --> 26:36.020
It will terminate you.

26:36.020 --> 26:38.820
Not like you, you, but your client, right?

26:39.240 --> 26:43.040
And it will generate a crash report, and at least it will explain exactly why.

26:44.380 --> 26:47.120
So you might be thinking, okay, Patrick, yeah, yeah, I get it.

26:47.120 --> 26:51.320
I'm going to make sure I respond fast enough so Apple doesn't kill me.

26:51.320 --> 26:53.940
But what if you're waiting on a user?

26:54.360 --> 27:01.980
So back to block block, when it detects a non-notarized process, it actually asks the user, yo, what do you want to do?

27:02.500 --> 27:03.820
What if the user is out to lunch?

27:03.820 --> 27:05.460
What if the user is not paying attention?

27:05.720 --> 27:10.000
Ah, if they don't respond, well, is Apple going to kill us?

27:10.000 --> 27:10.540
Yeah.

27:10.540 --> 27:13.040
So what is block block supposed to do?

27:16.340 --> 27:19.620
This is where end point security deadlines come into play.

27:19.660 --> 27:30.340
So recall that for every end point security event, we get this big end point security message that has a lot of metadata, but one of the things it has for these off events is a deadline.

27:30.700 --> 27:35.920
If we go to the header file, we can extract some important information about what these deadlines are.

27:35.960 --> 27:38.620
First, it's a mock absolute time.

27:38.620 --> 27:40.760
Next slide, we'll talk about what that is.

27:40.760 --> 27:43.460
It also says failure to respond.

27:43.460 --> 27:44.620
You will get nuked.

27:44.620 --> 27:46.120
Okay, Apple, we get it.

27:46.120 --> 27:50.280
And then thirdly, it says the deadline can and does vary between messages.

27:50.280 --> 27:55.800
And we can confirm this if we create a simple program that just spits out the off deadlines.

27:55.800 --> 27:59.460
We can see that for system processes, it's 3 or 4 seconds.

27:59.460 --> 28:01.600
For application , it's about 15.

28:01.600 --> 28:03.460
So that's a decent amount of time.

28:04.060 --> 28:06.920
Favor , don't ask Apple to increase this.

28:06.940 --> 28:18.760
There's a funny post where someone does and Quinn Eskimo, who is my favorite Apple employee, he is an OG that responds to everyone's technical questions on Apple forums.

28:18.760 --> 28:24.580
And he, I don't know if he's joking or not, but he's like, every time someone asks to make the ES off deadline longer, Apple shortens it.

28:24.580 --> 28:29.280
So don't ask Apple because we like that it's not super short so far.

28:30.700 --> 28:34.280
So let's talk a little bit more about this for two reasons.

28:34.280 --> 28:37.000
First, it is a mock absolute time.

28:37.000 --> 28:38.860
I have no idea what that was.

28:38.860 --> 28:40.260
I read Apple's documentation.

28:40.360 --> 28:43.200
It says a value of a clock that increments.

28:43.320 --> 28:45.360
Like, okay, that doesn't tell me too much.

28:45.460 --> 28:51.480
More importantly, though, most of the APIs we want to use to actually take into account the deadline want nanoseconds.

28:51.480 --> 29:00.500
So we need to convert this from a mock time clock increment value to something that we actually understand that the APIs want, which are nanoseconds.

29:00.940 --> 29:02.000
So what did Patrick do?

29:02.000 --> 29:03.400
Patrick said, okay, cool.

29:03.400 --> 29:06.160
Like, I will convert mock time to nanoseconds.

29:06.160 --> 29:09.000
And that was all well and good until Apple Silicon came along.

29:09.260 --> 29:15.980
With the release of Apple Silicon, Apple published a document called Addressing Architectural Differences.

29:16.100 --> 29:17.660
It's just gripping content.

29:17.860 --> 29:27.740
Of course, Patrick didn't read this, but this was problematic because one of the few things Apple says you must do very carefully on ARM systems is convert mock times to nanoseconds.

29:27.740 --> 29:29.100
You cannot do that directly.

29:29.100 --> 29:32.160
You're supposed to use a time-based information.

29:32.240 --> 29:41.500
I don't know exactly what that means, but Apple does provide a nice helper function that we can invoke to convert mock times to nanoseconds.

29:42.960 --> 29:47.400
So once we have that, here is some code to ensure that we respond to the deadline.

29:47.400 --> 29:50.180
Again, this is more for research resources.

29:50.180 --> 29:52.000
I don't want to stand up here explaining code all day.

29:52.000 --> 29:53.500
That's not that exciting.

29:53.500 --> 29:56.640
But what we can see is we essentially compute the delta.

29:56.840 --> 29:59.960
That is how much more time we have in the deadline.

29:59.960 --> 30:01.420
Is it 3.5 seconds?

30:01.420 --> 30:02.760
Is it 15 seconds?

30:02.840 --> 30:08.540
We then subtract a little bit of time from this because we want to make sure that we're responding before the deadline.

30:09.080 --> 30:22.080
And then at the bottom of the slide, we create a dispatch semaphore that will time out right before the deadline to make sure if the user, for example , hasn't responded, at least we programmatically respond so that macOS does not kill us.

30:22.080 --> 30:23.520
Now, there's probably other ways to do it.

30:23.520 --> 30:26.640
This is just the approach that block block takes.

30:26.800 --> 30:28.380
So again, that's off deadlines.

30:28.380 --> 30:33.740
Make sure you respond to them quickly enough or Apple will nuke your client and not restart it.

30:33.740 --> 30:36.320
Meaning the system is essentially then unprotected.

30:37.500 --> 30:38.000
Okay.

30:38.000 --> 30:41.520
Let's now talk about muting and mute inversions.

30:42.460 --> 30:48.320
So imagine you are using endpoint security and you go to create a file monitor.

30:48.520 --> 30:49.200
Awesome.

30:49.200 --> 30:51.480
You subscribe to all the file events.

30:51.480 --> 30:52.540
You get the entitlement.

30:52.540 --> 30:53.360
You compile it.

30:53.360 --> 30:54.860
You run your file monitor.

30:55.240 --> 30:56.860
And you're immediately overwhelmed.

30:56.940 --> 30:57.600
Why?

30:57.600 --> 30:58.320
Two reasons.

30:58.320 --> 31:03.200
First, there are a ton of legitimate file IO actions happening all over the system.

31:03.220 --> 31:10.720
And then secondly, if your tool actually prints or writes to the terminal, that is going to generate file events itself.

31:10.720 --> 31:13.760
The endpoint security is going to deliver back to you that then you're going to print out.

31:13.760 --> 31:16.000
You're going to kind of go into this recursive loop.

31:16.620 --> 31:23.100
So what we really want to do is tell endpoint security, okay, thank you for all the file events, but there's certain things that we want to avoid.

31:23.100 --> 31:24.300
That we want to ignore.

31:24.300 --> 31:28.520
For example, we want to ignore ourself as the responsible process.

31:28.520 --> 31:34.600
Or as we will see, you can also tell endpoint security to actually ignore or mute certain events.

31:34.600 --> 31:40.520
Perhaps you want to ignore all file events that are destined for the temporary directory.

31:40.520 --> 31:42.080
You just don't care about those.

31:43.560 --> 31:46.820
So let's start with talking about how to mute a process.

31:46.820 --> 31:52.200
Again, this is telling endpoint security you are not interested in receiving any events from the specified process.

31:52.280 --> 31:57.180
You do that via the aptly named ES mute process API.

31:57.300 --> 32:01.680
This takes an initialized client and then the audit token of the process.

32:02.020 --> 32:08.580
So there's a snippet of code on the slide where we're going to mute ourselves because we don't want file events from our own file monitor.

32:08.580 --> 32:09.900
That's pointless.

32:10.500 --> 32:14.180
Question though, how do you get an audit token and what even is an audit token?

32:14.660 --> 32:19.760
So an audit token is just a more modern way of identifying a process.

32:19.760 --> 32:23.720
PID are reused which introduces a bunch of security issues.

32:23.720 --> 32:26.700
So audit tokens are a better way.

32:26.700 --> 32:31.300
The problem is a lot of APIs still either want a PID or give you a PID.

32:31.300 --> 32:34.200
For example, if you enumerate all the running processes.

32:34.240 --> 32:38.760
So you might be wondering how given a PID you can get the process's audit token.

32:39.160 --> 32:42.740
Turns out you can use the task name for PID API.

32:42.920 --> 32:44.780
Here's some example code that does that.

32:44.780 --> 32:48.080
Given a PID it will give you the audit token for that.

32:48.460 --> 32:52.980
Make sure though you always call mock port deallocate otherwise you will have a memory leak.

32:52.980 --> 32:55.040
Again, found this out the hard way.

32:56.340 --> 33:01.100
You can also mute the process via the ES mute path API.

33:01.100 --> 33:04.240
Instead of an audit token this takes a path.

33:04.400 --> 33:06.620
So again, snippet of code on the slide.

33:06.820 --> 33:11.200
We mute ourselves by providing the path to our own process.

33:12.540 --> 33:14.760
Okay, so that's how to mute processes.

33:14.760 --> 33:19.880
Again, telling end point security, yo, we don't care about any events for this specific process.

33:19.960 --> 33:23.240
Well, what if you instead want to mute specific events?

33:23.240 --> 33:29.960
Like I mentioned, perhaps in your file monitor you want to ignore everything that is destined for the temporary directory.

33:30.720 --> 33:32.640
Well, turns out you can do that as well.

33:32.900 --> 33:37.520
And the good news is you actually use the same ES mute path API.

33:37.640 --> 33:45.910
As its last parameter, this API takes a type which tells end point security what thing you're actually trying to mute.

33:45.910 --> 33:48.250
Either a process or the actual event.

33:48.550 --> 33:52.930
And we can see on the slides there's four different types in two categories.

33:52.930 --> 33:55.790
The first category tells it to mute a process.

33:55.910 --> 33:59.390
The second one tells it to mute a path or an event.

34:00.490 --> 34:02.730
In each group there are two types.

34:02.730 --> 34:05.570
There's ones that end in prefix and one that ends in literal.

34:05.570 --> 34:09.310
Literal just means you're going to give it the full path to the process or the event.

34:09.310 --> 34:11.130
Prefix means it matches a prefix.

34:11.310 --> 34:20.530
So if we want to mute all file events going into the temporary directory or any of its subdirectories, we use the target prefix type.

34:20.950 --> 34:24.750
One more nuance because end point security is full of nuances.

34:24.990 --> 34:28.910
End point security does not support or handle symlinks.

34:29.030 --> 34:35.210
So that means we can't actually just give it slash TMP, slash temp because on macOS that is symlinked.

34:35.210 --> 34:44.010
The mute API will succeed but you'll actually still see events from slash temp because again it's symlinked and end point security doesn't support that.

34:44.010 --> 34:48.670
So you either have to resolve that path yourself or dynamically look it up.

34:50.230 --> 34:52.730
Alright, let's now talk about mute inversion.

34:52.730 --> 34:55.310
Conceptually this is pretty straight forward.

34:55.310 --> 34:57.970
To explain the APIs is a little bit more complicated.

34:57.970 --> 35:00.530
It messes with my head but I'm going to try my best.

35:01.090 --> 35:06.870
So, so far we've been talking about end point security messages in a very global context.

35:06.870 --> 35:14.810
Right, we've talked about process monitors and file monitors that once we subscribe to these events, end point security says here are all the events.

35:14.810 --> 35:21.830
Here's all the processes, here's all the files and yes we showed how to mute a few of them but what if we want to do the opposite?

35:21.830 --> 35:23.770
What if we want to do the invert?

35:24.010 --> 35:34.590
Specifically, what if we want to write a file monitor to analyze a piece of malware and ignore every process except the one specific one we are running, the malware.

35:34.590 --> 35:37.710
We want to see how the malware persists, what files it generates.

35:38.050 --> 35:41.730
Well, turns out you can now do this via mute inversion.

35:42.570 --> 35:49.070
Another example, say you want to protect the user's cookies or document directory.

35:49.210 --> 35:58.450
We have some source code from Mac Stealer, it's a malicious Python script and we can see it's accessing Google Chrome's cookie directory to grab all the cookies.

35:58.710 --> 36:05.710
So what we could do is write a security tool that monitors this directory and only authorize, for example, the browser.

36:05.950 --> 36:10.510
Again, we don't care about any other directory, we only care about this specific one.

36:10.510 --> 36:13.830
This is something that mute inversion can help us implement.

36:15.010 --> 36:18.590
So how does one actually utilize mute inversion?

36:18.590 --> 36:21.730
And this is where it gets a little complicated, at least to me.

36:21.830 --> 36:25.930
So what Apple could have done is implement new mute inversion APIs.

36:25.930 --> 36:29.670
For example, mute invert process, mute invert path.

36:29.670 --> 36:48.270
But what Apple did, which was very slick, is they said, okay, you already have mute path and mute process APIs, so what if we provide a new API that just toggles mute inversion and then you can still use those older APIs or the original APIs, but now they will be inverted.

36:48.450 --> 36:50.790
So that's exactly what we can do.

36:50.790 --> 36:53.650
And I'll show some code that hopefully illustrates that a little better.

36:53.830 --> 36:58.230
So first, we can invoke the ES invert muting API.

36:58.470 --> 37:02.870
This will unmute anything that's already muted, but then mute everything else.

37:04.330 --> 37:09.410
First, though, we have to talk about some more nuances, specifically the default mute set.

37:09.930 --> 37:22.310
Turns out when endpoint security starts, Apple, without really telling anybody too much about this, mutes a bunch of quote system critical binaries that protect clients from panics and timeouts.

37:22.310 --> 37:26.670
So a bunch of system processes are actually muted by default.

37:26.790 --> 37:36.710
Well, this is problematic if we invert muting because remember when I said we invert muting, that first unmutes everything, which means it's going to unmute the default set, which is not what we want to do.

37:37.050 --> 37:43.730
Apple says, okay, if you're going to do mute inversion, make sure you call ES unmute all first.

37:43.730 --> 37:57.150
This will temporarily unmute the default set and then when you invert muting, which mutes everything, it will mute the default set back, essentially ensuring that the default mute set is always muted, which is what we want.

37:58.830 --> 38:04.830
Let's now look at some code that implements mute inversion that hopefully makes this all a little bit more clear.

38:05.190 --> 38:08.810
So here is some code to protect the user's directory.

38:09.090 --> 38:13.530
Specifically, we're going to register for the auth open API event.

38:13.650 --> 38:20.410
This will be delivered to us any time anybody tries to open any files, in this case, in the user's document directory .

38:20.890 --> 38:22.750
Top part of the code, don't worry about it.

38:22.750 --> 38:25.690
In the bottom, though, is where we find the mute inversion logic.

38:25.990 --> 38:28.610
The first thing we do is unmute all the paths.

38:28.610 --> 38:30.610
This is to handle the default mute set.

38:30.610 --> 38:32.310
We then invert muting.

38:32.310 --> 38:43.110
This remutes the default mute set and then also tells Apple when subsequently we call the original mute APIs, instead of muting things, it should unmute something.

38:43.190 --> 38:56.690
So on line 19, we invoke ES mute path, but since we've inverted muting, this will actually tell end point security that we are just interested in events for the user's document directory.

38:57.250 --> 39:08.290
You can read more about that in the book, but if we compile this code and execute this, we can see now any time a process attempts to access the user's documents directory, we get a notification.

39:08.290 --> 39:11.710
Just for this, no other files, we don't care about anything else.

39:11.710 --> 39:19.910
And if it's something like finder, we can trust and allow that, whereas if it's something like max stealer, we can block that and protect the user.

39:21.150 --> 39:24.030
So that's mute and mute inversions.

39:24.230 --> 39:28.390
The next thing, one of the last things I want to talk about is, what's new?

39:28.610 --> 39:34.870
I mentioned that Apple continues to invest in end point security, which is awesome and something I really appreciate.

39:35.770 --> 39:39.870
And one of the great things they do is, they often add new events.

39:40.450 --> 39:43.830
This is added in the ES types dot H file.

39:43.830 --> 39:50.650
You can open that and you can see towards the end of the big structure that contains all the events, the new events that are added.

39:50.990 --> 40:00.330
Apple also adds comments explaining what versions of macOS these new events are supported on because, here's another nuance, they don't back port them.

40:00.430 --> 40:03.490
Which is fine, but just something we need to be aware of.

40:04.110 --> 40:09.970
So if we look at this enum, we can see some of the latest events they've added and they're actually super cool events.

40:10.210 --> 40:18.050
So for example, in macOS 10 dot 13, they added the XP malware detected notification event.

40:18.050 --> 40:23.010
XP is XProtect, this is Apple's internal macOS antivirus product.

40:23.010 --> 40:26.950
I don't know if we can quite determine that, but it's a malware detection capability.

40:26.950 --> 40:35.290
They've now added an end point security message that your tool can subscribe to that when Apple detects some malware, it will let you know as well.

40:35.290 --> 40:36.330
Super cool.

40:36.790 --> 40:40.050
Another one is the BTM launch item ad.

40:40.050 --> 40:41.970
This is related to persistence.

40:42.570 --> 40:54.890
If you register for this method, or this event, now anytime anything persists on the system as a login item, launch daemon or launch agent, macOS end point security will let you know.

40:54.890 --> 41:03.850
This is super useful as well because the vast majority of malware persists in this manner and now we have a generic way to detect that something was just persisted.

41:03.850 --> 41:04.890
Super cool.

41:05.090 --> 41:11.170
And then finally in macOS 15 dot 4, Apple added the ability to see TCC events.

41:11.170 --> 41:11.970
Which is amazing.

41:11.970 --> 41:14.310
I've been begging for this for years.

41:14.550 --> 41:23.570
So we'll look at this on the next slide, but before we jump to that, note that if you want to use the new events, you should wrap them in some run time safety checks.

41:23.570 --> 41:30.810
Again to ensure that if your tool is run on an older version of macOS where these new events are not available, bad things don't happen.

41:31.090 --> 41:37.330
If you're using objective C, you can just use the available keyword and the compiler will take care of everything else.

41:38.830 --> 41:45.490
So let's briefly talk about this new TCC event because it's something I'm super stoked and really appreciated that Apple added.

41:45.650 --> 41:48.750
So many of you are probably familiar with TCC.

41:48.750 --> 41:57.350
Quick reminder, it is the technology on macOS that protects sensitive user components and sensitive devices on macOS.

41:57.430 --> 42:02.910
If we pull out extracted strings from the TCC daemon, we get a comprehensive list.

42:02.910 --> 42:09.490
It's things like your address book, your calendar, your phone calls, your face ID, your desktop, your photos.

42:09.490 --> 42:14.050
Things that Apple rightfully says, hey, should be protected.

42:14.290 --> 42:21.490
This is great because it means if malware even gets on your system, if it tries to access your photos or your location, TCC will block that.

42:22.510 --> 42:32.890
Malware though is starting to catch on and some of it has, some samples have exploits to get around this, but the run of the mill malware just asks the users.

42:32.890 --> 42:39.210
Especially if the malware is in a trojanized application that the user thinks is legitimate.

42:39.490 --> 42:41.810
So as an example, we have gravity rat.

42:41.810 --> 42:48.830
Gravity rat can detect if an item it's interested in, for example, your photos or documents, are protected by TCC.

42:48.830 --> 42:58.990
In that case, it just shows the user an alert saying, hey, I can't run until you grant me full disk access, essentially sidestepping TCC.

42:59.190 --> 43:08.710
And again, since this is a trojanized application, naive users might not think anything is amiss and then go ahead and grant gravity rat or the terminal full disk access.

43:08.710 --> 43:11.550
Previously security tools could not see this happening.

43:11.730 --> 43:22.510
However, because of this new TCC modification event, we now can register for that and get alerted if the user or malware modifies the TCC permissions.

43:22.910 --> 43:28.870
Now the structure for this new event is pretty involved and the documentation wasn't that good.

43:28.870 --> 43:42.850
So what I do in this case is just execute Apple's ESS, ES logger tool, specify the new event and then perform some action to trigger that event and then look at what the values are reported.

43:43.330 --> 43:58.350
So if I follow the instructions for gravity rat and go into the system's settings preference pane and give terminal full disk access, this is what ES logger will report to us for this new TCC modification event.

43:58.450 --> 44:01.630
We see the responsible process is TCCD.

44:01.630 --> 44:03.550
This is not super useful.

44:03.670 --> 44:05.750
It's the same for all these messages.

44:05.870 --> 44:10.050
It's just because the TCC daemon is the one actually making the TCC modification.

44:10.290 --> 44:14.570
More importantly though, are the values in the actual event.

44:14.690 --> 44:17.370
We see the TCC access that was granted.

44:17.370 --> 44:19.510
In this case, full disk access.

44:19.610 --> 44:22.130
We see the subject of permissions.

44:22.130 --> 44:25.210
That is the process that was granted the TCC permissions.

44:25.210 --> 44:26.470
In this case, the terminal.

44:26.470 --> 44:27.910
And then finally, the instigator.

44:27.910 --> 44:30.730
This is kind of like another responsible process.

44:30.730 --> 44:39.630
And in this case, because we are following gravity rat instructions and doing it via the system preferences application, that is the value of this instigator application.

44:40.670 --> 44:42.910
We can then implement this in code.

44:42.910 --> 44:48.610
Again, this is just for a resource , but this is how to extract the relevant members from that new TCC event.

44:48.610 --> 44:53.570
So you can take some action to decide if this is something that you want to block or look into.

44:53.570 --> 44:56.550
You know, is it malware granting itself TCC permissions?

44:56.570 --> 45:00.310
Is it the user giving TCC permissions to something it should not?

45:00.310 --> 45:01.430
Et cetera, et cetera.

45:04.230 --> 45:15.530
Now the last new thing I want to talk about that I'm really excited about, yes, I get excited about these things, is new in Mac OS 26 and it is ESCS validation category.

45:16.010 --> 45:24.090
And what this is, is endpoint security will now for processes tell you the code sign validation category.

45:24.450 --> 45:35.950
As we can see in the enum, the values for this range from platform, if it's a platform binary, part of the operating system, to development, app store, locally, if it's ad hoc.

45:35.950 --> 45:38.310
And this is all super, super cool.

45:38.390 --> 45:40.090
Why is this super, super cool?

45:40.090 --> 45:45.690
Well, previously, endpoint security clients had to compute or figure out this information themselves.

45:45.770 --> 45:46.550
Why?

45:46.550 --> 45:49.050
Well, let's take block block, for example.

45:49.590 --> 45:56.550
Block block treats applications from the Mac OS official app store differently than ad hoc signed binaries.

45:56.550 --> 46:05.370
This is because apps from the legitimate official trusted Mac app store are signed, validated by Apple, and also run in a sandbox.

46:05.370 --> 46:07.790
So they can't really do much bad.

46:07.790 --> 46:11.670
So there's very few examples of actually malware coming from the Mac app store.

46:11.670 --> 46:14.970
However, there's a ton of malware that is ad hoc signed.

46:15.370 --> 46:22.410
Previously, endpoint security would just tell you, hey, this process is signed, and it would be up to you to determine how it was signed.

46:22.410 --> 46:25.730
Either ad hoc, from the Mac app store, et cetera, et cetera.

46:25.730 --> 46:32.330
Now, you could do this, but it was a little bit complicated and used a lot of code, and it was somewhat CPU intensive.

46:32.630 --> 46:37.130
Well, the great news is in Mac OS 26, endpoint security will now tell you this.

46:37.130 --> 46:43.250
So you can just delete all your old code, and your code is both now simplified and more optimal.

46:43.690 --> 46:44.730
Hooray.

46:45.730 --> 46:46.510
All right.

46:46.510 --> 46:55.750
The last thing I want to talk about are some limitations, because at this point, we've touched on a lot of advanced topics, and hopefully illustrated the power of endpoint security.

46:55.750 --> 47:01.330
So you might be thinking it's a panacea , and it almost is, save for two main limitations.

47:01.650 --> 47:06.130
First, events sometimes aren't as comprehensive as we would like.

47:06.130 --> 47:12.050
So, for example , the TCC event that we just talked about is only delivered when TCC is modified.

47:12.070 --> 47:16.030
There's a lot of malware that actually checks if it has TCC permissions.

47:16.150 --> 47:19.150
That does not generate currently any ESS event.

47:19.150 --> 47:24.050
I would like that, because legitimate software often doesn't check these things.

47:24.050 --> 47:26.050
So this would be a very good thing to have.

47:26.650 --> 47:35.490
Also, if malware tries to perform some TCC action that's blocked, that also doesn't generate an event, because the TCC event is just for modifications.

47:35.770 --> 47:39.770
So on the slide, we have malware known as Windtail and JokerSpy.

47:39.770 --> 47:42.910
JokerSpy checks to see if it has TCC permissions.

47:42.910 --> 47:45.550
This generates no endpoint security notifications.

47:45.610 --> 47:49.970
Windtape tries to execute the screen capture utility to take a screenshot.

47:49.970 --> 47:52.250
This is now blocked by TCC.

47:52.330 --> 47:55.870
Also we don't get an endpoint security message for this.

47:55.870 --> 48:01.690
So this is just one example, but sometimes the events are not as comprehensive as you'd like, so be aware of that limitation.

48:02.650 --> 48:07.530
The other limitation is endpoint security events only trigger for new activity.

48:07.530 --> 48:12.890
This is not a critique of endpoint security, it's just understanding what it is designed to do.

48:12.930 --> 48:24.850
So if you're writing a security tool and you get installed on a new system, you might want to, for example, enumerate all existing persistent items, or look at everything that has already been granted TCC access.

48:24.850 --> 48:26.890
Endpoint security is not going to help you there.

48:26.890 --> 48:27.970
Neither should it.

48:27.970 --> 48:30.590
So again, just be aware of that limitation.

48:30.970 --> 48:33.930
And also, endpoint security doesn't cover everything.

48:33.930 --> 48:41.870
So for example, if you want to do host-based network monitoring, endpoint security does not provide information about network activity.

48:41.870 --> 48:45.530
Instead, you're going to want to use Apple's network extension frameworks.

48:45.550 --> 48:55.370
Some resources on those additional technologies, but again, the takeaway here is you might need a supplement to create a comprehensive Mac security tool.

48:56.430 --> 49:00.150
Alright, finally, some conclusions and takeaways.

49:00.670 --> 49:03.510
Really, two main takeaways that are pretty simple.

49:03.510 --> 49:06.570
First, endpoint security should be your bestie.

49:06.570 --> 49:13.970
I cannot tell you how amazing it is for using or for creating security tools on Mac OS.

49:13.990 --> 49:23.770
Because it really gives us the ability to detect or at least observe, essentially, any action that even the most sophisticated malware performs.

49:24.290 --> 49:34.930
Now, it's up to us to determine if that action is malicious or not, and that could be a whole separate talk, but at least provides us the ability to observe the events of even the most sophisticated threats.

49:35.570 --> 49:40.870
Other takeaway, make sure you use the more advanced capabilities of endpoint security.

49:40.870 --> 49:50.430
Caching, authorization events, deadlines, et cetera, et cetera, but be aware of the nuances and limitations so you don't get bit figuratively in the butt.

49:51.390 --> 49:56.510
Now, if you are interested in learning more, I already mentioned the Art of the Mac Malware book series.

49:56.510 --> 50:05.990
I just want to reiterate that again because tomorrow I'm going to be doing a book signing at No Starch Presses, and we're actually going to be giving away I believe 20 or 30 copies for free.

50:06.130 --> 50:09.450
So if you want to grab a copy , show up, first come, first serve.

50:09.570 --> 50:10.610
Also, I can sign that.

50:10.610 --> 50:12.710
We can talk nerdy about endpoint security.

50:13.070 --> 50:25.450
Also, if you're interested in Mac security topics, Apple security topics, I want to invite you all to Objective by the Sea, which is three days of dedicated Mac security talks from the world's top Mac security researchers.

50:25.850 --> 50:30.350
Also, I'm doing a training there on this exact topic in lots more three days.

50:30.350 --> 50:35.110
So if you want to learn more and get a little bit more hands on, check that out as well.

50:36.110 --> 50:39.630
Briefly, I also want to mention the Objective Sea Foundation.

50:39.690 --> 50:41.570
We do a whole bunch of really cool stuff.

50:41.570 --> 50:49.270
So if you're interested in learning more about the conference, our student scholarships, and our diversity programs, check out ObjectiveSea.org.

50:49.690 --> 50:53.390
Finally, I first and foremost want to thank you all for attending my talk.

50:53.390 --> 50:56.510
Nothing worse than me as a speaker giving a talk when no one shows up.

50:56.510 --> 50:59.910
That hasn't happened yet, but very thankful for you being here.

50:59.950 --> 51:02.330
Also then, round of applause for DEF CON.

51:07.530 --> 51:15.630
I run OBTS, so it would be kind of blasphemous for me to say DEF CON is the best conference, but kind of is, so shout out to that.

51:15.630 --> 51:18.370
And then finally, I just want to thank the friends of Objective Sea.

51:18.370 --> 51:32.030
These are the companies and products that support the foundation, support my research, make us be able to give the books for free, etc., so if you know anybody who works at these companies, give them a high five and thank them.

51:32.130 --> 51:33.270
So, that is a wrap.

51:33.270 --> 51:35.170
Here are the resources if you want to learn more.

51:35.170 --> 51:37.570
Again, thank you so much for attending my talk.

51:37.570 --> 51:41.450
Go out and write some great security tools using endpoint security.

51:41.470 --> 51:42.290
Thank you.

