1
0
mirror of https://github.com/nganhkhoa/malware.git synced 2024-06-10 21:32:07 +07:00
mether049-malware/detecting_ph_process.md

219 lines
13 KiB
Markdown
Raw Normal View History

2020-03-01 01:28:00 +07:00
# Identification of Hollowed out processes
- [Process Hollowing](https://github.com/mether049/malware/blob/master/malware-tech_ref_and_memo.md#injectionhollowing)されたプロセスの識別方法を示す
2020-03-01 01:58:18 +07:00
- [Case1: Hollows Hunter](https://github.com/mether049/malware/blob/master/detecting_ph_process.md#case1-hollows-hunter)
- [Case2: Loki](https://github.com/mether049/malware/blob/master/detecting_ph_process.md#case2-loki)
- [Case3: EQL(Event Query Language)](https://github.com/mether049/malware/blob/master/detecting_ph_process.md#case3-eqlevent-query-language)
- [Extracting IoC from Process Memory with strings2](https://github.com/mether049/malware/blob/master/detecting_ph_process.md#extracting-ioc-from-process-memory-with-strings2)
- [Case4: Volatility](https://github.com/mether049/malware/blob/master/detecting_ph_process.md#case4-volatility)
2020-03-01 01:28:00 +07:00
## Sample/Environment
- Sample
|sha256|[05A14271A14004BF89D8B4DBED8E876A0A182BD98864BEDC86D824647D9D5810](https://www.virustotal.com/gui/file/05a14271a14004bf89d8b4dbed8e876a0a182bd98864bedc86d824647d9d5810/detection)|
|:-|:-|
|filetype|PE(exe,32bit)|
|sandbox|[ANYRUN](https://app.any.run/tasks/a90c4199-c3bf-4199-8b47-bd01cf2eca7a/)<br>[HYBRID ANALYSIS](https://hybrid-analysis.com/sample/05a14271a14004bf89d8b4dbed8e876a0a182bd98864bedc86d824647d9d5810?environmentId=100)<br>
|family|Trickbot|
- Environment
|vm|VirtualBox5.2, Guest Addtions Installed|
|:-|:-|
|os|Windows10 Home 64bit, FLARE VM Installed|
|Tools|PowerShell,Hollows Hunter,Loki,EQL,Sysmon,Strings2,Volatility|
## First
- Process Hollowingを行うマルウェア(今回はTrickbot)を実行する
- 検体にもよるがProcess Hollowingが完了するまでに時間を要するケースがあるので注意
以下Case1-4で各種Toolを用いてProcess Hollowingされたプロセスの識別を行う
## Case1: Hollows Hunter
2020-03-01 01:35:45 +07:00
Hollows Hunterは全プロセスもしくは特定の名称のプロセスのメモリをスキャンしProcess HollowingやInjectionを検出・ダンプすることが可能。[PE-Sieve](https://github.com/hasherezade/pe-sieve)と同じ開発者([@hasherezade](https://twitter.com/hasherezade))によって作成されたツールでありPE-Sieveのdllが内部で用いられている。
2020-03-01 01:28:00 +07:00
1. Hollows Hunterを[こちら](https://github.com/hasherezade/hollows_hunter/releases)からダウンロードする
2. 管理者権限でPowerShellを実行
3. 使用方法は```/help```で以下のように確認することができる(~の部分は省略)。
```
PS> \hollows_hunter.exe /help
Optional:
---scan options---
/pname <process_name>
: Scan only processes with given names (separated by ';').
Example: iexplore.exe;firefox.exe
/hooks : Detect hooks and in-memory patches.
/shellc : Detect shellcode implants. (By default it detects PE only).
~
~
---output options---
/ofilter <*ofilter_id>
: Filter the dumped output.
*ofilter_id:
0 - no filter: dump everything (default)
1 - don't dump the modified PEs, but save the report
2 - don't dump any files
/dir <output_dir>
: Set a root directory for the output (default: current directory).
/uniqd : Make a unique, timestamped directory for the output of each scan.
(Prevents overwriting results from previous scans)
/minidmp: Make a minidump of each detected process.
/suspend: Suspend processes detected as suspicious
/kill : Kill processes detected as suspicious
/quiet : Display only the summary and minimalistic info.
/log : Append each scan summary to the log.
/json : Display JSON report as the summary.
~
```
今回利用するオプションは<br>
```/hooks```...フックとメモリ内パッチを検出(直訳)<br>
```/shellc```...シェルコードインプラントの検出(直訳)<br>
```/quiet```...出力を最小限にする<br>
```/ofilter 2```...検出したProcessのdump fileを作成しない。(defaultだと作成される)<br>
```
PS> .\hollows_hunter.exe /hooks /shellc /quiet /ofilter 2
```
3. 結果は以下のようになりPID:11228のsvchost.exeがProcess HollowingされたProcessと識別された
![](https://github.com/mether049/malware/blob/master/Trickbot/img/Identification%20of%20Hollowed%20out%20processes/hollows_hunter1.PNG)
## Case2: Loki
一般的には以下の機能をもったなIoCスキャナーである。PE-Sieveも利用しているためProcess Hollwingの検出も可能と思われる
> Detection is based on four detection methods:<br>
> - File Name IOC : Regex match on full file path/name<br>
> - Yara Rule Check : Yara signature match on file data and process memory<br>
> - Hash check : Compares known malicious hashes (MD5, SHA1, SHA256) with scanned files
> - C2 Back Connect Check: Compares process connection endpoints with C2 IOCs (new since version v.10)<br>
>
> Additional Checks:
> - Regin filesystem check (via --reginfs)
> - Process anomaly check (based on Sysforensics)
> - SWF decompressed scan (new since version v0.8)
> - SAM dump check
> - DoublePulsar check - tries to detect DoublePulsar backdoor on port 445/tcp and 3389/tcp
> - PE-Sieve process check
2020-03-01 01:38:14 +07:00
1. Lokiを[こちら](https://github.com/Neo23x0/Loki)からダウンロードする
2020-03-01 01:28:00 +07:00
2. 以下のオプションで実行する(時間を要するので不要な機能は用いないようにする)
```
PS> .\loki.exe --nofilescan --nolevcheck --noindicator --onlyrelevant --nolisten
```
3. 結果は以下のようになり2つのプロセスが検出されたがHollows Hunterと同様にPID:11228のsvchost.exeを検出している
![](https://github.com/mether049/malware/blob/master/Trickbot/img/Identification%20of%20Hollowed%20out%20processes/Loki.PNG)
## Case3: EQL(Event Query Language)
EQLはWindowsイベントログ(Sysmonログ等)の検索・解析を可能にするクエリ言語。EQLを用いたスレットハンティングについては[こちら](https://www.sans.org/blog/eql-threat-hunting/)が参考になる
1. EQLを[こちら](https://github.com/endgameinc/eql)の手順でインストールする
2. Sysmonを[こちら](https://docs.microsoft.com/en-us/sysinternals/downloads/sysmon)からダウンロードし以下のようにインストールする
```
Sysmon.exe -AcceptEula -i -h * -n -l
```
3. Sysmonログはjson形式に変換する必要がある。以下のコマンドは直近5000件のSysmonログをjson形式に変換しmy-sysmon-data.jsonというファイルに出力している
```
PS> Get-LatestLogs | ConvertTo-Json | Out-File -Encoding ASCII -FilePath my-sysmon-data.json
```
4. クエリの内容を指定する。以下のクエリはプロセスの親子関係を確認し不自然なプロセスを検索している。例えばsvchost.exeの親プロセスがservices.exeではないかつ親プロセスのパスが*\\system32\\svchost.exeではないかつ子プロセスのパスが*\\syswow64\\svchost.exeではない場合は不自然とみなされる。Process Hollowingもこのプロセスの親子関係の不自然さから検出できるケースがある。<br>ref:[Unusual Child Process](https://eqllib.readthedocs.io/en/latest/analytics/3b1b9720-179b-47e2-930e-d3757bbe345e.html)
```
PS> $eql="
process where subtype.create and
(
(process_name == 'smss.exe' and not parent_process_name in ('System', 'smss.exe')) or
(process_name == 'csrss.exe' and not parent_process_name in ('smss.exe', 'svchost.exe')) or
(process_name == 'wininit.exe' and parent_process_name != 'smss.exe') or
(process_name == 'winlogon.exe' and parent_process_name != 'smss.exe') or
(process_name == 'lsass.exe' and parent_process_name != 'wininit.exe') or
(process_name == 'LogonUI.exe' and not parent_process_name in ('winlogon.exe', 'wininit.exe')) or
(process_name == 'services.exe' and parent_process_name != 'wininit.exe') or
(process_name == 'svchost.exe' and parent_process_name != 'services.exe' and
not (parent_process_path == '*\\system32\\svchost.exe' and process_path == '*\\syswow64\\svchost.exe')
) or
(process_name == 'spoolsv.exe' and parent_process_name != 'services.exe') or
(process_name == 'taskhost.exe' and not parent_process_name in ('services.exe', 'svchost.exe')) or
(process_name == 'taskhostw.exe' and not parent_process_name in ('services.exe', 'svchost.exe')) or
(process_name == 'userinit.exe' and not parent_process_name in ('dwm.exe', 'winlogon.exe'))
)"
```
5. json形式のSysmonログファイルに対して4.で指定したEQLで検索を行う
```
PS> eqllib query -f my-sysmon-data.json --source "Microsoft Sysmon" $eql | ConvertFrom-Json
```
6. 結果は以下のようになり2つのプロセスが検出された。ともに親プロセスはservices.exeではなくProcess Hollowingされた可能性が高い
![](https://github.com/mether049/malware/blob/master/Trickbot/img/Identification%20of%20Hollowed%20out%20processes/eql1.PNG)
7. それぞれのプロセスIDに対する以下のEQLを実行する
```
eqllib query -f my-sysmon-data.json --source "Microsoft Sysmon" "process where pid=7356"
```
2020-03-01 01:43:34 +07:00
![](https://github.com/mether049/malware/blob/master/Trickbot/img/Identification%20of%20Hollowed%20out%20processes/eql2.PNG?raw=true)
2020-03-01 01:28:00 +07:00
```
eqllib query -f my-sysmon-data.json --source "Microsoft Sysmon" "process where pid=11228"
```
![](https://github.com/mether049/malware/blob/master/Trickbot/img/Identification%20of%20Hollowed%20out%20processes/eql3.PNG?raw=true)
PID:7356はすでにTerminateされており現在はPID:11228のプロセスが動いていることが確認された
## Extracting IoC from Process Memory with strings2
ここでは上述したToolで識別したProcess HollwingされたProcessからstrings2を用いてIoCを取得する手法を示す。<br>
strings2は特定プロセスにおいてメモリに展開された文字列の抽出が可能なツールである
1. strings2を[こちら](http://split-code.com/strings2.html)からダウンロードする
2. 正規表現を用いてIP:PortURLを検索する
- IP:Port
```
PS> ./strings2.exe -pid 11228 | select-string -Pattern '^[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\:[\d]{0,4}$' | sort | gu
```
![](https://github.com/mether049/malware/blob/master/Trickbot/img/Identification%20of%20Hollowed%20out%20processes/strings1.PNG)
- URL
```
PS> ./strings2.exe -pid 11228 | select-string -Pattern '^http(s)?://([a-zA-Z_0-9-]+.)+[a-zA-Z_0-9-]+(/[a-zA-Z_0-9- ./?%&=]*)?' | sort | gu
```
![](https://github.com/mether049/malware/blob/master/Trickbot/img/Identification%20of%20Hollowed%20out%20processes/strings2.PNG?raw=true)
## Case4: Volatility
Volatilityはメモリフォレンジックツールである。またPluginが豊富である。メモリダンプが必要。今回はVirtual Boxからメモリダンプを取得することを想定。
1. VBoxManageを利用してホストOSからゲストOSを起動する
```
PS> .\VBoxManage.exe list vms # Virtual Boxで作成済みのゲストの名前とuuidの一覧を取得
PS> .\VBoxManage.exe startvm "guest name or uuid" #起動
```
2. VboxManageでメモリダンプ(VirtualBox ELF64 core dump)を取得する
```
2020-04-07 10:05:33 +07:00
PS> .\VBoxManage.exe debugvm "guest name or uuid" dumpvmcore --filename output.dmp
2020-03-01 01:28:00 +07:00
```
3. 最新のVolatilityを[こちら](https://github.com/volatilityfoundation/volatility)からダウンロードする
4. 考え方はEQLのときと同じでプロセスツリーから親子関係が不自然なプロセスを確認する(今回はTrickbotなのでsvchost.exeでgrepしている)
```
python vol.py --profile=[profile] -f ../output.dmp pstree | grep svchost.exe
```
![](https://github.com/mether049/malware/blob/master/Trickbot/img/Identification%20of%20Hollowed%20out%20processes/volatility4.PNG?raw=true)
2020-03-01 01:49:26 +07:00
PID:11228のプロセスのみ他のsvchost.exeと明らかに階層が異なり親プロセスのIDも異なることを確認
2020-03-01 01:28:00 +07:00
2020-03-01 01:49:26 +07:00
5. PID:11228とそれ以外のsvchost.exeの親プロセスを確認
2020-03-01 01:28:00 +07:00
```
python vol.py --profile=[profile] -f ../output.dmp pslist -p 604
```
![](https://github.com/mether049/malware/blob/master/Trickbot/img/Identification%20of%20Hollowed%20out%20processes/volatility2.PNG?raw=true)
PID:604はservices.exeでありsvchost.exeと自然な親子関係となっている
```
python vol.py --profile=[profile] -f ../output.dmp pslist -p 11020
```
![](https://github.com/mether049/malware/blob/master/Trickbot/img/Identification%20of%20Hollowed%20out%20processes/volatility3.PNG?raw=true)
PID:11020の親プロセスはメモリ上に存在せず確認できなかった。おそらくProcess Hollowingした後にTerminateされた
2020-03-01 01:49:26 +07:00
以上を踏まえるとPID:11228のsvchost.exeが不自然でありProcess Hollowingされたプロセスであると予想される
2020-03-01 01:28:00 +07:00
ref: [What Malware Authors Don't Want You To Know Evasive Hollow Process Injection](blackhat.com/docs/asia-17/materials/asia-17-KA-What-Malware-Authors-Don't-Want-You-To-Know-Evasive-Hollow-Process-Injection.pdf)<br>
※Volatilityは上述したようにPluginが豊富であり[HollowFind](https://github.com/monnappa22/HollowFind)や[MalConfScan](https://github.com/JPCERTCC/MalConfScan)を用いればおそらくProcess Hollowingの検出は容易である