start	end	text
250	4490	Hello everyone. Thank you for coming to our talk,
4490	8930	Shimmy What You Got? Manipulating Shim and Office for Code Injection.
8930	12570	We are very excited to be here. Let's introduce ourselves.
13570	17810	My name is Ron Ben-Yitzhak. I'm a security researcher at Deep Instinct.
17810	21590	And this is the third year in a row I'm speaking here at DEF CON.
25500	30360	And my name is David Shandalov. I'm also a security researcher at Deep Instinct.
30360	31920	And this is my first time here.
37980	41120	This is what we're going to talk about today.
41120	45440	I'll start with an intro about the app compatibility framework,
45440	48580	what it is made of, and known techniques to abuse it.
48580	53640	Then I'll dive into our attack surface research on Microsoft Office.
53640	56340	I'll show how we found an interesting RPC method
56340	59980	and combined several manipulations into a single attack
59980	64140	that achieves both code injection and privilege escalation.
64520	67560	Then we'll show another novel attack.
67560	70440	We'll show the reverse engineering process of the driver
70440	75080	and the undocumented structures that make the app compatibility mechanism.
75080	79960	And how we discovered the finest technique to apply a malicious shim on a process.
79960	85100	At the conclusion of the talk, we'll discuss how to detect the attacks shown here
85100	88280	and how the community can continue our research.
89640	94260	The app compatibility framework is used for backwards compatibility.
94260	96900	Software developed for old versions of Windows
96900	100300	might behave unexpectedly on newer versions.
100300	102700	Microsoft offers many compatibility modes
102700	106100	that might look familiar from this window.
106220	111420	Programs might access registry paths or directories that no longer exist,
111420	114980	such as the C-documented settings, for those who remember.
115520	118460	Those issues are fixed with API hooking,
118460	120400	patching the assembly of the program itself,
120400	122680	and other runtime modifications.
123540	126900	Behind the scenes, this is how the mechanism works.
126900	130780	The OS uses shim database files, or SDB files,
130780	134360	that contain the fixes and modes various applications require.
134360	137040	The main file is sysmain.sdb.
137040	142120	It is maintained by Microsoft and can only be modified by system updates.
142180	146200	We can view those files using a graphic software provided by Microsoft,
146200	148320	the compatibility administrator.
148320	152020	Here we can see that Edge of Empires 3
152020	155400	requires the compatibility mode High DPI Aware.
155440	158140	Users can also install custom SDB files
158140	160900	by writing them to these registry paths.
162120	164460	Like every component of the OS,
164460	166660	people looked for ways to abuse it.
166660	168480	There were several talks over the years
168480	171680	about the malicious implications to the shim framework.
171680	174600	Here you can see a DEF CON talk from almost 10 years ago
174600	177960	that shows shims can be used for credential access,
177960	180240	network redirection, and more.
180340	186300	Also, Alex UNESCO released several articles about this subject back in 2007.
186500	189160	Because this is such an old attack vector,
189160	192400	most security products should detect malicious shim usage.
192400	196000	And the easiest way to do it is by monitoring the registry paths
196000	198960	used for installing custom SDB files.
199820	205340	So, once upon a time, David and I wanted to start a new research.
205340	207820	Initially, we thought about bypassing an EDR,
207820	209820	or even disabling it.
209820	213340	But apparently, some products just disable themselves.
214160	216120	So, instead of EDR bypass,
216120	218740	we decided to start an attack surface research.
218740	220360	And we needed a target.
220380	223700	One of the first choices we came up with is Office.
223780	225960	This software is very popular.
225960	228720	It can be found on almost every Windows machine.
228720	230600	It is also very complex.
230600	233160	It has COM objects, tripped-in engines,
233160	235140	cloud synchronization, and more.
235140	236900	The more components there are,
236900	239280	the higher the chances to find an issue.
239460	241340	And the most promising feature about Office
241340	243640	is the backwards compatibility.
243900	246540	It was released over 30 years ago.
246540	249420	And legacy code is usually the problematic one,
249420	251260	which is good for us.
251820	254520	Now, let's talk about the research itself.
255480	259460	We wanted to find RPC servers related to Office.
259460	262960	And that led us to the service ClickToRunSVC.
263220	267180	Here you can see the RPC interfaces it exposes.
267180	270320	And narrowing down this list to files related to Office
270320	272060	results in three files.
272060	275080	The actual executable of the service,
275080	277320	OfficeClickToRun.exe.
277320	279480	And let's skip the long prefix
279480	282280	and just call them virtualization.dll
282280	285380	and subsystemcontroller.dll.
286960	289200	We started looking into these files
289200	291600	to see what functionality they provide.
291600	295200	And we found an interesting string in the virtualization.dll.
295360	298660	Could not inject subsystem.dll to child process.
299240	302300	And lucky us, this string is used by a function
302300	304720	that is exposed through RPC.
304720	307320	This means that you can easily invoke it.
307340	309920	Still, before we start reverse engineering
309920	313120	the RPC interface and its methods,
313120	316920	we wanted to make sure it actually performs DLL injection.
317020	320120	So we debugged it, put breakpoints on the API
320120	323580	used for code injection, and then we launched Word.
323600	326920	That caused the service to call write process memory.
327100	330840	This diagram shows the call stack that led to this API.
330940	333940	The RPC call went through several undocumented functions
333940	337640	in a few DLL files until it reached write process memory.
339120	341360	So what is this DLL?
341360	344570	The file description is Microsoft Application Virtualization
344940	347570	Client Virtualization Manager Component.
348040	351040	And yes, it says virtualization twice.
351260	355360	This file exposes two undocumented RPC methods.
355360	357740	Instead of diving headfirst into the code,
357740	361740	we wanted to find symbols that can shed some light on these functions.
361960	364620	We used PowerShell to find RPC clients,
364620	367500	and that led us to a file that has symbols.
368100	370080	subsystem64.dll.
370080	372420	Again, I'm going to skip the long names.
372420	375340	The functions in the client are called notifyNewProcess
375340	377340	and notifyNewChildProcess.
377340	380380	We didn't find anything interesting about the first one.
380380	384460	The second function causes the server to call write process memory.
386500	390600	Now we want to understand the flow that leads to the DLL injection.
390600	392900	So we'll start by debugging the client.
393100	395820	We notice that before Word performs the call,
395820	400380	it spawns ai.exe as a child process in a suspended state.
400560	402740	Then we reach the call itself.
402740	405840	We reverse-engineered it and came with its definition.
406020	408340	This syntax is for the IDL file.
408340	412260	It sends two parameters, the process ID of ai.exe
412260	415620	and the string subsystem64.dll,
415620	418020	the name of the DLL that made the call.
418900	421840	Time to switch sides to the RPC server.
421840	425420	Like I said before, those DLL files are undocumented
425420	428820	and we want to save time on reverse-engineering them.
428820	430840	We searched for all the files that are related
430840	432700	to the app virtualization platform
432700	435400	and found out that there are files with similar names
435400	437720	in the system32 directory.
437760	439180	Those files have symbols
439660	442880	and they show that the detours library is being used.
442880	445960	This is an official library by Microsoft used for hooking
445960	449740	and it can also inject code into another process.
449740	452720	The functions detourUpdateProcess.dll
452720	454860	and detourCopyPayloadToProcess
454860	458340	are used to patch the import address table of the target process
458340	460380	and force it to load a DLL.
460620	462340	Comparing the two files with bindif
462340	464600	further proves the similarities.
464780	467460	The name primary column belongs to the office file
467460	471640	and the name secondary column belongs to the system32 file.
471640	474140	Those functions are a perfect match.
475200	478020	We can easily understand how the injection is done
478020	479980	with the source code of detours.
480000	482040	The optional header is modified to point
482040	483740	to a new copy of the import table
483740	486340	that includes an additional import descriptor
486340	487780	to the injected DLL.
487860	490740	This is how WinDebug displays the headers.
490740	494320	We can see the full path to the DLL, which is unusual.
494420	496520	Compilers link the base name.
497680	500700	This is everything done by the RPC server.
500700	502260	Now let's go back to the client
502260	504460	and finish going through this process.
504800	506380	Word resumes ai.txt
506380	509540	and since the process is not yet initialized,
509540	511760	the loader uses the new import table.
511760	515880	Because of that, subsystem64 is loaded into the process.
516300	519940	We looked at what happens if we imitate the RPC call
519940	523180	but specify a 32-bit process as the target.
523180	525100	In this case, office click-to-run
525100	528180	isn't writing to the memory of this process directly.
528200	530600	It launches the tool mavinject32,
530600	533260	which is known as a living off-the-land binary,
533260	535160	but the injection is exactly the same.
536900	539300	Now we want to understand exactly...
539300	542260	now that we know exactly how the DLL is injected,
542260	543700	what can we gain from it?
543900	547660	Security products detect all kinds of malicious behavior.
547720	551520	File encryption, shellcode execution, and code injection.
551600	554420	But sometimes legitimate programs do that.
554420	555980	We just saw an example.
556100	559660	And to avoid generating false positive events for customers,
559660	562700	such programs will be excluded by the products.
562880	565200	This means that if we force office click-to-run
565200	568620	to inject a DLL, we'll be able to bypass detection.
569120	571900	We know the definition of the RPC method,
571900	575620	and we can imitate it to inject subsystem64.dll.
575620	579880	But the big question is, can we inject another DLL?
580040	583240	As I showed before, the function receives a string,
583240	586120	so we can just change the name of the file.
586140	588100	But that means we'll have to write our DLL
588100	591100	to the office directory, which is very suspicious.
591220	593580	And it also requires admin privileges.
594860	599220	We tried providing a full path to the file instead of the base name,
599220	601020	and this is what happened.
601080	604340	We changed the string to ctemp-injected.dll,
604340	607900	and it was appended as it is to the office directory.
607940	611100	This should raise a flag for every security researcher.
611100	614480	It means that there are no sanity checks on the inputs.
614480	619060	So we can go back to the 90s and use directory traversal.
619060	622820	We can manipulate the file lookup to a completely different place.
622820	626420	Let's display the headers of the process again with win-debug,
626420	628960	this time after we manipulated the call.
628960	632300	We can see our malicious string was appended to the office directory
632300	634920	and written to the memory of the process.
635900	639600	With this trick, we can inject any DLL we want.
639660	641760	But there are still a few limitations.
642040	644360	The modified import address table will be used
644360	646660	only if the process was launched as suspended
646660	649460	and wasn't resumed until the injection was done.
649460	651460	It must be uninitialized.
651460	655000	Right now, we have a new technique to force a legitimate program
655000	656900	to inject a DLL for us.
656900	659520	But what more can we achieve from this?
659700	664820	A nice thing about RPC is that the client can have lower privileges than the server.
665000	668080	The office service runs this anti-authority system.
668240	671120	So, can we perform privilege escalation?
678850	681230	Well, the short answer is no.
681510	685870	The server calls RPC impersonate client before the injection is done.
685870	689710	This means that the thread that handles our request will use our token
690470	693310	and not the token of anti-authority system.
694010	696810	This is done to verify that the client has enough permissions
696810	698930	to access the remote process.
699050	703310	After the impersonation, the request reaches a subsystem controller.dll
703650	707230	which calls open process to gain a handle to the remote process.
707230	710530	If we can't get this handle, so will the RPC server
710530	712310	and the call will fail.
712310	715970	But still, maybe we can escalate from admin to system.
716810	720910	The first step to do that will be to launch a process
720910	724110	with the privileges of system in a suspended state.
724110	726810	We used API monitoring to find such calls
726810	730930	and we found that the task scheduler service does exactly that.
731170	734910	Scheduled tasks are a great target because there are many default ones
734910	736530	that are configured to run a system
737270	740070	and even some that are related to office.
740990	744510	Such as this one, office automatic updates 2.0.
744510	746610	Our injection will be even less suspicious
746610	751470	if the service will inject a DLL to another process that is related to office.
751470	753930	But we still have a few challenges ahead.
754010	758270	The task scheduler service resumes the process shortly after it is launched.
758270	762470	We need to find a way to hold the execution of the task scheduler service.
762470	765810	And we can do that with an opportunistic lock.
767950	770830	Opportunistic locks, or oplocks for short,
770830	774130	are a special kind of locks that are used to keep data coherency
774130	776850	across computers accessing a file server.
776910	778790	A client can lock a file.
778790	782910	And when another client tries to access the same file, it will wait.
783070	786690	The server will break the lock and notify the first client.
786770	789910	The new data will be flushed, the file will be closed,
789910	793650	and only then the second client will be able to access it.
793650	796650	The nice thing about oplocks is that they can be requested
796650	799530	from the local file system by a process.
799710	803710	This usage is effectively a semaphore managed by the local file system
803710	805950	that synchronizes multiple processes.
807190	809750	So, how does it relate to our attack?
809910	813910	If we could find a file that is accessed by the task scheduler service
813910	817490	after the process is created, but before it is resumed,
817490	821730	we could lock it, and it will stop the service from resuming the process.
821730	825910	Keeping the process suspended will allow us to inject a DLL to it.
825910	832690	We monitor the system for file access while launching the scheduled tasks,
832690	835730	and we saw that sysmain.sdb was accessed.
835730	838190	In this image, we can see the call stack.
838190	842830	Inside createProcessInternal, functions related to the app compatibility were called,
842830	845310	and then the shim database was opened.
846570	851350	At this point, we know that the task scheduler sometimes reads sysmain.sdb,
851350	854810	but we need to understand which tasks lead to that.
854810	859570	We need to find a task that executes a file with app compatibility settings.
859570	865270	To do that, we locked the sdb file, launched every task registered on the machine,
865270	868850	and checked when we were notified about the lock breaking.
868950	873210	This led us to a task that executes Microsoft Edge updates.
873210	877570	This file has app compatibility settings because of the following entry.
877570	883050	The generic installer fix will be applied on every process that has the word update in it.
883170	886510	So, this is good, but still, it's not good enough.
886510	891930	This file is under Program Files x86, which means it is a 32-bit process.
891930	894870	We want to find a target for 64-bit as well.
895970	902530	We continue digging into this subject to understand under which circumstances the sdb file will be read,
902530	906370	and we noticed a strange behavior that applies to the OS as a whole,
906370	908530	not just the task scheduler service.
908990	913590	The sdb file was read the first time an executable ran since the machine started,
913590	915690	even if it didn't need a fix.
915690	918850	And after that, in all other runs, it wasn't.
919730	925090	If we could guarantee that the sdb file will be read any time an executable runs,
925090	928030	we could choose any scheduled task as our targets.
928350	934370	And, of course, we could register a custom sdb file that applies some fix to every process,
934370	936030	but that is too noisy.
936030	939650	We want to avoid actions that are monitored by security products.
939930	943570	We need to find a way to manage the app compatibility mechanism.
943830	948450	We looked for files related to this mechanism and found apphelp.dll.
948510	952650	By looking at the code of this DLL, we understood that it wraps various operations
952650	956710	with the API AntiAppHelpCacheControl.
956730	958950	Let's try to understand how to use it.
960070	964210	This is an undocumented API that is exported by NTDLL.
964570	968950	We searched for references to this API online and in several DLL files
968950	974130	until we found that the symbols of combase.dll contain information about it.
974130	979330	This is a screenshot of a function from combase without any reverse engineering.
979390	981850	We can see that the first parameter is an integer
981850	984710	that represents the type of operation to be performed,
984710	986730	and the second parameter is a structure
986730	990690	with various members that are filled based on the operation chosen.
992490	996470	We extracted those definitions and that revealed to us
996470	998990	everything that can be done with this API.
999050	1002670	We applied the definitions on calls from other DLL files
1002670	1004970	and that helped us understand them better.
1005050	1007310	Let's look at createProcess, for example.
1007550	1010150	Now we know that it performs the lookup operation
1010150	1012970	and what information it requires.
1013150	1016490	Like I said before, we encountered a strange behavior.
1016490	1019850	The sdb file was read the first time in an executable run
1019850	1023070	since the machine started, even if it didn't need a fix.
1023070	1024770	And then, it wasn't.
1024770	1026750	At this point, we had enough information
1026750	1030130	to come up with an assumption on why it happens.
1031370	1034790	In this scenario, cmd is going to launch calc.
1034790	1038530	So we have these two processes and also the upheld cache,
1038530	1040330	which is empty at this point.
1040410	1042630	We know that when we call createProcess,
1042630	1045090	the lookup operation is done on the cache.
1045090	1048550	So cmd is going to look for an entry about calc.
1048550	1052430	The cache is empty, so the response is no entry found.
1052430	1055150	That causes cmd to read the sdb file
1055150	1059410	to check if it contained information about fixes calc requires.
1059410	1061750	It doesn't require any fix.
1061770	1063990	So the next step is that the cache is updated
1063990	1066010	and an entry is added.
1066090	1068110	Calc, no fix needed.
1068450	1072070	Then, let's say cmd launches calc again,
1072070	1075170	so it queries that cache one more time.
1075430	1078990	This time, the response is no fix needed.
1078990	1082910	And that is why cmd doesn't read sysmin.sdb again.
1083070	1084750	Based on this assumption,
1084750	1087090	if we could remove this entry from the cache,
1087090	1089450	the sdb file will be read again.
1090850	1093830	We looked at various calls to anti-app-help-cache-controller
1093830	1097150	and found out that both kernel32 and app-help
1097150	1099410	perform the remove operation.
1099410	1102650	In this pseudocode, we can see the information required.
1102650	1105390	It requires the path and the handle to the file.
1105790	1109290	Kernel32 exports a function that does most of the work for us,
1109290	1112910	and it saves us the effort of recreating this call in our code.
1113390	1115790	After this call, the execution of the file
1115790	1119070	will once again trigger reading the sdb file.
1120330	1123450	Okay, so we talked about a lot of stuff.
1123450	1126770	RPC methods, locks, and undocumented API.
1126770	1130010	So in case you lost track, let's put everything together.
1130110	1131770	This is the flow of the attack.
1131870	1134890	We'll start by writing the DLL that will be injected.
1135170	1137050	Then we'll pick a scheduled task.
1137050	1139890	Let's say, Office Automatic Updates 2.0.
1139950	1142330	We need to take care of the shim cache.
1142330	1145250	The file that will be executed might have an entry,
1145250	1147350	so we're going to remove it.
1147910	1150490	Then we'll lock sysmin.sdb.
1152010	1154810	The next step will be to start the task,
1154810	1156790	and that will launch a suspended process
1156790	1158750	with the privileges of system.
1159070	1162450	The task scheduler will try to read the sdb file
1162450	1164110	and start waiting.
1164330	1167570	That will send us a notification about the lock breaking,
1167570	1169990	which means it's time to send the RPC request
1169990	1171710	to the office service.
1172250	1174370	This service will patch the import table
1174370	1178050	of the suspended process and link it to our DLL.
1178210	1180950	The last step will be to release the lock,
1180950	1183850	and that will cause the task scheduler to resume the process
1183850	1186050	and our DLL will be loaded.
1187810	1189710	Ready to see if it works?
1194870	1197570	First, we'll copy our tool to the machine.
1197990	1199690	And let's even scan it.
1201030	1203750	And of course, Defender won't detect it.
1204410	1206210	Now, just to make it clear,
1206210	1209810	we are running the latest version of Office 365,
1211850	1214870	and also the latest Windows 11 build.
1216170	1218330	Now that we made it clear,
1218330	1221810	let's start monitoring the system and launch our tool.
1223920	1228480	We can see that Office C to our client loaded our DLL,
1228480	1231620	and that we gained the console with the privileges of...
1231620	1233640	anti-authority system.
1239630	1241110	Time to summarize.
1241170	1243570	We decided to make an attack surface research
1243570	1245070	on Microsoft Office.
1245070	1247690	We manipulated several components of the OS
1247690	1250050	into a single functioning attack.
1250050	1253030	And these are the advantages of it.
1253150	1256190	Security products will most likely ignore code injection
1256190	1257870	done by Office click-to-run,
1257870	1259930	because this is its purpose.
1259970	1261990	So we'll bypass detection.
1261990	1265930	It will be difficult to link this attack back to us,
1265930	1269170	because not only the injection is done by another process,
1269170	1272230	but the target process is spawned under the task scheduler,
1272230	1273830	not under us.
1274130	1277550	We escalate our privileges from admin to system,
1277550	1280990	and the rest of the actions we perform aren't suspicious.
1281190	1283730	It is very unlikely that someone monitors calls
1283730	1285910	to anti-app-help-cache-control,
1285910	1288190	or monitors using Oprox.
1288830	1291370	So this is the end of my part of the talk.
1291370	1293590	Now please welcome David Chandalov.
1300620	1302100	Thank you, Ron.
1302220	1305400	As we concluded our first attack surface research,
1305400	1307740	we identified a significant knowledge gap
1307740	1310840	regarding anti-app-help-cache-control.
1310840	1314460	Despite extensive information available online,
1314460	1317560	we found that crucial details about some data structures
1317560	1320080	and flows remain unclear.
1320500	1323700	Additionally, with the continuous updates and changes
1323700	1326620	in Windows versions over the years,
1326620	1330800	many publicly shared insights have been altered by Microsoft.
1330840	1333980	Today, I'll provide a comprehensive overview
1333980	1336960	of the mechanism and the modernized attack.
1336960	1338940	So, let's dive right in.
1339780	1342860	As we embarked on our research journey,
1342860	1345380	we were driven by a fundamental question.
1345460	1349320	What can we achieve with the anti-app-help-cache-control API?
1349460	1352020	This inquiry became our guiding light,
1352020	1356040	sparking our curiosity and determination to delve deeper.
1356240	1358940	Our initial exploration gave us a foothold,
1358940	1360840	but we knew we needed more.
1360840	1364260	We needed to understand the technical intricacies.
1364580	1367740	After all, this API controls shim fixes.
1367740	1369720	Maybe we can bend it to our will
1369720	1374020	and control which shim fixes are applied to specific processes.
1375400	1378040	Our second question was more technical.
1378340	1380340	As you can see from the screenshots,
1380340	1383240	during the reading of sysmain.sdb,
1383240	1385920	we noticed that anti-app-help-cache-control
1385920	1387980	interacts with the kernel.
1388180	1392200	This API calls a driver named ahcache.sys,
1392200	1395880	which contains some intriguingly named functions.
1395880	1398640	Functions like api-lookup and write-to-process
1398640	1401140	and cache-lookup stood out,
1401140	1404180	suggesting deeper mechanisms at play.
1404240	1407260	These findings hinted at something significant
1407260	1409320	inside of ahcache.sys,
1409320	1412260	something that required us to dig deeper.
1412640	1415300	So, down the rabbit hole we go.
1416480	1419200	All right, let's lay the foundation.
1419200	1422080	To understand how ahcache.sys operates,
1422080	1426480	we need to start with the basics of its initialization process.
1426480	1430140	When the system boots up, ahcache.sys is loaded,
1430140	1433980	and it requires some initial setup to function properly.
1434080	1437260	This is where the registry comes into play.
1437820	1440360	The registry provides essential values
1440360	1443920	that ahcache.sys reads and stores data to.
1444140	1446440	These values act as a safe location
1446440	1448640	for the driver's operations.
1449660	1452160	This path contains binary data
1452160	1455500	that the driver sorts into an AVL table.
1455620	1458040	The cache needs to be properly initialized
1458040	1459280	through the Windows API
1459280	1463060	before these components can start working.
1464140	1468040	The opposite process happens a shutdown and restart.
1468120	1470680	The AVL table is dumped into the registry,
1470680	1473200	into the app.compat.cache value.
1474820	1476840	Let's take a moment to understand
1476840	1481400	the link between sysmain.sdb, registry entries,
1481400	1483620	and the app.compatibility cache.
1483760	1486140	Each entry in the registry's values data
1486140	1489540	is representing either a file that needs a shim fix
1489540	1491580	or a file that doesn't.
1491640	1494920	We'll revisit the decision-making process for applying fixes,
1494920	1497400	but for now, let's focus on entries
1497400	1499780	indicating files that need a fix.
1499920	1503240	These entries contain several fields,
1503240	1505960	the most significant being the exit tag,
1505960	1508170	which points to a specific shim fix.
1508620	1511180	By examining the data within these entries,
1511180	1513880	we can observe notable differences.
1514140	1517440	Specifically, free bytes vary across entries,
1517440	1520860	and in the last entry, the free bytes are zeroized.
1521040	1524020	Is it a sign for a file not needing a fix?
1524380	1527200	Considering the data's little-endian format,
1527200	1531260	converting it could reveal connections to sysmain.sdb.
1533120	1536400	With sdbexplorer, we can search for these converted values
1536400	1539480	in a readable version of sysmain.sdb.
1539640	1542480	Zooming in on the fields that appear in the sdb,
1542480	1544700	we have the name of the file field,
1544700	1547020	and we can see the matching file field.
1547260	1550360	The matching file field contains just an asterisk,
1550360	1554040	so the whole name field will be compared as it appears.
1554520	1557540	And lastly, we find the shim reference field.
1557540	1560440	Each shim reference has a name and an ID.
1560440	1564100	Some have a command line for additional arguments.
1564300	1567440	Each field has an hexadecimal number attached.
1567440	1568420	Why?
1569720	1574440	It represents the address in the sdb that contains the exit tag
1574440	1578260	as it prefixes the shimfix information block.
1579500	1582500	Now that we understand what an exit tag is
1582500	1586260	and how the registry cache and sysmain.sdb are linked,
1586260	1589980	we wanted to look under the hood of Ahcache.sys.
1590000	1594660	We started looking at the dispatch routines for device Ahcache,
1594660	1597320	and we found that, among other things,
1597320	1599140	anti-app-help-cache-control can
1599920	1602880	update the table with hc-api-update
1602880	1606440	that utilizes insert-element-api,
1606440	1610020	lookup a table entry with hc-api-lookup-cdb
1610020	1612540	that uses lookup-element-api,
1613620	1617980	or it can remove an entry from the table with hc-api-remove
1617980	1620380	using delete-element-api.
1620780	1624760	We decided to continue looking through the dispatch routines.
1626160	1628640	As we already have shown,
1628640	1632860	anti-app-help-cache-control uses the Ahc service class enum,
1632860	1636040	but it is also being used in the dispatch routine
1636040	1638520	inside of Ahcache.sys.
1638520	1642460	The enum has an interestingly sounding member,
1642460	1644240	in its process data for short.
1644240	1647280	We traced a function that is using this value.
1647940	1652380	We were surprised to see no mentions of AVL table manipulation.
1653620	1656040	Maybe this is what we were looking for?
1656040	1658200	Writing to a process through a kernel driver?
1658200	1659520	Sounds awesome!
1660460	1663180	But before we check if we got the good news,
1663180	1665160	let's go through some definitions.
1665160	1668340	Almost every dispatch routine has a unique structure
1668340	1669860	for its operation.
1671080	1674840	This structure contains an undocumented data field.
1674840	1677340	We tried to search the web for definitions,
1677340	1680360	and with some more in-house reverse engineering,
1681720	1683520	we got shim-data.
1683520	1687760	It contains a fixed magic value and a fixed size value.
1687760	1690940	Remember this struct, as we will come to visit it later.
1692320	1695260	Diving deeper inside the function,
1695260	1699080	the calling process and the target process are being checked.
1700000	1701820	Now here is the tricky part.
1701820	1705640	We need to have a protected signer app and PPL.
1706260	1709280	And these two values will be important later.
1710180	1714120	But the call fails in PSGetProcessProtection.
1714120	1717700	Looking at every process in Windows 11,
1717700	1719880	we concluded that no Windows apps
1719880	1722780	with this kind of protection exist.
1723180	1725140	We came to a dead end.
1725520	1728880	But the undocumented structure I talked about before,
1728880	1730720	it piqued our interest.
1731980	1734660	We decided to take that strange name we found
1734660	1738000	and try to look for references of this structure.
1738540	1741440	Maybe we can understand by which operation it is being used
1741440	1743480	and who can be the target.
1744840	1746760	There were a few hits.
1746760	1750200	Reverse engineering the functions that reference shim data
1750200	1752880	revealed that this structure represents
1753320	1756640	the shim fixes that need to be applied to a process.
1757960	1760780	Let's see how a new process is born.
1761860	1764180	Notepad.exe is the child process
1764180	1766940	that is created on behalf of the parent process
1766940	1768720	cmd.exe.
1768740	1771420	The parent queries the app help cache to check
1771420	1774620	if the child process requires shim fixes,
1774620	1777160	as we have shown in the first attack.
1777920	1780560	The parent process reads this main.sdb
1780560	1784000	to retrieve the complete information about the fixes.
1785400	1788180	The parent builds the structure according to
1788180	1791980	the specific fixes and writes it to the memory
1791980	1793660	of the child process.
1795740	1797580	The parent modifies the value
1797580	1800380	of the process environment blocks pshim data
1800380	1803020	to point to the new structure.
1805220	1808920	NTDLL is already loaded in the child process.
1810020	1811620	So NTDLL's loader
1811620	1813180	loads apphelp.dll
1813180	1816920	if pshim data is not empty.
1817920	1819740	Apphelp identifies which
1819740	1822060	shim fixes are to be applied.
1823000	1826060	And so apphelp.dll applies the shim fixes
1826060	1828000	according to the structure.
1829520	1832040	We also wanted to share the flow
1832040	1834140	of the shim data structure creation
1834140	1836560	for future references.
1836940	1839340	The flow starts with create process internal
1839340	1842700	in kernel base, goes through kernel 32
1842700	1847060	and finally ends with apphelp.dll.
1847120	1849580	The finished struct is built in the
1849580	1852340	sdb pack up compa data function
1852340	1856280	inside of apphelp.dll.
1856740	1858460	Okay.
1858460	1860880	Let's consider the implications
1860880	1863260	of manipulating a system component
1863260	1866960	to build and trigger unauthorized fixes.
1866960	1869500	This could potentially allow us to inject
1869500	1872180	or alter code in a way that bypasses
1872180	1874560	typical security measures.
1875460	1877960	Our investigation into pshim data
1877960	1880820	begins with understanding what data
1880820	1883000	is being written to this specific part
1883000	1885860	of the process environment block.
1887120	1890280	We utilized the compatibility administrator
1890280	1893380	to create and apply custom rules.
1896200	1898440	By extracting the shim data
1898440	1900440	directly from process memory,
1900440	1901800	we gained a first insight
1901800	1904320	into how the data is organized.
1905440	1907340	We chose to fuzz the inputs
1907340	1909680	to see the effect on the data.
1909680	1912240	This process helped us identify patterns
1912240	1914680	in the data handling.
1915080	1916540	By following these steps,
1916540	1918400	we gained a comprehensive understanding
1918400	1921060	of how shim data looks like.
1922220	1925840	And so, at last, we have reversed engineered
1925840	1927700	the shim data structure,
1927700	1929040	essential for understanding
1929040	1932180	how to manipulate shims to our advantage.
1932960	1935060	Here we can see the previous version
1935060	1937820	of the shim data, if you can recall.
1937820	1940380	This is the struct I ask you to remember.
1940400	1942260	There are quite a few changes,
1942260	1945180	most notably the exit tab type field,
1945180	1948160	the exit tag field, and the exit count field.
1948160	1950480	All are essential for correct use
1950480	1952640	of shim fix manipulation.
1954400	1957100	At this stage, we are preparing to use
1957100	1959780	all of our accumulated knowledge for an attack.
1959840	1962300	We can make a target process load a shim fix
1962300	1965020	simply by building our own shim data struct
1965020	1968240	and pointing to the target pshim data to it.
1968260	1970520	The process won't check any condition
1970520	1972720	the original rule has configured.
1972820	1976100	This allows us to apply any fix we want.
1976280	1977920	We chose to inject a DLL
1980400	1984260	into the target process by itself.
1992530	1995470	This effectively makes the attack
1995830	1998290	a file-less and register-less DLL injection
1998290	2000630	that can evade detection.
2001910	2003590	According to this entry,
2003590	2006190	rtvideo.dll will be injected
2006190	2009530	if the process name starts with glj,
2009530	2011530	ends with the temp extension,
2011530	2013730	and it has the correct checksum.
2013730	2015890	Luckily, these checks are done
2015890	2019180	by the parent process and not by the child process.
2019550	2021730	This means that once the exit tag
2021730	2024110	in shim data points to this entry,
2024110	2027390	the child process's app.ldll will apply the fix
2027390	2029910	without checking the conditions.
2030990	2032790	Having said all that,
2032790	2034850	our attack has three limitations.
2035070	2039090	The target process must be started as a suspended process.
2039830	2042770	If the injected process executable file
2042770	2045210	resides in this specific path,
2045210	2048190	or the security identifier of the file's owner
2048470	2050290	is a trusted installer,
2050290	2052690	the shim fix won't be loaded.
2053870	2057210	Injected DLL is not available to 64-bit processes
2057550	2060230	as acgeneral.dll revealed.
2060610	2063790	And you won't believe it, we found the target.
2063790	2067250	And it's the Microsoft Edge updater we have shown before.
2068090	2070290	Microsoft has made our lives easier
2070290	2072990	as all three limitations are not present.
2072990	2074410	Let's inject.
2075310	2078210	At this point, we have enough knowledge
2078210	2080690	to abuse the app compatibility mechanism.
2080690	2083370	So let's go over all of the steps.
2083910	2086070	We need to write our own DLL
2086070	2088750	as the name of the rule specifies.
2089970	2093550	We launch our binary as a suspended process.
2094410	2097590	The struct is built with the correct tag
2097590	2099190	as in our example.
2100650	2104050	We write the struct to the target process's memory.
2104270	2107310	We point to the struct.
2107930	2109890	We resume the execution.
2110690	2112430	And so app help will help us
2112430	2114790	and apply our desired fix.
2114790	2117670	An RT video will load to the target process.
2117870	2120170	Let's see how it looks in action.
2123970	2127270	shim injector.exe is dropped.
2128730	2131470	And so we can see the hello message
2131470	2134130	from inside of the child process.
2134510	2137470	RT video.dll is loaded by our target.
2137630	2140590	We can see our call stack going from install after init
2140590	2142970	to ns inject dll.
2142970	2145430	And lastly, to load library.
2145570	2148310	We also have some logs on the command prompt.
2148310	2151650	You can see the unique size, magic, exit type
2151650	2154330	and exit tag we defined earlier.
2161420	2163720	Let's recap our second attack.
2163720	2165780	There is a long history of shim attacks
2165780	2169460	and how security products typically detect and mitigate
2169460	2172640	malicious shim attacks, attack vectors.
2173360	2176220	We were able to uncover new definitions
2176220	2179260	and insights on the app compatibility component.
2179260	2182020	And we used them to change what we think about
2182020	2183800	this attack vector.
2184760	2187500	This new perspective allowed us to create a new
2187500	2190200	file-less and registry-less attack.
2190940	2193280	We essentially took care of the problem
2193280	2195640	of creating a custom SDB on a system
2195640	2199320	with all that comes with it, namely registry
2199320	2201060	and disk tracks.
2202680	2206000	By writing to a child process which is not suspicious
2206000	2209040	and by loading the target dll from the suspended
2209040	2213640	child process before any EDR hook can be established,
2213640	2216660	we effectively bypassed EDR detection.
2218680	2221700	We chose this specific shim fix because
2221700	2225240	it is applicable to many scenarios and demonstrates
2225240	2227220	our attack in a clear way.
2227480	2230380	There are many more shim fixes that can be used
2230380	2233780	for malicious purposes. This was only one of them.
2234940	2236480	We've come a long way.
2236480	2239020	Let's summarize both attacks and see what we can
2239020	2241120	take away from this research.
2242520	2245640	As for detections, let's go over how should
2245640	2248120	someone detect these kinds of attacks.
2248560	2252440	For the first attack, RPC is a big and early
2252440	2255080	part of the first attack. So monitoring
2255080	2258580	remote procedure calls made to click-to-run
2258580	2261300	service can reveal the use of non-standard
2261300	2264800	dll paths. Requests for opportunistic
2264800	2267800	locks on critical system files like
2267800	2270760	sysmain.sdb should be flagged.
2272120	2274480	Implementing security policies that
2274480	2277700	restrict such high-level memory write operations
2277700	2280780	as it is very suspicious. Click-to-run
2280780	2283660	service shouldn't write to this type of processes
2283660	2285180	on its own.
2286580	2289880	Regarding the second attack, keeping
2289880	2292560	an eye on file system activity, particularly
2292560	2295940	for the creation of dll files which are listed
2295940	2298500	in sysmain.sdb and
2298500	2301300	are in directories unrelated to the original
2301300	2304100	files, to the original rules.
2305760	2307860	Also, we invite the community
2307860	2310380	to take our findings to refine our attacks
2310380	2313300	and make new and better ones.
2313680	2316660	Some ideas. The community could find
2316660	2318720	the target for the init process data
2319300	2322360	operation that we didn't find.
2323020	2325160	There is much more to understand
2325160	2328360	about the shim data structure and how it can
2328360	2332120	affect the execution of the AHCache.sys functions.
2333260	2334580	There are many more
2334580	2337480	flows that can potentially manipulate the AVL table
2337480	2340300	which in turn will affect which process
2340300	2342300	will get what shim fix.
2345360	2348520	In conclusion,
2348520	2351820	in our presentation, we detailed our comprehensive
2351820	2355280	methodology for conducting attack surface research.
2356500	2358040	By leveraging and
2358040	2360840	manipulating various system components, including
2360840	2363780	services, op locks and compatibility
2363780	2366820	mechanisms, we demonstrated how to consolidate
2366820	2370000	these elements into a singular cohesive attack
2370000	2371420	strategy.
2372100	2375840	The op lock and the compatibility mechanisms could
2375840	2379140	be integral parts of other multi-component
2379140	2382400	sophisticated and complex attacks.
2382480	2384800	Op lock can be used in many scenarios
2384800	2387420	as a building block and there are many more
2387420	2390420	shim fixes that can be used with malicious intent,
2390420	2393800	even with 64-bit processes.
2395020	2397620	Our extensive research uncovered new
2397620	2400020	techniques for stealthy injection and
2400020	2402900	privilege escalation, enhancing the
2402900	2405260	effectiveness of these attacks.
2406600	2409640	We demonstrated two attacks that won't
2409640	2411780	be monitored by EDRs.
2411780	2414820	The injection occurs in a very early stage,
2415080	2418140	a stage where EDRs can't establish a
2418140	2421360	hook yet.
2421360	2423700	Through reverse engineering an undocumented
2423700	2427140	API and its associated structures, we gained
2427140	2429640	valuable insights that contributed to the
2429640	2433160	development of these methods.
2433320	2435600	Additionally, we modernized a previously
2435600	2438440	known malicious technique, transforming it into
2438560	2441880	a more elusive fileless and registryless attack.
2442680	2445080	Lastly, we once again encourage the
2445080	2447140	community to continue building on our
2447140	2449320	research, exploring the leads we have
2449320	2452180	provided to further advance this field.
2453820	2457020	Thank you. Thank you so much for being
2457020	2459840	here and hearing our talk. The source
2459840	2462340	code of our tools is now public. If you
2462340	2464220	have any questions, you are free to ask.
2464220	2466640	You can also find us on Twitter and LinkedIn.
2466680	2467680	Thanks again.
