WEBVTT

00:00.250 --> 00:02.610
Hello everyone.

00:02.630 --> 00:05.710
Thank you for coming to our talk, Shimmy What You Got?

00:06.110 --> 00:08.930
Manipulating Shim and Office for Code Injection.

00:08.930 --> 00:11.030
We are very excited to be here.

00:11.070 --> 00:12.570
Let's introduce ourselves.

00:13.570 --> 00:15.630
My name is Ron Ben-Yitzhak.

00:15.630 --> 00:17.810
I'm a security researcher at Deep Instinct.

00:17.810 --> 00:21.590
And this is the third year in a row I'm speaking here at DEF CON.

00:25.500 --> 00:27.900
And my name is David Shandalov.

00:27.900 --> 00:30.360
I'm also a security researcher at Deep Instinct.

00:30.360 --> 00:31.920
And this is my first time here.

00:37.980 --> 00:41.120
This is what we're going to talk about today.

00:41.120 --> 00:48.580
I'll start with an intro about the app compatibility framework, what it is made of, and known techniques to abuse it.

00:48.580 --> 00:53.640
Then I'll dive into our attack surface research on Microsoft Office.

00:53.640 --> 01:04.140
I'll show how we found an interesting RPC method and combined several manipulations into a single attack that achieves both code injection and privilege escalation.

01:04.520 --> 01:07.560
Then we'll show another novel attack.

01:07.560 --> 01:15.080
We'll show the reverse engineering process of the driver and the undocumented structures that make the app compatibility mechanism.

01:15.080 --> 01:19.960
And how we discovered the finest technique to apply a malicious shim on a process.

01:19.960 --> 01:28.280
At the conclusion of the talk, we'll discuss how to detect the attacks shown here and how the community can continue our research.

01:29.640 --> 01:34.260
The app compatibility framework is used for backwards compatibility.

01:34.260 --> 01:40.300
Software developed for old versions of Windows might behave unexpectedly on newer versions.

01:40.300 --> 01:46.100
Microsoft offers many compatibility modes that might look familiar from this window.

01:46.220 --> 01:54.980
Programs might access registry paths or directories that no longer exist, such as the C-documented settings, for those who remember.

01:55.520 --> 02:02.680
Those issues are fixed with API hooking, patching the assembly of the program itself, and other runtime modifications.

02:03.540 --> 02:06.900
Behind the scenes, this is how the mechanism works.

02:06.900 --> 02:14.360
The OS uses shim database files, or SDB files, that contain the fixes and modes various applications require.

02:14.360 --> 02:17.040
The main file is sysmain.sdb.

02:17.040 --> 02:22.120
It is maintained by Microsoft and can only be modified by system updates.

02:22.180 --> 02:28.320
We can view those files using a graphic software provided by Microsoft, the compatibility administrator.

02:28.320 --> 02:35.400
Here we can see that Edge of Empires 3 requires the compatibility mode High DPI Aware.

02:35.440 --> 02:40.900
Users can also install custom SDB files by writing them to these registry paths.

02:42.120 --> 02:46.660
Like every component of the OS, people looked for ways to abuse it.

02:46.660 --> 02:51.680
There were several talks over the years about the malicious implications to the shim framework.

02:51.680 --> 03:00.240
Here you can see a DEF CON talk from almost 10 years ago that shows shims can be used for credential access, network redirection, and more.

03:00.340 --> 03:06.300
Also, Alex UNESCO released several articles about this subject back in 2007.

03:06.500 --> 03:12.400
Because this is such an old attack vector, most security products should detect malicious shim usage.

03:12.400 --> 03:18.960
And the easiest way to do it is by monitoring the registry paths used for installing custom SDB files.

03:19.820 --> 03:25.340
So, once upon a time, David and I wanted to start a new research.

03:25.340 --> 03:29.820
Initially, we thought about bypassing an EDR, or even disabling it.

03:29.820 --> 03:33.340
But apparently, some products just disable themselves.

03:34.160 --> 03:38.740
So, instead of EDR bypass, we decided to start an attack surface research.

03:38.740 --> 03:40.360
And we needed a target.

03:40.380 --> 03:43.700
One of the first choices we came up with is Office.

03:43.780 --> 03:45.960
This software is very popular.

03:45.960 --> 03:48.720
It can be found on almost every Windows machine.

03:48.720 --> 03:50.600
It is also very complex.

03:50.600 --> 03:55.140
It has COM objects, tripped-in engines, cloud synchronization, and more.

03:55.140 --> 03:59.280
The more components there are, the higher the chances to find an issue.

03:59.460 --> 04:03.640
And the most promising feature about Office is the backwards compatibility.

04:03.900 --> 04:06.540
It was released over 30 years ago.

04:06.540 --> 04:11.260
And legacy code is usually the problematic one, which is good for us.

04:11.820 --> 04:14.520
Now, let's talk about the research itself.

04:15.480 --> 04:19.460
We wanted to find RPC servers related to Office.

04:19.460 --> 04:22.960
And that led us to the service ClickToRunSVC.

04:23.220 --> 04:27.180
Here you can see the RPC interfaces it exposes.

04:27.180 --> 04:32.060
And narrowing down this list to files related to Office results in three files.

