今回は、SearchPathWのWINAPIにフックすることにします。
この場合、最も意味のある引数を取得したいと考えており、この場合は2番目の引数であるlpFileNameを取得します。必要であれば、残りのフィールドから情報を抽出することも可能です。
この例では、次のようなプログラムを使用しています。
c:/windowsのパスが存在するかどうかを確認するだけです。コンパイルして、アタッチしてみましょう。
アプリを再開するために「%resume」と入力すると、次のような出力が得られます
1 2 3 4 5 6 7 8 | DWORD SearchPathW( LPCWSTR lpPath, LPCWSTR lpFileName, LPCWSTR lpExtension, DWORD nBufferLength, LPWSTR lpBuffer, LPWSTR *lpFilePart ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // searchPathCpp.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <iostream> #include <Windows.h> int main() { TCHAR lpBuffer[MAX_PATH]; LPWSTR *lpFilePart{}; DWORD result; result = SearchPath(NULL, L"c:\\windows\\", NULL, MAX_PATH, lpBuffer, lpFilePart); std::cout << "SearchPath retval: " << result; } |
frida -f searchPathCpp.exe
[Local::searchPathCpp.exe]-> searchPathPtr = Module.getExportByName("KERNELBASE.DLL", "SearchPathW")
"0x76fc02f0"
[Local::searchPathCpp.exe]-> Interceptor.attach(searchPathPtr, { onEnter: function (args) { console.log(args[1].readUtf
16String()); } })
{}
[Local::searchPathCpp.exe]-> %resume
順を追って説明します。
KERNELBASE.DLLのSearchPathWのポインタを取り出す
[Local::searchPathCpp.exe]-> searchPathPtr = Module.getExportByName("KERNELBASE.DLL", "SearchPathW")
"0x76fc02f0"
InterceptorのonEnterフックを入力する
1 2 3 4 5 | Interceptor.attach(searchPathPtr, { onEnter: function (args) { console.log(args[1].readUtf16String()); } }); |
[Local::searchPathCpp.exe]-> %resume
Search
Path retval: 11c:\windows\
他に質問があれば、Twitterで @entdark_ に連絡してください。
0 件のコメント:
コメントを投稿