###### tags: `InterKosenCTF` `Forensics` # [InterKosenCTF|Forensics 300] Matroska tar.gzファイルからは`memdump.raw`が出てくる。こういう名前なのでVolatilityで解析していく。imageinfoはものすごく時間がかかるので注意。 問題文からもWindows 10 のメモリダンプということは想像がつくのでこれでやっていく。プロファイルは`Win10x64_17134`を使った。まずpstreeをやる。 ```= $ vol.py -f memdump.raw --profile Win10x64_17134 pstree Name Pid PPid Thds Hnds Time -------------------------------------------------- ------ ------ ------ ------ ---- 0xffffe00e553b7080:winlogon.exe 516 432 6 0 2018-12-25 03:09:58 UTC+0000 . 0xffffe00e55794580:fontdrvhost.ex 664 516 6 0 2018-12-25 03:09:58 UTC+0000 . 0xffffe00e5703d580:userinit.exe 3364 516 0 ------ 2018-12-25 03:10:12 UTC+0000 .. 0xffffe00e5703f580:explorer.exe 3452 3364 88 0 2018-12-25 03:10:13 UTC+0000 ... 0xffffe00e577fe580:VBoxTray.exe 6036 3452 14 0 2018-12-25 03:10:43 UTC+0000 ... 0xffffe00e5701f080:DumpIt.exe 2080 3452 2 0 2018-12-25 03:11:30 UTC+0000 .... 0xffffe00e578a8080:conhost.exe 2260 2080 5 0 2018-12-25 03:11:30 UTC+0000 ... 0xffffe00e57376580:MSASCuiL.exe 5988 3452 6 0 2018-12-25 03:10:41 UTC+0000 ... 0xffffe00e576d1580:vlc.exe 5700 3452 0 ------ 2018-12-25 03:11:00 UTC+0000 .... 0xffffe00e574fe3c0:svchost.exe 4940 5700 2 0 2018-12-25 03:11:10 UTC+0000 ..... 0xffffe00e5618a580:conhost.exe 3368 4940 6 0 2018-12-25 03:11:10 UTC+0000 . 0xffffe00e568ed580:dwm.exe 884 516 14 0 2018-12-25 03:09:59 UTC+0000 0xffffe00e552ce580:csrss.exe 452 432 12 0 2018-12-25 03:09:57 UTC+0000 0xffffe00e551c1580:csrss.exe 372 364 11 0 2018-12-25 03:09:57 UTC+0000 0xffffe00e5539e080:wininit.exe 440 364 5 0 2018-12-25 03:09:57 UTC+0000 ...snip... ``` 動いていたアプリケーションで目立つのは `vlc.exe`。これの子プロセスとして`svchost.exe`が動いているけど普通こういうことはないので怪しい。とりあえずプロセスをダンプする。 ```= $ vol.py -f memdump.raw --profile Win10x64_17134 procdump -p 4940 --dump-dir svchost ``` とりあえず抽出したプロセスを見てみるけどどこが怪しいのかわからない。もしかしたらDLL InjectionかもしれないのでDLLもみてみる。 ```= $ vol.py -f memdump.raw --profile Win10x64_17134 dlllist -p 4940 Volatility Foundation Volatility Framework 2.6.1 ************************************************************************ svchost.exe pid: 4940 Command line : C:\Windows\svchost.exe Base Size LoadCount LoadTime Path ------------------ ------------------ ------------------ ------------------------------ ---- 0x0000000000880000 0x17000 0xffff 2018-12-25 03:11:10 UTC+0000 C:\Windows\svchost.exe 0x00007ffa8f6e0000 0x1e1000 0xffff 2018-12-25 03:11:10 UTC+0000 C:\Windows\SYSTEM32\ntdll.dll 0x0000000077410000 0x52000 0xffff 2018-12-25 03:11:10 UTC+0000 C:\Windows\System32\wow64.dll 0x0000000077380000 0x78000 0x6 2018-12-25 03:11:10 UTC+0000 C:\Windows\System32\wow64win.dll 0x0000000077400000 0xa000 0x6 2018-12-25 03:11:10 UTC+0000 C:\Windows\System32\wow64cpu.dll 0x0000000000880000 0x17000 0xffff 2018-12-25 03:11:10 UTC+0000 C:\Windows\svchost.exe 0x0000000077470000 0x190000 0xffff 2018-12-25 03:11:10 UTC+0000 C:\Windows\SYSTEM32\ntdll.dll 0x0000000074420000 0xe0000 0xffff 2018-12-25 03:11:10 UTC+0000 C:\Windows\System32\KERNEL32.DLL 0x0000000074550000 0x1e3000 0xffff 2018-12-25 03:11:10 UTC+0000 C:\Windows\System32\KERNELBASE.dll 0x0000000076790000 0x18d000 0x6 2018-12-25 03:11:11 UTC+0000 C:\Windows\System32\USER32.dll 0x00000000748f0000 0x17000 0x6 2018-12-25 03:11:11 UTC+0000 C:\Windows\System32\win32u.dll 0x00000000764f0000 0x22000 0x6 2018-12-25 03:11:11 UTC+0000 C:\Windows\System32\GDI32.dll 0x0000000075030000 0x164000 0x6 2018-12-25 03:11:11 UTC+0000 C:\Windows\System32\gdi32full.dll 0x0000000077060000 0x7d000 0x6 2018-12-25 03:11:11 UTC+0000 C:\Windows\System32\msvcp_win.dll 0x0000000076670000 0x11e000 0x6 2018-12-25 03:11:11 UTC+0000 C:\Windows\System32\ucrtbase.dll 0x0000000077030000 0x26000 0x6 2018-12-25 03:11:11 UTC+0000 C:\Windows\System32\IMM32.DLL 0x0000000073b80000 0x16000 0x6 2018-12-25 03:11:12 UTC+0000 C:\Windows\user32.dll 0x0000000073b00000 0x7c000 0x6 2018-12-25 03:11:12 UTC+0000 C:\Windows\system32\uxtheme.dll 0x0000000076a20000 0xbf000 0xffff 2018-12-25 03:11:12 UTC+0000 C:\Windows\System32\msvcrt.dll 0x0000000076c10000 0x25c000 0xffff 2018-12-25 03:11:12 UTC+0000 C:\Windows\System32\combase.dll 0x0000000076e70000 0xc0000 0xffff 2018-12-25 03:11:12 UTC+0000 C:\Windows\System32\RPCRT4.dll 0x0000000073d30000 0x20000 0x6 2018-12-25 03:11:12 UTC+0000 C:\Windows\System32\SspiCli.dll 0x0000000073d20000 0xa000 0xffff 2018-12-25 03:11:12 UTC+0000 C:\Windows\System32\CRYPTBASE.dll 0x0000000074350000 0x58000 0xffff 2018-12-25 03:11:12 UTC+0000 C:\Windows\System32\bcryptPrimitives.dll 0x0000000073d50000 0x44000 0x6 2018-12-25 03:11:12 UTC+0000 C:\Windows\System32\sechost.dll 0x0000000076520000 0x144000 0x6 2018-12-25 03:11:12 UTC+0000 C:\Windows\System32\MSCTF.dll 0x0000000077100000 0x96000 0x6 2018-12-25 03:11:12 UTC+0000 C:\Windows\System32\OLEAUT32.dll 0x00000000748e0000 0xf000 0xffff 2018-12-25 03:11:12 UTC+0000 C:\Windows\System32\kernel.appcore.dll 0x0000000073a80000 0x7e000 0x6 2018-12-25 03:11:13 UTC+0000 C:\Windows\SYSTEM32\TextInputFramework.dll 0x0000000073820000 0x25d000 0xffff 2018-12-25 03:11:13 UTC+0000 C:\Windows\SYSTEM32\CoreUIComponents.dll 0x0000000076f90000 0x89000 0xffff 2018-12-25 03:11:13 UTC+0000 C:\Windows\System32\SHCORE.dll 0x00000000772a0000 0x78000 0xffff 2018-12-25 03:11:13 UTC+0000 C:\Windows\System32\advapi32.dll 0x0000000073790000 0x8b000 0xffff 2018-12-25 03:11:13 UTC+0000 C:\Windows\SYSTEM32\CoreMessaging.dll 0x0000000073760000 0x29000 0xffff 2018-12-25 03:11:13 UTC+0000 C:\Windows\SYSTEM32\ntmarta.dll 0x0000000073680000 0xd6000 0xffff 2018-12-25 03:11:13 UTC+0000 C:\Windows\SYSTEM32\wintypes.dll 0x0000000076920000 0xfc000 0x6 2018-12-25 03:11:16 UTC+0000 C:\Windows\System32\ole32.dll ``` あやしいdllをみつけた。`C:\Windows\user32.dll`がそう。一個だけ置かれてるディレクトリ違うし。これもdumpしてみる ```= $ vol.py -f memdump.raw --profile Win10x64_17134 dlldump -p 4940 --dump-dir dlls ``` 解析する。WindowsのDLLはたくさん関数があって解析しにくいが、IDAでみたときの関数のリストの一番上はユーザが作ったものであることが多いらしいのでこれを見てみる。 この関数は2回MessageBoxを呼んでいる。1回はフラグっぽいtextで、もう一個は"Hacked by ptr-yudai"とかだったと思う。雑に手動デコンパイルをするとこんな感じ。 ```c= int len = strlen(text) for(int i = 0; i < len; i++) { text[i] = (i ^ ~text[i]) & 0xff; } MessageBox(text); for (int i = 0; i < len; i++) { text[i] = (~(len - i) ^ text[i]) & 0xff; } MessageBox("Hacked by ptr-yudai"); ``` 多分このtextがフラグ。実行後のデータはこんな感じ。なので戻していく。 ``` 0x85, 0x80, 0x83, 0x94, 0x9C, 0x90, 0x80, 0x93, 0xAD, 0x82, 0xAB, 0xBC, 0x85, 0x9A, 0xBA, 0xA9, 0xBB, 0xAD, 0xBF, 0xA7, 0x90, 0x86, 0x81, 0xBA, 0xA7, 0x95, 0x8A, 0x80, 0x9E, 0x99, 0x8D, 0x9F, 0x97, 0xB0, 0xB3, 0x9E, 0x96, 0x96, 0xAB, 0xB0, 0x8E, 0x92, 0x9B, 0x8C, 0x8E, 0x92, 0x93, 0x93, 0x83, ``` ```python= xs = [0x85, 0x80, 0x83, 0x94, 0x9C, 0x90, 0x80, 0x93, 0xAD, 0x82, 0xAB, 0xBC, 0x85, 0x9A, 0xBA, 0xA9, 0xBB, 0xAD, 0xBF, 0xA7, 0x90, 0x86, 0x81, 0xBA, 0xA7, 0x95, 0x8A, 0x80, 0x9E, 0x99, 0x8D, 0x9F, 0x97, 0xB0, 0xB3, 0x9E, 0x96, 0x96, 0xAB, 0xB0, 0x8E, 0x92, 0x9B, 0x8C, 0x8E, 0x92, 0x93, 0x93, 0x83] ys = [] for i, x in enumerate(xs): ys.append(0xFF ^ (len(xs) - i) ^ x & 0xFF) print("".join(map(chr, ys))) ``` Here is the flag. `KOSENCTF{Use_After_Free_Arbitrary_Code_Execution}`