Shims For The Win: Case study and investigative techniques for hijacked Application Compatibility Infrastructure
Willi Ballenthin (Malware Analyst · FireEye), Jon Tomczak (Professional Services · Mandiant)
BruCON 0x07 · Day 2
Overview
In this BruCON presentation, Willi Ballenthin and Jon Tomczak deliver a deep dive into the Application Compatibility Infrastructure (ACI) of Windows, commonly known as shims, and reveal how this often-overlooked feature is being exploited by attackers for persistence, evasion, and stealthy code injection. The talk is a critical exploration of an advanced technique that allows malware to bypass traditional security controls and remain hidden on compromised systems, providing a stark warning to defenders about an emerging threat vector.

Key moments
- 2:27 Malware evading sandbox using application compatibility shims
- 4:40 What are Application Compatibility Shims?
- 13:00 Malicious capabilities: disabling Defender, path redirection, registry
- 22:00 Malware injecting raw shellcode into processes via shims
- 34:00 Shim detection challenges: no central management or verification
- 42:00 Proposed detection: domain-specific hashing of shim entries
- 43:00 Advanced threat: injecting malicious shims into cismain.sdb
Shims For The Win: Case study and investigative techniques for hijacked Application Compatibility Infrastructure
Speakers: Willi Ballenthin (Malware Analyst, FireEye); Jon Tomczak (Professional Services, Mandiant)
Conference: BruCON
YouTube: https://www.youtube.com/watch?v=wQEnUISOZPI
Overview
In this BruCON presentation, Willi Ballenthin and Jon Tomczak deliver a deep dive into the Application Compatibility Infrastructure (ACI) of Windows, commonly known as shims, and reveal how this often-overlooked feature is being exploited by attackers for persistence, evasion, and stealthy code injection. The talk is a critical exploration of an advanced technique that allows malware to bypass traditional security controls and remain hidden on compromised systems, providing a stark warning to defenders about an emerging threat vector.
The motivation for their research stemmed from a real-world incident at FireEye/Mandiant, where sophisticated malware was evading detection by their security products. Despite significant investment in security solutions, a client's systems were compromised by spear-phishing emails delivering persistent malware. Upon deeper analysis, Ballenthin discovered that the malware was leveraging the ACI to maintain its foothold, a technique that was not only novel to the security team but also incredibly difficult to detect using existing methodologies.
This presentation matters immensely to the security community because it exposes a gap in defensive strategies. Shims, originally designed by Microsoft to ensure backward compatibility for applications across different Windows versions, offer powerful capabilities that, in the wrong hands, become potent tools for bypassing code signing, injecting malicious DLLs, and even directly patching memory. Ballenthin and Tomczak not only dissect the technical intricacies of shim-based attacks but also propose new investigative techniques and detection methodologies necessary to counter this insidious form of compromise.
Background
▶ Watch: Malware evading sandbox using application compatibility shims (2:27)
The Application Compatibility Infrastructure (ACI), at its core, is Windows' ingenious solution to a persistent problem: ensuring older applications continue to function correctly on newer operating system versions. As Windows evolves, API behaviors, file paths, and system configurations change, which could break applications compiled for previous versions. To avoid forcing developers to recompile their software for every new OS release, Microsoft introduced shims. These are small, pre-configured fixes that can modify how an application interacts with the operating system's APIs at runtime, without altering the application's original binary.
Shims operate by hooking into the Windows API. When an application is launched, the Windows loader checks if any shims are registered for it. If so, these shims intercept specific API calls, redirecting them or modifying their behavior as defined by the shim's configuration. This allows for a wide array of "fixes," such as emulating older file system structures for vintage games like Oregon Trail, or ensuring Microsoft Office applications remain stable across updates. Microsoft itself heavily uses shims, often delivering them through Windows updates to address vulnerabilities or compatibility issues in common applications. The talk also highlights that security solutions like EMET (Enhanced Mitigation Experience Toolkit) leverage this infrastructure to inject their DLLs into processes, enabling runtime mitigations against exploitation.
Shims are stored in binary databases called SDB files (Shim Database files) on the file system. Each shim entry within an SDB file specifies the target application using criteria like filename, PE checksum, file size, and version information. It then defines one or more of the 407 available preconfigured fixes to apply. These SDB files are installed and registered with the operating system, typically via the Application Compatibility Toolkit (ACT), a free tool provided by Microsoft. ACT allows developers to create custom shims and package them for deployment, often integrated into MSI installers or pushed via Group Policy. Once installed, shims are registered in specific registry keys (e.g., HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Custom\ and \InstalledSDB\), which the OS references to determine which shims to load for executing applications. The App Compat Cache, a well-known forensic artifact, is actually a performance optimization of this very infrastructure, allowing the system to quickly decide if a program needs shimming. While legitimate deployment usually involves ACT and structured installations, attackers can directly manipulate these registry values to install their malicious shims, bypassing standard controls.
Key Findings
▶ Watch: Malicious capabilities: disabling Defender, path redirection, registry (13:00)
The core discovery presented in this talk is that the powerful, legitimate capabilities of the Application Compatibility Infrastructure are being actively and maliciously leveraged by sophisticated attackers. Ballenthin and Tomczak categorize the malicious uses into several key areas, demonstrating how shims provide unparalleled opportunities for persistence, evasion, and covert operations.
Attackers can exploit a wide array of shim fixes for malicious purposes:
- Disable Windows Defender: A direct fix exists to turn off Windows Defender for a targeted application, potentially allowing malware to run unimpeded.
- Correct File Paths: This shim can redirect file system operations. As demonstrated by Jon Tomczak, an attacker can configure a shim to redirect a legitimate program's attempt to launch
executable_Ato instead launchmalicious_executable_B. This can be used for hidden persistence or man-in-the-middle attacks on process creation. - Redirect File System Reads/Writes: Attackers can use shims to divert file system activity, effectively creating a userland rootkit. Mark Bagot's DerbyCon presentation from two years prior (referenced by Ballenthin) demonstrated how this could hide files from antivirus solutions.
- Change DLL Search Paths: Shims can modify the directories
LoadLibraryuses to find DLLs, creating new load order hijacking vulnerabilities or exploiting existing ones more effectively. - No Signature Check: Though undocumented, this shim likely bypasses signature verification during DLL loading, offering a potent way to run unsigned malicious code in signed processes.
- Terminate Process on Execution: This fix can immediately kill a targeted process upon launch. An attacker could use this to frustrate defenders by automatically terminating tools like Process Explorer or other triage utilities.
- Virtual Registry: This allows redirecting registry reads and writes to different locations in the hive. An attacker could, for example, redirect
Kaspersky.exe's attempts to read persistence keys (CurrentVersion\Run) to a benign location, effectively hiding their malware from the AV.
The speakers detailed three compelling case studies to illustrate these findings:
- Core Plug and DLL Injection: The initial incident that sparked the research involved the Core Plug malware family, typically associated with Chinese threat actors. This malware used shims to inject
e-logger.dll(a backdoor) intosvchost.exe. The malware was delivered as a self-extracting RAR, which dropped files and executed a legitimate, vulnerable program that then loaded the malicious DLL through load order hijacking. The shim ensured that every timesvchost.exestarted, the malicious DLL was loaded. The key finding here was the extreme stealth: investigators examiningsvchost.exe's memory space would see the malicious DLL but find no evidence of code injection on disk, as the shim definition was hidden in an opaque binary SDB file registered in an obscure registry key. The reuse of database IDs across different victims also allowed FireEye to track a large campaign.
- Custom File Path Redirection (Demo): Jon Tomczak demonstrated the simplicity of creating a malicious shim. Using the Application Compatibility Toolkit, he created an SDB file that, when applied to
mine.exe, used the Correct File Path fix to redirect its execution tocdump1.exe. This process took approximately 30 seconds to build and deploy. This example highlighted the ease with which attackers can subvert application behavior, potentially modifyingcommand.exeor creating hidden persistence mechanisms that lead to DFIR confusion during investigations.
- Mamba Shim and Direct Memory Patching: A commodity malware family,
Mamba Shim(detected by Symantec), provided the most technically advanced example. This Python-based malware, using thectypesmodule to interact with the native Windows API, dynamically created and installed SDB files. Instead of DLL injection, Mamba Shim used the undocumented Patch Bits shim mechanism to directly patch shellcode into the memory of targeted executables, specificallyopera.exeandkernel32.dll. This shellcode was obfuscated within the SDB file, not present on disk, making detection extremely difficult. The malware even generated unique database IDs for each installation, further hindering blacklist-based detection. The ability to patch raw binary data into memory at specific offsets, verified by matching existing bytes to avoid corruption, represents a sophisticated method for runtime code injection and highly evasive backdoors.
Technical Deep Dive
▶ Watch: Malware injecting raw shellcode into processes via shims (22:00)
The technical core of shim-based attacks lies in the structure and manipulation of SDB files and the powerful, yet often undocumented, shim fixes they contain. Ballenthin describes an SDB file as conceptually an indexed XML document, despite its opaque binary format. It comprises three main nodes: an index, the database structure itself, and a string table. Crucially, there is no compression, no encryption, and no checksums protecting the integrity of the data within SDB files, which simplifies parsing for analysis but also means attackers face fewer hurdles in crafting malicious versions.
Parsing these binary SDB files is a significant challenge. While Windows exposes 254 exports in apphelp.dll for manipulating shims, relying on these routines for analysis is problematic. They are platform-dependent (Windows-only) and may interpret or "patch up" data, obscuring the raw information. To overcome this, Willi Ballenthin developed a Python SDB parser (available on his GitHub), enabling cross-platform analysis and ensuring that the raw, unadulterated data from the shim databases can be extracted and understood.
The Patch Bits mechanism, as seen in the Mamba Shim malware, represents a particularly sophisticated form of shim abuse. This feature allows an SDB file to define raw binary data that gets patched directly into a target process's memory at specific locations. The process involves:
- Matching Bits: Before patching, the shim can verify a sequence of bytes at the target memory address. This ensures that the patch only applies to expected versions of software and doesn't corrupt unintended memory regions, making memory patching a robust and precise operation.
- Patching Bits: Once the match is confirmed, the defined raw binary data (shellcode) is written into memory. This can target both EXEs and DLLs.
- Hooking
kernel32.dll: In the Mamba Shim example, the malware targetedkernel32.dll, a fundamental Windows library. It specifically utilized "hot-patching"NOP(No Operation) instructions found in function prologues and slack space (unused portions) within the binary. TheseNOPs are legitimate padding added by Microsoft to allow for future updates without recompiling the entire function. - Trampoline Injection: The malware replaced these
NOPs with aJMPinstruction to a custom trampoline (a small piece of assembly code). This trampoline saves the current CPU context, then calls the main malicious shellcode payload. After the shellcode executes (e.g., reaching out to the internet to download additional backdoors), the trampoline restores the context and returns execution to the originalkernel32.dllfunction, allowing it to complete its legitimate operations. This technique ensures stealth and stability, as the legitimate program continues to run normally, while the malicious payload executes covertly.
The result is a highly evasive form of code injection. The malicious shellcode exists only in memory, is split across different sections of the SDB file, and is never present on disk in an easily scannable format. This makes traditional disk-based forensic analysis and signature scanning for hashes ineffective, forcing defenders to confront complex in-memory analysis challenges.
Demo / Proof of Concept
▶ Watch: Proposed detection: domain-specific hashing of shim entries (42:00)
While the talk did not feature a live, dedicated "demo" section as a separate segment, Jon Tomczak provided a clear and concise explanation of a proof-of-concept he implemented in the lab, demonstrating the Correct File Path shim fix. This practical example illustrated the ease and speed with which an attacker could weaponize the Application Compatibility Infrastructure.
Tomczak described creating a custom shim database, mine.SDB, using the free Application Compatibility Toolkit provided by Microsoft. Within this toolkit, he selected the "Correct File Path" fix. This fix allows an administrator (or attacker) to redirect a specific argument or file path used by a target application to an entirely different location or executable. In his demonstration, he configured the shim so that whenever mine.exe attempted to call a particular executable, the shim would intercept this API call and redirect it to cdump1.exe instead.
The significance of this demonstration lies in its simplicity and the speed of deployment—Tomczak noted it took approximately 30 seconds to build and deploy such a shim database. This highlights the low barrier to entry for attackers to start leveraging these techniques. The implications are far-reaching: an attacker could, for example, redirect calls to cmd.exe or powershell.exe to a malicious version or intermediary, effectively man-in-the-middling system administration actions. This capability introduces significant DFIR confusion, as defenders might observe legitimate processes behaving maliciously without clear on-disk indicators, leading to wasted time and resources during incident response.
The demo underscored the broader point that the Application Compatibility Toolkit, designed for legitimate software compatibility, provides all the necessary functionality for malicious actors to craft sophisticated and stealthy attacks. The SDBInstall utility, which is part of the toolkit, facilitates the installation of these custom SDB files, automatically creating the necessary registry entries for persistence and even an uninstall entry in the Control Panel (which attackers can easily circumvent by direct registry manipulation).
Defensive Implications
▶ Watch: Advanced threat: injecting malicious shims into cismain.sdb (43:00)
The detailed analysis of shim-based attacks reveals significant challenges for defenders, primarily due to the inherent design of the Application Compatibility Infrastructure and the lack of robust security controls around it.
Lack of Centralized Management and Verification:
- No Central Management: There is no built-in Windows mechanism or Active Directory tool for centrally managing or auditing deployed SDB files across an enterprise. Each system's shim database can be unique, depending on installed software and update history.
- No Audit or Rollback: There's no native accounting of changes to shim databases or easy rollback features, making it difficult to detect unauthorized modifications or recover from malicious deployments.
- No Signature Verification: Crucially, Microsoft does not verify signatures when loading SDB files or applying shims. If an attacker gains administrative rights to a system, they can install any shim, and it will execute without further integrity checks. This is a critical security blind spot.
- Unique SDB Files: SDB files cannot be simply hashed and whitelisted because they contain unique metadata (timestamps, installation order, database IDs) that make each file largely unique to a specific system, even if the underlying shim definitions are similar.
Detection Challenges and Proposed Methodologies:
- Weak Indicators: The most basic indicator, the execution of
sdbinst.exe(the shim installation utility), is often too generic or easily bypassed by direct registry manipulation (as seen in Mamba Shim usingctypes). - Acquiring and Analyzing SDBs: SDB files can range from 50MB to 120MB per system, making large-scale collection and analysis resource-intensive. Legitimate SDBs are typically found in
Program FilesorWindows\AppPatch, while malicious ones are often dropped in user profile directories (e.g.,%USERPROFILE%), providing a potential "sore thumb" indicator. - Registry Key Inspection: Manually inspecting the
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Custom\and\InstalledSDB\registry keys can reveal registered shims, but this is not scalable for enterprise-wide detection. - Heuristics for Commodity Malware: For less sophisticated attacks like Mamba Shim, basic heuristics can work. For instance, Mamba Shim used random numbers for SDB file creation timestamps and compiler versions. Detecting SDBs with nonsensical or out-of-range timestamps (e.g., not within the last 10 years) could flag malicious activity. However, more advanced attackers would easily bypass such simple checks.
- Event Log Analysis: The
App Experience Program Telemetryevent log records when compatibility fixes are applied. While useful, the sheer volume of legitimate entries (for Office, Outlook, etc.) makes it challenging to identify malicious outliers. Ballenthin mentioned this as a potential, albeit distant, application for machine learning to detect anomalies.
Domain-Specific Hashing (A Promising Solution):
Given the limitations of traditional hashing and the uniqueness of full SDB files, the speakers propose domain-specific hashing. Instead of hashing entire SDB files, the approach focuses on hashing individual entries or definitions within those databases. Microsoft distributes approximately 410 default shims, applicable to thousands of programs, and these definitions are relatively stable across Windows versions.
- Community Whitelisting: By parsing SDB files and hashing their individual shim definitions, a community whitelist of known-good shim entries can be built.
- Anomaly Detection: Defenders could then compare the hashes of shim entries found on their systems against this whitelist. Any entry with an unknown hash would warrant further investigation.
- Challenges: This approach requires robust SDB parsing tools that can operate at scale across an entire environment and a continuous effort to update whitelists with every "Patch Tuesday" or new software release.
The "Scary Scenario":
The ultimate threat discussed is an attacker repackaging sysmain.sdb (the main system SDB) after injecting a custom shim for a critical process like explorer.exe with a shellcode payload (e.g., a keylogger). Deploying such a modified sysmain.sdb would be extremely difficult to detect, as it would blend seamlessly with legitimate system files, leveraging the unchecked nature of shims. This highlights the need for proactive research and tool development, as current capabilities leave defenders vulnerable to sophisticated shim-based attacks.
Key Takeaways
- Shims are a Powerful Attack Vector: Application Compatibility Shims, a core Windows feature, are being actively exploited by attackers for persistence, evasion, and stealthy code injection, often bypassing traditional security controls.
- Evasive Techniques: Shims enable sophisticated techniques like DLL injection into critical processes (
svchost.exe), file path redirection, and direct memory patching (Patch Bitsintokernel32.dll), making on-disk detection and traditional forensic analysis extremely challenging. - Lack of Security Controls: Microsoft's Application Compatibility Infrastructure lacks central management tools, signature verification for SDB files, and robust auditing, creating significant blind spots for defenders. Administrative privileges are sufficient to install persistent, unchecked shims.
- Traditional Detection Fails: Standard hashing and whitelisting of SDB files are ineffective due to the inherent uniqueness of SDB files across systems. Event log analysis is hampered by the high volume of legitimate shim activity.
- Proactive Defense is Crucial: Defenders need to develop new methodologies, such as domain-specific hashing of individual shim entries, and custom SDB parsing tools to build effective whitelists and detect malicious activity at scale.
- An Emerging Threat: While some shim-based attacks are currently detectable with basic heuristics, more sophisticated attackers will quickly adapt, requiring the security community to rapidly advance its understanding and tooling to prevent widespread compromise.
About the Speaker(s)
Willi Ballenthin is a Malware Analyst at FireEye, based in the DC area. Prior to his role at FireEye, he spent approximately five years at Mandiant, where he initially focused on incident response and computer forensics. In recent years, his work has primarily shifted to deep-dive malware analysis, spending late nights dissecting binaries with tools like IDA Pro. His expertise lies in understanding complex malware behaviors and developing new investigative techniques.
Jon Tomczak is part of the Professional Services team at Mandiant, specializing in incident response (IR) and forensics. Before joining Mandiant, Jon ran TZ Works with his father, where he was involved in building forensic tools. He also has a background in attempting to be a game developer. His work at Mandiant involves exploring new tools and techniques, including the intricacies of Windows application compatibility shims.