任意の Windows Search SQL のSELECT文を実行するために以前は C# のサンプルをコンパイルしてました。
Windows検索インデックスに直接SQLを投げてあげましょう
このサンプルは更新されてないので、Powershell のスクリプトでも十分であろうと思い乗り換えることにしました。
いくつか候補はありましたが以下からコードをコピーしました。
index is stored in a SQL database and the following script shows how to connect and search using PowerShell,
Using built-in OS indexing features for credential hunting · Embrace The Red
内容を少し削ったりして以下になりました。
$ grep -v '^ *#' /mnt/c/kinoue/misc/Invoke-WindowsSearch.ps1 function Invoke-WindowsSearch { param ( [Parameter()][string] $query = "select system.itempathdisplay from systemindex where contains('password')" ) $provider = "Provider=Search.CollatorDSO.1;Extended?PROPERTIES='Application=Windows'" $adapter = new-object System.Data.OleDb.OleDBDataAdapter -Argument $query, $provider $results = new-object System.Data.DataSet $adapter.Fill($results) $results.Tables } Invoke-WindowsSearch $args[0]
この powerpoint ファイルが検索で見つかるか試します。
$ powershell.exe -NoProfile -NoLogo -ExecutionPolicy Bypass \ $(wslpath -w /mnt/c/kinoue/misc/)\\Invoke-WindowsSearch.ps1 \ '"select system.itempathdisplay from systemindex where contains('\''""Dynatrace University login"" AND ""Application Security"" AND ""Synthetic Monitor""'\'')"' 1 SYSTEM.ITEMPATHDISPLAY ---------------------- C:\Users\katsumi.inoue\OneDrive - Dynatrace\Documents\dynatrace_0.pptx
見事瞬時に pptx ファイルがヒットしました!