04:32.060 --> 04:37.320
The actual executable of the service, OfficeClickToRun.exe.

04:37.320 --> 04:45.380
And let's skip the long prefix and just call them virtualization.dll and subsystemcontroller.dll.

04:46.960 --> 04:51.600
We started looking into these files to see what functionality they provide.

04:51.600 --> 04:55.200
And we found an interesting string in the virtualization.dll.

04:55.360 --> 04:58.660
Could not inject subsystem.dll to child process.

04:59.240 --> 05:04.720
And lucky us, this string is used by a function that is exposed through RPC.

05:04.720 --> 05:07.320
This means that you can easily invoke it.

05:07.340 --> 05:16.920
Still, before we start reverse engineering the RPC interface and its methods, we wanted to make sure it actually performs DLL injection.

05:17.020 --> 05:23.580
So we debugged it, put breakpoints on the API used for code injection, and then we launched Word.

05:23.600 --> 05:26.920
That caused the service to call write process memory.

05:27.100 --> 05:30.840
This diagram shows the call stack that led to this API.

05:30.940 --> 05:37.640
The RPC call went through several undocumented functions in a few DLL files until it reached write process memory.

05:39.120 --> 05:41.360
So what is this DLL?

05:41.360 --> 05:47.570
The file description is Microsoft Application Virtualization Client Virtualization Manager Component.

05:48.040 --> 05:51.040
And yes, it says virtualization twice.

05:51.260 --> 05:55.360
This file exposes two undocumented RPC methods.

05:55.360 --> 06:01.740
Instead of diving headfirst into the code, we wanted to find symbols that can shed some light on these functions.

06:01.960 --> 06:07.500
We used PowerShell to find RPC clients, and that led us to a file that has symbols.

06:08.100 --> 06:10.080
subsystem64.dll.

06:10.080 --> 06:12.420
Again, I'm going to skip the long names.

06:12.420 --> 06:17.340
The functions in the client are called notifyNewProcess and notifyNewChildProcess.

06:17.340 --> 06:20.380
We didn't find anything interesting about the first one.

06:20.380 --> 06:24.460
The second function causes the server to call write process memory.

06:26.500 --> 06:30.600
Now we want to understand the flow that leads to the DLL injection.

06:30.600 --> 06:32.900
So we'll start by debugging the client.

06:33.100 --> 06:40.380
We notice that before Word performs the call, it spawns ai.exe as a child process in a suspended state.

06:40.560 --> 06:42.740
Then we reach the call itself.

06:42.740 --> 06:45.840
We reverse-engineered it and came with its definition.

06:46.020 --> 06:48.340
This syntax is for the IDL file.

06:48.340 --> 06:58.020
It sends two parameters, the process ID of ai.exe and the string subsystem64.dll, the name of the DLL that made the call.

06:58.900 --> 07:01.840
Time to switch sides to the RPC server.

07:01.840 --> 07:08.820
Like I said before, those DLL files are undocumented and we want to save time on reverse-engineering them.

07:08.820 --> 07:17.720
We searched for all the files that are related to the app virtualization platform and found out that there are files with similar names in the system32 directory.

07:17.760 --> 07:22.880
Those files have symbols and they show that the detours library is being used.

07:22.880 --> 07:29.740
This is an official library by Microsoft used for hooking and it can also inject code into another process.

07:29.740 --> 07:40.380
The functions detourUpdateProcess.dll and detourCopyPayloadToProcess are used to patch the import address table of the target process and force it to load a DLL.

07:40.620 --> 07:44.600
Comparing the two files with bindif further proves the similarities.

07:44.780 --> 07:51.640
The name primary column belongs to the office file and the name secondary column belongs to the system32 file.

07:51.640 --> 07:54.140
Those functions are a perfect match.

07:55.200 --> 07:59.980
We can easily understand how the injection is done with the source code of detours.

08:00.000 --> 08:07.780
The optional header is modified to point to a new copy of the import table that includes an additional import descriptor to the injected DLL.

08:07.860 --> 08:10.740
This is how WinDebug displays the headers.

08:10.740 --> 08:14.320
We can see the full path to the DLL, which is unusual.

08:14.420 --> 08:16.520
Compilers link the base name.

08:17.680 --> 08:20.700
This is everything done by the RPC server.

08:20.700 --> 08:24.460
Now let's go back to the client and finish going through this process.

08:24.800 --> 08:31.760
Word resumes ai.txt and since the process is not yet initialized, the loader uses the new import table.

08:31.760 --> 08:35.880
Because of that, subsystem64 is loaded into the process.

08:36.300 --> 08:43.180
We looked at what happens if we imitate the RPC call but specify a 32-bit process as the target.

08:43.180 --> 08:48.180
In this case, office click-to-run isn't writing to the memory of this process directly.

08:48.200 --> 08:55.160
It launches the tool mavinject32, which is known as a living off-the-land binary, but the injection is exactly the same.

08:56.900 --> 08:59.300
Now we want to understand exactly...

08:59.300 --> 09:03.700
now that we know exactly how the DLL is injected, what can we gain from it?

09:03.900 --> 09:07.660
Security products detect all kinds of malicious behavior.

09:07.720 --> 09:11.520
File encryption, shellcode execution, and code injection.

