0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

メモリフォレンジックCTF「MemLabs」Lab1のWriteUp(Volatility3)

Posted at

はじめに

メモリフォレンジックを勉強することなったため,Volatilityを使用するメモリフォレンジックCTF「MemLabs」で学んでいきたいと思う.
「MemLabs」では,Volatility2が推奨されているが,2021年2月にVolatility3がリリースされており,出来るだけVolatility3を使用したいと思う.
また,使用するツールなどの備忘録を残す.

MemLabs

P.Abhiram Kumar氏が公開しているCTFスタイルでメモリフォレンジックを学ぶことができる教材で,Githubにて公開されています。

Writeup

使用したツール

  • unrar
  • gimp
  • feh

問題

My sister's computer crashed. We were very fortunate to recover this memory dump. Your job is get all her important files from the system. From what we remember, we suddenly saw a black window pop up with some thing being executed. When the crash happened, she was trying to draw something. Thats all we remember from the time of crash.
Note: This challenge is composed of 3 flags.

妹のパソコンがクラッシュしてしまいました。幸運にもこのメモリーダンプを復元することができました。
あなたの仕事は、システムから彼女の重要なファイルをすべて取得することです。
私たちが覚えているのは、突然黒いウィンドウが現れ、何かが実行されたことです。
クラッシュしたとき、彼女は何かを描こうとしていた。それが、クラッシュしたときの記憶すべてです。
注:この課題は3つのフラグで構成されています。

初動調査

取り敢えず,メモリダンプ取得時に起動していたプロセス情報を確認.

$ vol3 -f MemoryDump_Lab1.raw windows.pstree

image.png
特に不審なプロセスも見当たらないため,問題文にあるように妹が何か操作をしていたということから,
explorer.exeの子プロセスに注目して調査していきたいと思う.

explorer.exeの子プロセスは以下の通り.
1. cmd.exe(PID:1984)
2. VBoxTray.exe(PID:1844,2304)
3. DumpIt.exe(PID:796)
4. mspaint.exe(PID:2424)
5. WinRAR(PID:1512)
このうち,2と3のプロセスはCTF環境に関係するものと推測1されるため,1,4,5に注目して調査を行う.

Flag1

1.cmd.exe(PID:1984)について,調査していこうと思う.Volatility2では,コマンド履歴やその実行結果を取得できるプラグインcmdscanやconsolesがあるがVolatility3にはないため,cmd.exe(PID:1964)が使用しているメモリ領域をダンプしてみる.

$ vol3 -f MemoryDump_Lab1.raw windows.memmap --pid 1984 --dump
$ file pid.1984.dmp 
pid.1984.dmp: data

ダンプしたデータから,何か情報がないか調査したいと思う.ここで,問題文を振り返ると以下の記載があり,バッチファイルなどが起動された可能性が考えられるため,「echo」や「@echo off」などで情報がないか調べてみた.

私たちが覚えているのは、突然黒いウィンドウが現れ、何かが実行されたことです。

$ strings pid.1984.dmp | grep -i "@echo off" -C5
FILE0
I":"re
{"version":1,"listeners":{"remote-settings/monitor_changes":{"version":"\"1576032042722\"","sourceInfo":{"moduleURI":"resource://services-settings/remote-settings.js","symbolName":"remoteSettingsBroadcastHandler"}}}}
FILE0
FILE0
@ECHO OFF
ECHO ZmxhZ3t0aDFzXzFzX3RoM18xc3Rfc3Q0ZzMhIX0=
PAUSE
FILE0
FILE0
FILE0

次のようにいい感じに情報を得ることができた.ECHO ZmxhZ3t0aDFzXzFzX3RoM18xc3Rfc3Q0ZzMhIX0=
英数字と「=」記号から出来ていることからBase64でエンコードされていると考えれるため,デコードしてみる.

$ echo "ZmxhZ3t0aDFzXzFzX3RoM18xc3Rfc3Q0ZzMhIX0=" |base64 -d

Flagを得ることができる.

Flag1
Flag1
flag{th1s_1s_th3_1st_st4g3!!}

Flag2

次に4.mspaint.exe(PID:2424)について調査していきたいと思う.メモリフォレンジックのCTFでは,mspaint.exeに関する問題がいくつか出題されているように思える.他のWriteupにも記載2されている通り,「GIMP」を使用することで,データを読み込むことができる模様.やってみる.ちなみに,「.dmp」から「.data」にリネームしないと開けない模様.

$ vol3 -f MemoryDump_Lab1.raw windows.memmap --pid 2424 --dump
$ file pid.2424.dmp 
pid.2424.dmp: data
$ mv pid.2424.dmp pid.2424.data
$ gimp pid.2424.data

画像_2023-01-02_212730637.png
Offsetであたりを付けた後,高さや幅を変更することで文字列が見えてくる.
反転しているようなので調整したら,Flagを得ることができる.
画像_2023-01-02_213923355.png

Flag2
Flag2
flag{G00d_BoY_good_girl}

Flag3

最後に5.WinRAR(PID:1512)について調査していく.WinRARの特徴から,解凍または圧縮をしたのではないかと考えられる.
そのため,起動時のコマンドラインから読み込んだファイルがわかる可能性があるため,取り敢えず確認してみる.

$ vol3 -f MemoryDump_Lab1.raw windows.cmdline --pid 1512
Volatility 3 Framework 2.4.1
Progress:  100.00		PDB scanning finished                        
PID	Process	Args

