start	end	text
2310	6610	Okay, thank you all for coming to my presentation.
10370	13870	For those who I haven't met before, my name is Andrew Case.
13870	17390	I am a core developer on the Volatility Memory Analysis Project
17390	21010	and also the Director of Research at Vellect City.
22530	28430	At Vellect City, we do a significant amount of incident response and malware analysis.
28670	32390	And as part of our research workflow and being on the research team there,
32390	36930	we make sure that for all the malware techniques that we see during our attacks
36930	41110	and that we see other vendors reporting about, any type of malware technique,
41110	43930	any attacker toolkit that's really being used in the wild,
43930	47090	we want to make sure that we have a complete understanding of it
47090	50990	and also that we can automatically detect it during our investigations.
51890	55010	To ensure that we meet that goal and meet that reality,
55010	59310	we very often perform very targeted, very specific deep dives
59310	63870	on specific techniques that we see the malware using, that we see attackers using.
63990	67230	And then we make sure that we document all the different techniques,
67230	70810	all the different tools that use it, whether they're private tools from threat groups,
70810	74310	whether it's some open source tool that has implemented it.
74310	77110	And then we make infected machines with it.
77110	80970	So we make our infected virtual machines. We make sure all the techniques are active.
81010	84490	We do the deepest memory forensics research we know how to do,
84490	88310	which we have most of the volatility developers at Vellect City, so that's pretty deep.
88310	91130	And then we do talks like this where we publish it.
91270	96110	For one of the latest research projects that we did, that's what I'm going to be talking to you about today,
96110	101230	we looked at all the ways that EDRs were being evaded by real malware.
101230	106150	Because what we noticed in our investigations is that we're working in enterprises,
106150	111090	they're trying to do security correctly, they have EDRs, they have them configured,
111090	115010	they're listed as active on these machines, but over and over again,
115010	118690	as we were doing memory forensics, we were finding very potent malware
118690	122090	in the same processes where the EDRs supposedly were.
122090	125430	So obviously we wanted to figure out why that disconnect was happening,
125430	131330	and through our memory forensics work, we wanted to be able to detect it automatically as well.
131330	134050	Because as you'll see as we go through the slides,
134050	138110	normally when malware bypasses EDRs, it's not every process.
138110	142890	It's just the process or the two processes where the malware is running out of directly
142890	148590	or where it's injected code into, so if you detect the EDR evasion,
148590	150810	then you also directly detect the malware.
150810	153750	And so this has allowed us to do very scalable work.
154250	157250	And at Vilexity, where we're dealing in many investigations
157250	160530	with dozens, hundreds, thousands of memory samples,
160530	164070	we don't have time, and it would obviously not be very time efficient,
164410	166850	to manually look at anything to start.
166850	169630	So we want a set of techniques that will at least say,
169630	173610	hey, out of these hundred memory samples, these are the five you really need to focus on.
173610	175250	And that's where we target our research.
175250	176910	We don't want a lot of false positives.
176970	179150	We don't want algorithms that take forever to run.
179150	182650	We just want to find the malware so that we can deep dive it.
182710	184790	And then, as you can probably guess by the title
184790	187810	and the fact that all this research was done with volatility,
187810	190370	we're going to be looking for that malware in memory.
191530	193670	If you haven't seen memory forensics before,
193670	196170	or maybe you've never looked at a memory sample yourself,
196170	200070	the reason why there's this whole industry now around memory forensics
200070	203370	and why it's so vital to incorporate it in your investigations
203370	207090	is that when you look at the real attacks in the wild,
207090	210290	when you look at the malware that's going to be used in environments
210290	212110	where the attackers don't want to get caught,
212110	214890	where the EDRs are, where there's actually security teams,
214890	217270	that malware is going to be memory only.
217270	219550	It's not going to touch the file system.
219570	222770	Anything that traverses the network is going to be encrypted.
222850	224830	So if you don't get a memory sample,
224830	226890	then you just threw all the evidence away.
226890	229690	If you walk up to that compromised machine and you turn it off,
229690	233250	as soon as that machine shuts down, the evidence is gone forever.
233650	236470	And what I have highlighted here on the slide
236470	239130	is just an interesting report from Microsoft.
239130	240910	There's hundreds of reports like this
243410	245470	that companies have published.
245610	247530	But I like this one because in two sentences
247530	250730	it really summarizes why we spend so much time doing memory.
250890	253170	This was Microsoft. It was really interesting.
253170	256410	It was basically a spyware company out of Australia
256410	259650	that was being used to target some high-level people.
259790	262970	And Microsoft burned the whole company to the ground in one report.
262970	266410	They burned every piece of malware that company had, all the capabilities.
266810	269750	And as I have highlighted in red here with the screenshot,
269750	272170	over and over again, Microsoft made the point to say
272170	277030	that where the evasion is, where the real payloads are, are in memory.
277030	279530	And if you look at what these payloads are capable of,
279530	282710	it's key logging, it's screenshots, it's recording the microphone,
282710	285410	it's recording the webcam, exfiltrating files,
285410	290090	everything that allowed this spyware to operate against politicians,
290090	292610	journalists, all these people, it was memory only.
292610	295430	So traditional disk forensics isn't going to get you anywhere.
295530	298130	And you need to know how to efficiently do memory forensics
298130	302390	to even make sense of the data and detect the malware in the first place.
303290	305370	So as part of our research project,
305370	309550	when we first broke down how EDRs are monitoring system activity,
309550	312150	the first three have been around a while.
312150	316290	Kernel callbacks is where EDRs or antivirus inside the kernel,
316290	319010	so from their driver, they can register to say
319010	322910	that that callback will be notified every time a process starts
322910	325770	or a thread starts or a DLL gets loaded.
326030	330870	EDRs will also monitor activity through two of the newer interfaces,
330870	336010	so ETW and AMSI. ETW is where kernel drivers can receive
336230	339650	a wide range of system activity from processes,
339650	341370	also other parts of the kernel.
341530	344870	And then AMSI, if you go to other DEF CON talks, Black Hat talks,
344870	347370	it gets mentioned a lot because at this point,
347370	351450	what AMSI does is it lets Defender, so Windows Defender,
351450	354610	as well as all the AVs and EDRs,
354610	357670	they get to register to say before a PowerShell script runs,
357670	360390	before a macro runs, before all these scripting languages
360390	364950	where traditional reversing doesn't work and there's a lot of obfuscation,
364950	368850	those antivirus engines and the EDR engines get to scan the scripts.
368850	372590	If they say they are malicious, then the scripts get blocked.
372910	377250	And then what we'll really be focusing on with this talk is the last one,
377250	379230	which is system call monitoring.
379290	383230	And we'll have some pictures for that to make sure everyone is on the same page.
383830	386290	And so when we broke down the bypasses,
386290	389890	even, not even just like your really sophisticated threat groups,
389890	393650	every ransomware family at this point, the half-decent ones,
393650	395930	the first thing they do is load a kernel driver
395930	398010	through Bring Your Own Vulnerable Driver,
398010	401830	and they disable all the EDR callbacks and the AV callbacks.
401830	405370	At that point, the ransomware can inject code, start new processes,
405370	407630	and those systems are blind.
407690	411990	For event tracing and AMSI, there are dozens and dozens of papers
411990	415090	on how to disable these, and it's essentially a modern part
415090	417130	of what you see in real investigations.
417330	421410	But what we noticed, and as we'll see here on the next slide,
421410	425110	is when we get to system call monitoring, we had no way to detect this.
425110	429690	So before this research effort, with memory forensics, with volatility,
429690	433050	you could very quickly determine that callbacks had been unregistered,
433050	436970	that ETW had been tampered with, that AMSI had been tampered with.
436970	439530	Again, these are going to point you right to the malware.
439630	442210	But the system call monitoring that EDRs use,
442210	446090	and it's one of the best ways they get visibility on the system,
446090	447610	there was no way to detect this.
447610	450970	And so in our investigations, we were having to do a lot of manual work
450970	454170	to find it, to unravel it, and that just doesn't work
454170	457450	for the scale that we operate at. We need automated ways.
460270	463670	And the reason that the system calls are so critical to EDRs
463670	467550	is the idea with system calls is this is your boundary
467550	469910	from process memory to the kernel.
469910	472910	So this diagram here, the Windows internals book,
472910	477950	you have your processes running, your web browser, your office application,
477950	481750	whatever it is that the process is running in user land or user mode,
481750	483130	it's all the same thing.
483130	486970	Besides manipulating their own memory, whenever they want to access
487250	490330	a resource on the system, so they want to read or write a file,
490330	492370	they want to read or write a network packet,
492370	494770	anything beyond manipulating their own memory,
494770	497030	they have to ask the operating system to do it.
497030	499630	Because obviously you don't want your random notepad process
499630	501670	writing directly to the hard drive.
501670	504790	Or you don't want notepad writing directly to the ring buffer
504790	506870	of your network driver.
506870	511310	So, for processes that want to talk to network devices
511310	516010	and request those operations, reading a file, writing a file,
516010	519390	interacting with the network, it has to go through a system call.
519390	522630	And that system call is going to change the execution context
522630	526210	into the kernel, which is obviously the most privileged part.
526210	528670	It has full access to the operating system itself,
528670	530650	to other drivers, to other hardware.
530990	533270	What you're seeing on the right side of this slide
533270	537510	is the arrow that breaks down between process memory and the kernel
537510	539770	where the system calls happen.
539770	542070	You're seeing a stack trace of that here.
542190	544330	When you look at a stack trace, you want to start at the bottom
544330	545790	to make sense of it.
545790	549250	So in the beginning, what these lines or these rows here with the U,
549250	552070	this is in user land, or again, process memory.
552110	555010	You can see that the Edge browser is running.
555110	558570	It eventually gets to this call, ZW create file.
558570	562490	Your system calls will, in almost all cases, start with ZW.
562490	566750	And then you can see this is sysinternals monitoring the call stack.
566750	569010	It eventually, when the system call is made,
569010	571030	it jumps into the kernel file.
571050	573070	And this K means we're in kernel memory.
573170	577730	So this last call, the ZW, whatever that particular system call is,
577730	580550	that is the last boundary before we jump in the kernel.
580550	583270	And the reason we're focusing on this background so much
583270	585550	is this is where your EDRs live.
585910	588910	Because if you look at this slide, what we're seeing,
588910	590470	I'll explain in more detail in a second,
590470	593650	but on the left is the normal system call handler.
593650	596230	So this is what you get with Windows by default.
596230	600730	In this case, the slide is showing ZW protect virtual memory,
600730	602930	so another system call on Windows.
602930	606410	On the left is the normal flow that's going to reach the kernel.
606450	609290	On the right is an EDR that has hooked it.
609290	613330	So EDRs that want to monitor what processes are doing on the machine
613330	616690	by injecting code into every process,
616690	618970	hooking the system call functions of interest,
618970	621910	it has complete control over what that process is doing
621910	623950	right before it makes the system call.
623950	626390	So if it wants to look for suspicious parameters,
626390	628850	if it wants to log out what files are being read,
628850	631210	what parts of the registry are being interacted with,
631210	635770	by hooking that lowest level function, the EDR has full visibility.
636130	638270	And so as we'll see here in a second,
638270	641310	what malware wants to do is make its system calls
641310	644650	without EDRs interfering or detecting it.
644710	646010	But some background real quick
646010	648250	while we're on a nice slide with a picture.
648250	650750	What we're seeing here, again on the left,
650750	654170	is the normal system call handler that jumped.
654170	655290	We're going to go back.
655370	659030	So what we see on the left is the normal system call handler.
659030	661090	And there's a few things to keep in mind.
661090	663930	First off, when you have the NT version of a function
663930	666470	and then the ZW prefix version,
666470	669170	it's the same exact function, but one's in user land,
669170	670270	one's in the kernel.
670270	671930	So we're seeing that here.
671930	676430	The second thing is, from regular C code or C++ code,
676430	677730	when you call a function,
677730	680390	the parameters are sent in certain registers.
680390	682790	We're going to focus on 64-bit machines.
683050	687570	And besides RCX and R10, they're exactly the same.
687570	690830	The weird thing is, with Windows, when you make a system call,
690830	694770	your second parameter needs to be an R10 instead of RCX.
694770	697410	So this has to get updated in those paths.
697410	701410	And then EAX or REX has to hold the system call number.
701410	703470	So for all the hundreds of system calls
703470	706050	that Windows has for a particular version,
706050	708210	each system call has its own number.
708210	709590	And if you look at these handlers,
709590	712770	they all look exactly like this, except this number changes,
712770	716610	because that is the index into the system call table at runtime.
717130	718370	And then we have a quick check
718370	721130	to see what system call path is supported.
721290	724130	And then to make that transition to kernel mode,
724130	726290	we're either going to use the system call instruction,
726290	728330	or if we're on an older processor,
728330	729590	older version of Windows,
729590	731810	we're going to make the int2e call.
731890	733830	So again, this is, on the left,
733830	736350	is what we would expect on a regular machine
736350	737870	where you don't have EDRs.
737870	739730	And then if you look on the right here,
739730	741090	instead of all this code,
741090	743150	eventually calling system call,
743150	745470	we just have a jump out to an unknown region,
745470	747470	which is going to be the EDR.
747530	749450	And then when malware calls something like
749450	751490	protect virtual memory here,
751490	753630	or create file on the previous slide,
753630	755550	the EDR has full control of that.
755550	756710	It's going to kill the ransomware
756710	758970	before it can launch any payloads.
758970	761610	It's going to kill all the code injection techniques.
761610	763250	And so if you have a decent EDR
763250	765290	and it's not being tampered with,
765290	767750	it's going to stop all these regular malware techniques
767750	768790	from functioning.
768850	770770	But like I said, we constantly do investigations
770770	773810	where there's very potent malware on the machine,
773810	775910	there's supposedly EDR on the machine,
775910	778490	but when we dig into the infected processes,
778490	780230	the EDR has been nullified.
787280	789340	So what we're going to do for the rest of the talk
789340	792120	is look at all of the bypasses that we found.
792120	793780	Like I said, in our own investigations,
793780	795040	there's a bunch of open source tools
795040	796040	that do it as well.
796040	797900	And then how we can detect them.
797900	800800	The first one goes by a couple different names.
800800	802860	Module unhooking, system call unhooking,
802860	804280	API unhooking.
804360	806200	The basic idea here is the malware
806200	809200	is going to unhook the system call handlers.
809280	810600	And the end goal is
810600	812200	when malware starts running
812200	814260	and they're in a process that EDRs
814260	816660	have all the system calls in this hooked form,
816660	818520	it wants to get it back to the original form
818520	821640	so that the EDR is blind to what's going on.
822600	823960	The way this works,
823960	826180	and this PowerPoint keeps jumping a lot,
826180	828180	the way this works, this is a screenshot
828180	829940	from a very recent report
830800	832380	from a very recent report
832380	833620	maybe two or three months ago
834120	836120	of malware that did this to then spread
836120	837840	across a huge network.
837880	840480	The basic idea is where system calls
840480	841880	are implemented in memory
841880	843560	is NTDLL.
843680	845880	So the first DLL that loads in every process
845880	848300	is NTDLL that has all of those
848300	851180	system call handlers, one per system call.
851340	852900	And that's what the EDRs hook.
852900	854220	They put the jump instruction,
854220	855880	it goes directly to the EDR code
855880	857980	and then like I said, the EDR can evaluate
857980	860700	the parameters before the system call is made.
860760	862120	So you can see it in the steps here,
862120	863860	this report was really nice.
863860	865800	What this malware did is it read
865800	868320	the clean copy of NTDLL from disk
868320	870180	so that copy on disk is what
870180	872260	Microsoft published that does not have
872260	873860	any EDR hooks present.
873860	876000	So it reads NTDLL from disk,
876000	878060	it finds where those system call handlers
878060	880000	are in their clean state on disk
880000	882220	and it just overwrites all the EDRs
882220	884260	hooks. And now the malware can call
884260	886380	any system call at once with whatever malicious
886380	888320	parameters it wants, any malicious
888320	890380	end goal that it has, and even
890380	892320	though the EDR is technically loaded in that
892320	894220	process, its code is never going to be
894220	896440	activated. And so when we look at ransomware
896440	898200	and we're like, how can it inject code?
898200	900460	How's it encrypting all the files? How's it elevating
900460	902240	privileges? It's because the EDR
902240	904360	has no idea what's going on, and this
904360	906400	is one of the many ways that we'll talk
906400	908280	about how it happens. So again,
908280	910220	you go from the state where every
910220	912240	process on the machine has their
912240	914480	system calls hooked, the malicious
914480	916260	code, the malware is going to run in its
916260	918120	own process, or it's going to inject code
918120	920180	into a victim process, and in that
920180	922720	victim process, or the malware's own process,
922720	924280	the system call handlers will
924280	926200	be reverted back to where
926200	928120	they were on disk, but all the other
928120	930300	processes will have the hooked form.
930360	932200	So what we realized is instead of trying
932200	934000	to figure out the 50 different
934000	936260	variations for module unhooking,
936260	938240	we could just use data in memory to
938240	939140	tell us where
940460	942280	the malware is. So
942280	944240	what our new volatility plugin does
944240	946180	is it enumerates every
946180	948360	process, it reads the bytes
948360	950380	of all the system call handlers that
950380	952440	the malware often
952440	954160	targets, and then we just compare
954160	956300	the implementations. And as you'll see here
956300	958360	in a couple slides, what we can do is
958360	960160	say, you have 100 processes
960160	962160	running, 99 of them have
962160	964420	one implementation, and this one process
964420	966840	on its own has a different implementation.
966840	968760	The 99 are the ones where the EDR
968760	970800	is still active, and that one kind of
970800	972820	outlier process is the one that the malware
972820	974880	is unhooked. And so
974880	976800	we like, when we do this type of research, we
976800	978700	like to make experiments that can be
978700	980880	repeated by anyone else. Obviously
980880	982660	not everyone works at Velocity
982660	984820	and has access to our infected
984820	986700	samples from the wild, so we come up with
986700	988880	experiments using open source tools
988880	990760	where you can recreate this on your own
990760	993120	and you can test it in your own environment.
993220	994540	So a very nice tool
994540	996760	for testing EDR, a very nice
996760	998580	open source tool for testing
998580	1001260	EDR bypasses is called SilentStrike.
1001260	1002620	So this is an open
1002620	1004840	source EDR, and it was actually developed
1004840	1006960	just to test these bypasses
1006960	1008860	and then see if you could detect them.
1008860	1010620	The way SilentStrike works is
1010620	1012520	it hooks NT protect virtual
1012520	1014820	memory. This is one of the main functions
1014820	1016840	that malware needs to perform
1016840	1018680	code injection and also to try
1018680	1020840	to keep that code injection stealthy.
1020840	1022760	And so what this open source EDR
1022760	1024260	does is it hooks that function
1024260	1027020	if it gets called where the region is going to become
1027020	1028600	readable, writable, and executable
1028600	1030880	the EDR says you can't do that, and that
1030880	1033560	stops a lot of different code injection techniques.
1033680	1035020	So for our experiment
1035020	1036920	what we did is we took a base
1036920	1038820	Windows 10 install, so no
1038820	1040760	EDR. With SilentStrike
1041280	1042840	you can tell it to create
1042840	1044760	individual processes that it will
1044760	1047260	then treat as an EDR and protect.
1047340	1048640	So we started a notepad
1048640	1050920	and we started a wordpad. At this point
1050920	1052960	they have SilentStrike active in it
1052960	1054820	which is your EDR.
1054820	1056860	We then took a memory sample.
1057000	1058680	After that we ran R77
1058680	1060800	which is an open source rootkit
1060800	1062420	that does this module unhooking
1062920	1065040	and we unhooked the notepad
1065040	1066820	process. And then we took a second
1066820	1068880	memory sample. So we have the state
1068880	1071000	before and after the malware ran
1071920	1072980	and with
1072980	1074900	our new plugin, so unhook system
1074900	1076620	calls to volatility 3
1076620	1078900	what it's saying here is what
1078900	1080740	we do is we enumerate all the functions
1080740	1083080	the slide is cut, there's probably like 50 functions
1083080	1084960	we actually check. But the idea
1084960	1086920	is we're saying for these processes
1086920	1088920	down here, there's no distinct
1088920	1090920	implementations. So every process
1091580	1092880	inside of that memory
1092880	1095120	sample had the same version of the function
1095120	1097140	and then the two that we started
1097140	1098940	under SilentStrike, their NT
1098940	1100840	protect virtual memory, had the
1100840	1103080	EDR's view. This is before we ran
1103080	1104940	R77. We
1104940	1106920	then ran the R77 rootkit
1106920	1108840	on the machine. We
1108840	1110820	unhooked notepad and you can see it
1110820	1113020	removes from distinct implementations
1113020	1114820	it's been reverted back to the base
1114820	1116720	form. So then we took this plugin
1116720	1118980	ran it across the many
1118980	1120960	hundreds of memory samples that we have
1120960	1122420	to test our code on
1122760	1124720	and the only place this plugin
1124720	1126540	fired was either traditional
1126540	1128800	API hooking or EDR unhooks.
1128800	1131020	So there's no false positives with this
1131020	1132640	if the EDR's hooked every process
1132640	1134920	it doesn't make sense that it would skip one or that
1134920	1136860	one should be reverted. This directly
1136860	1139220	tells you where the malware is running.
1140560	1142900	We then started looking into other
1142900	1144980	ways to read NTDLL. So
1144980	1146960	you saw it in the screenshot before from that
1146960	1148900	malware report and I walked you
1148900	1150920	through where to, for unhooking
1150920	1152740	to work, the malware needs access
1152740	1154700	to a clean copy of NTDLL
1154700	1157060	which normally you can just read from disk
1157060	1158960	but there were several EDR vendors
1158960	1160820	that started detecting that because
1160820	1163080	why would some random process need to read
1163080	1164960	NTDLL as a file and like
1164960	1167100	parse the section? The only reason to
1167100	1168980	do that is to unhook the EDR
1168980	1171100	out of memory. So this made
1171100	1173280	it harder for that malware to operate
1173280	1175100	it can't read NTDLL from
1175100	1176740	disk or it's going to get caught.
1176780	1179140	So we saw some malware samples and some
1179140	1180820	open source tools that
1180820	1183060	abused suspended processes to get
1183060	1185380	the clean copy. If you've ever investigated
1185380	1187040	process hollowing, whether
1187040	1189080	you were writing code for it or you were trying to
1189080	1191060	detect it, creating suspended
1191060	1193140	processes is the first step of every
1193140	1195040	process hollowing technique. So we'll see
1195040	1196940	that we catch some of those as well
1196940	1199100	as kind of a side effect. But the idea
1199100	1200900	for EDR bypasses is
1200900	1203180	the malware will create a suspended
1203180	1205020	process. The idea with
1205180	1206960	a suspended process is that the
1206960	1209080	only thing that's going to load is
1209080	1211000	the application executable and
1211000	1212980	NTDLL. It's kind of like a half
1212980	1214800	created process at that point.
1215020	1216880	Once the EXE and
1216880	1219380	NTDLL are mapped into the process
1219380	1221500	then at that point the parent
1221500	1223500	process, the one who created the process, gets
1223500	1225420	control back. So then what the
1225420	1227380	malware does is it just reads from its
1227380	1229700	child process, the clean NTDLL
1229700	1231320	out of memory. The EDR
1231320	1233380	doesn't see a suspended process until
1233380	1235460	it actually starts running. So this
1235460	1237360	puts a clean copy of NTDLL in
1237360	1239500	memory. The malware doesn't have to go read it from
1239500	1241400	disk. And so obviously we want it to be
1241400	1243220	able to detect this as well.
1244240	1245380	So we did
1245380	1247140	some reverse engineering and read some
1247140	1249140	pre-existing reports on what
1249140	1251120	happens with suspended processes. Like I
1251120	1253060	said, we see it a lot because you have to do
1253060	1255600	this if you want to create a hollowed process.
1255740	1257020	But what you have in kernel
1257020	1259100	memory is for every process you have
1259100	1261060	an E-process structure. For every
1261060	1263020	thread you have an E-thread or a
1263020	1265260	K-thread structure. When that process
1265260	1267540	gets created in the suspended state
1267540	1269980	every process starts with one thread.
1269980	1271260	And when you create the
1271260	1273480	thread suspended, its suspense
1273480	1274960	count goes to one, which tells the
1274960	1277120	operating system not to run it. Normally
1277120	1278920	if you just create a process in the normal
1278920	1281240	way or you double click it on your desktop,
1281240	1283020	the suspend count is going to be zero.
1283020	1284940	And as soon as that process can get scheduled,
1284940	1286940	its threads are going to run. But what
1286940	1289020	we saw in every piece of malware
1289020	1290880	that we had and every open source tool we
1290880	1292880	had access to that did this, when
1292880	1294920	they create the suspended process just
1294920	1296980	to read the clean NTDLL,
1296980	1299220	they're never going to run that child process.
1299220	1300740	They are just getting that into memory
1300740	1302820	to get access to the clean
1302820	1304900	system call handlers. So this was
1304900	1307180	pretty easy. We wrote a plugin.
1307180	1308760	Volatility could already enumerate
1308760	1310760	every thread of every process.
1310760	1312760	And then we just added an extra step to say
1312760	1314620	does that thread have a suspend count
1314620	1316740	greater than zero. Running it across
1316740	1319260	our large data set of memory samples,
1319260	1320980	the only false positive we had,
1320980	1322620	which was pretty random, is this
1322620	1324740	work folder shell DLL inside
1324740	1326600	of edge makes suspended threads.
1326600	1328640	We don't know why. So we just added that
1328640	1331040	to the list of ones we don't print out.
1331040	1332820	And besides that, we didn't have a single
1332820	1334820	false positive. And then like I said,
1334820	1336840	at Vlexity, we have hundreds and hundreds
1336840	1338660	of memory samples in different states
1338660	1340680	that we test these things on. And
1340680	1342720	quite a few of the samples that we know
1342720	1344780	have process hollowing in them, they were
1344780	1346780	detected too, because if you're
1346780	1348700	familiar with that technique, the idea
1348700	1350580	is you create a process in a suspended
1350580	1352640	state, you overwrite the code, and then
1352640	1354800	you let that new process run. And so
1354800	1356660	not only is this plugin picking up
1356660	1358800	all the EDR bypasses, we caught
1358880	1361000	a bunch of different... we generically
1361000	1362900	caught a bunch of different process hollowing
1362900	1364340	techniques as well.
1371750	1372790	At Blackhat
1372790	1374750	Europe, maybe two years ago now,
1374750	1376730	three years ago, there was a really cool white
1376730	1378970	paper and talk on a project called
1378970	1381050	Dirty Vanity. The idea was
1381050	1382730	they tested against basically every
1382730	1384870	commercial EDR they could get their hands
1384870	1386650	on. And the idea is they wanted
1386650	1388630	to be able to do code injection into
1388870	1391050	a victim process without the EDRs
1391050	1392690	catching them. And if you're familiar
1392690	1394670	with this, to do code injection, there's five
1394670	1396690	or six APIs you have to call to make
1396690	1398770	that work. And if you call all
1398770	1400670	those in a row and you're injecting, the
1400670	1402610	end result is you're going to inject into your
1402610	1404890	victim process, any half-decent
1404890	1406810	EDR, any enterprise-level
1406810	1408890	EDR is going to catch that.
1408990	1410730	So what was really interesting about Dirty
1410730	1412630	Vanity is they instead created
1412630	1414750	clone processes, or a forked process
1414750	1416930	if you're more familiar with Linux.
1416950	1419110	So the idea with a clone or a
1419110	1420930	forked process is your process
1420930	1423030	is running, you create a clone
1423030	1424870	of your own process, so that
1424870	1426930	child process you created has your
1426930	1429010	same exact state. So then what
1429010	1431110	Dirty Vanity did is they called the first
1431110	1432710	couple APIs from the parent
1432710	1434890	and then they create the clone,
1434890	1436810	which has the same exact state as the parent
1436810	1438810	and they called the final set of APIs
1438810	1441030	from the child. So the end result is
1441030	1442970	they're still injecting code into the
1442970	1445030	victim process, but none of the
1445030	1447090	EDRs that they tested were able to
1447090	1448890	detect the calls going across
1448890	1450810	the process boundary. So obviously
1450810	1452350	we wanted to be able to detect this
1452810	1455150	from a memory forensic standpoint.
1455390	1456750	So while we were looking
1456750	1459110	into what it means to clone a process
1459110	1460830	in Windows, the real internal
1460830	1462970	state, we saw that what Windows
1462970	1464670	does when it's setting up that clone
1464670	1466810	is it makes a suspended thread.
1466810	1468950	So that child that's being cloned into
1468950	1470810	has its first thread suspended
1470810	1472910	and with Dirty Vanity it
1472910	1474850	never restarted the child process
1474850	1477390	or the initial thread of the child process.
1477390	1479270	So the plugin that we had detected it
1479270	1481530	right away. And if you're interested in this
1481530	1483670	I have it cited here at the bottom.
1483670	1485370	We found this thing called the Definitive Guide
1485370	1487110	to Process Cloning on Windows. It's like
1487110	1489290	40 pages of APIs and
1489290	1491230	data structures and background, but it
1491230	1493490	pretty much told us exactly what we needed to know
1493490	1496070	on top of what we saw with reversing.
1497190	1499110	We made a memory sample that was
1499110	1500870	infected with Dirty Vanity
1501390	1503090	and as you can see we're running our
1503090	1504890	suspended threads plugin.
1504890	1506630	It's telling us that inside
1506630	1508910	of the fake EXE process, which is
1508910	1510690	what Dirty Vanity calls itself
1510690	1512550	if you just compile it straight from GitHub
1512550	1514810	and then it's saying that
1514810	1517350	this process ID, 6752
1517350	1519070	this thread, it is
1519070	1520830	suspended or suspend count
1520830	1522750	is greater than zero. And then
1522750	1524750	if you look at PSTree in Volatility
1524750	1526950	so this is drawing out the parent
1526950	1528590	child relationship of processes
1528590	1531110	you can see that the original
1531110	1532910	fake EXE has
1533030	1535370	a child called fake EXE
1535370	1536730	so this is that
1536730	1539070	process that was created through
1539070	1540970	cloning. So this is the
1540970	1542890	parent, this is where Dirty Vanity
1542890	1544430	will call the first couple APIs
1544430	1546910	it then forks or clones off
1547090	1549010	a child process where it will call the remaining
1549010	1550970	APIs bypassing the
1550970	1552970	EDR, but what you can
1552970	1554930	see Volatility picking up on is the
1554930	1556790	child's always going to have it's main thread
1556790	1558950	suspended. And so we pick up on that
1558950	1561010	right away, you would then run PSTree
1561010	1562870	would probably be the next thing if this was a real
1562870	1564950	investigation, you would figure out the
1564950	1567150	parent that created the suspended
1567150	1568910	process. And then you can see
1568910	1571010	here what it does in demo
1571010	1573230	mode, so if you don't have an EDR you're targeting
1573230	1574910	Dirty Vanity will run
1574910	1577110	command shell with some shell code that
1577110	1579050	makes a pop up on the screen or prints it
1579050	1581050	to the terminal. So you see that here
1581050	1583010	as well, that child process.
1583010	1584890	But through the new plugin you see exactly
1584890	1586950	which process is malicious, you can
1586950	1588750	then do your normal memory forensics
1588750	1589730	workflow.
1594060	1596560	As you've been seeing in the slides,
1596560	1598220	the previous techniques that we looked
1598220	1600440	into for bypassing
1600440	1602400	the system call handlers relied
1602400	1604140	on overwriting code.
1604260	1606240	And you might have been thinking, especially if you've
1606240	1607680	done debugging before or
1607680	1610100	low level programming before, the
1610100	1612400	idea that you're going to overwrite NTDLL
1612400	1614160	the entire thing or certain functions
1614160	1616060	at run time is a bit unsafe.
1616060	1618320	Because you can imagine if you're overwriting
1618320	1620140	30 or 40 functions code in
1620140	1622120	memory, if any other thread is
1622120	1624100	using that function or a system call
1624100	1626160	was just made and you're waiting for user land
1626160	1628160	to return again, you just blew away
1628160	1630160	the code that was technically running on the
1630160	1632140	CPU. So malware does it,
1632140	1634380	it generally works, but it's a bit unsafe.
1634380	1636020	And then the other thing you could imagine
1636020	1638240	is EDR could just check for its hooks.
1638240	1640260	If it hooked 40 or 50 system
1640260	1642000	call handlers and then it checks
1642000	1644340	whatever frequency later and its handlers
1644340	1646200	are overwritten, it knows that there's
1646200	1648280	malware inside of that process.
1648280	1650260	So this led to what was some
1650260	1652280	really interesting research on the open
1652280	1653980	source side, and like I said, we saw it
1653980	1656220	in private malware as well.
1656220	1658140	So there were alternative methods developed
1658140	1660560	where the code is not overwritten.
1660560	1662300	The malware, as you'll see, can
1662300	1664260	still make its malicious system calls,
1664260	1666220	it can still do any system calls at once
1666220	1668180	with any parameters, but
1668180	1670400	we're not overwriting code. So inside
1670400	1672340	of NTDLL, in that EDR
1672340	1674440	protected process, the original
1674440	1676460	implementation that the EDR gave
1676460	1678460	is the same, the hooks are present,
1678460	1680560	the EDR would get control if the
1680560	1682480	real system call was used, but
1682480	1684440	malware is just going to avoid those code
1684440	1686280	paths. So we'll look at the different ways
1686280	1688840	they do that and the ways we can detect it.
1689540	1690540	The first one we
1690540	1692640	looked at were direct system calls.
1692680	1694540	So the malware authors realized that
1694540	1696560	why do I need to call the system call
1696560	1698860	handler inside of NTDLL?
1698860	1700420	You saw that a system call handler
1700420	1702780	is only 5 or 6 instructions,
1702780	1704500	why don't I just do that myself?
1704500	1706440	So rather than going through NTDLL,
1706440	1708500	which the EDR is hooked, I'm just going to
1708500	1710460	set up the registers that are needed and I'm going to
1710460	1712840	make the syscall instruction on my own.
1712920	1714580	And again, the EDRs that are
1714580	1716640	trying to catch you through system call hooks,
1716640	1718400	they are blind to you because you're not
1718400	1720200	going through their hooked code.
1720200	1722500	The problem with this, and there was a
1723740	1724840	very interesting series
1724840	1726680	of posts by Elastic that I have cited
1726680	1728860	at the end, this is where they started doing
1728860	1730740	call stack examination, Elastic
1730740	1732400	does this really well, there's some open
1732400	1734700	source implementations of it also,
1734700	1736400	but the idea is, if you
1736400	1738980	were making a system call instruction,
1738980	1740520	or you're calling a system call instruction
1740520	1742640	outside of NTDLL,
1742640	1744400	so you're in some random DLL that you've
1744400	1746540	injected, or you're in a shellcode region,
1746540	1748280	your EDR in kernel mode
1748280	1750380	can see that. And then it's going to say, why is
1750560	1752180	a system call being made from a random
1752180	1754240	shellcode region that wouldn't normally
1754240	1756160	happen on a running machine?
1756260	1758740	And then the other downside to this, as we'll see,
1758740	1760220	is you have to know where the system call
1760220	1762300	indexes are. So like I said, there's hundreds
1762300	1764200	of system calls per release of
1764200	1766340	Windows, and the indexes change almost
1766340	1768860	every time. The indexes are not guaranteed.
1768960	1770200	If you're writing normal
1770200	1772160	legitimate code, you shouldn't care about
1772160	1774220	the indexes, you just call the higher
1774220	1776100	level API, and the operating system
1776100	1778160	does the work for you. But in this case,
1778160	1780140	where you want to make the system call yourself, and you
1780140	1782360	don't want to use the normal APIs
1782360	1784160	because the EDR has hooked them, you
1784160	1786060	have to be able to get that index value
1786060	1788020	to put into EAX.
1788500	1789860	So if we look at the
1790400	1791860	way that this has evolved
1791860	1793980	over time, the first tool that made
1793980	1796060	this popular is called dumpERT.
1796060	1798280	It's an open source tool, it's still on GitHub,
1798280	1799880	has a very nice companion blog
1799880	1802080	post, and as you can see,
1802080	1803980	for every system call it
1803980	1805920	wants to make available to the malware,
1805920	1807920	it has to put that little stub itself.
1807920	1810000	It has to update R10,
1810000	1812060	update EAX with the very specific
1812060	1813880	index for the very specific system
1813880	1816020	call, then it can call system call
1816020	1818060	in return, and at this point you
1818060	1820180	can make those, but if you look at the code,
1820180	1821900	this is hard-coded to one
1821900	1823940	version of Windows 7, one release
1823940	1826100	under Service Pack 1, this is not
1826100	1827500	something you could use in
1828020	1830040	generic malware. So instead
1830040	1832120	what we want to be able to have is where
1832120	1834100	that is very loud,
1834100	1835960	instead we want to make it where system
1835960	1838040	calls can be resolved dynamically.
1838040	1839980	So instead of your malware having
1839980	1841880	what would literally be hundreds
1841880	1843880	of hard-coded system call
1843880	1846240	tables for different versions of Windows,
1846240	1847820	we want to find those indexes
1847820	1849760	dynamically. The first
1849760	1851980	implementation of this is called
1851980	1853720	Hell's Gate. Almost every technique
1853720	1855860	has gate in the name, which makes it kind of annoying
1855860	1857980	to remember. So the first one is Hell's
1857980	1859760	Gate. In this case, what it did
1859760	1862080	is it parsed NTDLL on disk.
1862080	1863860	Kind of like we talked about before, but
1863860	1865960	instead of overwriting pre-existing
1865960	1867820	code or the EDR's code,
1867820	1869960	it's just parsing NTDLL on disk
1869960	1871680	and then it's dynamically resolving
1871680	1874160	the numbers. Because, for example,
1874160	1875800	let's say in this case it wants to
1875800	1877780	call a ZW open process.
1877840	1879560	Instead of having to know beforehand
1879560	1881560	that on Windows 7 Service Pack 1
1881560	1883900	the index is 23 hex,
1883900	1886260	it can just load NTDLL,
1886260	1887600	it can call get proc address
1887600	1889720	for ZW open process, it can
1889720	1892080	do some automated disassembly on the code,
1892080	1894320	and it can read out the index dynamically.
1894620	1895920	So this was Hell's Gate.
1895920	1898020	You can see the code here on the right.
1898020	1899660	Instead of being hard-coded to a certain
1899660	1901800	number, it has a little API wrapper
1901800	1903500	that you use as a programmer.
1903640	1905660	You prep the system call, that's going to fill
1905660	1907620	in this global variable, and then when it
1907620	1909700	comes time to make the system call,
1909700	1912300	it will fill in the number correctly for you.
1912300	1914080	The problem with this, like I said,
1914080	1915180	is most
1915180	1917880	decent EDRs, I'm not going to say certain vendors,
1917880	1919600	but most decent EDRs, if
1919600	1921520	random code is reading NTDLL
1921520	1923720	and parsing the P header and all of that,
1923720	1925580	the EDR is going to flag on it because it's just
1925580	1928020	not something legitimate code would do.
1928020	1930020	So this led to even more
1930020	1932020	gates. There is Tataris
1932020	1934040	Gate, which initially, there
1934040	1935920	was some detections and some YARA
1935920	1938160	rules that were put out to detect
1938160	1940200	this code pattern that's very hard-coded
1940200	1941960	and this code pattern that's very
1941960	1944040	hard-coded. All it did was
1944040	1945960	make it a little more difficult to where
1945960	1947940	those naive patterns would break. It put
1947940	1949960	some no-op instructions, it
1949960	1951980	put some other instructions that didn't have a side
1951980	1953980	effect. But remember, you're in the system
1953980	1956020	call handler path, so you can't
1956020	1958080	add a bunch of junk instructions or you will
1958080	1960140	kill performance on the machine.
1960140	1962040	In a real process, you're going to have thousands
1962040	1964140	and thousands of system calls running.
1964140	1965980	You cannot have where you put in a bunch of
1965980	1967860	junk code just to throw off a YARA
1967860	1969860	rule. So even adding a few extra
1969860	1971820	instructions will have a real impact
1971820	1974120	on the system. So like I said, Tataris
1974120	1975960	Gate is just trying to make it where if all
1975960	1977780	you have is a kind of brittle, basic
1977780	1979960	YARA rule, you will not catch those code
1979960	1982000	patterns. There was then Halos
1982000	1984000	Gate, which was an interesting
1984000	1986220	twist on reading NTDLL
1986220	1988160	from disk. So they wanted to,
1988160	1990140	these malware authors wanted to get away
1990140	1992400	from reading NTDLL from disk.
1992400	1994080	So instead what they do is they kind
1994080	1996080	of rely on the fact that the EDRs
1996080	1998040	aren't going to hook every system call.
1998040	1999980	They're just going to, the malware is
1999980	2002020	only going to unhook this, sorry, the EDR is
2002020	2004160	only going to hook the system calls that it wants to
2004160	2005980	monitor. So what
2005980	2008180	Halos Gate does is it dynamically goes
2008180	2009720	through all the other system calls
2009720	2011820	that the EDR is not hooking
2011820	2013760	and then it just does some math. It says,
2013760	2015880	OK, I know the system call before it and the system
2015880	2017880	call after it are this number, so the one
2017880	2019880	in the middle, it can dynamically figure it
2019880	2021800	out. Again, this avoids reading
2021800	2023700	NTDLL from disk.
2023900	2025660	And then there's a really cool technique
2025660	2027160	called address sorting.
2027640	2029760	One of the authors of this open
2029760	2031760	source project realized that all the
2031760	2034500	system calls are put in order alphabetically.
2034500	2035740	So if you just read
2035740	2037840	the addresses of where they all are,
2037840	2039420	it's kind of the same idea. You
2040120	2041660	alphabetically sort them.
2041740	2043440	If they're the one that you're trying to use as
2043440	2045460	hooked, you just look at the one before it and you
2045460	2047440	add one and now you know the index that
2047440	2049360	you need. And then even dealing
2049360	2051340	with all of that previously was kind of
2051340	2053320	difficult. There's a lot of assembly, a lot of low
2053320	2055380	level C code. So there's this really
2055380	2057600	nice project called Sys Whisperers 2.
2057600	2059400	And the 2 is important because the first version
2059400	2061280	was not very good, but the second
2061280	2063400	version is very powerful.
2063420	2065640	This integrates with Visual Studio.
2065640	2067400	You call directly through this and
2067400	2069260	it does all the nasty work in the background
2069260	2071440	for you to dynamically resolve
2071440	2073420	those system call indexes. So if you
2073420	2075720	want to write code that bypasses EDRs,
2075720	2077520	you want to be able to make whatever system
2077520	2079440	call you want without being detected,
2079440	2081440	all you have to do is import the Sys
2081440	2083380	Whispers 2 into your Visual Studio
2083380	2085300	project, write your malware freely
2085300	2087380	and it does all the hard work in the
2087380	2089540	background for you. So with
2089540	2091340	all these different techniques that
2091340	2093600	make EDRs blind to what's happening,
2093600	2095660	we wanted to be able to detect this.
2095660	2097580	So we kind of already knew this before going
2097580	2099880	into it, but we did a large sweep
2099880	2101700	across all of our Windows
2101700	2103700	memory samples and for every
2103700	2105360	version of Windows going back to XP
2105360	2107560	through the latest Windows 11, there's
2107560	2109400	only 3 DLLs that legitimately
2109400	2111380	implement system calls. There's the
2111380	2113380	NTDLL that I talked about,
2113380	2115340	Wow64 for 32-bit processes
2115340	2117500	and then Win32 is for
2117500	2119540	the GUI, so what you're seeing here on the screen
2119540	2122080	with Explorer and PowerPoint.
2122260	2123640	So the idea is
2123640	2125800	through memory forensics, if we find
2125800	2127820	the instructions needed to make
2128020	2129640	a system call instruction and set the
2129640	2131820	parameters and it's not in one of those
2131820	2133540	3 DLLs, this is malware
2133540	2135700	trying to bypass the system.
2137400	2138020	And then
2138020	2139560	like I mentioned, it's some very, very
2139560	2141640	cool low-level work. I threw this
2141640	2143660	screenshot in literally last
2143660	2145600	second, like right before I sent these slides to
2145600	2147860	DEF CON, because
2147860	2149620	there was a talk by a security vendor
2149620	2151740	as I was making the slides, right as I
2151740	2153600	was about to upload it and I took this screenshot
2153600	2155640	and threw it in last second, because it was talking
2155640	2157580	about malware that was just used recently
2157580	2159880	in the last 1 or 2 months in real attacks
2159880	2161620	and it, the malware was called
2161620	2163860	Dodgebox and it's talking about how
2163860	2165880	in every phase of the malware, every component
2165880	2167800	the malware had, it did call
2167800	2170000	stack spoofing, so bypassing
2170000	2171900	the EDRs to make it appear
2171900	2173780	where those system calls, so it's doing
2173780	2175820	direct system calls, making it appear
2175820	2177720	where it came from the trusted binary, so
2177720	2179780	the ones we saw in the last slide, instead
2179780	2181740	of the malware itself. And so it's this
2181740	2183820	constant back and forth between EDRs
2183820	2185720	and malware, trying to figure out that
2185720	2187780	system calls are being made from the wrong spot
2187780	2189740	but quite honestly the EDRs are in
2189860	2191540	a tough spot and usually the malware
2191540	2193680	wins. We don't have
2193680	2195680	these problems with memory forensics, we don't have
2195680	2197720	to detect the system call the second
2197720	2199760	it's made, we're trying to find proof
2199760	2201680	of code that can do that or does that
2201680	2203800	through memory forensics, and so what
2203800	2205740	we did is we wrote, we used
2205740	2207900	Capstone, which is a very flexible
2207900	2210040	disassembly library, has Python
2210040	2212100	support so you can use it directly in volatility
2212100	2213940	and what we do is look
2213940	2215720	for blocks of code, so block
2215720	2217520	code pattern blocks where
2218100	2220040	EAX gets updated, that's your
2220040	2221940	system call index, where R10 gets
2221940	2223960	updated, where one of the system call
2223960	2226480	instruction happens and where there's a return.
2226500	2227920	We did a bunch of work so that
2227920	2229920	simple things like Tataris gate with this
2229920	2232240	noops wouldn't bypass our code,
2232240	2234060	we're not doing pattern matching, we're doing
2234060	2235980	actual automated static disassembly
2235980	2238200	and when we tested this on
2238200	2240200	every implementation that we had
2240200	2242260	of this technique, our new plug-in
2242260	2244340	direct system calls detected it.
2244340	2246180	In this case, just to make it fit on a slide
2246180	2248320	nicer, this is Hell's Descent
2248320	2250280	from Hell's Gate, so this is where it's
2250280	2252120	calling the system call instruction
2252120	2254220	on its own, and then the plug-in
2254220	2256060	saying, hey, inside of this process,
2256060	2258180	executable with this PID, and it shows
2258180	2260160	you right in memory where that system call
2260160	2262180	handler is. So it's as simple as
2262180	2264020	running this plug-in across your
2264020	2266140	potentially infected samples, and it tells you
2266140	2268260	right where the malware is.
2269620	2270200	And then
2270200	2272540	with the indirect system calls,
2272540	2274160	the idea is, instead of having
2274160	2276020	that code pattern where you're making
2276020	2278240	syscall or int2e directly from
2278240	2280400	your malware code or your shell code,
2280400	2282020	which, again, you have to do a bunch of call
2282020	2284060	stack spoofing and things, or the EDRs will
2284060	2286100	see you, the idea is
2286100	2288180	you find the address of the
2288180	2290660	syscall instruction in ntdll,
2290660	2292120	but instead of calling the
2292120	2294160	function of that, you find where
2294160	2296100	the syscall instruction is, and you jump to
2296100	2298340	it. So you set the registers yourself,
2298340	2300060	you do all the prereqs yourself,
2300060	2302160	you jump to the syscall instruction, it looks
2302160	2304380	like it's coming from ntdll,
2304380	2306060	and then depending on which EDR you
2306060	2308020	have, that EDR is going to think it's
2308020	2309980	the real system call, and then you've
2309980	2311140	bypassed it.
2311900	2313540	So we wanted to be able to
2314100	2316160	detect that as well, and something
2316160	2318060	that also gets used with this technique
2318060	2320140	are the exception handlers and the debug
2320140	2322120	registers, which is the last thing we
2322120	2324220	cover in this talk. So the idea is
2324220	2326140	debug registers have been abused forever
2326140	2328080	by malware, there was a frack article in
2328080	2330180	2008 that's the first, considered
2330180	2332480	the first public documentation of it,
2332480	2334120	and the idea is by
2334120	2336160	abusing debug registers, you can
2336160	2338100	get your exception handler called
2338100	2340080	at any point in time, and then
2340080	2342080	from your exception handler, you're going to
2342080	2344280	make the system call instruction, and
2345040	2346200	EDRs do not follow
2346200	2348040	this well as, at all. They don't expect
2348040	2350040	malware to be running inside of exception
2350040	2352080	handlers. So a cool
2352080	2354020	open source project for this, if you want to see it
2354020	2356060	yourself, is called MutationGate, it is
2356060	2358160	on GitHub, and you can see
2358160	2360340	what it's doing, it's adding a vectored
2360340	2362040	exception handler,
2362040	2363960	so it's saying it wants to handle exceptions
2363960	2366220	in its process, this is the function
2366220	2367980	that's going to be called, and then
2367980	2369820	on its own, it sets a breakpoint
2369820	2371940	at this innocuous system call,
2372460	2374100	NTDrawText, that has nothing to do
2374100	2376120	with code injection or malware,
2376120	2378360	so the idea is, this malware,
2378360	2380000	this code injection, uh, this EDR
2380000	2382080	bypass technique, will get called
2382080	2384120	whenever a breakpoint is set, and then
2384120	2386240	it explicitly sets a breakpoint on
2386240	2388300	where the system call instruction
2388300	2390880	is inside of this innocuous function.
2391280	2392180	So then, in
2392180	2394120	the implementation of it, what it does,
2394120	2396160	is every time the malware wants to make
2396260	2398220	a malicious system call, it just calls
2398220	2400040	NTDrawText, which again,
2400040	2402060	you can't do anything malicious with that,
2402060	2404580	and then the malware, the MutationGate,
2404580	2406700	it updates RAX right before
2406700	2408520	the system call instruction to be
2408520	2410560	the real system call. So your EDR
2410560	2412520	is going to think, hey, this malicious code's
2412520	2414540	calling DrawText, it's going to write something on
2414540	2416540	the screen, but in reality, it's
2416540	2418860	all the prereqs you need for code injection.
2420500	2422660	So we wanted to detect this, we didn't
2422660	2424600	even have to do any major reversing
2424600	2426520	for this, there was two very nice
2426520	2428600	blog posts on the topic that we have referenced
2428600	2430620	here, and the only downside
2430620	2432340	to this is legitimate software
2432340	2434620	uses uh, exception handlers,
2434620	2436280	you don't want your software
2436280	2438260	having an unhandled exception and then like
2438260	2440320	crashing the machine, so by having
2440320	2442320	an exception handler, you make it where
2442320	2444160	your code gets to handle the exception
2444160	2446340	and then you can cleanly exit.
2446360	2448380	So what we did is we, instead
2448380	2450440	of just listing them all out like some plugins
2450440	2452300	do, we applied very
2452300	2454400	similar static disassembly to
2454400	2456340	the function handlers, we looked
2456340	2458380	at all the malicious techniques, we saw which
2458380	2460440	registers they interacted with, which per-
2460440	2462560	which actions they performed, and so
2462560	2464480	instead of just listing out every vector
2464480	2466480	exception handler, we apply
2466480	2468560	the static disassembly, and then we only list
2468560	2470440	out the malicious ones. And as
2470440	2472380	you can see here, with our new plugin,
2472380	2474440	we're catching mutation gate generically
2474440	2476740	right away, because of how it interacts
2476740	2477600	with it.
2478280	2480260	There was also a cool project by
2481200	2482320	Marcus Hutchins, where
2482320	2484480	he wanted to bypass EDRs in the
2484480	2486860	same way, instead of the
2486860	2488460	vector exception handler, he
2488460	2490020	used the higher level one, the
2490840	2492660	unhandled exception filter.
2492660	2494380	In this case, this is going to be the
2494380	2496580	address of where he has his exception
2496580	2498440	handler called, and then he's
2498440	2500400	calling setThreadContext on what's an
2500400	2502400	invalid address. So this is going
2502400	2504500	to trigger the exception handler.
2504860	2506860	So what we did here was very similar.
2506860	2509160	We enumerate all the handlers,
2509160	2510420	and then we make it-
2510420	2512300	this keeps jumping a lot. We
2512300	2514620	enumerate all the handlers, we apply our static
2514620	2516480	disassembly, and then in this case
2516480	2518320	we find his malicious process
2518320	2520700	generically, because the exception
2520700	2522480	handler is doing things that you would need
2522480	2524260	to bypass an EDR.
2524800	2526540	And then with the debug registers, the last
2526540	2528500	thing we really show here, if
2528500	2530500	you're familiar with AMSI bypasses,
2530500	2532400	one of the things you need to do is,
2532400	2534480	one of the functions you're probably going to tamper with
2534480	2536580	is the scanBuffer1. In this
2536580	2538420	case, they set a breakpoint on it,
2538420	2540620	and they make it where that function doesn't
2540620	2542760	get- anytime that function returns,
2542760	2544580	it returns that the code is okay.
2544580	2546480	So you can send whatever malicious PowerShell
2546480	2548300	you want through, whatever malicious
2548300	2550300	macros that you have, and
2550300	2552400	with this code present, all of your
2552400	2554440	EDRs are forced to say, hey yeah, this is
2554440	2556200	clean, and then it gets to execute
2556200	2558340	on the system. And you can see
2558340	2560360	that here with our new plugin.
2560480	2562280	So with the vector exception handler,
2562280	2564280	we're catching it right away. The project
2564280	2566400	that implements what you're seeing on these slides
2566400	2568400	is called Patchless AMSI.
2568400	2570320	So we're not only catching its vector
2570320	2572380	exception handler, we're also catching
2572380	2573940	its abuse of the debug registers
2573940	2576220	so that it can be called whenever
2576220	2578280	the code is going to get scanned by the
2578280	2579960	AMSI subsystem.
2580380	2582460	So the end result of our project is we documented
2582460	2584380	and went through every single way that
2584380	2586520	EDRs get bypassed in user land,
2586520	2588440	and then we wrote a bunch of volatility plugins
2588440	2590200	to automatically detect it.
2590200	2592100	Two quick things before I break.
2592100	2594480	We wrote a 19-page white paper about this.
2594480	2596460	It should be on the DEF CON website by like now
2596460	2598400	or tomorrow. Feel free to email me
2598400	2600260	if not. Also, the slides.
2600260	2602360	Don't try to take pictures of the next couple slides.
2602360	2604380	These are all the references that you were seeing
2604380	2606480	with the numbers at the top of the slides.
2606480	2608440	We have like 45 references. It was a huge
2608440	2610340	research effort. The slides are on the
2610340	2612480	DEF CON website as well, or email me if you can't
2612480	2614300	find them. But if you really want
2614300	2616380	to understand in great detail,
2616380	2618180	read the paper, and then read all the references
2618180	2620260	as well. And again, thank you for coming
2620260	2621200	to the talk.
2622860	2625260	Thank you.