09:11.600 --> 09:14.420
But sometimes legitimate programs do that.

09:14.420 --> 09:15.980
We just saw an example.

09:16.100 --> 09:22.700
And to avoid generating false positive events for customers, such programs will be excluded by the products.

09:22.880 --> 09:28.620
This means that if we force office click-to-run to inject a DLL, we'll be able to bypass detection.

09:29.120 --> 09:35.620
We know the definition of the RPC method, and we can imitate it to inject subsystem64.dll.

09:35.620 --> 09:39.880
But the big question is, can we inject another DLL?

09:40.040 --> 09:46.120
As I showed before, the function receives a string, so we can just change the name of the file.

09:46.140 --> 09:51.100
But that means we'll have to write our DLL to the office directory, which is very suspicious.

09:51.220 --> 09:53.580
And it also requires admin privileges.

09:54.860 --> 10:01.020
We tried providing a full path to the file instead of the base name, and this is what happened.

10:01.080 --> 10:07.900
We changed the string to ctemp-injected.dll, and it was appended as it is to the office directory.

10:07.940 --> 10:11.100
This should raise a flag for every security researcher.

10:11.100 --> 10:14.480
It means that there are no sanity checks on the inputs.

10:14.480 --> 10:19.060
So we can go back to the 90s and use directory traversal.

10:19.060 --> 10:22.820
We can manipulate the file lookup to a completely different place.

10:22.820 --> 10:28.960
Let's display the headers of the process again with win-debug, this time after we manipulated the call.

10:28.960 --> 10:34.920
We can see our malicious string was appended to the office directory and written to the memory of the process.

10:35.900 --> 10:39.600
With this trick, we can inject any DLL we want.

10:39.660 --> 10:41.760
But there are still a few limitations.

10:42.040 --> 10:49.460
The modified import address table will be used only if the process was launched as suspended and wasn't resumed until the injection was done.

10:49.460 --> 10:51.460
It must be uninitialized.

10:51.460 --> 10:56.900
Right now, we have a new technique to force a legitimate program to inject a DLL for us.

10:56.900 --> 10:59.520
But what more can we achieve from this?

10:59.700 --> 11:04.820
A nice thing about RPC is that the client can have lower privileges than the server.

11:05.000 --> 11:08.080
The office service runs this anti-authority system.

11:08.240 --> 11:11.120
So, can we perform privilege escalation?

11:18.850 --> 11:21.230
Well, the short answer is no.

11:21.510 --> 11:25.870
The server calls RPC impersonate client before the injection is done.

11:25.870 --> 11:33.310
This means that the thread that handles our request will use our token and not the token of anti-authority system.

11:34.010 --> 11:38.930
This is done to verify that the client has enough permissions to access the remote process.

11:39.050 --> 11:47.230
After the impersonation, the request reaches a subsystem controller.dll which calls open process to gain a handle to the remote process.

11:47.230 --> 11:52.310
If we can't get this handle, so will the RPC server and the call will fail.

11:52.310 --> 11:55.970
But still, maybe we can escalate from admin to system.

11:56.810 --> 12:04.110
The first step to do that will be to launch a process with the privileges of system in a suspended state.

12:04.110 --> 12:10.930
We used API monitoring to find such calls and we found that the task scheduler service does exactly that.

12:11.170 --> 12:20.070
Scheduled tasks are a great target because there are many default ones that are configured to run a system and even some that are related to office.

12:20.990 --> 12:24.510
Such as this one, office automatic updates 2.0.

12:24.510 --> 12:31.470
Our injection will be even less suspicious if the service will inject a DLL to another process that is related to office.

12:31.470 --> 12:33.930
But we still have a few challenges ahead.

12:34.010 --> 12:38.270
The task scheduler service resumes the process shortly after it is launched.

12:38.270 --> 12:42.470
We need to find a way to hold the execution of the task scheduler service.

12:42.470 --> 12:45.810
And we can do that with an opportunistic lock.

12:47.950 --> 12:56.850
Opportunistic locks, or oplocks for short, are a special kind of locks that are used to keep data coherency across computers accessing a file server.

12:56.910 --> 12:58.790
A client can lock a file.

12:58.790 --> 13:02.910
And when another client tries to access the same file, it will wait.

13:03.070 --> 13:06.690
The server will break the lock and notify the first client.

13:06.770 --> 13:13.650
The new data will be flushed, the file will be closed, and only then the second client will be able to access it.

13:13.650 --> 13:19.530
The nice thing about oplocks is that they can be requested from the local file system by a process.

13:19.710 --> 13:25.950
This usage is effectively a semaphore managed by the local file system that synchronizes multiple processes.

13:27.190 --> 13:29.750
So, how does it relate to our attack?

13:29.910 --> 13:41.730
If we could find a file that is accessed by the task scheduler service after the process is created, but before it is resumed, we could lock it, and it will stop the service from resuming the process.

13:41.730 --> 13:45.910
Keeping the process suspended will allow us to inject a DLL to it.

13:45.910 --> 13:55.730
We monitor the system for file access while launching the scheduled tasks, and we saw that sysmain.sdb was accessed.

13:55.730 --> 13:58.190
In this image, we can see the call stack.

