Code Injectionの解析に関するメモ

CreateProcess => WriteProcessMemory

  • Injectionの手順例

CreateProcessA (Suspend)
NtUnmapViewOfSection
VirtualAllocEx
WriteProcessMemory

  • 作成したプロセスのEntryPoint変更

GetThreadContext(スレッドハンドラ、コンテキスト格納場所のアドレス)
[コンテキスト格納場所のアドレス + 0xB0] = 新しいEntry Point
SetThreadContext(スレッドハンドラ、コンテキスト格納場所のアドレス)
ResumeThread
[参考ページ Open RCE Unpacked RESOLVED:http://www.openrce.org/forums/posts/2134]

  • Injectされたプロセスの解析
    • Processへのattach
      • 新しいEPに書き込まれたコードを逆算

例: Modified EP=0x40EE60
WriteProcessMemory To:0x401000 Size:0xE000 (From: 0x16A740)
0x40EE60 - 0x401000 = 0xDE60
0x16A740 + 0xDE60 = 0x1785A0

      • 書き換え 0x51(PUSH ECX) => 0xCC(INT 3)

HeapAlloc => CreateRemoteThread

  • Injectionの手順

GetCurrentProcessId (自分自身に対しては何もしない)
OpenProcess (プロセスを開けるまで巡回)
OpenProcessToken
GetTokenInformation
GetLastWin32Error
RtlAllocateHeap
GetTokenInformation
EqualSid
FreeHeap
VirtualAllocEx
RtlAllocateHeap
WriteProcessMemory (4044E5)
RtlFreeHeap
CreateRemoteThread (40386C)
など

  • Injectされたコードの解析
    • 例)

WriteProcessMemory from: 150E60 To:0x5CC0000 Size:0x19000
CreateRemoteThread スレッド関数の開始アドレス: 0x5CCED50
フックを仕込む場所: 150E60 + 0xED50 = 0x15FBB0

    • Injectされた対象をhook
    • Memory Dump => IDAで静的解析

ntdll.RtlZeroMemory(dst,size)