The Microsoft Windows Application Compatibility Infrastructure/Framework (Application Shim) was created to allow for backward compatibility of software as the operating system codebase changes over time. For example, the application shimming feature allows developers to apply fixes to applications (without rewriting code) that were created for Windows XP so that it will work with Windows 10. (Citation: Elastic Process Injection July 2017) Within the framework, shims are created to act as a buffer between the program (or more specifically, the Import Address Table) and the Windows OS. When a program is executed, the shim cache is referenced to determine if the program requires the use of the shim database (.sdb). If so, the shim database uses Hooking to redirect the code as necessary in order to communicate with the OS.
A list of all shims currently installed by the default Windows installer (sdbinst.exe) is kept in:
%WINDIR%\AppPatch\sysmain.sdbhklm\software\microsoft\windows nt\currentversion\appcompatflags\installedsdbCustom databases are stored in:
%WINDIR%\AppPatch\custom & %WINDIR%\AppPatch\AppPatch64\Customhklm\software\microsoft\windows nt\currentversion\appcompatflags\customTo keep shims secure, Windows designed them to run in user mode so they cannot modify the kernel and you must have administrator privileges to install a shim. However, certain shims can be used to Bypass User Account Control (UAC) (RedirectEXE), inject DLLs into processes (InjectDLL), disable Data Execution Prevention (DisableNX) and Structure Exception Handling (DisableSEH), and intercept memory addresses (GetProcAddress). Similar to Hooking, utilizing these shims may allow an adversary to perform several malicious acts such as elevate privileges, install backdoors, disable defenses like Windows Defender, etc.
T1138は「Application Shimming(アプリケーション・シミング)」として定義されていた、Windowsの互換性維持機能を逆手に取った高度な攻撃手法です。
Windowsが古いソフトウェアを新しいOSでも動かせるように用意している「互換性スタック(Shim)」という仕組みを悪用し、特定のアプリケーションが起動した際にマルウェア(DLL)を自動的にプロセスインジェクション(強制注入)させる手法です。主に「永続化(Persistence)」と「防御回避(Defense Evasion)」に利用されます。
Windowsにおける「Shim(詰め木・隙間テープの意味)」とは、OSのバージョンアップによって動かなくなった古いアプリを、ソースコードを書き換えることなく動かすための救済システムです。
たとえば、Windows XP向けに作られた古い業務アプリをWindows 11で動かす際、Windowsがそのアプリと最新OSの「仲介役」となり、アプリからの古い命令(API呼び出し)を最新の命令に裏で変換してあげます。この仲介設定をまとめたデータベースファイルを .sdb (Shim Database) と呼びます。
攻撃者は、この「裏で命令をパッと書き換えて中継する」というShimの強力な挙動(フッキング機能)を、そのままマルウェアの起動に悪用します。
カスタムのShimデータベースをシステムに登録・適用するため、攻撃者は事前にシステム内での管理者権限(Administrator)を確保している必要があります。
悪意のあるShimの作成:
攻撃者はマイクロソフト公式の検証ツール(Application Compatibility Toolkit)などを使い、独自の .sdb ファイルを作成します。
iexplore.exe(Internet Explorer)や notepad.exe(メモ帳)が起動した時、特定のマルウェアDLLをそのメモリに注入(インジェクション)して実行する」というルールを仕込みます。データベースの登録:
Windows標準のコマンドである sdbinst.exe(Shimデータベースインストーラー)を悪用して、作成した .sdb ファイルをシステムにインストールします。
sdbinst.exe evil_shim.sdbレジストリへの自動反映:
このコマンドが実行されると、Windowsは自動的に以下のレジストリキーにShimの情報を登録します。
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Custom自動実行と隠蔽:
次回、ユーザーやシステムがターゲットにされた正規のアプリ(メモ帳など)を起動した瞬間、OSはShimデータベースに従い、アプリの起動と同時にマルウェアのDLLをそのプロセスの内部で強制実行させます。
「インストールコマンドの監視」と「レジストリのチェック」が非常に効果的です。
sdbinst.exeのプロセス監視(最重要):
通常の業務環境で、一般ユーザーやプロセスが sdbinst.exe コマンドラインを実行することはまずありません。SIEMやEDRでこのコマンドの実行履歴(特に引数に不審な .sdb ファイルが含まれていないか)を常時監視・アラート化します。
レジストリの監視:
カスタムShimが登録される以下のレジストリキーを監視します。
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\InstalledSDB
Autoruns の「App Compat」タブを確認することで、現在システムにインストールされているカスタムShimの一覧をひと目で確認・削除できます。極めて高い「防御回避(ステルス性)」:
マルウェアが独立したプロセスとして起動しないため、タスクマネージャーを見ても「ただメモ帳(notepad.exe)が動いている」ようにしか見えません。また、実行ファイル自体を改ざんするわけではないため、ファイルの整合性チェック(FIM)もすり抜けます。
UAC(ユーザーアカウント制御)のバイパス:
悪用するShimのタイプによっては、特定のプログラムが起動する際のセキュリティ制限(UACプロンプト)を自動で承認・バイパスさせるように設定することも可能です。
CWE-15: External Control of System or Configuration Setting:
システムの互換性設定(Shimデータベース)を外部から不正に変更されてしまう不備。
CWE-427: Uncontrolled Search Path Element:
アプリ起動時に読み込まれるコンポーネントの指定方法が適切に制御されていない問題。
OSの高度な正規機能をディープに悪用するため、サイバースパイ活動を行う国家系の組織が好む傾向にあります。
FinFisher (FinSpy) / Gazer:
高度な政府向け監視マルウェアや、APT29(Cozy Bear)が関与するとされるマルウェア「Gazer」では、セキュリティ製品の「プロセス監視」の目をかいくぐってバックドアを永続化させるために、このApplication Shimming(T1138 / T1546.011)を利用してシステムに深く潜伏する手口が確認されています。
Metasploit:
ペネトレーションテスト用フレームワークには、管理者権限を取得した後のUACバイパスや永続化を検証するためのモジュールとして、悪意あるSDBファイルを自動生成・インプットする機能が実装されています。
もしEDRなどで「プロセス sdbinst.exe が急に実行された」というアラートを検知した場合、それは「攻撃者がすでに管理者権限を持っており、最後の潜伏・永続化の罠を仕掛けた最終段階」である可能性が極めて高いです。即座にその端末を隔離し、インストールされた .sdb ファイルのタイムスタンプから前後に実行された不正なファイルを追跡してください。