13:58.190 --> 14:05.310
Inside createProcessInternal, functions related to the app compatibility were called, and then the shim database was opened.

14:06.570 --> 14:14.810
At this point, we know that the task scheduler sometimes reads sysmain.sdb, but we need to understand which tasks lead to that.

14:14.810 --> 14:19.570
We need to find a task that executes a file with app compatibility settings.

14:19.570 --> 14:28.850
To do that, we locked the sdb file, launched every task registered on the machine, and checked when we were notified about the lock breaking.

14:28.950 --> 14:33.210
This led us to a task that executes Microsoft Edge updates.

14:33.210 --> 14:37.570
This file has app compatibility settings because of the following entry.

14:37.570 --> 14:43.050
The generic installer fix will be applied on every process that has the word update in it.

14:43.170 --> 14:46.510
So, this is good, but still, it's not good enough.

14:46.510 --> 14:51.930
This file is under Program Files x86, which means it is a 32-bit process.

14:51.930 --> 14:54.870
We want to find a target for 64-bit as well.

14:55.970 --> 15:08.530
We continue digging into this subject to understand under which circumstances the sdb file will be read, and we noticed a strange behavior that applies to the OS as a whole, not just the task scheduler service.

15:08.990 --> 15:15.690
The sdb file was read the first time an executable ran since the machine started, even if it didn't need a fix.

15:15.690 --> 15:18.850
And after that, in all other runs, it wasn't.

15:19.730 --> 15:28.030
If we could guarantee that the sdb file will be read any time an executable runs, we could choose any scheduled task as our targets.

15:28.350 --> 15:36.030
And, of course, we could register a custom sdb file that applies some fix to every process, but that is too noisy.

15:36.030 --> 15:39.650
We want to avoid actions that are monitored by security products.

15:39.930 --> 15:43.570
We need to find a way to manage the app compatibility mechanism.

15:43.830 --> 15:48.450
We looked for files related to this mechanism and found apphelp.dll.

15:48.510 --> 15:56.710
By looking at the code of this DLL, we understood that it wraps various operations with the API AntiAppHelpCacheControl.

15:56.730 --> 15:58.950
Let's try to understand how to use it.

16:00.070 --> 16:04.210
This is an undocumented API that is exported by NTDLL.

16:04.570 --> 16:14.130
We searched for references to this API online and in several DLL files until we found that the symbols of combase.dll contain information about it.

16:14.130 --> 16:19.330
This is a screenshot of a function from combase without any reverse engineering.

16:19.390 --> 16:30.690
We can see that the first parameter is an integer that represents the type of operation to be performed, and the second parameter is a structure with various members that are filled based on the operation chosen.

16:32.490 --> 16:38.990
We extracted those definitions and that revealed to us everything that can be done with this API.

16:39.050 --> 16:44.970
We applied the definitions on calls from other DLL files and that helped us understand them better.

16:45.050 --> 16:47.310
Let's look at createProcess, for example.

16:47.550 --> 16:52.970
Now we know that it performs the lookup operation and what information it requires.

16:53.150 --> 16:56.490
Like I said before, we encountered a strange behavior.

16:56.490 --> 17:03.070
The sdb file was read the first time in an executable run since the machine started, even if it didn't need a fix.

17:03.070 --> 17:04.770
And then, it wasn't.

17:04.770 --> 17:10.130
At this point, we had enough information to come up with an assumption on why it happens.

17:11.370 --> 17:14.790
In this scenario, cmd is going to launch calc.

17:14.790 --> 17:20.330
So we have these two processes and also the upheld cache, which is empty at this point.

17:20.410 --> 17:25.090
We know that when we call createProcess, the lookup operation is done on the cache.

17:25.090 --> 17:28.550
So cmd is going to look for an entry about calc.

17:28.550 --> 17:32.430
The cache is empty, so the response is no entry found.

17:32.430 --> 17:39.410
That causes cmd to read the sdb file to check if it contained information about fixes calc requires.

17:39.410 --> 17:41.750
It doesn't require any fix.

17:41.770 --> 17:46.010
So the next step is that the cache is updated and an entry is added.

17:46.090 --> 17:48.110
Calc, no fix needed.

17:48.450 --> 17:55.170
Then, let's say cmd launches calc again, so it queries that cache one more time.

17:55.430 --> 17:58.990
This time, the response is no fix needed.

17:58.990 --> 18:02.910
And that is why cmd doesn't read sysmin.sdb again.

18:03.070 --> 18:09.450
Based on this assumption, if we could remove this entry from the cache, the sdb file will be read again.

18:10.850 --> 18:19.410
We looked at various calls to anti-app-help-cache-controller and found out that both kernel32 and app-help perform the remove operation.

18:19.410 --> 18:22.650
In this pseudocode, we can see the information required.

18:22.650 --> 18:25.390
It requires the path and the handle to the file.

18:25.790 --> 18:32.910
Kernel32 exports a function that does most of the work for us, and it saves us the effort of recreating this call in our code.

18:33.390 --> 18:39.070
After this call, the execution of the file will once again trigger reading the sdb file.

18:40.330 --> 18:43.450
Okay, so we talked about a lot of stuff.

18:43.450 --> 18:46.770
RPC methods, locks, and undocumented API.

