Detect Thread Local Storage in Microsoft Sentinel
Adversaries may inject malicious code into processes via thread local storage (TLS) callbacks in order to evade process-based defenses as well as possibly elevate privileges. TLS callback injection involves manipulating pointers inside a portable executable (PE) to redirect a process to malicious code before reaching the code's legitimate entry point. TLS callbacks are normally used by the OS to setup and/or cleanup data used by threads. Manipulating TLS callbacks may be performed by allocating and writing to specific offsets within a process' memory space using other Process Injection techniques such as Process Hollowing.
MITRE ATT&CK
- Technique
- T1055 Process Injection
- Sub-technique
- T1055.005 Thread Local Storage
- Canonical reference
- https://attack.mitre.org/techniques/T1055/005/
KQL Detection Query
// Detect TLS callback abuse indicators
// TLS callbacks execute before the main entry point - look for suspicious process behavior
// immediately after creation (network connections, file writes before expected initialization)
DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName in~ ("svchost.exe", "rundll32.exe", "regsvr32.exe", "dllhost.exe", "explorer.exe")
| where InitiatingProcessFileName !in~ ("services.exe", "svchost.exe", "explorer.exe", "winlogon.exe")
| join kind=inner (
DeviceNetworkEvents
| where Timestamp > ago(24h)
| where RemoteIPType == "Public"
| project NetTime=Timestamp, DeviceName, InitiatingProcessId, RemoteIP, RemotePort, RemoteUrl
) on DeviceName, $left.ProcessId == $right.InitiatingProcessId
| where datetime_diff('second', NetTime, Timestamp) between (0 .. 5)
| project Timestamp, NetTime, DeviceName, AccountName, InitiatingProcessFileName, FileName, RemoteIP, RemotePort, RemoteUrl
| sort by Timestamp desc Detects potential TLS callback injection by identifying system processes that establish outbound network connections within seconds of creation — indicating code execution before the expected initialization sequence. TLS callbacks execute before the entry point, so malicious callbacks often perform C2 communication before the legitimate process has time to initialize normally. This is a behavioral detection since TLS callbacks themselves are not directly logged by standard telemetry.
Data Sources
Required Tables
False Positives & Tuning
- Legitimate software with TLS callbacks for license verification or telemetry on startup
- Auto-update mechanisms that check for updates immediately on process start
- Browser processes establishing connections to configured home pages immediately on launch
- Cloud-connected applications that authenticate on startup
Other platforms for T1055.005
Testing Methodology
Validate this detection against 3 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.
- Test 1PE with TLS Callback - Compile and Execute
Expected signal: Sysmon Event ID 1: PowerShell execution. In a real TLS callback binary: execution trace would show TLS callback function executing before the PE entry point. Debuggers (x64dbg, WinDbg) would show the TLS callback break before OEP.
- Test 2Ursnif-style TLS Callback Chain Analysis
Expected signal: Sysmon Event ID 1: PowerShell reading PE headers of notepad.exe. Sysmon Event ID 11: No file creation (read-only operation). This is a defensive analysis technique, not an attack.
- Test 3Process Hollowing with TLS Callback Redirection
Expected signal: Sysmon Event ID 1: notepad.exe spawned by PowerShell. When using full technique: Sysmon Event ID 10 (ProcessAccess) with PROCESS_VM_WRITE rights, followed by process resume and immediate malicious activity before expected notepad initialization.
References (4)
- https://attack.mitre.org/techniques/T1055/005/
- https://www.fireeye.com/blog/threat-research/2017/11/ursnif-variant-malicious-tls-callback-technique.html
- https://www.endgame.com/blog/technical-blog/ten-process-injection-techniques-technical-survey-common-and-trending-process
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1055.005/T1055.005.md
Unlock Pro Content
Get the full detection package for T1055.005 including response playbook, investigation guide, and atomic red team tests.