DEFCON30-DemoLabs-EDR_detection_mechanisms_and_bypass_techniques_with_EDRSandblast-v1.0
DEFCON30-DemoLabs-EDR_detection_mechanisms_and_bypass_techniques_with_EDRSandblast-v1.0
© WAVESTONE 1
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
Hi !
© WAVESTONE 2
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
Hi !
github.com/wavestone-cdt/EDRSandblast
What is EDRSandblast ?
/ Tool written in C
/ Detects common monitoring techniques used by EDR software on
Windows endpoints
/ Implements techniques to bypass them (both user-land and kernel-land)
/ Exists as a CLI tool and as a static library to include in another project
© WAVESTONE 3
/ 01 So you want to dump LSASS ?
© WAVESTONE 4
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
…
© WAVESTONE 5
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
© WAVESTONE 6
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
© WAVESTONE 7
How come the EDR knows everything ?
Tool starts
> PE is loaded
> Process is created
> Main thread is started
© WAVESTONE 8
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
⁄ The Kernel notify routine callbacks are added through documented APIs to define driver-
supplied callback routines.
The callbacks routines are then stored in undocumented arrays in kernel memory:
PspCreateProcessNotifyRoutine, PspCreateThreadNotifyRoutine, and PspLoadImageNotifyRoutine
⁄ The callback routines are then called upon the occurrence of their associated system
events.
© WAVESTONE 9
Demo
© WAVESTONE 10
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
Tool starts
> PE is loaded
> Process is created
> Main thread is started
• Using these notifications, EDR may also insert its own libraries inside each process
memory space before it starts
© WAVESTONE 11
Demo
© WAVESTONE 12
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
Call to OpenProcess()
© WAVESTONE 13
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
⁄ The Kernel Object callbacks are added through a documented API to define driver-supplied
ObjectPreCallback and ObjectPostCallback routines.
The callbacks routines are then stored in an undocumented doubly linked list, with no
symbols.
⁄ The callback routines are then called when or after a process or thread make a handle
operation.
© WAVESTONE 14
Demo
© WAVESTONE 15
How come the EDR knows everything ?
Calls to
ReadProcessMemory()
• EDR subscribed to a special event provider called ETW Threat Intelligence, reserved to
security products (signed as « Early-Launch-Antimalware »)
• This provider resides in kernel memory and cannot be altered from userland
• Calling certain kernel functions (ex. MiReadWriteVirtualMemory) will generate events
available for the EDR to analyze
© WAVESTONE 16
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
© WAVESTONE 17
How come the EDR knows everything ?
Calls to
CreateFile()and
WriteFile()
© WAVESTONE 18
How come the EDR knows everything ?
© WAVESTONE 19
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
© WAVESTONE 20
/ 02 How to bypass these monitoring techniques
© WAVESTONE 21
Hooks are detected and removed by leveraging on-disk DLLs
Detecting hooks
For all loaded DLLs of a process, the content on disk is compared to the one in memory. Every
difference found in a code section is a potential hook.
Removing hooks
Instructions overwritten by hooks are restored using the on-disk content. Page containing the
instructions is temporarily set to be writable using NtProtectVirtualMemory.
However, this function is probably hooked itself by the EDR.
© WAVESTONE 22
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
Search and use an existing trampoline allocated by the EDR itself to get
2 an unhooked version of NtProtectVirtualMemory
Load an additional version of ntdll library into memory and use the
3 NtProtectVirtualMemory from this library
© WAVESTONE 23
Demo
© WAVESTONE 24
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
⁄ A driver can be leveraged to access the kernel ⁄ Global variables’ offsets and fields offsets in
memory as they share the same memory structures are leveraged by EDRSanblast to know
address space. where to write (instead of relying on the search of
memory patterns).
⁄ Since the introduction of Driver Signature
Enforcement (DSE), new drivers (post 07/2015) ⁄ Known offsets allow more stability and reduce
must be certified by Microsoft Windows Hardware the risk of BSOD.
Quality Labs (WHQL).
⁄ The offsets can be:
⁄ A legitimate and WHQL-certified but vulnerable
▪ Passed in a CSV file, with 450+ versions of
driver can be exploited to obtain arbitrary read /
the Windows kernel supported to date
write of kernel memory primitives.
▪ Automatically recovered, if the endpoint
has Internet connectivity, by downloading
the .pdb (from MS symbol server) associated
with the targeted ntoskrnl version
© WAVESTONE 25
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
Both lists are then walked and the PreOperation and PostOperation fields of the
undocumented structure of each item are analyzed to identify if the callbacks belong to an
EDR driver and to disable the callback, using the Enabled field.
The undocumented structure has been reversed and was constant from Windows 10 versions
10240 (July 2015) to 22000.
© WAVESTONE 26
Demo
© WAVESTONE 27
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
⁄ Patching a process memory to disable user-land ETW loggers (for instance by patching
ntdll!EtwEventWrite) will not impact the ETW TI provider.
As can sometimes be incorrectly stated, process memory patching does not "Disable Event
Tracing for Windows".
⁄ Disabling the ETW TI provider with a kernel memory read/write primitive is simply a
matter of patching a value in the _ETW_GUID_ENTRY entry representing the ETW
TI provider in memory.
© WAVESTONE 28
Demo
© WAVESTONE 29
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
github.com/wavestone-cdt/EDRSandblast
The vulnerable RTCore64.sys driver can be retrieved at:
https://tinyurl.com/Demo-RTCore64
Quick usage
EDRSandblast.exe <audit | dump | cmd | credguard | firewall> [--usermode] [--kernelmode]
Options
© WAVESTONE 30
New features published this morning!
/ Downloading and parsing of the ntoskrnl PDB at runtime for offsets retrieval
/ Refactoring of the kernel read/write primitives making the support of a new vulnerable driver
simpler to implement
© WAVESTONE 31
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
Example of a simple LSASS dumper program that uses the EDRSandblast API
© WAVESTONE 32
Any Questions,
Suggestions,
Ideas?
© WAVESTONE 33
/ 04 Annexes
© WAVESTONE 34
DEF CON 30 – DEMOLABS - EDR DETECTION MECHANISMS AND BYPASS TECHNIQUES WITH EDRSANDBLAST
⁄ PatchGuard, also known as Kernel Patch Protection (KPP), is a protection mechanism for
the Windows (x64) kernel memory to prevent illegitimate modifications of kernel
memory.
© WAVESTONE 35