18:46.770 --> 18:50.010
So in case you lost track, let's put everything together.

18:50.110 --> 18:51.770
This is the flow of the attack.

18:51.870 --> 18:54.890
We'll start by writing the DLL that will be injected.

18:55.170 --> 18:57.050
Then we'll pick a scheduled task.

18:57.050 --> 18:59.890
Let's say, Office Automatic Updates 2.0.

18:59.950 --> 19:02.330
We need to take care of the shim cache.

19:02.330 --> 19:07.350
The file that will be executed might have an entry, so we're going to remove it.

19:07.910 --> 19:10.490
Then we'll lock sysmin.sdb.

19:12.010 --> 19:18.750
The next step will be to start the task, and that will launch a suspended process with the privileges of system.

19:19.070 --> 19:24.110
The task scheduler will try to read the sdb file and start waiting.

19:24.330 --> 19:31.710
That will send us a notification about the lock breaking, which means it's time to send the RPC request to the office service.

19:32.250 --> 19:38.050
This service will patch the import table of the suspended process and link it to our DLL.

19:38.210 --> 19:46.050
The last step will be to release the lock, and that will cause the task scheduler to resume the process and our DLL will be loaded.

19:47.810 --> 19:49.710
Ready to see if it works?

19:54.870 --> 19:57.570
First, we'll copy our tool to the machine.

19:57.990 --> 19:59.690
And let's even scan it.

20:01.030 --> 20:03.750
And of course, Defender won't detect it.

20:04.410 --> 20:14.870
Now, just to make it clear, we are running the latest version of Office 365, and also the latest Windows 11 build.

20:16.170 --> 20:21.810
Now that we made it clear, let's start monitoring the system and launch our tool.

20:23.920 --> 20:31.620
We can see that Office C to our client loaded our DLL, and that we gained the console with the privileges of...

20:31.620 --> 20:33.640
anti-authority system.

20:39.630 --> 20:41.110
Time to summarize.

20:41.170 --> 20:45.070
We decided to make an attack surface research on Microsoft Office.

20:45.070 --> 20:50.050
We manipulated several components of the OS into a single functioning attack.

20:50.050 --> 20:53.030
And these are the advantages of it.

20:53.150 --> 20:59.930
Security products will most likely ignore code injection done by Office click-to-run, because this is its purpose.

20:59.970 --> 21:01.990
So we'll bypass detection.

21:01.990 --> 21:13.830
It will be difficult to link this attack back to us, because not only the injection is done by another process, but the target process is spawned under the task scheduler, not under us.

21:14.130 --> 21:20.990
We escalate our privileges from admin to system, and the rest of the actions we perform aren't suspicious.

21:21.190 --> 21:28.190
It is very unlikely that someone monitors calls to anti-app-help-cache-control, or monitors using Oprox.

21:28.830 --> 21:31.370
So this is the end of my part of the talk.

21:31.370 --> 21:33.590
Now please welcome David Chandalov.

21:40.620 --> 21:42.100
Thank you, Ron.

21:42.220 --> 21:50.840
As we concluded our first attack surface research, we identified a significant knowledge gap regarding anti-app-help-cache-control.

21:50.840 --> 22:00.080
Despite extensive information available online, we found that crucial details about some data structures and flows remain unclear.

22:00.500 --> 22:10.800
Additionally, with the continuous updates and changes in Windows versions over the years, many publicly shared insights have been altered by Microsoft.

22:10.840 --> 22:16.960
Today, I'll provide a comprehensive overview of the mechanism and the modernized attack.

22:16.960 --> 22:18.940
So, let's dive right in.

22:19.780 --> 22:25.380
As we embarked on our research journey, we were driven by a fundamental question.

22:25.460 --> 22:29.320
What can we achieve with the anti-app-help-cache-control API?

22:29.460 --> 22:36.040
This inquiry became our guiding light, sparking our curiosity and determination to delve deeper.

22:36.240 --> 22:40.840
Our initial exploration gave us a foothold, but we knew we needed more.

22:40.840 --> 22:44.260
We needed to understand the technical intricacies.

22:44.580 --> 22:47.740
After all, this API controls shim fixes.

22:47.740 --> 22:54.020
Maybe we can bend it to our will and control which shim fixes are applied to specific processes.

22:55.400 --> 22:58.040
Our second question was more technical.

22:58.340 --> 23:07.980
As you can see from the screenshots, during the reading of sysmain.sdb, we noticed that anti-app-help-cache-control interacts with the kernel.

23:08.180 --> 23:15.880
This API calls a driver named ahcache.sys, which contains some intriguingly named functions.

23:15.880 --> 23:24.180
Functions like api-lookup and write-to-process and cache-lookup stood out, suggesting deeper mechanisms at play.

23:24.240 --> 23:32.260
These findings hinted at something significant inside of ahcache.sys, something that required us to dig deeper.

23:32.640 --> 23:35.300
So, down the rabbit hole we go.

23:36.480 --> 23:39.200
All right, let's lay the foundation.

23:39.200 --> 23:46.480
To understand how ahcache.sys operates, we need to start with the basics of its initialization process.

23:46.480 --> 23:53.980
When the system boots up, ahcache.sys is loaded, and it requires some initial setup to function properly.

