# Process Hollowing(Trickbot) - Sample/Environment - Analysis contents - File copy - VirtualAlloc and Data transition - Createting Process and Heaven's Gate (Process Hollowing) - to do... ## Sample/Environment - Sample |sha256|[3A6C3F7B99B2E76914FBC338C622B92F9825CB77729B8BF050BA64ECE1679818](https://www.virustotal.com/gui/file/3a6c3f7b99b2e76914fbc338c622b92f9825cb77729b8bf050ba64ece1679818/detection)| |:-|:-| |filetype|PE(exe,32bit)| |sandbox|[ANYRUN](https://app.any.run/tasks/9f302b49-4585-4905-b466-9459ff88c558/)
[HYBRID ANALYSIS](https://www.hybrid-analysis.com/sample/3a6c3f7b99b2e76914fbc338c622b92f9825cb77729b8bf050ba64ece1679818?environmentId=100)
[Triage](https://tria.ge/reports/191018-jnffne1l7x/task2)
| - Environment |vm|VirtualBox5.2, Guest Addtions Installed| |:-|:-| |os|Windows10 Home 64bit, FLARE VM Installed| |debugger|x32/x64dbg, WinDbg| ## Analysis contents ※以下,誤って解釈している部分や解析しきれず不足している部分がある可能性有(更新予定)
Process HollowingやHeaven's Gate自体の説明は[こちら](https://github.com/mether049/malware/blob/master/malware-tech_ref_and_memo.md) ### File copy Trickbotの初期動作に関する説明 - CopyFileWによって特定のパスに自身(同一ファイル)のコピーの作成を試行する - 特定パスにコピーが存在していなかった場合,コピーを作成しShellExecuteWによってコピーされたファイルが実行される。その後,自プロセスをExitProcessによって終了させる - 特定パスにコピーが既に存在していた場合,CopyFileWは失敗し上記とは別の処理(Process Hollowing等)に分岐する(要するに,ShellExecuteWによって実行されたコピーのプロセスがこちらの分岐を通過する) ![](https://github.com/mether049/malware/blob/master/Trickbot/img/shellexecute_2_720.png) - CopyFileWによるコピー先は,C:\ProgramData\բնութագրվում է.exeであった(ファイル名はGoogle翻訳の検出結果によるとアルメニア語) ![](https://github.com/mether049/malware/blob/master/Trickbot/img/filecopy_1_720.png) 以降はコピーしたファイルに関するプロセスの処理の説明となる ### VirtualAlloc and Data transition Process Hollowingにも利用するデータに関する説明 - コピーのプロセス実行中に5~7回VirtualAllocによる領域確保が確認された ![](https://github.com/mether049/malware/blob/master/Trickbot/img/virtualalloc_3_720.png) - 1回目のVirtualAllocでは,0x2D000Byteの領域を確保する - 0x2D000Byteは.dataのサイズと同じである ![](https://github.com/mether049/malware/blob/master/Trickbot/img/datasection_4_720.png) - 確保した0x2D000Byteの領域に.dataをすべてコピーするわけではなく,.dataのベースアドレス+0x7C3の位置からコピーを開始する - +0x7C3のメモリダンプを確認すると,PEファイルのようである - +0x7C3の位置のデータもすべてをコピーするわけではなく,下図のように特定の条件にマッチした際に,1Byteずつ書き込みを行う(詳細は述べない) > 条件:0x3C <= ECX <= 0x3E or EAX <= ECX ![](https://github.com/mether049/malware/blob/master/Trickbot/img/datacopy_5_modify_720.png) - また,.dataの+0x9C3~+0x2B5C3の位置のデータは下図のように上記とは別の処理でコピーされる ![](https://github.com/mether049/malware/blob/master/Trickbot/img/datacopy2_6_720.png) - コピーされたデータに対してデコードを行う - xorが用いられていた - デコードした結果からは64bitのPEファイルを示すような文字列が確認された(下図メモリダンプより) ![](https://github.com/mether049/malware/blob/master/Trickbot/img/decode_7_720.png) - 上記からさらにデコードを実施し,3回目のVirtualAllocにより確保された領域(0x60000Byte)に書き込みを行う - 下図のメモリダンプをファイルに保存して確認した結果64bitのPEファイルであった ![](https://github.com/mether049/malware/blob/master/Trickbot/img/decode2_8_720.png) - 5~6回目のVirtualAllocで確保した領域(ベースアドレス:0x10001000)に対して,上記で確保した領域(0x60000Byte)に書き込まれたPEファイルの一部をコピーする - 下図より,PEファイルの.text以下がコピーされている ![](https://github.com/mether049/malware/blob/master/Trickbot/img/copytext_9_720.png) ### Createting Process and Heaven's Gate (Process Hollowing) - CreateProcessWによってProcess Hollowingの対象となるプロセス(svchost.exe)を作成する - プロセスはサスペンド状態で作成される ![](https://github.com/mether049/malware/blob/master/Trickbot/img/svchost_10_720.png) - 以降のProcess Hollowingの処理はHeavens's Gate(64bitシステムに切り替え)を利用して行われていた ![](https://github.com/mether049/malware/blob/master/Trickbot/img/heavensgate_11_720.png) - ここから64bitの命令群に遷移する(32bit向けのユーザモードデバッガでの追跡が困難になる。WinDbgなら追跡可能) - 遷移先は0x10001000であり,先ほどPEファイルの.text以下をコピーした領域である(64bitPEファイルを保存してそれに対してデバッガでデバッグすることは可能) ![](https://github.com/mether049/malware/blob/master/Trickbot/img/heavensgate_16_720.png) - ntdll.dllのexport table上の関数名リストから1つずつ関数名字列をとりだして目的の(Process Hollowingに利用すると思われる)関数名と一致するものを探し,さらにそのアドレスを取得する?(ここは詳細に確認していない。このあたりは[こちら](https://www.cyberbit.com/blog/endpoint-security/latest-trickbot-variant-has-new-tricks-up-its-sleeve/)でも詳しく書かれている気がする) ![](https://github.com/mether049/malware/blob/master/Trickbot/img/ntdll_12_720.png) - 目的のAPIは関数名のCRC32値?(ここも詳細に確認していない)で比較される ![](https://github.com/mether049/malware/blob/master/Trickbot/img/crccalc_13_720.png) - 目的のAPIとCRC32の組み合わせ:
> 26C4B1F1 LdrLoadDll
> E33A06BF NtAllocateVirtualMemory
> 82bb0ee0 NtProtectVirtualMemory
> 026da588 NtReadVirtualMemory
> 7a65c193 NtWriteVirtualMemory
> e873107e NtQueryInformationProcess
> 918a52f1 NtResumeThread
![](https://github.com/mether049/malware/blob/master/Trickbot/img/crccmp_14_720.png) - 取得したアドレスを利用してAPIを呼び出し,Process Hollowingを終了させる - 各APIの呼び出しで処理が失敗した場合,その時点でプロセスが終了する ![](https://github.com/mether049/malware/blob/master/Trickbot/img/apicall_15_720.png) - 以下は[NtQueryInformationProcess](https://docs.microsoft.com/ja-jp/windows/win32/api/winternl/nf-winternl-ntqueryinformationprocess?redirectedfrom=MSDN)の呼び出し後におけるPROCESS_BASIC_INFORMATION構造体の各メンバの値である - svchost.exeのプロセスIDは9652 ![](https://github.com/mether049/malware/blob/master/Trickbot/img/PROCESS_BASIC_INFORMATION.png) ![](https://github.com/mether049/malware/blob/master/Trickbot/img/processhacker.PNG) ## to do.. - 解析を進めて以下の部分について修正・追加を行う - 誤って解釈している部分 - 解析しきれていない部分 - あいまいに解釈している部分