Slapdash Safeguards

にわか仕込みのセキュリティ

Blue Team Labs Online - Nonyx Writeup

シナリオ

Exorcise Black Energy 2 from Shadowbrook’s digital infrastructure by reverse-engineering the malware’s code. You must dismantle its hooks, identify its payload, and stop its command-and-control mechanisms to restore peace to the town’s network before the Haunted Festival reaches its darkest hour.

Q1) Which process most likely contains injected code, providing its name, PID, and memory address? (Format: Name, PID, Address)(4 points)

readme.txtを見ると、プロファイルはWinXPSP2x86を使えとのことなのでそうする。

malfindプラグインなるものがあるそうなのでそれでスキャンをしてみる。

実行コマンド: python vol.py -f BlackEnergy.vnem --profile=WinXPSP2x86 malfind

image

ヘッダがMZのプロセスを発見した。

Answer: svchost.exe, 856, 0xc30000

Q2) What dump file in the malfind output directory corresponds to the memory address identified for code injection? (Format: Output File Name)(4 points)

malfindコマンドについて調べると、-Dオプションをつけることでダンプファイルを出力することができることが判明。pidと併せて出力してみる。

実行コマンド: python vol.py -f BlackEnergy.vnem --profile=WinXPSP2x86 malfind -D ./output --pid 856

出力されたファイル名を回答

image

Answer: process.0x80ff88d8.0xc30000.dmp

Q3) Which full filename path is referenced in the strings output of the memory section identified by malfind as containing a portable executable (PE32/MZ header)? (Format: Filename Path)(4 points)

ダンプファイルは手に入っているので、単純に中身を見てみる

実行コマンド: strings ./output/process.0x80ff88d8.0xc30000.dmp

image

Answer: C:\WINDOWS\system32\drivers\str.sys Bash

Q4) How many functions were hooked and by which module after running the ssdt plugin and filtering out legitimate SSDT entries using egrep -v '(ntoskrnl|win32k)'? (Format: XX, Module)(4 points)

まず、SSDTという概念を知らないので、調べる。

SSDT(System Service Descriptor Table)オプションは、Windowsカーネル内の「システム関数呼び出しのインデックス表」を調査するためのプラグインです。 簡単に言うと、「OSが何か命令を実行する際に参照する『電話帳』が、犯人(マルウェア)によって書き換えられていないか」を調べるために使います。

簡単に言うと、アプリケーションがOSの低レベル機能(プロセス操作・メモリ操作・レジストリアクセスなど)を呼び出した際に、「どのカーネル関数を実行するか」を決定する対応表のようなものですかね。マルウェア(特にルートキット)は、このSSDTのエントリを書き換えることで、本来呼ばれるはずのWindows標準処理ではなく、自身が用意したドライバ(.sys)内の処理へフックさせることがある。

これは単純に「マルウェアコードを実行する」目的というより、主に以下のような防御・隠蔽(自己保護)目的で利用される。

NtOpenProcess / NtOpenThread → セキュリティツールがプロセスへアクセスするのを監視・拒否し、マルウェアプロセスを保護する

NtProtectVirtualMemory / NtWriteVirtualMemory → メモリ改変や解析ツールによる書き込みを検知・阻止する

NtTerminateThread → 自身のプロセスやスレッドが終了させられるのを防ぐ

NtEnumerateKey → レジストリエントリを隠蔽し、存在を見えなくする

つまりSSDTフックは、「任意コード実行」というよりも、OSレベルのAPI呼び出しを横取りして挙動を改変し、マルウェアの存在を隠したり保護したりするための仕組みとして使われるケースが多いように思える。

また、SSDTのエントリとしてntoskrnl と win32k はWindowsの正規モジュールだからこれを除外して残ったものは怪しいということなのかな。

実行コマンド: python vol.py -f BlackEnergy.vnem --profile=WinXPSP2x86 ssdt | egrep -v '(ntoskrnl|win32k)'

image

Answer: 14, 00004A2A

Q5) Using the modules (or modscan) plugin to identify the hooking driver from the ssdt output, what is the base address for the module found in Q4? (Format: Base Address)

modscan

特定の Windows メモリ イメージ内に存在するモジュールをスキャンします。

とのことなので、先ほど特定したモジュール"00004A2A"をスキャンしてみる。

実行コマンド: python vol.py -f BlackEnergy.vnem --profile=WinXPSP2x86 modscan | grep "00004A2A"

image

Answer: 0xff0d1000

Q6) What is the hash for the malicious driver from the virtual memory image? (Format: SHA256)

ベースアドレスは特定できたのであとはドライバーをダンプしてハッシュを取ります。

moddumpというオプションを使えばカーネル ドライバーを実行可能ファイル サンプルにダンプできるとのことなので、ベースアドレスを指定してやってみる。

実行コマンド: python vol.py -f BlackEnergy.vnem --profile=WinXPSP2x86 moddump -b 0xff0d1000 -D ./

driver.ff0d1000.sysというファイルがダンプできたのでSHA256を取得する。

Answer: 12b0407d9298e1a7154f5196db4a716052ca3acc70becf2d5489efd35f6c6ec8

まとめ

個人的にvolatilityを使ったメモリフォレンジックはあまり知らなかったので、順を追って実際に手を動かしながら勉強できた。

ちなみに、今回調査したマルウェアのハッシュをVirustotalで検索した結果がこちら

www.virustotal.com