23:54.080 --> 23:57.260
This is where the registry comes into play.

23:57.820 --> 24:03.920
The registry provides essential values that ahcache.sys reads and stores data to.

24:04.140 --> 24:08.640
These values act as a safe location for the driver's operations.

24:09.660 --> 24:15.500
This path contains binary data that the driver sorts into an AVL table.

24:15.620 --> 24:23.060
The cache needs to be properly initialized through the Windows API before these components can start working.

24:24.140 --> 24:28.040
The opposite process happens a shutdown and restart.

24:28.120 --> 24:33.200
The AVL table is dumped into the registry, into the app.compat.cache value.

24:34.820 --> 24:43.620
Let's take a moment to understand the link between sysmain.sdb, registry entries, and the app.compatibility cache.

24:43.760 --> 24:51.580
Each entry in the registry's values data is representing either a file that needs a shim fix or a file that doesn't.

24:51.640 --> 24:59.780
We'll revisit the decision-making process for applying fixes, but for now, let's focus on entries indicating files that need a fix.

24:59.920 --> 25:08.170
These entries contain several fields, the most significant being the exit tag, which points to a specific shim fix.

25:08.620 --> 25:13.880
By examining the data within these entries, we can observe notable differences.

25:14.140 --> 25:20.860
Specifically, free bytes vary across entries, and in the last entry, the free bytes are zeroized.

25:21.040 --> 25:24.020
Is it a sign for a file not needing a fix?

25:24.380 --> 25:31.260
Considering the data's little-endian format, converting it could reveal connections to sysmain.sdb.

25:33.120 --> 25:39.480
With sdbexplorer, we can search for these converted values in a readable version of sysmain.sdb.

25:39.640 --> 25:47.020
Zooming in on the fields that appear in the sdb, we have the name of the file field, and we can see the matching file field.

25:47.260 --> 25:54.040
The matching file field contains just an asterisk, so the whole name field will be compared as it appears.

25:54.520 --> 25:57.540
And lastly, we find the shim reference field.

25:57.540 --> 26:00.440
Each shim reference has a name and an ID.

26:00.440 --> 26:04.100
Some have a command line for additional arguments.

26:04.300 --> 26:07.440
Each field has an hexadecimal number attached.

26:07.440 --> 26:08.420
Why?

26:09.720 --> 26:18.260
It represents the address in the sdb that contains the exit tag as it prefixes the shimfix information block.

26:19.500 --> 26:29.980
Now that we understand what an exit tag is and how the registry cache and sysmain.sdb are linked, we wanted to look under the hood of Ahcache.sys.

26:30.000 --> 26:52.540
We started looking at the dispatch routines for device Ahcache, and we found that, among other things, anti-app-help-cache-control can update the table with hc-api-update that utilizes insert-element-api, lookup a table entry with hc-api-lookup-cdb that uses lookup-element-api,

26:53.620 --> 27:00.380
or it can remove an entry from the table with hc-api-remove using delete-element-api.

27:00.780 --> 27:04.760
We decided to continue looking through the dispatch routines.

27:06.160 --> 27:18.520
As we already have shown, anti-app-help-cache-control uses the Ahc service class enum, but it is also being used in the dispatch routine inside of Ahcache.sys.

27:18.520 --> 27:24.240
The enum has an interestingly sounding member, in its process data for short.

27:24.240 --> 27:27.280
We traced a function that is using this value.

27:27.940 --> 27:32.380
We were surprised to see no mentions of AVL table manipulation.

27:33.620 --> 27:36.040
Maybe this is what we were looking for?

27:36.040 --> 27:38.200
Writing to a process through a kernel driver?

27:38.200 --> 27:39.520
Sounds awesome!

27:40.460 --> 27:45.160
But before we check if we got the good news, let's go through some definitions.

27:45.160 --> 27:49.860
Almost every dispatch routine has a unique structure for its operation.

27:51.080 --> 27:54.840
This structure contains an undocumented data field.

27:54.840 --> 28:03.520
We tried to search the web for definitions, and with some more in-house reverse engineering, we got shim-data.

28:03.520 --> 28:07.760
It contains a fixed magic value and a fixed size value.

28:07.760 --> 28:10.940
Remember this struct, as we will come to visit it later.

28:12.320 --> 28:19.080
Diving deeper inside the function, the calling process and the target process are being checked.

28:20.000 --> 28:21.820
Now here is the tricky part.

28:21.820 --> 28:25.640
We need to have a protected signer app and PPL.

28:26.260 --> 28:29.280
And these two values will be important later.

28:30.180 --> 28:34.120
But the call fails in PSGetProcessProtection.

28:34.120 --> 28:42.780
Looking at every process in Windows 11, we concluded that no Windows apps with this kind of protection exist.

28:43.180 --> 28:45.140
We came to a dead end.

28:45.520 --> 28:50.720
But the undocumented structure I talked about before, it piqued our interest.

28:51.980 --> 28:58.000
We decided to take that strange name we found and try to look for references of this structure.

28:58.540 --> 29:03.480
Maybe we can understand by which operation it is being used and who can be the target.

29:04.840 --> 29:06.760
There were a few hits.