1512	WinRAR.exe	"C:\Program Files\WinRAR\WinRAR.exe" "C:\Users\Alissa Simpson\Documents\Important.rar"

キーになりそうな"C:\Users\Alissa Simpson\Documents\Important.rar"を得ることができた.
対象のファイルデータをメモリが所持している可能性があり,ダンプするにはアドレスが必要なため確認する.

$ vol3 -f MemoryDump_Lab1.raw windows.filescan | grep -i Important.rar
0x3fa3ebc0 100.0\Users\Alissa Simpson\Documents\Important.rar	216
0x3fac3bc0	\Users\Alissa Simpson\Documents\Important.rar	216
0x3fb48bc0	\Users\Alissa Simpson\Documents\Important.rar	216

実行結果から,対象ファイルのOffset0x3fa3ebc0を得ることができる.
得たアドレスからファイルのダンプを試みる.

$ vol3 -f MemoryDump_Lab1.raw windows.dumpfiles --physaddr 0x3fa3ebc0
$ file file.0x3fa3ebc0.0xfa8001034450.DataSectionObject.Important.rar.dat 
file.0x3fa3ebc0.0xfa8001034450.DataSectionObject.Important.rar.dat: RAR archive data, v5
$ mv file.0x3fa3ebc0.0xfa8001034450.DataSectionObject.Important.rar.dat Important.rar

fileコマンドで確認しても,ダンプファイルは「rar」ファイルであることが分かる.
取り敢えず解凍してみる.

$ unrar x Important.rar 

UNRAR 5.61 beta 1 freeware      Copyright (c) 1993-2018 Alexander Roshal

Extracting from Important.rar

Password is NTLM hash(in uppercase) of Alissa's account passwd.

Enter password (will not be echoed) for flag3.png: 

当然ながらパスワードがかかっており,素直に解凍することは出来ない.しかし,ヒントが記載されておりパスワードは「Alissa」のNTLMハッシュを大文字にしたものだという情報を得ることができる.

Password is NTLM hash(in uppercase) of Alissa's account passwd.

それでは,AlissaのNTLMハッシュをダンプしていこうと思う.

$ vol3 -f MemoryDump_Lab1.raw windows.hashdump
Volatility 3 Framework 2.4.1
Progress:  100.00		PDB scanning finished                        
User	rid	lmhash	nthash

Administrator	500	aad3b435b51404eeaad3b435b51404ee	31d6cfe0d16ae931b73c59d7e0c089c0
Guest	501	aad3b435b51404eeaad3b435b51404ee	31d6cfe0d16ae931b73c59d7e0c089c0
SmartNet	1001	aad3b435b51404eeaad3b435b51404ee	4943abb39473a6f32c11301f4987e7e0
HomeGroupUser$	1002	aad3b435b51404eeaad3b435b51404ee	f0fc3d257814e08fea06e63c5762ebd5
Alissa Simpson	1003	aad3b435b51404eeaad3b435b51404ee	f4ff64c8baac57d22f22edc681055ba6

NTLMハッシュが手に入ったため,大文字にしてImportant.rarを解凍する.

$ echo "f4ff64c8baac57d22f22edc681055ba6" | tr a-z A-Z
F4FF64C8BAAC57D22F22EDC681055BA6
$ unrar x Important.rar 

UNRAR 5.61 beta 1 freeware      Copyright (c) 1993-2018 Alexander Roshal

Extracting from Important.rar

Password is NTLM hash(in uppercase) of Alissa's account passwd.

Enter password (will not be echoed) for flag3.png: 

Extracting  flag3.png                                                 OK 
All OK

解凍するとflag3.pngといったファイルが生成されるため,ビューアーなどで開くとFlagを得ることができる.

$ feh flag3.png
Flag3
Flag3
flag{w3ll_3rd_stage_was_easy}

おまけ

Flag1でstringsコマンドを使用する際に,grepで表示する範囲を広げるとファイルの名前が得られる.

$ strings pid.1984.dmp | grep -i "@echo off" -C15
FILE0
FILE0
PReg
FILE0
FILE0
FILE0
PReg
FILE0
FILE0
FILE0
FILE0
I":"re
{"version":1,"listeners":{"remote-settings/monitor_changes":{"version":"\"1576032042722\"","sourceInfo":{"moduleURI":"resource://services-settings/remote-settings.js","symbolName":"remoteSettingsBroadcastHandler"}}}}
FILE0
FILE0
@ECHO OFF
ECHO ZmxhZ3t0aDFzXzFzX3RoM18xc3Rfc3Q0ZzMhIX0=
PAUSE
FILE0
FILE0
FILE0
FILE0
FILE0
St4g3$1.txt
C:\Users\
\\SMARTNET-PC\Users
SmartNet\Desktop\St4g3$1.txt
1SPS
smartnet-pc
FILE0
OBH 

得られたファイルの情報が残っていないか,調査してみるとSt4g3$1.txtの情報はないがSt4G3$1.batのOffsetを得ることができたのでダンプしてみる.

$ vol3 -f MemoryDump_Lab1.raw windows.filescan | grep -i St4g3$1
0x3edcfc20 100.0\Windows\System32\St4G3$1.bat
$ vol3 -f MemoryDump_Lab1.raw windows.dumpfiles --physaddr 0x3edcfc20

vimで覗いてみると図のようになっていた.
画像_2023-01-02_233023800.png

  1. 2のプロセスはOracle VM VirtualBox Guest Additions
    3のプロセスはメモリダンプをするためツール

  2. HCTF 2018 Writeup
    FwordCTF 2020 Writeup

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?