1
0
mirror of https://github.com/nganhkhoa/malware.git synced 2024-06-10 21:32:07 +07:00
mether049-malware/Trickbot/analysis_processhollowing.md
2020-02-03 23:30:29 +09:00

130 lines
7.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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/)<br>[HYBRID ANALYSIS](https://www.hybrid-analysis.com/sample/3a6c3f7b99b2e76914fbc338c622b92f9825cb77729b8bf050ba64ece1679818?environmentId=100)<br>[Triage](https://tria.ge/reports/191018-jnffne1l7x/task2)<br>|
- Environment
|vm|VirtualBox5.2, Guest Addtions Installed|
|:-|:-|
|os|Windows10 Home 64bit, FLARE VM Installed|
|debugger|x32/x64dbg, WinDbg|
## Analysis contents
※以下,誤って解釈している部分や解析しきれず不足している部分がある可能性有(更新予定)<br>
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の位置のデータもすべてをコピーするわけではなく下図のように特定の条件にマッチした際にByteずつ書き込みを行う(詳細は述べない)
> 条件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上の関数名リストからつずつ関数名字列をとりだして目的の(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の組み合わせ<br>
> 26C4B1F1 LdrLoadDll<br>
> E33A06BF NtAllocateVirtualMemory<br>
> 82bb0ee0 NtProtectVirtualMemory<br>
> 026da588 NtReadVirtualMemory<br>
> 7a65c193 NtWriteVirtualMemory<br>
> e873107e NtQueryInformationProcess<br>
> 918a52f1 NtResumeThread<br>
![](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..
- 解析を進めて以下の部分について修正・追加を行う
- 誤って解釈している部分
- 解析しきれていない部分
- あいまいに解釈している部分