29:06.760 --> 29:16.640
Reverse engineering the functions that reference shim data revealed that this structure represents the shim fixes that need to be applied to a process.

29:17.960 --> 29:20.780
Let's see how a new process is born.

29:21.860 --> 29:28.720
Notepad.exe is the child process that is created on behalf of the parent process cmd.exe.

29:28.740 --> 29:37.160
The parent queries the app help cache to check if the child process requires shim fixes, as we have shown in the first attack.

29:37.920 --> 29:44.000
The parent process reads this main.sdb to retrieve the complete information about the fixes.

29:45.400 --> 29:53.660
The parent builds the structure according to the specific fixes and writes it to the memory of the child process.

29:55.740 --> 30:03.020
The parent modifies the value of the process environment blocks pshim data to point to the new structure.

30:05.220 --> 30:08.920
NTDLL is already loaded in the child process.

30:10.020 --> 30:16.920
So NTDLL's loader loads apphelp.dll if pshim data is not empty.

30:17.920 --> 30:22.060
Apphelp identifies which shim fixes are to be applied.

30:23.000 --> 30:28.000
And so apphelp.dll applies the shim fixes according to the structure.

30:29.520 --> 30:36.560
We also wanted to share the flow of the shim data structure creation for future references.

30:36.940 --> 30:47.060
The flow starts with create process internal in kernel base, goes through kernel 32 and finally ends with apphelp.dll.

30:47.120 --> 30:56.280
The finished struct is built in the sdb pack up compa data function inside of apphelp.dll.

30:56.740 --> 30:58.460
Okay.

30:58.460 --> 31:06.960
Let's consider the implications of manipulating a system component to build and trigger unauthorized fixes.

31:06.960 --> 31:14.560
This could potentially allow us to inject or alter code in a way that bypasses typical security measures.

31:15.460 --> 31:25.860
Our investigation into pshim data begins with understanding what data is being written to this specific part of the process environment block.

31:27.120 --> 31:33.380
We utilized the compatibility administrator to create and apply custom rules.

31:36.200 --> 31:44.320
By extracting the shim data directly from process memory, we gained a first insight into how the data is organized.

31:45.440 --> 31:49.680
We chose to fuzz the inputs to see the effect on the data.

31:49.680 --> 31:54.680
This process helped us identify patterns in the data handling.

31:55.080 --> 32:01.060
By following these steps, we gained a comprehensive understanding of how shim data looks like.

32:02.220 --> 32:12.180
And so, at last, we have reversed engineered the shim data structure, essential for understanding how to manipulate shims to our advantage.

32:12.960 --> 32:17.820
Here we can see the previous version of the shim data, if you can recall.

32:17.820 --> 32:20.380
This is the struct I ask you to remember.

32:20.400 --> 32:28.160
There are quite a few changes, most notably the exit tab type field, the exit tag field, and the exit count field.

32:28.160 --> 32:32.640
All are essential for correct use of shim fix manipulation.

32:34.400 --> 32:39.780
At this stage, we are preparing to use all of our accumulated knowledge for an attack.

32:39.840 --> 32:48.240
We can make a target process load a shim fix simply by building our own shim data struct and pointing to the target pshim data to it.

32:48.260 --> 32:52.720
The process won't check any condition the original rule has configured.

32:52.820 --> 32:56.100
This allows us to apply any fix we want.

32:56.280 --> 33:04.260
We chose to inject a DLL into the target process by itself.

33:12.530 --> 33:20.630
This effectively makes the attack a file-less and register-less DLL injection that can evade detection.

33:21.910 --> 33:33.730
According to this entry, rtvideo.dll will be injected if the process name starts with glj, ends with the temp extension, and it has the correct checksum.

33:33.730 --> 33:39.180
Luckily, these checks are done by the parent process and not by the child process.

33:39.550 --> 33:49.910
This means that once the exit tag in shim data points to this entry, the child process's app.ldll will apply the fix without checking the conditions.

33:50.990 --> 33:54.850
Having said all that, our attack has three limitations.

33:55.070 --> 33:59.090
The target process must be started as a suspended process.

33:59.830 --> 34:12.690
If the injected process executable file resides in this specific path, or the security identifier of the file's owner is a trusted installer, the shim fix won't be loaded.

34:13.870 --> 34:20.230
Injected DLL is not available to 64-bit processes as acgeneral.dll revealed.

34:20.610 --> 34:23.790
And you won't believe it, we found the target.

34:23.790 --> 34:27.250
And it's the Microsoft Edge updater we have shown before.

34:28.090 --> 34:32.990
Microsoft has made our lives easier as all three limitations are not present.

34:32.990 --> 34:34.410
Let's inject.

34:35.310 --> 34:40.690
At this point, we have enough knowledge to abuse the app compatibility mechanism.

34:40.690 --> 34:43.370
So let's go over all of the steps.

34:43.910 --> 34:48.750
We need to write our own DLL as the name of the rule specifies.

34:49.970 --> 34:53.550
We launch our binary as a suspended process.

34:54.410 --> 34:59.190
The struct is built with the correct tag as in our example.

35:00.650 --> 35:04.050
We write the struct to the target process's memory.

35:04.270 --> 35:07.310
We point to the struct.

35:07.930 --> 35:09.890
We resume the execution.

