When a program starts
Application Shimming: Custom Shim Database Persistence
How custom shim databases installed with sdbinst inject DLLs into or patch Windows programs at start, and how to find, read and remove a malicious one.
- MITRE ATT&CK
- T1546.011
- Tactics
- Persistence, Privilege escalation
- Runs
- When a program starts
- Set up by
- Administrators
- Locations
- HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\InstalledSDB
- HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Custom
- C:\Windows\AppPatch\Custom
- C:\Windows\AppPatch\Custom\Custom64
- HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
How it works
The Application Compatibility framework lets Windows run old programs without changing them. When a process starts, the loader checks the shim databases (.sdb files) for an entry that matches the program, by file name and by attributes such as version, size or company. On a match, it loads the shim engine into the new process, which applies the listed fixes before the program's own code runs. A fix (a "shim") might lie about the Windows version, redirect a file or registry path, or turn off a check.
Windows ships its own database, C:\Windows\AppPatch\sysmain.sdb. Administrators can add custom databases built with Compatibility Administrator, part of the Windows Assessment and Deployment Kit, and installed with sdbinst.exe, which is in System32. A custom database applies to every user and runs in the target process, as that process's account. Several fixes do much more than compatibility work:
| Fix | Effect |
|---|---|
InjectDll | Loads a DLL into the target at start |
RedirectEXE | Starts another program instead of the target, much like an IFEO debugger |
| In-memory patches | Rewrite the target's code in memory as it loads |
A database that patches or injects into a program started by SYSTEM, such as a service, runs as SYSTEM at each start of that program. Because the fix is applied by Windows' loader inside a signed program, the payload never appears as a process or autostart entry of its own.
Where it lives
sdbinst.exe copies the database to the AppPatch folder and registers it in two places, both under HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags:
| Location | What |
|---|---|
InstalledSDB\{GUID} | One key per database: DatabasePath, DatabaseDescription, DatabaseType, DatabaseInstallTimeStamp |
Custom\<program>.exe | One key per targeted file name, with a value named {GUID}.sdb for each database that applies to it |
C:\Windows\AppPatch\Custom\{GUID}.sdb | 32-bit databases |
C:\Windows\AppPatch\Custom\Custom64\{GUID}.sdb | 64-bit databases |
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{GUID}.sdb | An entry in Programs and Features, with an sdbinst -u uninstall string |
Writing any of these needs administrator rights; there is no per-user database. On a stock Windows 10 or 11 system, InstalledSDB and Custom are empty or absent. Some enterprise software and application compatibility projects install databases; outside those, any entry deserves a look. The registry is what makes a database apply: a .sdb file in a folder without its registration does nothing.
How attackers use it
Installing a database needs one command once the file exists:
sdbinst.exe -q C:\ProgramData\Microsoft\fix.sdb
The attacker builds a database that targets a program that runs all the time or at every boot, a service host or Explorer, with an InjectDll or RedirectEXE fix, or a patch. FIN7 used this: Mandiant described in 2017 a custom shim database that patched services.exe in memory so that it loaded a payload kept in the registry, giving SYSTEM execution at every boot with no service, task or Run key. Tools that list only services, tasks and Run keys show nothing.
To be less visible, attackers:
- give the database a description that looks like a vendor fix, since
DatabaseDescriptionis what shows in Programs and Features; - delete the Uninstall entry, or register the database by writing the
InstalledSDBandCustomkeys directly instead of runningsdbinst; - keep the payload in the registry or in the database itself, so no DLL appears on disk.
How to check a host
On a live machine:
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\InstalledSDB" /s
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Custom" /s
Get-ChildItem C:\Windows\AppPatch\Custom -Recurse -Force | Select-Object FullName, Length, CreationTime, LastWriteTime
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall' | Where-Object PSChildName -like '*.sdb'
For each database, note which programs it targets (Custom\<program>.exe) and read its content to see which fixes it applies. Windows has no built-in reader; the open-source python-sdb, for example, dumps a database as XML. An InjectDll or RedirectEXE fix, or a patch, on a system program is the finding; a WinXPSp3-style version lie on an old line-of-business application is not.
Offline, read the SOFTWARE hive at Microsoft\Windows NT\CurrentVersion\AppCompatFlags\InstalledSDB and Custom, and copy C:\Windows\AppPatch\Custom with its subfolder. DatabaseInstallTimeStamp and the keys' last-write times say when the database was installed; compare them with the creation time of the .sdb file and with Prefetch and Amcache records of sdbinst.exe. Process creation events (4688 with command-line auditing, Sysmon 1) show sdbinst.exe and its argument; Sysmon 13 shows the registry writes.
Suspicious: a database targeting services.exe, svchost.exe, explorer.exe, lsass.exe or another system process; a DatabasePath outside C:\Windows\AppPatch\Custom; a database with no Uninstall entry; one installed around the time of an intrusion with no software change to explain it.
What Windows Persistence flags
The tool reads the SOFTWARE hive. Each subkey of AppCompatFlags\InstalledSDB with a DatabasePath becomes an entry named after DatabaseDescription (or the GUID), with the database's path as its command. The details list the programs it applies to: the AppCompatFlags\Custom subkeys holding a value that starts with the database's GUID.
Every such entry raises Custom application shim installed: high when the database file is outside Windows' and Program Files' folders (in a user folder, most of ProgramData, or elsewhere), medium for a database in C:\Windows\AppPatch\Custom, where sdbinst puts it.
A value under Custom\<program>.exe that names a database InstalledSDB does not list becomes an entry of its own, named after the program and the value, with the same flag at medium. That is what an incomplete removal, or registry keys written by hand, leave behind. The path rules then run in their system-wide form: System-wide autostart from a writable folder, Runs from a temporary or public folder, Runs from a network share. Across mechanisms come Written date for a key written in the 7 days before the newest time in the collection, and Inside a Defender exclusion (path). Windows registers no custom database itself, so every entry of both kinds is flagged and the "Hide Windows entries" filter never hides one.
Limits: the tool does not read the .sdb file, so it cannot say which fixes a database applies or whether it injects anything; that is the next step for any entry. Changes to Windows' own sysmain.sdb are not reported. The compatibility modes users pick in a program's properties (AppCompatFlags\Layers) are not read; they change behaviour, not code.
Cleaning up
- Preserve: copy the
.sdbfile, exportInstalledSDB\{GUID}, theCustomkeys and the Uninstall entry withreg export, and hash the file. - Uninstall the database:
sdbinst.exe -u "C:\Windows\AppPatch\Custom\{GUID}.sdb". That removes the registration and the file. - If
sdbinstcannot do it, because the file is gone or the registration was written by hand, deleteInstalledSDB\{GUID}, every{GUID}.sdbvalue underCustom\<program>.exe(and the program's key when it is then empty), and the Uninstall entry. - Shims apply when a process starts: a patched process keeps running patched. Restart the targeted programs, or the machine when the target is a system process such as
services.exe.
Then deal with the payload: the injected DLL, the redirected program, or the registry value a patch loads code from. Installing a database needed administrator rights, so review how the attacker got them, and rotate credentials used on the machine.
See also
Related techniques
On Windows Forensics
The artifacts behind this technique, in the Windows Forensics reference: