Skip to main content
Mallory
← Back to News
persistence-methoddefense-evasion-methodpayload-delivery-evasion

Windows PE TLS Callbacks Execute Code Before the Program Entry Point

Attack Tradecraft · 4 sources · Updated 3mo ago · First seen Sep 5, 2026

Windows PE TLS Callbacks Execute Code Before the Program Entry Point

A Windows PE demonstration shows that Thread Local Storage (TLS) callbacks execute during process initialization before the executable entry point and C main. MinGW-w64 callback pointers placed in .CRT$XLB and .CRT$XLBB invoke two callbacks in order, producing 12 when both return normally. The first example ran raw x64 MessageBox payload through EnumDesktopsA, but its thread-exit behavior could end the initializing thread before the second callback and main executed; a revised payload restored the stack and returned normally, allowing initialization to complete.

TLS callbacks are legitimate PE and runtime infrastructure, but they can conceal behavior from analysts who begin debugging only at main. Defenders should inspect the PE TLS directory and callback-address array, then assess the callback code and its execution effects rather than treating TLS callback presence alone as malicious. Because this code runs amid loader initialization, unsafe operations and synchronization can also cause deadlocks or crashes under the loader lock; Microsoft recommends deferring complex initialization outside loader-managed entry paths.

Who uses this technique?Get the actors, campaigns, and ATT&CK mapping behind it.
Get the tradecraft
Event timeline

How this story unfolded

Events from the most recent confirmed update back to the earliest known activity.

3 events
  1. Reported Sep 5, 20263mo ago

    Revised TLS callback payload permits normal initialization

    A revised hack3 TLS-callback example resolved MessageBoxA through GetModuleHandleA and GetProcAddress, passed it to a callback-compatible EnumDesktopsA payload, and returned normally after displaying its dialog. This allowed the second TLS callback and main to execute, unlike the earlier thread-exiting payload path.

    Malware development trick 66: TLS callbacks before main. Simple C example - Malware Analysis - Malware Analysis, News and Indicators
  2. Reported Sep 5, 20263mo ago

    TLS callback execution before main demonstrated

    A MinGW-w64 PE experiment registered two TLS callbacks in .CRT$XLB and .CRT$XLBB, demonstrating that they run on the initializing thread before the normal entry-point and C main path; when both return normally, their recorded order is 12. The material also showed that an initial raw payload invoked from a callback could exit the initializing thread and prevent later callback and main execution.

    Malware development trick 66: TLS callbacks before main. Simple C example - Malware Analysis - Malware Analysis, News and Indicators
  3. Reported Aug 25, 20263mo ago

    PE binary-padding and overlay techniques demonstrated

    An educational Windows PE experiment showed two ways to add 16 MiB without changing a program's primary MessageBox behavior: an initialized .bloat section and a post-section overlay of repeated bytes. The material described structural, signature, entropy, and context-based checks for investigating such padding rather than treating file size as malicious by itself.

    Malware development trick 64: PE file bloating and overlay data. Simple C example - cocomelonc
Linked entities

Related entities

Vulnerabilities, threat actors, malware, products, organizations, and breaches Mallory has linked to this story.

Open in app →

Affected products

1 linked
Windows
Do you run this?Get the adversaries, campaigns, and ATT&CK mapping behind this technique, with detections ready to deploy.
See Who Uses This Technique
Mallory platform

See the full picture, correlated to your attack surface.

This page covers what’s public. Mallory adds the parts that aren’t: which of your assets are affected, which threat actors are using it right now, and what to deploy next.

Exposure mappingMap indicators from this story to your assets and identify affected systems in minutes.
Threat actor evidenceEvery observed campaign, victim, and pivot linked to actors named in this story.
Associated malwareMalware, exploits, and IOCs connected to the activity described here.
Detection signaturesYARA, Sigma, and Snort rules deployed to your SIEM as soon as they’re published.
Scheduled alertsGet matching new stories delivered to your team as they break, not the next morning.
AI threadsAsk questions about this story and take action on the answers.