35:10.690 --> 35:14.790
And so app help will help us and apply our desired fix.

35:14.790 --> 35:17.670
An RT video will load to the target process.

35:17.870 --> 35:20.170
Let's see how it looks in action.

35:23.970 --> 35:27.270
shim injector.exe is dropped.

35:28.730 --> 35:34.130
And so we can see the hello message from inside of the child process.

35:34.510 --> 35:37.470
RT video.dll is loaded by our target.

35:37.630 --> 35:42.970
We can see our call stack going from install after init to ns inject dll.

35:42.970 --> 35:45.430
And lastly, to load library.

35:45.570 --> 35:48.310
We also have some logs on the command prompt.

35:48.310 --> 35:54.330
You can see the unique size, magic, exit type and exit tag we defined earlier.

36:01.420 --> 36:03.720
Let's recap our second attack.

36:03.720 --> 36:12.640
There is a long history of shim attacks and how security products typically detect and mitigate malicious shim attacks, attack vectors.

36:13.360 --> 36:19.260
We were able to uncover new definitions and insights on the app compatibility component.

36:19.260 --> 36:23.800
And we used them to change what we think about this attack vector.

36:24.760 --> 36:30.200
This new perspective allowed us to create a new file-less and registry-less attack.

36:30.940 --> 36:41.060
We essentially took care of the problem of creating a custom SDB on a system with all that comes with it, namely registry and disk tracks.

36:42.680 --> 36:56.660
By writing to a child process which is not suspicious and by loading the target dll from the suspended child process before any EDR hook can be established, we effectively bypassed EDR detection.

36:58.680 --> 37:07.220
We chose this specific shim fix because it is applicable to many scenarios and demonstrates our attack in a clear way.

37:07.480 --> 37:11.920
There are many more shim fixes that can be used for malicious purposes.

37:11.920 --> 37:13.780
This was only one of them.

37:14.940 --> 37:16.480
We've come a long way.

37:16.480 --> 37:21.120
Let's summarize both attacks and see what we can take away from this research.

37:22.520 --> 37:28.120
As for detections, let's go over how should someone detect these kinds of attacks.

37:28.560 --> 37:34.300
For the first attack, RPC is a big and early part of the first attack.

37:34.300 --> 37:42.820
So monitoring remote procedure calls made to click-to-run service can reveal the use of non-standard dll paths.

37:43.300 --> 37:50.760
Requests for opportunistic locks on critical system files like sysmain.sdb should be flagged.

37:52.120 --> 38:00.180
Implementing security policies that restrict such high-level memory write operations as it is very suspicious.

38:00.320 --> 38:05.180
Click-to-run service shouldn't write to this type of processes on its own.

38:06.580 --> 38:24.100
Regarding the second attack, keeping an eye on file system activity, particularly for the creation of dll files which are listed in sysmain.sdb and are in directories unrelated to the original files, to the original rules.

38:25.760 --> 38:33.300
Also, we invite the community to take our findings to refine our attacks and make new and better ones.

38:33.680 --> 38:35.520
Some ideas.

38:35.520 --> 38:42.360
The community could find the target for the init process data operation that we didn't find.

38:43.020 --> 38:52.120
There is much more to understand about the shim data structure and how it can affect the execution of the AHCache.sys functions.

38:53.260 --> 39:02.300
There are many more flows that can potentially manipulate the AVL table which in turn will affect which process will get what shim fix.

39:05.360 --> 39:15.280
In conclusion, in our presentation, we detailed our comprehensive methodology for conducting attack surface research.

39:16.500 --> 39:31.420
By leveraging and manipulating various system components, including services, op locks and compatibility mechanisms, we demonstrated how to consolidate these elements into a singular cohesive attack strategy.

39:32.100 --> 39:42.400
The op lock and the compatibility mechanisms could be integral parts of other multi-component sophisticated and complex attacks.

39:42.480 --> 39:53.800
Op lock can be used in many scenarios as a building block and there are many more shim fixes that can be used with malicious intent, even with 64-bit processes.

39:55.020 --> 40:05.260
Our extensive research uncovered new techniques for stealthy injection and privilege escalation, enhancing the effectiveness of these attacks.

40:06.600 --> 40:11.780
We demonstrated two attacks that won't be monitored by EDRs.

40:11.780 --> 40:19.220
The injection occurs in a very early stage, a stage where EDRs can't establish a hook yet.

40:20.800 --> 40:31.400
Through reverse engineering an undocumented API and its associated structures, we gained valuable insights that contributed to the development of these methods.

40:32.760 --> 40:41.880
Additionally , we modernized a previously known malicious technique, transforming it into a more elusive fileless and registryless attack.

40:42.680 --> 40:52.180
Lastly, we once again encourage the community to continue building on our research, exploring the leads we have provided to further advance this field.

40:53.820 --> 40:55.000
Thank you.

40:55.580 --> 40:59.180
Thank you so much for being here and hearing our talk.

40:59.200 --> 41:01.940
The source code of our tools is now public.

41:01.940 --> 41:04.220
If you have any questions, you are free to ask.

41:04.220 --> 41:06.640
You can also find us on Twitter and LinkedIn.

41:06.680 --> 41:07.680
Thanks again.

