Event Tracing For Windows - Introduction
Event Tracing for Windows or ETW, is a powerful tracing mechanism built into the Windows OS which allows for collecting detailed information about events and activities that occ...
Jump to Section (8)
Introduction
Event Tracing for Windows or ETW, is a powerful tracing mechanism built into the Windows OS which allows for collecting detailed information about events and activities that occur on the system. Events are generated from within the system itself whether executed by the OS (e.g. loading a DLL or by the user (e.g. opening a file).
In addition, events are generated by both user-mode applications and kernel-mode drivers and subsequently recorded in log files. These log files can be retrieved and examined to gain insight into events that occurred on the system. With that being said, ETW is considered an invaluable source of information for defenders when analyzing breaches and attempting to understand the techniques used by the attackers.
Moreover, security solutions will commonly subscribe to ETW events to detect and prevent attackers in real-time. These solutions will use different algorithms and rules to determine whether an event is considered malicious.
ETW Architecture
Based on Microsoft's documentation, ETW is constructed from four main components:
- Providers Providers are the top-level entities in the ETW hierarchy. They are responsible for generating events and can be a user-mode application, a kernel-mode driver, or the Windows kernel itself. Each provider is represented by a unique GUID. A system's ETW providers can be listed by executing
logman query providersin the Windows command line. The image below shows a truncated output of this command. Thelogmancommand line tool will be explained further in the next module.

- Tracing session A tracing session represents a logical container for capturing and managing events from one or more ETW providers. It provides a centralized context where events are collected, filtered, and processed. In Microsoft's own words: "A session is a kernel object that collects events into a kernel buffer and sends them to a specified file or real-time consumer process". Tracing sessions can be queried using the
logman query -etscommand, which outputs the results shown below.

- Controllers Controllers are responsible for managing and controlling ETW tracing sessions by allowing the user to start, stop, and configure them. When a tracing session is enabled, a specific ETW provider can begin sending events to it, which can then be read by ETW consumers.
- Consumers As mentioned earlier, ETW consumers are applications that connect to an ETW tracing session and read events written to it that are supplied by one or more providers. A tracing session can be found running without any ETW consumer connected to it. Additionally, one ETW consumer can be connected to one or more tracing sessions, allowing it to read more than one type of logged event (e.g. network events and system events).
ETW Architecture Diagram
The following image depicts the interconnection of the ETW architecture. It is important to note that trace files have a .etl file extension and are produced by enabled ETW trace sessions. These files store the events that are recorded by the provider during the session.

Interacting With ETW
The ETW components are built into the Windows OS kernel, providing the infrastructure for event-based tracing and logging. ETW functionality is exposed to user-mode applications through a set of WinAPIs allowing developers to interact with the ETW infrastructure and utilize its tracing capabilities. User-mode applications can make use of the ETW WinAPIs to register and unregister ETW providers, write events to the trace session, and configure events to be logged. Some of the ETW WinAPIs are:
- EventWrite and EventWriteEx Write an event to the ETW event stream. These WinAPIs are also named
EtwEventWriteandEtwEventWriteEx, respectively. StartTraceA and StopTraceA Start and stop an ETW tracing session. - QueryAllTraces Retrieves the properties for all running ETW tracing sessions.
ETW evasion techniques can be constructed by altering the execution path of these WinAPIs by either patching or hooking these functions. It is worth mentioning that the ETW functions are often exported from the Advapi32 DLL.
Kernel-level ETW
ntoskrnl.exe, also known as Windows NT Operating System Kernel Executable, contains the kernel and executive layers of the Microsoft Windows NT kernel and is responsible for hardware abstraction, process handling, and memory management. The kernel implementation of ETW is done via the EtwTi functions, where Ti represents "threat intelligence".
The ntoskrnl.exe binary can be analyzed from within the IDA disassembler to find out where the EtwTi functions are called. The function being analyzed in this example is MiReadWriteVirtualMemory, which is called from within the NtReadVirtualMemory, NtWriteVirtualMemory, and NtReadVirtualMemoryEx syscalls.

The image below shows a snippet of MiReadWriteVirtualMemory from within IDA.

Notice how MiReadWriteVirtualMemory calls EtwTiLogReadWriteVm which logs read and write operations and is one of several EtwTi functions called from within the Windows kernel.

Additional EtwTi Functions
Searching for the EtwTi prefix in IDA will show other similar functions, as shown in the image below.

The name of the EtwTi function will generally indicate what's being logged. A few examples are provided below to further clarify this point.
EtwTiLogSetContextThreadThis function is called from thePspSetContextThreadInternalandPspWow64SetContextThreadkernel functions. ThisEtwTifunction is triggered when updating a thread's context.EtwTiLogSuspendResumeProcessThis function is called from multiple kernel functions, from which thePsMultiResumeProcessandPsSuspendProcessfunctions are the most interesting. ThisEtwTifunction is triggered when suspending or resuming a process.EtwTiLogAllocExecVmThis function is called from theMiAllocateVirtualMemorykernel function. ThisEtwTifunction is triggered when allocating executable memory.EtwTiLogProtectExecVmThis function is called from theNtProtectVirtualMemorysyscall (in the kernel). ThisEtwTifunction is triggered when updating memory permissions to executable.
Bypassing EtwTi Logging
Avoiding threat intelligence ETW logging from user-mode is not an easy task as it would generally require access from kernel mode. Later modules will address techniques for circumventing this form of ETW logging. However, it is strongly advised to review the Introduction to Threat Intelligence ETW and Uncovering Windows Events blog posts to gain a deeper understanding of threat intelligence ETW.
Conclusion
Having completed this module, one should have a fundamental understanding of ETW, including the functions and roles of each component. The subsequent module will focus on interacting with the ETW components using different tools.